mirror of https://github.com/NekoX-Dev/NekoX.git
Feature: custom save path
This commit is contained in:
parent
b848e5e666
commit
1d3011ea58
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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<String, String> 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<String, String> 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
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -138,5 +138,7 @@
|
|||
<string name="doubleTapSendReactions">Send Reaction when double tap (Default)</string>
|
||||
<string name="doubleTapShowReactions">Show reactions when double tap only</string>
|
||||
<string name="ReactionsDisabled">Disable</string>
|
||||
<string name="customSavePath">Custom Save Path</string>
|
||||
<string name="customSavePathHint">Leave blank to save directly</string>
|
||||
|
||||
</resources>
|
Loading…
Reference in New Issue