Possible crash fixes, fixed gif selection from new photo picker, added button to select documents from external apps

This commit is contained in:
DrKLO 2014-06-14 12:36:01 +04:00
parent 19ba20cdab
commit 02a20acc4c
34 changed files with 341 additions and 104 deletions

View file

@ -81,7 +81,7 @@ android {
defaultConfig {
minSdkVersion 8
targetSdkVersion 19
versionCode 253
versionName "1.5.2"
versionCode 254
versionName "1.5.3"
}
}

View file

@ -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);

View file

@ -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;

View file

@ -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);

View file

@ -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

View file

@ -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));

View file

@ -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)));

View file

@ -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)

View file

@ -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;

View file

@ -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;

View file

@ -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) {

View file

@ -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);
}
}
}

View file

@ -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();

View file

@ -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);
}
}
}

View file

@ -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;

View file

@ -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) {

View file

@ -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));

View file

@ -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;

View file

@ -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));

View file

@ -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)};

View file

@ -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;

View file

@ -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);
}
}
}
}
}

View file

@ -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;
}
}

View file

@ -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());
}
}

View file

@ -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);
}
}
}

View file

@ -4,12 +4,6 @@
android:layout_height="match_parent"
android:id="@+id/chat_layout">
<ImageView
android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:id="@+id/background_image"
android:scaleType="centerCrop"/>
<org.telegram.ui.Views.FrameLayoutFixed
android:layout_height="fill_parent"
android:layout_width="fill_parent"

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">قم بالسحب للإلغاء</string>
<string name="SaveToDownloads">حفظ في الجهاز</string>
<string name="ApplyLocalizationFile">تطبيق ملف التعريب</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">تم طلب محادثة سرية</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">WISCHEN UM ABZUBRECHEN</string>
<string name="SaveToDownloads">Im Ordner Downloads speichern</string>
<string name="ApplyLocalizationFile">Standort-Datei benutzen</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Geheimen Chat angefordert</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">DESLIZA PARA CANCELAR</string>
<string name="SaveToDownloads">Guardar en descargas</string>
<string name="ApplyLocalizationFile">Aplicar archivo de traducción</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Chat secreto solicitado</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">TRASCINA PER ANNULLARE</string>
<string name="SaveToDownloads">Salva in download</string>
<string name="ApplyLocalizationFile">Applica file di localizzazione</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Chat segreta richiesta</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">SLEEP OM TE ANNULEREN</string>
<string name="SaveToDownloads">Opslaan in Downloads</string>
<string name="ApplyLocalizationFile">Vertaling toepassen</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Privégesprek aangevraagd</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">DESLIZE PARA CANCELAR</string>
<string name="SaveToDownloads">Salvar em downloads</string>
<string name="ApplyLocalizationFile">Aplicar arquivo de localização</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Conversa secreta solicitada</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">DESLIZAR PARA CANCELAR</string>
<string name="SaveToDownloads">Guardar nas transferências</string>
<string name="ApplyLocalizationFile">Aplicar o ficheiro de localização</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Chat secreto pedido</string>

View file

@ -113,6 +113,7 @@
<string name="SlideToCancel">SLIDE TO CANCEL</string>
<string name="SaveToDownloads">Save to downloads</string>
<string name="ApplyLocalizationFile">Apply localization file</string>
<string name="UnsupportedAttachment">Unsupported attachment</string>
<!--notification-->
<string name="EncryptedChatRequested">Secret chat requested</string>