From 02a20acc4c7746f1de3628a74d095c4cf83b63a3 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sat, 14 Jun 2014 12:36:01 +0400 Subject: [PATCH] Possible crash fixes, fixed gif selection from new photo picker, added button to select documents from external apps --- TMessagesProj/build.gradle | 4 +- .../telegram/messenger/MediaController.java | 4 +- .../org/telegram/ui/ApplicationLoader.java | 3 +- .../org/telegram/ui/Cells/ChatBaseCell.java | 2 +- .../java/org/telegram/ui/ChatActivity.java | 156 ++++++++++++++---- .../org/telegram/ui/ChatProfileActivity.java | 13 ++ .../org/telegram/ui/ContactsActivity.java | 7 +- .../telegram/ui/DocumentSelectActivity.java | 15 +- .../telegram/ui/GroupCreateFinalActivity.java | 4 +- .../telegram/ui/LanguageSelectActivity.java | 2 +- .../java/org/telegram/ui/LaunchActivity.java | 4 +- .../org/telegram/ui/LocationActivity.java | 6 +- .../java/org/telegram/ui/LoginActivity.java | 15 ++ .../org/telegram/ui/LoginActivitySmsView.java | 35 ++-- .../org/telegram/ui/MessagesActivity.java | 5 +- .../java/org/telegram/ui/PhotoViewer.java | 12 +- .../org/telegram/ui/SettingsActivity.java | 51 +++++- .../org/telegram/ui/SettingsBlockedUsers.java | 2 +- .../ui/SettingsNotificationsActivity.java | 5 +- .../ui/SettingsWallpapersActivity.java | 3 + .../org/telegram/ui/UserProfileActivity.java | 13 +- .../ui/Views/ActionBar/ActionBarActivity.java | 16 +- .../ui/Views/ActionBar/BaseFragment.java | 5 +- .../ui/Views/PinnedHeaderListView.java | 22 ++- .../ui/Views/SizeNotifierRelativeLayout.java | 27 ++- .../src/main/res/layout/chat_layout.xml | 6 - .../src/main/res/values-ar/strings.xml | 1 + .../src/main/res/values-de/strings.xml | 1 + .../src/main/res/values-es/strings.xml | 1 + .../src/main/res/values-it/strings.xml | 1 + .../src/main/res/values-nl/strings.xml | 1 + .../src/main/res/values-pt-rBR/strings.xml | 1 + .../src/main/res/values-pt-rPT/strings.xml | 1 + TMessagesProj/src/main/res/values/strings.xml | 1 + 34 files changed, 341 insertions(+), 104 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index c156309c2..9e95adf0a 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -81,7 +81,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 253 - versionName "1.5.2" + versionCode 254 + versionName "1.5.3" } } diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index 7043c243e..b3f900a2e 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -1536,7 +1536,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel return false; } - public static String copyDocumentToCache(Uri uri) { + public static String copyDocumentToCache(Uri uri, String ext) { ParcelFileDescriptor parcelFD = null; FileInputStream input = null; FileOutputStream output = null; @@ -1545,7 +1545,7 @@ public class MediaController implements NotificationCenter.NotificationCenterDel UserConfig.lastLocalId--; parcelFD = ApplicationLoader.applicationContext.getContentResolver().openFileDescriptor(uri, "r"); input = new FileInputStream(parcelFD.getFileDescriptor()); - File f = new File(Utilities.getCacheDir(), String.format(Locale.US, "%d.gif", id)); + File f = new File(Utilities.getCacheDir(), String.format(Locale.US, "%d.%s", id, ext)); output = new FileOutputStream(f); input.getChannel().transferTo(0, input.getChannel().size(), output.getChannel()); UserConfig.saveConfig(false); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java index 27c313485..ac8a49cd8 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ApplicationLoader.java @@ -21,6 +21,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.res.Configuration; import android.graphics.Bitmap; +import android.graphics.drawable.Drawable; import android.os.AsyncTask; import android.os.Handler; import android.os.PowerManager; @@ -53,7 +54,7 @@ public class ApplicationLoader extends Application { private static final String PROPERTY_APP_VERSION = "appVersion"; private static final int PLAY_SERVICES_RESOLUTION_REQUEST = 9000; public static long lastPauseTime; - public static Bitmap cachedWallpaper = null; + public static Drawable cachedWallpaper = null; public static volatile Context applicationContext = null; public static volatile Handler applicationHandler = null; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java index 1cfbccf23..552b411fc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Cells/ChatBaseCell.java @@ -233,7 +233,7 @@ public class ChatBaseCell extends BaseCell { newUser = MessagesController.getInstance().users.get(currentMessageObject.messageOwner.fwd_from_id); newNameString = null; - if (drawForwardedName && currentMessageObject.messageOwner instanceof TLRPC.TL_messageForwarded) { + if (newUser != null && drawForwardedName && currentMessageObject.messageOwner instanceof TLRPC.TL_messageForwarded) { newNameString = Utilities.formatName(newUser.first_name, newUser.last_name); } return currentForwardNameString == null && newNameString != null || currentForwardNameString != null && newNameString == null || currentForwardNameString != null && newNameString != null && !currentForwardNameString.equals(newNameString); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 85e5f4ac3..e4957a2bf 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -21,7 +21,7 @@ import android.content.res.Configuration; import android.graphics.Bitmap; import android.graphics.Rect; import android.graphics.drawable.AnimationDrawable; -import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.media.MediaPlayer; import android.media.ThumbnailUtils; import android.net.Uri; @@ -60,6 +60,7 @@ import android.widget.PopupWindow; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; +import android.widget.Toast; import org.telegram.PhoneFormat.PhoneFormat; import org.telegram.messenger.LocaleController; @@ -643,33 +644,41 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa updateContactStatus(); - ImageView backgroundImage = (ImageView) fragmentView.findViewById(R.id.background_image); - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); int selectedBackground = preferences.getInt("selectedBackground", 1000001); int selectedColor = preferences.getInt("selectedColor", 0); if (selectedColor != 0) { - backgroundImage.setBackgroundColor(selectedColor); + contentView.setBackgroundColor(selectedColor); chatListView.setCacheColorHint(selectedColor); } else { chatListView.setCacheColorHint(0); - if (selectedBackground == 1000001) { - backgroundImage.setImageResource(R.drawable.background_hd); - } else { - File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); - if (toFile.exists()) { - if (ApplicationLoader.cachedWallpaper != null) { - backgroundImage.setImageBitmap(ApplicationLoader.cachedWallpaper); - } else { - backgroundImage.setImageURI(Uri.fromFile(toFile)); - if (backgroundImage.getDrawable() instanceof BitmapDrawable) { - ApplicationLoader.cachedWallpaper = ((BitmapDrawable)backgroundImage.getDrawable()).getBitmap(); - } - } - isCustomTheme = true; + try { + if (selectedBackground == 1000001) { + ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); } else { - backgroundImage.setImageResource(R.drawable.background_hd); + File toFile = new File(ApplicationLoader.applicationContext.getFilesDir(), "wallpaper.jpg"); + if (toFile.exists()) { + if (ApplicationLoader.cachedWallpaper != null) { + ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(ApplicationLoader.cachedWallpaper); + } else { + Drawable drawable = Drawable.createFromPath(toFile.getAbsolutePath()); + if (drawable != null) { + ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(drawable); + ApplicationLoader.cachedWallpaper = drawable; + } else { + contentView.setBackgroundColor(-2693905); + chatListView.setCacheColorHint(-2693905); + } + } + isCustomTheme = true; + } else { + ((SizeNotifierRelativeLayout) contentView).setBackgroundImage(R.drawable.background_hd); + } } + } catch (Exception e) { + contentView.setBackgroundColor(-2693905); + chatListView.setCacheColorHint(-2693905); + FileLog.e("tmessages", e); } } @@ -979,6 +988,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa bottomOverlayChat.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); @@ -1252,6 +1264,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa timerButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); builder.setItems(new CharSequence[]{ @@ -1625,6 +1640,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa currentPicturePath = null; } else if (requestCode == 1) { if (data == null || data.getData() == null) { + showAttachmentError(); return; } String tempPath = Utilities.getPath(data.getData()); @@ -1635,7 +1651,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } else if (tempPath == null) { isGif = MediaController.isGif(data.getData()); if (isGif) { - tempPath = MediaController.copyDocumentToCache(data.getData()); + tempPath = MediaController.copyDocumentToCache(data.getData(), "gif"); } } @@ -1678,10 +1694,32 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa currentPicturePath = null; } processSendingVideo(videoPath); + } else if (requestCode == 21) { + if (data == null || data.getData() == null) { + showAttachmentError(); + return; + } + String tempPath = Utilities.getPath(data.getData()); + if (tempPath == null) { + tempPath = MediaController.copyDocumentToCache(data.getData(), "file"); + } + if (tempPath == null) { + showAttachmentError(); + return; + } + processSendingDocument(tempPath); } } } + private void showAttachmentError() { + if (getParentActivity() == null) { + return; + } + Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnsupportedAttachment", R.string.UnsupportedAttachment), Toast.LENGTH_SHORT); + toast.show(); + } + @Override public void saveSelfArgs(Bundle args) { if (currentPicturePath != null) { @@ -1745,19 +1783,31 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } else if (!urisCopy.isEmpty()) { uri = urisCopy.get(a); } - final TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(path, uri); - Utilities.RunOnUIThread(new Runnable() { - @Override - public void run() { - if (photo != null) { - MessagesController.getInstance().sendMessage(photo, dialog_id); - if (chatListView != null) { - chatListView.setSelection(messages.size() + 1); - } - scrollToTopOnResume = true; + + boolean isGif = false; + if (path != null && path.endsWith(".gif")) { + final String finalPath = path; + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + processSendingDocument(finalPath); } - } - }); + }); + } else { + final TLRPC.TL_photo photo = MessagesController.getInstance().generatePhotoSizes(path, uri); + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + if (photo != null) { + MessagesController.getInstance().sendMessage(photo, dialog_id); + if (chatListView != null) { + chatListView.setSelection(messages.size() + 1); + } + scrollToTopOnResume = true; + } + } + }); + } } } }).start(); @@ -2560,6 +2610,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa topPanel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); @@ -2807,6 +2860,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void fixLayout() { + final int lastPos = chatListView.getLastVisiblePosition(); ViewTreeObserver obs = chatListView.getViewTreeObserver(); obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override @@ -2830,6 +2884,14 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa params.height = height; avatarImageView.setLayoutParams(params); } + if (lastPos >= messages.size() - 1) { + chatListView.post(new Runnable() { + @Override + public void run() { + chatListView.setSelectionFromTop(messages.size() - 1, -100000 - chatListView.getPaddingTop()); + } + }); + } return false; } }); @@ -2859,7 +2921,7 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } public void createMenu(View v, boolean single) { - if (getParentActivity() == null || actionBarLayer.isActionModeShowed()) { + if (actionBarLayer.isActionModeShowed()) { return; } @@ -2884,6 +2946,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (single || type < 2) { if (type >= 0) { selectedObject = message; + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = null; @@ -3022,6 +3087,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (LocaleController.getInstance().applyLanguageFile(locFile)) { presentFragment(new LanguageSelectActivity()); } else { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization)); @@ -3174,6 +3242,17 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa MessagesController.getInstance().sendMessage(document, dialog_id); } + @Override + public void startDocumentSelectActivity() { + try { + Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); + photoPickerIntent.setType("*/*"); + getParentActivity().startActivityForResult(photoPickerIntent, 21); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } + @Override public void didSelectDialog(MessagesActivity activity, long did) { if (dialog_id != 0 && (forwaringMessage != null || !selectedMessagesIds.isEmpty())) { @@ -3253,9 +3332,12 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa public boolean isGoogleMapsInstalled() { try { - ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0 ); + ApplicationInfo info = ApplicationLoader.applicationContext.getPackageManager().getApplicationInfo("com.google.android.apps.maps", 0); return true; } catch(PackageManager.NameNotFoundException e) { + if (getParentActivity() == null) { + return false; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage("Install Google Maps?"); builder.setCancelable(true); @@ -3376,6 +3458,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa } private void alertUserOpenError(MessageObject message) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setPositiveButton(R.string.OK, null); @@ -4105,6 +4190,9 @@ public class ChatActivity extends BaseFragment implements SizeNotifierRelativeLa if (message.messageOwner.media.phone_number == null || message.messageOwner.media.phone_number.length() == 0) { return; } + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setItems(new CharSequence[] {LocaleController.getString("Copy", R.string.Copy), LocaleController.getString("Call", R.string.Call)}, new DialogInterface.OnClickListener() { @Override diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index df1abdc64..aa7fd7f88 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -172,6 +172,10 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { if (i > membersSectionRow && i < addMemberRow) { + if (getParentActivity() == null) { + return false; + } + TLRPC.TL_chatParticipant user = info.participants.get(sortedUsers.get(i - membersSectionRow - 1)); if (user.user_id == UserConfig.getClientUserId()) { return false; @@ -247,6 +251,9 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen args.putInt("user_id", user_id); presentFragment(new UserProfileActivity(args)); } else if (i == settingsVibrateRow || i == settingsNotificationsRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { @@ -604,6 +611,9 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; int type; @@ -758,6 +768,9 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java index 709cc0595..5d1e82f1f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ContactsActivity.java @@ -146,6 +146,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter searchWas = false; ViewGroup group = (ViewGroup) listView.getParent(); listView.setAdapter(listViewAdapter); + listViewAdapter.notifyDataSetChanged(); if (!LocaleController.isRTL) { listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(30), listView.getPaddingBottom()); } else { @@ -171,6 +172,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (listView != null) { listView.setPadding(Utilities.dp(16), listView.getPaddingTop(), Utilities.dp(16), listView.getPaddingBottom()); listView.setAdapter(searchListViewAdapter); + searchListViewAdapter.notifyDataSetChanged(); if(android.os.Build.VERSION.SDK_INT >= 11) { listView.setFastScrollAlwaysVisible(false); } @@ -288,7 +290,7 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter if (!contact.phones.isEmpty()) { usePhone = contact.phones.get(0); } - if (usePhone == null) { + if (usePhone == null || getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); @@ -337,6 +339,9 @@ public class ContactsActivity extends BaseFragment implements NotificationCenter private void didSelectResult(final TLRPC.User user, boolean useAlert) { if (useAlert && selectAlertString != null) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setMessage(LocaleController.formatStringSimple(selectAlertString, Utilities.formatName(user.first_name, user.last_name))); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java index b59867c12..5aee769cb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DocumentSelectActivity.java @@ -29,6 +29,8 @@ import org.telegram.messenger.LocaleController; import org.telegram.messenger.R; import org.telegram.messenger.Utilities; import org.telegram.ui.Views.ActionBar.ActionBarLayer; +import org.telegram.ui.Views.ActionBar.ActionBarMenu; +import org.telegram.ui.Views.ActionBar.ActionBarMenuItem; import org.telegram.ui.Views.BackupImageView; import org.telegram.ui.Views.ActionBar.BaseFragment; @@ -44,6 +46,7 @@ public class DocumentSelectActivity extends BaseFragment { public static abstract interface DocumentSelectActivityDelegate { public void didSelectFile(DocumentSelectActivity activity, String path, String name, String ext, long size); + public void startDocumentSelectActivity(); } private ListView listView; @@ -134,9 +137,16 @@ public class DocumentSelectActivity extends BaseFragment { public void onItemClick(int id) { if (id == -1) { finishFragment(); + } else if (id == 1) { + if (delegate != null) { + delegate.startDocumentSelectActivity(); + } + finishFragment(false); } } }); + ActionBarMenu menu = actionBarLayer.createMenu(); + ActionBarMenuItem item = menu.addItem(1, R.drawable.ic_ab_other); fragmentView = inflater.inflate(R.layout.document_select_layout, container, false); listAdapter = new ListAdapter(getParentActivity()); @@ -290,7 +300,10 @@ public class DocumentSelectActivity extends BaseFragment { return true; } - private void showErrorBox(String error){ + private void showErrorBox(String error) { + if (getParentActivity() == null) { + return; + } new AlertDialog.Builder(getParentActivity()) .setTitle(LocaleController.getString("AppName", R.string.AppName)) .setMessage(error) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java index d5386df27..b3d0d2a94 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/GroupCreateFinalActivity.java @@ -176,7 +176,9 @@ public class GroupCreateFinalActivity extends BaseFragment implements Notificati button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java index d3299e1b0..7d207af1b 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LanguageSelectActivity.java @@ -143,7 +143,7 @@ public class LanguageSelectActivity extends BaseFragment { localeInfo = LocaleController.getInstance().sortedLanguages.get(i); } } - if (localeInfo == null || localeInfo.pathToFile == null) { + if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) { return false; } final LocaleController.LocaleInfo finalLocaleInfo = localeInfo; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 056902bfd..ed4ebbc7d 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -280,7 +280,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } else if (tempPath == null) { isGif = MediaController.isGif(uri); if (isGif) { - documentPath = MediaController.copyDocumentToCache(uri); + documentPath = MediaController.copyDocumentToCache(uri, "gif"); } } if (!isGif || documentPath == null) { @@ -325,7 +325,7 @@ public class LaunchActivity extends ActionBarActivity implements NotificationCen } else if (tempPath == null) { isGif = MediaController.isGif(uri); if (isGif) { - tempPath = MediaController.copyDocumentToCache(uri); + tempPath = MediaController.copyDocumentToCache(uri, "gif"); } } if (isGif && tempPath != null) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java index ccc43d62e..aacb381f4 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LocationActivity.java @@ -314,7 +314,11 @@ public class LocationActivity extends BaseFragment implements NotificationCenter public void onPause() { super.onPause(); if (mapView != null) { - mapView.onPause(); + try { + mapView.onPause(); + } catch (Exception e) { + FileLog.e("tmessages", e); + } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java index b54a1ebef..d19df2b59 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivity.java @@ -18,6 +18,8 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.animation.AccelerateDecelerateInterpolator; +import android.widget.FrameLayout; +import android.widget.ScrollView; import android.widget.TextView; import org.telegram.messenger.FileLog; @@ -81,6 +83,19 @@ public class LoginActivity extends BaseFragment implements SlideView.SlideViewDe views[1] = (SlideView)fragmentView.findViewById(R.id.login_page2); views[2] = (SlideView)fragmentView.findViewById(R.id.login_page3); + try { + if (views[0] == null || views[1] == null || views[2] == null) { + FrameLayout parent = (FrameLayout)((ScrollView) fragmentView).getChildAt(0); + for (int a = 0; a < views.length; a++) { + if (views[a] == null) { + views[a] = (SlideView)parent.getChildAt(a); + } + } + } + } catch (Exception e) { + FileLog.e("tmessages", e); + } + actionBarLayer.setTitle(views[0].getHeaderName()); Bundle savedInstanceState = loadCurrentState(); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java index b16eeeafb..44bc066af 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LoginActivitySmsView.java @@ -212,15 +212,12 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente Utilities.RunOnUIThread(new Runnable() { @Override public void run() { - nextPressed = false; - if (delegate != null) { - delegate.needHideProgress(); + if (delegate == null) { + return; } + nextPressed = false; if (error == null) { TLRPC.TL_auth_authorization res = (TLRPC.TL_auth_authorization)response; - if (delegate == null) { - return; - } try { synchronized(timerSync) { if (timeTimer != null) { @@ -242,9 +239,7 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente MessagesStorage.getInstance().putUsersAndChats(users, null, true, true); MessagesController.getInstance().users.put(res.user.id, res.user); ContactsController.getInstance().checkAppAccount(); - if (delegate != null) { - delegate.needFinishActivity(); - } + delegate.needFinishActivity(); ConnectionsManager.getInstance().initPushConnection(); } else { if (error.text.contains("PHONE_NUMBER_UNOCCUPIED") && registered == null) { @@ -302,18 +297,16 @@ public class LoginActivitySmsView extends SlideView implements NotificationCente } }, 0, 1000); } - if (delegate != null) { - if (error.text.contains("PHONE_NUMBER_INVALID")) { - delegate.needShowAlert(LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber)); - } else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) { - delegate.needShowAlert(LocaleController.getString("InvalidCode", R.string.InvalidCode)); - } else if (error.text.contains("PHONE_CODE_EXPIRED")) { - delegate.needShowAlert(LocaleController.getString("CodeExpired", R.string.CodeExpired)); - } else if (error.text.startsWith("FLOOD_WAIT")) { - delegate.needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait)); - } else { - delegate.needShowAlert(error.text); - } + if (error.text.contains("PHONE_NUMBER_INVALID")) { + delegate.needShowAlert(LocaleController.getString("InvalidPhoneNumber", R.string.InvalidPhoneNumber)); + } else if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) { + delegate.needShowAlert(LocaleController.getString("InvalidCode", R.string.InvalidCode)); + } else if (error.text.contains("PHONE_CODE_EXPIRED")) { + delegate.needShowAlert(LocaleController.getString("CodeExpired", R.string.CodeExpired)); + } else if (error.text.startsWith("FLOOD_WAIT")) { + delegate.needShowAlert(LocaleController.getString("FloodWait", R.string.FloodWait)); + } else { + delegate.needShowAlert(error.text); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java index 5c1245033..3350ba3dc 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/MessagesActivity.java @@ -297,7 +297,7 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter messagesListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - if (onlySelect || searching && searchWas) { + if (onlySelect || searching && searchWas || getParentActivity() == null) { return false; } TLRPC.TL_dialog dialog; @@ -455,6 +455,9 @@ public class MessagesActivity extends BaseFragment implements NotificationCenter private void didSelectResult(final long dialog_id, boolean useAlert) { if (useAlert && selectAlertString != null) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); int lower_part = (int)dialog_id; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java index a3e03900e..44c2633d9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/PhotoViewer.java @@ -312,13 +312,18 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat imagesArrLocations.clear(); imagesArrLocationsSizes.clear(); for (TLRPC.Photo photo : photos) { - if (photo instanceof TLRPC.TL_photoEmpty) { + if (photo instanceof TLRPC.TL_photoEmpty || photo.sizes == null) { continue; } TLRPC.PhotoSize sizeFull = PhotoObject.getClosestPhotoSizeWithSize(photo.sizes, 640, 640); if (sizeFull != null) { - if (currentFileLocation != null && sizeFull.location.local_id == currentFileLocation.local_id && sizeFull.location.volume_id == currentFileLocation.volume_id) { - setToImage = imagesArrLocations.size(); + if (currentFileLocation != null) { + for (TLRPC.PhotoSize size : photo.sizes) { + if (size.location.local_id == currentFileLocation.local_id && size.location.volume_id == currentFileLocation.volume_id) { + setToImage = imagesArrLocations.size(); + break; + } + } } imagesArrLocations.add(sizeFull.location); imagesArrLocationsSizes.add(sizeFull.size); @@ -330,6 +335,7 @@ public class PhotoViewer implements NotificationCenter.NotificationCenterDelegat setImageIndex(setToImage, true); } else { imagesArrLocations.add(0, currentFileLocation); + imagesArrLocationsSizes.add(0, 0); setImageIndex(0, true); } if (fromCache) { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java index 19341e7ab..eeb6d8fdd 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsActivity.java @@ -240,6 +240,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter @Override public void onItemClick(AdapterView adapterView, View view, final int i, long l) { if (i == textSizeRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("TextSize", R.string.TextSize)); builder.setItems(new CharSequence[]{String.format("%d", 12), String.format("%d", 13), String.format("%d", 14), String.format("%d", 15), String.format("%d", 16), String.format("%d", 17), String.format("%d", 18), String.format("%d", 19), String.format("%d", 20), String.format("%d", 21), String.format("%d", 22), String.format("%d", 23), String.format("%d", 24)}, new DialogInterface.OnClickListener() { @@ -273,6 +276,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else if (i == backgroundRow) { presentFragment(new SettingsWallpapersActivity()); } else if (i == askQuestionRow) { + if (getParentActivity() == null) { + return; + } final TextView message = new TextView(getParentActivity()); message.setText(Html.fromHtml(LocaleController.getString("AskAQuestionInfo", R.string.AskAQuestionInfo))); message.setTextSize(18); @@ -303,6 +309,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter listView.invalidateViews(); } } else if (i == terminateSessionsRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); @@ -312,16 +321,27 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter TLRPC.TL_auth_resetAuthorizations req = new TLRPC.TL_auth_resetAuthorizations(); ConnectionsManager.getInstance().performRpc(req, new RPCRequest.RPCRequestDelegate() { @Override - public void run(TLObject response, TLRPC.TL_error error) { - if (error == null && response instanceof TLRPC.TL_boolTrue) { - Toast toast = Toast.makeText(getParentActivity(), R.string.TerminateAllSessions, Toast.LENGTH_SHORT); - toast.show(); - } else { - Toast toast = Toast.makeText(getParentActivity(), R.string.UnknownError, Toast.LENGTH_SHORT); - toast.show(); - } + public void run(final TLObject response, final TLRPC.TL_error error) { + Utilities.RunOnUIThread(new Runnable() { + @Override + public void run() { + if (getParentActivity() == null) { + return; + } + if (error == null && response instanceof TLRPC.TL_boolTrue) { + Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("TerminateAllSessions", R.string.TerminateAllSessions), Toast.LENGTH_SHORT); + toast.show(); + } else { + Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("UnknownError", R.string.UnknownError), Toast.LENGTH_SHORT); + toast.show(); + } + } + }); UserConfig.registeredForPush = false; + UserConfig.registeredForInternalPush = false; + UserConfig.saveConfig(false); MessagesController.getInstance().registerForPush(UserConfig.pushString); + ConnectionsManager.getInstance().initPushConnection(); } }, null, true, RPCRequest.RPCRequestClassGeneric); } @@ -331,6 +351,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else if (i == languageRow) { presentFragment(new LanguageSelectActivity()); } else if (i == switchBackendButtonRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); @@ -352,6 +375,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter } else if (i == contactsReimportRow) { } else if (i == contactsSortRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy)); builder.setItems(new CharSequence[] { @@ -373,6 +399,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showAlertDialog(builder); } else if (i == photoDownloadChatRow || i == photoDownloadPrivateRow || i == audioDownloadChatRow || i == audioDownloadPrivateRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { @@ -667,6 +696,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items; @@ -890,6 +922,9 @@ public class SettingsActivity extends BaseFragment implements NotificationCenter textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java index b0643ce6e..3b250a4bb 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsBlockedUsers.java @@ -120,7 +120,7 @@ public class SettingsBlockedUsers extends BaseFragment implements NotificationCe listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView adapterView, View view, int i, long l) { - if (i >= blockedContacts.size()) { + if (i >= blockedContacts.size() || getParentActivity() == null) { return true; } selectedUserId = blockedContacts.get(i).user_id; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java index 7c268ea67..35a1ee78f 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsNotificationsActivity.java @@ -217,7 +217,7 @@ public class SettingsNotificationsActivity extends BaseFragment { listView.invalidateViews(); } if (getParentActivity() != null) { - Toast toast = Toast.makeText(getParentActivity(), R.string.ResetNotificationsText, Toast.LENGTH_SHORT); + Toast toast = Toast.makeText(getParentActivity(), LocaleController.getString("ResetNotificationsText", R.string.ResetNotificationsText), Toast.LENGTH_SHORT); toast.show(); } } @@ -270,6 +270,9 @@ public class SettingsNotificationsActivity extends BaseFragment { listView.invalidateViews(); ApplicationLoader.startPushService(); } else { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("NotificationsServiceDisableInfo", R.string.NotificationsServiceDisableInfo)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java index 536876128..c68f428ea 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/SettingsWallpapersActivity.java @@ -158,6 +158,9 @@ public class SettingsWallpapersActivity extends BaseFragment implements Notifica @Override public void onItemClick(AdapterView adapterView, View view, int i, long l) { if (i == 0) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); CharSequence[] items = new CharSequence[] {LocaleController.getString("FromCamera", R.string.FromCamera), LocaleController.getString("FromGalley", R.string.FromGalley), LocaleController.getString("Cancel", R.string.Cancel)}; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java index 496ed2afe..15e387b73 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/UserProfileActivity.java @@ -181,7 +181,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen presentFragment(new ContactAddActivity(args)); } else if (id == delete_contact) { final TLRPC.User user = MessagesController.getInstance().users.get(user_id); - if (user == null) { + if (user == null || getParentActivity() == null) { return; } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); @@ -213,6 +213,9 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen startSecretButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setMessage(LocaleController.getString("AreYouSure", R.string.AreYouSure)); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); @@ -239,6 +242,9 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen @Override public void onItemClick(AdapterView adapterView, View view, final int i, long l) { if (i == settingsVibrateRow || i == settingsNotificationsRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("AppName", R.string.AppName)); builder.setItems(new CharSequence[] { @@ -313,6 +319,9 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen args.putInt("chat_id", (int)(dialog_id >> 32)); presentFragment(new IdenticonActivity(args)); } else if (i == settingsTimerRow) { + if (getParentActivity() == null) { + return; + } AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity()); builder.setTitle(LocaleController.getString("MessageLifetime", R.string.MessageLifetime)); builder.setItems(new CharSequence[]{ @@ -657,7 +666,7 @@ public class UserProfileActivity extends BaseFragment implements NotificationCen view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - if (user.phone == null || user.phone.length() == 0) { + if (user.phone == null || user.phone.length() == 0 || getParentActivity() == null) { return; } selectedPhone = user.phone; diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java index ff544b672..a047a6e53 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/ActionBar/ActionBarActivity.java @@ -735,9 +735,21 @@ public class ActionBarActivity extends Activity { onOpenAnimationEnd(false); } containerView.invalidate(); - ActionBarActivity.super.startActivityForResult(intent, requestCode); + if (intent != null) { + try { + ActionBarActivity.super.startActivityForResult(intent, requestCode); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } } else { - super.startActivityForResult(intent, requestCode); + if (intent != null) { + try { + super.startActivityForResult(intent, requestCode); + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } } } } 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 7ff59d965..2082c2e52 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 @@ -196,9 +196,9 @@ public class BaseFragment { } - protected boolean showAlertDialog(AlertDialog.Builder builder) { + protected void showAlertDialog(AlertDialog.Builder builder) { if (parentActivity == null || parentActivity.checkTransitionAnimation() || parentActivity.animationInProgress || parentActivity.startedTracking) { - return false; + return; } try { if (visibleDialog != null) { @@ -216,6 +216,5 @@ public class BaseFragment { visibleDialog = null; } }); - return true; } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/PinnedHeaderListView.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/PinnedHeaderListView.java index f4c272852..6d31c0b40 100755 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/PinnedHeaderListView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/PinnedHeaderListView.java @@ -17,6 +17,8 @@ import android.view.ViewGroup; import android.widget.*; import android.widget.AbsListView.OnScrollListener; +import org.telegram.messenger.FileLog; + public class PinnedHeaderListView extends ListView implements OnScrollListener, View.OnTouchListener { private OnScrollListener mOnScrollListener; @@ -69,6 +71,9 @@ public class PinnedHeaderListView extends ListView implements OnScrollListener, @Override public void setAdapter(ListAdapter adapter) { + if (mAdapter == adapter) { + return; + } mCurrentHeader = null; if (adapter instanceof PinnedSectionedHeaderAdapter) { mAdapter = (PinnedSectionedHeaderAdapter) adapter; @@ -80,14 +85,14 @@ public class PinnedHeaderListView extends ListView implements OnScrollListener, @Override public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) { - if (mAdapter == null) { - return; - } if (mOnScrollListener != null) { mOnScrollListener.onScroll(view, firstVisibleItem, visibleItemCount, totalItemCount); } + if (mAdapter == null) { + return; + } - if (mAdapter == null || mAdapter.getCount() == 0 || !mShouldPin || (firstVisibleItem < getHeaderViewsCount())) { + if (mAdapter.getCount() == 0 || !mShouldPin || (firstVisibleItem < getHeaderViewsCount())) { mCurrentHeader = null; mHeaderOffset = 0.0f; for (int i = firstVisibleItem; i < firstVisibleItem + visibleItemCount; i++) { @@ -131,9 +136,6 @@ public class PinnedHeaderListView extends ListView implements OnScrollListener, @Override public void onScrollStateChanged(AbsListView view, int scrollState) { - if (mAdapter == null) { - return; - } if (mOnScrollListener != null) { mOnScrollListener.onScrollStateChanged(view, scrollState); } @@ -173,7 +175,11 @@ public class PinnedHeaderListView extends ListView implements OnScrollListener, } else { heightSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED); } - header.measure(widthSpec, heightSpec); + try { + header.measure(widthSpec, heightSpec); + } catch (Exception e) { + FileLog.e("tmessages", e); + } header.layout(0, 0, header.getMeasuredWidth(), header.getMeasuredHeight()); } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java index a2b81dd2f..13b594bd9 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/SizeNotifierRelativeLayout.java @@ -9,8 +9,9 @@ package org.telegram.ui.Views; import android.content.Context; +import android.graphics.Canvas; import android.graphics.Rect; -import android.util.Log; +import android.graphics.drawable.Drawable; import android.widget.RelativeLayout; import org.telegram.messenger.Utilities; @@ -18,6 +19,7 @@ import org.telegram.messenger.Utilities; public class SizeNotifierRelativeLayout extends RelativeLayout { private Rect rect = new Rect(); + private Drawable backgroundDrawable; public SizeNotifierRelativeLayoutDelegate delegate; public abstract interface SizeNotifierRelativeLayoutDelegate { @@ -36,6 +38,14 @@ public class SizeNotifierRelativeLayout extends RelativeLayout { super(context, attrs, defStyle); } + public void setBackgroundImage(int resourceId) { + backgroundDrawable = getResources().getDrawable(resourceId); + } + + public void setBackgroundImage(Drawable bitmap) { + backgroundDrawable = bitmap; + } + @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { super.onLayout(changed, l, t, r, b); @@ -46,4 +56,19 @@ public class SizeNotifierRelativeLayout extends RelativeLayout { delegate.onSizeChanged(keyboardHeight); } } + + @Override + protected void onDraw(Canvas canvas) { + if (backgroundDrawable != null) { + float scaleX = (float)Utilities.displaySize.x / (float)backgroundDrawable.getIntrinsicWidth(); + float scaleY = (float)Utilities.displaySize.y / (float)backgroundDrawable.getIntrinsicHeight(); + float scale = scaleX < scaleY ? scaleY : scaleX; + int width = (int)Math.ceil(backgroundDrawable.getIntrinsicWidth() * scale); + int height = (int)Math.ceil(backgroundDrawable.getIntrinsicHeight() * scale); + int x = (Utilities.displaySize.x - width) / 2; + int y = (Utilities.displaySize.y - height) / 2; + backgroundDrawable.setBounds(x, y, x + width, y + height); + backgroundDrawable.draw(canvas); + } + } } diff --git a/TMessagesProj/src/main/res/layout/chat_layout.xml b/TMessagesProj/src/main/res/layout/chat_layout.xml index 9d7f7137d..b0b79a514 100644 --- a/TMessagesProj/src/main/res/layout/chat_layout.xml +++ b/TMessagesProj/src/main/res/layout/chat_layout.xml @@ -4,12 +4,6 @@ android:layout_height="match_parent" android:id="@+id/chat_layout"> - - قم بالسحب للإلغاء حفظ في الجهاز تطبيق ملف التعريب + Unsupported attachment تم طلب محادثة سرية diff --git a/TMessagesProj/src/main/res/values-de/strings.xml b/TMessagesProj/src/main/res/values-de/strings.xml index f3c962443..ec96fd4fe 100644 --- a/TMessagesProj/src/main/res/values-de/strings.xml +++ b/TMessagesProj/src/main/res/values-de/strings.xml @@ -113,6 +113,7 @@ WISCHEN UM ABZUBRECHEN Im Ordner Downloads speichern Standort-Datei benutzen + Unsupported attachment Geheimen Chat angefordert diff --git a/TMessagesProj/src/main/res/values-es/strings.xml b/TMessagesProj/src/main/res/values-es/strings.xml index 234cc4705..648fd6a77 100644 --- a/TMessagesProj/src/main/res/values-es/strings.xml +++ b/TMessagesProj/src/main/res/values-es/strings.xml @@ -113,6 +113,7 @@ DESLIZA PARA CANCELAR Guardar en descargas Aplicar archivo de traducción + Unsupported attachment Chat secreto solicitado diff --git a/TMessagesProj/src/main/res/values-it/strings.xml b/TMessagesProj/src/main/res/values-it/strings.xml index 2098c442c..0b3a29421 100644 --- a/TMessagesProj/src/main/res/values-it/strings.xml +++ b/TMessagesProj/src/main/res/values-it/strings.xml @@ -113,6 +113,7 @@ TRASCINA PER ANNULLARE Salva in download Applica file di localizzazione + Unsupported attachment Chat segreta richiesta diff --git a/TMessagesProj/src/main/res/values-nl/strings.xml b/TMessagesProj/src/main/res/values-nl/strings.xml index a5d3aa4ce..62e8b7962 100644 --- a/TMessagesProj/src/main/res/values-nl/strings.xml +++ b/TMessagesProj/src/main/res/values-nl/strings.xml @@ -113,6 +113,7 @@ SLEEP OM TE ANNULEREN Opslaan in Downloads Vertaling toepassen + Unsupported attachment Privégesprek aangevraagd diff --git a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml index 122fd1e7e..78e1cbb65 100644 --- a/TMessagesProj/src/main/res/values-pt-rBR/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rBR/strings.xml @@ -113,6 +113,7 @@ DESLIZE PARA CANCELAR Salvar em downloads Aplicar arquivo de localização + Unsupported attachment Conversa secreta solicitada diff --git a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml index 56fab818f..faf698f08 100644 --- a/TMessagesProj/src/main/res/values-pt-rPT/strings.xml +++ b/TMessagesProj/src/main/res/values-pt-rPT/strings.xml @@ -113,6 +113,7 @@ DESLIZAR PARA CANCELAR Guardar nas transferências Aplicar o ficheiro de localização + Unsupported attachment Chat secreto pedido diff --git a/TMessagesProj/src/main/res/values/strings.xml b/TMessagesProj/src/main/res/values/strings.xml index 925862056..d5cd5feee 100644 --- a/TMessagesProj/src/main/res/values/strings.xml +++ b/TMessagesProj/src/main/res/values/strings.xml @@ -113,6 +113,7 @@ SLIDE TO CANCEL Save to downloads Apply localization file + Unsupported attachment Secret chat requested