Skip to content

Commit 1c2010a

Browse files
author
DrKLO
committed
Bug fixes
1 parent d24578f commit 1c2010a

Some content is hidden

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

45 files changed

+1253
-76
lines changed

TMessagesProj/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ android {
8383
defaultConfig {
8484
minSdkVersion 8
8585
targetSdkVersion 19
86-
versionCode 281
87-
versionName "1.6.0"
86+
versionCode 286
87+
versionName "1.6.1"
8888
}
8989
}

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,23 @@ public static void hideKeyboard(View view) {
174174
public static File getCacheDir() {
175175
if (externalCacheNotAvailableState == 1 || externalCacheNotAvailableState == 0 && Environment.getExternalStorageState().startsWith(Environment.MEDIA_MOUNTED)) {
176176
externalCacheNotAvailableState = 1;
177-
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
178-
if (file != null) {
179-
return file;
177+
try {
178+
File file = ApplicationLoader.applicationContext.getExternalCacheDir();
179+
if (file != null) {
180+
return file;
181+
}
182+
} catch (Exception e) {
183+
FileLog.e("tmessages", e);
180184
}
181185
}
182186
externalCacheNotAvailableState = 2;
183-
File file = ApplicationLoader.applicationContext.getCacheDir();
184-
if (file != null) {
185-
return file;
187+
try {
188+
File file = ApplicationLoader.applicationContext.getCacheDir();
189+
if (file != null) {
190+
return file;
191+
}
192+
} catch (Exception e) {
193+
FileLog.e("tmessages", e);
186194
}
187195
return new File("");
188196
}

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

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -354,30 +354,45 @@ private void showOrUpdateNotification(boolean notifyAboutLast) {
354354
.setContentIntent(contentIntent);
355355

356356
String lastMessage = null;
357-
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
358-
inboxStyle.setBigContentTitle(name);
359-
int count = Math.min(10, pushMessages.size());
360-
for (int i = 0; i < count; i++) {
361-
String message = getStringForMessage(pushMessages.get(i));
357+
if (pushMessages.size() == 1) {
358+
String message = lastMessage = getStringForMessage(pushMessages.get(0));
362359
if (message == null) {
363-
continue;
360+
return;
364361
}
365-
if (i == 0) {
366-
lastMessage = message;
362+
if (replace) {
363+
if (chat != null) {
364+
message = message.replace(" @ " + name, "");
365+
} else {
366+
message = message.replace(name + ": ", "").replace(name + " ", "");
367+
}
367368
}
368-
if (pushDialogs.size() == 1) {
369-
if (replace) {
370-
if (chat != null) {
371-
message = message.replace(" @ " + name, "");
372-
} else {
373-
message = message.replace(name + ": ", "").replace(name + " ", "");
369+
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
370+
} else {
371+
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
372+
inboxStyle.setBigContentTitle(name);
373+
int count = Math.min(10, pushMessages.size());
374+
for (int i = 0; i < count; i++) {
375+
String message = getStringForMessage(pushMessages.get(i));
376+
if (message == null) {
377+
continue;
378+
}
379+
if (i == 0) {
380+
lastMessage = message;
381+
}
382+
if (pushDialogs.size() == 1) {
383+
if (replace) {
384+
if (chat != null) {
385+
message = message.replace(" @ " + name, "");
386+
} else {
387+
message = message.replace(name + ": ", "").replace(name + " ", "");
388+
}
374389
}
375390
}
391+
inboxStyle.addLine(message);
376392
}
377-
inboxStyle.addLine(message);
393+
inboxStyle.setSummaryText(detailText);
394+
mBuilder.setStyle(inboxStyle);
378395
}
379-
inboxStyle.setSummaryText(detailText);
380-
mBuilder.setStyle(inboxStyle);
381396

382397
if (photoPath != null) {
383398
Bitmap img = FileLoader.getInstance().getImageFromMemory(photoPath, null, null, "50_50", false);
@@ -547,38 +562,47 @@ public void processNewMessages(ArrayList<MessageObject> messageObjects, boolean
547562

548563
public void processDialogsUpdateRead(final HashMap<Long, Integer> dialogsToUpdate, boolean replace) {
549564
int old_unread_count = total_unread_count;
565+
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
550566
for (HashMap.Entry<Long, Integer> entry : dialogsToUpdate.entrySet()) {
551-
Long dialog_id = entry.getKey();
567+
long dialog_id = entry.getKey();
568+
569+
int notify_override = preferences.getInt("notify2_" + dialog_id, 0);
570+
boolean isChat = (int)dialog_id < 0;
552571
Integer currentCount = pushDialogs.get(dialog_id);
553-
Integer newCount = entry.getValue();
554-
if (replace) {
555-
if (currentCount != null) {
556-
total_unread_count -= currentCount;
557-
}
558-
if (newCount == 0) {
559-
pushDialogs.remove(dialog_id);
572+
if (!(notify_override == 2 || (!preferences.getBoolean("EnableAll", true) || isChat && !preferences.getBoolean("EnableGroup", true)) && notify_override == 0)) {
573+
Integer newCount = entry.getValue();
574+
if (replace) {
575+
if (currentCount != null) {
576+
total_unread_count -= currentCount;
577+
}
578+
if (newCount == 0) {
579+
pushDialogs.remove(dialog_id);
580+
} else {
581+
total_unread_count += newCount;
582+
pushDialogs.put(dialog_id, newCount);
583+
}
560584
} else {
585+
if (currentCount == null) {
586+
currentCount = 0;
587+
}
588+
currentCount += newCount;
561589
total_unread_count += newCount;
562-
pushDialogs.put(dialog_id, newCount);
590+
pushDialogs.put(dialog_id, currentCount);
563591
}
564-
} else {
565-
if (currentCount == null) {
566-
currentCount = 0;
567-
}
568-
currentCount += newCount;
569-
total_unread_count += newCount;
570-
pushDialogs.put(dialog_id, currentCount);
571592
}
572593
}
573594
if (old_unread_count != total_unread_count) {
574595
showOrUpdateNotification(notifyCheck);
575596
notifyCheck = false;
576597
}
577-
setBadge(ApplicationLoader.applicationContext, total_unread_count);
598+
if (preferences.getBoolean("badgeNumber", true)) {
599+
setBadge(ApplicationLoader.applicationContext, total_unread_count);
600+
}
578601
}
579602

580603
public void processLoadedUnreadMessages(HashMap<Long, Integer> dialogs) {
581604
pushDialogs.clear();
605+
total_unread_count = 0;
582606
SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Context.MODE_PRIVATE);
583607
String dialogsToLoad = "";
584608
for (HashMap.Entry<Long, Integer> entry : dialogs.entrySet()) {
@@ -594,7 +618,20 @@ public void processLoadedUnreadMessages(HashMap<Long, Integer> dialogs) {
594618
dialogsToLoad += "" + dialog_id;
595619
}
596620
}
597-
setBadge(ApplicationLoader.applicationContext, total_unread_count);
621+
if (total_unread_count == 0) {
622+
pushMessages.clear();
623+
pushMessagesDict.clear();
624+
popupMessages.clear();
625+
showOrUpdateNotification(false);
626+
NotificationCenter.getInstance().postNotificationName(pushMessagesUpdated);
627+
}
628+
if (preferences.getBoolean("badgeNumber", true)) {
629+
setBadge(ApplicationLoader.applicationContext, total_unread_count);
630+
}
631+
}
632+
633+
public void setBadgeEnabled(boolean enabled) {
634+
setBadge(ApplicationLoader.applicationContext, enabled ? total_unread_count : 0);
598635
}
599636

600637
private void setBadge(Context context, int count) {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,15 +101,18 @@ public static ConnectionsManager getInstance() {
101101
public void run() {
102102
Utilities.stageQueue.handler.removeCallbacks(stageRunnable);
103103
if (datacenters != null) {
104+
Datacenter datacenter = datacenterWithId(currentDatacenterId);
104105
if (sendingPushPing && lastPushPingTime < System.currentTimeMillis() - 30000 || Math.abs(lastPushPingTime - System.currentTimeMillis()) > 60000 * 3 + 10000) {
105106
lastPushPingTime = 0;
106107
sendingPushPing = false;
108+
if (datacenter != null && datacenter.pushConnection != null) {
109+
datacenter.pushConnection.suspendConnection(true);
110+
}
107111
FileLog.e("tmessages", "push ping timeout");
108112
}
109113
if (lastPushPingTime < System.currentTimeMillis() - 60000 * 3) {
110114
FileLog.e("tmessages", "time for push ping");
111115
lastPushPingTime = System.currentTimeMillis();
112-
Datacenter datacenter = datacenterWithId(currentDatacenterId);
113116
if (datacenter != null) {
114117
generatePing(datacenter, true);
115118
}
@@ -448,7 +451,7 @@ private void fillDatacenters() {
448451

449452
datacenter = new Datacenter();
450453
datacenter.datacenterId = 4;
451-
datacenter.addAddressAndPort("31.210.235.12", 443);
454+
datacenter.addAddressAndPort("149.154.167.90", 443);
452455
datacenters.put(datacenter.datacenterId, datacenter);
453456

454457
datacenter = new Datacenter();
@@ -2374,7 +2377,7 @@ public void tcpConnectionClosed(TcpConnection connection) {
23742377
FileLog.e("tmessages", "no network available");
23752378
}
23762379
} catch (Exception e) {
2377-
FileLog.e("tmessages", "NETWORK STATE GET ERROR");
2380+
FileLog.e("tmessages", "NETWORK STATE GET ERROR", e);
23782381
}
23792382
}
23802383
final int stateCopy = connectionState;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -674,7 +674,7 @@ private void processRequestResult(RequestInfo requestInfo, TLRPC.TL_error error)
674674
}
675675
}
676676

677-
if (downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
677+
if (totalBytesCount != downloadedBytes && downloadedBytes % downloadChunkSize == 0 || totalBytesCount > 0 && totalBytesCount > downloadedBytes) {
678678
startDownloadRequest();
679679
} else {
680680
onFinishLoadingFile();

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -174,17 +174,13 @@ long generateMessageId() {
174174
}
175175

176176
ByteBufferDesc sendMessageData(TLObject message, long messageId) {
177-
ByteBufferDesc innerOs = BuffersStorage.getInstance().getFreeBuffer(message.getObjectSize());
178-
message.serializeToStream(innerOs);
179-
message.freeResources();
180-
181-
ByteBufferDesc messageOs = BuffersStorage.getInstance().getFreeBuffer(8 + 8 + 4 + innerOs.length());
177+
int messageLength = message.getObjectSize();
178+
ByteBufferDesc messageOs = BuffersStorage.getInstance().getFreeBuffer(8 + 8 + 4 + messageLength);
182179
messageOs.writeInt64(0);
183180
messageOs.writeInt64(messageId);
184-
messageOs.writeInt32(innerOs.length());
185-
innerOs.position(0);
186-
messageOs.writeRaw(innerOs);
187-
BuffersStorage.getInstance().reuseFreeBuffer(innerOs);
181+
messageOs.writeInt32(messageLength);
182+
message.serializeToStream(messageOs);
183+
message.freeResources();
188184

189185
datacenter.connection.sendData(messageOs, false, false);
190186
return messageOs;

TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import com.google.android.gms.gcm.GoogleCloudMessaging;
3131

3232
import org.telegram.android.AndroidUtilities;
33+
import org.telegram.android.ContactsController;
3334
import org.telegram.android.NotificationsService;
3435
import org.telegram.messenger.BuildVars;
3536
import org.telegram.messenger.ConnectionsManager;
@@ -128,6 +129,8 @@ public static void postInitApplication() {
128129
ApplicationLoader app = (ApplicationLoader)ApplicationLoader.applicationContext;
129130
app.initPlayServices();
130131
FileLog.e("tmessages", "app initied");
132+
133+
ContactsController.getInstance().checkAppAccount();
131134
}
132135

133136
@Override

TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatOrUserCell.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public void build(int width, int height) {
307307
nameString = nameString2.replace("\n", " ");
308308
}
309309
if (nameString.length() == 0) {
310-
if (user.phone != null && user.phone.length() != 0) {
310+
if (user != null && user.phone != null && user.phone.length() != 0) {
311311
nameString = PhoneFormat.getInstance().format("+" + user.phone);
312312
} else {
313313
nameString = LocaleController.getString("HiddenName", R.string.HiddenName);

TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,8 @@
8989
import java.util.concurrent.Semaphore;
9090

9191
public class ChatActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate, MessagesActivity.MessagesActivityDelegate,
92-
DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider, PhotoPickerActivity.PhotoPickerActivityDelegate {
92+
DocumentSelectActivity.DocumentSelectActivityDelegate, PhotoViewer.PhotoViewerProvider, PhotoPickerActivity.PhotoPickerActivityDelegate,
93+
VideoEditorActivity.VideoEditorActivityDelegate {
9394

9495
private ChatActivityEnterView chatActivityEnterView;
9596
private View timeItem;
@@ -1318,7 +1319,15 @@ public void onActivityResultFragment(int requestCode, int resultCode, Intent dat
13181319
}
13191320
currentPicturePath = null;
13201321
}
1321-
processSendingVideo(videoPath);
1322+
/*if(android.os.Build.VERSION.SDK_INT >= 10) {
1323+
Bundle args = new Bundle();
1324+
args.putString("videoPath", videoPath);
1325+
VideoEditorActivity fragment = new VideoEditorActivity(args);
1326+
fragment.setDelegate(this);
1327+
presentFragment(fragment);
1328+
} else {*/
1329+
processSendingVideo(videoPath);
1330+
//}
13221331
} else if (requestCode == 21) {
13231332
if (data == null || data.getData() == null) {
13241333
showAttachmentError();
@@ -1339,6 +1348,11 @@ public void onActivityResultFragment(int requestCode, int resultCode, Intent dat
13391348
}
13401349
}
13411350

1351+
@Override
1352+
public void didFinishedVideoConverting(String videoPath) {
1353+
processSendingVideo(videoPath);
1354+
}
1355+
13421356
private void showAttachmentError() {
13431357
if (getParentActivity() == null) {
13441358
return;

TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ public void onItemClick(int id) {
133133
}
134134

135135
avatarImageView = (BackupImageView)fragmentView.findViewById(R.id.location_avatar_view);
136+
if (avatarImageView != null) {
137+
avatarImageView.processDetach = false;
138+
}
136139
nameTextView = (TextView)fragmentView.findViewById(R.id.location_name_label);
137140
distanceTextView = (TextView)fragmentView.findViewById(R.id.location_distance_label);
138141
View bottomView = fragmentView.findViewById(R.id.location_bottom_view);

0 commit comments

Comments
 (0)