2013-10-25 15:19:00 +00:00
|
|
|
/*
|
2013-12-20 19:25:49 +00:00
|
|
|
* This is the source code of Telegram for Android v. 1.3.2.
|
2013-10-25 15:19:00 +00: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).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui;
|
|
|
|
|
|
|
|
import android.app.AlertDialog;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.content.DialogInterface;
|
2014-11-12 22:16:59 +00:00
|
|
|
import android.os.Build;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.os.Bundle;
|
2014-11-12 22:16:59 +00:00
|
|
|
import android.view.Gravity;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.LayoutInflater;
|
2014-10-07 20:14:27 +00:00
|
|
|
import android.view.MotionEvent;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
2014-11-12 22:16:59 +00:00
|
|
|
import android.widget.FrameLayout;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.ListView;
|
2014-11-12 22:16:59 +00:00
|
|
|
import android.widget.ProgressBar;
|
2013-10-25 15:19:00 +00:00
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.LocaleController;
|
2014-02-28 22:28:25 +00:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-07-02 22:39:05 +00:00
|
|
|
import org.telegram.android.MessagesController;
|
2014-08-22 14:24:33 +00:00
|
|
|
import org.telegram.android.NotificationCenter;
|
2013-10-25 15:19:00 +00:00
|
|
|
import org.telegram.messenger.R;
|
2014-06-20 00:18:13 +00:00
|
|
|
import org.telegram.ui.Adapters.BaseFragmentAdapter;
|
2014-11-12 22:16:59 +00:00
|
|
|
import org.telegram.ui.Cells.TextInfoCell;
|
2014-11-10 11:05:22 +00:00
|
|
|
import org.telegram.ui.Cells.UserCell;
|
2014-11-13 20:10:14 +00:00
|
|
|
import org.telegram.ui.ActionBar.ActionBar;
|
|
|
|
import org.telegram.ui.ActionBar.ActionBarMenu;
|
|
|
|
import org.telegram.ui.ActionBar.BaseFragment;
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-11-13 20:10:14 +00:00
|
|
|
public class BlockedUsersActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, ContactsActivity.ContactsActivityDelegate {
|
2014-11-17 02:44:57 +00:00
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
private ListView listView;
|
|
|
|
private ListAdapter listViewAdapter;
|
2014-11-12 22:16:59 +00:00
|
|
|
private FrameLayout progressView;
|
|
|
|
private TextView emptyTextView;
|
2013-10-25 15:19:00 +00:00
|
|
|
private int selectedUserId;
|
|
|
|
|
2014-04-02 17:36:57 +00:00
|
|
|
private final static int block_user = 1;
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
@Override
|
|
|
|
public boolean onFragmentCreate() {
|
|
|
|
super.onFragmentCreate();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().addObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFragmentDestroy() {
|
|
|
|
super.onFragmentDestroy();
|
2014-08-22 14:24:33 +00:00
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
|
|
|
|
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.blockedUsersDidLoaded);
|
|
|
|
MessagesController.getInstance().getBlockedUsers(false);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-06-03 23:31:48 +00:00
|
|
|
public View createView(LayoutInflater inflater, ViewGroup container) {
|
2013-10-25 15:19:00 +00:00
|
|
|
if (fragmentView == null) {
|
2014-11-11 22:16:17 +00:00
|
|
|
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
|
|
|
|
actionBar.setBackOverlay(R.layout.updating_state_layout);
|
|
|
|
actionBar.setTitle(LocaleController.getString("BlockedUsers", R.string.BlockedUsers));
|
|
|
|
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
|
2014-06-03 23:31:48 +00:00
|
|
|
@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);
|
2014-11-13 20:10:14 +00:00
|
|
|
fragment.setDelegate(BlockedUsersActivity.this);
|
2014-06-03 23:31:48 +00:00
|
|
|
presentFragment(fragment);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-11-11 22:16:17 +00:00
|
|
|
ActionBarMenu menu = actionBar.createMenu();
|
2014-06-03 23:31:48 +00:00
|
|
|
menu.addItem(block_user, R.drawable.plus);
|
|
|
|
|
2014-11-12 22:16:59 +00:00
|
|
|
fragmentView = new FrameLayout(getParentActivity());
|
|
|
|
FrameLayout frameLayout = (FrameLayout) fragmentView;
|
|
|
|
|
|
|
|
emptyTextView = new TextView(getParentActivity());
|
|
|
|
emptyTextView.setTextColor(0xff808080);
|
2014-11-17 02:44:57 +00:00
|
|
|
emptyTextView.setTextSize(20);
|
2014-11-12 22:16:59 +00:00
|
|
|
emptyTextView.setGravity(Gravity.CENTER);
|
|
|
|
emptyTextView.setVisibility(View.INVISIBLE);
|
|
|
|
emptyTextView.setText(LocaleController.getString("NoBlocked", R.string.NoBlocked));
|
|
|
|
frameLayout.addView(emptyTextView);
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) emptyTextView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.gravity = Gravity.TOP;
|
|
|
|
emptyTextView.setLayoutParams(layoutParams);
|
|
|
|
emptyTextView.setOnTouchListener(new View.OnTouchListener() {
|
2014-10-07 20:14:27 +00:00
|
|
|
@Override
|
|
|
|
public boolean onTouch(View v, MotionEvent event) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-11-12 22:16:59 +00:00
|
|
|
|
|
|
|
progressView = new FrameLayout(getParentActivity());
|
|
|
|
frameLayout.addView(progressView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
progressView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
ProgressBar progressBar = new ProgressBar(getParentActivity());
|
|
|
|
progressView.addView(progressBar);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) progressView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.WRAP_CONTENT;
|
|
|
|
layoutParams.gravity = Gravity.CENTER;
|
|
|
|
progressView.setLayoutParams(layoutParams);
|
|
|
|
|
|
|
|
listView = new ListView(getParentActivity());
|
|
|
|
listView.setEmptyView(emptyTextView);
|
|
|
|
listView.setVerticalScrollBarEnabled(false);
|
|
|
|
listView.setDivider(null);
|
|
|
|
listView.setDividerHeight(0);
|
|
|
|
listView.setAdapter(listViewAdapter = new ListAdapter(getParentActivity()));
|
|
|
|
if (Build.VERSION.SDK_INT >= 11) {
|
|
|
|
listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-11-12 22:16:59 +00:00
|
|
|
frameLayout.addView(listView);
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
|
|
|
|
layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT;
|
|
|
|
listView.setLayoutParams(layoutParams);
|
|
|
|
|
2013-10-25 15:19:00 +00:00
|
|
|
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (i < MessagesController.getInstance().blockedUsers.size()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
Bundle args = new Bundle();
|
2014-08-22 14:24:33 +00:00
|
|
|
args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i));
|
2014-11-10 11:05:22 +00:00
|
|
|
presentFragment(new ProfileActivity(args));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
|
|
|
|
@Override
|
|
|
|
public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (i < 0 || i >= MessagesController.getInstance().blockedUsers.size() || getParentActivity() == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return true;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
selectedUserId = MessagesController.getInstance().blockedUsers.get(i);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-06-03 23:31:48 +00:00
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
2013-10-25 15:19:00 +00:00
|
|
|
|
2014-03-22 22:31:55 +00:00
|
|
|
CharSequence[] items = new CharSequence[] {LocaleController.getString("Unblock", R.string.Unblock)};
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
builder.setItems(items, new DialogInterface.OnClickListener() {
|
|
|
|
@Override
|
|
|
|
public void onClick(DialogInterface dialogInterface, int i) {
|
|
|
|
if (i == 0) {
|
2014-08-22 14:24:33 +00:00
|
|
|
MessagesController.getInstance().unblockUser(selectedUserId);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2014-06-06 23:35:21 +00:00
|
|
|
showAlertDialog(builder);
|
2013-10-25 15:19:00 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2014-11-12 22:16:59 +00:00
|
|
|
|
|
|
|
if (MessagesController.getInstance().loadingBlockedUsers) {
|
|
|
|
progressView.setVisibility(View.VISIBLE);
|
|
|
|
emptyTextView.setVisibility(View.GONE);
|
|
|
|
listView.setEmptyView(null);
|
|
|
|
} else {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
listView.setEmptyView(emptyTextView);
|
|
|
|
}
|
2013-10-25 15:19:00 +00:00
|
|
|
} else {
|
|
|
|
ViewGroup parent = (ViewGroup)fragmentView.getParent();
|
|
|
|
if (parent != null) {
|
|
|
|
parent.removeView(fragmentView);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fragmentView;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void didReceivedNotification(int id, Object... args) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (id == NotificationCenter.updateInterfaces) {
|
2014-02-04 18:36:55 +00:00
|
|
|
int mask = (Integer)args[0];
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
updateVisibleRows(mask);
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
} else if (id == NotificationCenter.blockedUsersDidLoaded) {
|
|
|
|
if (progressView != null) {
|
|
|
|
progressView.setVisibility(View.GONE);
|
|
|
|
}
|
|
|
|
if (listView != null && listView.getEmptyView() == null) {
|
2014-11-12 22:16:59 +00:00
|
|
|
listView.setEmptyView(emptyTextView);
|
2014-08-22 14:24:33 +00:00
|
|
|
}
|
|
|
|
if (listViewAdapter != null) {
|
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
2014-02-04 18:36:55 +00: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);
|
2014-11-10 11:05:22 +00:00
|
|
|
if (child instanceof UserCell) {
|
|
|
|
((UserCell) child).update(mask);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onResume() {
|
2014-06-04 16:00:42 +00:00
|
|
|
super.onResume();
|
2014-06-03 23:31:48 +00:00
|
|
|
if (listViewAdapter != null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
listViewAdapter.notifyDataSetChanged();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-08-22 14:24:33 +00:00
|
|
|
public void didSelectContact(final TLRPC.User user, String param) {
|
|
|
|
if (user == null) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
MessagesController.getInstance().blockUser(user.id);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
2014-06-20 00:18:13 +00:00
|
|
|
private class ListAdapter extends BaseFragmentAdapter {
|
2013-10-25 15:19:00 +00:00
|
|
|
private Context mContext;
|
|
|
|
|
|
|
|
public ListAdapter(Context context) {
|
|
|
|
mContext = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean areAllItemsEnabled() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEnabled(int i) {
|
2014-08-22 14:24:33 +00:00
|
|
|
return i != MessagesController.getInstance().blockedUsers.size();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getCount() {
|
2014-08-22 14:24:33 +00:00
|
|
|
if (MessagesController.getInstance().blockedUsers.isEmpty()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
return MessagesController.getInstance().blockedUsers.size() + 1;
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getItem(int i) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public long getItemId(int i) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasStableIds() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public View getView(int i, View view, ViewGroup viewGroup) {
|
|
|
|
int type = getItemViewType(i);
|
|
|
|
if (type == 0) {
|
|
|
|
if (view == null) {
|
2014-11-12 22:16:59 +00:00
|
|
|
view = new UserCell(mContext, 1);
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
2014-08-22 14:24:33 +00:00
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i));
|
2014-11-12 22:16:59 +00:00
|
|
|
((UserCell)view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown), 0);
|
2013-10-25 15:19:00 +00:00
|
|
|
} else if (type == 1) {
|
|
|
|
if (view == null) {
|
2014-11-12 22:16:59 +00:00
|
|
|
view = new TextInfoCell(mContext);
|
|
|
|
((TextInfoCell) view).setText(LocaleController.getString("UnblockText", R.string.UnblockText));
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getItemViewType(int i) {
|
2014-08-22 14:24:33 +00:00
|
|
|
if(i == MessagesController.getInstance().blockedUsers.size()) {
|
2013-10-25 15:19:00 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getViewTypeCount() {
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isEmpty() {
|
2014-08-22 14:24:33 +00:00
|
|
|
return MessagesController.getInstance().blockedUsers.isEmpty();
|
2013-10-25 15:19:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|