Skip to content

Commit

Permalink
Merge pull request #1 from ouyangzn/develop
Browse files Browse the repository at this point in the history
Develop completed(v1.1.0)
  • Loading branch information
ouyangzn authored Jun 6, 2017
2 parents f779719 + d04e920 commit 7340bf9
Show file tree
Hide file tree
Showing 84 changed files with 3,280 additions and 890 deletions.
23 changes: 19 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'android-apt'
apply plugin: 'realm-android'
apply plugin: 'me.tatarka.retrolambda'
apply plugin: 'org.greenrobot.greendao' // apply plugin

// 跟下面的versionName保持一致,最后一位用于紧急修复版本
def versionMajor = 1
Expand All @@ -18,6 +18,7 @@ android {
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode versionMajor * 1000000 + versionMinor * 10000 + versionPatch * 100 + versionBuild
versionName "1.0.0"

}
Properties properties = new Properties()
properties.load(project.rootProject.file('local.properties').newDataInputStream())
Expand Down Expand Up @@ -63,9 +64,18 @@ android {
}
}

greendao {
schemaVersion 1
daoPackage "com.ouyangzn.github.dao"
}
apt {
arguments {
eventBusIndex "com.ouyangzn.github.event.EventBusIndex"
}
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
testCompile 'junit:junit:4.12'
//
compile "com.android.support:appcompat-v7:${APPCOMPAT_V7_VERSION}"
compile "com.android.support:design:${DESIGN_VERSION}"
Expand All @@ -81,7 +91,6 @@ dependencies {
compile "com.jakewharton.rxbinding:rxbinding:${RXBINDING_VERSION}"
compile "com.jakewharton.rxbinding:rxbinding-recyclerview-v7:${RXBINDING_SUPPORT_VERSION}"
compile "com.jakewharton.rxbinding:rxbinding-support-v4:${RXBINDING_SUPPORT_VERSION}"
compile 'com.trello:rxlifecycle:1.0'
// If you want to bind to Android-specific lifecycles
compile "com.trello:rxlifecycle-android:${RXLIFECYCLE_VERSION}"
// If you want pre-written Activities and Fragments you can subclass as providers
Expand All @@ -102,8 +111,14 @@ dependencies {
// butterknife系列
compile "com.jakewharton:butterknife:${BUTTERKNIFE_VERSION}"
apt "com.jakewharton:butterknife-compiler:${BUTTERKNIFE_COMPILER_VERSION}"
// greendao
compile "org.greenrobot:greendao:${GREENDAO_VERSION}"
// eventBus
compile "org.greenrobot:eventbus:${EVENT_BUS_VERSION}"
apt "org.greenrobot:eventbus-annotation-processor:${EVENTBUS_ANNOTATION_PROCESSOR_VERSION}"

// chrome调试与realm的调试
debugCompile "com.facebook.stetho:stetho:${STETHO_VERSION}"
debugCompile "com.facebook.stetho:stetho-okhttp3:${STETHO_OKHTTP_VERSION}"
debugCompile "com.uphyca:stetho_realm:${STETHO_REALM_VERSION}"
testCompile 'junit:junit:4.12'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
-keep class retrofit2.** { *; }
-keepattributes Signature
-keepattributes Exceptions
# 保留retrofit的方法参数
-keepclasseswithmembers class * {
@retrofit2.http.* <methods>;
}

# butterknife
-keep class butterknife.** { *; }
Expand Down Expand Up @@ -157,4 +161,25 @@
public *;
}

# greenDao
-keepclassmembers class * extends org.greenrobot.greendao.AbstractDao {
public static java.lang.String TABLENAME;
}
-keep class **$Properties

# If you do not use SQLCipher:
-dontwarn org.greenrobot.greendao.database.**

# eventBus
-keepattributes *Annotation*
-keepclassmembers class ** {
@org.greenrobot.eventbus.Subscribe <methods>;
}
-keep enum org.greenrobot.eventbus.ThreadMode { *; }

# Only required if you use AsyncExecutor
-keepclassmembers class * extends org.greenrobot.eventbus.util.ThrowableFailureEvent {
<init>(java.lang.Throwable);
}


21 changes: 9 additions & 12 deletions app/src/debug/java/com/ouyangzn/github/DebugApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
package com.ouyangzn.github;

import com.facebook.stetho.Stetho;
import com.uphyca.stetho_realm.RealmInspectorModulesProvider;

import static com.ouyangzn.github.db.GlobalRealmMigration.DB_NAME;

/**
* Created by ouyangzn on 2016/9/29.<br/>
Expand All @@ -33,17 +30,17 @@ public class DebugApp extends App {
}

private void initStetho() {
RealmInspectorModulesProvider provider = RealmInspectorModulesProvider.builder(this)
//.withFolder(getCacheDir())
.withEncryptionKey(DB_NAME, getGlobalRealmKey())
//.withMetaTables()
//.withDescendingOrder()
//.withLimit(1000)
//.databaseNamePattern(Pattern.compile(".+\\.realm"))
.build();
//RealmInspectorModulesProvider provider = RealmInspectorModulesProvider.builder(this)
// //.withFolder(getCacheDir())
// .withEncryptionKey(DB_NAME, getGlobalRealmKey())
// //.withMetaTables()
// //.withDescendingOrder()
// //.withLimit(1000)
// //.databaseNamePattern(Pattern.compile(".+\\.realm"))
// .build();
Stetho.initialize(Stetho.newInitializerBuilder(this)
.enableDumpapp(Stetho.defaultDumperPluginsProvider(this))
.enableWebKitInspector(provider)
.enableWebKitInspector(Stetho.defaultInspectorModulesProvider(this))
.build());
}
}
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".module.collect.CollectActivity">
</activity>
<activity android:name=".base.BaseFragmentActivity"/>
</application>
</manifest>
91 changes: 73 additions & 18 deletions app/src/main/java/com/ouyangzn/github/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,27 @@
package com.ouyangzn.github;

import android.app.Application;
import android.text.TextUtils;
import android.util.Base64;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.internal.bind.TypeAdapters;
import com.ouyangzn.github.db.GlobalRealmMigration;
import com.ouyangzn.github.bean.apibean.User;
import com.ouyangzn.github.db.DaoHelper;
import com.ouyangzn.github.event.Event;
import com.ouyangzn.github.event.EventBusIndex;
import com.ouyangzn.github.json.DoubleAdapter;
import com.ouyangzn.github.json.IntegerAdapter;
import com.ouyangzn.github.json.LongAdapter;
import com.ouyangzn.github.utils.ImageLoader;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import com.ouyangzn.github.utils.SpUtils;
import org.greenrobot.eventbus.EventBus;

import static com.ouyangzn.github.db.GlobalRealmMigration.DB_NAME;
import static com.ouyangzn.github.db.GlobalRealmMigration.DB_VERSION;
import static com.ouyangzn.github.event.EventType.TYPE_LOGIN;
import static com.ouyangzn.github.event.EventType.TYPE_LOGOUT;
import static com.ouyangzn.github.utils.SpUtils.KEY_AUTHORIZATION;
import static com.ouyangzn.github.utils.SpUtils.KEY_USER;
import static com.ouyangzn.github.utils.SpUtils.KEY_USERNAME;

/**
* Created by ouyangzn on 2016/9/5.<br/>
Expand All @@ -37,21 +45,66 @@
public class App extends Application {

private static App sApp;

private static String sUsername;
private static String sAuthorization;
private static User sUser;
private Gson mGson;

public static App getApp() {
return sApp;
}

public Realm getGlobalRealm() {
return Realm.getInstance(new RealmConfiguration.Builder().name(DB_NAME)
// 密码必须64个字节
.encryptionKey(getGlobalRealmKey())
.schemaVersion(DB_VERSION)
.migration(new GlobalRealmMigration())
//.deleteRealmIfMigrationNeeded()
.build());
public static String getUsername() {
if (TextUtils.isEmpty(sUsername)) {
sUsername = SpUtils.getString(sApp, KEY_USERNAME);
}
return sUsername;
}

public static void setUsername(String username) {
App.sUsername = username;
SpUtils.put(sApp, KEY_USERNAME, username);
}

public static void onLogin(User user) {
setUser(user);
EventBus.getDefault().post(new Event(TYPE_LOGIN));
}

public static void onLogout() {
clearAuthorization();
setUser(null);
EventBus.getDefault().post(new Event(TYPE_LOGOUT));
}

public static User getUser() {
if (sUser == null) {
sUser = sApp.getGson().fromJson(SpUtils.getString(sApp, KEY_USER), User.class);
}
return sUser;
}

public static void setUser(User user) {
sUser = user;
SpUtils.put(sApp, KEY_USER, sApp.getGson().toJson(user));
}

public static String getAuthorization() {
if (sAuthorization == null) {
sAuthorization = SpUtils.getString(sApp, KEY_AUTHORIZATION);
}
return sAuthorization;
}

public static void setAuthorization(String username, String password) {
sAuthorization =
"Basic " + Base64.encodeToString((username + ":" + password).getBytes(), Base64.NO_WRAP);
SpUtils.put(sApp, KEY_AUTHORIZATION, sAuthorization);
}

private static void clearAuthorization() {
sAuthorization = null;
SpUtils.put(sApp, KEY_AUTHORIZATION, null);
}

public Gson getGson() {
Expand All @@ -72,10 +125,12 @@ public Gson getGson() {
super.onCreate();
sApp = this;
ImageLoader.init(sApp);
Realm.init(sApp);
DaoHelper.initDao(sApp);
EventBus.builder()
.addIndex(new EventBusIndex())
.logNoSubscriberMessages(BuildConfig.LOG_DEBUG)
.throwSubscriberException(BuildConfig.LOG_DEBUG)
.installDefaultEventBus();
}

protected byte[] getGlobalRealmKey() {
return "abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789".getBytes();
}
}
54 changes: 43 additions & 11 deletions app/src/main/java/com/ouyangzn/github/base/BaseFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -42,7 +43,9 @@ public abstract class BaseFragment<V extends BaseView, T extends BasePresenter<V
protected View mContentView;
protected View mLoadingView;
protected View mErrorView;
protected Toolbar mToolbar;
private ViewGroup mRootView;
private ViewGroup mContentContainer;
private com.ouyangzn.github.utils.Toast mToast;
private Status mStatus;
private Unbinder mUnbinder;
Expand All @@ -61,13 +64,17 @@ public final View onCreateView(LayoutInflater inflater, @Nullable ViewGroup cont
super.onCreateView(inflater, container, savedInstanceState);
mInflater = inflater;
mRootView = (ViewGroup) inflater.inflate(R.layout.fragment_base_content, container, false);
mContentContainer = (ViewGroup) mRootView.findViewById(R.id.layout_content_container);
mLoadingView = mRootView.findViewById(R.id.stub_loading);
mErrorView = mRootView.findViewById(R.id.stub_error);
mContentView = inflater.inflate(getContentView(), container, false);
if (mContentView == null) throw new UnsupportedOperationException("contentView == null");
mRootView.addView(mContentView);
mContentContainer.addView(mContentView);
mToolbar = (Toolbar) mRootView.findViewById(R.id.toolbar);
requestToolbarOverlay(false);
if (mStatus == null) {
switchStatus(getCurrentStatus());
Status status = getCurrentStatus();
switchStatus(status == null ? Status.STATUS_NORMAL : status);
} else {
switchStatus(mStatus);
}
Expand All @@ -77,7 +84,9 @@ public final View onCreateView(LayoutInflater inflater, @Nullable ViewGroup cont

@Override public final void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mPresenter.onAttach((V) this);
if (mPresenter != null) {
mPresenter.onAttach((V) this);
}
initView(mContentView);
}

Expand All @@ -87,17 +96,31 @@ public final View onCreateView(LayoutInflater inflater, @Nullable ViewGroup cont
mUnbinder.unbind();
}

public void requestToolbarOverlay(boolean overlay) {
if (overlay) {
mContentContainer.setPadding(0, 0, 0, 0);
} else {
mContentContainer.setPadding(0, getResources().getDimensionPixelSize(R.dimen.toolbar_height),
0, 0);
}
}

public void requestNoToolbar() {
mToolbar.setVisibility(View.GONE);
requestToolbarOverlay(true);
}

protected void setLoadingView(View loadingView) {
loadingView.setVisibility(mLoadingView.getVisibility());
mRootView.removeView(mLoadingView);
mRootView.addView(loadingView);
mContentContainer.removeView(mLoadingView);
mContentContainer.addView(loadingView);
mLoadingView = loadingView;
}

protected void setErrorView(View errorView) {
errorView.setVisibility(mErrorView.getVisibility());
mRootView.removeView(mErrorView);
mRootView.addView(errorView);
mContentContainer.removeView(mErrorView);
mContentContainer.addView(errorView);
mErrorView = errorView;
}

Expand Down Expand Up @@ -143,6 +166,8 @@ protected void toast(int resId) {

protected abstract int getContentView();

public abstract T initPresenter();

/**
* 初始化一些数据,此时view还未创建完,
* 如果是拿到数据马上显示的操作,应放到{@link #initView(View)}中
Expand All @@ -153,12 +178,10 @@ protected void toast(int resId) {

protected abstract void initView(View parent);

public abstract T initPresenter();

private void hideAllView() {
int childCount = mRootView.getChildCount();
int childCount = mContentContainer.getChildCount();
for (int i = 0; i < childCount; i++) {
mRootView.getChildAt(i).setVisibility(View.GONE);
mContentContainer.getChildAt(i).setVisibility(View.GONE);
}
}

Expand All @@ -170,6 +193,15 @@ private void hideAllView() {
@Override public void setLoadingIndicator(boolean isActive) {
}

/**
* 返回键事件
*
* @return 是否继续传播
*/
public boolean onBackPressed() {
return false;
}

/**
* fragment的数据等加载状态
*/
Expand Down
Loading

0 comments on commit 7340bf9

Please sign in to comment.