开箱发送消息开关逻辑优化(分账号保存)

This commit is contained in:
huangjian
2022-05-09 17:37:03 +08:00
parent 9588e6b514
commit 0849d7f33b
5 changed files with 27 additions and 28 deletions

View File

@@ -32,6 +32,7 @@ import com.yizhuan.treasure_box.model.BoxModel;
import com.yizhuan.treasure_box.model.IBoxModel;
import com.yizhuan.xchat_android_core.DemoCache;
import com.yizhuan.xchat_android_core.UriProvider;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
import com.yizhuan.xchat_android_core.manager.RoomEvent;
import com.yizhuan.xchat_android_core.pay.PayModel;
@@ -191,7 +192,7 @@ public class TreasureBoxActivity extends BaseBindingActivity<ActivityTreasureBox
mBinding.ivFirstBox.setVisibility(View.GONE);
mBinding.ivBoxOpen.startAnimation();
long startTime = System.currentTimeMillis();
BoxModel.get().openBox(boxType, count, DemoCache.readBoolean(DemoCache.KEY_BOX_MESSAGE, true))
BoxModel.get().openBox(boxType, count, DemoCache.readNeedBoxMsg())
.compose(bindToLifecycle())
.doOnError(throwable -> {
mBinding.ivOpen.setEnabled(true);

View File

@@ -32,6 +32,7 @@ import com.yizhuan.treasure_box.model.BoxModel;
import com.yizhuan.treasure_box.model.IBoxModel;
import com.yizhuan.xchat_android_core.DemoCache;
import com.yizhuan.xchat_android_core.UriProvider;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.manager.IMNetEaseManager;
import com.yizhuan.xchat_android_core.manager.RoomEvent;
import com.yizhuan.xchat_android_core.pay.PayModel;
@@ -50,6 +51,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers;
@ActLayoutRes(R.layout.activity_treasure_box_honour)
public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreasureBoxHonourBinding> {
private final Runnable removeRunnable = () -> mBinding.llPrizeHint.removeAllViews();
private int price = 20;
private volatile int keyNum;
private ArrayList<PrizeInfo> cacheList = new ArrayList<>();
@@ -60,7 +62,6 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
private int height;
private int sendMessageSwitchLevel;
public static void start(Context context) {
Intent starter = new Intent(context, TreasureBoxHonourActivity.class);
context.startActivity(starter);
@@ -110,7 +111,6 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
looperHintPrize();
}
@SuppressLint("CheckResult")
private void loadKeyInfo() {
BoxModel.get()
@@ -133,7 +133,7 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
openBox(StringUtils.toInt(mBinding.editNum.getText().toString()));
break;
case R.id.iv_more:
new BoxMoreDialog(context,sendMessageSwitchLevel).openDialog();
new BoxMoreDialog(context, sendMessageSwitchLevel).openDialog();
break;
case R.id.tv_rank:
BoxRankingActivity.start(this);
@@ -173,7 +173,6 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
return false;
}
@SuppressLint("CheckResult")
private void openBox(int count) {
if (checkKeyNum(count)) {
@@ -182,7 +181,7 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
mBinding.ivOpen.setEnabled(false);
mBinding.svgaOpen.startAnimation();
BoxModel.get()
.openBox(boxType, count, DemoCache.readBoolean(DemoCache.KEY_BOX_MESSAGE, true))
.openBox(boxType, count, DemoCache.readNeedBoxMsg())
.compose(bindToLifecycle())
.doOnError(throwable -> {
mBinding.ivOpen.setEnabled(true);
@@ -220,7 +219,6 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
, e -> looperPrize());//出错了继续looper......
}
private final Runnable removeRunnable = () -> mBinding.llPrizeHint.removeAllViews();
@SuppressLint("CheckResult")
private void looperHintPrize() {
@@ -264,6 +262,7 @@ public class TreasureBoxHonourActivity extends BaseBindingActivity<ActivityTreas
((TextView) linearLayout.findViewById(R.id.tv_prize_name)).setText(prizeInfo.getPrizeName());
((TextView) linearLayout.findViewById(R.id.tv_prize_num)).setText("x" + prizeInfo.getPrizeNum());
}
/**
* 更新钥匙(锤子)数量
*

View File

@@ -13,6 +13,7 @@ import com.yizhuan.erban.ui.webview.DialogWebViewActivity;
import com.yizhuan.erban.utils.UserUtils;
import com.yizhuan.xchat_android_core.DemoCache;
import com.yizhuan.xchat_android_core.UriProvider;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.user.UserModel;
import com.yizhuan.xchat_android_core.user.bean.UserInfo;
import com.yizhuan.xchat_android_library.annatation.ActLayoutRes;
@@ -56,15 +57,15 @@ public class BoxMoreDialog extends BaseBindingDialog<DialogBoxMoreBinding> {
});
if (sendMessageSwitchLevel != 0 && UserUtils.getExpLevel() >= sendMessageSwitchLevel) {
binding.ivSwitch.setVisibility(View.VISIBLE);
updateMsgSwitch(DemoCache.readBoolean(DemoCache.KEY_BOX_MESSAGE, true));
binding.flMsgSwitch.setVisibility(View.VISIBLE);
updateMsgSwitch(DemoCache.readNeedBoxMsg());
binding.ivSwitch.setOnClickListener(v -> {
boolean sendMsg = !DemoCache.readBoolean(DemoCache.KEY_BOX_MESSAGE, true);
boolean sendMsg = !DemoCache.readNeedBoxMsg();
updateMsgSwitch(sendMsg);
DemoCache.saveBoolean(DemoCache.KEY_BOX_MESSAGE, sendMsg);
DemoCache.saveNeedBoxMsg(sendMsg);
});
} else {
binding.ivSwitch.setVisibility(View.GONE);
binding.flMsgSwitch.setVisibility(View.GONE);
}
}

View File

@@ -54,10 +54,13 @@
android:layout_height="43dp"
android:gravity="center_vertical"
android:text="玩法规则"
android:background="@drawable/bottom_line"
android:textColor="#ff333333"
android:textSize="14sp" />
<FrameLayout
android:id="@+id/fl_msg_switch"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content">

View File

@@ -10,6 +10,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.netease.nimlib.sdk.StatusBarNotificationConfig;
import com.netease.nimlib.sdk.auth.LoginInfo;
import com.yizhuan.xchat_android_core.auth.AuthModel;
import com.yizhuan.xchat_android_core.auth.entity.AccountInfo;
import com.yizhuan.xchat_android_core.auth.entity.ThirdUserInfo;
import com.yizhuan.xchat_android_core.auth.entity.TicketInfo;
@@ -37,6 +38,8 @@ import java.util.Map;
public class DemoCache {
public static final String KEY_IS_FIRST_HOME_HIGH_PARTY_DIALOG = "IsFirstHomeHighPartyDialog";
public static final String KEY_VIP_RED_POINT = "key_vip_red_point";
private static final String KEY_BOX_MESSAGE = "key_box_message";
private static final String KEY_TICKET_INFO = "TicketInfo";
private static final String KEY_ACCOUNT_INFO = "AccountInfo";
private static final String KEY_THIRD_USER_INFO = "ThirdUserInfo";
@@ -57,10 +60,7 @@ public class DemoCache {
private static final String KEY_IS_FIRST_HIGH_PARTY_DIALOG = "IsFirstHighPartyDialog";
private static final String KEY_FILTRATE_TYPE = "FilTrateType";
private static final String KEY_RED_PACKAGE = "RedPackage";
public static final String KEY_VIP_RED_POINT = "key_vip_red_point";
private static final String KEY_AT_MSG_UUID = "AtMsgUuid";
public static final String KEY_BOX_MESSAGE = "key_box_message";
/**
* 保存网页域名
*/
@@ -330,18 +330,13 @@ public class DemoCache {
ObjectPref.instance(BasicConfig.INSTANCE.getAppContext()).saveObject(KEY_INIT_DATA_API_HOST, initDataApiHost);
}
private LoginInfo loginInfo() {
// 从本地读取上次登录成功时保存的用户登录信息
LoginInfo loginInfo = DemoCache.readLoginInfo(BasicConfig.INSTANCE.getAppContext());
// 如果已经存在用户登录信息返回LoginInfo否则返回null即可
if (null != loginInfo) {
if (!TextUtils.isEmpty(loginInfo.getAccount()) && !TextUtils.isEmpty(loginInfo.getToken())) {
return loginInfo;
} else {
return null;
}
} else {
return null;
}
public static void saveNeedBoxMsg(boolean value) {
SettingsPref.instance(BasicConfig.INSTANCE.getAppContext()).putBoolean(KEY_BOX_MESSAGE + AuthModel.get().getCurrentUid(), value);
}
public static Boolean readNeedBoxMsg() {
return SettingsPref.instance(BasicConfig.INSTANCE.getAppContext()).getBoolean(KEY_BOX_MESSAGE + AuthModel.get().getCurrentUid(), true);
}
}