diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 1809c71c2..c70fe9ca0 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -43,19 +43,19 @@ android { buildTypes { debug { debuggable true - jniDebugBuild false + jniDebuggable true signingConfig signingConfigs.debug } release { debuggable false - jniDebugBuild false + jniDebuggable false signingConfig signingConfigs.release } foss { debuggable false - jniDebugBuild false + jniDebuggable false signingConfig signingConfigs.release } } @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 21 - versionCode 379 - versionName "1.9.7" + versionCode 380 + versionName "2.0.0" } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java index c57e9c519..45a85ecf9 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java +++ b/TMessagesProj/src/main/java/org/telegram/android/ContactsController.java @@ -10,9 +10,11 @@ package org.telegram.android; import android.accounts.Account; import android.accounts.AccountManager; +import android.app.Activity; import android.content.ContentProviderOperation; import android.content.ContentProviderResult; import android.content.ContentResolver; +import android.content.SharedPreferences; import android.database.Cursor; import android.net.Uri; import android.provider.BaseColumns; @@ -35,6 +37,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.HashMap; +import java.util.Locale; import java.util.concurrent.ConcurrentHashMap; public class ContactsController { @@ -48,6 +51,8 @@ public class ContactsController { private boolean contactsBookLoaded = false; private String lastContactsVersions = ""; private ArrayList delayedContactsUpdate = new ArrayList(); + private String inviteText; + private boolean updatingInviteText = false; public static class Contact { public int id; @@ -75,8 +80,7 @@ public class ContactsController { public HashMap contactsBook = new HashMap(); public HashMap contactsBookSPhones = new HashMap(); - public HashMap> contactsSectionsDict = new HashMap>(); - public ArrayList sortedContactsSectionsArray = new ArrayList(); + public ArrayList phoneBookContacts = new ArrayList(); public ArrayList contacts = new ArrayList(); public SparseArray contactsDict = new SparseArray(); @@ -102,8 +106,7 @@ public class ContactsController { public void cleanup() { contactsBook.clear(); contactsBookSPhones.clear(); - contactsSectionsDict.clear(); - sortedContactsSectionsArray.clear(); + phoneBookContacts.clear(); contacts.clear(); contactsDict.clear(); usersSectionsDict.clear(); @@ -118,6 +121,45 @@ public class ContactsController { lastContactsVersions = ""; } + public void checkInviteText() { + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + inviteText = preferences.getString("invitetext", null); + int time = preferences.getInt("invitetexttime", 0); + if (!updatingInviteText && (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000))) { + updatingInviteText = true; + TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText(); + req.lang_code = LocaleController.getLocaleString(Locale.getDefault()); + if (req.lang_code == null || req.lang_code.length() == 0) { + req.lang_code = "en"; + } + ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { + @Override + public void run(TLObject response, TLRPC.TL_error error) { + if (error == null) { + final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response; + if (res.message.length() != 0) { + AndroidUtilities.runOnUIThread(new Runnable() { + @Override + public void run() { + updatingInviteText = false; + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + editor.putString("invitetext", res.message); + editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000)); + editor.commit(); + } + }); + } + } + } + }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); + } + } + + public String getInviteText() { + return inviteText != null ? inviteText : LocaleController.getString("InviteText", R.string.InviteText); + } + public void checkAppAccount() { AccountManager am = AccountManager.get(ApplicationLoader.applicationContext); Account[] accounts = am.getAccountsByType("org.telegram.account"); @@ -989,8 +1031,7 @@ public class ContactsController { contactsPhonesShort.put(user.phone, value); } - final HashMap> sectionsPhoneDict = new HashMap>(); - final ArrayList sortedSectionsPhoneArray = new ArrayList(); + final ArrayList sortedPhoneBookContacts = new ArrayList(); for (HashMap.Entry pair : contactsBook.entrySet()) { Contact value = pair.getValue(); int id = pair.getKey(); @@ -1007,61 +1048,24 @@ public class ContactsController { continue; } - String key = value.first_name; - if (key.length() == 0) { - key = value.last_name; - } - if (key.length() == 0) { - key = "#"; - if (value.phones.size() != 0) { - value.first_name = "+" + value.phones.get(0); - } - } else { - key = key.toUpperCase(); - } - if (key.length() > 1) { - key = key.substring(0, 1); - } - ArrayList arr = sectionsPhoneDict.get(key); - if (arr == null) { - arr = new ArrayList(); - sectionsPhoneDict.put(key, arr); - sortedSectionsPhoneArray.add(key); - } - arr.add(value); + sortedPhoneBookContacts.add(value); } - for (HashMap.Entry> entry : sectionsPhoneDict.entrySet()) { - Collections.sort(entry.getValue(), new Comparator() { - @Override - public int compare(Contact contact, Contact contact2) { - String toComapre1 = contact.first_name; - if (toComapre1.length() == 0) { - toComapre1 = contact.last_name; - } - String toComapre2 = contact2.first_name; - if (toComapre2.length() == 0) { - toComapre2 = contact2.last_name; - } - return toComapre1.compareTo(toComapre2); - } - }); - } - Collections.sort(sortedSectionsPhoneArray, new Comparator() { + Collections.sort(sortedPhoneBookContacts, new Comparator() { @Override - public int compare(String s, String s2) { - char cv1 = s.charAt(0); - char cv2 = s2.charAt(0); - if (cv1 == '#') { - return 1; - } else if (cv2 == '#') { - return -1; + public int compare(Contact contact, Contact contact2) { + String toComapre1 = contact.first_name; + if (toComapre1.length() == 0) { + toComapre1 = contact.last_name; } - return s.compareTo(s2); + String toComapre2 = contact2.first_name; + if (toComapre2.length() == 0) { + toComapre2 = contact2.last_name; + } + return toComapre1.compareTo(toComapre2); } }); - contactsSectionsDict = sectionsPhoneDict; - sortedContactsSectionsArray = sortedSectionsPhoneArray; + phoneBookContacts = sortedPhoneBookContacts; } private void buildContactsSectionsArrays(boolean sort) { diff --git a/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java b/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java index 612e35be3..d85db21ce 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java +++ b/TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java @@ -45,6 +45,7 @@ public class NotificationCenter { public static final int wallpapersDidLoaded = 171; public static final int closeOtherAppActivities = 702; public static final int didUpdatedConnectionState = 703; + public static final int didReceiveSmsCode = 998; public static final int emojiDidLoaded = 999; public static final int appDidLogout = 1234; diff --git a/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java b/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java index ce57865a2..c4470fa41 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SmsListener.java @@ -48,7 +48,7 @@ public class SmsListener extends BroadcastReceiver { if (matcher.find()) { String str = matcher.group(0); if (str.length() >= 3) { - NotificationCenter.getInstance().postNotificationName(998, matcher.group(0)); + NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, matcher.group(0)); } } } catch (Exception e) { diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index 71ee8a2f4..4823e5123 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -640,7 +640,7 @@ public class Utilities { builder.append(" "); } query.trim(); - builder.append(Html.fromHtml("" + query + "")); + builder.append(Html.fromHtml("" + query + "")); lastIndex = end; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/BaseSectionsAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/BaseSectionsAdapter.java new file mode 100644 index 000000000..0023f3baf --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/BaseSectionsAdapter.java @@ -0,0 +1,152 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Adapters; + +import android.util.SparseArray; +import android.view.View; +import android.view.ViewGroup; + +public abstract class BaseSectionsAdapter extends BaseFragmentAdapter { + + private SparseArray sectionPositionCache; + private SparseArray sectionCache; + private SparseArray sectionCountCache; + private int sectionCount; + private int count; + + private void cleanupCache() { + sectionCache = new SparseArray(); + sectionPositionCache = new SparseArray(); + sectionCountCache = new SparseArray(); + count = -1; + sectionCount = -1; + } + + public BaseSectionsAdapter() { + super(); + cleanupCache(); + } + + @Override + public void notifyDataSetChanged() { + cleanupCache(); + super.notifyDataSetChanged(); + } + + @Override + public void notifyDataSetInvalidated() { + cleanupCache(); + super.notifyDataSetInvalidated(); + } + + @Override + public boolean areAllItemsEnabled() { + return false; + } + + @Override + public boolean isEnabled(int position) { + return isRowEnabled(getSectionForPosition(position), getPositionInSectionForPosition(position)); + } + + @Override + public final long getItemId(int position) { + return position; + } + + @Override + public final int getCount() { + if (count >= 0) { + return count; + } + count = 0; + for (int i = 0; i < internalGetSectionCount(); i++) { + count += internalGetCountForSection(i); + } + return count; + } + + @Override + public final Object getItem(int position) { + return getItem(getSectionForPosition(position), getPositionInSectionForPosition(position)); + } + + @Override + public final int getItemViewType(int position) { + return getItemViewType(getSectionForPosition(position), getPositionInSectionForPosition(position)); + } + + @Override + public final View getView(int position, View convertView, ViewGroup parent) { + return getItemView(getSectionForPosition(position), getPositionInSectionForPosition(position), convertView, parent); + } + + private int internalGetCountForSection(int section) { + Integer cachedSectionCount = sectionCountCache.get(section); + if (cachedSectionCount != null) { + return cachedSectionCount; + } + int sectionCount = getCountForSection(section); + sectionCountCache.put(section, sectionCount); + return sectionCount; + } + + private int internalGetSectionCount() { + if (sectionCount >= 0) { + return sectionCount; + } + sectionCount = getSectionCount(); + return sectionCount; + } + + public final int getSectionForPosition(int position) { + Integer cachedSection = sectionCache.get(position); + if (cachedSection != null) { + return cachedSection; + } + int sectionStart = 0; + for (int i = 0; i < internalGetSectionCount(); i++) { + int sectionCount = internalGetCountForSection(i); + int sectionEnd = sectionStart + sectionCount; + if (position >= sectionStart && position < sectionEnd) { + sectionCache.put(position, i); + return i; + } + sectionStart = sectionEnd; + } + return 0; + } + + public int getPositionInSectionForPosition(int position) { + Integer cachedPosition = sectionPositionCache.get(position); + if (cachedPosition != null) { + return cachedPosition; + } + int sectionStart = 0; + for (int i = 0; i < internalGetSectionCount(); i++) { + int sectionCount = internalGetCountForSection(i); + int sectionEnd = sectionStart + sectionCount; + if (position >= sectionStart && position < sectionEnd) { + int positionInSection = position - sectionStart; + sectionPositionCache.put(position, positionInSection); + return positionInSection; + } + sectionStart = sectionEnd; + } + return 0; + } + + public abstract int getSectionCount(); + public abstract int getCountForSection(int section); + public abstract boolean isRowEnabled(int section, int row); + public abstract int getItemViewType(int section, int position); + public abstract Object getItem(int section, int position); + public abstract View getItemView(int section, int position, View convertView, ViewGroup parent); + public abstract View getSectionHeaderView(int section, View convertView, ViewGroup parent); +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java index 1bc0b293f..6030b4ec4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivityAdapter.java @@ -9,221 +9,245 @@ package org.telegram.ui.Adapters; import android.content.Context; -import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.widget.TextView; +import org.telegram.android.AndroidUtilities; import org.telegram.android.LocaleController; import org.telegram.messenger.TLRPC; import org.telegram.android.ContactsController; import org.telegram.android.MessagesController; import org.telegram.messenger.R; -import org.telegram.ui.Cells.ChatOrUserCell; -import org.telegram.ui.Views.SectionedBaseAdapter; -import org.telegram.ui.Views.SettingsSectionLayout; +import org.telegram.ui.Cells.DividerCell; +import org.telegram.ui.Cells.GreySectionCell; +import org.telegram.ui.Cells.LetterSectionCell; +import org.telegram.ui.Cells.TextCell; +import org.telegram.ui.Cells.UserCell; import java.util.ArrayList; import java.util.HashMap; -public class ContactsActivityAdapter extends SectionedBaseAdapter { +public class ContactsActivityAdapter extends BaseSectionsAdapter { private Context mContext; private boolean onlyUsers; - private boolean usersAsSections; + private boolean needPhonebook; private HashMap ignoreUsers; public ContactsActivityAdapter(Context context, boolean arg1, boolean arg2, HashMap arg3) { mContext = context; onlyUsers = arg1; - usersAsSections = arg2; + needPhonebook = arg2; ignoreUsers = arg3; } @Override public Object getItem(int section, int position) { + if (onlyUsers) { + if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); + return MessagesController.getInstance().getUser(arr.get(position).user_id); + } + return null; + } else { + if (section == 0) { + return null; + } else { + if (section - 1 < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - 1)); + if (position < arr.size()) { + return MessagesController.getInstance().getUser(arr.get(position).user_id); + } + return null; + } + } + } + if (needPhonebook) { + return ContactsController.getInstance().phoneBookContacts.get(position); + } return null; } @Override - public long getItemId(int section, int position) { - return 0; + public boolean isRowEnabled(int section, int row) { + if (onlyUsers) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); + return row < arr.size(); + } else { + if (section == 0) { + if (needPhonebook) { + if (row == 1) { + return false; + } + } else { + if (row == 3) { + return false; + } + } + return true; + } else if (section - 1 < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - 1)); + return row < arr.size(); + } + } + return true; } @Override public int getSectionCount() { - int count = 0; - if (usersAsSections) { - count += ContactsController.getInstance().sortedUsersSectionsArray.size(); - } else { + int count = ContactsController.getInstance().sortedUsersSectionsArray.size(); + if (!onlyUsers) { count++; } - if (!onlyUsers) { - count += ContactsController.getInstance().sortedContactsSectionsArray.size(); + if (needPhonebook) { + count++; } return count; } @Override public int getCountForSection(int section) { - if (usersAsSections) { + if (onlyUsers) { if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); - return arr.size(); + int count = arr.size(); + if (section != (ContactsController.getInstance().sortedUsersSectionsArray.size() - 1) || needPhonebook) { + count++; + } + return count; } } else { if (section == 0) { - return ContactsController.getInstance().contacts.size() + 1; + if (needPhonebook) { + return 2; + } else { + return 4; + } + } else if (section - 1 < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - 1)); + int count = arr.size(); + if (section - 1 != (ContactsController.getInstance().sortedUsersSectionsArray.size() - 1) || needPhonebook) { + count++; + } + return count; } } - ArrayList arr = ContactsController.getInstance().contactsSectionsDict.get(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1)); - return arr.size(); + if (needPhonebook) { + return ContactsController.getInstance().phoneBookContacts.size(); + } + return 0; + } + + @Override + public View getSectionHeaderView(int section, View convertView, ViewGroup parent) { + if (convertView == null) { + convertView = new LetterSectionCell(mContext); + } + if (onlyUsers) { + if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ((LetterSectionCell) convertView).setLetter(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); + } else { + ((LetterSectionCell) convertView).setLetter(""); + } + } else { + if (section == 0) { + ((LetterSectionCell) convertView).setLetter(""); + } else if (section - 1 < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ((LetterSectionCell) convertView).setLetter(ContactsController.getInstance().sortedUsersSectionsArray.get(section - 1)); + } else { + ((LetterSectionCell) convertView).setLetter(""); + } + } + return convertView; } @Override public View getItemView(int section, int position, View convertView, ViewGroup parent) { - - TLRPC.User user = null; - int count = 0; - if (usersAsSections) { - if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { - ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); - user = MessagesController.getInstance().getUser(arr.get(position).user_id); - count = arr.size(); - } - } else { - if (section == 0) { - if (position == 0) { - if (convertView == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = li.inflate(R.layout.contacts_invite_row_layout, parent, false); - TextView textView = (TextView)convertView.findViewById(R.id.messages_list_row_name); - textView.setText(LocaleController.getString("InviteFriends", R.string.InviteFriends)); - } - View divider = convertView.findViewById(R.id.settings_row_divider); - if (ContactsController.getInstance().contacts.isEmpty()) { - divider.setVisibility(View.INVISIBLE); - } else { - divider.setVisibility(View.VISIBLE); - } - return convertView; - } - user = MessagesController.getInstance().getUser(ContactsController.getInstance().contacts.get(position - 1).user_id); - count = ContactsController.getInstance().contacts.size(); - } - } - if (user != null) { + int type = getItemViewType(section, position); + if (type == 4) { if (convertView == null) { - convertView = new ChatOrUserCell(mContext); - ((ChatOrUserCell)convertView).usePadding = false; + convertView = new DividerCell(mContext); + convertView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 24 : 72), 0, AndroidUtilities.dp(LocaleController.isRTL ? 72 : 24), 0); + } + } else if (type == 3) { + if (convertView == null) { + convertView = new GreySectionCell(mContext); + ((GreySectionCell) convertView).setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase()); + } + } else if (type == 2) { + if (convertView == null) { + convertView = new TextCell(mContext); + } + TextCell actionCell = (TextCell) convertView; + if (needPhonebook) { + actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite); + } else { + if (position == 0) { + actionCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup); + } else if (position == 1) { + actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret); + } else if (position == 2) { + actionCell.setTextAndIcon(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList), R.drawable.menu_broadcast); + } + } + } else if (type == 1) { + if (convertView == null) { + convertView = new TextCell(mContext); + } + ContactsController.Contact contact = ContactsController.getInstance().phoneBookContacts.get(position); + if (contact.first_name != null && contact.last_name != null) { + ((TextCell) convertView).setText(contact.first_name + " " + contact.last_name); + } else if (contact.first_name != null && contact.last_name == null) { + ((TextCell) convertView).setText(contact.first_name); + } else { + ((TextCell) convertView).setText(contact.last_name); + } + } else if (type == 0) { + if (convertView == null) { + convertView = new UserCell(mContext); + convertView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 16 : 54), 0, 0, 0); } - ((ChatOrUserCell)convertView).setData(user, null, null, null, null); - + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - (onlyUsers ? 0 : 1))); + TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id); + ((UserCell)convertView).setData(user, null, null); if (ignoreUsers != null) { if (ignoreUsers.containsKey(user.id)) { - ((ChatOrUserCell)convertView).drawAlpha = 0.5f; + ((UserCell)convertView).drawAlpha = 0.5f; } else { - ((ChatOrUserCell)convertView).drawAlpha = 1.0f; + ((UserCell)convertView).drawAlpha = 1.0f; } } - - ((ChatOrUserCell) convertView).useSeparator = position != count - 1; - - return convertView; - } - - TextView textView; - if (convertView == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = li.inflate(R.layout.settings_row_button_layout, parent, false); - textView = (TextView)convertView.findViewById(R.id.settings_row_text); - } else { - textView = (TextView)convertView.findViewById(R.id.settings_row_text); - } - - View divider = convertView.findViewById(R.id.settings_row_divider); - ArrayList arr = ContactsController.getInstance().contactsSectionsDict.get(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1)); - ContactsController.Contact contact = arr.get(position); - if (divider != null) { - if (position == arr.size() - 1) { - divider.setVisibility(View.INVISIBLE); - } else { - divider.setVisibility(View.VISIBLE); - } - } - if (contact.first_name != null && contact.last_name != null) { - textView.setText(contact.first_name + " " + contact.last_name); - } else if (contact.first_name != null && contact.last_name == null) { - textView.setText(contact.first_name); - } else { - textView.setText(contact.last_name); } return convertView; } @Override public int getItemViewType(int section, int position) { - if (usersAsSections) { - if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { - return 0; - } - } else if (section == 0) { - if (position == 0) { - return 2; - } - return 0; - } - return 1; - } - - @Override - public int getItemViewTypeCount() { - return 3; - } - - @Override - public int getSectionHeaderViewType(int section) { - if (usersAsSections) { - if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { - return 1; - } - } else if (section == 0) { - return 0; - } - return 1; - } - - @Override - public int getSectionHeaderViewTypeCount() { - return 2; - } - - @Override - public View getSectionHeaderView(int section, View convertView, ViewGroup parent) { - if (usersAsSections) { - if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { - if (convertView == null) { - convertView = new SettingsSectionLayout(mContext); - convertView.setBackgroundColor(0xffffffff); - } - ((SettingsSectionLayout) convertView).setText(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); - return convertView; - } + if (onlyUsers) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); + return position < arr.size() ? 0 : 4; } else { if (section == 0) { - if (convertView == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = li.inflate(R.layout.empty_layout, parent, false); + if (needPhonebook) { + if (position == 1) { + return 3; + } + } else { + if (position == 3) { + return 3; + } } - return convertView; + return 2; + } else if (section - 1 < ContactsController.getInstance().sortedUsersSectionsArray.size()) { + ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section - 1)); + return position < arr.size() ? 0 : 4; } } + return 1; + } - if (convertView == null) { - convertView = new SettingsSectionLayout(mContext); - convertView.setBackgroundColor(0xffffffff); - } - ((SettingsSectionLayout) convertView).setText(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1)); - return convertView; + @Override + public int getViewTypeCount() { + return 5; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java index e01c1c4ce..16f87e897 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/ContactsActivitySearchAdapter.java @@ -22,8 +22,8 @@ import org.telegram.messenger.FileLog; import org.telegram.android.MessagesController; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; -import org.telegram.ui.Cells.ChatOrUserCell; -import org.telegram.ui.Views.SettingsSectionLayout; +import org.telegram.ui.Cells.GreySectionCell; +import org.telegram.ui.Cells.ProfileSearchCell; import java.util.ArrayList; import java.util.HashMap; @@ -197,16 +197,15 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter { public View getView(int i, View view, ViewGroup viewGroup) { if (i == searchResult.size()) { if (view == null) { - view = new SettingsSectionLayout(mContext); - ((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch)); + view = new GreySectionCell(mContext); + ((GreySectionCell) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch)); } } else { if (view == null) { - view = new ChatOrUserCell(mContext); - ((ChatOrUserCell) view).usePadding = false; + view = new ProfileSearchCell(mContext); } - ((ChatOrUserCell) view).useSeparator = (i != getCount() - 1 && i != searchResult.size() - 1); + ((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != searchResult.size() - 1); TLRPC.User user = getItem(i); if (user != null) { CharSequence username = null; @@ -221,20 +220,20 @@ public class ContactsActivitySearchAdapter extends BaseContactsSearchAdapter { } } else if (i > searchResult.size() && user.username != null) { try { - username = Html.fromHtml(String.format("@%s%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length()))); + username = Html.fromHtml(String.format("@%s%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length()))); } catch (Exception e) { username = user.username; FileLog.e("tmessages", e); } } - ((ChatOrUserCell) view).setData(user, null, null, name, username); + ((ProfileSearchCell) view).setData(user, null, null, name, username); if (ignoreUsers != null) { if (ignoreUsers.containsKey(user.id)) { - ((ChatOrUserCell) view).drawAlpha = 0.5f; + ((ProfileSearchCell) view).drawAlpha = 0.5f; } else { - ((ChatOrUserCell) view).drawAlpha = 1.0f; + ((ProfileSearchCell) view).drawAlpha = 1.0f; } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DrawerLayoutAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DrawerLayoutAdapter.java index f4da419a6..8304f7f7e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DrawerLayoutAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/DrawerLayoutAdapter.java @@ -18,8 +18,8 @@ import org.telegram.android.MessagesController; import org.telegram.messenger.R; import org.telegram.messenger.UserConfig; import org.telegram.ui.Cells.DrawerActionCell; -import org.telegram.ui.Cells.DrawerDividerCell; -import org.telegram.ui.Cells.DrawerEmptyCell; +import org.telegram.ui.Cells.DividerCell; +import org.telegram.ui.Cells.EmptyCell; import org.telegram.ui.Cells.DrawerProfileCell; public class DrawerLayoutAdapter extends BaseAdapter { @@ -37,12 +37,12 @@ public class DrawerLayoutAdapter extends BaseAdapter { @Override public boolean isEnabled(int i) { - return !(i == 0 || i == 1 || i == 5 || i == 6 || i == 7); + return !(i == 0 || i == 1 || i == 5); } @Override public int getCount() { - return UserConfig.isClientActivated() ? 12 : 0; + return UserConfig.isClientActivated() ? 10 : 0; } @Override @@ -70,11 +70,11 @@ public class DrawerLayoutAdapter extends BaseAdapter { ((DrawerProfileCell) view).setUser(MessagesController.getInstance().getUser(UserConfig.getClientUserId())); } else if (type == 1) { if (view == null) { - view = new DrawerEmptyCell(mContext); + view = new EmptyCell(mContext, 8); } } else if (type == 2) { if (view == null) { - view = new DrawerDividerCell(mContext); + view = new DividerCell(mContext); } } else if (type == 3) { if (view == null) { @@ -87,13 +87,13 @@ public class DrawerLayoutAdapter extends BaseAdapter { actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret); } else if (i == 4) { actionCell.setTextAndIcon(LocaleController.getString("NewBroadcastList", R.string.NewBroadcastList), R.drawable.menu_broadcast); - } else if (i == 8) { + } else if (i == 6) { actionCell.setTextAndIcon(LocaleController.getString("Contacts", R.string.Contacts), R.drawable.menu_contacts); - } else if (i == 9) { + } else if (i == 7) { actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite); - } else if (i == 10) { + } else if (i == 8) { actionCell.setTextAndIcon(LocaleController.getString("Settings", R.string.Settings), R.drawable.menu_settings); - } else if (i == 11) { + } else if (i == 9) { actionCell.setTextAndIcon(LocaleController.getString("TelegramFaq", R.string.TelegramFaq), R.drawable.menu_help); } } @@ -105,9 +105,9 @@ public class DrawerLayoutAdapter extends BaseAdapter { public int getItemViewType(int i) { if (i == 0) { return 0; - } else if (i == 1 || i == 5 || i == 7) { + } else if (i == 1) { return 1; - } else if (i == 6) { + } else if (i == 5) { return 2; } return 3; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MessagesActivitySearchAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MessagesActivitySearchAdapter.java index c1d508d73..348cb493e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MessagesActivitySearchAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Adapters/MessagesActivitySearchAdapter.java @@ -30,9 +30,9 @@ import org.telegram.messenger.TLObject; import org.telegram.messenger.TLRPC; import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; -import org.telegram.ui.Cells.ChatOrUserCell; import org.telegram.ui.Cells.DialogCell; -import org.telegram.ui.Views.SettingsSectionLayout; +import org.telegram.ui.Cells.GreySectionCell; +import org.telegram.ui.Cells.ProfileSearchCell; import java.util.ArrayList; import java.util.Timer; @@ -113,7 +113,7 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); } - private void searchDialogsInternal(final String query, final boolean needEncrypted) { + private void searchDialogsInternal(final String query, final boolean serverOnly) { MessagesStorage.getInstance().getStorageQueue().postRunnable(new Runnable() { @Override public void run() { @@ -162,7 +162,7 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { } cursor.dispose(); - if (needEncrypted) { + if (!serverOnly) { cursor = MessagesStorage.getInstance().getDatabase().queryFinalized("SELECT q.data, u.name, q.user, q.g, q.authkey, q.ttl, u.data, u.status, q.layer, q.seq_in, q.seq_out FROM enc_chats as q INNER JOIN dialogs as d ON (q.uid << 32) = d.did INNER JOIN users as u ON q.user = u.uid"); while (cursor.next()) { String name = cursor.stringValue(1); @@ -219,7 +219,7 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { ByteBufferDesc data = MessagesStorage.getInstance().getBuffersStorage().getFreeBuffer(cursor.byteArrayLength(0)); if (data != null && cursor.byteBufferValue(0, data.buffer) != 0) { TLRPC.Chat chat = (TLRPC.Chat) TLClassStore.Instance().TLdeserialize(data, data.readInt32()); - if (!needEncrypted && chat.id < 0) { + if (serverOnly && chat.id < 0) { continue; } resultArrayNames.add(Utilities.generateSearchName(chat.title, null, q)); @@ -367,17 +367,16 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { if (type == 1) { if (view == null) { - view = new SettingsSectionLayout(mContext); - view.setPadding(AndroidUtilities.dp(11), 0, AndroidUtilities.dp(11), 0); + view = new GreySectionCell(mContext); } if (!globalSearch.isEmpty() && i == searchResult.size()) { - ((SettingsSectionLayout) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch)); + ((GreySectionCell) view).setText(LocaleController.getString("GlobalSearch", R.string.GlobalSearch)); } else { - ((SettingsSectionLayout) view).setText(LocaleController.getString("SearchMessages", R.string.SearchMessages)); + ((GreySectionCell) view).setText(LocaleController.getString("SearchMessages", R.string.SearchMessages)); } } else if (type == 0) { if (view == null) { - view = new ChatOrUserCell(mContext); + view = new ProfileSearchCell(mContext); } TLRPC.User user = null; @@ -385,9 +384,9 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { TLRPC.EncryptedChat encryptedChat = null; int localCount = searchResult.size(); - int globalCount = globalSearch.isEmpty() ? -1 : globalSearch.size() + 1; + int globalCount = globalSearch.isEmpty() ? 0 : globalSearch.size() + 1; - ((ChatOrUserCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1); + ((ProfileSearchCell) view).useSeparator = (i != getCount() - 1 && i != localCount - 1 && i != localCount + globalCount - 1); Object obj = getItem(i); if (obj instanceof TLRPC.User) { user = MessagesController.getInstance().getUser(((TLRPC.User) obj).id); @@ -413,14 +412,14 @@ public class MessagesActivitySearchAdapter extends BaseContactsSearchAdapter { } } else if (i > searchResult.size() && user != null && user.username != null) { try { - username = Html.fromHtml(String.format("@%s%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length()))); + username = Html.fromHtml(String.format("@%s%s", user.username.substring(0, lastFoundUsername.length()), user.username.substring(lastFoundUsername.length()))); } catch (Exception e) { username = user.username; FileLog.e("tmessages", e); } } - ((ChatOrUserCell) view).setData(user, chat, encryptedChat, name, username); + ((ProfileSearchCell) view).setData(user, chat, encryptedChat, name, username); } else if (type == 2) { if (view == null) { view = new DialogCell(mContext); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java index ec07f5044..dac69c9f6 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DialogCell.java @@ -70,7 +70,6 @@ public class DialogCell extends BaseCell { private int nameLeft; - private int nameTop = AndroidUtilities.dp(13); private StaticLayout nameLayout; private boolean drawNameLock; private boolean drawNameGroup; @@ -142,13 +141,13 @@ public class DialogCell extends BaseCell { countPaint.setColor(0xffffffff); countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); - lockDrawable = getResources().getDrawable(R.drawable.ic_lock_green); + lockDrawable = getResources().getDrawable(R.drawable.list_secret); checkDrawable = getResources().getDrawable(R.drawable.dialogs_check); halfCheckDrawable = getResources().getDrawable(R.drawable.dialogs_halfcheck); clockDrawable = getResources().getDrawable(R.drawable.msg_clock); errorDrawable = getResources().getDrawable(R.drawable.dialogs_warning); countDrawable = getResources().getDrawable(R.drawable.dialogs_badge); - groupDrawable = getResources().getDrawable(R.drawable.grouplist); + groupDrawable = getResources().getDrawable(R.drawable.list_group); broadcastDrawable = getResources().getDrawable(R.drawable.broadcast); } } @@ -217,7 +216,7 @@ public class DialogCell extends BaseCell { if (encryptedChat != null) { drawNameLock = true; - nameLockTop = AndroidUtilities.dp(15); + nameLockTop = AndroidUtilities.dp(16.5f); if (!LocaleController.isRTL) { nameLockLeft = AndroidUtilities.dp(72); nameLeft = AndroidUtilities.dp(76) + lockDrawable.getIntrinsicWidth(); @@ -229,10 +228,12 @@ public class DialogCell extends BaseCell { if (chat != null) { if (chat.id < 0) { drawNameBroadcast = true; + nameLockTop = AndroidUtilities.dp(16.5f); } else { drawNameGroup = true; + nameLockTop = AndroidUtilities.dp(17.5f); } - nameLockTop = AndroidUtilities.dp(16); + if (!LocaleController.isRTL) { nameLockLeft = AndroidUtilities.dp(72); nameLeft = AndroidUtilities.dp(76) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); @@ -655,7 +656,7 @@ public class DialogCell extends BaseCell { if (nameLayout != null) { canvas.save(); - canvas.translate(nameLeft, nameTop); + canvas.translate(nameLeft, AndroidUtilities.dp(13)); nameLayout.draw(canvas); canvas.restore(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DividerCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DividerCell.java new file mode 100644 index 000000000..55ce4d3fe --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DividerCell.java @@ -0,0 +1,36 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; + +import org.telegram.android.AndroidUtilities; + +public class DividerCell extends BaseCell { + + Paint paint = new Paint(); + + public DividerCell(Context context) { + super(context); + paint.setColor(0xffd9d9d9); + paint.setStrokeWidth(1); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(16) + 1); + } + + @Override + protected void onDraw(Canvas canvas) { + canvas.drawLine(getPaddingLeft(), AndroidUtilities.dp(8), getWidth() - getPaddingRight(), AndroidUtilities.dp(8), paint); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerActionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerActionCell.java index a61e4cceb..2a4d708fc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerActionCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerActionCell.java @@ -30,13 +30,13 @@ public class DrawerActionCell extends FrameLayout { textView.setLines(1); textView.setMaxLines(1); textView.setSingleLine(true); - textView.setGravity(Gravity.LEFT | Gravity.CENTER); + textView.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); textView.setCompoundDrawablePadding(AndroidUtilities.dp(34)); addView(textView); LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams(); layoutParams.width = LayoutParams.MATCH_PARENT; layoutParams.height = LayoutParams.MATCH_PARENT; - layoutParams.gravity = Gravity.LEFT | Gravity.BOTTOM; + layoutParams.gravity = Gravity.LEFT; layoutParams.leftMargin = AndroidUtilities.dp(14); layoutParams.rightMargin = AndroidUtilities.dp(16); textView.setLayoutParams(layoutParams); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerDividerCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerDividerCell.java deleted file mode 100644 index 05aca7ec4..000000000 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerDividerCell.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * This is the source code of Telegram for Android v. 1.7.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-2014. - */ - -package org.telegram.ui.Cells; - -import android.content.Context; -import android.widget.FrameLayout; - -public class DrawerDividerCell extends FrameLayout { - - public DrawerDividerCell(Context context) { - super(context); - setBackgroundColor(0xffd9d9d9); - } - - @Override - protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(1, MeasureSpec.EXACTLY)); - } -} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerEmptyCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/EmptyCell.java similarity index 73% rename from TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerEmptyCell.java rename to TMessagesProj/src/main/java/org/telegram/ui/Cells/EmptyCell.java index 4df169104..828e59271 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/DrawerEmptyCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/EmptyCell.java @@ -13,14 +13,17 @@ import android.widget.FrameLayout; import org.telegram.android.AndroidUtilities; -public class DrawerEmptyCell extends FrameLayout { +public class EmptyCell extends FrameLayout { - public DrawerEmptyCell(Context context) { + int cellHeight; + + public EmptyCell(Context context, int height) { super(context); + cellHeight = height; } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(8), MeasureSpec.EXACTLY)); + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(cellHeight), MeasureSpec.EXACTLY)); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/GreySectionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/GreySectionCell.java new file mode 100644 index 000000000..b13f3de75 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/GreySectionCell.java @@ -0,0 +1,70 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.FrameLayout; +import android.widget.TextView; + +import org.telegram.android.AndroidUtilities; +import org.telegram.android.LocaleController; + +public class GreySectionCell extends FrameLayout { + private TextView textView; + + private void init() { + setBackgroundColor(0xfff2f2f2); + + textView = new TextView(getContext()); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); + textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + textView.setTextColor(0xff8a8a8a); + textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); + addView(textView); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)textView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.leftMargin = AndroidUtilities.dp(16); + layoutParams.rightMargin = AndroidUtilities.dp(16); + layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT; + textView.setLayoutParams(layoutParams); + } + + public GreySectionCell(Context context) { + super(context); + init(); + } + + public GreySectionCell(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public GreySectionCell(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(36), MeasureSpec.EXACTLY)); + } + + public void setText(String text) { + textView.setText(text); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/LetterSectionCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/LetterSectionCell.java new file mode 100644 index 000000000..ad385f981 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/LetterSectionCell.java @@ -0,0 +1,43 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.TextView; + +import org.telegram.android.AndroidUtilities; + +public class LetterSectionCell extends FrameLayout { + + private TextView textView; + + public LetterSectionCell(Context context) { + super(context); + setLayoutParams(new ViewGroup.LayoutParams(AndroidUtilities.dp(54), AndroidUtilities.dp(64))); + + textView = new TextView(getContext()); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 22); + textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + textView.setTextColor(0xff808080); + textView.setGravity(Gravity.CENTER); + addView(textView); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams)textView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + textView.setLayoutParams(layoutParams); + } + + public void setLetter(String letter) { + textView.setText(letter.toUpperCase()); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ProfileSearchCell.java similarity index 82% rename from TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java rename to TMessagesProj/src/main/java/org/telegram/ui/Cells/ProfileSearchCell.java index a705adc9a..7249674b0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ProfileSearchCell.java @@ -1,9 +1,9 @@ /* - * This is the source code of Telegram for Android v. 1.3.x. + * This is the source code of Telegram for Android v. 1.7.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. + * Copyright Nikolai Kudashov, 2013-2014. */ package org.telegram.ui.Cells; @@ -17,19 +17,19 @@ import android.text.StaticLayout; import android.text.TextPaint; import android.text.TextUtils; -import org.telegram.android.AndroidUtilities; import org.telegram.PhoneFormat.PhoneFormat; +import org.telegram.android.AndroidUtilities; import org.telegram.android.ContactsController; -import org.telegram.android.LocaleController; -import org.telegram.messenger.TLRPC; -import org.telegram.messenger.ConnectionsManager; -import org.telegram.android.MessagesController; -import org.telegram.messenger.R; -import org.telegram.messenger.UserConfig; import org.telegram.android.ImageReceiver; +import org.telegram.android.LocaleController; +import org.telegram.android.MessagesController; +import org.telegram.messenger.ConnectionsManager; +import org.telegram.messenger.R; +import org.telegram.messenger.TLRPC; +import org.telegram.messenger.UserConfig; import org.telegram.ui.Views.AvatarDrawable; -public class ChatOrUserCell extends BaseCell { +public class ProfileSearchCell extends BaseCell { private static TextPaint namePaint; private static TextPaint nameEncryptedPaint; private static TextPaint onlinePaint; @@ -52,7 +52,6 @@ public class ChatOrUserCell extends BaseCell { private int lastStatus = 0; private TLRPC.FileLocation lastAvatar = null; - public boolean usePadding = true; public boolean useSeparator = false; public float drawAlpha = 1; @@ -66,44 +65,44 @@ public class ChatOrUserCell extends BaseCell { private int nameLockTop; private int onlineLeft; - private int onlineTop = AndroidUtilities.dp(36); private StaticLayout onlineLayout; - private int avatarTop = AndroidUtilities.dp(7); - - public ChatOrUserCell(Context context) { + public ProfileSearchCell(Context context) { super(context); init(); avatarImage = new ImageReceiver(this); + avatarImage.setRoundRadius(AndroidUtilities.dp(26)); avatarDrawable = new AvatarDrawable(); } private void init() { if (namePaint == null) { namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); - namePaint.setTextSize(AndroidUtilities.dp(18)); + namePaint.setTextSize(AndroidUtilities.dp(17)); namePaint.setColor(0xff222222); + namePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); - nameEncryptedPaint.setTextSize(AndroidUtilities.dp(18)); + nameEncryptedPaint.setTextSize(AndroidUtilities.dp(17)); nameEncryptedPaint.setColor(0xff00a60e); + nameEncryptedPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); - onlinePaint.setTextSize(AndroidUtilities.dp(15)); + onlinePaint.setTextSize(AndroidUtilities.dp(16)); onlinePaint.setColor(0xff316f9f); offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); - offlinePaint.setTextSize(AndroidUtilities.dp(15)); + offlinePaint.setTextSize(AndroidUtilities.dp(16)); offlinePaint.setColor(0xff999999); - lockDrawable = getResources().getDrawable(R.drawable.ic_lock_green); + lockDrawable = getResources().getDrawable(R.drawable.list_secret); linePaint = new Paint(); linePaint.setColor(0xffdcdcdc); broadcastDrawable = getResources().getDrawable(R.drawable.broadcast); - groupDrawable = getResources().getDrawable(R.drawable.grouplist); + groupDrawable = getResources().getDrawable(R.drawable.list_group); } } @@ -127,7 +126,7 @@ public class ChatOrUserCell extends BaseCell { @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(64)); + setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(72)); } @Override @@ -152,33 +151,35 @@ public class ChatOrUserCell extends BaseCell { if (encryptedChat != null) { drawNameLock = true; if (!LocaleController.isRTL) { - nameLockLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0)); - nameLeft = AndroidUtilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth(); + nameLockLeft = AndroidUtilities.dp(72); + nameLeft = AndroidUtilities.dp(76) + lockDrawable.getIntrinsicWidth(); } else { - nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth(); - nameLeft = usePadding ? AndroidUtilities.dp(11) : 0; + nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(74) - lockDrawable.getIntrinsicWidth(); + nameLeft = AndroidUtilities.dp(11); } - nameLockTop = AndroidUtilities.dp(15); + nameLockTop = AndroidUtilities.dp(16.5f); } else { if (chat != null) { - nameLockTop = AndroidUtilities.dp(26); + if (chat.id < 0) { drawNameBroadcast = true; + nameLockTop = AndroidUtilities.dp(28.5f); } else { drawNameGroup = true; + nameLockTop = AndroidUtilities.dp(30); } if (!LocaleController.isRTL) { - nameLockLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0)); - nameLeft = AndroidUtilities.dp(65 + (usePadding ? 11 : 0)) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); + nameLockLeft = AndroidUtilities.dp(72); + nameLeft = AndroidUtilities.dp(76) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); } else { - nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(63 + (usePadding ? 11 : 0)) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); - nameLeft = usePadding ? AndroidUtilities.dp(11) : 0; + nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(74) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth()); + nameLeft = AndroidUtilities.dp(11); } } else { if (!LocaleController.isRTL) { - nameLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0)); + nameLeft = AndroidUtilities.dp(72); } else { - nameLeft = usePadding ? AndroidUtilities.dp(11) : 0; + nameLeft = AndroidUtilities.dp(11); } } } @@ -210,14 +211,16 @@ public class ChatOrUserCell extends BaseCell { int onlineWidth; int nameWidth; if (!LocaleController.isRTL) { - onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(3 + (usePadding ? 11 : 0)); + onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14); } else { - onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(61 + (usePadding ? 11 : 0)); + onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(72); } if (drawNameLock) { nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth(); } else if (drawNameBroadcast) { nameWidth -= AndroidUtilities.dp(6) + broadcastDrawable.getIntrinsicWidth(); + } else if (drawNameGroup) { + nameWidth -= AndroidUtilities.dp(6) + groupDrawable.getIntrinsicWidth(); } CharSequence nameStringFinal = TextUtils.ellipsize(nameString, currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); @@ -225,9 +228,9 @@ public class ChatOrUserCell extends BaseCell { if (chat == null) { if (!LocaleController.isRTL) { - onlineLeft = AndroidUtilities.dp(61 + (usePadding ? 11 : 0)); + onlineLeft = AndroidUtilities.dp(72); } else { - onlineLeft = usePadding ? AndroidUtilities.dp(11) : 0; + onlineLeft = AndroidUtilities.dp(11); } CharSequence onlineString = ""; @@ -243,22 +246,22 @@ public class ChatOrUserCell extends BaseCell { } } - CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); - onlineLayout = new StaticLayout(onlineStringFinal, currentOnlinePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); - nameTop = AndroidUtilities.dp(12); + CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, onlineWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); + onlineLayout = new StaticLayout(onlineStringFinal, currentOnlinePaint, onlineWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + nameTop = AndroidUtilities.dp(13); } else { onlineLayout = null; - nameTop = AndroidUtilities.dp(22); + nameTop = AndroidUtilities.dp(25); } int avatarLeft; if (!LocaleController.isRTL) { - avatarLeft = usePadding ? AndroidUtilities.dp(11) : 0; + avatarLeft = AndroidUtilities.dp(9); } else { - avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(50 + (usePadding ? 11 : 0)); + avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(61); } - avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(50), AndroidUtilities.dp(50)); + avatarImage.setImageCoords(avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52)); double widthpx = 0; float left = 0; @@ -382,11 +385,10 @@ public class ChatOrUserCell extends BaseCell { } if (useSeparator) { - int h = getMeasuredHeight(); - if (!usePadding) { - canvas.drawLine(0, h - 1, getMeasuredWidth(), h - 1, linePaint); + if (LocaleController.isRTL) { + canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(72), getMeasuredHeight() - 1, linePaint); } else { - canvas.drawLine(AndroidUtilities.dp(11), h - 1, getMeasuredWidth() - AndroidUtilities.dp(11), h - 1, linePaint); + canvas.drawLine(AndroidUtilities.dp(72), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint); } } @@ -412,7 +414,7 @@ public class ChatOrUserCell extends BaseCell { if (onlineLayout != null) { canvas.save(); - canvas.translate(onlineLeft, onlineTop); + canvas.translate(onlineLeft, AndroidUtilities.dp(40)); onlineLayout.draw(canvas); canvas.restore(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextCell.java new file mode 100644 index 000000000..f51b48bad --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextCell.java @@ -0,0 +1,126 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.graphics.drawable.Drawable; +import android.util.TypedValue; +import android.view.Gravity; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import org.telegram.android.AndroidUtilities; +import org.telegram.android.LocaleController; + +public class TextCell extends FrameLayout { + + private TextView textView; + private TextView valueTextView; + private ImageView imageView; + private ImageView valueImageView; + + public TextCell(Context context) { + super(context); + + textView = new TextView(context); + textView.setTextColor(0xff000000); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); + textView.setLines(1); + textView.setMaxLines(1); + textView.setSingleLine(true); + textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); + addView(textView); + LayoutParams layoutParams = (LayoutParams) textView.getLayoutParams(); + layoutParams.width = LayoutParams.MATCH_PARENT; + layoutParams.height = LayoutParams.MATCH_PARENT; + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 71 : 16); + layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT; + textView.setLayoutParams(layoutParams); + + valueTextView = new TextView(context); + valueTextView.setTextColor(0xff2f8cc9); + valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); + valueTextView.setLines(1); + valueTextView.setMaxLines(1); + valueTextView.setSingleLine(true); + valueTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL); + addView(valueTextView); + layoutParams = (LayoutParams) valueTextView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.MATCH_PARENT; + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16); + layoutParams.gravity = LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT; + valueTextView.setLayoutParams(layoutParams); + + imageView = new ImageView(context); + imageView.setScaleType(ImageView.ScaleType.CENTER); + addView(imageView); + layoutParams = (LayoutParams) imageView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0); + layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL; + imageView.setLayoutParams(layoutParams); + + valueImageView = new ImageView(context); + valueImageView.setScaleType(ImageView.ScaleType.CENTER); + addView(valueImageView); + layoutParams = (LayoutParams) valueImageView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16); + layoutParams.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL; + valueImageView.setLayoutParams(layoutParams); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(48), MeasureSpec.EXACTLY)); + } + + public void setTextColor(int color) { + textView.setTextColor(color); + } + + public void setText(String text) { + textView.setText(text); + imageView.setVisibility(GONE); + valueTextView.setVisibility(GONE); + valueImageView.setVisibility(GONE); + } + + public void setTextAndIcon(String text, int resId) { + textView.setText(text); + imageView.setImageResource(resId); + imageView.setVisibility(VISIBLE); + valueTextView.setVisibility(GONE); + valueImageView.setVisibility(GONE); + } + + public void setTextAndValue(String text, String value) { + textView.setText(text); + valueTextView.setText(value); + valueTextView.setVisibility(VISIBLE); + imageView.setVisibility(GONE); + valueImageView.setVisibility(GONE); + } + + public void setTextAndValueDrawable(String text, Drawable drawable) { + textView.setText(text); + valueImageView.setVisibility(VISIBLE); + valueImageView.setImageDrawable(drawable); + valueTextView.setVisibility(GONE); + imageView.setVisibility(GONE); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextDetailCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextDetailCell.java new file mode 100644 index 000000000..1854a990a --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/TextDetailCell.java @@ -0,0 +1,94 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.util.TypedValue; +import android.view.Gravity; +import android.view.View; +import android.widget.FrameLayout; +import android.widget.ImageView; +import android.widget.TextView; + +import org.telegram.android.AndroidUtilities; +import org.telegram.android.LocaleController; + +public class TextDetailCell extends FrameLayout { + + private TextView textView; + private TextView valueTextView; + private ImageView imageView; + + public TextDetailCell(Context context) { + super(context); + + textView = new TextView(context); + textView.setTextColor(0xff000000); + textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16); + textView.setLines(1); + textView.setMaxLines(1); + textView.setSingleLine(true); + textView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL); + addView(textView); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) textView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.topMargin = AndroidUtilities.dp(11); + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 71 : 16); + layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT; + textView.setLayoutParams(layoutParams); + + valueTextView = new TextView(context); + valueTextView.setTextColor(0xff8a8a8a); + valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 13); + valueTextView.setLines(1); + valueTextView.setMaxLines(1); + valueTextView.setSingleLine(true); + valueTextView.setGravity((LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL); + addView(valueTextView); + layoutParams = (FrameLayout.LayoutParams) valueTextView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.topMargin = AndroidUtilities.dp(36); + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 71); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 71 : 16); + layoutParams.gravity = LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT; + valueTextView.setLayoutParams(layoutParams); + + imageView = new ImageView(context); + imageView.setScaleType(ImageView.ScaleType.CENTER); + addView(imageView); + layoutParams = (LayoutParams) imageView.getLayoutParams(); + layoutParams.width = LayoutParams.WRAP_CONTENT; + layoutParams.height = LayoutParams.WRAP_CONTENT; + layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16); + layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0); + layoutParams.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL; + imageView.setLayoutParams(layoutParams); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), View.MeasureSpec.EXACTLY)); + } + + public void setTextAndValue(String text, String value) { + textView.setText(text); + valueTextView.setText(value); + imageView.setVisibility(GONE); + } + + public void setTextAndValueAndIcon(String text, String value, int resId) { + textView.setText(text); + valueTextView.setText(value); + imageView.setVisibility(VISIBLE); + imageView.setImageResource(resId); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java new file mode 100644 index 000000000..585114313 --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java @@ -0,0 +1,302 @@ +/* + * This is the source code of Telegram for Android v. 1.3.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. + */ + +package org.telegram.ui.Cells; + +import android.content.Context; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.text.Layout; +import android.text.StaticLayout; +import android.text.TextPaint; +import android.text.TextUtils; + +import org.telegram.android.AndroidUtilities; +import org.telegram.PhoneFormat.PhoneFormat; +import org.telegram.android.ContactsController; +import org.telegram.android.LocaleController; +import org.telegram.messenger.TLRPC; +import org.telegram.messenger.ConnectionsManager; +import org.telegram.android.MessagesController; +import org.telegram.messenger.R; +import org.telegram.messenger.UserConfig; +import org.telegram.android.ImageReceiver; +import org.telegram.ui.Views.AvatarDrawable; + +public class UserCell extends BaseCell { + private static TextPaint namePaint; + private static TextPaint onlinePaint; + private static TextPaint offlinePaint; + private static Paint linePaint; + + private CharSequence currentName; + private ImageReceiver avatarImage; + private AvatarDrawable avatarDrawable; + private CharSequence subLabel; + + private TLRPC.User user = null; + + private String lastName = null; + private int lastStatus = 0; + private TLRPC.FileLocation lastAvatar = null; + + public boolean useSeparator = false; + public float drawAlpha = 1; + + private int nameLeft; + private int nameTop; + private StaticLayout nameLayout; + + private int onlineLeft; + private int onlineTop = AndroidUtilities.dp(36); + private StaticLayout onlineLayout; + + public UserCell(Context context) { + super(context); + init(); + avatarImage = new ImageReceiver(this); + avatarImage.setRoundRadius(AndroidUtilities.dp(24)); + avatarDrawable = new AvatarDrawable(); + } + + private void init() { + if (namePaint == null) { + namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); + namePaint.setTextSize(AndroidUtilities.dp(18)); + namePaint.setColor(0xff222222); + + onlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); + onlinePaint.setTextSize(AndroidUtilities.dp(15)); + onlinePaint.setColor(0xff316f9f); + + offlinePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG); + offlinePaint.setTextSize(AndroidUtilities.dp(15)); + offlinePaint.setColor(0xff999999); + + linePaint = new Paint(); + linePaint.setColor(0xffdcdcdc); + } + } + + public void setData(TLRPC.User u, CharSequence n, CharSequence s) { + currentName = n; + user = u; + subLabel = s; + update(0); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (avatarImage != null) { + avatarImage.clearImage(); + lastAvatar = null; + } + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec) - getPaddingRight(), AndroidUtilities.dp(64)); + } + + @Override + protected void onLayout(boolean changed, int left, int top, int right, int bottom) { + if (user == null) { + super.onLayout(changed, left, top, right, bottom); + return; + } + if (changed) { + buildLayout(); + } + } + + public void buildLayout() { + int paddingLeft = getPaddingLeft(); + int paddingRight = getPaddingRight(); + + onlineLeft = nameLeft = AndroidUtilities.dp(LocaleController.isRTL ? 11 : 72) + paddingLeft; + int avatarLeft = paddingLeft + (LocaleController.isRTL ? (getMeasuredWidth() - AndroidUtilities.dp(61)) : AndroidUtilities.dp(11)); + int nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(LocaleController.isRTL ? 72 : 14); + int avatarTop = AndroidUtilities.dp(8); + + CharSequence nameString = ""; + if (currentName != null) { + nameString = currentName; + } else { + String nameString2 = ""; + if (user != null) { + nameString2 = ContactsController.formatName(user.first_name, user.last_name); + } + nameString = nameString2.replace("\n", " "); + } + if (nameString.length() == 0) { + if (user != null && user.phone != null && user.phone.length() != 0) { + nameString = PhoneFormat.getInstance().format("+" + user.phone); + } else { + nameString = LocaleController.getString("HiddenName", R.string.HiddenName); + } + } + CharSequence nameStringFinal = TextUtils.ellipsize(nameString, namePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); + nameLayout = new StaticLayout(nameStringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + + CharSequence onlineString = ""; + TextPaint currentOnlinePaint = offlinePaint; + if (subLabel != null) { + onlineString = subLabel; + } else { + onlineString = LocaleController.formatUserStatus(user); + if (user != null && (user.id == UserConfig.getClientUserId() || user.status != null && user.status.expires > ConnectionsManager.getInstance().getCurrentTime())) { + currentOnlinePaint = onlinePaint; + onlineString = LocaleController.getString("Online", R.string.Online); + } + } + + CharSequence onlineStringFinal = TextUtils.ellipsize(onlineString, currentOnlinePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END); + onlineLayout = new StaticLayout(onlineStringFinal, currentOnlinePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false); + nameTop = AndroidUtilities.dp(12); + + avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(48), AndroidUtilities.dp(48)); + + double widthpx = 0; + float left = 0; + if (LocaleController.isRTL) { + if (nameLayout.getLineCount() > 0) { + left = nameLayout.getLineLeft(0); + if (left == 0) { + widthpx = Math.ceil(nameLayout.getLineWidth(0)); + if (widthpx < nameWidth) { + nameLeft += (nameWidth - widthpx); + } + } + } + if (onlineLayout != null && onlineLayout.getLineCount() > 0) { + left = onlineLayout.getLineLeft(0); + if (left == 0) { + widthpx = Math.ceil(onlineLayout.getLineWidth(0)); + if (widthpx < nameWidth) { + onlineLeft += (nameWidth - widthpx); + } + } + } + } else { + if (nameLayout.getLineCount() > 0) { + left = nameLayout.getLineRight(0); + if (left == nameWidth) { + widthpx = Math.ceil(nameLayout.getLineWidth(0)); + if (widthpx < nameWidth) { + nameLeft -= (nameWidth - widthpx); + } + } + } + if (onlineLayout != null && onlineLayout.getLineCount() > 0) { + left = onlineLayout.getLineRight(0); + if (left == nameWidth) { + widthpx = Math.ceil(onlineLayout.getLineWidth(0)); + if (widthpx < nameWidth) { + onlineLeft -= (nameWidth - widthpx); + } + } + } + } + } + + public void update(int mask) { + TLRPC.FileLocation photo = null; + if (user != null) { + if (user.photo != null) { + photo = user.photo.photo_small; + } + avatarDrawable.setInfo(user); + } else { + avatarDrawable.setInfo(0, null, null, false); + } + + if (mask != 0) { + boolean continueUpdate = false; + if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 && user != null) { + if (lastAvatar != null && photo == null || lastAvatar == null && photo != null && lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) { + continueUpdate = true; + } + } + if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0 && user != null) { + int newStatus = 0; + if (user.status != null) { + newStatus = user.status.expires; + } + if (newStatus != lastStatus) { + continueUpdate = true; + } + } + if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_NAME) != 0 && user != null) { + String newName = null; + if (user != null) { + newName = user.first_name + user.last_name; + } + if (newName == null || !newName.equals(lastName)) { + continueUpdate = true; + } + } + + if (!continueUpdate) { + return; + } + } + + if (user != null) { + if (user.status != null) { + lastStatus = user.status.expires; + } else { + lastStatus = 0; + } + lastName = user.first_name + user.last_name; + } + + lastAvatar = photo; + avatarImage.setImage(photo, "50_50", avatarDrawable, false); + + if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) { + buildLayout(); + } else { + requestLayout(); + } + postInvalidate(); + } + + @Override + protected void onDraw(Canvas canvas) { + if (user == null) { + return; + } + + if (useSeparator) { + if (LocaleController.isRTL) { + canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(72), getMeasuredHeight() - 1, linePaint); + } else { + canvas.drawLine(AndroidUtilities.dp(72), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint); + } + } + + if (drawAlpha != 1) { + canvas.saveLayerAlpha(0, 0, canvas.getWidth(), canvas.getHeight(), (int)(255 * drawAlpha), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG); + } + + canvas.save(); + canvas.translate(nameLeft, nameTop); + nameLayout.draw(canvas); + canvas.restore(); + + if (onlineLayout != null) { + canvas.save(); + canvas.translate(onlineLeft, onlineTop); + onlineLayout.draw(canvas); + canvas.restore(); + } + + avatarImage.draw(canvas); + } +} diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index e933bb6f4..d5e8630da 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -436,7 +436,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (currentEncryptedChat != null) { MediaController.getInstance().stopMediaObserver(); } - + getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); AndroidUtilities.unlockOrientation(getParentActivity()); MediaController.getInstance().stopAudio(); } @@ -555,7 +555,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (currentEncryptedChat != null) { args.putLong("dialog_id", dialog_id); } - presentFragment(new UserProfileActivity(args)); + presentFragment(new ProfileActivity(args)); } else if (currentChat != null) { if (info != null && info instanceof TLRPC.TL_chatParticipantsForbidden) { return; @@ -2383,6 +2383,9 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not public void onResume() { super.onResume(); + if (parentLayout != null) { + parentLayout.getDrawerLayoutContainer().setStatusBarColor(0xff54759e); + } getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); checkActionBarMenu(); @@ -2459,7 +2462,6 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not @Override public void onPause() { super.onPause(); - getParentActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); actionBarLayer.hideActionMode(); chatActivityEnterView.hideEmojiPopup(); paused = true; @@ -3127,7 +3129,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (user != null && user.id != UserConfig.getClientUserId()) { Bundle args = new Bundle(); args.putInt("user_id", user.id); - presentFragment(new UserProfileActivity(args)); + presentFragment(new ProfileActivity(args)); } } @@ -3315,7 +3317,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not if (uid != UserConfig.getClientUserId()) { Bundle args = new Bundle(); args.putInt("user_id", uid); - presentFragment(new UserProfileActivity(args)); + presentFragment(new ProfileActivity(args)); } } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index 38725543e..f58ead169 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -36,7 +36,7 @@ import org.telegram.messenger.UserConfig; import org.telegram.messenger.Utilities; import org.telegram.android.MessageObject; import org.telegram.ui.Adapters.BaseFragmentAdapter; -import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Cells.UserCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.AvatarDrawable; @@ -257,7 +257,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } Bundle args = new Bundle(); args.putInt("user_id", user_id); - presentFragment(new UserProfileActivity(args)); + presentFragment(new ProfileActivity(args)); } else if (i == settingsNotificationsRow) { Bundle args = new Bundle(); args.putLong("dialog_id", -chat_id); @@ -403,8 +403,8 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); - if (child instanceof ChatOrUserCell) { - ((ChatOrUserCell) child).update(mask); + if (child instanceof UserCell) { + ((UserCell) child).update(mask); } } } @@ -476,7 +476,6 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen Bundle args = new Bundle(); args.putBoolean("onlyUsers", true); args.putBoolean("destroyAfterSelect", true); - args.putBoolean("usersAsSections", true); args.putBoolean("returnAsResult", true); //args.putBoolean("allowUsernameSearch", false); if (chat_id > 0) { @@ -633,7 +632,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen } if (count != 0 && onlineCount > 1) { - onlineText.setText(Html.fromHtml(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount)))); + onlineText.setText(Html.fromHtml(String.format("%s, %s", LocaleController.formatPluralString("Members", count), LocaleController.formatPluralString("Online", onlineCount)))); } else { onlineText.setText(LocaleController.formatPluralString("Members", count)); } @@ -685,12 +684,11 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen TLRPC.User user = MessagesController.getInstance().getUser(part.user_id); if (view == null) { - view = new ChatOrUserCell(mContext); - ((ChatOrUserCell)view).usePadding = false; - ((ChatOrUserCell)view).useSeparator = true; + view = new UserCell(mContext); + ((UserCell)view).useSeparator = true; } - ((ChatOrUserCell)view).setData(user, null, null, null, null); + ((UserCell)view).setData(user, null, null); } else if (type == 4) { if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index 79bfe6efe..583319f97 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -8,11 +8,9 @@ package org.telegram.ui; -import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.content.Intent; -import android.content.SharedPreferences; import android.net.Uri; import android.os.Build; import android.os.Bundle; @@ -33,48 +31,43 @@ import android.widget.TextView; import org.telegram.android.AndroidUtilities; import org.telegram.android.LocaleController; import org.telegram.android.MessagesStorage; -import org.telegram.messenger.TLObject; import org.telegram.messenger.TLRPC; -import org.telegram.messenger.ConnectionsManager; import org.telegram.android.ContactsController; import org.telegram.messenger.FileLog; import org.telegram.android.MessagesController; import org.telegram.android.NotificationCenter; import org.telegram.messenger.R; -import org.telegram.messenger.RPCRequest; import org.telegram.messenger.UserConfig; +import org.telegram.ui.Adapters.BaseSectionsAdapter; import org.telegram.ui.Adapters.ContactsActivityAdapter; import org.telegram.ui.Adapters.ContactsActivitySearchAdapter; -import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Cells.UserCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; import org.telegram.ui.Views.ActionBar.BaseFragment; -import org.telegram.ui.Views.PinnedHeaderListView; -import org.telegram.ui.Views.SectionedBaseAdapter; +import org.telegram.ui.Views.SectionsListView; import java.util.ArrayList; import java.util.HashMap; -import java.util.Locale; public class ContactsActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate { - private SectionedBaseAdapter listViewAdapter; - private PinnedHeaderListView listView; + + private BaseSectionsAdapter listViewAdapter; + private TextView emptyTextView; + private SectionsListView listView; private ContactsActivitySearchAdapter searchListViewAdapter; + private boolean searchWas; private boolean searching; private boolean onlyUsers; - private boolean usersAsSections; + private boolean needPhonebook; private boolean destroyAfterSelect; private boolean returnAsResult; private boolean createSecretChat; private boolean creatingChat = false; private String selectAlertString = null; - private TextView emptyTextView; private HashMap ignoreUsers; - - private String inviteText; - private boolean updatingInviteText = false; private boolean allowUsernameSearch = true; private ContactsActivityDelegate delegate; @@ -96,19 +89,15 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (arguments != null) { onlyUsers = getArguments().getBoolean("onlyUsers", false); destroyAfterSelect = arguments.getBoolean("destroyAfterSelect", false); - usersAsSections = arguments.getBoolean("usersAsSections", false); returnAsResult = arguments.getBoolean("returnAsResult", false); createSecretChat = arguments.getBoolean("createSecretChat", false); selectAlertString = arguments.getString("selectAlertString"); allowUsernameSearch = arguments.getBoolean("allowUsernameSearch", true); + } else { + needPhonebook = true; } - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - inviteText = preferences.getString("invitetext", null); - int time = preferences.getInt("invitetexttime", 0); - if (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000)) { - updateInviteText(); - } + ContactsController.getInstance().checkInviteText(); return true; } @@ -125,6 +114,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter @Override public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + searching = false; + searchWas = false; + actionBarLayer.setBackButtonImage(R.drawable.ic_ab_back); actionBarLayer.setBackOverlay(R.layout.updating_state_layout); if (destroyAfterSelect) { @@ -157,7 +149,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter ViewGroup group = (ViewGroup) listView.getParent(); listView.setAdapter(listViewAdapter); listViewAdapter.notifyDataSetChanged(); - listView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 30 : 16), listView.getPaddingTop(), AndroidUtilities.dp(LocaleController.isRTL ? 16 : 30), listView.getPaddingBottom()); if (android.os.Build.VERSION.SDK_INT >= 11) { listView.setFastScrollAlwaysVisible(true); } @@ -176,7 +167,6 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (text.length() != 0) { searchWas = true; if (listView != null) { - listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom()); listView.setAdapter(searchListViewAdapter); searchListViewAdapter.notifyDataSetChanged(); if(android.os.Build.VERSION.SDK_INT >= 11) { @@ -193,31 +183,48 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } }); - searching = false; - searchWas = false; - - fragmentView = inflater.inflate(R.layout.contacts_layout, container, false); - - emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView); - emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); searchListViewAdapter = new ContactsActivitySearchAdapter(getParentActivity(), ignoreUsers, allowUsernameSearch); + listViewAdapter = new ContactsActivityAdapter(getParentActivity(), onlyUsers, needPhonebook, ignoreUsers); - listView = (PinnedHeaderListView)fragmentView.findViewById(R.id.listView); - listView.setEmptyView(emptyTextView); - listView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 30 : 16), listView.getPaddingTop(), AndroidUtilities.dp(LocaleController.isRTL ? 16 : 30), listView.getPaddingBottom()); - if (Build.VERSION.SDK_INT >= 11) { - listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); - } + fragmentView = new FrameLayout(getParentActivity()); + + emptyTextView = new TextView(getParentActivity()); + emptyTextView.setTextColor(0xff808080); + emptyTextView.setTextSize(24); + emptyTextView.setGravity(Gravity.CENTER); + emptyTextView.setVisibility(View.INVISIBLE); + emptyTextView.setText(LocaleController.getString("NoContacts", R.string.NoContacts)); + ((FrameLayout) fragmentView).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() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); - listView.setVerticalScrollBarEnabled(false); - listViewAdapter = new ContactsActivityAdapter(getParentActivity(), onlyUsers, usersAsSections, ignoreUsers); + listView = new SectionsListView(getParentActivity()); + listView.setEmptyView(emptyTextView); + listView.setVerticalScrollBarEnabled(false); + listView.setDivider(null); + listView.setDividerHeight(0); + listView.setFastScrollEnabled(true); + listView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY); listView.setAdapter(listViewAdapter); + if (Build.VERSION.SDK_INT >= 11) { + listView.setFastScrollAlwaysVisible(true); + listView.setVerticalScrollbarPosition(LocaleController.isRTL ? ListView.SCROLLBAR_POSITION_LEFT : ListView.SCROLLBAR_POSITION_RIGHT); + } + ((FrameLayout) fragmentView).addView(listView); + layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + listView.setLayoutParams(layoutParams); + listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { @@ -253,86 +260,84 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (row < 0 || section < 0) { return; } - TLRPC.User user = null; - if (usersAsSections) { - if (section < ContactsController.getInstance().sortedUsersSectionsArray.size()) { - ArrayList arr = ContactsController.getInstance().usersSectionsDict.get(ContactsController.getInstance().sortedUsersSectionsArray.get(section)); - if (row < arr.size()) { - TLRPC.TL_contact contact = arr.get(row); - user = MessagesController.getInstance().getUser(contact.user_id); - } else { - return; - } - } - } else { - if (section == 0) { + if (!onlyUsers && section == 0) { + if (needPhonebook) { if (row == 0) { try { Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain"); - intent.putExtra(Intent.EXTRA_TEXT, inviteText != null ? inviteText : LocaleController.getString("InviteText", R.string.InviteText)); + intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText()); getParentActivity().startActivity(intent); } catch (Exception e) { FileLog.e("tmessages", e); } - return; - } else { - if (row - 1 < ContactsController.getInstance().contacts.size()) { - user = MessagesController.getInstance().getUser(ContactsController.getInstance().contacts.get(row - 1).user_id); - } else { - return; - } } - } - } - - if (user != null) { - if (user.id == UserConfig.getClientUserId()) { - return; - } - if (returnAsResult) { - if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) { - return; - } - didSelectResult(user, true, null); } else { - if (createSecretChat) { - creatingChat = true; - MessagesController.getInstance().startSecretChat(getParentActivity(), user); - } else { + if (row == 0) { + presentFragment(new GroupCreateActivity(), true); + } else if (row == 1) { Bundle args = new Bundle(); - args.putInt("user_id", user.id); - presentFragment(new ChatActivity(args), true); + args.putBoolean("onlyUsers", true); + args.putBoolean("destroyAfterSelect", true); + args.putBoolean("createSecretChat", true); + presentFragment(new ContactsActivity(args), true); + } else if (row == 2) { + Bundle args = new Bundle(); + args.putBoolean("broadcast", true); + presentFragment(new GroupCreateActivity(args), true); } } } else { - ArrayList arr = ContactsController.getInstance().contactsSectionsDict.get(ContactsController.getInstance().sortedContactsSectionsArray.get(section - 1)); - ContactsController.Contact contact = arr.get(row); - String usePhone = null; - if (!contact.phones.isEmpty()) { - usePhone = contact.phones.get(0); - } - if (usePhone == null || getParentActivity() == null) { - return; - } - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser)); - builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); - final String arg1 = usePhone; - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - try { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null)); - intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText)); - getParentActivity().startActivity(intent); - } catch (Exception e) { - FileLog.e("tmessages", e); + Object item = listViewAdapter.getItem(section, row); + + if (item instanceof TLRPC.User) { + TLRPC.User user = (TLRPC.User) item; + if (user.id == UserConfig.getClientUserId()) { + return; + } + if (returnAsResult) { + if (ignoreUsers != null && ignoreUsers.containsKey(user.id)) { + return; + } + didSelectResult(user, true, null); + } else { + if (createSecretChat) { + creatingChat = true; + MessagesController.getInstance().startSecretChat(getParentActivity(), user); + } else { + Bundle args = new Bundle(); + args.putInt("user_id", user.id); + presentFragment(new ChatActivity(args), true); } } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - showAlertDialog(builder); + } else if (item instanceof ContactsController.Contact) { + ContactsController.Contact contact = (ContactsController.Contact) item; + String usePhone = null; + if (!contact.phones.isEmpty()) { + usePhone = contact.phones.get(0); + } + if (usePhone == null || getParentActivity() == null) { + return; + } + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setMessage(LocaleController.getString("InviteUser", R.string.InviteUser)); + builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); + final String arg1 = usePhone; + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + try { + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", arg1, null)); + intent.putExtra("sms_body", LocaleController.getString("InviteText", R.string.InviteText)); + getParentActivity().startActivity(intent); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + showAlertDialog(builder); + } } } } @@ -432,45 +437,13 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter } } - private void updateInviteText() { - if (!updatingInviteText) { - updatingInviteText = true; - TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText(); - req.lang_code = LocaleController.getLocaleString(Locale.getDefault()); - if (req.lang_code == null || req.lang_code.length() == 0) { - req.lang_code = "en"; - } - ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { - @Override - public void run(TLObject response, TLRPC.TL_error error) { - if (error == null) { - final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response; - if (res.message.length() != 0) { - AndroidUtilities.runOnUIThread(new Runnable() { - @Override - public void run() { - updatingInviteText = false; - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - editor.putString("invitetext", res.message); - editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000)); - editor.commit(); - } - }); - } - } - } - }, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors); - } - } - private void updateVisibleRows(int mask) { if (listView != null) { int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); - if (child instanceof ChatOrUserCell) { - ((ChatOrUserCell) child).update(mask); + if (child instanceof UserCell) { + ((UserCell) child).update(mask); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java index 2df5cc6de..d2681cbd6 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateActivity.java @@ -568,7 +568,7 @@ public class GroupCreateActivity extends BaseFragment implements NotificationCen holder.messageTextView.setText(LocaleController.formatUserStatus(user)); if (user.status != null && user.status.expires > ConnectionsManager.getInstance().getCurrentTime()) { - holder.messageTextView.setTextColor(0xff357aa8); + holder.messageTextView.setTextColor(0xff548ab6); } else { holder.messageTextView.setTextColor(0xff808080); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java index 36dcce7de..fb76a7bc0 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java @@ -30,7 +30,7 @@ import org.telegram.messenger.FileLog; import org.telegram.android.MessagesController; import org.telegram.android.NotificationCenter; import org.telegram.messenger.R; -import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Cells.UserCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.AvatarDrawable; @@ -64,6 +64,7 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati public GroupCreateFinalActivity(Bundle args) { super(args); isBroadcast = args.getBoolean("broadcast", false); + avatarDrawable = new AvatarDrawable(); } @SuppressWarnings("unchecked") @@ -339,8 +340,8 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); - if (child instanceof ChatOrUserCell) { - ((ChatOrUserCell) child).update(mask); + if (child instanceof UserCell) { + ((UserCell) child).update(mask); } } } @@ -390,12 +391,11 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati TLRPC.User user = MessagesController.getInstance().getUser(selectedContacts.get(position)); if (convertView == null) { - convertView = new ChatOrUserCell(mContext); - ((ChatOrUserCell)convertView).usePadding = false; + convertView = new UserCell(mContext); } - ((ChatOrUserCell)convertView).setData(user, null, null, null, null); - ((ChatOrUserCell) convertView).useSeparator = position != selectedContacts.size() - 1; + ((UserCell)convertView).setData(user, null, null); + ((UserCell) convertView).useSeparator = position != selectedContacts.size() - 1; return convertView; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java index 0db139257..fa8d56248 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/IdenticonActivity.java @@ -17,6 +17,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.WindowManager; +import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; @@ -27,7 +28,7 @@ import org.telegram.android.MessagesController; import org.telegram.messenger.R; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.BaseFragment; -import org.telegram.ui.Views.IdenticonView; +import org.telegram.ui.Views.IdenticonDrawable; public class IdenticonActivity extends BaseFragment { private int chat_id; @@ -60,11 +61,13 @@ public class IdenticonActivity extends BaseFragment { }); fragmentView = inflater.inflate(R.layout.identicon_layout, container, false); - IdenticonView identiconView = (IdenticonView) fragmentView.findViewById(R.id.identicon_view); + ImageView identiconView = (ImageView) fragmentView.findViewById(R.id.identicon_view); TextView textView = (TextView)fragmentView.findViewById(R.id.identicon_text); TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat(chat_id); if (encryptedChat != null) { - identiconView.setBytes(encryptedChat.auth_key); + IdenticonDrawable drawable = new IdenticonDrawable(); + identiconView.setImageDrawable(drawable); + drawable.setBytes(encryptedChat.auth_key); TLRPC.User user = MessagesController.getInstance().getUser(encryptedChat.user_id); textView.setText(Html.fromHtml(LocaleController.formatString("EncryptionKeyDescription", R.string.EncryptionKeyDescription, user.first_name, user.first_name))); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index a086266ed..6869ee2bb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -39,6 +39,7 @@ import android.widget.Toast; import org.telegram.android.AndroidUtilities; import org.telegram.PhoneFormat.PhoneFormat; +import org.telegram.android.ContactsController; import org.telegram.android.SendMessagesHelper; import org.telegram.messenger.ConnectionsManager; import org.telegram.messenger.FileLog; @@ -204,7 +205,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa Bundle args = new Bundle(); args.putBoolean("onlyUsers", true); args.putBoolean("destroyAfterSelect", true); - args.putBoolean("usersAsSections", true); args.putBoolean("createSecretChat", true); presentFragment(new ContactsActivity(args)); } @@ -268,7 +268,6 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa Bundle args = new Bundle(); args.putBoolean("onlyUsers", true); args.putBoolean("destroyAfterSelect", true); - args.putBoolean("usersAsSections", true); args.putBoolean("createSecretChat", true); presentFragment(new ContactsActivity(args)); drawerLayoutContainer.closeDrawer(false); @@ -277,15 +276,29 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa args.putBoolean("broadcast", true); presentFragment(new GroupCreateActivity(args)); drawerLayoutContainer.closeDrawer(false); - } else if (position == 8) { + } else if (position == 6) { presentFragment(new ContactsActivity(null)); drawerLayoutContainer.closeDrawer(false); - } else if (position == 9) { + } else if (position == 7) { + try { + Intent intent = new Intent(Intent.ACTION_SEND); + intent.setType("text/plain"); + intent.putExtra(Intent.EXTRA_TEXT, ContactsController.getInstance().getInviteText()); + startActivity(intent); + } catch (Exception e) { + FileLog.e("tmessages", e); + } drawerLayoutContainer.closeDrawer(false); - } else if (position == 10) { + } else if (position == 8) { presentFragment(new SettingsActivity()); drawerLayoutContainer.closeDrawer(false); - } else if (position == 11) { + } else if (position == 9) { + try { + Intent pickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(LocaleController.getString("TelegramFaqUrl", R.string.TelegramFaqUrl))); + startActivity(pickIntent); + } catch (Exception e) { + FileLog.e("tmessages", e); + } drawerLayoutContainer.closeDrawer(false); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java index 6c5898cd9..9f8eb75b6 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java @@ -144,7 +144,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente } codeField.setText(""); AndroidUtilities.setWaitingForSms(true); - NotificationCenter.getInstance().addObserver(this, 998); + NotificationCenter.getInstance().addObserver(this, NotificationCenter.didReceiveSmsCode); currentParams = params; waitingForSms = true; String phone = params.getString("phone"); @@ -279,7 +279,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente nextPressed = true; waitingForSms = false; AndroidUtilities.setWaitingForSms(false); - NotificationCenter.getInstance().removeObserver(this, 998); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode); final TLRPC.TL_auth_signIn req = new TLRPC.TL_auth_signIn(); req.phone_number = requestPhone; req.phone_code = codeField.getText().toString(); @@ -353,7 +353,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente destroyCodeTimer(); currentParams = null; AndroidUtilities.setWaitingForSms(false); - NotificationCenter.getInstance().removeObserver(this, 998); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode); waitingForSms = false; } @@ -361,7 +361,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente public void onDestroyActivity() { super.onDestroyActivity(); AndroidUtilities.setWaitingForSms(false); - NotificationCenter.getInstance().removeObserver(this, 998); + NotificationCenter.getInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode); destroyTimer(); destroyCodeTimer(); waitingForSms = false; @@ -378,7 +378,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente @Override public void didReceivedNotification(int id, final Object... args) { - if (id == 998) { + if (id == NotificationCenter.didReceiveSmsCode) { AndroidUtilities.runOnUIThread(new Runnable() { @Override public void run() { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index 5fae08af3..9eb7d940e 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -259,6 +259,9 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No @Override public void onResume() { super.onResume(); + if (parentLayout != null) { + parentLayout.getDrawerLayoutContainer().setStatusBarColor(0xff54759e); + } if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 72b762e10..7dc66a992 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -44,7 +44,7 @@ import org.telegram.ui.Adapters.MessagesActivityAdapter; import org.telegram.ui.Adapters.MessagesActivitySearchAdapter; import org.telegram.ui.AnimationCompat.ObjectAnimatorProxy; import org.telegram.ui.AnimationCompat.ViewProxy; -import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Cells.UserCell; import org.telegram.ui.Cells.DialogCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; @@ -266,9 +266,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter @Override public void onClick(View v) { Bundle args = new Bundle(); - args.putBoolean("onlyUsers", true); args.putBoolean("destroyAfterSelect", true); - args.putBoolean("usersAsSections", true); presentFragment(new ContactsActivity(args)); } }); @@ -613,8 +611,8 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter } } cell.update(mask); - } else if (child instanceof ChatOrUserCell) { - ((ChatOrUserCell) child).update(mask); + } else if (child instanceof UserCell) { + ((UserCell) child).update(mask); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java similarity index 58% rename from TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java rename to TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java index 46bdd0189..f4996bf94 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileActivity.java @@ -12,14 +12,17 @@ import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; -import android.graphics.Typeface; import android.net.Uri; +import android.os.Build; import android.os.Bundle; +import android.util.TypedValue; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; -import android.widget.ImageButton; +import android.widget.FrameLayout; +import android.widget.ImageView; import android.widget.ListView; import android.widget.TextView; @@ -35,20 +38,28 @@ import org.telegram.android.NotificationCenter; import org.telegram.messenger.R; import org.telegram.android.MessageObject; import org.telegram.ui.Adapters.BaseFragmentAdapter; +import org.telegram.ui.Cells.DividerCell; +import org.telegram.ui.Cells.EmptyCell; +import org.telegram.ui.Cells.TextCell; +import org.telegram.ui.Cells.TextDetailCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; import org.telegram.ui.Views.AvatarDrawable; import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.ActionBar.BaseFragment; -import org.telegram.ui.Views.IdenticonView; -import org.telegram.ui.Views.SettingsSectionLayout; +import org.telegram.ui.Views.IdenticonDrawable; import java.util.ArrayList; -public class UserProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, PhotoViewer.PhotoViewerProvider { +public class ProfileActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate, PhotoViewer.PhotoViewerProvider { private ListView listView; private ListAdapter listAdapter; + private BackupImageView avatarImage; + private TextView nameTextView; + private TextView onlineTextView; + FrameLayout nameContainer; + private int user_id; private int totalMediaCount = -1; private boolean creatingChat = false; @@ -62,19 +73,18 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen private final static int edit_contact = 4; private final static int delete_contact = 5; - private int avatarRow; - private int phoneSectionRow; + private int emptyRow; private int phoneRow; private int usernameRow; - private int settingsSectionRow; private int settingsTimerRow; private int settingsKeyRow; private int settingsNotificationsRow; - private int sharedMediaSectionRow; private int sharedMediaRow; + private int startSecretChatRow; + private int sectionRow; private int rowCount = 0; - public UserProfileActivity(Bundle args) { + public ProfileActivity(Bundle args) { super(args); } @@ -115,41 +125,12 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen MessagesController.getInstance().cancelLoadFullUser(user_id); } - private void updateRowsIds() { - rowCount = 0; - avatarRow = rowCount++; - phoneSectionRow = rowCount++; - phoneRow = rowCount++; - TLRPC.User user = MessagesController.getInstance().getUser(user_id); - if (user != null && user.username != null && user.username.length() > 0) { - usernameRow = rowCount++; - } else { - usernameRow = -1; - } - settingsSectionRow = rowCount++; - if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) { - settingsTimerRow = rowCount++; - settingsKeyRow = rowCount++; - } else { - settingsTimerRow = -1; - settingsKeyRow = -1; - } - settingsNotificationsRow = rowCount++; - sharedMediaSectionRow = rowCount++; - sharedMediaRow = rowCount++; - } - @Override public View createView(LayoutInflater inflater, ViewGroup container) { if (fragmentView == null) { + actionBarLayer.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(user_id)); actionBarLayer.setBackButtonImage(R.drawable.ic_ab_back); actionBarLayer.setBackOverlay(R.layout.updating_state_layout); - if (dialog_id != 0) { - actionBarLayer.setTitle(LocaleController.getString("SecretTitle", R.string.SecretTitle)); - actionBarLayer.setTitleIcon(R.drawable.ic_lock_white, AndroidUtilities.dp(4)); - } else { - actionBarLayer.setTitle(LocaleController.getString("ContactInfo", R.string.ContactInfo)); - } actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() { @Override public void onItemClick(final int id) { @@ -185,7 +166,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen args.putBoolean("onlySelect", true); args.putBoolean("serverOnly", true); MessagesActivity fragment = new MessagesActivity(args); - fragment.setDelegate(UserProfileActivity.this); + fragment.setDelegate(ProfileActivity.this); presentFragment(fragment); } else if (id == edit_contact) { Bundle args = new Bundle(); @@ -215,44 +196,95 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen createActionBarMenu(); - fragmentView = inflater.inflate(R.layout.user_profile_layout, container, false); listAdapter = new ListAdapter(getParentActivity()); - TextView textView = (TextView)fragmentView.findViewById(R.id.start_secret_button_text); - textView.setText(LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat)); + fragmentView = new FrameLayout(getParentActivity()); + FrameLayout frameLayout = (FrameLayout) fragmentView; - View startSecretButton = fragmentView.findViewById(R.id.start_secret_button); - startSecretButton.setOnClickListener(new View.OnClickListener() { + nameContainer = new FrameLayout(getParentActivity()); + nameContainer.setBackgroundColor(AvatarDrawable.getProfileBackColorForId(user_id)); + frameLayout.addView(nameContainer); + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) nameContainer.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = AndroidUtilities.dp(88); + nameContainer.setLayoutParams(layoutParams); + + avatarImage = new BackupImageView(getParentActivity()); + avatarImage.imageReceiver.setRoundRadius(AndroidUtilities.dp(30)); + avatarImage.processDetach = false; + nameContainer.addView(avatarImage); + FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) avatarImage.getLayoutParams(); + layoutParams1.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; + layoutParams1.width = AndroidUtilities.dp(60); + layoutParams1.height = AndroidUtilities.dp(60); + layoutParams1.leftMargin = LocaleController.isRTL ? 0 : AndroidUtilities.dp(17); + layoutParams1.rightMargin = LocaleController.isRTL ? AndroidUtilities.dp(17) : 0; + layoutParams1.bottomMargin = AndroidUtilities.dp(22); + avatarImage.setLayoutParams(layoutParams1); + avatarImage.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View view) { - if (getParentActivity() == null) { - return; + public void onClick(View v) { + TLRPC.User user = MessagesController.getInstance().getUser(user_id); + if (user.photo != null && user.photo.photo_big != null) { + PhotoViewer.getInstance().setParentActivity(getParentActivity()); + PhotoViewer.getInstance().openPhoto(user.photo.photo_big, ProfileActivity.this); } - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - builder.setMessage(LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat)); - builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); - builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - creatingChat = true; - MessagesController.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id)); - } - }); - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - showAlertDialog(builder); } }); - if (dialog_id == 0) { - startSecretButton.setVisibility(View.VISIBLE); - } else { - startSecretButton.setVisibility(View.GONE); - } - listView = (ListView)fragmentView.findViewById(R.id.listView); + nameTextView = new TextView(getParentActivity()); + nameTextView.setTextColor(0xffffffff); + nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20); + nameTextView.setLines(1); + nameTextView.setMaxLines(1); + nameTextView.setSingleLine(true); + nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); + nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf")); + nameContainer.addView(nameTextView); + layoutParams1 = (FrameLayout.LayoutParams) nameTextView.getLayoutParams(); + layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97); + layoutParams1.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16); + layoutParams1.bottomMargin = AndroidUtilities.dp(51); + layoutParams1.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; + nameTextView.setLayoutParams(layoutParams1); + + onlineTextView = new TextView(getParentActivity()); + onlineTextView.setTextColor(0xffd0e4ea); + onlineTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14); + onlineTextView.setLines(1); + onlineTextView.setMaxLines(1); + onlineTextView.setSingleLine(true); + onlineTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT)); + nameContainer.addView(onlineTextView); + layoutParams1 = (FrameLayout.LayoutParams) onlineTextView.getLayoutParams(); + layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 97); + layoutParams1.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 97 : 16); + layoutParams1.bottomMargin = AndroidUtilities.dp(30); + layoutParams1.gravity = (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.BOTTOM; + onlineTextView.setLayoutParams(layoutParams1); + + listView = new ListView(getParentActivity()); + listView.setDivider(null); + listView.setDividerHeight(0); + listView.setVerticalScrollBarEnabled(false); + frameLayout.addView(listView); + layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); + layoutParams.topMargin = AndroidUtilities.dp(88); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.height = FrameLayout.LayoutParams.MATCH_PARENT; + listView.setLayoutParams(layoutParams); + listView.setAdapter(listAdapter); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, final int i, long l) { + if (getParentActivity() == null) { + return; + } if (i == sharedMediaRow) { Bundle args = new Bundle(); if (dialog_id != 0) { @@ -274,6 +306,50 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen Bundle args = new Bundle(); args.putLong("dialog_id", dialog_id == 0 ? user_id : dialog_id); presentFragment(new ProfileNotificationsActivity(args)); + } else if (i == startSecretChatRow) { + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setMessage(LocaleController.getString("AreYouSureSecretChat", R.string.AreYouSureSecretChat)); + builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); + builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + creatingChat = true; + MessagesController.getInstance().startSecretChat(getParentActivity(), MessagesController.getInstance().getUser(user_id)); + } + }); + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + showAlertDialog(builder); + } else if (i == phoneRow) { + final TLRPC.User user = MessagesController.getInstance().getUser(user_id); + if (user == null || user.phone == null || user.phone.length() == 0 || getParentActivity() == null) { + return; + } + + AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); + builder.setItems(new CharSequence[] {LocaleController.getString("Call", R.string.Call), LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int i) { + if (i == 0) { + try { + Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone)); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + getParentActivity().startActivity(intent); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } else if (i == 1) { + if(Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.HONEYCOMB) { + android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + clipboard.setText(user.phone); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); + android.content.ClipData clip = android.content.ClipData.newPlainText("label", user.phone); + clipboard.setPrimaryClip(clip); + } + } + } + }); + showAlertDialog(builder); } } }); @@ -282,6 +358,33 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen } else { MessagesController.getInstance().getMediaCount(user_id, classGuid, true); } + + ImageView writeButton = new ImageView(getParentActivity()); + writeButton.setImageResource(R.drawable.floating_states); + frameLayout.addView(writeButton); + layoutParams1 = (FrameLayout.LayoutParams) writeButton.getLayoutParams(); + layoutParams1.width = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.height = FrameLayout.LayoutParams.WRAP_CONTENT; + layoutParams1.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 16 : 0); + layoutParams1.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 16); + layoutParams1.topMargin = AndroidUtilities.dp(58); + layoutParams1.gravity = (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT); + writeButton.setLayoutParams(layoutParams1); + writeButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + TLRPC.User user = MessagesController.getInstance().getUser(user_id); + if (user == null || user instanceof TLRPC.TL_userEmpty) { + return; + } + NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); + Bundle args = new Bundle(); + args.putInt("user_id", user_id); + presentFragment(new ChatActivity(args), true); + } + }); + + updateUserData(); } else { ViewGroup parent = (ViewGroup)fragmentView.getParent(); if (parent != null) { @@ -295,10 +398,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if (id == NotificationCenter.updateInterfaces) { int mask = (Integer)args[0]; if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0 || (mask & MessagesController.UPDATE_MASK_NAME) != 0) { - updateRowsIds(); - if (listView != null) { - listView.invalidateViews(); - } + updateUserData(); } } else if (id == NotificationCenter.contactsDidLoaded) { createActionBarMenu(); @@ -344,6 +444,9 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public void onResume() { super.onResume(); + if (parentLayout != null) { + parentLayout.getDrawerLayoutContainer().setStatusBarColor(AvatarDrawable.getProfileBackColorForId(user_id)); + } if (listAdapter != null) { listAdapter.notifyDataSetChanged(); } @@ -358,24 +461,17 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen if (user != null && user.photo != null && user.photo.photo_big != null) { TLRPC.FileLocation photoBig = user.photo.photo_big; if (photoBig.local_id == fileLocation.local_id && photoBig.volume_id == fileLocation.volume_id && photoBig.dc_id == fileLocation.dc_id) { - int count = listView.getChildCount(); - for (int a = 0; a < count; a++) { - View view = listView.getChildAt(a); - BackupImageView avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); - if (avatarImage != null) { - int coords[] = new int[2]; - avatarImage.getLocationInWindow(coords); - PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject(); - object.viewX = coords[0]; - object.viewY = coords[1] - AndroidUtilities.statusBarHeight; - object.parentView = listView; - object.imageReceiver = avatarImage.imageReceiver; - object.user_id = user_id; - object.thumb = object.imageReceiver.getBitmap(); - object.size = -1; - return object; - } - } + int coords[] = new int[2]; + avatarImage.getLocationInWindow(coords); + PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject(); + object.viewX = coords[0]; + object.viewY = coords[1] - AndroidUtilities.statusBarHeight; + object.parentView = nameContainer; + object.imageReceiver = avatarImage.imageReceiver; + object.user_id = user_id; + object.thumb = object.imageReceiver.getBitmap(); + object.size = -1; + return object; } } return null; @@ -402,6 +498,50 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public int getSelectedCount() { return 0; } + private void updateRowsIds() { + rowCount = 0; + emptyRow = rowCount++; + phoneRow = rowCount++; + TLRPC.User user = MessagesController.getInstance().getUser(user_id); + if (user != null && user.username != null && user.username.length() > 0) { + usernameRow = rowCount++; + } else { + usernameRow = -1; + } + sectionRow = rowCount++; + if (currentEncryptedChat instanceof TLRPC.TL_encryptedChat) { + settingsTimerRow = rowCount++; + settingsKeyRow = rowCount++; + } else { + settingsTimerRow = -1; + settingsKeyRow = -1; + } + settingsNotificationsRow = rowCount++; + sharedMediaRow = rowCount++; + if (currentEncryptedChat == null) { + startSecretChatRow = rowCount++; + } else { + startSecretChatRow = -1; + } + } + + private void updateUserData() { + TLRPC.User user = MessagesController.getInstance().getUser(user_id); + TLRPC.FileLocation photo = null; + TLRPC.FileLocation photoBig = null; + if (user.photo != null) { + photo = user.photo.photo_small; + photoBig = user.photo.photo_big; + } + avatarImage.setImage(photo, "50_50", new AvatarDrawable(user, true)); + avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false); + + nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name)); + onlineTextView.setText(LocaleController.formatUserStatus(user)); + + avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false); + } + private void createActionBarMenu() { ActionBarMenu menu = actionBarLayer.createMenu(); menu.clearItems(); @@ -472,7 +612,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public boolean isEnabled(int i) { - return i == phoneRow || i == settingsTimerRow || i == settingsKeyRow || i == settingsNotificationsRow || i == sharedMediaRow; + return i == phoneRow || i == settingsTimerRow || i == settingsKeyRow || i == settingsNotificationsRow || i == sharedMediaRow || i == startSecretChatRow; } @Override @@ -499,191 +639,72 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen public View getView(int i, View view, ViewGroup viewGroup) { int type = getItemViewType(i); if (type == 0) { - BackupImageView avatarImage; - TextView onlineText; - TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (view == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = li.inflate(R.layout.user_profile_avatar_layout, viewGroup, false); - - onlineText = (TextView)view.findViewById(R.id.settings_online); - avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); - avatarImage.processDetach = false; - avatarImage.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - TLRPC.User user = MessagesController.getInstance().getUser(user_id); - if (user.photo != null && user.photo.photo_big != null) { - PhotoViewer.getInstance().setParentActivity(getParentActivity()); - PhotoViewer.getInstance().openPhoto(user.photo.photo_big, UserProfileActivity.this); - } - } - }); - } else { - avatarImage = (BackupImageView)view.findViewById(R.id.settings_avatar_image); - onlineText = (TextView)view.findViewById(R.id.settings_online); + view = new EmptyCell(mContext, 36); } - TextView textView = (TextView)view.findViewById(R.id.settings_name); - Typeface typeface = AndroidUtilities.getTypeface("fonts/rmedium.ttf"); - textView.setTypeface(typeface); - - textView.setText(ContactsController.formatName(user.first_name, user.last_name)); - onlineText.setText(LocaleController.formatUserStatus(user)); - - TLRPC.FileLocation photo = null; - TLRPC.FileLocation photoBig = null; - if (user.photo != null) { - photo = user.photo.photo_small; - photoBig = user.photo.photo_big; - } - avatarImage.setImage(photo, "50_50", new AvatarDrawable(user)); - avatarImage.imageReceiver.setVisible(!PhotoViewer.getInstance().isShowingImage(photoBig), false); - return view; } else if (type == 1) { if (view == null) { - view = new SettingsSectionLayout(mContext); - } - if (i == phoneSectionRow) { - ((SettingsSectionLayout) view).setText(LocaleController.getString("Info", R.string.Info)); - } else if (i == settingsSectionRow) { - ((SettingsSectionLayout) view).setText(LocaleController.getString("SETTINGS", R.string.SETTINGS)); - } else if (i == sharedMediaSectionRow) { - ((SettingsSectionLayout) view).setText(LocaleController.getString("SHAREDMEDIA", R.string.SHAREDMEDIA)); + view = new DividerCell(mContext); + view.setPadding(AndroidUtilities.dp(72), 0, 0, 0); } } else if (type == 2) { final TLRPC.User user = MessagesController.getInstance().getUser(user_id); if (view == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = li.inflate(R.layout.user_profile_phone_layout, viewGroup, false); - view.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - if (user.phone == null || user.phone.length() == 0 || getParentActivity() == null) { - return; - } - - AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); - - builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy)}, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - if (i == 0) { - int sdk = android.os.Build.VERSION.SDK_INT; - if(sdk < android.os.Build.VERSION_CODES.HONEYCOMB) { - android.text.ClipboardManager clipboard = (android.text.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); - clipboard.setText(user.phone); - } else { - android.content.ClipboardManager clipboard = (android.content.ClipboardManager)ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE); - android.content.ClipData clip = android.content.ClipData.newPlainText("label", user.phone); - clipboard.setPrimaryClip(clip); - } - } - } - }); - showAlertDialog(builder); - } - }); - ImageButton button = (ImageButton)view.findViewById(R.id.settings_edit_name); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - TLRPC.User user = MessagesController.getInstance().getUser(user_id); - if (user == null || user instanceof TLRPC.TL_userEmpty) { - return; - } - NotificationCenter.getInstance().postNotificationName(NotificationCenter.closeChats); - Bundle args = new Bundle(); - args.putInt("user_id", user_id); - presentFragment(new ChatActivity(args), true); - } - }); - button = (ImageButton)view.findViewById(R.id.settings_call_phone); - button.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - try { - Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:+" + user.phone)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getParentActivity().startActivity(intent); - } catch (Exception e) { - FileLog.e("tmessages", e); - } - } - }); + view = new TextDetailCell(mContext); } - ImageButton button = (ImageButton)view.findViewById(R.id.settings_call_phone); - button.setVisibility(user.phone == null || user.phone.length() == 0 ? View.GONE : View.VISIBLE); + TextDetailCell textDetailCell = (TextDetailCell) view; - TextView textView = (TextView)view.findViewById(R.id.settings_row_text); - TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail); - View divider = view.findViewById(R.id.settings_row_divider); if (i == phoneRow) { + String text; if (user.phone != null && user.phone.length() != 0) { - textView.setText(PhoneFormat.getInstance().format("+" + user.phone)); + text = PhoneFormat.getInstance().format("+" + user.phone); } else { - textView.setText(LocaleController.getString("NumberUnknown", R.string.NumberUnknown)); + text = LocaleController.getString("NumberUnknown", R.string.NumberUnknown); } - divider.setVisibility(usernameRow != -1 ? View.VISIBLE : View.INVISIBLE); - detailTextView.setText(LocaleController.getString("PhoneMobile", R.string.PhoneMobile)); + textDetailCell.setTextAndValue(text, LocaleController.getString("PhoneMobile", R.string.PhoneMobile)); + } else if (i == usernameRow) { + String text; + if (user != null && user.username != null && user.username.length() != 0) { + text = "@" + user.username; + } else { + text = "-"; + } + textDetailCell.setTextAndValue(text, LocaleController.getString("Username", R.string.Username)); } } else if (type == 3) { if (view == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false); + view = new TextCell(mContext); } - TextView textView = (TextView)view.findViewById(R.id.settings_row_text); - TextView detailTextView = (TextView)view.findViewById(R.id.settings_row_text_detail); + TextCell textCell = (TextCell) view; + textCell.setTextColor(0xff000000); - View divider = view.findViewById(R.id.settings_row_divider); if (i == sharedMediaRow) { - textView.setText(LocaleController.getString("SharedMedia", R.string.SharedMedia)); + String value; if (totalMediaCount == -1) { - detailTextView.setText(LocaleController.getString("Loading", R.string.Loading)); + value = LocaleController.getString("Loading", R.string.Loading); } else { - detailTextView.setText(String.format("%d", totalMediaCount)); + value = String.format("%d", totalMediaCount); } - divider.setVisibility(View.INVISIBLE); + textCell.setTextAndValue(LocaleController.getString("SharedMedia", R.string.SharedMedia), value); } else if (i == settingsTimerRow) { TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32)); - textView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); - divider.setVisibility(View.VISIBLE); + String value; if (encryptedChat.ttl == 0) { - detailTextView.setText(LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever)); + value = LocaleController.getString("ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever); } else { - detailTextView.setText(AndroidUtilities.formatTTLString(encryptedChat.ttl)); + value = AndroidUtilities.formatTTLString(encryptedChat.ttl); } - } else if (i == usernameRow) { - TLRPC.User user = MessagesController.getInstance().getUser(user_id); - textView.setText(LocaleController.getString("Username", R.string.Username)); - if (user != null && user.username != null && user.username.length() != 0) { - detailTextView.setText("@" + user.username); - } else { - detailTextView.setText("-"); - } - divider.setVisibility(View.INVISIBLE); - } - } else if (type == 4) { - if (view == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = li.inflate(R.layout.user_profile_identicon_layout, viewGroup, false); - } - TextView textView = (TextView)view.findViewById(R.id.settings_row_text); - View divider = view.findViewById(R.id.settings_row_divider); - divider.setVisibility(View.VISIBLE); - IdenticonView identiconView = (IdenticonView)view.findViewById(R.id.identicon_view); - TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32)); - identiconView.setBytes(encryptedChat.auth_key); - textView.setText(LocaleController.getString("EncryptionKey", R.string.EncryptionKey)); - } else if (type == 5) { - if (view == null) { - LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - view = li.inflate(R.layout.settings_row_button_layout, viewGroup, false); - } - TextView textView = (TextView)view.findViewById(R.id.settings_row_text); - View divider = view.findViewById(R.id.settings_row_divider); - if (i == settingsNotificationsRow) { - textView.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); - divider.setVisibility(View.INVISIBLE); + textCell.setTextAndValue(LocaleController.getString("MessageLifetime", R.string.MessageLifetime), value); + } else if (i == settingsNotificationsRow) { + textCell.setText(LocaleController.getString("NotificationsAndSounds", R.string.NotificationsAndSounds)); + } else if (i == startSecretChatRow) { + textCell.setText(LocaleController.getString("StartEncryptedChat", R.string.StartEncryptedChat)); + textCell.setTextColor(0xff37a919); + } else if (i == settingsKeyRow) { + IdenticonDrawable identiconDrawable = new IdenticonDrawable(); + TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance().getEncryptedChat((int)(dialog_id >> 32)); + identiconDrawable.setBytes(encryptedChat.auth_key); + textCell.setTextAndValueDrawable(LocaleController.getString("EncryptionKey", R.string.EncryptionKey), identiconDrawable); } } return view; @@ -691,25 +712,21 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public int getItemViewType(int i) { - if (i == avatarRow) { + if (i == emptyRow) { return 0; - } else if (i == phoneSectionRow || i == settingsSectionRow || i == sharedMediaSectionRow) { + } else if (i == sectionRow) { return 1; - } else if (i == phoneRow) { + } else if (i == phoneRow || i == usernameRow) { return 2; - } else if (i == sharedMediaRow || i == settingsTimerRow || i == usernameRow) { + } else if (i == sharedMediaRow || i == settingsTimerRow || i == settingsNotificationsRow || i == startSecretChatRow || i == settingsKeyRow) { return 3; - } else if (i == settingsKeyRow) { - return 4; - } else if (i == settingsNotificationsRow) { - return 5; } return 0; } @Override public int getViewTypeCount() { - return 6; + return 4; } @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java index 58c0ccc6f..3aadeff64 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ProfileNotificationsActivity.java @@ -253,6 +253,14 @@ public class ProfileNotificationsActivity extends BaseFragment implements Notifi return fragmentView; } + @Override + public void onResume() { + super.onResume(); + if (parentLayout != null) { + parentLayout.getDrawerLayoutContainer().setStatusBarColor(0xff54759e); + } + } + public void updateServerNotificationsSettings() { if ((int)dialog_id == 0) { return; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java index 96ffb2676..490cb5194 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsersActivity.java @@ -27,7 +27,7 @@ import org.telegram.android.MessagesController; import org.telegram.android.NotificationCenter; import org.telegram.messenger.R; import org.telegram.ui.Adapters.BaseFragmentAdapter; -import org.telegram.ui.Cells.ChatOrUserCell; +import org.telegram.ui.Cells.UserCell; import org.telegram.ui.Views.ActionBar.ActionBarLayer; import org.telegram.ui.Views.ActionBar.ActionBarMenu; import org.telegram.ui.Views.ActionBar.BaseFragment; @@ -72,7 +72,6 @@ public class SettingsBlockedUsersActivity extends BaseFragment implements Notifi Bundle args = new Bundle(); args.putBoolean("onlyUsers", true); args.putBoolean("destroyAfterSelect", true); - args.putBoolean("usersAsSections", true); args.putBoolean("returnAsResult", true); ContactsActivity fragment = new ContactsActivity(args); fragment.setDelegate(SettingsBlockedUsersActivity.this); @@ -111,7 +110,7 @@ public class SettingsBlockedUsersActivity extends BaseFragment implements Notifi if (i < MessagesController.getInstance().blockedUsers.size()) { Bundle args = new Bundle(); args.putInt("user_id", MessagesController.getInstance().blockedUsers.get(i)); - presentFragment(new UserProfileActivity(args)); + presentFragment(new ProfileActivity(args)); } } }); @@ -177,8 +176,8 @@ public class SettingsBlockedUsersActivity extends BaseFragment implements Notifi int count = listView.getChildCount(); for (int a = 0; a < count; a++) { View child = listView.getChildAt(a); - if (child instanceof ChatOrUserCell) { - ((ChatOrUserCell) child).update(mask); + if (child instanceof UserCell) { + ((UserCell) child).update(mask); } } } @@ -244,12 +243,11 @@ public class SettingsBlockedUsersActivity extends BaseFragment implements Notifi int type = getItemViewType(i); if (type == 0) { if (view == null) { - view = new ChatOrUserCell(mContext); - ((ChatOrUserCell)view).usePadding = false; - ((ChatOrUserCell)view).useSeparator = true; + view = new UserCell(mContext); + ((UserCell)view).useSeparator = true; } TLRPC.User user = MessagesController.getInstance().getUser(MessagesController.getInstance().blockedUsers.get(i)); - ((ChatOrUserCell)view).setData(user, null, null, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown)); + ((UserCell)view).setData(user, null, user.phone != null && user.phone.length() != 0 ? PhoneFormat.getInstance().format("+" + user.phone) : LocaleController.getString("NumberUnknown", R.string.NumberUnknown)); } else if (type == 1) { if (view == null) { LayoutInflater li = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 881d75bf2..104a2bd60 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -16,6 +16,7 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.Point; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.Bundle; @@ -222,7 +223,8 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica if (requestCode == 10) { Utilities.addMediaToGallery(currentPicturePath); try { - Bitmap bitmap = ImageLoader.loadBitmap(currentPicturePath, null, AndroidUtilities.dp(320), AndroidUtilities.dp(480)); + Point screenSize = AndroidUtilities.getRealScreenSize(); + Bitmap bitmap = ImageLoader.loadBitmap(currentPicturePath, null, screenSize.x, screenSize.y); File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); @@ -238,7 +240,8 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica return; } try { - Bitmap bitmap = ImageLoader.loadBitmap(null, data.getData(), AndroidUtilities.dp(320), AndroidUtilities.dp(480)); + Point screenSize = AndroidUtilities.getRealScreenSize(); + Bitmap bitmap = ImageLoader.loadBitmap(null, data.getData(), screenSize.x, screenSize.y); File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper-temp.jpg"); FileOutputStream stream = new FileOutputStream(toFile); bitmap.compress(Bitmap.CompressFormat.JPEG, 87, stream); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarDrawable.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarDrawable.java index 23a406d07..ef9eeed0d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarDrawable.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarDrawable.java @@ -26,11 +26,14 @@ public class AvatarDrawable extends Drawable { private static Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); private static TextPaint namePaint; private static int[] arrColors = {0xffe56555, 0xfff28c48, 0xffeec764, 0xff76c84d, 0xff5fbed5, 0xff549cdd, 0xff8e85ee, 0xfff2749a}; + private static int[] arrColorsProfiles = {0xffd86f65, 0xffdc9663, 0xffdebc68, 0xff67b35d, 0xff56a2bb, 0xff5c98cd, 0xff8c79d2, 0xffda738e}; + private static int[] arrColorsProfilesBack = {0xffca6056, 0xffcf8550, 0xffcfa742, 0xff56a14c, 0xff4492ac, 0xff4c84b6, 0xff7d6ac4, 0xffc9637e}; private int color; private StaticLayout textLayout; private float textWidth; private float textHeight; + private boolean isProfile; public AvatarDrawable() { super(); @@ -56,10 +59,28 @@ public class AvatarDrawable extends Drawable { } } + public AvatarDrawable(TLRPC.User user, boolean profile) { + this(user); + isProfile = profile; + } + + public AvatarDrawable(TLRPC.Chat chat, boolean profile) { + this(chat); + isProfile = profile; + } + public static int getColorForId(int id) { return arrColors[Math.abs(id) % arrColors.length]; } + public static int getProfileColorForId(int id) { + return arrColorsProfiles[Math.abs(id) % arrColorsProfiles.length]; + } + + public static int getProfileBackColorForId(int id) { + return arrColorsProfilesBack[Math.abs(id) % arrColorsProfilesBack.length]; + } + public void setInfo(TLRPC.User user) { if (user != null) { setInfo(user.id, user.first_name, user.last_name, false); @@ -77,7 +98,11 @@ public class AvatarDrawable extends Drawable { } public void setInfo(int id, String firstName, String lastName, boolean isBroadcast) { - color = arrColors[Math.abs(id) % arrColors.length]; + if (isProfile) { + color = arrColorsProfiles[Math.abs(id) % arrColors.length]; + } else { + color = arrColors[Math.abs(id) % arrColors.length]; + } String text = ""; if (firstName != null && firstName.length() > 0) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonDrawable.java similarity index 63% rename from TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonView.java rename to TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonDrawable.java index 52e18d260..6ceba01c7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/IdenticonDrawable.java @@ -1,22 +1,22 @@ /* - * This is the source code of Telegram for Android v. 1.3.2. + * This is the source code of Telegram for Android v. 1.7.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. + * Copyright Nikolai Kudashov, 2013-2014. */ package org.telegram.ui.Views; -import android.content.Context; import android.graphics.Canvas; +import android.graphics.ColorFilter; import android.graphics.Paint; -import android.util.AttributeSet; -import android.view.View; +import android.graphics.drawable.Drawable; +import org.telegram.android.AndroidUtilities; import org.telegram.messenger.Utilities; -public class IdenticonView extends View { +public class IdenticonDrawable extends Drawable { private byte[] data; private Paint paint = new Paint(); private int colors[] = { @@ -26,18 +26,6 @@ public class IdenticonView extends View { 0xff2f99c9 }; - public IdenticonView(Context context) { - super(context); - } - - public IdenticonView(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public IdenticonView(Context context, AttributeSet attrs, int defStyle) { - super(context, attrs, defStyle); - } - int get_bits(int bitOffset, int numBits) { numBits = (int)Math.pow(2, numBits) - 1; int offset = bitOffset / 8; @@ -56,20 +44,19 @@ public class IdenticonView extends View { System.arraycopy(data, 0, temp, 0, data.length); data = temp; } - invalidate(); + invalidateSelf(); } @Override - protected void onDraw(Canvas canvas) { - super.onDraw(canvas); + public void draw(Canvas canvas) { if (data == null) { return; } int bitPointer = 0; - float rectSize = (float)Math.floor(Math.min(getWidth(), getHeight()) / 8.0f); - float xOffset = Math.max(0, (getWidth() - rectSize * 8) / 2); - float yOffset = Math.max(0, (getHeight() - rectSize * 8) / 2); + float rectSize = (float)Math.floor(Math.min(getBounds().width(), getBounds().height()) / 8.0f); + float xOffset = Math.max(0, (getBounds().width() - rectSize * 8) / 2); + float yOffset = Math.max(0, (getBounds().height() - rectSize * 8) / 2); for (int iy = 0; iy < 8; iy++) { for (int ix = 0; ix < 8; ix++) { int byteValue = get_bits(bitPointer, 2); @@ -80,4 +67,29 @@ public class IdenticonView extends View { } } } + + @Override + public void setAlpha(int alpha) { + + } + + @Override + public void setColorFilter(ColorFilter cf) { + + } + + @Override + public int getOpacity() { + return 0; + } + + @Override + public int getIntrinsicWidth() { + return AndroidUtilities.dp(32); + } + + @Override + public int getIntrinsicHeight() { + return AndroidUtilities.dp(32); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java index 1c9f97d68..5cfa5f3e0 100755 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionedBaseAdapter.java @@ -8,7 +8,6 @@ package org.telegram.ui.Views; -import android.database.DataSetObserver; import android.util.SparseArray; import android.view.View; import android.view.ViewGroup; @@ -223,11 +222,4 @@ public abstract class SectionedBaseAdapter extends BaseFragmentAdapter implement mSectionCount = getSectionCount(); return mSectionCount; } - - @Override - public void unregisterDataSetObserver(DataSetObserver observer) { - if (observer != null) { - super.unregisterDataSetObserver(observer); - } - } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java new file mode 100644 index 000000000..d2ee0169c --- /dev/null +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SectionsListView.java @@ -0,0 +1,215 @@ +/* + * This is the source code of Telegram for Android v. 1.7.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-2014. + */ + +package org.telegram.ui.Views; + +import android.content.Context; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.view.View; +import android.view.ViewGroup; +import android.widget.AbsListView; +import android.widget.AdapterView; +import android.widget.ListAdapter; +import android.widget.ListView; + +import org.telegram.messenger.FileLog; +import org.telegram.ui.Adapters.BaseSectionsAdapter; + +import java.util.ArrayList; + +public class SectionsListView extends ListView implements AbsListView.OnScrollListener { + + private ArrayList headers = new ArrayList(); + private ArrayList headersCache = new ArrayList(); + private OnScrollListener mOnScrollListener; + private BaseSectionsAdapter mAdapter; + private int currentFirst = -1; + private int currentVisible = -1; + private int startSection; + private int sectionsCount; + + public SectionsListView(Context context) { + super(context); + super.setOnScrollListener(this); + } + + public SectionsListView(Context context, AttributeSet attrs) { + super(context, attrs); + super.setOnScrollListener(this); + } + + public SectionsListView(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + super.setOnScrollListener(this); + } + + @Override + public void setAdapter(ListAdapter adapter) { + if (mAdapter == adapter) { + return; + } + headers.clear(); + headersCache.clear(); + if (adapter instanceof BaseSectionsAdapter) { + mAdapter = (BaseSectionsAdapter) adapter; + } else { + mAdapter = null; + } + super.setAdapter(adapter); + } + + @Override + public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { + if (mOnScrollListener != null) { + mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); + } + if (mAdapter == null) { + return; + } + + headersCache.addAll(headers); + headers.clear(); + + if (mAdapter.getCount() == 0) { + return; + } + + if (currentFirst != firstVisibleItem || currentVisible != visibleItemCount) { + currentFirst = firstVisibleItem; + currentVisible = visibleItemCount; + + sectionsCount = 1; + startSection = mAdapter.getSectionForPosition(firstVisibleItem); + int itemNum = firstVisibleItem + mAdapter.getCountForSection(startSection) - mAdapter.getPositionInSectionForPosition(firstVisibleItem); + while (true) { + if (itemNum >= firstVisibleItem + visibleItemCount) { + break; + } + itemNum += mAdapter.getCountForSection(startSection + sectionsCount); + sectionsCount++; + } + } + + int itemNum = firstVisibleItem; + for (int a = startSection; a < startSection + sectionsCount; a++) { + View header = null; + if (!headersCache.isEmpty()) { + header = headersCache.get(0); + headersCache.remove(0); + } + header = getSectionHeaderView(a, header); + headers.add(header); + int count = mAdapter.getCountForSection(a); + if (a == startSection) { + int pos = mAdapter.getPositionInSectionForPosition(itemNum); + if (pos == count - 1) { + header.setTag(-header.getHeight()); + } else if (pos == count - 2) { + View child = getChildAt(itemNum - firstVisibleItem); + int headerTop = child.getTop(); + if (headerTop < 0) { + header.setTag(headerTop); + } else { + header.setTag(0); + } + } else { + header.setTag(0); + } + itemNum += count - mAdapter.getPositionInSectionForPosition(firstVisibleItem); + } else { + View child = getChildAt(itemNum - firstVisibleItem); + header.setTag(child.getTop()); + itemNum += count; + } + } + + invalidate(); + } + + @Override + public void onScrollStateChanged(AbsListView view, int scrollState) { + if (mOnScrollListener != null) { + mOnScrollListener.onScrollStateChanged(view, scrollState); + } + } + + private View getSectionHeaderView(int section, View oldView) { + boolean shouldLayout = oldView == null; + View view = mAdapter.getSectionHeaderView(section, oldView, this); + if (shouldLayout) { + ensurePinnedHeaderLayout(view, false); + } + return view; + } + + @Override + protected void onSizeChanged(int w, int h, int oldw, int oldh) { + super.onSizeChanged(w, h, oldw, oldh); + if (mAdapter == null || headers.isEmpty()) { + return; + } + for (View header : headers) { + ensurePinnedHeaderLayout(header, true); + } + } + + private void ensurePinnedHeaderLayout(View header, boolean forceLayout) { + if (header.isLayoutRequested() || forceLayout) { + ViewGroup.LayoutParams layoutParams = header.getLayoutParams(); + int heightSpec = MeasureSpec.makeMeasureSpec(layoutParams.height, MeasureSpec.EXACTLY); + int widthSpec = MeasureSpec.makeMeasureSpec(layoutParams.width, MeasureSpec.EXACTLY); + try { + header.measure(widthSpec, heightSpec); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); + } + } + + @Override + protected void dispatchDraw(Canvas canvas) { + super.dispatchDraw(canvas); + if (mAdapter == null || headers.isEmpty()) { + return; + } + for (View header : headers) { + int saveCount = canvas.save(); + int top = (Integer)header.getTag(); + canvas.translate(0, top); + canvas.clipRect(0, 0, getWidth(), header.getMeasuredHeight()); + if (top < 0) { + canvas.saveLayerAlpha(0, top, header.getWidth(), top + canvas.getHeight(), (int)(255 * (1.0f + (float)top / (float)header.getMeasuredHeight())), Canvas.HAS_ALPHA_LAYER_SAVE_FLAG); + } + header.draw(canvas); + canvas.restoreToCount(saveCount); + } + } + + @Override + public void setOnScrollListener(OnScrollListener l) { + mOnScrollListener = l; + } + + public void setOnItemClickListener(SectionsListView.OnItemClickListener listener) { + super.setOnItemClickListener(listener); + } + + public static abstract class OnItemClickListener implements AdapterView.OnItemClickListener { + @Override + public void onItemClick(AdapterView adapterView, View view, int rawPosition, long id) { + SectionedBaseAdapter adapter = (SectionedBaseAdapter) adapterView.getAdapter(); + int section = adapter.getSectionForPosition(rawPosition); + int position = adapter.getPositionInSectionForPosition(rawPosition); + onItemClick(adapterView, view, section, position, id); + } + + public abstract void onItemClick(AdapterView adapterView, View view, int section, int position, long id); + } +} diff --git a/TMessagesProj/src/main/res/drawable-hdpi/bigtimer.png b/TMessagesProj/src/main/res/drawable-hdpi/bigtimer.png deleted file mode 100755 index 083bb13a6..000000000 Binary files a/TMessagesProj/src/main/res/drawable-hdpi/bigtimer.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/broadcast_w.png b/TMessagesProj/src/main/res/drawable-hdpi/broadcast_w.png new file mode 100755 index 000000000..007323ebc Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/broadcast_w.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/grouplist.png b/TMessagesProj/src/main/res/drawable-hdpi/grouplist.png deleted file mode 100755 index d57569f74..000000000 Binary files a/TMessagesProj/src/main/res/drawable-hdpi/grouplist.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/header_shadow.png b/TMessagesProj/src/main/res/drawable-hdpi/header_shadow.png new file mode 100755 index 000000000..9adb8afca Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/header_shadow.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/ic_lock_green.png b/TMessagesProj/src/main/res/drawable-hdpi/ic_lock_green.png deleted file mode 100644 index a7adbff61..000000000 Binary files a/TMessagesProj/src/main/res/drawable-hdpi/ic_lock_green.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/list_group.png b/TMessagesProj/src/main/res/drawable-hdpi/list_group.png new file mode 100755 index 000000000..bde0ddcb3 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/list_group.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/list_secret.png b/TMessagesProj/src/main/res/drawable-hdpi/list_secret.png new file mode 100755 index 000000000..54ed6bf28 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/list_secret.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/phone.png b/TMessagesProj/src/main/res/drawable-hdpi/phone.png new file mode 100755 index 000000000..7936266c9 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-hdpi/phone.png differ diff --git a/TMessagesProj/src/main/res/drawable-hdpi/popup_fixed.9.png b/TMessagesProj/src/main/res/drawable-hdpi/popup_fixed.9.png old mode 100644 new mode 100755 index 385734ee4..07c30b766 Binary files a/TMessagesProj/src/main/res/drawable-hdpi/popup_fixed.9.png and b/TMessagesProj/src/main/res/drawable-hdpi/popup_fixed.9.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/bigtimer.png b/TMessagesProj/src/main/res/drawable-mdpi/bigtimer.png deleted file mode 100755 index 6e92a895b..000000000 Binary files a/TMessagesProj/src/main/res/drawable-mdpi/bigtimer.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/broadcast_w.png b/TMessagesProj/src/main/res/drawable-mdpi/broadcast_w.png new file mode 100755 index 000000000..53ba97a4a Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/broadcast_w.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/grouplist.png b/TMessagesProj/src/main/res/drawable-mdpi/grouplist.png deleted file mode 100755 index d585fb875..000000000 Binary files a/TMessagesProj/src/main/res/drawable-mdpi/grouplist.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/header_shadow.png b/TMessagesProj/src/main/res/drawable-mdpi/header_shadow.png new file mode 100755 index 000000000..3f23c3eb5 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/header_shadow.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/ic_lock_green.png b/TMessagesProj/src/main/res/drawable-mdpi/ic_lock_green.png deleted file mode 100644 index f700548da..000000000 Binary files a/TMessagesProj/src/main/res/drawable-mdpi/ic_lock_green.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/list_group.png b/TMessagesProj/src/main/res/drawable-mdpi/list_group.png new file mode 100755 index 000000000..3d5818c4a Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/list_group.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/list_secret.png b/TMessagesProj/src/main/res/drawable-mdpi/list_secret.png new file mode 100755 index 000000000..4fc91b4d9 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/list_secret.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/phone.png b/TMessagesProj/src/main/res/drawable-mdpi/phone.png new file mode 100755 index 000000000..080456b47 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-mdpi/phone.png differ diff --git a/TMessagesProj/src/main/res/drawable-mdpi/popup_fixed.9.png b/TMessagesProj/src/main/res/drawable-mdpi/popup_fixed.9.png old mode 100644 new mode 100755 index e9204993d..8b72316de Binary files a/TMessagesProj/src/main/res/drawable-mdpi/popup_fixed.9.png and b/TMessagesProj/src/main/res/drawable-mdpi/popup_fixed.9.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/bigtimer.png b/TMessagesProj/src/main/res/drawable-xhdpi/bigtimer.png deleted file mode 100755 index 646b0042e..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xhdpi/bigtimer.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/broadcast_w.png b/TMessagesProj/src/main/res/drawable-xhdpi/broadcast_w.png new file mode 100755 index 000000000..ea1da2f3e Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/broadcast_w.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/grouplist.png b/TMessagesProj/src/main/res/drawable-xhdpi/grouplist.png deleted file mode 100755 index fc062608b..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xhdpi/grouplist.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/header_shadow.png b/TMessagesProj/src/main/res/drawable-xhdpi/header_shadow.png new file mode 100755 index 000000000..5492342b5 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/header_shadow.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/ic_lock_green.png b/TMessagesProj/src/main/res/drawable-xhdpi/ic_lock_green.png deleted file mode 100755 index 8515448c4..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xhdpi/ic_lock_green.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/list_group.png b/TMessagesProj/src/main/res/drawable-xhdpi/list_group.png new file mode 100755 index 000000000..98e1e2be8 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/list_group.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/list_secret.png b/TMessagesProj/src/main/res/drawable-xhdpi/list_secret.png new file mode 100755 index 000000000..f4ebc8b57 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/list_secret.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/phone.png b/TMessagesProj/src/main/res/drawable-xhdpi/phone.png new file mode 100755 index 000000000..bed929c52 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xhdpi/phone.png differ diff --git a/TMessagesProj/src/main/res/drawable-xhdpi/popup_fixed.9.png b/TMessagesProj/src/main/res/drawable-xhdpi/popup_fixed.9.png old mode 100644 new mode 100755 index a081ceb95..c94b50ef8 Binary files a/TMessagesProj/src/main/res/drawable-xhdpi/popup_fixed.9.png and b/TMessagesProj/src/main/res/drawable-xhdpi/popup_fixed.9.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/bigtimer.png b/TMessagesProj/src/main/res/drawable-xxhdpi/bigtimer.png deleted file mode 100755 index 04b0616e3..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xxhdpi/bigtimer.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/broadcast_w.png b/TMessagesProj/src/main/res/drawable-xxhdpi/broadcast_w.png new file mode 100755 index 000000000..c60de471f Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/broadcast_w.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/grouplist.png b/TMessagesProj/src/main/res/drawable-xxhdpi/grouplist.png deleted file mode 100755 index b63fa34e3..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xxhdpi/grouplist.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/header_shadow.png b/TMessagesProj/src/main/res/drawable-xxhdpi/header_shadow.png new file mode 100755 index 000000000..382af9c50 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/header_shadow.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/ic_lock_green.png b/TMessagesProj/src/main/res/drawable-xxhdpi/ic_lock_green.png deleted file mode 100644 index 3dd21a8ab..000000000 Binary files a/TMessagesProj/src/main/res/drawable-xxhdpi/ic_lock_green.png and /dev/null differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/list_group.png b/TMessagesProj/src/main/res/drawable-xxhdpi/list_group.png new file mode 100755 index 000000000..8113ffea0 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/list_group.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/list_secret.png b/TMessagesProj/src/main/res/drawable-xxhdpi/list_secret.png new file mode 100755 index 000000000..fd1e9f59f Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/list_secret.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/phone.png b/TMessagesProj/src/main/res/drawable-xxhdpi/phone.png new file mode 100755 index 000000000..4d8994378 Binary files /dev/null and b/TMessagesProj/src/main/res/drawable-xxhdpi/phone.png differ diff --git a/TMessagesProj/src/main/res/drawable-xxhdpi/popup_fixed.9.png b/TMessagesProj/src/main/res/drawable-xxhdpi/popup_fixed.9.png old mode 100644 new mode 100755 index fb7d715fa..050190c71 Binary files a/TMessagesProj/src/main/res/drawable-xxhdpi/popup_fixed.9.png and b/TMessagesProj/src/main/res/drawable-xxhdpi/popup_fixed.9.png differ diff --git a/TMessagesProj/src/main/res/layout-ar/user_profile_identicon_layout.xml b/TMessagesProj/src/main/res/layout-ar/user_profile_identicon_layout.xml deleted file mode 100644 index c35c5daa2..000000000 --- a/TMessagesProj/src/main/res/layout-ar/user_profile_identicon_layout.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/contacts_layout.xml b/TMessagesProj/src/main/res/layout/contacts_layout.xml deleted file mode 100644 index 8b281bc3e..000000000 --- a/TMessagesProj/src/main/res/layout/contacts_layout.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - diff --git a/TMessagesProj/src/main/res/layout/identicon_layout.xml b/TMessagesProj/src/main/res/layout/identicon_layout.xml index 1b4dac4d7..aed5e9270 100644 --- a/TMessagesProj/src/main/res/layout/identicon_layout.xml +++ b/TMessagesProj/src/main/res/layout/identicon_layout.xml @@ -15,9 +15,10 @@ android:paddingTop="20dp" android:paddingBottom="20dp"> - diff --git a/TMessagesProj/src/main/res/layout/user_profile_identicon_layout.xml b/TMessagesProj/src/main/res/layout/user_profile_identicon_layout.xml deleted file mode 100644 index ae0129fed..000000000 --- a/TMessagesProj/src/main/res/layout/user_profile_identicon_layout.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - \ No newline at end of file diff --git a/TMessagesProj/src/main/res/layout/user_profile_layout.xml b/TMessagesProj/src/main/res/layout/user_profile_layout.xml deleted file mode 100644 index f9583be97..000000000 --- a/TMessagesProj/src/main/res/layout/user_profile_layout.xml +++ /dev/null @@ -1,43 +0,0 @@ - - - - - - - - - - - diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 35a1c4601..c5e718a90 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -187,11 +187,11 @@ Block Edit Delete - HOME - MOBILE - WORK - OTHER - MAIN + Home + Mobile + Work + Other + Main Contact Info PHONE Start Secret Chat