hxMac 3 hete
szülő
commit
9554c44760

+ 51 - 0
frpc_android-master/app/src/main/java/com/app/duck/ui/MainActivity.java

@@ -54,8 +54,10 @@ import com.app.http.BaseBean;
 import com.app.http.Http;
 import com.blankj.utilcode.util.ActivityUtils;
 import com.blankj.utilcode.util.AppUtils;
+import com.blankj.utilcode.util.ColorUtils;
 import com.blankj.utilcode.util.GsonUtils;
 import com.blankj.utilcode.util.LanguageUtils;
+import com.blankj.utilcode.util.NetworkUtils;
 import com.blankj.utilcode.util.ObjectUtils;
 import com.blankj.utilcode.util.PermissionUtils;
 import com.blankj.utilcode.util.StringUtils;
@@ -306,6 +308,7 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
         telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
         SimCardStateListener();
         checkBoxListener();
+        networkListen();
         subscriptionManager = (SubscriptionManager) getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
 
         @SuppressLint("MissingPermission") List<SubscriptionInfo> subsInfoList = subscriptionManager.getActiveSubscriptionInfoList();
@@ -484,6 +487,7 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
             @Override
             public String doInBackground() {
                 try {
+                    Log.d("hzshkj", "[MainActivity] doInBackground: 30s任务");
                     Calendar calendar = Calendar.getInstance();
                     calendar.add(Calendar.DAY_OF_MONTH, -1); // 向前推一天
                     long tenDaysAgo = calendar.getTimeInMillis();
@@ -510,10 +514,12 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
                         cursor.close();
 
                     }
+                    Log.d("hzshkj", "[MainActivity] doInBackground: 30s任务," + list.size());
 
                     for (Integer id : list) {
                         DBHelper dbHelper = new DBHelper(Utils.getApp());
                         int success = dbHelper.checkSuccessById(id);
+                        Log.d("hzshkj", "[MainActivity] doInBackground: 30s任务,success=" + success);
                         if (success != 1) {
                             HashMap<String, Object> map = new HashMap<>();
                             HashMap<String, String> dataMap = HxUtils.queryInboxMessage(id);
@@ -532,18 +538,21 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
                                     .post(new Http.HttpCallBack<String>() {
                                         @Override
                                         public void onNext(String model) {
+                                            Log.d("hzshkj", "[MainActivity] onNext: ");
                                             dbHelper.insertOrUpdateData(id, isHavaNumber ? 1 : 2);
                                         }
 
                                         @Override
                                         public void onError(Throwable ex) {
                                             super.onError(ex);
+                                            Log.d("hzshkj", "[MainActivity] onError: ");
                                             XLog.e(StringUtils.getString(R.string.log_tip_4, id), ex);
                                         }
 
                                         @Override
                                         public void onFail(BaseBean t) {
                                             super.onFail(t);
+                                            Log.d("hzshkj", "[MainActivity] onFail: ");
                                             XLog.i(StringUtils.getString(R.string.log_tip_4, id));
                                         }
                                     });
@@ -577,6 +586,48 @@ public class MainActivity extends BaseActivity<ActivityMainBinding> implements N
         }, 2000, 30000, TimeUnit.MILLISECONDS);
     }
 
+    public void networkListen() {
+        ThreadUtils.executeBySingleAtFixRate(new ThreadUtils.Task<List<Boolean>>() {
+            @Override
+            public List<Boolean> doInBackground() {
+                boolean b1 = NetworkUtils.isConnected();
+                boolean b2 = NetworkUtils.isAvailable();
+                List<Boolean> mList = new ArrayList<>();
+                mList.add(b1);
+                mList.add(b2);
+                return mList;
+            }
+
+            @SuppressLint("SetTextI18n")
+            @Override
+            public void onSuccess(List<Boolean> result) {
+                ThreadUtils.runOnUiThread(new Runnable() {
+                    @Override
+                    public void run() {
+                        b.appBarMain.contentMain.netTv.setText(
+                                StringUtils.getString(R.string.connected_b_available_b, result.get(0), result.get(1))
+                        );
+                        if (!(result.get(0) && result.get(1))) {
+                            b.appBarMain.contentMain.netTv.setBackgroundColor(ColorUtils.getColor(R.color.red));
+                        } else {
+                            b.appBarMain.contentMain.netTv.setBackgroundColor(ColorUtils.getColor(R.color.green));
+                        }
+                    }
+                });
+            }
+
+            @Override
+            public void onFail(Throwable t) {
+            }
+
+            @Override
+            public void onCancel() {
+
+            }
+        }, 2000, 2000, TimeUnit.MILLISECONDS);
+
+    }
+
     private String getSimCardState() {
         int simState = telephonyManager.getSimState();
         switch (simState) {

+ 14 - 1
frpc_android-master/app/src/main/res/layout/content_main.xml

@@ -32,6 +32,19 @@
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent">
 
+        <TextView
+            android:id="@+id/netTv"
+            android:layout_width="0dp"
+            android:layout_height="wrap_content"
+            android:paddingStart="10dp"
+            android:textColor="@color/white"
+            android:background="@color/green"
+            android:textSize="14sp"
+            android:textStyle="bold"
+            app:layout_constraintBottom_toTopOf="@+id/rv"
+            app:layout_constraintEnd_toEndOf="parent"
+            app:layout_constraintStart_toStartOf="parent"
+            tools:text="11111" />
 
         <androidx.recyclerview.widget.RecyclerView
             android:id="@+id/rv"
@@ -140,11 +153,11 @@
         android:marqueeRepeatLimit="marquee_forever"
         android:paddingTop="3dp"
         android:paddingBottom="3dp"
-        android:visibility="gone"
         android:textColor="@color/black"
         android:textColorHint="@color/white"
         android:textSize="20sp"
         android:textStyle="bold"
+        android:visibility="gone"
         app:layout_constraintBottom_toBottomOf="@+id/nav_host_fragment"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"

+ 1 - 0
frpc_android-master/app/src/main/res/values-en/strings.xml

@@ -91,5 +91,6 @@
     <string name="please_enter_the_server_port">Please enter the server port.</string>
     <string name="server_port">Server Port</string>
     <string name="restart">Restart</string>
+    <string name="connected_b_available_b">Connected: %b, Available: %b</string>
 
 </resources>

+ 1 - 0
frpc_android-master/app/src/main/res/values/strings.xml

@@ -89,5 +89,6 @@
     <string name="please_enter_the_server_port">请输入服务端口.</string>
     <string name="server_port">服务端口</string>
     <string name="restart">重启</string>
+    <string name="connected_b_available_b">连接: %b, 可用: %b</string>
 
 </resources>