-
Notifications
You must be signed in to change notification settings - Fork 911
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c57ed43
commit b1f8247
Showing
11 changed files
with
341 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
104 changes: 104 additions & 0 deletions
104
chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistListFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewHolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
chat/kit/src/main/java/cn/wildfire/chat/kit/settings/blacklist/BlacklistViewModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters