2014-11-17 03:44:57 +01:00
|
|
|
/*
|
2019-06-04 12:14:50 +02:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2014-11-17 03:44:57 +01:00
|
|
|
* It is licensed under GNU GPL v. 2 or later.
|
|
|
|
* You should have received a copy of the license in this archive (see LICENSE).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2014-11-17 03:44:57 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.os.Bundle;
|
2019-06-04 12:14:50 +02:00
|
|
|
import android.text.TextUtils;
|
2014-11-17 03:44:57 +01:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2019-06-04 12:14:50 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.NotificationCenter;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.messenger.R;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2019-06-04 12:14:50 +02:00
|
|
|
import org.telegram.ui.Cells.HeaderCell;
|
|
|
|
import org.telegram.ui.Cells.ManageChatTextCell;
|
|
|
|
import org.telegram.ui.Cells.ManageChatUserCell;
|
|
|
|
import org.telegram.ui.Cells.ShadowSectionCell;
|
|
|
|
import org.telegram.ui.Cells.TextInfoPrivacyCell;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.EmptyTextProgressView;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.Components.RecyclerListView;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
|
|
import androidx.recyclerview.widget.RecyclerView;
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public class PrivacyUsersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2019-08-22 01:53:26 +02:00
|
|
|
private LinearLayoutManager layoutManager;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ListAdapter listViewAdapter;
|
2017-03-31 01:58:05 +02:00
|
|
|
private EmptyTextProgressView emptyView;
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
private int rowCount;
|
|
|
|
private int blockUserRow;
|
|
|
|
private int blockUserDetailRow;
|
|
|
|
private int usersHeaderRow;
|
|
|
|
private int usersStartRow;
|
|
|
|
private int usersEndRow;
|
|
|
|
private int usersDetailRow;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
private boolean blockedUsersActivity;
|
2016-03-06 02:49:31 +01:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
private boolean isGroup;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ArrayList<Integer> uidArray;
|
|
|
|
private boolean isAlwaysShare;
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
private PrivacyActivityDelegate delegate;
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public interface PrivacyActivityDelegate {
|
|
|
|
void didUpdateUserList(ArrayList<Integer> ids, boolean added);
|
|
|
|
}
|
|
|
|
|
|
|
|
public PrivacyUsersActivity() {
|
|
|
|
super();
|
|
|
|
blockedUsersActivity = true;
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public PrivacyUsersActivity(ArrayList<Integer> users, boolean group, boolean always) {
|
2014-11-17 03:44:57 +01:00
|
|
|
super();
|
|
|
|
uidArray = users;
|
|
|
|
isAlwaysShare = always;
|
2016-03-06 02:49:31 +01:00
|
|
|
isGroup = group;
|
2019-06-04 12:14:50 +02:00
|
|
|
blockedUsersActivity = false;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.updateInterfaces);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (blockedUsersActivity) {
|
|
|
|
NotificationCenter.getInstance(currentAccount).addObserver(this, NotificationCenter.blockedUsersDidLoad);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2018-07-30 04:07:02 +02:00
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.updateInterfaces);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (blockedUsersActivity) {
|
|
|
|
NotificationCenter.getInstance(currentAccount).removeObserver(this, NotificationCenter.blockedUsersDidLoad);
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-07-22 20:56:37 +02:00
|
|
|
public View createView(Context context) {
|
2015-04-09 20:00:14 +02:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setAllowOverlayTitle(true);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (blockedUsersActivity) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (isGroup) {
|
|
|
|
if (isAlwaysShare) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AlwaysAllow", R.string.AlwaysAllow));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("NeverAllow", R.string.NeverAllow));
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (isAlwaysShare) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
|
|
|
|
}
|
2016-03-06 02:49:31 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(int id) {
|
|
|
|
if (id == -1) {
|
|
|
|
finishFragment();
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
fragmentView = new FrameLayout(context);
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
2019-06-04 12:14:50 +02:00
|
|
|
frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
emptyView = new EmptyTextProgressView(context);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (blockedUsersActivity) {
|
|
|
|
emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
|
|
|
|
} else {
|
|
|
|
emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
frameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
listView = new RecyclerListView(context);
|
|
|
|
listView.setEmptyView(emptyView);
|
2019-08-22 01:53:26 +02:00
|
|
|
listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
|
2019-06-04 12:14:50 +02:00
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setAdapter(listViewAdapter = new ListAdapter(context));
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
|
|
|
|
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
listView.setOnItemClickListener((view, position) -> {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (position == blockUserRow) {
|
|
|
|
if (blockedUsersActivity) {
|
2019-07-18 15:01:39 +02:00
|
|
|
presentFragment(new DialogOrContactPickerActivity());
|
2019-06-04 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putBoolean(isAlwaysShare ? "isAlwaysShare" : "isNeverShare", true);
|
|
|
|
args.putBoolean("isGroup", isGroup);
|
|
|
|
GroupCreateActivity fragment = new GroupCreateActivity(args);
|
|
|
|
fragment.setDelegate(ids -> {
|
|
|
|
for (Integer id1 : ids) {
|
|
|
|
if (uidArray.contains(id1)) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
uidArray.add(id1);
|
|
|
|
}
|
|
|
|
updateRows();
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didUpdateUserList(uidArray, true);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
|
|
|
} else if (position >= usersStartRow && position < usersEndRow) {
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", getMessagesController().blockedUsers.keyAt(position - usersStartRow));
|
|
|
|
presentFragment(new ProfileActivity(args));
|
|
|
|
} else {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
Integer id = uidArray.get(position - usersStartRow);
|
|
|
|
if (id > 0) {
|
|
|
|
args.putInt("user_id", id);
|
|
|
|
} else {
|
|
|
|
args.putInt("chat_id", -id);
|
|
|
|
}
|
|
|
|
presentFragment(new ProfileActivity(args));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2019-06-04 12:14:50 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
listView.setOnItemLongClickListener((view, position) -> {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (position >= usersStartRow && position < usersEndRow) {
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
showUnblockAlert(getMessagesController().blockedUsers.keyAt(position - usersStartRow));
|
|
|
|
} else {
|
|
|
|
showUnblockAlert(uidArray.get(position - usersStartRow));
|
|
|
|
}
|
|
|
|
return true;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
return false;
|
|
|
|
});
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
if (blockedUsersActivity) {
|
|
|
|
listView.setOnScrollListener(new RecyclerView.OnScrollListener() {
|
|
|
|
@Override
|
|
|
|
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
|
|
|
|
if (getMessagesController().blockedEndReached) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
|
|
|
|
int visibleItemCount = Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
|
|
|
|
int totalItemCount = recyclerView.getAdapter().getItemCount();
|
|
|
|
if (visibleItemCount > 0) {
|
|
|
|
if (layoutManager.findLastVisibleItemPosition() >= totalItemCount - 10) {
|
|
|
|
getMessagesController().getBlockedUsers(false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getMessagesController().totalBlockedCount < 0) {
|
2019-06-04 12:14:50 +02:00
|
|
|
emptyView.showProgress();
|
|
|
|
} else {
|
|
|
|
emptyView.showTextView();
|
|
|
|
}
|
|
|
|
updateRows();
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(PrivacyActivityDelegate privacyActivityDelegate) {
|
|
|
|
delegate = privacyActivityDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void showUnblockAlert(int uid) {
|
|
|
|
if (getParentActivity() == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
CharSequence[] items;
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
|
|
|
|
} else {
|
|
|
|
items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
}
|
|
|
|
builder.setItems(items, (dialogInterface, i) -> {
|
|
|
|
if (i == 0) {
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
getMessagesController().unblockUser(uid);
|
|
|
|
} else {
|
|
|
|
uidArray.remove((Integer) uid);
|
|
|
|
updateRows();
|
2019-01-23 18:03:33 +01:00
|
|
|
if (delegate != null) {
|
2019-06-04 12:14:50 +02:00
|
|
|
delegate.didUpdateUserList(uidArray, false);
|
|
|
|
}
|
|
|
|
if (uidArray.isEmpty()) {
|
|
|
|
finishFragment();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
2019-06-04 12:14:50 +02:00
|
|
|
showDialog(builder.create());
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
private void updateRows() {
|
|
|
|
rowCount = 0;
|
2019-08-22 01:53:26 +02:00
|
|
|
if (!blockedUsersActivity || getMessagesController().totalBlockedCount >= 0) {
|
2019-06-04 12:14:50 +02:00
|
|
|
blockUserRow = rowCount++;
|
|
|
|
blockUserDetailRow = rowCount++;
|
|
|
|
|
|
|
|
int count;
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
count = getMessagesController().blockedUsers.size();
|
|
|
|
} else {
|
|
|
|
count = uidArray.size();
|
|
|
|
}
|
|
|
|
if (count != 0) {
|
|
|
|
usersHeaderRow = rowCount++;
|
|
|
|
usersStartRow = rowCount;
|
|
|
|
rowCount += count;
|
|
|
|
usersEndRow = rowCount;
|
|
|
|
usersDetailRow = rowCount++;
|
|
|
|
} else {
|
|
|
|
usersHeaderRow = -1;
|
|
|
|
usersStartRow = -1;
|
|
|
|
usersEndRow = -1;
|
|
|
|
usersDetailRow = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2018-07-30 04:07:02 +02:00
|
|
|
public void didReceivedNotification(int id, int account, Object... args) {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (id == NotificationCenter.updateInterfaces) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int mask = (Integer) args[0];
|
2014-11-17 03:44:57 +01:00
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
updateVisibleRows(mask);
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
} else if (id == NotificationCenter.blockedUsersDidLoad) {
|
|
|
|
emptyView.showTextView();
|
|
|
|
updateRows();
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateVisibleRows(int mask) {
|
|
|
|
if (listView == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = listView.getChildAt(a);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (child instanceof ManageChatUserCell) {
|
|
|
|
((ManageChatUserCell) child).update(mask);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
@Override
|
|
|
|
public void didSelectContact(final TLRPC.User user, String param, ContactsActivity activity) {
|
|
|
|
if (user == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
getMessagesController().blockUser(user.id);
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private class ListAdapter extends RecyclerListView.SelectionAdapter {
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-04 12:14:50 +02:00
|
|
|
public int getItemCount() {
|
|
|
|
return rowCount;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-04 12:14:50 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
int viewType = holder.getItemViewType();
|
|
|
|
return viewType == 0 || viewType == 2;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2019-06-04 12:14:50 +02:00
|
|
|
view = new ManageChatUserCell(mContext, 7, 6, true);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
((ManageChatUserCell) view).setDelegate((cell, click) -> {
|
|
|
|
if (click) {
|
|
|
|
showUnblockAlert((Integer) cell.getTag());
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
});
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
2019-06-04 12:14:50 +02:00
|
|
|
view = new TextInfoPrivacyCell(mContext);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
view = new ManageChatTextCell(mContext);
|
|
|
|
view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
break;
|
|
|
|
case 3:
|
2017-03-31 01:58:05 +02:00
|
|
|
default:
|
2019-06-04 12:14:50 +02:00
|
|
|
HeaderCell headerCell = new HeaderCell(mContext, false, 21, 11, false);
|
|
|
|
headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
headerCell.setHeight(43);
|
|
|
|
view = headerCell;
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
return new RecyclerListView.Holder(view);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
|
2019-06-04 12:14:50 +02:00
|
|
|
switch (holder.getItemViewType()) {
|
|
|
|
case 0:
|
|
|
|
ManageChatUserCell userCell = (ManageChatUserCell) holder.itemView;
|
|
|
|
int uid;
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
uid = getMessagesController().blockedUsers.keyAt(position - usersStartRow);
|
|
|
|
} else {
|
|
|
|
uid = uidArray.get(position - usersStartRow);
|
|
|
|
}
|
|
|
|
userCell.setTag(uid);
|
|
|
|
if (uid > 0) {
|
|
|
|
TLRPC.User user = getMessagesController().getUser(uid);
|
|
|
|
if (user != null) {
|
|
|
|
String number;
|
|
|
|
if (user.bot) {
|
|
|
|
number = LocaleController.getString("Bot", R.string.Bot).substring(0, 1).toUpperCase() + LocaleController.getString("Bot", R.string.Bot).substring(1);
|
|
|
|
} else if (user.phone != null && user.phone.length() != 0) {
|
|
|
|
number = PhoneFormat.getInstance().format("+" + user.phone);
|
|
|
|
} else {
|
|
|
|
number = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
|
|
|
|
}
|
|
|
|
userCell.setData(user, null, number, position != usersEndRow - 1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TLRPC.Chat chat = getMessagesController().getChat(-uid);
|
|
|
|
if (chat != null) {
|
|
|
|
String subtitle;
|
|
|
|
if (chat.participants_count != 0) {
|
|
|
|
subtitle = LocaleController.formatPluralString("Members", chat.participants_count);
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (chat.has_geo) {
|
|
|
|
subtitle = LocaleController.getString("MegaLocation", R.string.MegaLocation);
|
2019-06-04 12:14:50 +02:00
|
|
|
} else if (TextUtils.isEmpty(chat.username)) {
|
|
|
|
subtitle = LocaleController.getString("MegaPrivate", R.string.MegaPrivate);
|
|
|
|
} else {
|
|
|
|
subtitle = LocaleController.getString("MegaPublic", R.string.MegaPublic);
|
|
|
|
}
|
|
|
|
userCell.setData(chat, null, subtitle, position != usersEndRow - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
TextInfoPrivacyCell privacyCell = (TextInfoPrivacyCell) holder.itemView;
|
|
|
|
if (position == blockUserDetailRow) {
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
privacyCell.setText(LocaleController.getString("BlockedUsersInfo", R.string.BlockedUsersInfo));
|
|
|
|
} else {
|
|
|
|
privacyCell.setText(null);
|
|
|
|
}
|
|
|
|
if (usersStartRow == -1) {
|
|
|
|
privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
} else {
|
|
|
|
privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
}
|
|
|
|
} else if (position == usersDetailRow) {
|
|
|
|
privacyCell.setText("");
|
|
|
|
privacyCell.setBackgroundDrawable(Theme.getThemedDrawable(mContext, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
ManageChatTextCell actionCell = (ManageChatTextCell) holder.itemView;
|
|
|
|
actionCell.setColors(Theme.key_windowBackgroundWhiteBlueIcon, Theme.key_windowBackgroundWhiteBlueButton);
|
|
|
|
if (blockedUsersActivity) {
|
|
|
|
actionCell.setText(LocaleController.getString("BlockUser", R.string.BlockUser), null, R.drawable.actions_addmember2, false);
|
|
|
|
} else {
|
|
|
|
actionCell.setText(LocaleController.getString("PrivacyAddAnException", R.string.PrivacyAddAnException), null, R.drawable.actions_addmember2, false);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
HeaderCell headerCell = (HeaderCell) holder.itemView;
|
|
|
|
if (position == usersHeaderRow) {
|
|
|
|
if (blockedUsersActivity) {
|
2019-08-22 01:53:26 +02:00
|
|
|
headerCell.setText(LocaleController.formatPluralString("BlockedUsersCount", getMessagesController().totalBlockedCount));
|
2019-06-04 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
headerCell.setText(LocaleController.getString("PrivacyExceptions", R.string.PrivacyExceptions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-06-04 12:14:50 +02:00
|
|
|
public int getItemViewType(int position) {
|
|
|
|
if (position == usersHeaderRow) {
|
|
|
|
return 3;
|
|
|
|
} else if (position == blockUserRow) {
|
|
|
|
return 2;
|
|
|
|
} else if (position == blockUserDetailRow || position == usersDetailRow) {
|
2017-03-31 01:58:05 +02:00
|
|
|
return 1;
|
2019-06-04 12:14:50 +02:00
|
|
|
} else {
|
|
|
|
return 0;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
@Override
|
|
|
|
public ThemeDescription[] getThemeDescriptions() {
|
2019-01-23 18:03:33 +01:00
|
|
|
ThemeDescription.ThemeDescriptionDelegate cellDelegate = () -> {
|
|
|
|
if (listView != null) {
|
|
|
|
int count = listView.getChildCount();
|
|
|
|
for (int a = 0; a < count; a++) {
|
|
|
|
View child = listView.getChildAt(a);
|
2019-06-04 12:14:50 +02:00
|
|
|
if (child instanceof ManageChatUserCell) {
|
|
|
|
((ManageChatUserCell) child).update(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return new ThemeDescription[]{
|
2019-06-04 12:14:50 +02:00
|
|
|
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{ManageChatUserCell.class, ManageChatTextCell.class, HeaderCell.class}, null, null, null, Theme.key_windowBackgroundWhite),
|
2017-03-31 01:58:05 +02:00
|
|
|
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle),
|
|
|
|
new ThemeDescription(actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_SELECTOR, null, null, null, null, Theme.key_listSelector),
|
|
|
|
|
|
|
|
new ThemeDescription(emptyView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_emptyListPlaceholder),
|
2019-06-04 12:14:50 +02:00
|
|
|
new ThemeDescription(emptyView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle),
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow),
|
2017-03-31 01:58:05 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
new ThemeDescription(listView, 0, new Class[]{ManageChatUserCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{ManageChatUserCell.class}, new String[]{"statusColor"}, null, null, cellDelegate, Theme.key_windowBackgroundWhiteGrayText),
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{ManageChatUserCell.class}, new String[]{"statusOnlineColor"}, null, null, cellDelegate, Theme.key_windowBackgroundWhiteBlueText),
|
2019-09-10 12:56:11 +02:00
|
|
|
new ThemeDescription(listView, 0, new Class[]{ManageChatUserCell.class}, null, new Drawable[]{Theme.avatar_savedDrawable}, null, Theme.key_avatar_text),
|
2018-07-30 04:07:02 +02:00
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundRed),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundOrange),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundViolet),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundGreen),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundCyan),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundBlue),
|
|
|
|
new ThemeDescription(null, 0, null, null, null, cellDelegate, Theme.key_avatar_backgroundPink),
|
2019-06-04 12:14:50 +02:00
|
|
|
|
|
|
|
new ThemeDescription(listView, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader),
|
|
|
|
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKTAG, new Class[]{ManageChatTextCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKTAG, new Class[]{ManageChatTextCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayIcon),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKTAG, new Class[]{ManageChatTextCell.class}, new String[]{"imageView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueButton),
|
|
|
|
new ThemeDescription(listView, ThemeDescription.FLAG_CHECKTAG, new Class[]{ManageChatTextCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteBlueIcon),
|
2017-03-31 01:58:05 +02:00
|
|
|
};
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|