From ea9200cc9ce72e60d9d1c283e54db9be468d4ce9 Mon Sep 17 00:00:00 2001 From: NekoInverter <42698724+NekoInverter@users.noreply.github.com> Date: Thu, 7 May 2020 13:44:06 +0800 Subject: [PATCH] Confirm before sending video/voice message --- .../ui/Components/ChatActivityEnterView.java | 38 +++++--- .../java/tw/nekomimi/nekogram/NekoConfig.java | 11 +++ .../nekogram/NekoSettingsActivity.java | 96 ++++++++++--------- .../src/main/res/values/strings_neko.xml | 1 + 4 files changed, 90 insertions(+), 56 deletions(-) diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java index 04d3a9c9a..4ede774d2 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/ChatActivityEnterView.java @@ -2393,16 +2393,22 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe if (!hasRecordVideo || calledRecordRunnable) { startedDraggingX = -1; if (hasRecordVideo && videoSendButton.getTag() != null) { - delegate.needStartRecordVideo(1, true, 0); + delegate.needStartRecordVideo(NekoConfig.confirmAVMessage ? 3 : 1, true, 0); } else { - if (recordingAudioVideo && isInScheduleMode()) { - AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (notify, scheduleDate) -> MediaController.getInstance().stopRecording(1, notify, scheduleDate), () -> MediaController.getInstance().stopRecording(0, false, 0)); + if (NekoConfig.confirmAVMessage) { + MediaController.getInstance().stopRecording(2, true, 0); + } else { + if (recordingAudioVideo && isInScheduleMode()) { + AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (notify, scheduleDate) -> MediaController.getInstance().stopRecording(1, notify, scheduleDate), () -> MediaController.getInstance().stopRecording(0, false, 0)); + } + MediaController.getInstance().stopRecording(isInScheduleMode() ? 3 : 1, true, 0); } - MediaController.getInstance().stopRecording(isInScheduleMode() ? 3 : 1, true, 0); delegate.needStartRecordAudio(0); } - recordingAudioVideo = false; - updateRecordIntefrace(RECORD_STATE_SENDING); + if (!NekoConfig.confirmAVMessage) { + recordingAudioVideo = false; + updateRecordIntefrace(RECORD_STATE_SENDING); + } } return false; } @@ -2469,16 +2475,24 @@ public class ChatActivityEnterView extends FrameLayout implements NotificationCe startedDraggingX = -1; if (hasRecordVideo && videoSendButton.getTag() != null) { CameraController.getInstance().cancelOnInitRunnable(onFinishInitCameraRunnable); - delegate.needStartRecordVideo(1, true, 0); + delegate.needStartRecordVideo(NekoConfig.confirmAVMessage ? 3 : 1, true, 0); } else { - if (recordingAudioVideo && isInScheduleMode()) { - AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (notify, scheduleDate) -> MediaController.getInstance().stopRecording(1, notify, scheduleDate), () -> MediaController.getInstance().stopRecording(0, false, 0)); + if (!NekoConfig.confirmAVMessage) { + if (recordingAudioVideo && isInScheduleMode()) { + AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (notify, scheduleDate) -> MediaController.getInstance().stopRecording(1, notify, scheduleDate), () -> MediaController.getInstance().stopRecording(0, false, 0)); + } } delegate.needStartRecordAudio(0); - MediaController.getInstance().stopRecording(isInScheduleMode() ? 3 : 1, true, 0); + if (!NekoConfig.confirmAVMessage) { + MediaController.getInstance().stopRecording(isInScheduleMode() ? 3 : 1, true, 0); + } else { + MediaController.getInstance().stopRecording(2, true, 0); + } + } + if (!NekoConfig.confirmAVMessage) { + recordingAudioVideo = false; + updateRecordIntefrace(RECORD_STATE_SENDING); } - recordingAudioVideo = false; - updateRecordIntefrace(RECORD_STATE_SENDING); } } } else if (motionEvent.getAction() == MotionEvent.ACTION_MOVE && recordingAudioVideo) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index cccf489f1..eac64bd79 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -32,6 +32,7 @@ public class NekoConfig { public static boolean chatMessageAnimation = false; public static boolean rearVideoMessages = false; public static boolean hideAllTab = false; + public static boolean confirmAVMessage = true; public static int mapPreviewProvider = 0; public static float stickerSize = 14.0f; public static int translationProvider = 1; @@ -106,6 +107,7 @@ public class NekoConfig { editor.putBoolean("chatMessageAnimation", chatMessageAnimation); editor.putBoolean("rearVideoMessages", rearVideoMessages); editor.putBoolean("hideAllTab", hideAllTab); + editor.putBoolean("confirmAVMessage", confirmAVMessage); editor.putFloat("stickerSize", stickerSize); editor.putInt("typeface", typeface); editor.putInt("nameOrder", nameOrder); @@ -167,6 +169,7 @@ public class NekoConfig { rearVideoMessages = preferences.getBoolean("rearVideoMessages", false); hideAllTab = preferences.getBoolean("hideAllTab", false); tabsTitleType = preferences.getInt("tabsTitleType", TITLE_TYPE_TEXT); + confirmAVMessage = preferences.getBoolean("confirmAVMessage", true); configLoaded = true; } } @@ -485,4 +488,12 @@ public class NekoConfig { editor.putInt("tabsTitleType", tabsTitleType); editor.commit(); } + + public static void toggleConfirmAVMessage() { + confirmAVMessage = !confirmAVMessage; + SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); + SharedPreferences.Editor editor = preferences.edit(); + editor.putBoolean("confirmAVMessage", confirmAVMessage); + editor.commit(); + } } diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoSettingsActivity.java index ad7da4862..e76f4db8e 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoSettingsActivity.java @@ -82,6 +82,7 @@ public class NekoSettingsActivity extends BaseFragment { private int hideKeyboardOnChatScrollRow; private int rearVideoMessagesRow; private int hideAllTabRow; + private int confirmAVRow; private int mapPreviewRow; private int stickerSizeRow; private int translationProviderRow; @@ -113,6 +114,47 @@ public class NekoSettingsActivity extends BaseFragment { private int deleteAccountRow; private int needRestartRow; + static public AlertDialog getTranslationProviderAlert(Context context) { + ArrayList arrayList = new ArrayList<>(); + ArrayList types = new ArrayList<>(); + arrayList.add(LocaleController.getString("ProviderGoogleTranslate", R.string.ProviderGoogleTranslate)); + types.add(Translator.PROVIDER_GOOGLE); + arrayList.add(LocaleController.getString("ProviderGoogleTranslateCN", R.string.ProviderGoogleTranslateCN)); + types.add(Translator.PROVIDER_GOOGLE_CN); + arrayList.add(LocaleController.getString("ProviderLingocloud", R.string.ProviderLingocloud)); + types.add(Translator.PROVIDER_LINGO); + arrayList.add(LocaleController.getString("ProviderGoogleTranslateWeb", R.string.ProviderGoogleTranslateWeb)); + types.add(Translator.PROVIDER_GOOGLE_WEB); + arrayList.add(LocaleController.getString("ProviderGoogleTranslateCNWeb", R.string.ProviderGoogleTranslateCNWeb)); + types.add(Translator.PROVIDER_GOOGLE_CN_WEB); + arrayList.add(LocaleController.getString("ProviderBaiduFanyiWeb", R.string.ProviderBaiduFanyiWeb)); + types.add(Translator.PROVIDER_BAIDU_WEB); + arrayList.add(LocaleController.getString("ProviderDeepLWeb", R.string.ProviderDeepLWeb)); + types.add(Translator.PROVIDER_DEEPL_WEB); + + AlertDialog.Builder builder = new AlertDialog.Builder(context); + builder.setTitle(LocaleController.getString("TranslationProvider", R.string.TranslationProvider)); + final LinearLayout linearLayout = new LinearLayout(context); + linearLayout.setOrientation(LinearLayout.VERTICAL); + builder.setView(linearLayout); + + for (int a = 0; a < arrayList.size(); a++) { + RadioColorCell cell = new RadioColorCell(context); + cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); + cell.setTag(a); + cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); + cell.setTextAndValue(arrayList.get(a), NekoConfig.translationProvider == types.get(a)); + linearLayout.addView(cell); + cell.setOnClickListener(v -> { + Integer which = (Integer) v.getTag(); + NekoConfig.setTranslationProvider(types.get(which)); + builder.getDismissRunnable().run(); + }); + } + builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); + return builder.create(); + } + @Override public boolean onFragmentCreate() { super.onFragmentCreate(); @@ -538,8 +580,12 @@ public class NekoSettingsActivity extends BaseFragment { } builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); showDialog(builder.create()); + } else if (position == confirmAVRow) { + NekoConfig.toggleConfirmAVMessage(); + if (view instanceof TextCheckCell) { + ((TextCheckCell) view).setChecked(NekoConfig.confirmAVMessage); + } } - }); return fragmentView; @@ -569,6 +615,7 @@ public class NekoSettingsActivity extends BaseFragment { hideKeyboardOnChatScrollRow = rowCount++; rearVideoMessagesRow = rowCount++; hideAllTabRow = rowCount++; + confirmAVRow = rowCount++; mapPreviewRow = rowCount++; stickerSizeRow = rowCount++; messageMenuRow = rowCount++; @@ -688,47 +735,6 @@ public class NekoSettingsActivity extends BaseFragment { })); } - static public AlertDialog getTranslationProviderAlert(Context context) { - ArrayList arrayList = new ArrayList<>(); - ArrayList types = new ArrayList<>(); - arrayList.add(LocaleController.getString("ProviderGoogleTranslate", R.string.ProviderGoogleTranslate)); - types.add(Translator.PROVIDER_GOOGLE); - arrayList.add(LocaleController.getString("ProviderGoogleTranslateCN", R.string.ProviderGoogleTranslateCN)); - types.add(Translator.PROVIDER_GOOGLE_CN); - arrayList.add(LocaleController.getString("ProviderLingocloud", R.string.ProviderLingocloud)); - types.add(Translator.PROVIDER_LINGO); - arrayList.add(LocaleController.getString("ProviderGoogleTranslateWeb", R.string.ProviderGoogleTranslateWeb)); - types.add(Translator.PROVIDER_GOOGLE_WEB); - arrayList.add(LocaleController.getString("ProviderGoogleTranslateCNWeb", R.string.ProviderGoogleTranslateCNWeb)); - types.add(Translator.PROVIDER_GOOGLE_CN_WEB); - arrayList.add(LocaleController.getString("ProviderBaiduFanyiWeb", R.string.ProviderBaiduFanyiWeb)); - types.add(Translator.PROVIDER_BAIDU_WEB); - arrayList.add(LocaleController.getString("ProviderDeepLWeb", R.string.ProviderDeepLWeb)); - types.add(Translator.PROVIDER_DEEPL_WEB); - - AlertDialog.Builder builder = new AlertDialog.Builder(context); - builder.setTitle(LocaleController.getString("TranslationProvider", R.string.TranslationProvider)); - final LinearLayout linearLayout = new LinearLayout(context); - linearLayout.setOrientation(LinearLayout.VERTICAL); - builder.setView(linearLayout); - - for (int a = 0; a < arrayList.size(); a++) { - RadioColorCell cell = new RadioColorCell(context); - cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0); - cell.setTag(a); - cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked)); - cell.setTextAndValue(arrayList.get(a), NekoConfig.translationProvider == types.get(a)); - linearLayout.addView(cell); - cell.setOnClickListener(v -> { - Integer which = (Integer) v.getTag(); - NekoConfig.setTranslationProvider(types.get(which)); - builder.getDismissRunnable().run(); - }); - } - builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null); - return builder.create(); - } - private void showMessageMenuAlert() { if (getParentActivity() == null) { return; @@ -1132,6 +1138,8 @@ public class NekoSettingsActivity extends BaseFragment { textCell.setTextAndCheck(LocaleController.getString("RearVideoMessages", R.string.RearVideoMessages), NekoConfig.rearVideoMessages, true); } else if (position == hideAllTabRow) { textCell.setTextAndValueAndCheck(LocaleController.getString("HideAllTab", R.string.HideAllTab), LocaleController.getString("HideAllTabAbout", R.string.HideAllTabAbout), NekoConfig.hideAllTab, true, true); + } else if (position == confirmAVRow) { + textCell.setTextAndCheck(LocaleController.getString("ConfirmAVMessage", R.string.ConfirmAVMessage), NekoConfig.confirmAVMessage, true); } break; } @@ -1172,7 +1180,7 @@ public class NekoSettingsActivity extends BaseFragment { position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow || position == experimentRow || position == hideKeyboardOnChatScrollRow || position == avatarAsDrawerBackgroundRow || position == showTabsOnForwardRow || position == chatMessageAnimationRow || position == rearVideoMessagesRow || - position == hideAllTabRow || position == tabsTitleTypeRow; + position == hideAllTabRow || position == tabsTitleTypeRow || position == confirmAVRow; } @Override @@ -1228,7 +1236,7 @@ public class NekoSettingsActivity extends BaseFragment { position == disableFilteringRow || position == smoothKeyboardRow || position == pauseMusicOnRecordRow || position == disablePhotoSideActionRow || position == unlimitedPinnedDialogsRow || position == openArchiveOnPullRow || position == hideKeyboardOnChatScrollRow || position == avatarAsDrawerBackgroundRow || position == showTabsOnForwardRow || - position == chatMessageAnimationRow || position == rearVideoMessagesRow || position == hideAllTabRow) { + position == chatMessageAnimationRow || position == rearVideoMessagesRow || position == hideAllTabRow || position == confirmAVRow) { return 3; } else if (position == settingsRow || position == connectionRow || position == chatRow || position == experimentRow) { return 4; diff --git a/TMessagesProj/src/main/res/values/strings_neko.xml b/TMessagesProj/src/main/res/values/strings_neko.xml index 15ef3bd28..70d4f220b 100644 --- a/TMessagesProj/src/main/res/values/strings_neko.xml +++ b/TMessagesProj/src/main/res/values/strings_neko.xml @@ -96,4 +96,5 @@ Titles Emoticons Emoticons with titles + Confirm before sending video/voice message \ No newline at end of file