From b1f82476ac7996784a9265001f85a1e6c739224a Mon Sep 17 00:00:00 2001 From: heavyrain2012 Date: Fri, 22 Nov 2019 12:54:29 +0800 Subject: [PATCH] =?UTF-8?q?=E9=BB=91=E5=90=8D=E5=8D=95ui?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- chat/kit/src/main/AndroidManifest.xml | 3 + .../kit/settings/PrivacySettingActivity.java | 3 +- .../blacklist/BlacklistListActivity.java | 23 ++++ .../blacklist/BlacklistListAdapter.java | 63 +++++++++++ .../blacklist/BlacklistListFragment.java | 104 ++++++++++++++++++ .../blacklist/BlacklistViewHolder.java | 33 ++++++ .../blacklist/BlacklistViewModel.java | 24 ++++ .../src/main/res/layout/blacklist_item.xml | 64 +++++++++++ .../res/layout/blacklist_list_frament.xml | 11 ++ .../kit/src/main/res/menu/blacklist_popup.xml | 8 ++ chat/src/main/AndroidManifest.xml | 6 + 11 files changed, 341 insertions(+), 1 deletion(-) create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListActivity.java create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListAdapter.java create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListFragment.java create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewHolder.java create mode 100644 chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewModel.java create mode 100644 chat/kit/src/main/res/layout/blacklist_item.xml create mode 100644 chat/kit/src/main/res/layout/blacklist_list_frament.xml create mode 100644 chat/kit/src/main/res/menu/blacklist_popup.xml diff --git a/chat/kit/src/main/AndroidManifest.xml b/chat/kit/src/main/AndroidManifest.xml index 2ac6f87aa..9e4277e67 100644 --- a/chat/kit/src/main/AndroidManifest.xml +++ b/chat/kit/src/main/AndroidManifest.xml @@ -161,6 +161,9 @@ + 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 index 2b83153b3..7237a210d 100644 --- 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 @@ -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; @@ -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); } diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListActivity.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListActivity.java new file mode 100644 index 000000000..7296f45cd --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListActivity.java @@ -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(); + } +} diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListAdapter.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListAdapter.java new file mode 100644 index 000000000..c2af1e48f --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListAdapter.java @@ -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 { + private List blackedUserIds; + private OnBlacklistItemClickListener onBlacklistItemClickListener; + + public void setBlackedUserIds(List blackedUserIds) { + this.blackedUserIds = blackedUserIds; + } + + public List 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); + } +} diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListFragment.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListFragment.java new file mode 100644 index 000000000..cdbefae9c --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListFragment.java @@ -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 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; + } +} diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewHolder.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewHolder.java new file mode 100644 index 000000000..93ecdea37 --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewHolder.java @@ -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); + } +} diff --git a/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewModel.java b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewModel.java new file mode 100644 index 000000000..50e19df26 --- /dev/null +++ b/chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewModel.java @@ -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 getBlacklists() { + return ChatManager.Instance().getBlackList(true); + } + +} diff --git a/chat/kit/src/main/res/layout/blacklist_item.xml b/chat/kit/src/main/res/layout/blacklist_item.xml new file mode 100644 index 000000000..18837d003 --- /dev/null +++ b/chat/kit/src/main/res/layout/blacklist_item.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/chat/kit/src/main/res/layout/blacklist_list_frament.xml b/chat/kit/src/main/res/layout/blacklist_list_frament.xml new file mode 100644 index 000000000..80a3a60d6 --- /dev/null +++ b/chat/kit/src/main/res/layout/blacklist_list_frament.xml @@ -0,0 +1,11 @@ + + + + + \ No newline at end of file diff --git a/chat/kit/src/main/res/menu/blacklist_popup.xml b/chat/kit/src/main/res/menu/blacklist_popup.xml new file mode 100644 index 000000000..85a0d9022 --- /dev/null +++ b/chat/kit/src/main/res/menu/blacklist_popup.xml @@ -0,0 +1,8 @@ + + + + + \ No newline at end of file diff --git a/chat/src/main/AndroidManifest.xml b/chat/src/main/AndroidManifest.xml index fc8fd84c2..4ec4e30f1 100644 --- a/chat/src/main/AndroidManifest.xml +++ b/chat/src/main/AndroidManifest.xml @@ -161,6 +161,12 @@ + +