diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java index 75a698eac..1b8859ff7 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/AndroidUtilities.java @@ -1714,8 +1714,16 @@ public class AndroidUtilities { } public static boolean isTablet() { - if (isTablet == null) { - isTablet = NekoConfig.forceTablet || ApplicationLoader.applicationContext.getResources().getBoolean(R.bool.isTablet); + if (isTablet == null) switch (NekoConfig.tabletMode) { + case 0: + isTablet = ApplicationLoader.applicationContext.getResources().getBoolean(R.bool.isTablet); + break; + case 1: + isTablet = true; + break; + case 2: + isTablet = false; + break; } return isTablet; } @@ -2595,7 +2603,7 @@ public class AndroidUtilities { if (num_ < 0.1) { return "0"; } else { - if ((num_ * 10)== (int) (num_ * 10)) { + if ((num_ * 10) == (int) (num_ * 10)) { return String.format(Locale.ENGLISH, "%s%s", AndroidUtilities.formatCount((int) num_), numbersSignatureArray[count]); } else { return String.format(Locale.ENGLISH, "%.1f%s", (int) (num_ * 10) / 10f, numbersSignatureArray[count]); @@ -2779,7 +2787,7 @@ public class AndroidUtilities { if (Build.VERSION.SDK_INT >= 26 && realMimeType != null && realMimeType.equals("application/vnd.android.package-archive") && !ApplicationLoader.applicationContext.getPackageManager().canRequestPackageInstalls()) { BottomBuilder builder = new BottomBuilder(activity); builder.addTitle(LocaleController.getString("ApkRestricted", R.string.ApkRestricted)); - builder.addItem(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), R.drawable.baseline_settings_24,(i) -> { + builder.addItem(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), R.drawable.baseline_settings_24, (i) -> { try { activity.startActivity(new Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES, Uri.parse("package:" + activity.getPackageName()))); } catch (Exception e) { @@ -3992,7 +4000,7 @@ public class AndroidUtilities { flags &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR; decorView.setSystemUiVisibility(flags); if (!SharedConfig.noStatusBar && !NekoConfig.transparentStatusBar) { - window.setStatusBarColor(0x33000000); + window.setStatusBarColor(0x33000000); } } } diff --git a/TMessagesProj/src/main/java/org/telegram/ui/Components/UndoView.java b/TMessagesProj/src/main/java/org/telegram/ui/Components/UndoView.java index 3c3d49cb5..b5c95b287 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/Components/UndoView.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/Components/UndoView.java @@ -5,6 +5,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.content.Context; +import android.content.Intent; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.PorterDuff; @@ -31,6 +32,8 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; +import com.jakewharton.processphoenix.ProcessPhoenix; + import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.ChatObject; import org.telegram.messenger.Emoji; @@ -43,8 +46,10 @@ import org.telegram.messenger.UserConfig; import org.telegram.messenger.UserObject; import org.telegram.tgnet.TLRPC; import org.telegram.ui.ActionBar.Theme; +import org.telegram.ui.LaunchActivity; import tw.nekomimi.nekogram.NekoConfig; +import tw.nekomimi.nekogram.utils.UIUtil; @SuppressWarnings("FieldCanBeLocal") public class UndoView extends FrameLayout { @@ -117,6 +122,8 @@ public class UndoView extends FrameLayout { public final static int ACTION_VOIP_LINK_COPIED = 33; public final static int ACTION_VOIP_INVITED = 34; + public final static int ACTION_NEED_RESATRT = 100; + private CharSequence infoText; public class LinkMovementMethodMy extends LinkMovementMethod { @@ -246,7 +253,7 @@ public class UndoView extends FrameLayout { currentAction == ACTION_OWNER_TRANSFERED_GROUP || currentAction == ACTION_QUIZ_CORRECT || currentAction == ACTION_QUIZ_INCORRECT || currentAction == ACTION_CACHE_WAS_CLEARED || currentAction == ACTION_ADDED_TO_FOLDER || currentAction == ACTION_REMOVED_FROM_FOLDER || currentAction == ACTION_PROFILE_PHOTO_CHANGED || currentAction == ACTION_CHAT_UNARCHIVED || currentAction == ACTION_VOIP_MUTED || currentAction == ACTION_VOIP_UNMUTED || currentAction == ACTION_VOIP_REMOVED || - currentAction == ACTION_VOIP_LINK_COPIED || currentAction == ACTION_VOIP_INVITED; + currentAction == ACTION_VOIP_LINK_COPIED || currentAction == ACTION_VOIP_INVITED || currentAction == ACTION_NEED_RESATRT; } private boolean hasSubInfo() { @@ -341,7 +348,7 @@ public class UndoView extends FrameLayout { if (currentActionRunnable != null) { currentActionRunnable.run(); } - if (NekoConfig.disableUndo && action < ACTION_QUIZ_CORRECT) { + if (NekoConfig.disableUndo && !isTooltipAction()) { if (actionRunnable != null) actionRunnable.run(); return; } @@ -373,7 +380,28 @@ public class UndoView extends FrameLayout { infoTextView.setMinHeight(0); - if (isTooltipAction()) { + if (currentAction == ACTION_NEED_RESATRT) { + infoTextView.setText(LocaleController.getString("RestartAppToTakeEffect", R.string.RestartAppToTakeEffect)); + + layoutParams.leftMargin = AndroidUtilities.dp(58); + layoutParams.topMargin = AndroidUtilities.dp(13); + layoutParams.rightMargin = 0; + + infoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); + undoButton.setVisibility(VISIBLE); + infoTextView.setTypeface(Typeface.DEFAULT); + subinfoTextView.setVisibility(GONE); + + leftImageView.setVisibility(VISIBLE); + leftImageView.setAnimation(R.raw.chats_infotip, 36, 36); + leftImageView.setProgress(0); + leftImageView.playAnimation(); + undoImageView.setVisibility(GONE); + + undoTextView.setText(LocaleController.getString("ApplyTheme", R.string.ApplyTheme)); + currentCancelRunnable = () -> ProcessPhoenix.triggerRebirth(getContext(), new Intent(getContext(), LaunchActivity.class)); + + } else if (isTooltipAction()) { CharSequence infoText; String subInfoText; int icon; @@ -680,7 +708,7 @@ public class UndoView extends FrameLayout { if ("\uD83C\uDFB2".equals(emoji)) { infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DiceInfo2", R.string.DiceInfo2))); leftImageView.setImageResource(R.drawable.dice); - } else{ + } else { if ("\uD83C\uDFAF".equals(emoji)) { infoTextView.setText(AndroidUtilities.replaceTags(LocaleController.getString("DartInfo", R.string.DartInfo))); } else { diff --git a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java index 06dd4760b..5ca9949a1 100644 --- a/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java +++ b/TMessagesProj/src/main/java/org/telegram/ui/DialogsActivity.java @@ -1912,7 +1912,7 @@ private int lastMeasuredTopPadding; if (folderId != 0) { actionBar.setTitle(LocaleController.getString("ArchivedChats", R.string.ArchivedChats)); } else { - actionBar.setTitle(getNekoTitle(LocaleController.getString("NekoX", R.string.NekoX))); + actionBar.setTitle(LocaleController.getString("NekoX", R.string.NekoX)); } if (folderId == 0) { actionBar.setSupportsHolidayImage(true); @@ -5661,22 +5661,6 @@ private int lastMeasuredTopPadding; } } - private String getNekoTitle(String title) { - - if (!NekoConfig.removeTitleEmoji) { - - title = LocaleController.getString("NekogramEmojiDialogs", R.string.NekogramEmojiDialogs) + " " + title; - - } - - return title; - - //if (FilterPopup.getInstance(currentAccount).getTotalUnreadCount() == 0) { - // return LocaleController.getString("NekogramEmojiDialogs", R.string.NekogramEmojiDialogs) + " " + title; - //} - //return LocaleController.getString("NekogramEmojiDialogsUnread", R.string.NekogramEmojiDialogsUnread) + " " + title; - } - @SuppressWarnings("unchecked") @Override public void didReceivedNotification(int id, int account, Object... args) { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index aea56e852..b6e662b33 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -14,14 +14,14 @@ import org.telegram.messenger.NotificationCenter; import org.telegram.messenger.NotificationsService; import org.telegram.messenger.R; -import java.util.Locale; - -import cn.hutool.core.util.StrUtil; import java.io.BufferedReader; import java.io.FileReader; +import java.util.Locale; import java.util.regex.Matcher; import java.util.regex.Pattern; +import cn.hutool.core.util.StrUtil; + public class NekoConfig { public static final int TITLE_TYPE_TEXT = 0; @@ -60,7 +60,7 @@ public class NekoConfig { public static boolean hidePhone; public static int typeface; public static boolean transparentStatusBar; - public static boolean forceTablet; + public static int tabletMode; public static boolean openArchiveOnPull; public static boolean avatarAsDrawerBackground; public static boolean showTabsOnForward; @@ -96,7 +96,6 @@ public class NekoConfig { public static boolean disableProxyWhenVpnEnabled; public static boolean skipOpenLinkConfirm; - public static boolean removeTitleEmoji; public static boolean useDefaultTheme; public static boolean showIdAndDc; @@ -179,7 +178,18 @@ public class NekoConfig { useIPv6 = preferences.getBoolean("useIPv6", false); hidePhone = preferences.getBoolean("hidePhone", true); ignoreBlocked = preferences.getBoolean("ignoreBlocked", false); - forceTablet = preferences.getBoolean("forceTablet", false); + + boolean forceTablet = preferences.getBoolean("forceTablet", false); + if (forceTablet) { + tabletMode = 1; + preferences.edit() + .remove("forceTablet") + .putInt("tabletMode", 1) + .apply(); + } else { + tabletMode = preferences.getInt("tabletMode", 0); + } + typeface = preferences.getInt("typeface", 0); nameOrder = preferences.getInt("nameOrder", 1); mapPreviewProvider = preferences.getInt("mapPreviewProvider", 0); @@ -234,7 +244,6 @@ public class NekoConfig { disableProxyWhenVpnEnabled = preferences.getBoolean("disable_proxy_when_vpn_enabled", false); skipOpenLinkConfirm = preferences.getBoolean("skip_open_link_confirm", false); - removeTitleEmoji = preferences.getBoolean("remove_title_emoji", true); ignoreMutedCount = preferences.getBoolean("ignore_muted_count", true); useDefaultTheme = preferences.getBoolean("use_default_theme", false); showIdAndDc = preferences.getBoolean("show_id_and_dc", false); @@ -365,14 +374,6 @@ public class NekoConfig { editor.apply(); } - public static void toggleForceTablet() { - forceTablet = !forceTablet; - SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); - SharedPreferences.Editor editor = preferences.edit(); - editor.putBoolean("forceTablet", forceTablet); - editor.apply(); - } - public static void toggleTypeface() { typeface = typeface == 0 ? 1 : 0; SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("nekoconfig", Activity.MODE_PRIVATE); @@ -593,10 +594,6 @@ public class NekoConfig { preferences.edit().putBoolean("skip_open_link_confirm", skipOpenLinkConfirm = !skipOpenLinkConfirm).apply(); } - public static void toggleRemoveTitleEmoji() { - preferences.edit().putBoolean("remove_title_emoji", removeTitleEmoji = !removeTitleEmoji).apply(); - } - public static void toggleIgnoredMutedCount() { preferences.edit().putBoolean("ignore_muted_count", ignoreMutedCount = !ignoreMutedCount).apply(); } @@ -716,6 +713,10 @@ public class NekoConfig { } + public static void setTabletMode(int mode) { + preferences.edit().putInt("tabletMode", tabletMode = mode).apply(); + } + private static final String EMOJI_FONT_AOSP = "NotoColorEmoji.ttf"; public static Typeface getSystemEmojiTypeface() { diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java index d9234c5cb..8fefe0cf8 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -24,7 +24,6 @@ import org.openintents.openpgp.util.OpenPgpApi; import org.telegram.messenger.AndroidUtilities; import org.telegram.messenger.BuildConfig; import org.telegram.messenger.ContactsController; -import org.telegram.messenger.ImageLoader; import org.telegram.messenger.LocaleController; import org.telegram.messenger.MessagesController; import org.telegram.messenger.NotificationCenter; @@ -53,7 +52,6 @@ import org.telegram.ui.Components.UndoView; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; -import java.util.concurrent.atomic.AtomicReference; import cn.hutool.core.util.StrUtil; import kotlin.Unit; @@ -63,7 +61,6 @@ import tw.nekomimi.nekogram.PopupBuilder; import tw.nekomimi.nekogram.transtale.Translator; import tw.nekomimi.nekogram.transtale.TranslatorKt; import tw.nekomimi.nekogram.utils.AlertUtil; -import tw.nekomimi.nekogram.utils.EnvUtil; import tw.nekomimi.nekogram.utils.PGPUtil; @SuppressLint("RtlHardcoded") @@ -103,12 +100,11 @@ public class NekoGeneralSettingsActivity extends BaseFragment { private int useDefaultThemeRow; private int useSystemEmojiRow; private int transparentStatusBarRow; - private int forceTabletRow; private int avatarAsDrawerBackgroundRow; - private int removeTitleEmojiRow; private int newYearRow; private int actionBarDecorationRow; private int appBarShadowRow; + private int tabletModeRow; private int appearance2Row; private int privacyRow; @@ -212,18 +208,12 @@ public class NekoGeneralSettingsActivity extends BaseFragment { if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(NekoConfig.useDefaultTheme); } + restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null); } else if (position == inappCameraRow) { SharedConfig.toggleInappCamera(); if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(SharedConfig.inappCamera); } - - } else if (position == forceTabletRow) { - NekoConfig.toggleForceTablet(); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.forceTablet); - } - restartTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); } else if (position == transparentStatusBarRow) { NekoConfig.toggleTransparentStatusBar(); if (view instanceof TextCheckCell) { @@ -260,7 +250,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { }, (i, __) -> { NekoConfig.setNameOrder(i + 1); listAdapter.notifyItemChanged(position); - restartTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); + restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null); return Unit.INSTANCE; }); @@ -278,7 +268,27 @@ public class NekoGeneralSettingsActivity extends BaseFragment { NekoConfig.setActionBarDecoration(i); listAdapter.notifyItemChanged(position); - restartTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); + restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null); + + return null; + + }); + + builder.show(); + + } else if (position == tabletModeRow) { + + PopupBuilder builder = new PopupBuilder(view); + + builder.setItems(new String[]{ + LocaleController.getString("TabletModeDefault", R.string.TabletModeDefault), + LocaleController.getString("Enable", R.string.Enable), + LocaleController.getString("Disable", R.string.Disable) + }, (i, __) -> { + + NekoConfig.setTabletMode(i); + listAdapter.notifyItemChanged(position); + restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null); return null; @@ -290,7 +300,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { NekoConfig.toggleNewYear(); if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(NekoConfig.newYear); - restartTooltip.showWithAction(0, UndoView.ACTION_CACHE_WAS_CLEARED, null, null); + restartTooltip.showWithAction(0, UndoView.ACTION_NEED_RESATRT, null, null); } } else if (position == translationProviderRow) { @@ -407,12 +417,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment { if (view instanceof TextCheckCell) { ((TextCheckCell) view).setChecked(NekoConfig.avatarAsDrawerBackground); } - } else if (position == removeTitleEmojiRow) { - NekoConfig.toggleRemoveTitleEmoji(); - NotificationCenter.getInstance(UserConfig.selectedAccount).postNotificationName(NotificationCenter.mainUserInfoChanged); - if (view instanceof TextCheckCell) { - ((TextCheckCell) view).setChecked(NekoConfig.removeTitleEmoji); - } } else if (position == showIdAndDcRow) { NekoConfig.toggleShowIdAndDc(); if (view instanceof TextCheckCell) { @@ -499,7 +503,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment { }); restartTooltip = new UndoView(context); - restartTooltip.setInfoText(LocaleController.formatString("RestartAppToTakeEffect", R.string.RestartAppToTakeEffect)); frameLayout.addView(restartTooltip, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8)); return fragmentView; @@ -697,12 +700,11 @@ public class NekoGeneralSettingsActivity extends BaseFragment { useDefaultThemeRow = rowCount++; useSystemEmojiRow = !BuildConfig.FLAVOR.contains("No") ? rowCount++ : -1; transparentStatusBarRow = Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ? rowCount++ : -1; - forceTabletRow = rowCount++; avatarAsDrawerBackgroundRow = rowCount++; appBarShadowRow = rowCount++; - removeTitleEmojiRow = rowCount++; newYearRow = rowCount++; actionBarDecorationRow = rowCount++; + tabletModeRow = rowCount ++; appearance2Row = rowCount++; privacyRow = rowCount++; @@ -817,7 +819,21 @@ public class NekoGeneralSettingsActivity extends BaseFragment { default: value = LocaleController.getString("DependsOnDate", R.string.DependsOnDate); } - textCell.setTextAndValue(LocaleController.getString("ActionBarDecoration", R.string.ActionBarDecoration), value, false); + textCell.setTextAndValue(LocaleController.getString("ActionBarDecoration", R.string.ActionBarDecoration), value, true); + } else if (position == tabletModeRow) { + String value; + switch (NekoConfig.tabletMode) { + case 0: + value = LocaleController.getString("TabletModeDefault", R.string.TabletModeDefault); + break; + case 1: + value = LocaleController.getString("Enable", R.string.Enable); + break; + case 2: + default: + value = LocaleController.getString("Disable", R.string.Disable); + } + textCell.setTextAndValue(LocaleController.getString("TabletMode", R.string.TabletMode), value, false); } else if (position == sortMenuRow) { textCell.setText(LocaleController.getString("SortMenu", R.string.SortMenu), true); } else if (position == translateToLangRow) { @@ -884,8 +900,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment { textCell.setTextAndCheck(LocaleController.getString("EmojiUseDefault", R.string.EmojiUseDefault), NekoConfig.useSystemEmoji, true); } else if (position == typefaceRow) { textCell.setTextAndCheck(LocaleController.getString("TypefaceUseDefault", R.string.TypefaceUseDefault), NekoConfig.typeface == 1, true); - } else if (position == forceTabletRow) { - textCell.setTextAndCheck(LocaleController.getString("ForceTabletMode", R.string.ForceTabletMode), NekoConfig.forceTablet, true); } else if (position == newYearRow) { textCell.setTextAndCheck(LocaleController.getString("ChristmasHat", R.string.ChristmasHat), NekoConfig.newYear, true); } else if (position == openArchiveOnPullRow) { @@ -894,8 +908,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment { textCell.setTextAndCheck(LocaleController.getString("DisableSystemAccount", R.string.DisableSystemAccount), NekoConfig.disableSystemAccount, false); } else if (position == avatarAsDrawerBackgroundRow) { textCell.setTextAndCheck(LocaleController.getString("UseAvatarAsDrawerBackground", R.string.UseAvatarAsDrawerBackground), NekoConfig.avatarAsDrawerBackground, true); - } else if (position == removeTitleEmojiRow) { - textCell.setTextAndCheck(LocaleController.getString("RemoveTitleEmoji", R.string.RemoveTitleEmoji), NekoConfig.removeTitleEmoji, true); } else if (position == showIdAndDcRow) { textCell.setTextAndCheck(LocaleController.getString("ShowIdAndDc", R.string.ShowIdAndDc), NekoConfig.showIdAndDc, true); } else if (position == askBeforeCallRow) { @@ -984,7 +996,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment { return 1; } else if (position == nameOrderRow || position == sortMenuRow || position == translateToLangRow || position == translateInputToLangRow || position == translationProviderRow || position == actionBarDecorationRow || - position == pgpAppRow || position == keyRow) { + position == pgpAppRow || position == keyRow || position == tabletModeRow) { return 2; } else if (position == connectionRow || position == transRow || position == dialogsRow || position == privacyRow || position == generalRow || position == appearanceRow || position == openKeyChainRow) { diff --git a/TMessagesProj/src/main/res/values/strings_nekox.xml b/TMessagesProj/src/main/res/values/strings_nekox.xml index e0f0c8c49..0b6416d7b 100644 --- a/TMessagesProj/src/main/res/values/strings_nekox.xml +++ b/TMessagesProj/src/main/res/values/strings_nekox.xml @@ -273,4 +273,7 @@ Accept new secret chat + Tablet mode + Depends on device + \ No newline at end of file