From c57ed438d0b0f235ca2942000c14e2c9301c08fc Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Fri, 22 Nov 2019 11:46:00 +0800 Subject: [PATCH] blacklist ui --- chat/kit/src/main/AndroidManifest.xml | 3 + .../chat/kit/contact/ContactViewModel.java | 21 +++++ .../kit/settings/PrivacySettingActivity.java | 37 ++++++++ .../chat/kit/user/UserInfoActivity.java | 92 ++++++++++++++++++- .../res/layout/privacy_setting_activity.xml | 40 ++++++++ chat/kit/src/main/res/menu/user_info.xml | 27 +++++- .../chat/app/setting/SettingActivity.java | 8 +- chat/src/main/res/layout/setting_activity.xml | 4 +- 8 files changed, 220 insertions(+), 12 deletions(-) create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/PrivacySettingActivity.java create mode 100644 chat/kit/src/main/res/layout/privacy_setting_activity.xml diff --git a/chat/kit/src/main/AndroidManifest.xml b/chat/kit/src/main/AndroidManifest.xml index 5aa995d22..2ac6f87aa 100644 --- a/chat/kit/src/main/AndroidManifest.xml +++ b/chat/kit/src/main/AndroidManifest.xml @@ -158,6 +158,9 @@ + diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/contact/ContactViewModel.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/contact/ContactViewModel.java index 36dc2b056..cf8ed4fc7 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/contact/ContactViewModel.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/contact/ContactViewModel.java @@ -153,6 +153,10 @@ public boolean isFriend(String targetUid) { return ChatManager.Instance().isMyFriend(targetUid); } + public boolean isBlacklisted(String targetUid) { + return ChatManager.Instance().isBlackListed(targetUid); + } + public LiveData> deleteFriend(String userId) { MutableLiveData> result = new MutableLiveData<>(); ChatManager.Instance().deleteFriend(userId, new GeneralCallback() { @@ -171,6 +175,23 @@ public void onFail(int errorCode) { return result; } + public LiveData> setBlacklist(String userId, boolean value) { + MutableLiveData> result = new MutableLiveData<>(); + ChatManager.Instance().setBlackList(userId, value, new GeneralCallback() { + @Override + public void onSuccess() { + result.postValue(new OperateResult<>(0)); + } + + @Override + public void onFail(int errorCode) { + result.postValue(new OperateResult<>(errorCode)); + } + }); + + return result; + } + public MutableLiveData invite(String targetUid, String message) { MutableLiveData result = new MutableLiveData<>(); ChatManager.Instance().sendFriendRequest(targetUid, message, new GeneralCallback() { diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/PrivacySettingActivity.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/PrivacySettingActivity.java new file mode 100644 index 000000000..2b83153b3 --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/PrivacySettingActivity.java @@ -0,0 +1,37 @@ +package cn.wildfire.chat.kit.settings; + +import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.widget.Toast; + +import butterknife.BindView; +import butterknife.OnClick; +import cn.wildfire.chat.app.Config; +import cn.wildfire.chat.app.main.SplashActivity; +import cn.wildfire.chat.app.setting.AboutActivity; +import cn.wildfire.chat.kit.ChatManagerHolder; +import cn.wildfire.chat.kit.WfcBaseActivity; +import cn.wildfire.chat.kit.net.OKHttpHelper; +import cn.wildfire.chat.kit.net.SimpleCallback; +import cn.wildfire.chat.kit.widget.OptionItemView; +import cn.wildfirechat.chat.R; + +public class PrivacySettingActivity extends WfcBaseActivity { + + @Override + protected int contentLayout() { + return R.layout.privacy_setting_activity; + } + + @OnClick(R.id.blacklistOptionItemView) + void blacklistSettings() { + Intent intent = new Intent(this, AboutActivity.class); + startActivity(intent); + } + + @OnClick(R.id.momentsPrivacyOptionItemView) + void mementsSettings() { + + } +} diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/user/UserInfoActivity.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/user/UserInfoActivity.java index b9631de8c..bb4ddd9e1 100644 --- a/chat/kit/src/main/java/cn/wildfire/chat/kit/user/UserInfoActivity.java +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/user/UserInfoActivity.java @@ -10,8 +10,10 @@ import cn.wildfire.chat.app.main.MainActivity; import cn.wildfire.chat.kit.WfcBaseActivity; import cn.wildfire.chat.kit.contact.ContactViewModel; +import cn.wildfire.chat.kit.contact.newfriend.InviteFriendActivity; import cn.wildfirechat.chat.R; import cn.wildfirechat.model.UserInfo; +import cn.wildfirechat.remote.ChatManager; public class UserInfoActivity extends WfcBaseActivity { private UserInfo userInfo; @@ -42,17 +44,64 @@ protected int menu() { protected void afterMenus(Menu menu) { super.afterMenus(menu); ContactViewModel contactViewModel = ViewModelProviders.of(this).get(ContactViewModel.class); - if (!contactViewModel.isFriend(userInfo.uid)) { - MenuItem item = menu.findItem(R.id.delete); - item.setEnabled(false); - item.setVisible(false); + + MenuItem itemDelete = menu.findItem(R.id.delete); + MenuItem itemAddFriend = menu.findItem(R.id.addFriend); + MenuItem itemAddBlacklist = menu.findItem(R.id.addBlacklist); + MenuItem itemRemoveBlacklist = menu.findItem(R.id.removeBlacklist); + MenuItem itemSetAlias = menu.findItem(R.id.setAlias); + + if (ChatManager.Instance().getUserId().equals(userInfo.uid)) { + itemAddBlacklist.setEnabled(false); + itemAddBlacklist.setVisible(false); + itemAddFriend.setEnabled(false); + itemAddFriend.setVisible(false); + itemDelete.setEnabled(false); + itemDelete.setVisible(false); + itemRemoveBlacklist.setEnabled(false); + itemRemoveBlacklist.setVisible(false); + itemSetAlias.setEnabled(false); + itemSetAlias.setVisible(false); + } else { + if (contactViewModel.isFriend(userInfo.uid)) { + itemAddFriend.setEnabled(false); + itemAddFriend.setVisible(false); + itemDelete.setEnabled(true); + itemDelete.setVisible(true); + itemSetAlias.setEnabled(true); + itemSetAlias.setVisible(true); + } else { + itemAddFriend.setEnabled(true); + itemAddFriend.setVisible(true); + itemDelete.setEnabled(false); + itemDelete.setVisible(false); + } + + if (contactViewModel.isBlacklisted(userInfo.uid)) { + itemAddBlacklist.setEnabled(false); + itemAddBlacklist.setVisible(false); + itemRemoveBlacklist.setEnabled(true); + itemRemoveBlacklist.setVisible(true); + } else { + itemAddBlacklist.setEnabled(true); + itemAddBlacklist.setVisible(true); + itemRemoveBlacklist.setEnabled(false); + itemRemoveBlacklist.setVisible(false); + } } } +// android:id="@+id/delete" +// android:id="@+id/addFriend" +// android:id="@+id/addBlacklist" +// android:id="@+id/removeBlacklist" +// android:id="@+id/setAlias" + @Override public boolean onOptionsItemSelected(MenuItem item) { + ContactViewModel contactViewModel = ViewModelProviders.of(this).get(ContactViewModel.class); + if (item.getItemId() == R.id.delete) { - ContactViewModel contactViewModel = ViewModelProviders.of(this).get(ContactViewModel.class); contactViewModel.deleteFriend(userInfo.uid).observe( this, booleanOperateResult -> { if (booleanOperateResult.isSuccess()) { @@ -64,7 +113,40 @@ public boolean onOptionsItemSelected(MenuItem item) { } ); return true; + } else if (item.getItemId() == R.id.addFriend) { + Intent intent = new Intent(this, InviteFriendActivity.class); + intent.putExtra("userInfo", userInfo); + startActivity(intent); + return true; + } else if (item.getItemId() == R.id.addBlacklist) { + contactViewModel.setBlacklist(userInfo.uid, true).observe( + this, booleanOperateResult -> { + if (booleanOperateResult.isSuccess()) { + Toast.makeText(this, "设置成功", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(this, "add blacklist error " + booleanOperateResult.getErrorCode(), Toast.LENGTH_SHORT).show(); + } + } + ); + return true; + } else if (item.getItemId() == R.id.removeBlacklist) { + contactViewModel.setBlacklist(userInfo.uid, false).observe( + this, booleanOperateResult -> { + if (booleanOperateResult.isSuccess()) { + Toast.makeText(this, "设置成功", Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(this, "remove blacklist error " + booleanOperateResult.getErrorCode(), Toast.LENGTH_SHORT).show(); + } + } + ); + return true; + } else if (item.getItemId() == R.id.setAlias) { + Intent intent = new Intent(this, SetAliasActivity.class); + intent.putExtra("userId", userInfo.uid); + startActivity(intent); + return true; } + return super.onOptionsItemSelected(item); } diff --git a/chat/kit/src/main/res/layout/privacy_setting_activity.xml b/chat/kit/src/main/res/layout/privacy_setting_activity.xml new file mode 100644 index 000000000..c1fbed9e8 --- /dev/null +++ b/chat/kit/src/main/res/layout/privacy_setting_activity.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chat/kit/src/main/res/menu/user_info.xml b/chat/kit/src/main/res/menu/user_info.xml index 383c9b197..50901ed1e 100644 --- a/chat/kit/src/main/res/menu/user_info.xml +++ b/chat/kit/src/main/res/menu/user_info.xml @@ -5,6 +5,29 @@ + android:title="删除好友" + app:showAsAction="never" /> + + + + + + + \ No newline at end of file diff --git a/chat/src/main/java/cn/wildfire/chat/app/setting/SettingActivity.java b/chat/src/main/java/cn/wildfire/chat/app/setting/SettingActivity.java index 569aa5d8d..b9508566e 100644 --- a/chat/src/main/java/cn/wildfire/chat/app/setting/SettingActivity.java +++ b/chat/src/main/java/cn/wildfire/chat/app/setting/SettingActivity.java @@ -13,6 +13,7 @@ import cn.wildfire.chat.kit.WfcBaseActivity; import cn.wildfire.chat.kit.net.OKHttpHelper; import cn.wildfire.chat.kit.net.SimpleCallback; +import cn.wildfire.chat.kit.settings.PrivacySettingActivity; import cn.wildfire.chat.kit.widget.OptionItemView; import cn.wildfirechat.chat.R; @@ -37,9 +38,10 @@ void exit() { finish(); } - @OnClick(R.id.newMsgNotifyOptionItemView) - void notifySetting() { - + @OnClick(R.id.privacySettingOptionItemView) + void privacySetting() { + Intent intent = new Intent(this, PrivacySettingActivity.class); + startActivity(intent); } @OnClick(R.id.diagnoseOptionItemView) diff --git a/chat/src/main/res/layout/setting_activity.xml b/chat/src/main/res/layout/setting_activity.xml index 9de3da34d..32efe88b8 100644 --- a/chat/src/main/res/layout/setting_activity.xml +++ b/chat/src/main/res/layout/setting_activity.xml @@ -16,10 +16,10 @@ android:orientation="vertical"> + app:title="隐私设置" />