NekoX/TMessagesProj/src/main/java/org/telegram/ui/BlockedUsersActivity.java

300 lines
13 KiB
Java
Raw Normal View History

2013-10-25 17:19:00 +02:00
/*
2015-10-29 18:10:07 +01:00
* This is the source code of Telegram for Android v. 3.x.x.
2013-10-25 17:19:00 +02: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).
*
2017-03-31 01:58:05 +02:00
* Copyright Nikolai Kudashov, 2013-2017.
2013-10-25 17:19:00 +02:00
*/
package org.telegram.ui;
import android.content.Context;
import android.content.DialogInterface;
2017-03-31 01:58:05 +02:00
import android.graphics.drawable.Drawable;
2013-10-25 17:19:00 +02:00
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
2014-11-12 23:16:59 +01:00
import android.widget.FrameLayout;
2013-10-25 17:19:00 +02:00
import org.telegram.PhoneFormat.PhoneFormat;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.LocaleController;
2017-03-31 01:58:05 +02:00
import org.telegram.messenger.support.widget.LinearLayoutManager;
import org.telegram.messenger.support.widget.RecyclerView;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
2013-10-25 17:19:00 +02: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;
2014-11-12 23:16:59 +01:00
import org.telegram.ui.Cells.TextInfoCell;
2014-11-10 12:05:22 +01:00
import org.telegram.ui.Cells.UserCell;
2014-11-13 21:10:14 +01:00
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.BaseFragment;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.EmptyTextProgressView;
import org.telegram.ui.Components.LayoutHelper;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.RecyclerListView;
2013-10-25 17:19:00 +02:00
2014-11-13 21:10:14 +01:00
public class BlockedUsersActivity 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;
2013-10-25 17:19:00 +02:00
private ListAdapter listViewAdapter;
2017-03-31 01:58:05 +02:00
private EmptyTextProgressView emptyView;
2013-10-25 17:19:00 +02:00
private int selectedUserId;
private final static int block_user = 1;
2013-10-25 17:19:00 +02:00
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
2015-09-24 22:52:02 +02:00
MessagesController.getInstance().getBlockedUsers(false);
2013-10-25 17:19:00 +02:00
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded);
2013-10-25 17:19:00 +02: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);
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
} else if (id == block_user) {
Bundle args = new Bundle();
args.putBoolean("onlyUsers", true);
args.putBoolean("destroyAfterSelect", true);
args.putBoolean("returnAsResult", true);
ContactsActivity fragment = new ContactsActivity(args);
fragment.setDelegate(BlockedUsersActivity.this);
presentFragment(fragment);
2014-10-07 22:14:27 +02:00
}
2013-10-25 17:19:00 +02:00
}
2015-04-09 20:00:14 +02:00
});
ActionBarMenu menu = actionBar.createMenu();
menu.addItem(block_user, R.drawable.plus);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
2017-03-31 01:58:05 +02:00
emptyView = new EmptyTextProgressView(context);
emptyView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
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);
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
2015-04-09 20:00:14 +02:00
listView.setVerticalScrollBarEnabled(false);
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);
2015-05-21 23:27:27 +02:00
frameLayout.addView(listView, 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.setOnItemClickListener(new RecyclerListView.OnItemClickListener() {
2015-04-09 20:00:14 +02:00
@Override
2017-03-31 01:58:05 +02:00
public void onItemClick(View view, int position) {
if (position >= MessagesController.getInstance().blockedUsers.size()) {
return;
2013-10-25 17:19:00 +02:00
}
2017-03-31 01:58:05 +02:00
Bundle args = new Bundle();
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(position));
presentFragment(new ProfileActivity(args));
2015-04-09 20:00:14 +02:00
}
});
2013-10-25 17:19:00 +02:00
2017-03-31 01:58:05 +02:00
listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListener() {
2015-04-09 20:00:14 +02:00
@Override
2017-03-31 01:58:05 +02:00
public boolean onItemClick(View view, int position) {
if (position >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
2013-10-25 17:19:00 +02:00
return true;
}
2017-03-31 01:58:05 +02:00
selectedUserId = MessagesController.getInstance().blockedUsers.get(position);
2015-04-09 20:00:14 +02:00
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
CharSequence[] items = new CharSequence[]{LocaleController.getString("Unblock", R.string.Unblock)};
builder.setItems(items, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) {
MessagesController.getInstance().unblockUser(selectedUserId);
}
}
});
2015-05-21 23:27:27 +02:00
showDialog(builder.create());
2014-11-12 23:16:59 +01:00
2015-04-09 20:00:14 +02:00
return true;
2014-11-12 23:16:59 +01:00
}
2015-04-09 20:00:14 +02:00
});
if (MessagesController.getInstance().loadingBlockedUsers) {
2017-03-31 01:58:05 +02:00
emptyView.showProgress();
2013-10-25 17:19:00 +02:00
} else {
2017-03-31 01:58:05 +02:00
emptyView.showTextView();
2013-10-25 17:19:00 +02:00
}
return fragmentView;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.updateInterfaces) {
2017-03-31 01:58:05 +02:00
int mask = (Integer) args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
updateVisibleRows(mask);
}
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
2017-03-31 01:58:05 +02:00
emptyView.showTextView();
if (listViewAdapter != null) {
listViewAdapter.notifyDataSetChanged();
}
}
}
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);
2014-11-10 12:05:22 +01:00
if (child instanceof UserCell) {
((UserCell) child).update(mask);
2013-10-25 17:19:00 +02:00
}
}
}
@Override
public void onResume() {
super.onResume();
if (listViewAdapter != null) {
2013-10-25 17:19:00 +02:00
listViewAdapter.notifyDataSetChanged();
}
}
@Override
2017-07-08 18:32:04 +02:00
public void didSelectContact(final TLRPC.User user, String param, ContactsActivity activity) {
if (user == null) {
2013-10-25 17:19:00 +02:00
return;
}
MessagesController.getInstance().blockUser(user.id);
2013-10-25 17:19:00 +02:00
}
2017-03-31 01:58:05 +02:00
private class ListAdapter extends RecyclerListView.SelectionAdapter {
2013-10-25 17:19:00 +02:00
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
2017-03-31 01:58:05 +02:00
public int getItemCount() {
if (MessagesController.getInstance().blockedUsers.isEmpty()) {
2013-10-25 17:19:00 +02:00
return 0;
}
return MessagesController.getInstance().blockedUsers.size() + 1;
2013-10-25 17:19:00 +02:00
}
@Override
2017-03-31 01:58:05 +02:00
public boolean isEnabled(RecyclerView.ViewHolder holder) {
return holder.getItemViewType() == 0;
2013-10-25 17:19:00 +02:00
}
@Override
2017-03-31 01:58:05 +02:00
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view;
switch (viewType) {
case 0:
view = new UserCell(mContext, 1, 0, false);
break;
case 1:
default:
view = new TextInfoCell(mContext);
((TextInfoCell) view).setText(LocaleController.getString("UnblockText", R.string.UnblockText));
break;
}
return new RecyclerListView.Holder(view);
2013-10-25 17:19:00 +02:00
}
@Override
2017-03-31 01:58:05 +02:00
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
if (holder.getItemViewType() == 0) {
TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(position));
2014-11-21 11:59:05 +01:00
if (user != null) {
2016-03-16 13:26:32 +01:00
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);
}
2017-03-31 01:58:05 +02:00
((UserCell) holder.itemView).setData(user, null, number, 0);
2013-10-25 17:19:00 +02:00
}
}
}
@Override
public int getItemViewType(int i) {
2017-03-31 01:58:05 +02:00
if (i == MessagesController.getInstance().blockedUsers.size()) {
2013-10-25 17:19:00 +02:00
return 1;
}
return 0;
}
2017-03-31 01:58:05 +02:00
}
2013-10-25 17:19:00 +02:00
2017-03-31 01:58:05 +02:00
@Override
public ThemeDescription[] getThemeDescriptions() {
ThemeDescription.ThemeDescriptionDelegate сellDelegate = new ThemeDescription.ThemeDescriptionDelegate() {
@Override
public void didSetColor(int color) {
int count = listView.getChildCount();
for (int a = 0; a < count; a++) {
View child = listView.getChildAt(a);
if (child instanceof UserCell) {
((UserCell) child).update(0);
}
}
}
};
return new ThemeDescription[]{
new ThemeDescription(fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite),
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),
new ThemeDescription(emptyView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle),
new ThemeDescription(listView, 0, new Class[]{TextInfoCell.class}, new String[]{"textView"}, null, null, null, Theme.key_windowBackgroundWhiteGrayText5),
new ThemeDescription(listView, 0, new Class[]{UserCell.class}, new String[]{"nameTextView"}, null, null, null, Theme.key_windowBackgroundWhiteBlackText),
new ThemeDescription(listView, 0, new Class[]{UserCell.class}, new String[]{"statusColor"}, null, null, сellDelegate, Theme.key_windowBackgroundWhiteGrayText),
new ThemeDescription(listView, 0, new Class[]{UserCell.class}, null, new Drawable[]{Theme.avatar_photoDrawable, Theme.avatar_broadcastDrawable}, null, Theme.key_avatar_text),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundRed),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundOrange),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundViolet),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundGreen),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundCyan),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundBlue),
new ThemeDescription(null, 0, null, null, null, сellDelegate, Theme.key_avatar_backgroundPink),
};
2013-10-25 17:19:00 +02:00
}
}