10
10
11
11
import android .accounts .Account ;
12
12
import android .accounts .AccountManager ;
13
+ import android .app .Activity ;
13
14
import android .content .ContentProviderOperation ;
14
15
import android .content .ContentProviderResult ;
15
16
import android .content .ContentResolver ;
17
+ import android .content .SharedPreferences ;
16
18
import android .database .Cursor ;
17
19
import android .net .Uri ;
18
20
import android .provider .BaseColumns ;
35
37
import java .util .Collections ;
36
38
import java .util .Comparator ;
37
39
import java .util .HashMap ;
40
+ import java .util .Locale ;
38
41
import java .util .concurrent .ConcurrentHashMap ;
39
42
40
43
public class ContactsController {
@@ -48,6 +51,8 @@ public class ContactsController {
48
51
private boolean contactsBookLoaded = false ;
49
52
private String lastContactsVersions = "" ;
50
53
private ArrayList <Integer > delayedContactsUpdate = new ArrayList <Integer >();
54
+ private String inviteText ;
55
+ private boolean updatingInviteText = false ;
51
56
52
57
public static class Contact {
53
58
public int id ;
@@ -75,8 +80,7 @@ public static class Contact {
75
80
76
81
public HashMap <Integer , Contact > contactsBook = new HashMap <Integer , Contact >();
77
82
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 >();
80
84
81
85
public ArrayList <TLRPC .TL_contact > contacts = new ArrayList <TLRPC .TL_contact >();
82
86
public SparseArray <TLRPC .TL_contact > contactsDict = new SparseArray <TLRPC .TL_contact >();
@@ -102,8 +106,7 @@ public static ContactsController getInstance() {
102
106
public void cleanup () {
103
107
contactsBook .clear ();
104
108
contactsBookSPhones .clear ();
105
- contactsSectionsDict .clear ();
106
- sortedContactsSectionsArray .clear ();
109
+ phoneBookContacts .clear ();
107
110
contacts .clear ();
108
111
contactsDict .clear ();
109
112
usersSectionsDict .clear ();
@@ -118,6 +121,45 @@ public void cleanup() {
118
121
lastContactsVersions = "" ;
119
122
}
120
123
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
+
121
163
public void checkAppAccount () {
122
164
AccountManager am = AccountManager .get (ApplicationLoader .applicationContext );
123
165
Account [] accounts = am .getAccountsByType ("org.telegram.account" );
@@ -989,8 +1031,7 @@ private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contac
989
1031
contactsPhonesShort .put (user .phone , value );
990
1032
}
991
1033
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 >();
994
1035
for (HashMap .Entry <Integer , Contact > pair : contactsBook .entrySet ()) {
995
1036
Contact value = pair .getValue ();
996
1037
int id = pair .getKey ();
@@ -1007,61 +1048,24 @@ private void updateUnregisteredContacts(final ArrayList<TLRPC.TL_contact> contac
1007
1048
continue ;
1008
1049
}
1009
1050
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 );
1032
1052
}
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 >() {
1050
1054
@ 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 ;
1058
1059
}
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 );
1060
1065
}
1061
1066
});
1062
1067
1063
- contactsSectionsDict = sectionsPhoneDict ;
1064
- sortedContactsSectionsArray = sortedSectionsPhoneArray ;
1068
+ phoneBookContacts = sortedPhoneBookContacts ;
1065
1069
}
1066
1070
1067
1071
private void buildContactsSectionsArrays (boolean sort ) {
0 commit comments