Skip to content

Commit

Permalink
blacklist ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Nov 22, 2019
1 parent 8393399 commit c57ed43
Show file tree
Hide file tree
Showing 8 changed files with 220 additions and 12 deletions.
3 changes: 3 additions & 0 deletions chat/kit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,9 @@
<activity
android:name="cn.wildfire.chat.kit.user.UserInfoActivity"
android:label="用户信息" />
<activity
android:name="cn.wildfire.chat.kit.settings.PrivacySettingActivity"
android:label="隐私设置" />
<activity
android:name="cn.wildfire.chat.kit.settings.MessageNotifySettingActivity"
android:label="新消息通知" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<OperateResult<Boolean>> deleteFriend(String userId) {
MutableLiveData<OperateResult<Boolean>> result = new MutableLiveData<>();
ChatManager.Instance().deleteFriend(userId, new GeneralCallback() {
Expand All @@ -171,6 +175,23 @@ public void onFail(int errorCode) {
return result;
}

public LiveData<OperateResult<Boolean>> setBlacklist(String userId, boolean value) {
MutableLiveData<OperateResult<Boolean>> 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<Boolean> invite(String targetUid, String message) {
MutableLiveData<Boolean> result = new MutableLiveData<>();
ChatManager.Instance().sendFriendRequest(targetUid, message, new GeneralCallback() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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() {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()) {
Expand All @@ -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);
}

Expand Down
40 changes: 40 additions & 0 deletions chat/kit/src/main/res/layout/privacy_setting_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/gray5"
android:orientation="vertical">

<include layout="@layout/toolbar" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/option_item_margin_top"
android:background="@color/white"
android:orientation="vertical">

<cn.wildfire.chat.kit.widget.OptionItemView
android:id="@+id/blacklistOptionItemView"
style="@style/OptionItem"
android:background="@drawable/selector_option_item"
app:title="黑名单" />
</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/option_item_margin_top"
android:background="@color/white"
android:orientation="vertical">

<cn.wildfire.chat.kit.widget.OptionItemView
android:id="@+id/momentsPrivacyOptionItemView"
style="@style/OptionItem"
android:background="@drawable/selector_option_item"
app:title="朋友圈" />
</LinearLayout>


</LinearLayout>
27 changes: 25 additions & 2 deletions chat/kit/src/main/res/menu/user_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
<item
android:id="@+id/delete"
android:orderInCategory="100"
android:title="删除"
app:showAsAction="always" />
android:title="删除好友"
app:showAsAction="never" />

<item
android:id="@+id/addFriend"
android:orderInCategory="100"
android:title="添加好友"
app:showAsAction="never" />
<item
android:id="@+id/addBlacklist"
android:orderInCategory="100"
android:title="加入黑名单"
app:showAsAction="never" />

<item
android:id="@+id/removeBlacklist"
android:orderInCategory="100"
android:title="移出黑名单"
app:showAsAction="never" />

<item
android:id="@+id/setAlias"
android:orderInCategory="100"
android:title="设置备注名"
app:showAsAction="never" />
</menu>
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions chat/src/main/res/layout/setting_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
android:orientation="vertical">

<cn.wildfire.chat.kit.widget.OptionItemView
android:id="@+id/newMsgNotifyOptionItemView"
android:id="@+id/privacySettingOptionItemView"
style="@style/OptionItem"
android:background="@drawable/selector_option_item"
app:title="@string/new_message_remind" />
app:title="隐私设置" />
</LinearLayout>

<LinearLayout
Expand Down

0 comments on commit c57ed43

Please sign in to comment.