Skip to content

Commit

Permalink
黑名单ui
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Nov 22, 2019
1 parent c57ed43 commit b1f8247
Show file tree
Hide file tree
Showing 11 changed files with 341 additions and 1 deletion.
3 changes: 3 additions & 0 deletions chat/kit/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@
<activity
android:name="cn.wildfire.chat.kit.settings.PrivacySettingActivity"
android:label="隐私设置" />
<activity
android:name="cn.wildfire.chat.kit.settings.blacklist.BlacklistListActivity"
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 @@ -14,6 +14,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.blacklist.BlacklistListActivity;
import cn.wildfire.chat.kit.widget.OptionItemView;
import cn.wildfirechat.chat.R;

Expand All @@ -26,7 +27,7 @@ protected int contentLayout() {

@OnClick(R.id.blacklistOptionItemView)
void blacklistSettings() {
Intent intent = new Intent(this, AboutActivity.class);
Intent intent = new Intent(this, BlacklistListActivity.class);
startActivity(intent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cn.wildfire.chat.kit.settings.blacklist;

import android.content.Intent;
import android.view.MenuItem;

import cn.wildfire.chat.kit.WfcBaseActivity;
import cn.wildfirechat.chat.R;

public class BlacklistListActivity extends WfcBaseActivity {


@Override
protected int contentLayout() {
return R.layout.fragment_container_activity;
}

@Override
protected void afterViews() {
getSupportFragmentManager().beginTransaction()
.replace(R.id.containerFrameLayout, new BlacklistListFragment())
.commit();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cn.wildfire.chat.kit.settings.blacklist;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import cn.wildfirechat.chat.R;

public class BlacklistListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<String> blackedUserIds;
private OnBlacklistItemClickListener onBlacklistItemClickListener;

public void setBlackedUserIds(List<String> blackedUserIds) {
this.blackedUserIds = blackedUserIds;
}

public List<String> getBlackedUserIds() {
return blackedUserIds;
}

public void setOnBlacklistItemClickListener(OnBlacklistItemClickListener listener) {
this.onBlacklistItemClickListener = listener;
}

@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.blacklist_item, parent, false);
RecyclerView.ViewHolder holder = new BlacklistViewHolder(view);
view.setOnClickListener(v -> {
if (onBlacklistItemClickListener != null) {
int position = holder.getAdapterPosition();
onBlacklistItemClickListener.onItemClick(blackedUserIds.get(position), v);
}
});
return holder;
}

@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
((BlacklistViewHolder) holder).bind(blackedUserIds.get(position));
}


@Override
public int getItemCount() {
return blackedUserIds == null ? 0 : blackedUserIds.size();
}

@Override
public int getItemViewType(int position) {
return R.layout.blacklist_item;
}

public interface OnBlacklistItemClickListener {
void onItemClick(String userId, View view);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package cn.wildfire.chat.kit.settings.blacklist;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.widget.PopupMenu;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.wildfirechat.chat.R;
import cn.wildfirechat.remote.ChatManager;
import cn.wildfirechat.remote.GeneralCallback;


public class BlacklistListFragment extends Fragment implements BlacklistListAdapter.OnBlacklistItemClickListener, PopupMenu.OnMenuItemClickListener {
@BindView(R.id.recyclerView)
RecyclerView recyclerView;
private BlacklistViewModel blacklistViewModel;
private BlacklistListAdapter blacklistListAdapter;

private String selectedUserId;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.blacklist_list_frament, container, false);
ButterKnife.bind(this, view);
init();
return view;
}

@Override
public void onResume() {
super.onResume();
refreshBlacklist();
}

private void init() {
blacklistViewModel = ViewModelProviders.of(getActivity()).get(BlacklistViewModel.class);

blacklistListAdapter = new BlacklistListAdapter();
blacklistListAdapter.setOnBlacklistItemClickListener(this);

recyclerView.setAdapter(blacklistListAdapter);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
}

private void refreshBlacklist() {
List<String> blacklists = blacklistViewModel.getBlacklists();
blacklistListAdapter.setBlackedUserIds(blacklists);
blacklistListAdapter.notifyDataSetChanged();
}

@Override
public void onItemClick(String userId, View v) {

PopupMenu popup = new PopupMenu(getActivity(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.blacklist_popup, popup.getMenu());
popup.setOnMenuItemClickListener(this);
popup.show();
selectedUserId = userId;

}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
}

@Override
public boolean onMenuItemClick(MenuItem item) {
if (item.getItemId() == R.id.remove) {
ChatManager.Instance().setBlackList(selectedUserId, false, new GeneralCallback() {
@Override
public void onSuccess() {
blacklistListAdapter.getBlackedUserIds().remove(selectedUserId);
blacklistListAdapter.notifyDataSetChanged();
}

@Override
public void onFail(int errorCode) {
Toast.makeText(getActivity(), "删除失败", Toast.LENGTH_SHORT).show();
}
});
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package cn.wildfire.chat.kit.settings.blacklist;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.wildfirechat.chat.R;
import cn.wildfirechat.model.UserInfo;
import cn.wildfirechat.remote.ChatManager;

public class BlacklistViewHolder extends RecyclerView.ViewHolder {
@BindView(R.id.portraitImageView)
ImageView portraitImageView;
@BindView(R.id.userNameTextView)
TextView userNameTextView;

public BlacklistViewHolder(View itemView) {
super(itemView);
ButterKnife.bind(this, itemView);
}

public void bind(String userId) {
UserInfo userInfo = ChatManager.Instance().getUserInfo(userId, false);
userNameTextView.setText(userInfo.displayName == null ? "< " + userInfo.uid + "> " : userInfo.displayName);
Glide.with(itemView.getContext()).load(userInfo.portrait).into(portraitImageView);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package cn.wildfire.chat.kit.settings.blacklist;

import androidx.lifecycle.ViewModel;

import java.util.List;

import cn.wildfirechat.remote.ChatManager;

public class BlacklistViewModel extends ViewModel {

public BlacklistViewModel() {
super();
}

@Override
protected void onCleared() {
super.onCleared();
}

public List<String> getBlacklists() {
return ChatManager.Instance().getBlackList(true);
}

}
64 changes: 64 additions & 0 deletions chat/kit/src/main/res/layout/blacklist_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@drawable/selector_common_item"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingLeft="@dimen/item_margin_left_and_right"
android:paddingRight="@dimen/item_margin_left_and_right">

<RelativeLayout
android:layout_width="46dp"
android:layout_height="match_parent">

<ImageView
android:id="@+id/portraitImageView"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_centerVertical="true"
android:src="@mipmap/ic_new_friend" />

<TextView
android:id="@+id/unreadCountTextView"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_alignTop="@id/portraitImageView"
android:layout_alignRight="@id/portraitImageView"
android:layout_marginTop="-6dp"
android:layout_marginRight="-6dp"
android:background="@mipmap/bg_unread"
android:gravity="center"
android:text="10"
android:textColor="@color/white"
android:textSize="10sp"
android:visibility="gone"
tools:visibility="visible" />

</RelativeLayout>


<TextView
android:id="@+id/userNameTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:text=""
android:textColor="@color/black0"
android:textSize="16sp" />

</LinearLayout>

<View
style="@style/Line"
android:layout_marginLeft="@dimen/item_margin_left_and_right"
android:layout_marginRight="@dimen/item_margin_left_and_right" />

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

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
8 changes: 8 additions & 0 deletions chat/kit/src/main/res/menu/blacklist_popup.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/remove"
android:title="删除"
app:showAsAction="always" />

</menu>
6 changes: 6 additions & 0 deletions chat/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
<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.blacklist.BlacklistListActivity"
android:label="黑名单" />
<activity
android:name="cn.wildfire.chat.kit.settings.MessageNotifySettingActivity"
android:label="新消息通知" />
Expand Down

0 comments on commit b1f8247

Please sign in to comment.