mirror of https://github.com/NekoX-Dev/NekoX.git
Migrate to new storage setting
This commit is contained in:
parent
eb91f02681
commit
dce4798c4c
|
@ -1528,23 +1528,8 @@ public class AndroidUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File getCacheDir() {
|
public static File getCacheDir() {
|
||||||
String state = null;
|
|
||||||
try {
|
try {
|
||||||
File file;
|
File file = new File(EnvUtil.getTelegramPath(), "caches");
|
||||||
if (Build.VERSION.SDK_INT >= 19) {
|
|
||||||
File[] dirs = ApplicationLoader.applicationContext.getExternalCacheDirs();
|
|
||||||
file = dirs[0];
|
|
||||||
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
|
|
||||||
for (int a = 0; a < dirs.length; a++) {
|
|
||||||
if (dirs[a] != null && dirs[a].getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
|
|
||||||
file = dirs[a];
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
file = new File(EnvUtil.getTelegramPath(), "caches");
|
|
||||||
}
|
|
||||||
FileUtil.initDir(file);
|
FileUtil.initDir(file);
|
||||||
return file;
|
return file;
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
|
|
|
@ -174,22 +174,7 @@ public class CacheControlActivity extends BaseFragment {
|
||||||
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), 0);
|
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), 0);
|
||||||
totalSize = cacheSize + videoSize + audioSize + photoSize + documentsSize + musicSize + stickersSize;
|
totalSize = cacheSize + videoSize + audioSize + photoSize + documentsSize + musicSize + stickersSize;
|
||||||
|
|
||||||
File path;
|
File path = EnvUtil.getTelegramPath();
|
||||||
if (Build.VERSION.SDK_INT >= 19) {
|
|
||||||
ArrayList<File> storageDirs = AndroidUtilities.getRootDirs();
|
|
||||||
String dir = (path = storageDirs.get(0)).getAbsolutePath();
|
|
||||||
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
|
|
||||||
for (int a = 0, N = storageDirs.size(); a < N; a++) {
|
|
||||||
File file = storageDirs.get(a);
|
|
||||||
if (file.getAbsolutePath().startsWith(SharedConfig.storageCacheDir)) {
|
|
||||||
path = file;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
path = new File(SharedConfig.storageCacheDir);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
StatFs stat = new StatFs(path.getPath());
|
StatFs stat = new StatFs(path.getPath());
|
||||||
long blockSize;
|
long blockSize;
|
||||||
|
@ -324,36 +309,21 @@ public class CacheControlActivity extends BaseFragment {
|
||||||
file = FileLoader.checkDirectory(type);
|
file = FileLoader.checkDirectory(type);
|
||||||
}
|
}
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
Utilities.clearDir(file.getAbsolutePath(), documentsMusicType, Long.MAX_VALUE, false);
|
Utilities.clearDir(file.getAbsolutePath(), documentsMusicType, Long.MAX_VALUE, true);
|
||||||
}
|
}
|
||||||
if (type == FileLoader.MEDIA_DIR_CACHE) {
|
if (type == FileLoader.MEDIA_DIR_CACHE) {
|
||||||
cacheSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_CACHE), documentsMusicType);
|
cacheSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_CACHE), documentsMusicType);
|
||||||
imagesCleared = true;
|
imagesCleared = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
FileUtil.delete(new File(ApplicationLoader.getDataDirFixed(), "cache"));
|
FileUtil.delete(new File(ApplicationLoader.getDataDirFixed(), "cache"));
|
||||||
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
FileUtil.delete(new File(EnvUtil.getTelegramPath(), "logs"));
|
FileUtil.delete(new File(EnvUtil.getTelegramPath(), "logs"));
|
||||||
|
|
||||||
} catch (Exception ignored) {
|
} catch (Exception ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
// :)
|
|
||||||
|
|
||||||
FileUtil.delete(ApplicationLoader.applicationContext.getExternalFilesDir("Telegram"));
|
|
||||||
FileUtil.delete(Environment.getExternalStoragePublicDirectory("Telegram"));
|
|
||||||
|
|
||||||
} catch (Exception ignored) {
|
|
||||||
}
|
|
||||||
|
|
||||||
} else if (type == FileLoader.MEDIA_DIR_AUDIO) {
|
} else if (type == FileLoader.MEDIA_DIR_AUDIO) {
|
||||||
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), documentsMusicType);
|
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), documentsMusicType);
|
||||||
} else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
|
} else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
|
||||||
|
|
|
@ -50,10 +50,17 @@ import org.telegram.ui.Components.voip.VoIPHelper;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
|
import kotlin.Unit;
|
||||||
|
import tw.nekomimi.nekogram.BottomBuilder;
|
||||||
|
import tw.nekomimi.nekogram.NekoConfig;
|
||||||
|
import tw.nekomimi.nekogram.NekoXConfig;
|
||||||
|
import tw.nekomimi.nekogram.utils.EnvUtil;
|
||||||
|
|
||||||
public class DataSettingsActivity extends BaseFragment {
|
public class DataSettingsActivity extends BaseFragment {
|
||||||
|
|
||||||
private ListAdapter listAdapter;
|
private ListAdapter listAdapter;
|
||||||
|
@ -105,13 +112,7 @@ public class DataSettingsActivity extends BaseFragment {
|
||||||
usageSectionRow = rowCount++;
|
usageSectionRow = rowCount++;
|
||||||
storageUsageRow = rowCount++;
|
storageUsageRow = rowCount++;
|
||||||
dataUsageRow = rowCount++;
|
dataUsageRow = rowCount++;
|
||||||
storageNumRow = -1;
|
storageNumRow = rowCount++;
|
||||||
if (Build.VERSION.SDK_INT >= 19) {
|
|
||||||
storageDirs = AndroidUtilities.getRootDirs();
|
|
||||||
if (storageDirs.size() > 1) {
|
|
||||||
storageNumRow = rowCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
usageSection2Row = rowCount++;
|
usageSection2Row = rowCount++;
|
||||||
mediaDownloadSectionRow = rowCount++;
|
mediaDownloadSectionRow = rowCount++;
|
||||||
mobileRow = rowCount++;
|
mobileRow = rowCount++;
|
||||||
|
@ -338,41 +339,38 @@ public class DataSettingsActivity extends BaseFragment {
|
||||||
} else if (position == dataUsageRow) {
|
} else if (position == dataUsageRow) {
|
||||||
presentFragment(new DataUsageActivity());
|
presentFragment(new DataUsageActivity());
|
||||||
} else if (position == storageNumRow) {
|
} else if (position == storageNumRow) {
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
BottomBuilder builder = new BottomBuilder(getParentActivity());
|
||||||
builder.setTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
|
|
||||||
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
|
|
||||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
|
||||||
builder.setView(linearLayout);
|
|
||||||
|
|
||||||
String dir = storageDirs.get(0).getAbsolutePath();
|
builder.addTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
|
||||||
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
|
|
||||||
for (int a = 0, N = storageDirs.size(); a < N; a++) {
|
|
||||||
String path = storageDirs.get(a).getAbsolutePath();
|
|
||||||
if (path.startsWith(SharedConfig.storageCacheDir)) {
|
|
||||||
dir = path;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int a = 0, N = storageDirs.size(); a < N; a++) {
|
AtomicReference<String> target = new AtomicReference<>();
|
||||||
String storageDir = storageDirs.get(a).getAbsolutePath();
|
|
||||||
RadioColorCell cell = new RadioColorCell(context);
|
builder.addRadioItems(EnvUtil.getAvailableDirectories(),
|
||||||
cell.setPadding(AndroidUtilities.dp(4), 0, AndroidUtilities.dp(4), 0);
|
(index, path) -> path.equals(NekoConfig.cachePath), (__, path, cell) -> {
|
||||||
cell.setTag(a);
|
|
||||||
cell.setCheckColor(Theme.getColor(Theme.key_radioBackground), Theme.getColor(Theme.key_dialogRadioBackgroundChecked));
|
target.set(path);
|
||||||
cell.setTextAndValue(storageDir, storageDir.startsWith(dir));
|
builder.doRadioCheck(cell);
|
||||||
linearLayout.addView(cell);
|
|
||||||
cell.setOnClickListener(v -> {
|
return null;
|
||||||
SharedConfig.storageCacheDir = storageDir;
|
|
||||||
SharedConfig.saveConfig();
|
});
|
||||||
|
|
||||||
|
builder.addCancelButton();
|
||||||
|
builder.addOkButton((it) -> {
|
||||||
|
|
||||||
|
if (target.get() != null) {
|
||||||
|
|
||||||
|
NekoConfig.setCachePath(target.get());
|
||||||
ImageLoader.getInstance().checkMediaPaths();
|
ImageLoader.getInstance().checkMediaPaths();
|
||||||
builder.getDismissRunnable().run();
|
listAdapter.notifyItemChanged(position);
|
||||||
listAdapter.notifyItemChanged(storageNumRow);
|
|
||||||
});
|
}
|
||||||
}
|
|
||||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
return Unit.INSTANCE;
|
||||||
showDialog(builder.create());
|
|
||||||
|
});
|
||||||
|
|
||||||
|
builder.show();
|
||||||
} else if (position == proxyRow) {
|
} else if (position == proxyRow) {
|
||||||
presentFragment(new ProxyListActivity());
|
presentFragment(new ProxyListActivity());
|
||||||
} else if (position == enableStreamRow) {
|
} else if (position == enableStreamRow) {
|
||||||
|
@ -486,26 +484,16 @@ public class DataSettingsActivity extends BaseFragment {
|
||||||
}
|
}
|
||||||
textCell.setTextAndValue(LocaleController.getString("VoipUseLessData", R.string.VoipUseLessData), value, true);
|
textCell.setTextAndValue(LocaleController.getString("VoipUseLessData", R.string.VoipUseLessData), value, true);
|
||||||
} else if (position == dataUsageRow) {
|
} else if (position == dataUsageRow) {
|
||||||
textCell.setText(LocaleController.getString("NetworkUsage", R.string.NetworkUsage), storageNumRow != -1);
|
textCell.setText(LocaleController.getString("NetworkUsage", R.string.NetworkUsage), true);
|
||||||
} else if (position == storageNumRow) {
|
} else if (position == storageNumRow) {
|
||||||
String dir = storageDirs.get(0).getAbsolutePath();
|
textCell.setTextAndValue(LocaleController.getString("StoragePath", R.string.StoragePath), NekoConfig.cachePath, false);
|
||||||
if (!TextUtils.isEmpty(SharedConfig.storageCacheDir)) {
|
|
||||||
for (int a = 0, N = storageDirs.size(); a < N; a++) {
|
|
||||||
String path = storageDirs.get(a).getAbsolutePath();
|
|
||||||
if (path.startsWith(SharedConfig.storageCacheDir)) {
|
|
||||||
dir = path;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
textCell.setTextAndValue(LocaleController.getString("StoragePath", R.string.StoragePath), dir, false);
|
|
||||||
} else if (position == proxyRow) {
|
} else if (position == proxyRow) {
|
||||||
textCell.setText(LocaleController.getString("ProxySettings", R.string.ProxySettings), false);
|
textCell.setText(LocaleController.getString("ProxySettings", R.string.ProxySettings), false);
|
||||||
} else if (position == resetDownloadRow) {
|
} else if (position == resetDownloadRow) {
|
||||||
textCell.setCanDisable(true);
|
textCell.setCanDisable(true);
|
||||||
textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText));
|
textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText));
|
||||||
textCell.setText(LocaleController.getString("ResetAutomaticMediaDownload", R.string.ResetAutomaticMediaDownload), false);
|
textCell.setText(LocaleController.getString("ResetAutomaticMediaDownload", R.string.ResetAutomaticMediaDownload), false);
|
||||||
} else if (position == quickRepliesRow){
|
} else if (position == quickRepliesRow) {
|
||||||
textCell.setText(LocaleController.getString("VoipQuickReplies", R.string.VoipQuickReplies), false);
|
textCell.setText(LocaleController.getString("VoipQuickReplies", R.string.VoipQuickReplies), false);
|
||||||
} else if (position == clearDraftsRow) {
|
} else if (position == clearDraftsRow) {
|
||||||
textCell.setText(LocaleController.getString("PrivacyDeleteCloudDrafts", R.string.PrivacyDeleteCloudDrafts), false);
|
textCell.setText(LocaleController.getString("PrivacyDeleteCloudDrafts", R.string.PrivacyDeleteCloudDrafts), false);
|
||||||
|
|
|
@ -116,7 +116,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
private int privacy2Row;
|
private int privacy2Row;
|
||||||
|
|
||||||
private int generalRow;
|
private int generalRow;
|
||||||
private int cachePathRow;
|
|
||||||
private int hidePhoneRow;
|
private int hidePhoneRow;
|
||||||
private int disableUndoRow;
|
private int disableUndoRow;
|
||||||
private int showIdAndDcRow;
|
private int showIdAndDcRow;
|
||||||
|
@ -303,41 +302,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
|
|
||||||
builder.show();
|
builder.show();
|
||||||
|
|
||||||
} else if (position == cachePathRow) {
|
|
||||||
|
|
||||||
BottomBuilder builder = new BottomBuilder(getParentActivity());
|
|
||||||
|
|
||||||
builder.addTitle(LocaleController.getString("CachePath", R.string.CachePath));
|
|
||||||
|
|
||||||
AtomicReference<String> target = new AtomicReference<>();
|
|
||||||
|
|
||||||
builder.addRadioItems(EnvUtil.getAvailableDirectories(),
|
|
||||||
(index, path) -> path.equals(NekoConfig.cachePath), (__, path, cell) -> {
|
|
||||||
|
|
||||||
target.set(path);
|
|
||||||
builder.doRadioCheck(cell);
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.addCancelButton();
|
|
||||||
builder.addOkButton((it) -> {
|
|
||||||
|
|
||||||
if (target.get() != null) {
|
|
||||||
|
|
||||||
NekoConfig.setCachePath(target.get());
|
|
||||||
ImageLoader.getInstance().checkMediaPaths();
|
|
||||||
listAdapter.notifyItemChanged(position);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
return Unit.INSTANCE;
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
builder.show();
|
|
||||||
|
|
||||||
} else if (position == newYearRow) {
|
} else if (position == newYearRow) {
|
||||||
NekoConfig.toggleNewYear();
|
NekoConfig.toggleNewYear();
|
||||||
if (view instanceof TextCheckCell) {
|
if (view instanceof TextCheckCell) {
|
||||||
|
@ -755,7 +719,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
privacy2Row = rowCount++;
|
privacy2Row = rowCount++;
|
||||||
|
|
||||||
generalRow = rowCount++;
|
generalRow = rowCount++;
|
||||||
cachePathRow = rowCount++;
|
|
||||||
hidePhoneRow = rowCount++;
|
hidePhoneRow = rowCount++;
|
||||||
disableUndoRow = rowCount++;
|
disableUndoRow = rowCount++;
|
||||||
showIdAndDcRow = rowCount++;
|
showIdAndDcRow = rowCount++;
|
||||||
|
@ -914,8 +877,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView;
|
TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView;
|
||||||
if (position == googleCloudTranslateKeyRow) {
|
if (position == googleCloudTranslateKeyRow) {
|
||||||
textCell.setTextAndValue(LocaleController.getString("GoogleCloudTransKey", R.string.GoogleCloudTransKey), StrUtil.isNotBlank(NekoConfig.googleCloudTranslateKey) ? NekoConfig.googleCloudTranslateKey : LocaleController.getString("GoogleCloudTransKeyNotice", R.string.GoogleCloudTransKeyNotice), false);
|
textCell.setTextAndValue(LocaleController.getString("GoogleCloudTransKey", R.string.GoogleCloudTransKey), StrUtil.isNotBlank(NekoConfig.googleCloudTranslateKey) ? NekoConfig.googleCloudTranslateKey : LocaleController.getString("GoogleCloudTransKeyNotice", R.string.GoogleCloudTransKeyNotice), false);
|
||||||
} else if (position == cachePathRow) {
|
|
||||||
textCell.setTextAndValue(LocaleController.getString("CachePath", R.string.CachePath), NekoConfig.cachePath, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
@ -1049,7 +1010,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
||||||
} else if (position == connectionRow || position == transRow || position == dialogsRow ||
|
} else if (position == connectionRow || position == transRow || position == dialogsRow ||
|
||||||
position == privacyRow || position == generalRow || position == appearanceRow || position == openKeyChainRow) {
|
position == privacyRow || position == generalRow || position == appearanceRow || position == openKeyChainRow) {
|
||||||
return 4;
|
return 4;
|
||||||
} else if (position == googleCloudTranslateKeyRow || position == cachePathRow) {
|
} else if (position == googleCloudTranslateKeyRow) {
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
return 3;
|
return 3;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.os.storage.StorageManager
|
import android.os.storage.StorageManager
|
||||||
|
import org.telegram.messenger.AndroidUtilities
|
||||||
import org.telegram.messenger.ApplicationLoader
|
import org.telegram.messenger.ApplicationLoader
|
||||||
import org.telegram.messenger.FileLog
|
import org.telegram.messenger.FileLog
|
||||||
import tw.nekomimi.nekogram.NekoConfig
|
import tw.nekomimi.nekogram.NekoConfig
|
||||||
|
@ -14,11 +15,14 @@ object EnvUtil {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val rootDirectories by lazy {
|
val rootDirectories: List<File> by lazy {
|
||||||
|
|
||||||
val mStorageManager = ApplicationLoader.applicationContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
try {
|
||||||
|
val mStorageManager = ApplicationLoader.applicationContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
||||||
(mStorageManager.javaClass.getMethod("getVolumePaths").invoke(mStorageManager) as Array<String>).map { File(it) }
|
(mStorageManager.javaClass.getMethod("getVolumePaths").invoke(mStorageManager) as Array<String>).map { File(it) }
|
||||||
|
} catch (e: Throwable) {
|
||||||
|
AndroidUtilities.getRootDirs()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -53,8 +53,6 @@
|
||||||
<string name="CustomBackendPublicKey">Public Key</string>
|
<string name="CustomBackendPublicKey">Public Key</string>
|
||||||
<string name="CustomBackendFingerprint">Key Fingerprint</string>
|
<string name="CustomBackendFingerprint">Key Fingerprint</string>
|
||||||
|
|
||||||
<string name="CachePath">Cache directory</string>
|
|
||||||
|
|
||||||
<string name="AllowFlashCall">Allow flash call</string>
|
<string name="AllowFlashCall">Allow flash call</string>
|
||||||
|
|
||||||
<string name="ChangeTranslateProvider">Change Provider</string>
|
<string name="ChangeTranslateProvider">Change Provider</string>
|
||||||
|
|
Loading…
Reference in New Issue