diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index a0173758..7f216ab8 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -19,7 +19,7 @@ tasks.withType(JavaCompile) { dependencies { compile 'com.android.support:support-v4:20.0.+' compile 'com.google.android.gms:play-services:3.2.+' - compile 'net.hockeyapp.android:HockeySDK:3.0.1' + compile 'net.hockeyapp.android:HockeySDK:3.0.2' compile 'com.googlecode.mp4parser:isoparser:1.0.+' } diff --git a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java index d96bd68d..8de3f997 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/android/AndroidUtilities.java @@ -9,6 +9,7 @@ package org.telegram.android; import android.app.Activity; +import android.app.ProgressDialog; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; @@ -32,6 +33,9 @@ import java.util.Hashtable; import java.util.Locale; public class AndroidUtilities { + + public static ProgressDialog progressDialog; + private static final Hashtable typefaceCache = new Hashtable(); private static int prevOrientation = -10; private static boolean waitingForSms = false; @@ -371,4 +375,32 @@ public class AndroidUtilities { } return photoSize; } + + public static void ShowProgressDialog(final Activity activity, final String message) { + activity.runOnUiThread(new Runnable() { + @Override + public void run() { + if(activity != null && !activity.isFinishing()) { + progressDialog = new ProgressDialog(activity); + if (message != null) { + progressDialog.setMessage(message); + } + progressDialog.setCanceledOnTouchOutside(false); + progressDialog.setCancelable(false); + progressDialog.show(); + } + } + }); + } + + public static void HideProgressDialog() { + RunOnUIThread(new Runnable() { + @Override + public void run() { + if (progressDialog != null) { + progressDialog.dismiss(); + } + } + }); + } } diff --git a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java index 592b6e29..e47cb866 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java +++ b/TMessagesProj/src/main/java/org/telegram/android/MessagesStorage.java @@ -183,7 +183,8 @@ public class MessagesStorage { @Override public void run() { try { - if (currentVersion < 4) { + int version = currentVersion; + if (version < 4) { database.executeFast("CREATE TABLE IF NOT EXISTS user_photos(uid INTEGER, id INTEGER, data BLOB, PRIMARY KEY (uid, id))").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS mid_idx_media ON media(mid);").stepThis().dispose(); @@ -254,8 +255,10 @@ public class MessagesStorage { } } }); + database.executeFast("PRAGMA user_version = 4").stepThis().dispose(); + version = 4; } - if (currentVersion < 6) { + if (version == 4 && version < 6) { database.executeFast("CREATE TABLE IF NOT EXISTS enc_tasks_v2(mid INTEGER PRIMARY KEY, date INTEGER)").stepThis().dispose(); database.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v2 ON enc_tasks_v2(date);").stepThis().dispose(); database.beginTransaction(); @@ -284,6 +287,12 @@ public class MessagesStorage { database.executeFast("ALTER TABLE messages ADD COLUMN media INTEGER default 0").stepThis().dispose(); database.executeFast("PRAGMA user_version = 6").stepThis().dispose(); + version = 6; + } + if (version == 6 && version < 7) { + database.executeFast("ALTER TABLE enc_chats ADD COLUMN layer INTEGER default 0").stepThis().dispose(); + database.executeFast("PRAGMA user_version = 6").stepThis().dispose(); + version = 7; } } catch (Exception e) { FileLog.e("tmessages", e); diff --git a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java index ff2a5e90..63b2b1c1 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java +++ b/TMessagesProj/src/main/java/org/telegram/android/SendMessagesHelper.java @@ -326,23 +326,23 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } public void sendMessage(TLRPC.User user, long peer) { - sendMessage(null, 0, 0, null, null, null, user, null, null, null, peer, false, null); + sendMessage(null, null, null, null, null, null, user, null, null, null, peer, false, null); } public void sendMessage(MessageObject message) { - sendMessage(null, 0, 0, null, null, message, null, null, null, null, message.getDialogId(), true, message.messageOwner.attachPath); + sendMessage(null, null, null, null, null, message, null, null, null, null, message.getDialogId(), true, message.messageOwner.attachPath); } public void sendMessage(MessageObject message, long peer) { - sendMessage(null, 0, 0, null, null, message, null, null, null, null, peer, false, message.messageOwner.attachPath); + sendMessage(null, null, null, null, null, message, null, null, null, null, peer, false, message.messageOwner.attachPath); } public void sendMessage(TLRPC.TL_document document, String originalPath, String path, long peer) { - sendMessage(null, 0, 0, null, null, null, null, document, null, originalPath, peer, false, path); + sendMessage(null, null, null, null, null, null, null, document, null, originalPath, peer, false, path); } public void sendMessage(String message, long peer) { - sendMessage(message, 0, 0, null, null, null, null, null, null, null, peer, false, null); + sendMessage(message, null, null, null, null, null, null, null, null, null, peer, false, null); } public void sendMessage(double lat, double lon, long peer) { @@ -350,18 +350,18 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter } public void sendMessage(TLRPC.TL_photo photo, String originalPath, long peer) { - sendMessage(null, 0, 0, photo, null, null, null, null, null, originalPath, peer, false, null); + sendMessage(null, null, null, photo, null, null, null, null, null, originalPath, peer, false, null); } public void sendMessage(TLRPC.TL_video video, String originalPath, String path, long peer) { - sendMessage(null, 0, 0, null, video, null, null, null, null, originalPath, peer, false, path); + sendMessage(null, null, null, null, video, null, null, null, null, originalPath, peer, false, path); } public void sendMessage(TLRPC.TL_audio audio, String path, long peer) { - sendMessage(null, 0, 0, null, null, null, null, null, audio, null, peer, false, path); + sendMessage(null, null, null, null, null, null, null, null, audio, null, peer, false, path); } - private int sendMessage(String message, double lat, double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer, boolean retry, String path) { + private int sendMessage(String message, Double lat, Double lon, TLRPC.TL_photo photo, TLRPC.TL_video video, MessageObject msgObj, TLRPC.User user, TLRPC.TL_document document, TLRPC.TL_audio audio, String originalPath, long peer, boolean retry, String path) { TLRPC.Message newMsg = null; int type = -1; int lower_id = (int) peer; @@ -420,7 +420,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter newMsg.media = new TLRPC.TL_messageMediaEmpty(); type = 0; newMsg.message = message; - } else if (lat != 0 && lon != 0) { + } else if (lat != null && lon != null) { if (lower_id != 0) { newMsg = new TLRPC.TL_message(); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/android/VideoEncodingService.java b/TMessagesProj/src/main/java/org/telegram/android/VideoEncodingService.java index 17357053..e057c682 100644 --- a/TMessagesProj/src/main/java/org/telegram/android/VideoEncodingService.java +++ b/TMessagesProj/src/main/java/org/telegram/android/VideoEncodingService.java @@ -45,7 +45,7 @@ public class VideoEncodingService extends Service implements NotificationCenter. public void didReceivedNotification(int id, Object... args) { if (id == NotificationCenter.FileUploadProgressChanged) { String fileName = (String)args[0]; - if (path.equals(fileName)) { + if (path != null && path.equals(fileName)) { Float progress = (Float) args[1]; Boolean enc = (Boolean) args[2]; currentProgress = (int)(progress * 100); diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java index 998079ff..5fbf4226 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/Utilities.java @@ -9,7 +9,6 @@ package org.telegram.messenger; import android.app.Activity; -import android.app.ProgressDialog; import android.content.ContentUris; import android.content.Context; import android.content.Intent; @@ -73,8 +72,6 @@ public class Utilities { final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); - public static ProgressDialog progressDialog; - static { try { File URANDOM_FILE = new File("/dev/urandom"); @@ -426,34 +423,6 @@ public class Utilities { return packedData; } - public static void ShowProgressDialog(final Activity activity, final String message) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if(!activity.isFinishing()) { - progressDialog = new ProgressDialog(activity); - if (message != null) { - progressDialog.setMessage(message); - } - progressDialog.setCanceledOnTouchOutside(false); - progressDialog.setCancelable(false); - progressDialog.show(); - } - } - }); - } - - public static void HideProgressDialog(Activity activity) { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - if (progressDialog != null) { - progressDialog.dismiss(); - } - } - }); - } - public static boolean copyFile(InputStream sourceFile, File destFile) throws IOException { OutputStream out = new FileOutputStream(destFile); byte[] buf = new byte[4096]; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 16284f91..5d913818 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -834,35 +834,37 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not chatListView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { - if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { - if (openSecretPhotoRunnable != null) { - AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); - openSecretPhotoRunnable = null; - } else { - if (SecretPhotoViewer.getInstance().isVisible()) { - AndroidUtilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - chatListView.setOnItemLongClickListener(onItemLongClickListener); - chatListView.setOnItemClickListener(onItemClickListener); - chatListView.setLongClickable(true); - } - }); - SecretPhotoViewer.getInstance().closePhoto(); + if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) { + if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { + if (openSecretPhotoRunnable != null) { + AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); + openSecretPhotoRunnable = null; + } else { + if (SecretPhotoViewer.getInstance().isVisible()) { + AndroidUtilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + chatListView.setOnItemLongClickListener(onItemLongClickListener); + chatListView.setOnItemClickListener(onItemClickListener); + chatListView.setLongClickable(true); + } + }); + SecretPhotoViewer.getInstance().closePhoto(); + } } - } - } else if (event.getAction() != MotionEvent.ACTION_DOWN) { - if (SecretPhotoViewer.getInstance().isVisible()) { - return true; - } else if (openSecretPhotoRunnable != null) { - if (event.getAction() == MotionEvent.ACTION_MOVE) { - if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities.dp(5)) { + } else if (event.getAction() != MotionEvent.ACTION_DOWN) { + if (SecretPhotoViewer.getInstance().isVisible()) { + return true; + } else if (openSecretPhotoRunnable != null) { + if (event.getAction() == MotionEvent.ACTION_MOVE) { + if (Math.hypot(startX - event.getX(), startY - event.getY()) > AndroidUtilities.dp(5)) { + AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); + openSecretPhotoRunnable = null; + } + } else { AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); openSecretPhotoRunnable = null; } - } else { - AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); - openSecretPhotoRunnable = null; } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java index 5118653f..0eb4b6c5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MediaActivity.java @@ -94,7 +94,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No @Override public void onItemClick(int id) { if (id == -1) { - if (Build.VERSION.SDK_INT < 11) { + if (Build.VERSION.SDK_INT < 11 && listView != null) { listView.setAdapter(null); listView = null; listAdapter = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java index f9ce3165..351d86b3 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoPickerActivity.java @@ -341,7 +341,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen @Override public void sendButtonPressed(int index) { if (selectedPhotos.isEmpty()) { - if (index < 0 || index >= selectedAlbum.photos.size()) { + if (selectedAlbum == null || index < 0 || index >= selectedAlbum.photos.size()) { return; } MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java index 0528a8cc..1dfef5f5 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarLayer.java @@ -171,9 +171,9 @@ public class ActionBarLayer extends FrameLayout { x = AndroidUtilities.dp(16 + leftMargin); } else { if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - x = AndroidUtilities.dp(22 + leftMargin) + (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f); + x = AndroidUtilities.dp(22 + leftMargin) + (logoImageView.getDrawable() != null ? (int)(logoImageView.getDrawable().getIntrinsicWidth() / 1.3f) : 0); } else { - x = AndroidUtilities.dp(22 + leftMargin) + logoImageView.getDrawable().getIntrinsicWidth(); + x = AndroidUtilities.dp(22 + leftMargin) + (logoImageView.getDrawable() != null ? logoImageView.getDrawable().getIntrinsicWidth() : 0); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java index c18ca4f9..51e4b430 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/BaseFragment.java @@ -54,7 +54,11 @@ public class BaseFragment { if (fragmentView != null) { ViewGroup parent = (ViewGroup) fragmentView.getParent(); if (parent != null) { - parent.removeView(fragmentView); + try { + parent.removeView(fragmentView); + } catch (Exception e) { + FileLog.e("tmessages", e); + } } fragmentView = null; } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/LayoutListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/LayoutListView.java index a475bc3c..4d5617a8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/LayoutListView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/LayoutListView.java @@ -42,7 +42,7 @@ public class LayoutListView extends ListView { @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (onInterceptTouchEventListener != null) { - return onInterceptTouchEventListener.onInterceptTouchEvent(ev); + return onInterceptTouchEventListener.onInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev); } return super.onInterceptTouchEvent(ev); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/VideoTimelineView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/VideoTimelineView.java index 92e2ef3a..451a7e14 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/VideoTimelineView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/VideoTimelineView.java @@ -153,9 +153,13 @@ public class VideoTimelineView extends View { public void setVideoPath(String path) { mediaMetadataRetriever = new MediaMetadataRetriever(); - mediaMetadataRetriever.setDataSource(path); - String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); - videoLength = Long.parseLong(duration); + try { + mediaMetadataRetriever.setDataSource(path); + String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); + videoLength = Long.parseLong(duration); + } catch (Exception e) { + FileLog.e("tmessages", e); + } } public void setDelegate(VideoTimelineViewDelegate delegate) {