通知提醒设置新增个播开播通知设置

This commit is contained in:
huangjian
2022-07-18 15:27:11 +08:00
parent 1cfdd1e5a0
commit bd0a210804
4 changed files with 82 additions and 25 deletions

View File

@@ -1,5 +1,6 @@
package com.yizhuan.erban.ui.setting; package com.yizhuan.erban.ui.setting;
import android.annotation.SuppressLint;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
@@ -30,6 +31,12 @@ public class NoticeSettingActivity extends BaseActivity {
@BindView(R.id.ll_container) @BindView(R.id.ll_container)
LinearLayout llContainer; LinearLayout llContainer;
private View systemNoticeView;
private TutuSwitchView switchSystemNotice;
private boolean notifyMsg = false;
private View attentionNoticeView;
private TutuSwitchView switchAttentionNotice;
private boolean notifyAttention = false;
public static void start(Context context) { public static void start(Context context) {
StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_SETTING_NOTICE, StatisticManager.Instance().onEvent(StatisticsProtocol.EVENT_SETTING_NOTICE,
@@ -38,11 +45,7 @@ public class NoticeSettingActivity extends BaseActivity {
context.startActivity(intent); context.startActivity(intent);
} }
private View systemNoticeView; @SuppressLint("CheckResult")
private TutuSwitchView switchSystemNotice;
private boolean notifyMsg = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -53,8 +56,12 @@ public class NoticeSettingActivity extends BaseActivity {
SettingsModel.get().getSysMsgNotify() SettingsModel.get().getSysMsgNotify()
.compose(bindUntilEvent(ActivityEvent.DESTROY)) .compose(bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(result -> { .subscribe(result -> {
notifyMsg = result.isSysMsgNotify(); notifyMsg = result.isSysMsgNotify();
initSystemNotice(); initSystemNotice();
notifyAttention = result.isSingleBroadcastMsgNotify();
initAttentionNotice();
}); });
} }
@@ -96,6 +103,40 @@ public class NoticeSettingActivity extends BaseActivity {
} }
private void initAttentionNotice() {
if (attentionNoticeView == null) {
attentionNoticeView = LayoutInflater.from(context).inflate(R.layout.item_system_notice, null);
switchAttentionNotice = attentionNoticeView.findViewById(R.id.switch_notice);
llContainer.addView(attentionNoticeView, new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
getResources().getDimensionPixelOffset(R.dimen.dp_setting_sys_notice_item_height))
);
setName(attentionNoticeView, "开播通知");
setDesc(attentionNoticeView, "关闭后,官方小秘书不再提示您关注主播的开播情况");
}
switchAttentionNotice.setOn(notifyAttention);
switchAttentionNotice.setOnSwitchStateChangeListener(new IOSSwitchView.OnSwitchStateChangeListener() {
@Override
public void onStateSwitched(boolean isOn) {
SettingsModel.get().setAttentionMsgNotify(isOn)
.compose(bindUntilEvent(ActivityEvent.DESTROY))
.subscribe(new DontWarnObserver<String>() {
@Override
public void accept(String s, String error) {
super.accept(s, error);
if (error == null) {
notifyAttention = isOn;
} else {
toast(error);
}
}
});
}
});
}
private void setName(View targetView, String name) { private void setName(View targetView, String name) {
if (targetView == null) { if (targetView == null) {
return; return;

View File

@@ -25,6 +25,8 @@ public interface ISettingsModel extends IModel {
Single<String> setSysMsgNotify(boolean sysMsgNotify); Single<String> setSysMsgNotify(boolean sysMsgNotify);
Single<String> setAttentionMsgNotify(boolean attentionMsgNotify);
Single<SysAccount> getSysAccount(); Single<SysAccount> getSysAccount();
Single<String> interactiveMsgNotify(boolean interactiveMsgNotify); Single<String> interactiveMsgNotify(boolean interactiveMsgNotify);

View File

@@ -28,6 +28,10 @@ public class SettingsModel implements ISettingsModel {
private static SettingsModel instance; private static SettingsModel instance;
private final Api api; private final Api api;
private SettingsModel() {
api = RxNet.create(Api.class);
}
public static ISettingsModel get() { public static ISettingsModel get() {
if (instance == null) { if (instance == null) {
synchronized (SettingsModel.class) { synchronized (SettingsModel.class) {
@@ -39,10 +43,6 @@ public class SettingsModel implements ISettingsModel {
return instance; return instance;
} }
private SettingsModel() {
api = RxNet.create(Api.class);
}
@Override @Override
public Single<ServiceResult<String>> showLocation(long uid, boolean showLocation) { public Single<ServiceResult<String>> showLocation(long uid, boolean showLocation) {
return api.showLocation(uid, showLocation); return api.showLocation(uid, showLocation);
@@ -79,25 +79,31 @@ public class SettingsModel implements ISettingsModel {
.compose(RxHelper.handleIgnoreData())); .compose(RxHelper.handleIgnoreData()));
} }
@Override
public Single<String> setAttentionMsgNotify(boolean attentionMsgNotify) {
return api.apiAttentionMsgNotify(AuthModel.get().getCurrentUid(), attentionMsgNotify)
.compose(RxHelper.handleIgnoreData());
}
private Single<Boolean> setNotifyAccount(String account, boolean notify) { private Single<Boolean> setNotifyAccount(String account, boolean notify) {
return Single.create((SingleOnSubscribe<Boolean>) e -> return Single.create((SingleOnSubscribe<Boolean>) e ->
NIMClient.getService(FriendService.class).setMessageNotify(account, notify) NIMClient.getService(FriendService.class).setMessageNotify(account, notify)
.setCallback(new RequestCallback<Void>() { .setCallback(new RequestCallback<Void>() {
@Override @Override
public void onSuccess(Void param) { public void onSuccess(Void param) {
e.onSuccess(notify); e.onSuccess(notify);
} }
@Override @Override
public void onFailed(int code) { public void onFailed(int code) {
e.onError(new Throwable("设置不提醒用户出错code=" + code)); e.onError(new Throwable("设置不提醒用户出错code=" + code));
} }
@Override @Override
public void onException(Throwable exception) { public void onException(Throwable exception) {
e.onError(exception); e.onError(exception);
} }
})) }))
.observeOn(AndroidSchedulers.mainThread()); .observeOn(AndroidSchedulers.mainThread());
} }
@@ -136,8 +142,14 @@ public class SettingsModel implements ISettingsModel {
Single<ServiceResult<JsonElement>> apiSysMsgNotify(@Query("uid") long uid, Single<ServiceResult<JsonElement>> apiSysMsgNotify(@Query("uid") long uid,
@Query("sysMsgNotify") boolean sysMsgNotify); @Query("sysMsgNotify") boolean sysMsgNotify);
@FormUrlEncoded
@POST("/user/singleBroadcastMsgNotify")
Single<ServiceResult<JsonElement>> apiAttentionMsgNotify(@Field("uid") long uid,
@Field("msgNotify") boolean sysMsgNotify);
/** /**
* 获得小秘书和系统通知uid * 获得小秘书和系统通知uid
*
* @return * @return
*/ */
@GET("client/prop") @GET("client/prop")
@@ -145,7 +157,7 @@ public class SettingsModel implements ISettingsModel {
@POST("user/interactiveMsgNotify") @POST("user/interactiveMsgNotify")
Single<ServiceResult<JsonElement>> interactiveMsgNotify(@Query("uid") long uid, Single<ServiceResult<JsonElement>> interactiveMsgNotify(@Query("uid") long uid,
@Query("interactiveMsgNotify") boolean interactiveMsgNotify); @Query("interactiveMsgNotify") boolean interactiveMsgNotify);
} }
} }

View File

@@ -766,6 +766,8 @@ public class UserInfo implements Serializable {
* 互动消息通知true:提醒 * 互动消息通知true:提醒
*/ */
private boolean interactiveMsgNotify = true; private boolean interactiveMsgNotify = true;
private boolean singleBroadcastMsgNotify;
} }
/** /**