|
@@ -3,12 +3,9 @@ package com.example.webapplication.ui.notifications;
|
|
|
import android.annotation.SuppressLint;
|
|
|
import android.util.Log;
|
|
|
|
|
|
-import androidx.lifecycle.LiveData;
|
|
|
import androidx.lifecycle.MutableLiveData;
|
|
|
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;
|
|
|
|
|
@@ -16,19 +13,14 @@ import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
public class NotificationsViewModel extends ViewModel {
|
|
|
|
|
|
- private final MutableLiveData<String> mUrl = new MutableLiveData<>();
|
|
|
+ private final MutableLiveData<Boolean> success = new MutableLiveData<>();
|
|
|
|
|
|
- public NotificationsViewModel() {
|
|
|
+ public MutableLiveData<String> getError() {
|
|
|
+ return error;
|
|
|
}
|
|
|
|
|
|
+ private final MutableLiveData<String> error = new MutableLiveData<>();
|
|
|
|
|
|
- public LiveData<String> getUrl() {
|
|
|
- return mUrl;
|
|
|
- }
|
|
|
-
|
|
|
- public void getMsg() {
|
|
|
- networkListen();
|
|
|
- }
|
|
|
|
|
|
public void networkListen() {
|
|
|
ThreadUtils.executeBySingleAtFixRate(new ThreadUtils.Task<String>() {
|
|
@@ -40,24 +32,30 @@ public class NotificationsViewModel extends ViewModel {
|
|
|
@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);
|
|
|
- }
|
|
|
+ Log.d("hzshkj", "[NotificationsViewModel] onSuccess: "+result);
|
|
|
+ error.postValue(result);
|
|
|
+ success.postValue(true);
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onFail(Throwable t) {
|
|
|
- Log.e("hzshkj", "onFail: ", t);
|
|
|
+ Log.d("hzshkj", "[NotificationsViewModel] onFail: "+t.getMessage());
|
|
|
+ success.postValue(false);
|
|
|
+ error.postValue(t.getMessage());
|
|
|
networkListen();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public void onCancel() {
|
|
|
+ success.postValue(false);
|
|
|
+ error.postValue("Task is cancel.");
|
|
|
networkListen();
|
|
|
}
|
|
|
- }, 5000, 5000, TimeUnit.MILLISECONDS);
|
|
|
+ }, 100, 10000, TimeUnit.MILLISECONDS);
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
+ public MutableLiveData<Boolean> getSuccess() {
|
|
|
+ return success;
|
|
|
}
|
|
|
}
|