Skip to content

Commit 41359b1

Browse files
author
DrKLO
committed
More Android L design
1 parent a4d42cb commit 41359b1

File tree

81 files changed

+1898
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+1898
-948
lines changed

TMessagesProj/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ android {
4343
buildTypes {
4444
debug {
4545
debuggable true
46-
jniDebugBuild false
46+
jniDebuggable true
4747
signingConfig signingConfigs.debug
4848
}
4949

5050
release {
5151
debuggable false
52-
jniDebugBuild false
52+
jniDebuggable false
5353
signingConfig signingConfigs.release
5454
}
5555

5656
foss {
5757
debuggable false
58-
jniDebugBuild false
58+
jniDebuggable false
5959
signingConfig signingConfigs.release
6060
}
6161
}
@@ -80,7 +80,7 @@ android {
8080
defaultConfig {
8181
minSdkVersion 8
8282
targetSdkVersion 21
83-
versionCode 379
84-
versionName "1.9.7"
83+
versionCode 380
84+
versionName "2.0.0"
8585
}
8686
}

TMessagesProj/src/main/java/org/telegram/android/ContactsController.java

Lines changed: 59 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010

1111
import android.accounts.Account;
1212
import android.accounts.AccountManager;
13+
import android.app.Activity;
1314
import android.content.ContentProviderOperation;
1415
import android.content.ContentProviderResult;
1516
import android.content.ContentResolver;
17+
import android.content.SharedPreferences;
1618
import android.database.Cursor;
1719
import android.net.Uri;
1820
import android.provider.BaseColumns;
@@ -35,6 +37,7 @@
3537
import java.util.Collections;
3638
import java.util.Comparator;
3739
import java.util.HashMap;
40+
import java.util.Locale;
3841
import java.util.concurrent.ConcurrentHashMap;
3942

4043
public class ContactsController {
@@ -48,6 +51,8 @@ public class ContactsController {
4851
private boolean contactsBookLoaded = false;
4952
private String lastContactsVersions = "";
5053
private ArrayList<Integer> delayedContactsUpdate = new ArrayList<Integer>();
54+
private String inviteText;
55+
private boolean updatingInviteText = false;
5156

5257
public static class Contact {
5358
public int id;
@@ -75,8 +80,7 @@ public static class Contact {
7580

7681
public HashMap<Integer, Contact> contactsBook = new HashMap<Integer, Contact>();
7782
public HashMap<String, Contact> contactsBookSPhones = new HashMap<String, Contact>();
78-
public HashMap<String, ArrayList<Contact>> contactsSectionsDict = new HashMap<String, ArrayList<Contact>>();
79-
public ArrayList<String> sortedContactsSectionsArray = new ArrayList<String>();
83+
public ArrayList<Contact> phoneBookContacts = new ArrayList<Contact>();
8084

8185
public ArrayList<TLRPC.TL_contact> contacts = new ArrayList<TLRPC.TL_contact>();
8286
public SparseArray<TLRPC.TL_contact> contactsDict = new SparseArray<TLRPC.TL_contact>();
@@ -102,8 +106,7 @@ public static ContactsController getInstance() {
102106
public void cleanup() {
103107
contactsBook.clear();
104108
contactsBookSPhones.clear();
105-
contactsSectionsDict.clear();
106-
sortedContactsSectionsArray.clear();
109+
phoneBookContacts.clear();
107110
contacts.clear();
108111
contactsDict.clear();
109112
usersSectionsDict.clear();
@@ -118,6 +121,45 @@ public void cleanup() {
118121
lastContactsVersions = "";
119122
}
120123

124+
public void checkInviteText() {
125+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
126+
inviteText = preferences.getString("invitetext", null);
127+
int time = preferences.getInt("invitetexttime", 0);
128+
if (!updatingInviteText && (inviteText == null || time + 86400 < (int)(System.currentTimeMillis() / 1000))) {
129+
updatingInviteText = true;
130+
TLRPC.TL_help_getInviteText req = new TLRPC.TL_help_getInviteText();
131+
req.lang_code = LocaleController.getLocaleString(Locale.getDefault());
132+
if (req.lang_code == null || req.lang_code.length() == 0) {
133+
req.lang_code = "en";
134+
}
135+
ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() {
136+
@Override
137+
public void run(TLObject response, TLRPC.TL_error error) {
138+
if (error == null) {
139+
final TLRPC.TL_help_inviteText res = (TLRPC.TL_help_inviteText)response;
140+
if (res.message.length() != 0) {
141+
AndroidUtilities.runOnUIThread(new Runnable() {
142+
@Override
143+
public void run() {
144+
updatingInviteText = false;
145+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE);
146+
SharedPreferences.Editor editor = preferences.edit();
147+
editor.putString("invitetext", res.message);
148+
editor.putInt("invitetexttime", (int) (System.currentTimeMillis() / 1000));
149+
editor.commit();
150+
}
151+
});
152+
}
153+
}
154+
}
155+
}, true, RPCRequest.RPCRequestClassGeneric | RPCRequest.RPCRequestClassFailOnServerErrors);
156+
}
157+
}
158+
159+
public String getInviteText() {
160+
return inviteText != null ? inviteText : LocaleController.getString("InviteText", R.string.InviteText);
161+
}
162+
121163
public void checkAppAccount() {
122164
AccountManager am = AccountManager.get(ApplicationLoader.applicationContext);
123165
Account[] accounts = am.getAccountsByType("org.telegram.account");
@@ -989,8 +1031,7 @@ private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contac
9891031
contactsPhonesShort.put(user.phone, value);
9901032
}
9911033

992-
final HashMap<String, ArrayList<Contact>> sectionsPhoneDict = new HashMap<String, ArrayList<Contact>>();
993-
final ArrayList<String> sortedSectionsPhoneArray = new ArrayList<String>();
1034+
final ArrayList<Contact> sortedPhoneBookContacts = new ArrayList<Contact>();
9941035
for (HashMap.Entry<Integer, Contact> pair : contactsBook.entrySet()) {
9951036
Contact value = pair.getValue();
9961037
int id = pair.getKey();
@@ -1007,61 +1048,24 @@ private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contac
10071048
continue;
10081049
}
10091050

1010-
String key = value.first_name;
1011-
if (key.length() == 0) {
1012-
key = value.last_name;
1013-
}
1014-
if (key.length() == 0) {
1015-
key = "#";
1016-
if (value.phones.size() != 0) {
1017-
value.first_name = "+" + value.phones.get(0);
1018-
}
1019-
} else {
1020-
key = key.toUpperCase();
1021-
}
1022-
if (key.length() > 1) {
1023-
key = key.substring(0, 1);
1024-
}
1025-
ArrayList<Contact> arr = sectionsPhoneDict.get(key);
1026-
if (arr == null) {
1027-
arr = new ArrayList<Contact>();
1028-
sectionsPhoneDict.put(key, arr);
1029-
sortedSectionsPhoneArray.add(key);
1030-
}
1031-
arr.add(value);
1051+
sortedPhoneBookContacts.add(value);
10321052
}
1033-
for (HashMap.Entry<String, ArrayList<Contact>> entry : sectionsPhoneDict.entrySet()) {
1034-
Collections.sort(entry.getValue(), new Comparator<Contact>() {
1035-
@Override
1036-
public int compare(Contact contact, Contact contact2) {
1037-
String toComapre1 = contact.first_name;
1038-
if (toComapre1.length() == 0) {
1039-
toComapre1 = contact.last_name;
1040-
}
1041-
String toComapre2 = contact2.first_name;
1042-
if (toComapre2.length() == 0) {
1043-
toComapre2 = contact2.last_name;
1044-
}
1045-
return toComapre1.compareTo(toComapre2);
1046-
}
1047-
});
1048-
}
1049-
Collections.sort(sortedSectionsPhoneArray, new Comparator<String>() {
1053+
Collections.sort(sortedPhoneBookContacts, new Comparator<Contact>() {
10501054
@Override
1051-
public int compare(String s, String s2) {
1052-
char cv1 = s.charAt(0);
1053-
char cv2 = s2.charAt(0);
1054-
if (cv1 == '#') {
1055-
return 1;
1056-
} else if (cv2 == '#') {
1057-
return -1;
1055+
public int compare(Contact contact, Contact contact2) {
1056+
String toComapre1 = contact.first_name;
1057+
if (toComapre1.length() == 0) {
1058+
toComapre1 = contact.last_name;
10581059
}
1059-
return s.compareTo(s2);
1060+
String toComapre2 = contact2.first_name;
1061+
if (toComapre2.length() == 0) {
1062+
toComapre2 = contact2.last_name;
1063+
}
1064+
return toComapre1.compareTo(toComapre2);
10601065
}
10611066
});
10621067

1063-
contactsSectionsDict = sectionsPhoneDict;
1064-
sortedContactsSectionsArray = sortedSectionsPhoneArray;
1068+
phoneBookContacts = sortedPhoneBookContacts;
10651069
}
10661070

10671071
private void buildContactsSectionsArrays(boolean sort) {

TMessagesProj/src/main/java/org/telegram/android/NotificationCenter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class NotificationCenter {
4545
public static final int wallpapersDidLoaded = 171;
4646
public static final int closeOtherAppActivities = 702;
4747
public static final int didUpdatedConnectionState = 703;
48+
public static final int didReceiveSmsCode = 998;
4849
public static final int emojiDidLoaded = 999;
4950
public static final int appDidLogout = 1234;
5051

TMessagesProj/src/main/java/org/telegram/android/SmsListener.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void onReceive(Context context, Intent intent) {
4848
if (matcher.find()) {
4949
String str = matcher.group(0);
5050
if (str.length() >= 3) {
51-
NotificationCenter.getInstance().postNotificationName(998, matcher.group(0));
51+
NotificationCenter.getInstance().postNotificationName(NotificationCenter.didReceiveSmsCode, matcher.group(0));
5252
}
5353
}
5454
} catch (Exception e) {

TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ public static CharSequence generateSearchName(String name, String name2, String
640640
builder.append(" ");
641641
}
642642
query.trim();
643-
builder.append(Html.fromHtml("<font color=\"#357aa8\">" + query + "</font>"));
643+
builder.append(Html.fromHtml("<font color=\"#548ab6\">" + query + "</font>"));
644644

645645
lastIndex = end;
646646
}
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* This is the source code of Telegram for Android v. 1.7.x.
3+
* It is licensed under GNU GPL v. 2 or later.
4+
* You should have received a copy of the license in this archive (see LICENSE).
5+
*
6+
* Copyright Nikolai Kudashov, 2013-2014.
7+
*/
8+
9+
package org.telegram.ui.Adapters;
10+
11+
import android.util.SparseArray;
12+
import android.view.View;
13+
import android.view.ViewGroup;
14+
15+
public abstract class BaseSectionsAdapter extends BaseFragmentAdapter {
16+
17+
private SparseArray<Integer> sectionPositionCache;
18+
private SparseArray<Integer> sectionCache;
19+
private SparseArray<Integer> sectionCountCache;
20+
private int sectionCount;
21+
private int count;
22+
23+
private void cleanupCache() {
24+
sectionCache = new SparseArray<Integer>();
25+
sectionPositionCache = new SparseArray<Integer>();
26+
sectionCountCache = new SparseArray<Integer>();
27+
count = -1;
28+
sectionCount = -1;
29+
}
30+
31+
public BaseSectionsAdapter() {
32+
super();
33+
cleanupCache();
34+
}
35+
36+
@Override
37+
public void notifyDataSetChanged() {
38+
cleanupCache();
39+
super.notifyDataSetChanged();
40+
}
41+
42+
@Override
43+
public void notifyDataSetInvalidated() {
44+
cleanupCache();
45+
super.notifyDataSetInvalidated();
46+
}
47+
48+
@Override
49+
public boolean areAllItemsEnabled() {
50+
return false;
51+
}
52+
53+
@Override
54+
public boolean isEnabled(int position) {
55+
return isRowEnabled(getSectionForPosition(position), getPositionInSectionForPosition(position));
56+
}
57+
58+
@Override
59+
public final long getItemId(int position) {
60+
return position;
61+
}
62+
63+
@Override
64+
public final int getCount() {
65+
if (count >= 0) {
66+
return count;
67+
}
68+
count = 0;
69+
for (int i = 0; i < internalGetSectionCount(); i++) {
70+
count += internalGetCountForSection(i);
71+
}
72+
return count;
73+
}
74+
75+
@Override
76+
public final Object getItem(int position) {
77+
return getItem(getSectionForPosition(position), getPositionInSectionForPosition(position));
78+
}
79+
80+
@Override
81+
public final int getItemViewType(int position) {
82+
return getItemViewType(getSectionForPosition(position), getPositionInSectionForPosition(position));
83+
}
84+
85+
@Override
86+
public final View getView(int position, View convertView, ViewGroup parent) {
87+
return getItemView(getSectionForPosition(position), getPositionInSectionForPosition(position), convertView, parent);
88+
}
89+
90+
private int internalGetCountForSection(int section) {
91+
Integer cachedSectionCount = sectionCountCache.get(section);
92+
if (cachedSectionCount != null) {
93+
return cachedSectionCount;
94+
}
95+
int sectionCount = getCountForSection(section);
96+
sectionCountCache.put(section, sectionCount);
97+
return sectionCount;
98+
}
99+
100+
private int internalGetSectionCount() {
101+
if (sectionCount >= 0) {
102+
return sectionCount;
103+
}
104+
sectionCount = getSectionCount();
105+
return sectionCount;
106+
}
107+
108+
public final int getSectionForPosition(int position) {
109+
Integer cachedSection = sectionCache.get(position);
110+
if (cachedSection != null) {
111+
return cachedSection;
112+
}
113+
int sectionStart = 0;
114+
for (int i = 0; i < internalGetSectionCount(); i++) {
115+
int sectionCount = internalGetCountForSection(i);
116+
int sectionEnd = sectionStart + sectionCount;
117+
if (position >= sectionStart && position < sectionEnd) {
118+
sectionCache.put(position, i);
119+
return i;
120+
}
121+
sectionStart = sectionEnd;
122+
}
123+
return 0;
124+
}
125+
126+
public int getPositionInSectionForPosition(int position) {
127+
Integer cachedPosition = sectionPositionCache.get(position);
128+
if (cachedPosition != null) {
129+
return cachedPosition;
130+
}
131+
int sectionStart = 0;
132+
for (int i = 0; i < internalGetSectionCount(); i++) {
133+
int sectionCount = internalGetCountForSection(i);
134+
int sectionEnd = sectionStart + sectionCount;
135+
if (position >= sectionStart && position < sectionEnd) {
136+
int positionInSection = position - sectionStart;
137+
sectionPositionCache.put(position, positionInSection);
138+
return positionInSection;
139+
}
140+
sectionStart = sectionEnd;
141+
}
142+
return 0;
143+
}
144+
145+
public abstract int getSectionCount();
146+
public abstract int getCountForSection(int section);
147+
public abstract boolean isRowEnabled(int section, int row);
148+
public abstract int getItemViewType(int section, int position);
149+
public abstract Object getItem(int section, int position);
150+
public abstract View getItemView(int section, int position, View convertView, ViewGroup parent);
151+
public abstract View getSectionHeaderView(int section, View convertView, ViewGroup parent);
152+
}

0 commit comments

Comments
 (0)