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() {
|
||||
String state = null;
|
||||
try {
|
||||
File file;
|
||||
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");
|
||||
}
|
||||
File file = new File(EnvUtil.getTelegramPath(), "caches");
|
||||
FileUtil.initDir(file);
|
||||
return file;
|
||||
} catch (Throwable e) {
|
||||
|
|
|
@ -174,22 +174,7 @@ public class CacheControlActivity extends BaseFragment {
|
|||
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), 0);
|
||||
totalSize = cacheSize + videoSize + audioSize + photoSize + documentsSize + musicSize + stickersSize;
|
||||
|
||||
File path;
|
||||
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);
|
||||
}
|
||||
File path = EnvUtil.getTelegramPath();
|
||||
try {
|
||||
StatFs stat = new StatFs(path.getPath());
|
||||
long blockSize;
|
||||
|
@ -324,36 +309,21 @@ public class CacheControlActivity extends BaseFragment {
|
|||
file = FileLoader.checkDirectory(type);
|
||||
}
|
||||
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) {
|
||||
cacheSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_CACHE), documentsMusicType);
|
||||
imagesCleared = true;
|
||||
|
||||
try {
|
||||
|
||||
FileUtil.delete(new File(ApplicationLoader.getDataDirFixed(), "cache"));
|
||||
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
FileUtil.delete(new File(EnvUtil.getTelegramPath(), "logs"));
|
||||
|
||||
} 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) {
|
||||
audioSize = getDirectorySize(FileLoader.checkDirectory(FileLoader.MEDIA_DIR_AUDIO), documentsMusicType);
|
||||
} else if (type == FileLoader.MEDIA_DIR_DOCUMENT) {
|
||||
|
|
|
@ -50,10 +50,17 @@ import org.telegram.ui.Components.voip.VoIPHelper;
|
|||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
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 {
|
||||
|
||||
private ListAdapter listAdapter;
|
||||
|
@ -105,13 +112,7 @@ public class DataSettingsActivity extends BaseFragment {
|
|||
usageSectionRow = rowCount++;
|
||||
storageUsageRow = rowCount++;
|
||||
dataUsageRow = rowCount++;
|
||||
storageNumRow = -1;
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
storageDirs = AndroidUtilities.getRootDirs();
|
||||
if (storageDirs.size() > 1) {
|
||||
storageNumRow = rowCount++;
|
||||
}
|
||||
}
|
||||
storageNumRow = rowCount++;
|
||||
usageSection2Row = rowCount++;
|
||||
mediaDownloadSectionRow = rowCount++;
|
||||
mobileRow = rowCount++;
|
||||
|
@ -338,41 +339,38 @@ public class DataSettingsActivity extends BaseFragment {
|
|||
} else if (position == dataUsageRow) {
|
||||
presentFragment(new DataUsageActivity());
|
||||
} else if (position == storageNumRow) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
|
||||
builder.setTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
|
||||
final LinearLayout linearLayout = new LinearLayout(getParentActivity());
|
||||
linearLayout.setOrientation(LinearLayout.VERTICAL);
|
||||
builder.setView(linearLayout);
|
||||
BottomBuilder builder = new BottomBuilder(getParentActivity());
|
||||
|
||||
String dir = storageDirs.get(0).getAbsolutePath();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
builder.addTitle(LocaleController.getString("StoragePath", R.string.StoragePath));
|
||||
|
||||
for (int a = 0, N = storageDirs.size(); a < N; a++) {
|
||||
String storageDir = storageDirs.get(a).getAbsolutePath();
|
||||
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(storageDir, storageDir.startsWith(dir));
|
||||
linearLayout.addView(cell);
|
||||
cell.setOnClickListener(v -> {
|
||||
SharedConfig.storageCacheDir = storageDir;
|
||||
SharedConfig.saveConfig();
|
||||
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();
|
||||
builder.getDismissRunnable().run();
|
||||
listAdapter.notifyItemChanged(storageNumRow);
|
||||
});
|
||||
}
|
||||
builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
|
||||
showDialog(builder.create());
|
||||
listAdapter.notifyItemChanged(position);
|
||||
|
||||
}
|
||||
|
||||
return Unit.INSTANCE;
|
||||
|
||||
});
|
||||
|
||||
builder.show();
|
||||
} else if (position == proxyRow) {
|
||||
presentFragment(new ProxyListActivity());
|
||||
} else if (position == enableStreamRow) {
|
||||
|
@ -486,26 +484,16 @@ public class DataSettingsActivity extends BaseFragment {
|
|||
}
|
||||
textCell.setTextAndValue(LocaleController.getString("VoipUseLessData", R.string.VoipUseLessData), value, true);
|
||||
} 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) {
|
||||
String dir = storageDirs.get(0).getAbsolutePath();
|
||||
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);
|
||||
textCell.setTextAndValue(LocaleController.getString("StoragePath", R.string.StoragePath), NekoConfig.cachePath, false);
|
||||
} else if (position == proxyRow) {
|
||||
textCell.setText(LocaleController.getString("ProxySettings", R.string.ProxySettings), false);
|
||||
} else if (position == resetDownloadRow) {
|
||||
textCell.setCanDisable(true);
|
||||
textCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText));
|
||||
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);
|
||||
} else if (position == clearDraftsRow) {
|
||||
textCell.setText(LocaleController.getString("PrivacyDeleteCloudDrafts", R.string.PrivacyDeleteCloudDrafts), false);
|
||||
|
|
|
@ -116,7 +116,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
private int privacy2Row;
|
||||
|
||||
private int generalRow;
|
||||
private int cachePathRow;
|
||||
private int hidePhoneRow;
|
||||
private int disableUndoRow;
|
||||
private int showIdAndDcRow;
|
||||
|
@ -303,41 +302,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
|
||||
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) {
|
||||
NekoConfig.toggleNewYear();
|
||||
if (view instanceof TextCheckCell) {
|
||||
|
@ -755,7 +719,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
privacy2Row = rowCount++;
|
||||
|
||||
generalRow = rowCount++;
|
||||
cachePathRow = rowCount++;
|
||||
hidePhoneRow = rowCount++;
|
||||
disableUndoRow = rowCount++;
|
||||
showIdAndDcRow = rowCount++;
|
||||
|
@ -914,8 +877,6 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
TextDetailSettingsCell textCell = (TextDetailSettingsCell) holder.itemView;
|
||||
if (position == googleCloudTranslateKeyRow) {
|
||||
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;
|
||||
|
@ -1049,7 +1010,7 @@ public class NekoGeneralSettingsActivity extends BaseFragment {
|
|||
} else if (position == connectionRow || position == transRow || position == dialogsRow ||
|
||||
position == privacyRow || position == generalRow || position == appearanceRow || position == openKeyChainRow) {
|
||||
return 4;
|
||||
} else if (position == googleCloudTranslateKeyRow || position == cachePathRow) {
|
||||
} else if (position == googleCloudTranslateKeyRow) {
|
||||
return 6;
|
||||
}
|
||||
return 3;
|
||||
|
|
|
@ -4,6 +4,7 @@ import android.content.Context
|
|||
import android.os.Build
|
||||
import android.os.Environment
|
||||
import android.os.storage.StorageManager
|
||||
import org.telegram.messenger.AndroidUtilities
|
||||
import org.telegram.messenger.ApplicationLoader
|
||||
import org.telegram.messenger.FileLog
|
||||
import tw.nekomimi.nekogram.NekoConfig
|
||||
|
@ -14,11 +15,14 @@ object EnvUtil {
|
|||
|
||||
@JvmStatic
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
val rootDirectories by lazy {
|
||||
val rootDirectories: List<File> by lazy {
|
||||
|
||||
val mStorageManager = ApplicationLoader.applicationContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
||||
|
||||
(mStorageManager.javaClass.getMethod("getVolumePaths").invoke(mStorageManager) as Array<String>).map { File(it) }
|
||||
try {
|
||||
val mStorageManager = ApplicationLoader.applicationContext.getSystemService(Context.STORAGE_SERVICE) as StorageManager
|
||||
(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="CustomBackendFingerprint">Key Fingerprint</string>
|
||||
|
||||
<string name="CachePath">Cache directory</string>
|
||||
|
||||
<string name="AllowFlashCall">Allow flash call</string>
|
||||
|
||||
<string name="ChangeTranslateProvider">Change Provider</string>
|
||||
|
|
Loading…
Reference in New Issue