diff --git a/.gitignore b/.gitignore index 5edb4ee..4191246 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ /build /captures .externalNativeBuild +/keystore.properties diff --git a/app/build.gradle b/app/build.gradle index 3bbf52f..c700110 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -4,6 +4,9 @@ apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' +Properties props = new Properties() +props.load(project.rootProject.file('local.properties').newDataInputStream()) + android { compileSdkVersion rootProject.compileSdk @@ -11,8 +14,8 @@ android { applicationId "com.xujiaji.wanandroid" minSdkVersion rootProject.minSdk targetSdkVersion rootProject.targetSdk - versionCode 3 - versionName "1.0.2" + versionCode 4 + versionName "1.0.3" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" // externalNativeBuild { // cmake { @@ -30,14 +33,29 @@ android { buildConfigField "String", "UPDATE_VERSION_URL", "$versionUrl" buildConfigField "String", "CATEGORY_THUMB", "$categoryThumb" } + + signingConfigs { + release { + storeFile file(props['KEYSTORE_PATH']) + storePassword props['KEYSTORE_PASSWORD'] + keyAlias props['KEY_ALIAS'] + keyPassword props['KEY_PASSWORD'] + } + } + buildTypes { release { minifyEnabled true zipAlignEnabled true // 移除无用的resource文件 shrinkResources true + signingConfig signingConfigs.release proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } + + debug { + signingConfig signingConfigs.release + } } compileOptions { diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e2c042d..58b8176 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,6 +1,7 @@ + package="com.xujiaji.wanandroid" + android:sharedUserId="com.xujiaji"> diff --git a/app/src/main/java/com/xujiaji/wanandroid/helper/PrefHelper.java b/app/src/main/java/com/xujiaji/wanandroid/helper/PrefHelper.java index 53d3b86..301f566 100644 --- a/app/src/main/java/com/xujiaji/wanandroid/helper/PrefHelper.java +++ b/app/src/main/java/com/xujiaji/wanandroid/helper/PrefHelper.java @@ -1,10 +1,13 @@ package com.xujiaji.wanandroid.helper; +import android.content.Context; import android.content.SharedPreferences; +import android.content.pm.PackageManager; import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; + import com.xujiaji.wanandroid.base.App; import java.util.Map; @@ -18,6 +21,28 @@ public class PrefHelper { */ public static final String USER_INFO = "user_info"; + private static Context mHostContext; + private static boolean isFailCreateHostContext; + + /** + * 获取玩安卓客户端Context + */ + private static Context getShareUserContext() { + if (mHostContext == null) { + if (isFailCreateHostContext) return null; + synchronized (PrefHelper.class) { + try { + mHostContext = App.getInstance().createPackageContext("com.xujiaji.todo", + Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + isFailCreateHostContext = true; + } + } + } + return mHostContext; + } + /** * @param key ( the Key to used to retrieve this data later ) * @param value ( any kind of primitive values ) @@ -52,7 +77,13 @@ public static void set(@NonNull String key, @Nullable T value) { @Nullable public static String getString(@NonNull String key) { - return PreferenceManager.getDefaultSharedPreferences(App.getInstance()).getString(key, null); + String value = PreferenceManager.getDefaultSharedPreferences(App.getInstance()).getString(key, null); + if (value == null) { + if (getShareUserContext() == null) return null; + return PreferenceManager.getDefaultSharedPreferences(getShareUserContext()).getString(key, null); + } else { + return value; + } } public static boolean getBoolean(@NonNull String key) { @@ -78,7 +109,8 @@ public static void clearKey(@NonNull String key) { } public static boolean isExist(@NonNull String key) { - return PreferenceManager.getDefaultSharedPreferences(App.getInstance()).contains(key); + boolean value = PreferenceManager.getDefaultSharedPreferences(App.getInstance()).contains(key); + return value || getShareUserContext() != null && PreferenceManager.getDefaultSharedPreferences(getShareUserContext()).contains(key); } public static void clearPrefs() { diff --git a/app/src/main/java/com/xujiaji/wanandroid/module/main/MainActivity.java b/app/src/main/java/com/xujiaji/wanandroid/module/main/MainActivity.java index eaee86e..5ad953e 100644 --- a/app/src/main/java/com/xujiaji/wanandroid/module/main/MainActivity.java +++ b/app/src/main/java/com/xujiaji/wanandroid/module/main/MainActivity.java @@ -1,5 +1,7 @@ package com.xujiaji.wanandroid.module.main; +import android.content.Intent; +import android.content.pm.PackageManager; import android.os.Bundle; import android.support.annotation.IdRes; import android.support.annotation.NonNull; @@ -16,6 +18,7 @@ import android.widget.TextView; import com.google.gson.Gson; +import com.qihoo360.replugin.RePlugin; import com.xujiaji.mvvmquick.util.ActivityUtils; import com.xujiaji.wanandroid.R; import com.xujiaji.wanandroid.adapter.FragmentsPagerAdapter; @@ -31,9 +34,9 @@ import com.xujiaji.wanandroid.module.login.LoginActivity; import com.xujiaji.wanandroid.module.set.SettingsActivity; import com.xujiaji.wanandroid.repository.bean.UserBean; +import com.xujiaji.wanandroid.util.ApkUtil; import java.util.List; -import java.util.Objects; import javax.inject.Inject; import javax.inject.Named; @@ -153,13 +156,32 @@ public void onBinding(@NonNull ActivityMainBinding binding) { binding.navMenu.drawerTabLayout.setupWithViewPager(binding.navMenu.drawerViewPager); binding.fab.setOnClickListener(v -> { if (App.Login.isOK()) { - ToastHelper.info("敬请期待!"); + launchTodo(); } else { LoginActivity.launch(MainActivity.this); } }); } + /** + * launch todoapp + */ + private void launchTodo() { + if (ApkUtil.isInstalled(this, "com.xujiaji.todo")) { + Intent intent = getPackageManager().getLaunchIntentForPackage("com.xujiaji.todo"); + startActivity(intent); + } else { + int tip_todo_sum = PrefHelper.getInt("tip_todo_sum"); + if (tip_todo_sum < 2) { + ToastHelper.info("可进入设置,单独安装 Todo Apk"); + PrefHelper.set("tip_todo_sum", tip_todo_sum + 1); + } + RePlugin.startActivity(this, + RePlugin.createIntent("com.xujiaji.todo", + "com.xujiaji.todo.module.main.MainActivity")); + } + } + private void changeAccount(UserBean userBean) { TextView tvName = binding.navMenu.extrasNav.getHeaderView(0).findViewById(R.id.navFullName); TextView tvEmail = binding.navMenu.extrasNav.getHeaderView(0).findViewById(R.id.navUsername); diff --git a/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsActivity.java b/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsActivity.java index 828e03a..2a71f41 100644 --- a/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsActivity.java +++ b/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsActivity.java @@ -6,12 +6,15 @@ import android.support.annotation.NonNull; import com.qihoo360.replugin.RePlugin; +import com.qihoo360.replugin.model.PluginInfo; import com.xujiaji.mvvmquick.base.NoneViewModel; import com.xujiaji.wanandroid.base.BaseActivity; import com.xujiaji.wanandroid.databinding.ActivitySettingsBinding; import com.xujiaji.wanandroid.helper.ToolbarHelper; import com.xujiaji.wanandroid.util.FileUtil; +import java.util.List; + /** * author: xujiaji * created on: 2018/8/23 19:39 @@ -40,6 +43,10 @@ public void onObserveViewModel(@NonNull SettingsViewModel viewModel) { super.onObserveViewModel(viewModel); binding.setSettingsViewModel(viewModel); viewModel.cacheSize.set(FileUtil.getCacheSizeStr(this)); - viewModel.pluginNum.set(RePlugin.getPluginInfoList().size()); + int pluginNum = 0; + for (PluginInfo pluginInfo : RePlugin.getPluginInfoList()) { + pluginNum += pluginInfo.isUsed() ? 1 : 0; + } + viewModel.pluginNum.set(pluginNum); } } diff --git a/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsViewModel.java b/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsViewModel.java index 597102b..465fc3a 100644 --- a/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsViewModel.java +++ b/app/src/main/java/com/xujiaji/wanandroid/module/set/SettingsViewModel.java @@ -9,9 +9,12 @@ import com.qihoo360.replugin.RePlugin; import com.qihoo360.replugin.model.PluginInfo; +import com.xujiaji.wanandroid.base.App; import com.xujiaji.wanandroid.base.BaseViewModel; import com.xujiaji.wanandroid.helper.ToastHelper; +import com.xujiaji.wanandroid.util.ApkUtil; import com.xujiaji.wanandroid.util.FileUtil; +import com.xujiaji.wanandroid.util.NetUtil; import javax.inject.Inject; import javax.inject.Singleton; @@ -56,4 +59,12 @@ public void cleanPlugin(View view) { pluginNum.set(0); ToastHelper.success("已清除,重启生效"); } + + public boolean isUnInstallTodoApk() { + return !ApkUtil.isInstalled(App.getInstance(), "com.xujiaji.todo"); + } + + public void installTodoApk(View view) { + NetUtil.systemBrowserOpen(view.getContext(), "https://github.com/xujiaji/Todo"); + } } diff --git a/app/src/main/java/com/xujiaji/wanandroid/util/ApkUtil.java b/app/src/main/java/com/xujiaji/wanandroid/util/ApkUtil.java new file mode 100644 index 0000000..8a3794a --- /dev/null +++ b/app/src/main/java/com/xujiaji/wanandroid/util/ApkUtil.java @@ -0,0 +1,25 @@ +package com.xujiaji.wanandroid.util; + +import android.content.Context; +import android.content.pm.PackageManager; +import android.text.TextUtils; + +/** + * author: xujiaji + * created on: 2018/10/18 14:18 + * description: + */ +public class ApkUtil { + public static boolean isInstalled(Context context, String packageName) { + if (TextUtils.isEmpty(packageName)) { + return false; + } + try { + context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES); + return true; + } catch (PackageManager.NameNotFoundException e) { + e.printStackTrace(); + return false; + } + } +} diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 8da564b..01f6d1f 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,6 +1,7 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:bind="http://schemas.android.com/tools"> + + + + + diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index e22b688..7741a12 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -91,5 +91,6 @@ ]]> %s个子分类 正在初始化体系数据,请稍后... + 下载安装Todo Apk(建议) diff --git a/build.gradle b/build.gradle index 043f2f2..df845d7 100644 --- a/build.gradle +++ b/build.gradle @@ -8,7 +8,7 @@ buildscript { jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.1.3' + classpath 'com.android.tools.build:gradle:3.1.4' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" classpath "com.qihoo360.replugin:replugin-host-gradle:$replugin_host_version" // NOTE: Do not place your application dependencies here; they belong @@ -38,11 +38,11 @@ ext{ categoryThumb = '"https://raw.githubusercontent.com/xujiaji/xujiaji.github.io/pictures/wanandroid/category_thumb/%s.jpg"' addOwnPlugin = '"https://github.com/xujiaji/WanAndroid/issues/1"' - compileSdk = 27 + compileSdk = 28 minSdk = 21 - targetSdk = 27 + targetSdk = 28 - support = '27.1.1' + support = '28.0.0' okhttp3 = '3.6.0' retrofit = '2.0.2' arch = '1.1.1' diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 500f892..9654650 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,4 +1,4 @@ -#Thu Aug 02 22:41:26 CST 2018 +#Thu Oct 18 14:59:29 CST 2018 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME