diff --git a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java index a486c3a9e..99544f5a9 100644 --- a/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java +++ b/TMessagesProj/src/main/java/org/telegram/messenger/MediaController.java @@ -58,6 +58,8 @@ import android.view.WindowManager; import android.webkit.MimeTypeMap; import android.widget.FrameLayout; +import androidx.annotation.RequiresApi; + import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.ExoPlayer; import com.google.android.exoplayer2.ui.AspectRatioFrameLayout; @@ -3942,7 +3944,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, try { boolean result = true; - final String folderName = "NekoX"; + final String folderName = NekoConfig.customSavePath.String(); if (Build.VERSION.SDK_INT >= 29) { result = saveFileInternal(type, sourceFile, null); } else { @@ -4047,6 +4049,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, } } + @RequiresApi(api = Build.VERSION_CODES.Q) private static boolean saveFileInternal(int type, File sourceFile, String filename) { try { int selectedType = type; @@ -4065,7 +4068,7 @@ public class MediaController implements AudioManager.OnAudioFocusChangeListener, selectedType = 1; } } - final String folderName = "NekoX"; + final String folderName = NekoConfig.customSavePath.String(); if (selectedType == 0) { if (filename == null) { filename = AndroidUtilities.generateFileName(0, extension); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java index 7fa52bc86..349415572 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/NekoConfig.java @@ -115,6 +115,7 @@ public class NekoConfig { public static ConfigItem googleCloudTranslateKey = addConfig("GoogleCloudTransKey", configTypeString, ""); public static ConfigItem cachePath = addConfig("cache_path", configTypeString, ""); + public static ConfigItem customSavePath = addConfig("customSavePath", configTypeString, "NekoX"); public static ConfigItem translateToLang = addConfig("TransToLang", configTypeString, ""); // "" -> translate to current language (MessageTrans.kt & Translator.kt) public static ConfigItem translateInputLang = addConfig("TransInputToLang", configTypeString, "en"); diff --git a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextInput.java b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextInput.java index 042203cbd..012c5c9a5 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextInput.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/config/cell/ConfigCellTextInput.java @@ -14,6 +14,8 @@ import org.telegram.ui.Cells.TextSettingsCell; import org.telegram.ui.Components.EditTextBoldCursor; import org.telegram.ui.Components.LayoutHelper; +import java.util.function.Function; + import tw.nekomimi.nekogram.config.CellGroup; import tw.nekomimi.nekogram.config.ConfigItem; @@ -22,9 +24,14 @@ public class ConfigCellTextInput extends AbstractConfigCell { private final String hint; private final String title; private final Runnable onClickCustom; + private final Function inputChecker; + + public ConfigCellTextInput(String customTitle, ConfigItem bind, String hint, Runnable customOnClick) { + this(customTitle, bind, hint, customOnClick, null); + } // default: customTitle=null customOnClick=null - public ConfigCellTextInput(String customTitle, ConfigItem bind, String hint, Runnable customOnClick) { + public ConfigCellTextInput(String customTitle, ConfigItem bind, String hint, Runnable customOnClick, Function inputChecker) { this.bindConfig = bind; if (hint == null) { this.hint = ""; @@ -37,6 +44,7 @@ public class ConfigCellTextInput extends AbstractConfigCell { title = customTitle; } this.onClickCustom = customOnClick; + this.inputChecker = inputChecker; } public int getType() { @@ -80,6 +88,8 @@ public class ConfigCellTextInput extends AbstractConfigCell { builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (d, v) -> { String newV = editText.getText().toString(); + if (this.inputChecker != null) + newV = this.inputChecker.apply(newV); bindConfig.setConfigString(newV); //refresh 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 f5f747cb6..ec959271c 100644 --- a/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java +++ b/TMessagesProj/src/main/java/tw/nekomimi/nekogram/settings/NekoGeneralSettingsActivity.java @@ -50,9 +50,12 @@ import org.telegram.ui.Components.LayoutHelper; import org.telegram.ui.Components.RecyclerListView; import org.telegram.ui.Components.UndoView; +import java.nio.file.InvalidPathException; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.LinkedList; import java.util.List; +import java.util.Locale; import cn.hutool.core.util.StrUtil; import kotlin.Unit; @@ -148,6 +151,9 @@ public class NekoGeneralSettingsActivity extends BaseFragment { private final AbstractConfigCell divider6 = cellGroup.appendCell(new ConfigCellDivider()); private final AbstractConfigCell header7 = cellGroup.appendCell(new ConfigCellHeader(LocaleController.getString("General"))); + private final AbstractConfigCell customSavePathRow = cellGroup.appendCell(new ConfigCellTextInput(null, NekoConfig.customSavePath, + LocaleController.getString("customSavePathHint", R.string.customSavePathHint), null, + (input) -> input.matches("^[A-za-z0-9.]{1,255}$") || input.isEmpty() ? input : (String) NekoConfig.customSavePath.defaultValue)); private final AbstractConfigCell disableUndoRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.disableUndo)); private final AbstractConfigCell showIdAndDcRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.showIdAndDc)); private final AbstractConfigCell inappCameraRow = cellGroup.appendCell(new ConfigCellTextCheck(NekoConfig.inappCamera)); diff --git a/TMessagesProj/src/main/res/values/strings_neko.xml b/TMessagesProj/src/main/res/values/strings_neko.xml index 85fdd7172..568604b39 100644 --- a/TMessagesProj/src/main/res/values/strings_neko.xml +++ b/TMessagesProj/src/main/res/values/strings_neko.xml @@ -138,5 +138,7 @@ Send Reaction when double tap (Default) Show reactions when double tap only Disable + Custom Save Path + Leave blank to save directly \ No newline at end of file