Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 48 additions & 26 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,25 @@ apply plugin: 'android-apt'
apply plugin: 'realm-android'

android {
compileSdkVersion 24
buildToolsVersion "24.0.1"
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}

dataBinding {
enabled = true
}


compileSdkVersion Integer.parseInt(project.ANDROID_BUILD_SDK_VERSION)
buildToolsVersion project.ANDROID_BUILD_TOOLS_VERSION

defaultConfig {
applicationId "com.codeest.geeknews"
minSdkVersion 21
targetSdkVersion 24
versionCode 2
versionName "1.0.1"
applicationId project.APP_APPLICATIONID
minSdkVersion Integer.parseInt(project.ANDROID_BUILD_MIN_SDK_VERSION)
targetSdkVersion Integer.parseInt(project.ANDROID_BUILD_TARGET_SDK_VERSION)
versionCode Integer.parseInt(project.APP_VERSIONCODE)
versionName project.APP_VERSIONNAME
}

buildTypes {
Expand All @@ -28,37 +38,49 @@ android {
}
}

ext {
appCompat = "25.0.1"
easyPermissions="0.2.1"
retrofit = "2.0.2"
dagger = "2.0.2"
reactivex = "1.1.0"
butterknife = "8.2.1"
blockcanary = "1.2.1"
leakcanary = "1.4-beta2"
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile files('libs/tbs_sdk_thirdapp_v2.2.0.1096_36549_sharewithdownload_withoutGame_obfs_20160830_211645.jar')
testCompile 'junit:junit:4.12'

//ui
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'com.android.support:cardview-v7:24.1.1'
compile "com.android.support:recyclerview-v7:${appCompat}"
compile "com.android.support:appcompat-v7:${appCompat}"
compile "com.android.support:cardview-v7:${appCompat}"
compile "com.android.support:design:${appCompat}"
compile "pub.devrel:easypermissions:${easyPermissions}"

//rx
compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:1.1.0'
compile "io.reactivex:rxjava:${reactivex}"
compile "io.reactivex:rxandroid:${reactivex}"
compile 'com.jakewharton.rxbinding:rxbinding:0.4.0'

//network
compile 'com.google.code.gson:gson:2.4'
compile 'com.squareup.retrofit2:retrofit:2.0.2'
compile 'com.squareup.retrofit2:converter-gson:2.0.2'
compile 'com.squareup.retrofit2:adapter-rxjava:2.0.2'
compile 'com.google.code.gson:gson:2.7'
compile "com.squareup.retrofit2:retrofit:${retrofit}"
compile "com.squareup.retrofit2:converter-gson:${retrofit}"
compile "com.squareup.retrofit2:adapter-rxjava:${retrofit}"
compile 'com.squareup.okhttp3:okhttp:3.2.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.0.1'
compile 'com.github.bumptech.glide:glide:3.7.0'
compile 'com.github.bumptech.glide:okhttp3-integration:1.4.0@aar'

//di
compile 'com.google.dagger:dagger:2.0.2'
compile 'com.google.dagger:dagger-compiler:2.0.2'
compile 'com.jakewharton:butterknife:8.2.1'
apt 'com.jakewharton:butterknife-compiler:8.2.1'
compile "com.google.dagger:dagger:${dagger}"
compile "com.google.dagger:dagger-compiler:${dagger}"
compile "com.jakewharton:butterknife:${butterknife}"
apt "com.jakewharton:butterknife-compiler:${butterknife}"
provided 'org.glassfish:javax.annotation:10.0-b28'

//other
Expand All @@ -69,13 +91,13 @@ dependencies {
//widget
compile 'com.victor:lib:1.0.4'
compile 'com.prolificinteractive:material-calendarview:1.4.0'
compile 'net.opacapp:multiline-collapsingtoolbar:1.2.2'
compile 'net.opacapp:multiline-collapsingtoolbar:1.3.1'
compile 'com.github.chrisbanes:PhotoView:1.3.0'
compile 'com.miguelcatalan:materialsearchview:1.4.0'

//canary
debugCompile 'com.github.moduth:blockcanary-android:1.2.1'
releaseCompile 'com.github.moduth:blockcanary-no-op:1.2.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.4-beta2'
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.4-beta2'
debugCompile "com.github.moduth:blockcanary-android:${blockcanary}"
releaseCompile "com.github.moduth:blockcanary-no-op:${blockcanary}"
debugCompile "com.squareup.leakcanary:leakcanary-android:${leakcanary}"
releaseCompile "com.squareup.leakcanary:leakcanary-android-no-op:${leakcanary}"
}
3 changes: 2 additions & 1 deletion app/src/main/java/com/codeest/geeknews/app/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatDelegate;
import android.util.DisplayMetrics;
import android.view.Display;
Expand Down Expand Up @@ -93,7 +94,7 @@ public void exitApp() {
if (allActivities != null) {
synchronized (allActivities) {
for (Activity act : allActivities) {
act.finish();
ActivityCompat.finishAfterTransition(act);
}
}
}
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/com/codeest/geeknews/base/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatDelegate;
import android.support.v7.widget.Toolbar;
import android.view.View;
Expand Down Expand Up @@ -100,6 +101,15 @@ public void useNightMode(boolean isNight) {
recreate();
}

@Override
public void onBackPressedSupport() {
if (getSupportFragmentManager().getBackStackEntryCount() > 1) {
pop();
} else {
ActivityCompat.finishAfterTransition(this);
}
}

protected abstract void initInject();
protected abstract int getLayout();
protected abstract void initEventAndData();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package com.codeest.geeknews.ui.main.activity;

import android.Manifest;
import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.widget.ImageView;
import android.widget.TextView;

Expand All @@ -12,13 +17,20 @@
import com.codeest.geeknews.presenter.WelcomePresenter;
import com.codeest.geeknews.presenter.contract.WelcomeContract;

import java.util.List;

import butterknife.BindView;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.AppSettingsDialog;
import pub.devrel.easypermissions.EasyPermissions;

import static pub.devrel.easypermissions.AppSettingsDialog.DEFAULT_SETTINGS_REQ_CODE;

/**
* Created by codeest on 16/8/15.
*/

public class WelcomeActivity extends BaseActivity<WelcomePresenter> implements WelcomeContract.View {
public class WelcomeActivity extends BaseActivity<WelcomePresenter> implements WelcomeContract.View, EasyPermissions.PermissionCallbacks {

@BindView(R.id.iv_welcome_bg)
ImageView ivWelcomeBg;
Expand Down Expand Up @@ -49,21 +61,99 @@ public void showContent(WelcomeBean welcomeBean) {

@Override
public void jumpToMain() {
requirePermissions();
}

@Override
protected void onDestroy() {
Glide.clear(ivWelcomeBg);
super.onDestroy();
}

@Override
public void showError(String msg) {

}


private void toMain() {
Intent intent = new Intent();
intent.setClass(this,MainActivity.class);
startActivity(intent);
finish();
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
}


private static final int RC_PERMISSIONS = 123;

@SuppressLint("InlinedApi")
private boolean hasPermissions() {
return EasyPermissions.hasPermissions(this, Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.READ_PHONE_STATE);
}


@SuppressLint("InlinedApi")
@AfterPermissionGranted(RC_PERMISSIONS)
private void requirePermissions() {
if (hasPermissions()) {
toMain();
} else {
// Ask for one permission
EasyPermissions.requestPermissions(this,
getString(R.string.rationale_permissions),
RC_PERMISSIONS,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_PHONE_STATE);
}
}


@Override
protected void onDestroy() {
Glide.clear(ivWelcomeBg);
super.onDestroy();
public void onPermissionsGranted(int requestCode, List<String> perms) {
toMain();
}


@Override
public void showError(String msg) {
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}


@Override
public void onPermissionsDenied(int requestCode, List<String> perms) {
permissionsDeniedOpenSetting();
}


private void permissionsDeniedOpenSetting() {
if (!hasPermissions()) {
new AppSettingsDialog.Builder(this, getString(R.string.app_settings_dialog_rationale_ask_again)).setTitle(getString(R.string.app_settings_dialog_title_settings_dialog))
.setPositiveButton(getString(R.string.app_settings_dialog_setting))
.setNegativeButton(getString(R.string.app_settings_dialog_cancel),
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
ActivityCompat.finishAffinity(WelcomeActivity.this);
}
})
.build()
.show();
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case DEFAULT_SETTINGS_REQ_CODE:
if (hasPermissions()) {
toMain();
}
permissionsDeniedOpenSetting();
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.support.annotation.NonNull;
import android.support.v4.app.ActivityCompat;
import android.support.v7.widget.Toolbar;

import com.codeest.geeknews.R;
Expand Down Expand Up @@ -54,6 +55,6 @@ public void onDateSelected(@NonNull MaterialCalendarView widget, @NonNull Calend
@OnClick(R.id.tv_calender_enter)
void chooseDate() {
RxBus.getDefault().post(mDate);
finish();
ActivityCompat.finishAfterTransition(this);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.codeest.geeknews.ui.zhihu.activity;

import android.app.ActivityOptions;
import android.content.Intent;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.view.ViewCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
Expand Down Expand Up @@ -43,6 +45,8 @@ public class SectionActivity extends BaseActivity<SectionChildPresenter> impleme
int id;
String title;

private int position = -1;

@Override
protected void initInject() {
getActivityComponent().inject(this);
Expand Down Expand Up @@ -74,21 +78,37 @@ public void onRefresh() {
public void OnItemClick(int position, View shareView) {
mPresenter.insertReadToDB(mList.get(position).getId());
mAdapter.setReadState(position, true);
mAdapter.notifyItemChanged(position);
SectionActivity.this.position = position;
Intent intent = new Intent();
intent.setClass(mContext, ZhihuDetailActivity.class);
intent.putExtra("id", mList.get(position).getId());
String transitionSharedItemName = ViewCompat.getTransitionName(shareView);
intent.putExtra("shared-item-name", transitionSharedItemName);
if (shareView != null) {
mContext.startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext, shareView, "shareView").toBundle());
ActivityCompat.startActivity(SectionActivity.this, intent, ActivityOptionsCompat.makeSceneTransitionAnimation(mContext, shareView, transitionSharedItemName).toBundle());
} else {
startActivity(intent, ActivityOptions.makeSceneTransitionAnimation(mContext).toBundle());
ActivityCompat.startActivity(SectionActivity.this, intent, ActivityOptionsCompat.makeBasic().toBundle());
}
}
});
mPresenter.getThemeChildData(id);
viewLoading.start();
}

@Override
protected void onResume() {
super.onResume();
if (mAdapter != null && position > 0) {
mAdapter.notifyItemChanged(position);
}
}

@Override
protected void onDestroy() {
super.onDestroy();
position = -1;
}

@Override
public void showContent(SectionChildListBean sectionChildListBean) {
if(swipeRefresh.isRefreshing()) {
Expand Down
Loading