Kaynağa Gözat

判空之前

詹子聪 5 yıl önce
ebeveyn
işleme
b1da66c4e5

+ 5 - 8
app/build.gradle

@@ -1,5 +1,5 @@
 apply plugin: 'com.android.application'
-//apply plugin: 'com.hujiang.android-aspectjx'
+apply plugin: 'com.hujiang.android-aspectjx'
 
 
 android {
@@ -31,12 +31,9 @@ dependencies {
     implementation project(path: ':common')
     implementation project(path: ':mvp')
 
-    // 查看内存泄露
-    debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.1'
-
-//    compile 'org.aspectj:aspectjrt:1.8.+'
+    compile 'org.aspectj:aspectjrt:1.8.+'
 }
 
-//aspectjx {
-//    exclude  "android.support",'androidx','com.google','com.squareup.leakcanary','com.squareup.leakcanary.core','com.alipay','org.apache','com.tencent'
-//}
+aspectjx {
+    exclude  "android.support",'androidx','com.google','com.squareup.leakcanary','com.squareup.leakcanary.core','com.alipay','org.apache','com.tencent'
+}

+ 1 - 1
app/src/main/java/com/miekir/newmvp/LoadingAspect.java

@@ -1,4 +1,4 @@
-package com.miekir.newmvp;
+package com.miekir.aspectj;
 
 //import android.util.Log;
 //

+ 6 - 10
app/src/main/java/com/miekir/newmvp/MainActivity.java

@@ -24,24 +24,20 @@ public class MainActivity extends BaseMvpActivity implements View.OnClickListene
         TextView tv_name = findViewById(R.id.tv_name);
         tv_name.setText("MainActivity");
 
-        findViewById(R.id.view_test).setOnClickListener(this);
-
-        findViewById(R.id.btn_test).setOnClickListener(new View.OnClickListener() {
-            @Override
-            public void onClick(View view) {
-            // 点击之后,后台执行耗时操作
-            startActivity(new Intent(MainActivity.this, MainActivity.class));
-            }
-        });
+        findViewById(R.id.btn_task).setOnClickListener(this);
+        findViewById(R.id.btn_jump).setOnClickListener(this);
     }
 
     @Override
     public void onClick(View v) {
         switch (v.getId()) {
-            case R.id.view_test:
+            case R.id.btn_task:
                 // 点击之后,后台执行耗时操作
                 presenter.doWork();
                 break;
+            case R.id.btn_jump:
+                startActivity(new Intent(MainActivity.this, MainActivity.class));
+                break;
             default:
                 break;
         }

+ 2 - 2
app/src/main/res/layout/activity_main.xml

@@ -15,14 +15,14 @@
         android:layout_marginTop="16dp"/>
 
     <Button
-        android:id="@+id/btn_test"
+        android:id="@+id/btn_jump"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="跳到下一个界面"
         android:layout_marginBottom="16dp"/>
 
     <Button
-        android:id="@+id/view_test"
+        android:id="@+id/btn_task"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="耗时任务"

+ 1 - 1
build.gradle

@@ -8,7 +8,7 @@ buildscript {
     }
     dependencies {
         classpath 'com.android.tools.build:gradle:3.6.1'
-//        classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
+        classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:2.0.10'
     }
 }
 

+ 3 - 0
common/build.gradle

@@ -62,6 +62,9 @@ dependencies {
     api 'com.github.bumptech.glide:glide:4.11.0'
     annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
 
+    // guava
+    api("com.google.guava:guava:30.0-android")
+
     // 适配器
     //api 'com.github.CymChad:BaseRecyclerViewAdapterHelper:2.9.50'
 }

+ 25 - 0
common/src/main/java/com/miekir/common/utils/LogTool.java

@@ -0,0 +1,25 @@
+package com.miekir.common.utils;
+
+import android.util.Log;
+
+import com.miekir.common.BuildConfig;
+
+/**
+ * Copyright (C), 2019-2020, Miekir
+ *
+ * @author Miekir
+ * @date 2020/11/19 9:19
+ * Description:
+ * todo 完善
+ */
+public class LogTool {
+    private static final int RETURN_DEFAULT = -1;
+    private LogTool() {}
+
+    public static int d(String tag, String message) {
+        if (BuildConfig.IS_DEBUG) {
+            return Log.d(tag, message);
+        }
+        return RETURN_DEFAULT;
+    }
+}

+ 5 - 3
mvp/build.gradle

@@ -25,13 +25,15 @@ android {
 }
 
 dependencies {
-    implementation fileTree(dir: 'libs', include: ['*.jar'])
-
-    compile 'androidx.appcompat:appcompat:1.3.0-alpha02'
     testImplementation 'junit:junit:4.12'
     androidTestImplementation 'androidx.test.ext:junit:1.1.1'
     androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
 
+    implementation fileTree(dir: 'libs', include: ['*.jar'])
+    implementation project(path: ':common')
+
+    compile 'androidx.appcompat:appcompat:1.3.0-alpha02'
+
     def lifecycle_version = "2.2.0"
     //implementation "androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version"
     implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$lifecycle_version"

+ 0 - 18
mvp/src/main/java/com/miekir/mvp/model/DataMethod.java

@@ -1,18 +0,0 @@
-package com.miekir.mvp.model;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- *
- * @author zicong
- * @description 方法回调标记
- * @date 2019/8/19
- */
-@Retention(RetentionPolicy.RUNTIME)
-@Target(ElementType.METHOD)
-public @interface DataMethod {
-    int dataSource() default DataSource.DEFAULT;
-}

+ 0 - 16
mvp/src/main/java/com/miekir/mvp/model/DataSource.java

@@ -1,16 +0,0 @@
-package com.miekir.mvp.model;
-
-/**
- * Copyright (C), 2019-2020, Miekir
- *
- * @author Miekir
- * @date 2020/10/30 9:00
- * Description: 用于区分数据来源。如一个界面上有两个列表,左边是展示本地数据库的数据,右边是展示远程数据库的数据,数据类型一样,
- * 此时有必要区分来源。
- */
-public interface DataSource {
-    int DEFAULT = 0;
-    int INTERNET = 1;
-    int DATABASE = 2;
-    int FILE = 3;
-}

+ 6 - 4
mvp/src/main/java/com/miekir/mvp/presenter/BasePresenter.java

@@ -1,9 +1,8 @@
 package com.miekir.mvp.presenter;
 
-import android.util.Log;
-
 import androidx.lifecycle.ViewModel;
 
+import com.miekir.common.utils.LogTool;
 import com.miekir.mvp.view.IView;
 
 import java.lang.ref.WeakReference;
@@ -14,6 +13,10 @@ import java.lang.ref.WeakReference;
  * @author Miekir
  * @date 2020/10/7 22:46
  * Description:
+ *
+ * View (strong)-> Presenter (strong)-> Model (strong)-> Repository
+ * View <-(weak) Presenter <-(weak) Model <-(weak) Repository
+
  */
 public abstract class BasePresenter<V extends IView> extends ViewModel {
     private WeakReference<V> wrf;
@@ -30,8 +33,7 @@ public abstract class BasePresenter<V extends IView> extends ViewModel {
     protected void onCleared() {
         super.onCleared();
         detachView();
-        // todo
-        Log.d(getClass().getName(), "view model clear:" + this.toString());
+        LogTool.d(getClass().getName(), "view model clear:" + this.toString());
     }
 
     /**

+ 4 - 3
network/build.gradle

@@ -50,14 +50,15 @@ android {
 }
 
 dependencies {
+    testImplementation 'junit:junit:4.12'
+    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
+    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
+
     api project(path: ':mvp')
     implementation project(path: ':common')
     implementation fileTree(dir: 'libs', include: ['*.jar'])
 
     implementation 'androidx.appcompat:appcompat:1.3.0-alpha02'
-    testImplementation 'junit:junit:4.12'
-    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
-    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
 
     // 使用 retrofit + rx + gson 实现网络请求与解析start---->
     // 导入 retrofit