Show username and address.

This commit is contained in:
B. Petersen
2016-10-08 17:10:19 +02:00
parent ec9acc9db6
commit fb3e2b5a5a
8 changed files with 77 additions and 698 deletions
+1 -1
View File
@@ -130,7 +130,7 @@ JNIEXPORT jstring Java_org_telegram_messenger_MrMailbox_MrMailboxGetConfig(JNIEn
{
CHAR_REF(key);
CHAR_REF(def);
const char* temp = (jlong)mrmailbox_get_config((mrmailbox_t*)hMailbox, keyPtr, def);
char* temp = mrmailbox_get_config((mrmailbox_t*)hMailbox, keyPtr, defPtr);
jstring ret = JSTRING_NEW(temp);
free(temp);
CHAR_UNREF(key);
@@ -32,17 +32,19 @@ public class DrawerLayoutAdapter extends BaseAdapter {
public final static int iEmptyBelowProfile = 1;
public final static int iNewGroup = 2;
public final static int iNewSecretChat = 3;
public final static int iNewChannel = 4;
public final static int iDivider = 5;
public final static int iContacts = 6;
public final static int iInviteFriends = 7;
public final static int iSettings = 8;
public final static int iFaq = 9;
public final static int iCount = 10;
public final static int iNewChannel = -1;
public final static int iContacts = 4;
public final static int iInviteFriends = 5;
public final static int iDivider = 6;
public final static int iSettings = 7;
public final static int iFaq = 8;
public final static int iCount = 9;
// disabled:
// EDIT BY MR
public final static int typeProfile = 0;
public final static int typeEmpty = 1;
public final static int typeDivider = 2;
public final static int typeButton = 3;
// /EDIT BY MR
public DrawerLayoutAdapter(Context context) {
mContext = context;
@@ -81,20 +83,20 @@ public class DrawerLayoutAdapter extends BaseAdapter {
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
int type = getItemViewType(i);
if (type == 0) {
if (type == typeProfile) {
if (view == null) {
view = new DrawerProfileCell(mContext);
}
((DrawerProfileCell) view).setUser(MessagesController.getInstance().getUser(UserConfig.getClientUserId()));
} else if (type == 1) {
} else if (type == typeEmpty) {
if (view == null) {
view = new EmptyCell(mContext, AndroidUtilities.dp(8));
}
} else if (type == 2) {
} else if (type == typeDivider) {
if (view == null) {
view = new DividerCell(mContext);
}
} else if (type == 3) {
} else if (type == typeButton) {
if (view == null) {
view = new DrawerActionCell(mContext);
}
@@ -122,13 +124,13 @@ public class DrawerLayoutAdapter extends BaseAdapter {
@Override
public int getItemViewType(int i) {
if (i == iProfile) {
return 0;
return typeProfile;
} else if (i == iEmptyBelowProfile) {
return 1;
return typeEmpty;
} else if (i == iDivider) {
return 2;
return typeDivider;
}
return 3;
return typeButton;
}
@Override
@@ -28,19 +28,21 @@ import android.widget.TextView;
import org.telegram.PhoneFormat.PhoneFormat;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MrMailbox;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.ApplicationLoader;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.R;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.Components.AvatarDrawable;
//import org.telegram.ui.Components.AvatarDrawable; -- EDIT BY MR
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.LayoutHelper;
import org.telegram.ui.ActionBar.Theme;
public class DrawerProfileCell extends FrameLayout {
private BackupImageView avatarImageView;
//private BackupImageView avatarImageView; -- EDIT BY MR
private TextView nameTextView;
private TextView phoneTextView;
private ImageView shadowView;
@@ -57,15 +59,17 @@ public class DrawerProfileCell extends FrameLayout {
shadowView.setVisibility(INVISIBLE);
shadowView.setScaleType(ImageView.ScaleType.FIT_XY);
shadowView.setImageResource(R.drawable.bottom_shadow);
addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 70, Gravity.LEFT | Gravity.BOTTOM));
addView(shadowView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 100/*EDIT BY MR, was 70*/, Gravity.LEFT | Gravity.BOTTOM));
/* EDIT BY MR
avatarImageView = new BackupImageView(context);
avatarImageView.getImageReceiver().setRoundRadius(AndroidUtilities.dp(32));
addView(avatarImageView, LayoutHelper.createFrame(64, 64, Gravity.LEFT | Gravity.BOTTOM, 16, 0, 0, 67));
*/
nameTextView = new TextView(context);
nameTextView.setTextColor(0xffffffff);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 22 /*EDIT BY MR, was 15*/);
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setLines(1);
nameTextView.setMaxLines(1);
@@ -86,13 +90,14 @@ public class DrawerProfileCell extends FrameLayout {
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int mrHeight = 180; // EDIT BY MR -- was: 148
if (Build.VERSION.SDK_INT >= 21) {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148) + AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(mrHeight) + AndroidUtilities.statusBarHeight, MeasureSpec.EXACTLY));
} else {
try {
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(148), MeasureSpec.EXACTLY));
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(mrHeight), MeasureSpec.EXACTLY));
} catch (Exception e) {
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(148));
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(mrHeight));
FileLog.e("tmessages", e);
}
}
@@ -107,7 +112,7 @@ public class DrawerProfileCell extends FrameLayout {
shadowView.getDrawable().setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
}
if (ApplicationLoader.isCustomTheme() && backgroundDrawable != null) {
if (/*ApplicationLoader.isCustomTheme() && EDIT BY MR -- also show the default wallpaper in drawer*/ backgroundDrawable != null) {
phoneTextView.setTextColor(0xffffffff);
shadowView.setVisibility(VISIBLE);
if (backgroundDrawable instanceof ColorDrawable) {
@@ -141,10 +146,27 @@ public class DrawerProfileCell extends FrameLayout {
if (user.photo != null) {
photo = user.photo.photo_small;
}
/* EDIT BY MR */
String displayname = MrMailbox.MrMailboxGetConfig(MrMailbox.hMailbox, "displayname", LocaleController.getString("YourAccount", R.string.YourAccount));
String addr;
if( MrMailbox.MrMailboxIsConfigured(MrMailbox.hMailbox)!=0) {
addr = MrMailbox.MrMailboxGetConfig(MrMailbox.hMailbox, "addr", "");
}
else {
addr = LocaleController.getString("NotLoggedIn", R.string.NotLoggedIn);
}
nameTextView.setText(displayname);
phoneTextView.setText(addr);
/*
nameTextView.setText(UserObject.getUserName(user));
phoneTextView.setText(PhoneFormat.getInstance().format("+" + user.phone));
AvatarDrawable avatarDrawable = new AvatarDrawable(user);
avatarDrawable.setColor(Theme.ACTION_BAR_MAIN_AVATAR_COLOR);
avatarImageView.setImage(photo, "50_50", avatarDrawable);
/EDIT BY MR */
}
}
@@ -499,11 +499,13 @@ public class ProfileActivity extends BaseFragment implements NotificationCenter.
FileLog.e("tmessages", e);
}
} else if (id == set_admins) {
/* EDIT BY MR
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
SetAdminsActivity fragment = new SetAdminsActivity(args);
fragment.setChatInfo(info);
presentFragment(fragment);
*/
} else if (id == convert_to_supergroup) {
Bundle args = new Bundle();
args.putInt("chat_id", chat_id);
@@ -1,669 +0,0 @@
/*
* This is the source code of Telegram for Android v. 3.x.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).
*
* Copyright Nikolai Kudashov, 2013-2016.
*/
package org.telegram.ui;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ListView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ContactsController;
import org.telegram.messenger.FileLog;
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.NotificationCenter;
import org.telegram.messenger.R;
import org.telegram.messenger.UserConfig;
import org.telegram.messenger.Utilities;
import org.telegram.tgnet.TLRPC;
import org.telegram.ui.ActionBar.ActionBar;
import org.telegram.ui.ActionBar.ActionBarMenu;
import org.telegram.ui.ActionBar.ActionBarMenuItem;
import org.telegram.ui.ActionBar.BaseFragment;
import org.telegram.ui.Adapters.BaseFragmentAdapter;
import org.telegram.ui.Cells.TextCheckCell;
import org.telegram.ui.Cells.TextInfoPrivacyCell;
import org.telegram.ui.Cells.UserCell;
import org.telegram.ui.Components.EmptyTextProgressView;
import org.telegram.ui.Components.LayoutHelper;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Timer;
import java.util.TimerTask;
public class SetAdminsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
private ListAdapter listAdapter;
private SearchAdapter searchAdapter;
private EmptyTextProgressView searchEmptyView;
private ListView listView;
private TLRPC.ChatFull info;
private ArrayList<TLRPC.ChatParticipant> participants = new ArrayList<>();
private int chat_id;
private TLRPC.Chat chat;
private ActionBarMenuItem searchItem;
private boolean searching;
private boolean searchWas;
private int allAdminsRow;
private int allAdminsInfoRow;
private int usersStartRow;
private int usersEndRow;
private int rowCount;
public SetAdminsActivity(Bundle args) {
super(args);
chat_id = args.getInt("chat_id");
}
@Override
public boolean onFragmentCreate() {
super.onFragmentCreate();
NotificationCenter.getInstance().addObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().addObserver(this, NotificationCenter.updateInterfaces);
return true;
}
@Override
public void onFragmentDestroy() {
super.onFragmentDestroy();
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.chatInfoDidLoaded);
NotificationCenter.getInstance().removeObserver(this, NotificationCenter.updateInterfaces);
}
@Override
public View createView(Context context) {
searching = false;
searchWas = false;
actionBar.setBackButtonImage(R.drawable.ic_ab_back);
actionBar.setAllowOverlayTitle(true);
actionBar.setTitle(LocaleController.getString("SetAdminsTitle", R.string.SetAdminsTitle));
actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
@Override
public void onItemClick(int id) {
if (id == -1) {
finishFragment();
}
}
});
ActionBarMenu menu = actionBar.createMenu();
searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
@Override
public void onSearchExpand() {
searching = true;
listView.setEmptyView(searchEmptyView);
}
@Override
public void onSearchCollapse() {
searching = false;
searchWas = false;
if (listView != null) {
listView.setEmptyView(null);
searchEmptyView.setVisibility(View.GONE);
if (listView.getAdapter() != listAdapter) {
listView.setAdapter(listAdapter);
fragmentView.setBackgroundColor(0xfff0f0f0);
}
}
if (searchAdapter != null) {
searchAdapter.search(null);
}
}
@Override
public void onTextChanged(EditText editText) {
String text = editText.getText().toString();
if (text.length() != 0) {
searchWas = true;
if (searchAdapter != null && listView.getAdapter() != searchAdapter) {
listView.setAdapter(searchAdapter);
fragmentView.setBackgroundColor(0xffffffff);
}
if (searchEmptyView != null && listView.getEmptyView() != searchEmptyView) {
searchEmptyView.showTextView();
listView.setEmptyView(searchEmptyView);
}
}
if (searchAdapter != null) {
searchAdapter.search(text);
}
}
});
searchItem.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));
listAdapter = new ListAdapter(context);
searchAdapter = new SearchAdapter(context);
fragmentView = new FrameLayout(context);
FrameLayout frameLayout = (FrameLayout) fragmentView;
fragmentView.setBackgroundColor(0xfff0f0f0);
listView = new ListView(context);
listView.setDivider(null);
listView.setDividerHeight(0);
listView.setVerticalScrollBarEnabled(false);
listView.setDrawSelectorOnTop(true);
frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
listView.setAdapter(listAdapter);
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, final int i, long l) {
if (listView.getAdapter() == searchAdapter || i >= usersStartRow && i < usersEndRow) {
UserCell userCell = (UserCell) view;
chat = MessagesController.getInstance().getChat(chat_id);
TLRPC.ChatParticipant participant;
int index = -1;
if (listView.getAdapter() == searchAdapter) {
participant = searchAdapter.getItem(i);
for (int a = 0; a < participants.size(); a++) {
TLRPC.ChatParticipant p = participants.get(a);
if (p.user_id == participant.user_id) {
index = a;
break;
}
}
} else {
participant = participants.get(index = i - usersStartRow);
}
if (index != -1 && !(participant instanceof TLRPC.TL_chatParticipantCreator)) {
TLRPC.ChatParticipant newParticipant;
if (participant instanceof TLRPC.TL_chatParticipant) {
newParticipant = new TLRPC.TL_chatParticipantAdmin();
newParticipant.user_id = participant.user_id;
newParticipant.date = participant.date;
newParticipant.inviter_id = participant.inviter_id;
} else {
newParticipant = new TLRPC.TL_chatParticipant();
newParticipant.user_id = participant.user_id;
newParticipant.date = participant.date;
newParticipant.inviter_id = participant.inviter_id;
}
participants.set(index, newParticipant);
index = info.participants.participants.indexOf(participant);
if (index != -1) {
info.participants.participants.set(index, newParticipant);
}
if (listView.getAdapter() == searchAdapter) {
searchAdapter.searchResult.set(i, newParticipant);
}
participant = newParticipant;
userCell.setChecked(!(participant instanceof TLRPC.TL_chatParticipant) || chat != null && !chat.admins_enabled, true);
if (chat != null && chat.admins_enabled) {
MessagesController.getInstance().toggleUserAdmin(chat_id, participant.user_id, !(participant instanceof TLRPC.TL_chatParticipant));
}
}
} else {
if (i == allAdminsRow) {
chat = MessagesController.getInstance().getChat(chat_id);
if (chat != null) {
chat.admins_enabled = !chat.admins_enabled;
((TextCheckCell) view).setChecked(!chat.admins_enabled);
MessagesController.getInstance().toggleAdminMode(chat_id, chat.admins_enabled);
}
}
}
}
});
searchEmptyView = new EmptyTextProgressView(context);
searchEmptyView.setVisibility(View.GONE);
searchEmptyView.setShowAtCenter(true);
searchEmptyView.setText(LocaleController.getString("NoResult", R.string.NoResult));
frameLayout.addView(searchEmptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
searchEmptyView.showTextView();
updateRowsIds();
return fragmentView;
}
@Override
public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.chatInfoDidLoaded) {
TLRPC.ChatFull chatFull = (TLRPC.ChatFull) args[0];
if (chatFull.id == chat_id) {
info = chatFull;
updateChatParticipants();
updateRowsIds();
}
} if (id == NotificationCenter.updateInterfaces) {
int mask = (Integer) args[0];
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0 || (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
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(mask);
}
}
}
}
}
}
@Override
public void onResume() {
super.onResume();
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
public void setChatInfo(TLRPC.ChatFull chatParticipants) {
info = chatParticipants;
updateChatParticipants();
}
private int getChatAdminParticipantType(TLRPC.ChatParticipant participant) {
if (participant instanceof TLRPC.TL_chatParticipantCreator) {
return 0;
} else if (participant instanceof TLRPC.TL_chatParticipantAdmin) {
return 1;
} else {
return 2;
}
}
private void updateChatParticipants() {
if (info == null) {
return;
}
if (participants.size() != info.participants.participants.size()) {
participants.clear();
participants.addAll(info.participants.participants);
try {
Collections.sort(participants, new Comparator<TLRPC.ChatParticipant>() {
@Override
public int compare(TLRPC.ChatParticipant lhs, TLRPC.ChatParticipant rhs) {
int type1 = getChatAdminParticipantType(lhs);
int type2 = getChatAdminParticipantType(rhs);
if (type1 > type2) {
return 1;
} else if (type1 < type2) {
return -1;
} else if (type1 == type2) {
TLRPC.User user1 = MessagesController.getInstance().getUser(rhs.user_id);
TLRPC.User user2 = MessagesController.getInstance().getUser(lhs.user_id);
int status1 = 0;
int status2 = 0;
if (user1 != null && user1.status != null) {
status1 = user1.status.expires;
}
if (user2 != null && user2.status != null) {
status2 = user2.status.expires;
}
if (status1 > 0 && status2 > 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 < 0) {
if (status1 > status2) {
return 1;
} else if (status1 < status2) {
return -1;
}
return 0;
} else if (status1 < 0 && status2 > 0 || status1 == 0 && status2 != 0) {
return -1;
} else if (status2 < 0 && status1 > 0 || status2 == 0 && status1 != 0) {
return 1;
}
}
return 0;
}
});
} catch (Exception e) {
FileLog.e("tmessages", e);
}
}
}
private void updateRowsIds() {
rowCount = 0;
allAdminsRow = rowCount++;
allAdminsInfoRow = rowCount++;
if (info != null) {
usersStartRow = rowCount;
rowCount += participants.size();
usersEndRow = rowCount++;
if (searchItem != null && !searchWas) {
searchItem.setVisibility(View.VISIBLE);
}
} else {
usersStartRow = -1;
usersEndRow = -1;
if (searchItem != null) {
searchItem.setVisibility(View.GONE);
}
}
if (listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
private class ListAdapter extends BaseFragmentAdapter {
private Context mContext;
public ListAdapter(Context context) {
mContext = context;
}
@Override
public boolean areAllItemsEnabled() {
return false;
}
@Override
public boolean isEnabled(int i) {
if (i == allAdminsRow) {
return true;
} else if (i >= usersStartRow && i < usersEndRow) {
TLRPC.ChatParticipant participant = participants.get(i - usersStartRow);
if (!(participant instanceof TLRPC.TL_chatParticipantCreator)) {
return true;
}
}
return false;
}
@Override
public int getCount() {
return rowCount;
}
@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) {
view = new TextCheckCell(mContext);
view.setBackgroundColor(0xffffffff);
}
TextCheckCell checkCell = (TextCheckCell) view;
chat = MessagesController.getInstance().getChat(chat_id);
checkCell.setTextAndCheck(LocaleController.getString("SetAdminsAll", R.string.SetAdminsAll), chat != null && !chat.admins_enabled, false);
} else if (type == 1) {
if (view == null) {
view = new TextInfoPrivacyCell(mContext);
}
if (i == allAdminsInfoRow) {
if (chat.admins_enabled) {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("SetAdminsNotAllInfo", R.string.SetAdminsNotAllInfo));
} else {
((TextInfoPrivacyCell) view).setText(LocaleController.getString("SetAdminsAllInfo", R.string.SetAdminsAllInfo));
}
if (usersStartRow != -1) {
view.setBackgroundResource(R.drawable.greydivider);
} else {
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (i == usersEndRow) {
((TextInfoPrivacyCell) view).setText("");
view.setBackgroundResource(R.drawable.greydivider_bottom);
}
} else if (type == 2) {
if (view == null) {
view = new UserCell(mContext, 1, 2, false);
view.setBackgroundColor(0xffffffff);
}
UserCell userCell = (UserCell) view;
TLRPC.ChatParticipant part = participants.get(i - usersStartRow);
TLRPC.User user = MessagesController.getInstance().getUser(part.user_id);
userCell.setData(user, null, null, 0);
chat = MessagesController.getInstance().getChat(chat_id);
userCell.setChecked(!(part instanceof TLRPC.TL_chatParticipant) || chat != null && !chat.admins_enabled, false);
userCell.setCheckDisabled(chat == null || !chat.admins_enabled || part.user_id == UserConfig.getClientUserId());
}
return view;
}
@Override
public int getItemViewType(int i) {
if (i == allAdminsRow) {
return 0;
} else if (i == allAdminsInfoRow || i == usersEndRow) {
return 1;
} else {
return 2;
}
}
@Override
public int getViewTypeCount() {
return 3;
}
@Override
public boolean isEmpty() {
return false;
}
}
public class SearchAdapter extends BaseFragmentAdapter {
private Context mContext;
private ArrayList<TLRPC.ChatParticipant> searchResult = new ArrayList<>();
private ArrayList<CharSequence> searchResultNames = new ArrayList<>();
private Timer searchTimer;
public SearchAdapter(Context context) {
mContext = context;
}
public void search(final String query) {
try {
if (searchTimer != null) {
searchTimer.cancel();
}
} catch (Exception e) {
FileLog.e("tmessages", e);
}
if (query == null) {
searchResult.clear();
searchResultNames.clear();
notifyDataSetChanged();
} else {
searchTimer = new Timer();
searchTimer.schedule(new TimerTask() {
@Override
public void run() {
try {
searchTimer.cancel();
searchTimer = null;
} catch (Exception e) {
FileLog.e("tmessages", e);
}
processSearch(query);
}
}, 200, 300);
}
}
private void processSearch(final String query) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
final ArrayList<TLRPC.ChatParticipant> contactsCopy = new ArrayList<>();
contactsCopy.addAll(participants);
Utilities.searchQueue.postRunnable(new Runnable() {
@Override
public void run() {
String search1 = query.trim().toLowerCase();
if (search1.length() == 0) {
updateSearchResults(new ArrayList<TLRPC.ChatParticipant>(), new ArrayList<CharSequence>());
return;
}
String search2 = LocaleController.getInstance().getTranslitString(search1);
if (search1.equals(search2) || search2.length() == 0) {
search2 = null;
}
String search[] = new String[1 + (search2 != null ? 1 : 0)];
search[0] = search1;
if (search2 != null) {
search[1] = search2;
}
ArrayList<TLRPC.ChatParticipant> resultArray = new ArrayList<>();
ArrayList<CharSequence> resultArrayNames = new ArrayList<>();
for (int a = 0; a < contactsCopy.size(); a++) {
TLRPC.ChatParticipant participant = contactsCopy.get(a);
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
if (user.id == UserConfig.getClientUserId()) {
continue;
}
String name = ContactsController.formatName(user.first_name, user.last_name).toLowerCase();
String tName = LocaleController.getInstance().getTranslitString(name);
if (name.equals(tName)) {
tName = null;
}
int found = 0;
for (String q : search) {
if (name.startsWith(q) || name.contains(" " + q) || tName != null && (tName.startsWith(q) || tName.contains(" " + q))) {
found = 1;
} else if (user.username != null && user.username.startsWith(q)) {
found = 2;
}
if (found != 0) {
if (found == 1) {
resultArrayNames.add(AndroidUtilities.generateSearchName(user.first_name, user.last_name, q));
} else {
resultArrayNames.add(AndroidUtilities.generateSearchName("@" + user.username, null, "@" + q));
}
resultArray.add(participant);
break;
}
}
}
updateSearchResults(resultArray, resultArrayNames);
}
});
}
});
}
private void updateSearchResults(final ArrayList<TLRPC.ChatParticipant> users, final ArrayList<CharSequence> names) {
AndroidUtilities.runOnUIThread(new Runnable() {
@Override
public void run() {
searchResult = users;
searchResultNames = names;
notifyDataSetChanged();
}
});
}
@Override
public boolean areAllItemsEnabled() {
return true;
}
@Override
public boolean isEnabled(int i) {
return true;
}
@Override
public int getCount() {
return searchResult.size();
}
@Override
public TLRPC.ChatParticipant getItem(int i) {
return searchResult.get(i);
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public boolean hasStableIds() {
return true;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
if (view == null) {
view = new UserCell(mContext, 1, 2, false);
}
TLRPC.ChatParticipant participant = getItem(i);
TLRPC.User user = MessagesController.getInstance().getUser(participant.user_id);
String un = user.username;
CharSequence username = null;
CharSequence name = null;
if (i < searchResult.size()) {
name = searchResultNames.get(i);
if (name != null && un != null && un.length() > 0) {
if (name.toString().startsWith("@" + un)) {
username = name;
name = null;
}
}
}
UserCell userCell = (UserCell) view;
userCell.setData(user, name, username, 0);
chat = MessagesController.getInstance().getChat(chat_id);
userCell.setChecked(!(participant instanceof TLRPC.TL_chatParticipant) || chat != null && !chat.admins_enabled, false);
userCell.setCheckDisabled(chat == null || !chat.admins_enabled || participant.user_id == UserConfig.getClientUserId());
return view;
}
@Override
public int getItemViewType(int i) {
return 0;
}
@Override
public int getViewTypeCount() {
return 1;
}
@Override
public boolean isEmpty() {
return searchResult.isEmpty();
}
}
}
@@ -1374,7 +1374,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} else if (i == mediaDownloadSection2) {
((HeaderCell) view).setText(LocaleController.getString("AutomaticMediaDownload", R.string.AutomaticMediaDownload));
} else if (i == numberSectionRow) {
((HeaderCell) view).setText(LocaleController.getString("Info", R.string.Info));
((HeaderCell) view).setText(LocaleController.getString("YourAccount", R.string.YourAccount));
}
} else if (type == 5) {
if (view == null) {
@@ -1473,6 +1473,7 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
textCell.setTextAndValue(value, LocaleController.getString("Phone", R.string.Phone), true);
*/
} else if (i == usernameRow) {
/* EDIT BY MR
TLRPC.User user = UserConfig.getCurrentUser();
String value;
if (user != null && user.username != null && user.username.length() != 0) {
@@ -1480,7 +1481,22 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter
} else {
value = LocaleController.getString("UsernameEmpty", R.string.UsernameEmpty);
}
textCell.setTextAndValue(value, LocaleController.getString("Username", R.string.Username), false);
textCell.setTextAndValue("foo", LocaleController.getString("Username", R.string.Username), false);
*/
// EDIT BY MR
String subtitle;
if( MrMailbox.MrMailboxIsConfigured(MrMailbox.hMailbox)!=0) {
subtitle = MrMailbox.MrMailboxGetConfig(MrMailbox.hMailbox, "displayname", "");
if( !subtitle.isEmpty()) { subtitle += ", ";}
subtitle += MrMailbox.MrMailboxGetConfig(MrMailbox.hMailbox, "addr", "");
}
else {
subtitle = LocaleController.getString("NotLoggedIn", R.string.NotLoggedIn);
}
textCell.setTextAndValue(LocaleController.getString("AccountSettings", R.string.AccountSettings), subtitle, false);
// /EDIT BY MR
}
}
return view;
@@ -1202,4 +1202,7 @@
<string name="formatterDay24H">HH:mm</string>
<string name="formatterDay12H">h:mm a</string>
<string name="formatDateAtTime">%1$s um %2$s</string>
<string name="NotLoggedIn">Nicht angemeldet</string>
<string name="YourAccount">Ihr Konto</string>
<string name="AccountSettings">Kontoeinstellungen</string>
</resources>
@@ -1203,4 +1203,7 @@
<string name="formatterDay24H">HH:mm</string>
<string name="formatterDay12H">h:mm a</string>
<string name="formatDateAtTime">%1$s at %2$s</string>
<string name="YourAccount">Your account</string>
<string name="NotLoggedIn">Not logged in</string>
<string name="AccountSettings">Account settings</string>
</resources>