Stability improvements

This commit is contained in:
DrKLO 2014-10-11 15:30:32 +04:00
parent ad863779f7
commit 98a0a67c10
13 changed files with 99 additions and 79 deletions

View File

@ -19,7 +19,7 @@ tasks.withType(JavaCompile) {
dependencies { dependencies {
compile 'com.android.support:support-v4:20.0.+' compile 'com.android.support:support-v4:20.0.+'
compile 'com.google.android.gms:play-services:3.2.+' 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.+' compile 'com.googlecode.mp4parser:isoparser:1.0.+'
} }

View File

@ -9,6 +9,7 @@
package org.telegram.android; package org.telegram.android;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Context; import android.content.Context;
import android.content.pm.ActivityInfo; import android.content.pm.ActivityInfo;
import android.content.res.Configuration; import android.content.res.Configuration;
@ -32,6 +33,9 @@ import java.util.Hashtable;
import java.util.Locale; import java.util.Locale;
public class AndroidUtilities { public class AndroidUtilities {
public static ProgressDialog progressDialog;
private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>(); private static final Hashtable<String, Typeface> typefaceCache = new Hashtable<String, Typeface>();
private static int prevOrientation = -10; private static int prevOrientation = -10;
private static boolean waitingForSms = false; private static boolean waitingForSms = false;
@ -371,4 +375,32 @@ public class AndroidUtilities {
} }
return photoSize; 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();
}
}
});
}
} }

View File

@ -183,7 +183,8 @@ public class MessagesStorage {
@Override @Override
public void run() { public void run() {
try { 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 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(); 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 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.executeFast("CREATE INDEX IF NOT EXISTS date_idx_enc_tasks_v2 ON enc_tasks_v2(date);").stepThis().dispose();
database.beginTransaction(); database.beginTransaction();
@ -284,6 +287,12 @@ public class MessagesStorage {
database.executeFast("ALTER TABLE messages ADD COLUMN media INTEGER default 0").stepThis().dispose(); database.executeFast("ALTER TABLE messages ADD COLUMN media INTEGER default 0").stepThis().dispose();
database.executeFast("PRAGMA user_version = 6").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) { } catch (Exception e) {
FileLog.e("tmessages", e); FileLog.e("tmessages", e);

View File

@ -326,23 +326,23 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
} }
public void sendMessage(TLRPC.User user, long peer) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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) { 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; TLRPC.Message newMsg = null;
int type = -1; int type = -1;
int lower_id = (int) peer; int lower_id = (int) peer;
@ -420,7 +420,7 @@ public class SendMessagesHelper implements NotificationCenter.NotificationCenter
newMsg.media = new TLRPC.TL_messageMediaEmpty(); newMsg.media = new TLRPC.TL_messageMediaEmpty();
type = 0; type = 0;
newMsg.message = message; newMsg.message = message;
} else if (lat != 0 && lon != 0) { } else if (lat != null && lon != null) {
if (lower_id != 0) { if (lower_id != 0) {
newMsg = new TLRPC.TL_message(); newMsg = new TLRPC.TL_message();
} else { } else {

View File

@ -45,7 +45,7 @@ public class VideoEncodingService extends Service implements NotificationCenter.
public void didReceivedNotification(int id, Object... args) { public void didReceivedNotification(int id, Object... args) {
if (id == NotificationCenter.FileUploadProgressChanged) { if (id == NotificationCenter.FileUploadProgressChanged) {
String fileName = (String)args[0]; String fileName = (String)args[0];
if (path.equals(fileName)) { if (path != null && path.equals(fileName)) {
Float progress = (Float) args[1]; Float progress = (Float) args[1];
Boolean enc = (Boolean) args[2]; Boolean enc = (Boolean) args[2];
currentProgress = (int)(progress * 100); currentProgress = (int)(progress * 100);

View File

@ -9,7 +9,6 @@
package org.telegram.messenger; package org.telegram.messenger;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog;
import android.content.ContentUris; import android.content.ContentUris;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -73,8 +72,6 @@ public class Utilities {
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray(); final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static ProgressDialog progressDialog;
static { static {
try { try {
File URANDOM_FILE = new File("/dev/urandom"); File URANDOM_FILE = new File("/dev/urandom");
@ -426,34 +423,6 @@ public class Utilities {
return packedData; 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 { public static boolean copyFile(InputStream sourceFile, File destFile) throws IOException {
OutputStream out = new FileOutputStream(destFile); OutputStream out = new FileOutputStream(destFile);
byte[] buf = new byte[4096]; byte[] buf = new byte[4096];

View File

@ -834,6 +834,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
chatListView.setOnTouchListener(new View.OnTouchListener() { chatListView.setOnTouchListener(new View.OnTouchListener() {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
if (openSecretPhotoRunnable != null || SecretPhotoViewer.getInstance().isVisible()) {
if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) { if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_POINTER_UP) {
if (openSecretPhotoRunnable != null) { if (openSecretPhotoRunnable != null) {
AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable); AndroidUtilities.CancelRunOnUIThread(openSecretPhotoRunnable);
@ -866,6 +867,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not
} }
} }
} }
}
return false; return false;
} }
}); });

View File

@ -94,7 +94,7 @@ public class MediaActivity extends BaseFragment implements NotificationCenter.No
@Override @Override
public void onItemClick(int id) { public void onItemClick(int id) {
if (id == -1) { if (id == -1) {
if (Build.VERSION.SDK_INT < 11) { if (Build.VERSION.SDK_INT < 11 && listView != null) {
listView.setAdapter(null); listView.setAdapter(null);
listView = null; listView = null;
listAdapter = null; listAdapter = null;

View File

@ -341,7 +341,7 @@ public class PhotoPickerActivity extends BaseFragment implements NotificationCen
@Override @Override
public void sendButtonPressed(int index) { public void sendButtonPressed(int index) {
if (selectedPhotos.isEmpty()) { if (selectedPhotos.isEmpty()) {
if (index < 0 || index >= selectedAlbum.photos.size()) { if (selectedAlbum == null || index < 0 || index >= selectedAlbum.photos.size()) {
return; return;
} }
MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index); MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);

View File

@ -171,9 +171,9 @@ public class ActionBarLayer extends FrameLayout {
x = AndroidUtilities.dp(16 + leftMargin); x = AndroidUtilities.dp(16 + leftMargin);
} else { } else {
if (!AndroidUtilities.isTablet() && getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { 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 { } else {
x = AndroidUtilities.dp(22 + leftMargin) + logoImageView.getDrawable().getIntrinsicWidth(); x = AndroidUtilities.dp(22 + leftMargin) + (logoImageView.getDrawable() != null ? logoImageView.getDrawable().getIntrinsicWidth() : 0);
} }
} }

View File

@ -54,7 +54,11 @@ public class BaseFragment {
if (fragmentView != null) { if (fragmentView != null) {
ViewGroup parent = (ViewGroup) fragmentView.getParent(); ViewGroup parent = (ViewGroup) fragmentView.getParent();
if (parent != null) { if (parent != null) {
try {
parent.removeView(fragmentView); parent.removeView(fragmentView);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} }
fragmentView = null; fragmentView = null;
} }

View File

@ -42,7 +42,7 @@ public class LayoutListView extends ListView {
@Override @Override
public boolean onInterceptTouchEvent(MotionEvent ev) { public boolean onInterceptTouchEvent(MotionEvent ev) {
if (onInterceptTouchEventListener != null) { if (onInterceptTouchEventListener != null) {
return onInterceptTouchEventListener.onInterceptTouchEvent(ev); return onInterceptTouchEventListener.onInterceptTouchEvent(ev) || super.onInterceptTouchEvent(ev);
} }
return super.onInterceptTouchEvent(ev); return super.onInterceptTouchEvent(ev);
} }

View File

@ -153,9 +153,13 @@ public class VideoTimelineView extends View {
public void setVideoPath(String path) { public void setVideoPath(String path) {
mediaMetadataRetriever = new MediaMetadataRetriever(); mediaMetadataRetriever = new MediaMetadataRetriever();
try {
mediaMetadataRetriever.setDataSource(path); mediaMetadataRetriever.setDataSource(path);
String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION); String duration = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
videoLength = Long.parseLong(duration); videoLength = Long.parseLong(duration);
} catch (Exception e) {
FileLog.e("tmessages", e);
}
} }
public void setDelegate(VideoTimelineViewDelegate delegate) { public void setDelegate(VideoTimelineViewDelegate delegate) {