删除首页开启推送通知提醒功能
This commit is contained in:
@@ -56,7 +56,6 @@ import com.chwl.app.home.fragment.MeFragment;
|
||||
import com.chwl.app.home.presenter.MainPresenter;
|
||||
import com.chwl.app.home.view.IMainView;
|
||||
import com.chwl.app.home.widget.AnchorCardView;
|
||||
import com.chwl.app.main.helper.NoticationsUiHelper;
|
||||
import com.chwl.app.module.Extras;
|
||||
import com.chwl.app.module_hall.secretcode.PwdCodeMgr;
|
||||
import com.chwl.app.service.DaemonService;
|
||||
@@ -110,7 +109,6 @@ import com.chwl.core.utils.SharedPreferenceUtils;
|
||||
import com.chwl.core.utils.StringFormatUtils;
|
||||
import com.chwl.library.base.factory.CreatePresenter;
|
||||
import com.chwl.library.threadmgr.ThreadPoolManager;
|
||||
import com.chwl.library.utils.JavaUtil;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
@@ -688,9 +686,6 @@ public class MainActivity extends BaseMvpActivity<IMainView, MainPresenter>
|
||||
//青少年弹窗处理
|
||||
PmDialogShowMrg.get().handle(new WeakReference<>(this));
|
||||
|
||||
//通知栏权限判断
|
||||
NoticationsUiHelper.handle(this, getDialogManager());
|
||||
|
||||
handleChannelPageInfo();
|
||||
|
||||
checkProtocolUpdate();
|
||||
|
@@ -1,118 +0,0 @@
|
||||
package com.chwl.app.main.helper;
|
||||
|
||||
import static android.Manifest.permission.POST_NOTIFICATIONS;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import com.chwl.app.R;
|
||||
import com.chwl.app.common.widget.dialog.DialogManager;
|
||||
import com.chwl.app.utils.NotificationsUtils;
|
||||
import com.chwl.core.utils.SharedPreferenceUtils;
|
||||
import com.chwl.core.utils.net.DontWarnObserver;
|
||||
import com.chwl.core.utils.net.RxHelper;
|
||||
import com.chwl.library.utils.ResUtil;
|
||||
import com.chwl.library.utils.TimeUtils;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import io.reactivex.SingleEmitter;
|
||||
import io.reactivex.SingleOnSubscribe;
|
||||
import io.reactivex.SingleSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
/**
|
||||
* 通知栏ui处理逻辑
|
||||
* Created by lvzebiao on 2020/3/16.
|
||||
*/
|
||||
public class NoticationsUiHelper {
|
||||
|
||||
/**
|
||||
* 用于处理,用户关闭通知栏时,每N天,弹一次
|
||||
*/
|
||||
private static final String KEY_NOTICATIONS_DIALOG_TIME = "notications_dialog_time";
|
||||
|
||||
private static final long CACHE_DISTANCE_TIME = 3 * TimeUtils.MILLIS_OF_A_DAY;
|
||||
|
||||
public static void handle(Activity activity, DialogManager dialogManager) {
|
||||
if (Build.VERSION.SDK_INT >= 33) {
|
||||
if (ActivityCompat.checkSelfPermission(activity, POST_NOTIFICATIONS) == PackageManager.PERMISSION_DENIED) {
|
||||
if (!ActivityCompat.shouldShowRequestPermissionRationale(activity, POST_NOTIFICATIONS)) {
|
||||
enableNotification(activity, dialogManager);
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(activity, new String[]{POST_NOTIFICATIONS}, 100);
|
||||
}
|
||||
}
|
||||
} else if (NotificationsUtils.isNotificationEnabled(activity)) {
|
||||
return;
|
||||
}
|
||||
enableNotification(activity, dialogManager);
|
||||
}
|
||||
|
||||
private static void enableNotification(Activity activity, DialogManager dialogManager) {
|
||||
Single.create(new SingleOnSubscribe<String>() {
|
||||
@Override
|
||||
public void subscribe(SingleEmitter<String> emitter) throws Exception {
|
||||
long lastDialogTime = (long) SharedPreferenceUtils
|
||||
.get(KEY_NOTICATIONS_DIALOG_TIME, 0L);
|
||||
long currTime = System.currentTimeMillis();
|
||||
if (lastDialogTime == 0L || currTime - lastDialogTime >= CACHE_DISTANCE_TIME) {
|
||||
//超过三天需要重新弹窗
|
||||
emitter.onSuccess("");
|
||||
return;
|
||||
}
|
||||
emitter.onError(new Throwable("no need to show notications dialog"));
|
||||
}
|
||||
})
|
||||
.flatMap(new Function<String, SingleSource<String>>() {
|
||||
@Override
|
||||
public SingleSource<String> apply(String s) throws Exception {
|
||||
return Single.just(s).delay(60, TimeUnit.SECONDS);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.compose(RxHelper.bindContext(activity))
|
||||
.subscribe(new DontWarnObserver<String>() {
|
||||
@Override
|
||||
public void accept(String s, String error) {
|
||||
super.accept(s, error);
|
||||
if (error != null) {
|
||||
return;
|
||||
}
|
||||
if (NotificationsUtils.isNotificationEnabled(activity)) {
|
||||
return;
|
||||
}
|
||||
DialogManager tempDialogManager = dialogManager;
|
||||
if (tempDialogManager == null) {
|
||||
tempDialogManager = new DialogManager(activity);
|
||||
}
|
||||
SharedPreferenceUtils.put(KEY_NOTICATIONS_DIALOG_TIME, System.currentTimeMillis());
|
||||
tempDialogManager.showOkCancelDialog(
|
||||
ResUtil.getString(R.string.main_helper_noticationsuihelper_01),
|
||||
ResUtil.getString(R.string.main_helper_noticationsuihelper_02),
|
||||
ResUtil.getString(R.string.main_helper_noticationsuihelper_03),
|
||||
ResUtil.getString(R.string.main_helper_noticationsuihelper_04),
|
||||
new DialogManager.OkCancelDialogListener() {
|
||||
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onOk() {
|
||||
NotificationsUtils.openPush(activity);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user