diff --git a/.gitignore b/.gitignore index 39b6783..0638c1a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -63,3 +88,17 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore index 3c117df..0638c1a 100644 --- a/app/.gitignore +++ b/app/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/base/.gitignore b/base/.gitignore index 3c117df..0638c1a 100644 --- a/base/.gitignore +++ b/base/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/base/src/main/java/com/heyongrui/base/assist/AppManager.java b/base/src/main/java/com/heyongrui/base/assist/AppManager.java index a69384a..841e4c3 100644 --- a/base/src/main/java/com/heyongrui/base/assist/AppManager.java +++ b/base/src/main/java/com/heyongrui/base/assist/AppManager.java @@ -3,123 +3,110 @@ import android.app.Activity; import android.os.Build; -import java.util.Iterator; -import java.util.Stack; +import androidx.annotation.NonNull; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.LinkedList; +import java.util.List; /** * Created by lambert on 2018/3/5. */ public final class AppManager { - /** - * 是否使用桥接模式 - **/ - private boolean isBridge = false; - /** - * AppManager管理activity的委托类 - **/ - private AppManagerDelegate mDelegate; - /** - * 维护activity的栈结构 - **/ - private Stack mActivityStack; + private static List mActivitys = Collections.synchronizedList(new LinkedList<>()); private static volatile AppManager sInstance; - /** - * 隐藏构造器 - * - * @param isBridge 是否开启桥接模式 - */ - private AppManager(boolean isBridge) { - this.isBridge = isBridge; - mDelegate = AppManagerDelegate.getInstance(); - } - - /** - * 单例 - * - * @return 返回AppManager的单例 - */ public static AppManager getInstance() { if (sInstance == null) { synchronized (AppManager.class) { if (sInstance == null) { - sInstance = new AppManager(true); + sInstance = new AppManager(); } } } return sInstance; } + public List getActivitys() { + return mActivitys; + } + /** - * 添加Activity到堆栈 - * - * @param activity activity实例 + * 添加一个activity到list里 */ public void addActivity(Activity activity) { - if (isBridge) { - mDelegate.addActivity(activity); - } else { - if (mActivityStack == null) { - mActivityStack = new Stack<>(); - } - mActivityStack.add(activity); + if (mActivitys == null) { + return; } + mActivitys.add(activity); } + /** - * 从堆栈移除Activity - * - * @param activity activity实例 + * 从list里删除一个activity */ public void removeActivity(Activity activity) { - if (isBridge) { - mDelegate.removeActivity(activity); - } else { - if (mActivityStack == null) { - mActivityStack = new Stack<>(); - } - mActivityStack.remove(activity); + if (mActivitys == null) { + return; } + mActivitys.remove(activity); } + /** - * 获取当前Activity(栈中最后一个压入的) - * - * @return 当前(栈顶)activity + * 结束指定类名的Activity */ - public Activity currentActivity() { - if (isBridge) { - return mDelegate.currentActivity(); - } else { - if (mActivityStack != null && !mActivityStack.isEmpty()) { - return mActivityStack.lastElement(); + public void finishActivity(Class cls) { + if (mActivitys == null || mActivitys.isEmpty()) { + return; + } + List activityList = new ArrayList<>(); + for (Activity activity : mActivitys) { + if (activity != null && activity.getClass().equals(cls)) { + activityList.add(activity); + } + } + mActivitys.removeAll(activityList); + for (int i = 0; i < activityList.size(); i++) { + Activity activity = activityList.get(i); + if (activity != null) { + activity.finish(); } - return null; } } + /** - * 结束除当前activtiy以外的所有activity - * 注意:不能使用foreach遍历并发删除,会抛出java.util.ConcurrentModificationException的异常 - * - * @param activity 不需要结束的activity + * 结束指定类名的 Activity 集合 */ - public void finishOtherActivity(Activity activity) { - if (isBridge) { - mDelegate.finishOtherActivity(activity); - } else { - if (mActivityStack != null) { - for (Iterator it = mActivityStack.iterator(); it.hasNext(); ) { - Activity temp = it.next(); - if (temp != null && temp != activity) { - finishActivity(temp); + public void finishActivityCollection(@NonNull List> classList) { + if (mActivitys == null || mActivitys.isEmpty()) { + return; + } + List needFinishedActivityList = new ArrayList<>(); + for (int i = 0; i < classList.size(); i++) { + Class aClass = classList.get(i); + for (Activity activity : mActivitys) { + if (activity != null && activity.getClass().equals(aClass)) { + if (!needFinishedActivityList.contains(activity)) { + needFinishedActivityList.add(activity); } } } } + + mActivitys.removeAll(needFinishedActivityList); + for (int j = 0; j < needFinishedActivityList.size(); j++) { + Activity activity = needFinishedActivityList.get(j); + if (activity != null) { + activity.finish(); + } + } } + /** * 结束除这一类activtiy以外的所有activity * 注意:不能使用foreach遍历并发删除,会抛出java.util.ConcurrentModificationException的异常 @@ -127,105 +114,81 @@ public void finishOtherActivity(Activity activity) { * @param cls 不需要结束的activity */ public void finishOtherActivity(Class cls) { - if (isBridge) { - mDelegate.finishOtherActivity(cls); - } else { - if (mActivityStack != null) { - for (Iterator it = mActivityStack.iterator(); it.hasNext(); ) { - Activity activity = it.next(); - if (!activity.getClass().equals(cls)) { - finishActivity(activity); - } - } - } + if (mActivitys == null || mActivitys.isEmpty()) { + return; } - } + List needFinishedActivityList = new ArrayList<>(); - /** - * 结束当前Activity(堆栈中最后一个压入的) - */ - public void finishActivity() { - if (isBridge) { - mDelegate.finishActivity(); - } else { - if (mActivityStack != null && !mActivityStack.isEmpty()) { - Activity activity = mActivityStack.lastElement(); - finishActivity(activity); + for (Activity activity : mActivitys) { + if (activity != null && !activity.getClass().equals(cls)) { + if (!needFinishedActivityList.contains(activity)) { + needFinishedActivityList.add(activity); + } } } - } - - /** - * 结束指定的Activity - * - * @param activity 指定的activity实例 - */ - public void finishActivity(Activity activity) { - if (isBridge) { - mDelegate.finishActivity(activity); - } else { - if (activity != null) { - if (mActivityStack != null && mActivityStack.contains(activity)) {// 兼容未使用AppManager管理的实例 - mActivityStack.remove(activity); + if (!needFinishedActivityList.isEmpty()) { + mActivitys.removeAll(needFinishedActivityList); + for (Activity activity : needFinishedActivityList) { + if (activity != null) { + activity.finish(); } - activity.finish(); } } } /** - * 结束指定类名的所有Activity - * - * @param cls 指定的类的class + * 结束所有Activity */ - public void finishActivity(Class cls) { - if (isBridge) { - mDelegate.finishActivity(cls); - } else { - if (mActivityStack != null) { - for (Iterator it = mActivityStack.iterator(); it.hasNext(); ) { - Activity activity = it.next(); - if (activity.getClass().equals(cls)) { - finishActivity(activity); + public void finishAllActivity() { + if (mActivitys == null) { + return; + } + + List needFinishedActivityList = new ArrayList<>(); + for (int i = 0; i < mActivitys.size(); i++) { + for (Activity activity : mActivitys) { + if (activity != null) { + if (!needFinishedActivityList.contains(activity)) { + needFinishedActivityList.add(activity); } } } } + + mActivitys.removeAll(needFinishedActivityList); + for (int j = 0; j < needFinishedActivityList.size(); j++) { + Activity activity = needFinishedActivityList.get(j); + if (activity != null) { + activity.finish(); + } + } } /** - * 结束所有Activity + * 获取当前Activity(栈中最后一个压入的) */ - public void finishAllActivity() { - if (isBridge) { - mDelegate.finishAllActivity(); - } else { - if (mActivityStack != null) { - for (int i = 0, size = mActivityStack.size(); i < size; i++) { - if (null != mActivityStack.get(i)) { - mActivityStack.get(i).finish(); - } - } - mActivityStack.clear(); - } + public Activity currentActivity() { + if (mActivitys == null || mActivitys.isEmpty()) { + return null; } + return mActivitys.get(mActivitys.size() - 1); } + /** * 判断特定Activity是否被销毁 */ public boolean isDestroy(Class cls) { + if (mActivitys == null || mActivitys.isEmpty()) { + return true; + } boolean isDestroy = true; - if (isBridge) { - isDestroy = mDelegate.isDestroy(cls); - } else { - for (Activity activity : mActivityStack) { - if (activity.getClass().equals(cls)) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - isDestroy = activity.isDestroyed() || activity.isFinishing(); - } else { - isDestroy = activity.isFinishing(); - } + for (Activity activity : mActivitys) { + if (null != activity && activity.getClass().equals(cls)) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + isDestroy = activity.isDestroyed() || activity.isFinishing(); + } else { + isDestroy = activity.isFinishing(); } } } @@ -236,18 +199,14 @@ public boolean isDestroy(Class cls) { * 退出应用程序 */ public void exitApp() { - if (isBridge) { - mDelegate.exitApp(); - } else { - try { - finishAllActivity(); - // 退出JVM(java虚拟机),释放所占内存资源,0表示正常退出(非0的都为异常退出) - System.exit(0); - // 从操作系统中结束掉当前程序的进程 - android.os.Process.killProcess(android.os.Process.myPid()); - } catch (Exception e) { - e.printStackTrace(); - } + try { + finishAllActivity(); + // 退出JVM(java虚拟机),释放所占内存资源,0表示正常退出(非0的都为异常退出) + System.exit(0); + // 从操作系统中结束掉当前程序的进程 + android.os.Process.killProcess(android.os.Process.myPid()); + } catch (Exception e) { + e.printStackTrace(); } } } \ No newline at end of file diff --git a/base/src/main/java/com/heyongrui/base/assist/AppManagerDelegate.java b/base/src/main/java/com/heyongrui/base/assist/AppManagerDelegate.java deleted file mode 100644 index defbaf5..0000000 --- a/base/src/main/java/com/heyongrui/base/assist/AppManagerDelegate.java +++ /dev/null @@ -1,243 +0,0 @@ -package com.heyongrui.base.assist; - -import android.app.Activity; -import android.os.Build; - -import com.blankj.utilcode.util.LogUtils; - -import java.lang.ref.WeakReference; -import java.util.Iterator; -import java.util.Stack; - -/** - * Created by lambert on 2018/3/5. - */ - -public final class AppManagerDelegate { - - // 使用弱引用是因为存在未使用AppManager的finish方法来释放的activity,但mActivityStack并未断开对其应用导致内存泄露的问题 - private Stack> mActivityStack; - private static volatile AppManagerDelegate sInstance; - - private AppManagerDelegate() { - } - - /** - * 单例 - * - * @return 返回AppManager的单例 - */ - public static AppManagerDelegate getInstance() { - if (sInstance == null) { - synchronized (AppManagerDelegate.class) { - if (sInstance == null) { - sInstance = new AppManagerDelegate(); - } - } - } - return sInstance; - } - - /** - * 添加Activity到堆栈 - * - * @param activity activity实例 - */ - public void addActivity(Activity activity) { - if (mActivityStack == null) { - mActivityStack = new Stack<>(); - } - mActivityStack.add(new WeakReference<>(activity)); - } - - /** - * 从堆栈移除Activity - * - * @param activity activity实例 - */ - public void removeActivity(Activity activity) { - if (mActivityStack == null) { - mActivityStack = new Stack<>(); - } - mActivityStack.remove(new WeakReference<>(activity)); - } - - /** - * 检查弱引用是否释放,若释放,则从栈中清理掉该元素 - */ - public void checkWeakReference() { - if (mActivityStack != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity temp = activityReference.get(); - if (temp == null) { - it.remove();// 使用迭代器来进行安全的加锁操作 - } - } - } - } - - /** - * 获取当前Activity(栈中最后一个压入的) - * - * @return 当前(栈顶)activity - */ - public Activity currentActivity() { - checkWeakReference(); - if (mActivityStack != null && !mActivityStack.isEmpty()) { - return mActivityStack.lastElement().get(); - } - return null; - } - - /** - * 结束除当前activtiy以外的所有activity - * 注意:不能使用foreach遍历并发删除,会抛出java.util.ConcurrentModificationException的异常 - * - * @param activtiy 不需要结束的activity - */ - public void finishOtherActivity(Activity activtiy) { - if (mActivityStack != null && activtiy != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity temp = activityReference.get(); - if (temp == null) {// 清理掉已经释放的activity - it.remove(); - continue; - } - if (temp != activtiy) { - it.remove();// 使用迭代器来进行安全的加锁操作 - temp.finish(); - } - } - } - } - - /** - * 结束除这一类activtiy以外的所有activity - * - * @param cls 指定的某类activity - */ - public void finishOtherActivity(Class cls) { - if (mActivityStack != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity activity = activityReference.get(); - if (activity == null) {// 清理掉已经释放的activity - it.remove(); - continue; - } - if (!activity.getClass().equals(cls)) { - it.remove();// 使用迭代器来进行安全的加锁操作 - activity.finish(); - } - } - } - } - - /** - * 结束当前Activity(堆栈中最后一个压入的) - */ - public void finishActivity() { - Activity activity = currentActivity(); - if (activity != null) { - finishActivity(activity); - } - } - - /** - * 结束指定的Activity - * - * @param activity 指定的activity实例 - */ - public void finishActivity(Activity activity) { - if (activity != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity temp = activityReference.get(); - if (temp == null) {// 清理掉已经释放的activity - it.remove(); - continue; - } - if (temp == activity) { - it.remove(); - } - } - activity.finish(); - } - } - - /** - * 结束指定类名的所有Activity - * - * @param cls 指定的类的class - */ - public void finishActivity(Class cls) { - if (mActivityStack != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity activity = activityReference.get(); - if (activity == null) {// 清理掉已经释放的activity - it.remove(); - continue; - } - if (activity.getClass().equals(cls)) { - it.remove(); - activity.finish(); - } - } - } - } - - /** - * 结束所有Activity - */ - public void finishAllActivity() { - if (mActivityStack != null) { - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity activity = activityReference.get(); - if (activity != null) { - activity.finish(); - } - } - mActivityStack.clear(); - } - } - - /** - * 判断特定Activity是否被销毁 - * - * @param cls 指定的类的class - */ - public boolean isDestroy(Class cls) { - boolean isDestroy = true; - for (Iterator> it = mActivityStack.iterator(); it.hasNext(); ) { - WeakReference activityReference = it.next(); - Activity activity = activityReference.get(); - if (activity != null) { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { - isDestroy = activity.isDestroyed() || activity.isFinishing(); - } else { - isDestroy = activity.isFinishing(); - } - } - } - return isDestroy; - } - - /** - * 退出应用程序 - */ - public void exitApp() { - try { - finishAllActivity(); - // 退出JVM(java虚拟机),释放所占内存资源,0表示正常退出(非0的都为异常退出) - System.exit(0); - // 从操作系统中结束掉当前程序的进程 - android.os.Process.killProcess(android.os.Process.myPid()); - } catch (Exception e) { - LogUtils.e("Exit exception", e); - } - } -} \ No newline at end of file diff --git a/base/src/main/java/com/heyongrui/base/utils/DrawableUtil.java b/base/src/main/java/com/heyongrui/base/utils/DrawableUtil.java index 70ee1fa..c1346fc 100644 --- a/base/src/main/java/com/heyongrui/base/utils/DrawableUtil.java +++ b/base/src/main/java/com/heyongrui/base/utils/DrawableUtil.java @@ -128,11 +128,14 @@ public static class DrawableBuilder { @DrawableRes private int mStateListPressedRes; @DrawableRes + private int mStateListCheckRes; + @DrawableRes private int mStateListFocusedRes; @DrawableRes private int mStateListUnableRes; private Drawable mStateListNormalDrawable;//StateList private Drawable mStateListPressedDrawable;//Selector + private Drawable mStateListCheckDrawable; private Drawable mStateListFocusedDrawable; private Drawable mStateListUnableDrawable; //水波纹(5.0以上) @@ -310,6 +313,11 @@ public DrawableBuilder setStateListPressedRes(int mStateListPressedRes) { return this; } + public DrawableBuilder setStateListCheckRes(int mStateListCheckRes) { + this.mStateListCheckRes = mStateListCheckRes; + return this; + } + public DrawableBuilder setStateListFocusedRes(int mStateListFocusedRes) { this.mStateListFocusedRes = mStateListFocusedRes; return this; @@ -330,6 +338,11 @@ public DrawableBuilder setStateListPressedDrawable(Drawable mStateListPressedDra return this; } + public DrawableBuilder setStateListCheckDrawable(Drawable mStateListCheckDrawable) { + this.mStateListCheckDrawable = mStateListCheckDrawable; + return this; + } + public DrawableBuilder setStateListFocusedDrawable(Drawable mStateListFocusedDrawable) { this.mStateListFocusedDrawable = mStateListFocusedDrawable; return this; @@ -482,6 +495,9 @@ public StateListDrawable createStateListDrawable() { if (mStateListPressedDrawable == null && mContext != null && mStateListPressedRes != 0) { mStateListPressedDrawable = ContextCompat.getDrawable(mContext, mStateListPressedRes); } + if (mStateListCheckDrawable == null && mContext != null && mStateListCheckRes != 0) { + mStateListCheckDrawable = ContextCompat.getDrawable(mContext, mStateListCheckRes); + } if (mStateListFocusedDrawable == null && mContext != null && mStateListFocusedRes != 0) { mStateListFocusedDrawable = ContextCompat.getDrawable(mContext, mStateListFocusedRes); } @@ -492,6 +508,9 @@ public StateListDrawable createStateListDrawable() { if (mStateListPressedDrawable != null) { stateListDrawable.addState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}, mStateListPressedDrawable); } + if (mStateListCheckDrawable != null) { + stateListDrawable.addState(new int[]{android.R.attr.state_checked, android.R.attr.state_enabled}, mStateListCheckDrawable); + } // View.ENABLED_FOCUSED_STATE_SET if (mStateListFocusedDrawable != null) { stateListDrawable.addState(new int[]{android.R.attr.state_enabled, android.R.attr.state_focused}, mStateListFocusedDrawable); diff --git a/iflytek/.gitignore b/iflytek/.gitignore index 3c117df..0638c1a 100644 --- a/iflytek/.gitignore +++ b/iflytek/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/main/.gitignore b/main/.gitignore index 3c117df..0638c1a 100644 --- a/main/.gitignore +++ b/main/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/module/.gitignore b/module/.gitignore index 39b6783..0638c1a 100644 --- a/module/.gitignore +++ b/module/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -63,3 +88,17 @@ fastlane/Preview.html fastlane/screenshots fastlane/test_output fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/module2/.gitignore b/module2/.gitignore index 3c117df..0638c1a 100644 --- a/module2/.gitignore +++ b/module2/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/network/.gitignore b/network/.gitignore index 3c117df..0638c1a 100644 --- a/network/.gitignore +++ b/network/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file diff --git a/network/src/main/java/com/heyongrui/network/configure/FactoryException.java b/network/src/main/java/com/heyongrui/network/configure/FactoryException.java index 31c8e17..b789c80 100644 --- a/network/src/main/java/com/heyongrui/network/configure/FactoryException.java +++ b/network/src/main/java/com/heyongrui/network/configure/FactoryException.java @@ -3,11 +3,12 @@ import com.blankj.utilcode.util.NetworkUtils; import com.google.gson.JsonParseException; import com.google.gson.JsonSyntaxException; -import com.heyongrui.network.core.CodeException; import com.heyongrui.network.core.CoreApiException; import org.json.JSONException; +import org.json.JSONObject; +import java.io.IOException; import java.net.ConnectException; import java.net.SocketException; import java.net.SocketTimeoutException; @@ -20,6 +21,22 @@ public class FactoryException { + + /*网络错误*/ + public static final int NETWORD_ERROR = 504; + /*http_错误*/ + public static final int HTTP_ERROR = 400; + /*fastjson错误*/ + public static final int JSON_ERROR = 401; + /*未知错误*/ + public static final int UNKNOWN_ERROR = 500; + /*运行时异常-包含自定义异常*/ + public static final int RUNTIME_ERROR = 501; + /*无法解析该域名*/ + public static final int UNKOWNHOST_ERROR = 503; + /*超时错误*/ + public static final int TIMEOUT_ERROR = 408; + /** * 解析异常 */ @@ -27,27 +44,39 @@ public static CoreApiException analysisExcetpion(Throwable e) { e.printStackTrace(); CoreApiException apiException; if (!NetworkUtils.isAvailableByPing()) {//无网络 - apiException = new CoreApiException(e, CodeException.NETWORD_ERROR, "无网络连接"); + apiException = new CoreApiException(e, NETWORD_ERROR, "无网络连接"); return apiException; } if (e instanceof CoreApiException) { apiException = (CoreApiException) e; } else if (e instanceof HttpException) { - apiException = new CoreApiException(e, CodeException.TIMEOUT_ERROR, "网络错误"); + try { + String errorBody = ((HttpException) e).response().errorBody().string(); + JSONObject jsonObject = new JSONObject(errorBody); + int status = jsonObject.getInt("status"); + String info = jsonObject.getString("info"); + apiException = new CoreApiException(status, info); + } catch (IOException ex) { + ex.printStackTrace(); + apiException = new CoreApiException(e, TIMEOUT_ERROR, "网络错误"); + } catch (JSONException ex) { + ex.printStackTrace(); + apiException = new CoreApiException(e, TIMEOUT_ERROR, "解析错误"); + } } else if (e instanceof UnknownHostException) { //主机挂了,也就是你服务器关了 - apiException = new CoreApiException(e, CodeException.UNKOWNHOST_ERROR, "服务异常"); + apiException = new CoreApiException(e, UNKOWNHOST_ERROR, "服务异常"); } else if (e instanceof ConnectException || e instanceof SocketTimeoutException || e instanceof TimeoutException || e instanceof SocketException) { //连接超时等 - apiException = new CoreApiException(e, CodeException.TIMEOUT_ERROR, "连接失败"); + apiException = new CoreApiException(e, TIMEOUT_ERROR, "连接失败"); } else if (e instanceof NumberFormatException || e instanceof IllegalArgumentException || e instanceof JsonSyntaxException || e instanceof JsonParseException || e instanceof JSONException || e instanceof ParseException) { - apiException = new CoreApiException(e, CodeException.JSON_ERROR, "解析错误"); + apiException = new CoreApiException(e, JSON_ERROR, "解析错误"); } else { //其他未知 HttpException RuntimeException等 - apiException = new CoreApiException(e, CodeException.UNKNOWN_ERROR, "未知错误"); + apiException = new CoreApiException(e, UNKNOWN_ERROR, "未知错误"); } return apiException; } diff --git a/network/src/main/java/com/heyongrui/network/core/CodeException.java b/network/src/main/java/com/heyongrui/network/core/CodeException.java deleted file mode 100644 index 38d82f0..0000000 --- a/network/src/main/java/com/heyongrui/network/core/CodeException.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.heyongrui.network.core; - -/** - * 自定义错误code类型:注解写法 - *

- * 可自由扩展 - * Created by WZG on 2016/12/12. - */ - -public class CodeException { - - /*网络错误*/ - public static final int NETWORD_ERROR = 504; - /*http_错误*/ - public static final int HTTP_ERROR = 400; - /*fastjson错误*/ - public static final int JSON_ERROR = 401; - /*未知错误*/ - public static final int UNKNOWN_ERROR = 500; - /*运行时异常-包含自定义异常*/ - public static final int RUNTIME_ERROR = 501; - /*无法解析该域名*/ - public static final int UNKOWNHOST_ERROR = 503; - /*超时错误*/ - public static final int TIMEOUT_ERROR = 408; - -} diff --git a/user/.gitignore b/user/.gitignore index 3c117df..0638c1a 100644 --- a/user/.gitignore +++ b/user/.gitignore @@ -1,6 +1,8 @@ +### Android ### # Built application files *.apk *.ap_ +*.aab # Files for the ART/Dalvik VM *.dex @@ -12,6 +14,7 @@ bin/ gen/ out/ +release/ # Gradle files .gradle/ @@ -32,25 +35,47 @@ proguard/ # Android Studio captures folder captures/ +/local.properties +.DS_Store +.DS_Store? +._* +/build +/captures + # IntelliJ *.iml +.idea .idea/workspace.xml .idea/tasks.xml .idea/gradle.xml +.idea/misc.xml +.idea/compiler.xml .idea/assetWizardSettings.xml +.idea/copyright/profiles_settings.xml +.idea/encodings.xml +.idea/scopes/scope_settings.xml .idea/dictionaries .idea/libraries +.idea/vcs.xml +# Android Studio 3 in .gitignore file. .idea/caches +.idea/modules.xml +# Comment next line if keeping position of elements in Navigation Editor is relevant for you +.idea/navEditor.xml + +# Signing files +.signing/ # Keystore files -# Uncomment the following line if you do not want to check your keystore files in. +# Uncomment the following lines if you do not want to check your keystore files in. #*.jks +#*.keystore # External native build folder generated in Android Studio 2.2 and later .externalNativeBuild # Google Services (e.g. APIs or Firebase) -google-services.json +# google-services.json # Freeline freeline.py @@ -62,4 +87,18 @@ fastlane/report.xml fastlane/Preview.html fastlane/screenshots fastlane/test_output -fastlane/readme.md \ No newline at end of file +fastlane/readme.md + +# Version control +vcs.xml + +# lint +lint/intermediates/ +lint/generated/ +lint/outputs/ +lint/tmp/ +# lint/reports/ + +### Android Patch ### +gen-external-apklibs +output.json \ No newline at end of file