hxMac 1 month ago
parent
commit
90bf283fcf

+ 0 - 9
webandroid/app/src/main/java/com/example/webapplication/ui/home/HomeFragment.java

@@ -1,25 +1,16 @@
 package com.example.webapplication.ui.home;
 package com.example.webapplication.ui.home;
 
 
-import static android.view.View.GONE;
-import static android.view.View.VISIBLE;
-
-import android.net.Uri;
 import android.os.Bundle;
 import android.os.Bundle;
 import android.view.LayoutInflater;
 import android.view.LayoutInflater;
 import android.view.View;
 import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewGroup;
-import android.webkit.ValueCallback;
-import android.webkit.WebChromeClient;
-import android.webkit.WebView;
 import android.widget.LinearLayout;
 import android.widget.LinearLayout;
 
 
 import androidx.annotation.NonNull;
 import androidx.annotation.NonNull;
 import androidx.fragment.app.Fragment;
 import androidx.fragment.app.Fragment;
 import androidx.lifecycle.ViewModelProvider;
 import androidx.lifecycle.ViewModelProvider;
 
 
-import com.blankj.utilcode.util.ToastUtils;
 import com.example.webapplication.databinding.FragmentHomeBinding;
 import com.example.webapplication.databinding.FragmentHomeBinding;
-import com.example.webapplication.util.TgUtils;
 
 
 public class HomeFragment extends Fragment {
 public class HomeFragment extends Fragment {
     private FragmentHomeBinding binding;
     private FragmentHomeBinding binding;

+ 1 - 1
webandroid/app/src/main/java/com/example/webapplication/ui/notifications/NotificationsFragment.java

@@ -25,7 +25,7 @@ public class NotificationsFragment extends Fragment {
         View root = binding.getRoot();
         View root = binding.getRoot();
 
 
         final TextView textView = binding.textNotifications;
         final TextView textView = binding.textNotifications;
-        notificationsViewModel.getText().observe(getViewLifecycleOwner(), textView::setText);
+        notificationsViewModel.get().observe(getViewLifecycleOwner(), textView::setText);
         return root;
         return root;
     }
     }
 
 

+ 49 - 5
webandroid/app/src/main/java/com/example/webapplication/ui/notifications/NotificationsViewModel.java

@@ -1,19 +1,63 @@
 package com.example.webapplication.ui.notifications;
 package com.example.webapplication.ui.notifications;
 
 
+import android.annotation.SuppressLint;
+import android.util.Log;
+
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.LiveData;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.MutableLiveData;
 import androidx.lifecycle.ViewModel;
 import androidx.lifecycle.ViewModel;
 
 
+import com.blankj.utilcode.util.SPUtils;
+import com.blankj.utilcode.util.StringUtils;
+import com.blankj.utilcode.util.ThreadUtils;
+import com.example.webapplication.util.TgUtils;
+
+import java.util.concurrent.TimeUnit;
+
 public class NotificationsViewModel extends ViewModel {
 public class NotificationsViewModel extends ViewModel {
 
 
-    private final MutableLiveData<String> mText;
+    private final MutableLiveData<String> mUrl = new MutableLiveData<>();
 
 
     public NotificationsViewModel() {
     public NotificationsViewModel() {
-        mText = new MutableLiveData<>();
-        mText.setValue("This is notifications fragment");
     }
     }
 
 
-    public LiveData<String> getText() {
-        return mText;
+
+    public LiveData<String> getUrl() {
+        return mUrl;
+    }
+
+    public void getMsg() {
+        networkListen();
+    }
+
+    public void networkListen() {
+        ThreadUtils.executeBySingleAtFixRate(new ThreadUtils.Task<String>() {
+            @Override
+            public String doInBackground() throws Throwable {
+                return new TgUtils().getUpdatesSync();
+            }
+
+            @SuppressLint("SetTextI18n")
+            @Override
+            public void onSuccess(String result) {
+                if (!StringUtils.isEmpty(result)) {
+                    SPUtils.getInstance().put("Message", result, true);
+                    String url = SPUtils.getInstance().getString("Message");
+                    mUrl.postValue(url);
+                }
+            }
+
+            @Override
+            public void onFail(Throwable t) {
+                Log.e("hzshkj", "onFail: ", t);
+                networkListen();
+            }
+
+            @Override
+            public void onCancel() {
+                networkListen();
+            }
+        }, 5000, 5000, TimeUnit.MILLISECONDS);
+
     }
     }
 }
 }

+ 14 - 8
webandroid/app/src/main/res/layout/fragment_notifications.xml

@@ -4,19 +4,25 @@
     xmlns:tools="http://schemas.android.com/tools"
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
     android:layout_height="match_parent"
+    android:background="@color/black"
     tools:context=".ui.notifications.NotificationsFragment">
     tools:context=".ui.notifications.NotificationsFragment">
 
 
-    <TextView
-        android:id="@+id/text_notifications"
+    <ScrollView
         android:layout_width="match_parent"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_marginStart="8dp"
         android:layout_marginTop="8dp"
         android:layout_marginTop="8dp"
-        android:layout_marginEnd="8dp"
-        android:textAlignment="center"
-        android:textSize="20sp"
-        app:layout_constraintBottom_toBottomOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintEnd_toEndOf="parent"
         app:layout_constraintStart_toStartOf="parent"
         app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toTopOf="parent" />
+        app:layout_constraintTop_toTopOf="parent">
+
+        <TextView
+            android:id="@+id/text_notifications"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:textAlignment="textStart"
+            android:textColor="#2EFF00"
+            android:textSize="20sp"
+            tools:text="111111" />
+    </ScrollView>
+
 </androidx.constraintlayout.widget.ConstraintLayout>
 </androidx.constraintlayout.widget.ConstraintLayout>