Skip to content

Commit

Permalink
feat(module): todo list
Browse files Browse the repository at this point in the history
  • Loading branch information
xujiaji committed Oct 21, 2018
1 parent 88e67aa commit 44da764
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
/build
/captures
.externalNativeBuild
/keystore.properties
22 changes: 20 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ 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
defaultConfig {
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 {
Expand All @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xujiaji.wanandroid">
package="com.xujiaji.wanandroid"
android:sharedUserId="com.xujiaji">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
Expand Down
36 changes: 34 additions & 2 deletions app/src/main/java/com/xujiaji/wanandroid/helper/PrefHelper.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 )
Expand Down Expand Up @@ -52,7 +77,13 @@ public static <T> 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) {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}
25 changes: 25 additions & 0 deletions app/src/main/java/com/xujiaji/wanandroid/util/ApkUtil.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
27 changes: 26 additions & 1 deletion app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:bind="http://schemas.android.com/tools">

<data>
<variable
Expand Down Expand Up @@ -121,6 +122,30 @@

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:gravity="center_vertical"
android:minHeight="70dp"
android:onClick="@{settingsViewModel::installTodoApk}"
bind:visibleGone="@{settingsViewModel.isUnInstallTodoApk()}"
android:orientation="horizontal"
android:paddingLeft="@dimen/spacing_large"
android:paddingRight="@dimen/spacing_large"
android:focusable="true">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:fontFamily="sans-serif-light"
android:text="@string/download_todo_apk"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="@color/grey_80" />

</LinearLayout>

</LinearLayout>

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,5 +91,6 @@
<string name="give_friend_download"><![CDATA[分享给身边的好友扫描下载 >]]></string>
<string name="format_have_sum_category">%s个子分类</string>
<string name="start_init_tree_data">正在初始化体系数据,请稍后...</string>
<string name="download_todo_apk">下载安装Todo Apk(建议)</string>

</resources>
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 44da764

Please sign in to comment.