2014-11-17 03:44:57 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 2.0.x.
|
|
|
|
* 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;
|
|
|
|
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;
|
|
|
|
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.messenger.support.widget.LinearLayoutManager;
|
|
|
|
import org.telegram.messenger.support.widget.RecyclerView;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.AlertDialog;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.ActionBar.ThemeDescription;
|
2014-11-17 03:44:57 +01:00
|
|
|
import org.telegram.ui.Cells.TextInfoCell;
|
|
|
|
import org.telegram.ui.Cells.UserCell;
|
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;
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public class PrivacyUsersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
|
2014-11-17 03:44:57 +01:00
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public interface PrivacyActivityDelegate {
|
2015-03-19 00:09:45 +01:00
|
|
|
void didUpdatedUserList(ArrayList<Integer> ids, boolean added);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
private RecyclerListView listView;
|
2014-11-17 03:44:57 +01:00
|
|
|
private ListAdapter listViewAdapter;
|
2017-03-31 01:58:05 +02:00
|
|
|
private EmptyTextProgressView emptyView;
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
private int selectedUserId;
|
|
|
|
|
2016-03-06 02:49:31 +01: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
|
|
|
|
|
|
|
private final static int block_user = 1;
|
|
|
|
|
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;
|
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);
|
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);
|
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);
|
2016-03-06 02:49:31 +01:00
|
|
|
if (isGroup) {
|
|
|
|
if (isAlwaysShare) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AlwaysAllow", R.string.AlwaysAllow));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("NeverAllow", R.string.NeverAllow));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
2016-03-06 02:49:31 +01:00
|
|
|
if (isAlwaysShare) {
|
|
|
|
actionBar.setTitle(LocaleController.getString("AlwaysShareWithTitle", R.string.AlwaysShareWithTitle));
|
|
|
|
} else {
|
|
|
|
actionBar.setTitle(LocaleController.getString("NeverShareWithTitle", R.string.NeverShareWithTitle));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
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(isAlwaysShare ? "isAlwaysShare" : "isNeverShare", true);
|
2016-03-06 02:49:31 +01:00
|
|
|
args.putBoolean("isGroup", isGroup);
|
2015-04-09 20:00:14 +02:00
|
|
|
GroupCreateActivity fragment = new GroupCreateActivity(args);
|
2019-01-23 18:03:33 +01:00
|
|
|
fragment.setDelegate(ids -> {
|
|
|
|
for (Integer id1 : ids) {
|
|
|
|
if (uidArray.contains(id1)) {
|
|
|
|
continue;
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
uidArray.add(id1);
|
|
|
|
}
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didUpdatedUserList(uidArray, true);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
presentFragment(fragment);
|
2014-11-17 03:44:57 +01: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.showTextView();
|
|
|
|
emptyView.setText(LocaleController.getString("NoContacts", R.string.NoContacts));
|
|
|
|
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);
|
2015-04-09 20:00:14 +02:00
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
2017-03-31 01:58:05 +02:00
|
|
|
listView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, 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) -> {
|
|
|
|
if (position < uidArray.size()) {
|
|
|
|
Bundle args = new Bundle();
|
|
|
|
args.putInt("user_id", uidArray.get(position));
|
|
|
|
presentFragment(new ProfileActivity(args));
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
});
|
2019-01-23 18:03:33 +01:00
|
|
|
listView.setOnItemLongClickListener((view, position) -> {
|
|
|
|
if (position < 0 || position >= uidArray.size() || getParentActivity() == null) {
|
|
|
|
return false;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
selectedUserId = uidArray.get(position);
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
|
|
|
CharSequence[] items = new CharSequence[]{LocaleController.getString("Delete", R.string.Delete)};
|
|
|
|
builder.setItems(items, (dialogInterface, i) -> {
|
|
|
|
if (i == 0) {
|
|
|
|
uidArray.remove((Integer) selectedUserId);
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didUpdatedUserList(uidArray, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
showDialog(builder.create());
|
|
|
|
return true;
|
2015-04-09 20:00:14 +02:00
|
|
|
});
|
|
|
|
|
2014-11-17 03:44:57 +01:00
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
if (child instanceof UserCell) {
|
|
|
|
((UserCell) child).update(mask);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-06 02:49:31 +01:00
|
|
|
public void setDelegate(PrivacyActivityDelegate privacyActivityDelegate) {
|
|
|
|
delegate = privacyActivityDelegate;
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
|
|
|
super.onResume();
|
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2017-03-31 01:58:05 +02:00
|
|
|
public boolean isEnabled(RecyclerView.ViewHolder holder) {
|
|
|
|
return holder.getAdapterPosition() != uidArray.size();
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemCount() {
|
2014-11-17 03:44:57 +01:00
|
|
|
if (uidArray.isEmpty()) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return uidArray.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
|
|
|
View view;
|
|
|
|
switch (viewType) {
|
|
|
|
case 0:
|
2016-03-16 13:26:32 +01:00
|
|
|
view = new UserCell(mContext, 1, 0, false);
|
2017-03-31 01:58:05 +02:00
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
default:
|
2014-11-17 03:44:57 +01:00
|
|
|
view = new TextInfoCell(mContext);
|
|
|
|
((TextInfoCell) view).setText(LocaleController.getString("RemoveFromListText", R.string.RemoveFromListText));
|
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) {
|
|
|
|
if (holder.getItemViewType() == 0) {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(uidArray.get(position));
|
2017-03-31 01:58:05 +02:00
|
|
|
((UserCell) holder.itemView).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0);
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-03-31 01:58:05 +02:00
|
|
|
public int getItemViewType(int i) {
|
|
|
|
if (i == uidArray.size()) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
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);
|
|
|
|
if (child instanceof UserCell) {
|
|
|
|
((UserCell) child).update(0);
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
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(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),
|
2018-07-30 04:07:02 +02:00
|
|
|
new ThemeDescription(listView, 0, new Class[]{UserCell.class}, new String[]{"statusColor"}, null, null, cellDelegate, Theme.key_windowBackgroundWhiteGrayText),
|
2019-01-23 18:03:33 +01:00
|
|
|
new ThemeDescription(listView, 0, new Class[]{UserCell.class}, null, new Drawable[]{Theme.avatar_broadcastDrawable, 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),
|
2017-03-31 01:58:05 +02:00
|
|
|
};
|
2014-11-17 03:44:57 +01:00
|
|
|
}
|
|
|
|
}
|