From f83a1b56ff1743f783ab05ad87c7f79c65ae6cb4 Mon Sep 17 00:00:00 2001 From: DrKLO Date: Sun, 28 Sep 2014 19:07:16 +0400 Subject: [PATCH] Bug fixes https://github.com/DrKLO/Telegram/pull/581 --- TMessagesProj/build.gradle | 2 +- .../java/org/telegram/ui/ChatActivity.java | 2 +- .../org/telegram/ui/ChatProfileActivity.java | 2 +- .../java/org/telegram/ui/LaunchActivity.java | 13 +- .../org/telegram/ui/VideoEditorActivity.java | 138 +++++++++++------- .../org/telegram/ui/Views/AvatarUpdater.java | 2 +- 6 files changed, 93 insertions(+), 66 deletions(-) diff --git a/TMessagesProj/build.gradle b/TMessagesProj/build.gradle index 2abf7266..88d655bf 100644 --- a/TMessagesProj/build.gradle +++ b/TMessagesProj/build.gradle @@ -80,7 +80,7 @@ android { defaultConfig { minSdkVersion 8 targetSdkVersion 19 - versionCode 331 + versionCode 332 versionName "1.9.0" } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java index 89fe5f20..a250b4c1 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatActivity.java @@ -1364,7 +1364,7 @@ public class ChatActivity extends BaseFragment implements NotificationCenter.Not args.putString("videoPath", videoPath); VideoEditorActivity fragment = new VideoEditorActivity(args); fragment.setDelegate(this); - presentFragment(fragment); + presentFragment(fragment, false, true); } else { processSendingVideo(videoPath, 0, 0, 0, 0, null); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java index 2b4834da..1545a3e7 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/ChatProfileActivity.java @@ -629,7 +629,7 @@ public class ChatProfileActivity extends BaseFragment implements NotificationCen count = info.participants.size(); } - if (count != 0 && onlineCount > 0) { + if (count != 0 && onlineCount > 1) { onlineText.setText(Html.fromHtml(String.format("%s, %d %s", LocaleController.formatPluralString("Members", count), onlineCount, LocaleController.getString("Online", R.string.Online)))); } else { onlineText.setText(LocaleController.formatPluralString("Members", count)); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java index 635197d3..fee454ec 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/LaunchActivity.java @@ -760,15 +760,16 @@ public class LaunchActivity extends Activity implements ActionBarLayout.ActionBa public void fixLayout() { if (AndroidUtilities.isTablet()) { - final ViewTreeObserver obs = actionBarLayout.getViewTreeObserver(); - obs.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + actionBarLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { needLayout(); - if (Build.VERSION.SDK_INT < 16) { - obs.removeGlobalOnLayoutListener(this); - } else { - obs.removeOnGlobalLayoutListener(this); + if (actionBarLayout != null) { + if (Build.VERSION.SDK_INT < 16) { + actionBarLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } else { + actionBarLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } } } }); diff --git a/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java index cec19bab..9ba8b869 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/VideoEditorActivity.java @@ -12,6 +12,7 @@ import android.annotation.TargetApi; import android.content.res.Configuration; import android.graphics.SurfaceTexture; import android.media.MediaPlayer; +import android.os.Build; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; @@ -76,6 +77,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur private final Object sync = new Object(); private Thread thread = null; + private long createTime = 0; private int rotationValue = 0; private int originalWidth = 0; @@ -106,7 +108,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur AndroidUtilities.RunOnUIThread(new Runnable() { @Override public void run() { - if (videoPlayer.isPlaying()) { + if (videoPlayer != null && videoPlayer.isPlaying()) { float startTime = videoTimelineView.getLeftProgress() * videoDuration; float endTime = videoTimelineView.getRightProgress() * videoDuration; if (startTime == endTime) { @@ -186,6 +188,15 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur if (videoTimelineView != null) { videoTimelineView.destroy(); } + if (videoPlayer != null) { + try { + videoPlayer.stop(); + videoPlayer.release(); + videoPlayer = null; + } catch (Exception e) { + FileLog.e("tmessages", e); + } + } super.onFragmentDestroy(); } @@ -323,13 +334,15 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur parent.removeView(fragmentView); } } + fixLayoutInternal(); + createTime = System.currentTimeMillis(); return fragmentView; } @Override public void onResume() { super.onResume(); - fixLayout(); + fixLayoutInternal(); } @Override @@ -479,64 +492,77 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur textureView.setLayoutParams(layoutParams); } + private void fixLayoutInternal() { + if (!AndroidUtilities.isTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams(); + layoutParams.topMargin = AndroidUtilities.dp(16); + layoutParams.bottomMargin = AndroidUtilities.dp(16); + layoutParams.width = AndroidUtilities.displaySize.x / 3 - AndroidUtilities.dp(24); + layoutParams.leftMargin = AndroidUtilities.dp(16); + videoContainerView.setLayoutParams(layoutParams); + + layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams(); + layoutParams.topMargin = AndroidUtilities.dp(16); + layoutParams.bottomMargin = 0; + layoutParams.width = AndroidUtilities.displaySize.x / 3 * 2 - AndroidUtilities.dp(32); + layoutParams.leftMargin = AndroidUtilities.displaySize.x / 3 + AndroidUtilities.dp(16); + layoutParams.gravity = Gravity.TOP; + controlView.setLayoutParams(layoutParams); + + layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams(); + layoutParams.width = AndroidUtilities.displaySize.x / 3 * 2 - AndroidUtilities.dp(32); + layoutParams.leftMargin = AndroidUtilities.displaySize.x / 3 + AndroidUtilities.dp(16); + layoutParams.rightMargin = AndroidUtilities.dp(16); + layoutParams.bottomMargin = AndroidUtilities.dp(16); + textContainerView.setLayoutParams(layoutParams); + } else { + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams(); + layoutParams.topMargin = AndroidUtilities.dp(16); + layoutParams.bottomMargin = AndroidUtilities.dp(260); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.leftMargin = 0; + videoContainerView.setLayoutParams(layoutParams); + + layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams(); + layoutParams.topMargin = 0; + layoutParams.leftMargin = 0; + layoutParams.bottomMargin = AndroidUtilities.dp(150); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.gravity = Gravity.BOTTOM; + controlView.setLayoutParams(layoutParams); + + layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams(); + layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; + layoutParams.leftMargin = AndroidUtilities.dp(16); + layoutParams.rightMargin = AndroidUtilities.dp(16); + layoutParams.bottomMargin = AndroidUtilities.dp(16); + textContainerView.setLayoutParams(layoutParams); + } + fixVideoSize(); + videoTimelineView.clearFrames(); + } + private void fixLayout() { if (originalSizeTextView == null) { return; } - originalSizeTextView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { - @Override - public boolean onPreDraw() { - originalSizeTextView.getViewTreeObserver().removeOnPreDrawListener(this); - if (!AndroidUtilities.isTablet() && getParentActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { - FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams(); - layoutParams.topMargin = AndroidUtilities.dp(16); - layoutParams.bottomMargin = AndroidUtilities.dp(16); - layoutParams.width = AndroidUtilities.displaySize.x / 3 - AndroidUtilities.dp(24); - layoutParams.leftMargin = AndroidUtilities.dp(16); - videoContainerView.setLayoutParams(layoutParams); - - layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams(); - layoutParams.topMargin = AndroidUtilities.dp(16); - layoutParams.bottomMargin = 0; - layoutParams.width = AndroidUtilities.displaySize.x / 3 * 2 - AndroidUtilities.dp(32); - layoutParams.leftMargin = AndroidUtilities.displaySize.x / 3 + AndroidUtilities.dp(16); - layoutParams.gravity = Gravity.TOP; - controlView.setLayoutParams(layoutParams); - - layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams(); - layoutParams.width = AndroidUtilities.displaySize.x / 3 * 2 - AndroidUtilities.dp(32); - layoutParams.leftMargin = AndroidUtilities.displaySize.x / 3 + AndroidUtilities.dp(16); - layoutParams.rightMargin = AndroidUtilities.dp(16); - layoutParams.bottomMargin = AndroidUtilities.dp(16); - textContainerView.setLayoutParams(layoutParams); - } else { - FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoContainerView.getLayoutParams(); - layoutParams.topMargin = AndroidUtilities.dp(16); - layoutParams.bottomMargin = AndroidUtilities.dp(260); - layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; - layoutParams.leftMargin = 0; - videoContainerView.setLayoutParams(layoutParams); - - layoutParams = (FrameLayout.LayoutParams) controlView.getLayoutParams(); - layoutParams.topMargin = 0; - layoutParams.leftMargin = 0; - layoutParams.bottomMargin = AndroidUtilities.dp(150); - layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; - layoutParams.gravity = Gravity.BOTTOM; - controlView.setLayoutParams(layoutParams); - - layoutParams = (FrameLayout.LayoutParams) textContainerView.getLayoutParams(); - layoutParams.width = FrameLayout.LayoutParams.MATCH_PARENT; - layoutParams.leftMargin = AndroidUtilities.dp(16); - layoutParams.rightMargin = AndroidUtilities.dp(16); - layoutParams.bottomMargin = AndroidUtilities.dp(16); - textContainerView.setLayoutParams(layoutParams); + if (createTime < System.currentTimeMillis() - 3000) { + originalSizeTextView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { + @Override + public void onGlobalLayout() { + if (originalSizeTextView != null) { + if (Build.VERSION.SDK_INT < 16) { + originalSizeTextView.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } else { + originalSizeTextView.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } + } + fixLayoutInternal(); } - fixVideoSize(); - videoTimelineView.clearFrames(); - return false; - } - }); + }); + } else { + fixLayoutInternal(); + } } private void play() { @@ -571,7 +597,7 @@ public class VideoEditorActivity extends BaseFragment implements TextureView.Sur }); videoPlayer.start(); synchronized (sync) { - if (thread != null) { + if (thread == null) { thread = new Thread(progressRunnable); thread.start(); } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java index 276275e4..fafff6ec 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Views/AvatarUpdater.java @@ -69,7 +69,7 @@ public class AvatarUpdater implements NotificationCenter.NotificationCenterDeleg public void openGallery() { try { - Intent photoPickerIntent = new Intent(Intent.ACTION_PICK); + Intent photoPickerIntent = new Intent(Intent.ACTION_GET_CONTENT); photoPickerIntent.setType("image/*"); parentFragment.getParentActivity().startActivityForResult(photoPickerIntent, 14); } catch (Exception e) {