6.7.0 - Alpha11 - 修复文件管理器删除项目文件夹后 UI 未能自动刷新的问题
This commit is contained in:
@@ -77,8 +77,7 @@ open class AssetsProjectLauncher(private val mAssetsProjectDir: String, private
|
||||
}
|
||||
|
||||
private fun prepare() {
|
||||
val projectConfigPath = PFiles.join(mProjectDir, ProjectConfig.CONFIG_FILE_NAME)
|
||||
val projectConfig = ProjectConfig.fromFile(projectConfigPath)
|
||||
val projectConfig = ProjectConfig.fromProjectDir(mProjectDir)
|
||||
if (projectConfig != null &&
|
||||
TextUtils.equals(projectConfig.buildInfo.buildId, mProjectConfig.buildInfo.buildId)
|
||||
) {
|
||||
|
||||
@@ -8,6 +8,11 @@ import java.io.File;
|
||||
public class ExplorerProjectPage extends ExplorerDirPage {
|
||||
private final ProjectConfig mProjectConfig;
|
||||
|
||||
public ExplorerProjectPage(PFile file, ExplorerPage parent) {
|
||||
super(file, parent);
|
||||
mProjectConfig = ProjectConfig.fromFile(file);
|
||||
}
|
||||
|
||||
public ExplorerProjectPage(PFile file, ExplorerPage parent, ProjectConfig projectConfig) {
|
||||
super(file, parent);
|
||||
mProjectConfig = projectConfig;
|
||||
|
||||
@@ -199,7 +199,11 @@ public class ProjectConfig {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ProjectConfig fromFile(String path) {
|
||||
public static ProjectConfig fromFile(File file) {
|
||||
return fromFilePath(file.getPath());
|
||||
}
|
||||
|
||||
public static ProjectConfig fromFilePath(String path) {
|
||||
String fileContents = null;
|
||||
try {
|
||||
fileContents = PFiles.read(path);
|
||||
@@ -369,14 +373,21 @@ public class ProjectConfig {
|
||||
// ! zh-CN: 无论 project.json 是否包含必要信息或是否可以正常解析, 都认为是一个有效项目.
|
||||
// !
|
||||
// # return fromProjectDir(page.getPath()) != null;
|
||||
String path = page.getPath();
|
||||
return isProject(page.getPath());
|
||||
}
|
||||
|
||||
public static boolean isProject(File file) {
|
||||
return isProject(file.getPath());
|
||||
}
|
||||
|
||||
public static boolean isProject(String path) {
|
||||
String pathname = configFileOfDir(path);
|
||||
return new File(pathname).exists();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static ProjectConfig fromProjectDir(String path) {
|
||||
return fromFile(configFileOfDir(path));
|
||||
return fromFilePath(configFileOfDir(path));
|
||||
}
|
||||
|
||||
public static String configFileOfDir(String projectDir) {
|
||||
|
||||
@@ -27,6 +27,7 @@ import org.autojs.autojs.model.explorer.Explorer;
|
||||
import org.autojs.autojs.model.explorer.ExplorerDirPage;
|
||||
import org.autojs.autojs.model.explorer.ExplorerFileItem;
|
||||
import org.autojs.autojs.model.explorer.ExplorerPage;
|
||||
import org.autojs.autojs.model.explorer.ExplorerProjectPage;
|
||||
import org.autojs.autojs.model.explorer.Explorers;
|
||||
import org.autojs.autojs.model.sample.SampleFile;
|
||||
import org.autojs.autojs.model.script.ScriptFile;
|
||||
@@ -35,6 +36,7 @@ import org.autojs.autojs.network.download.DownloadManager;
|
||||
import org.autojs.autojs.pio.PFile;
|
||||
import org.autojs.autojs.pio.PFiles;
|
||||
import org.autojs.autojs.pio.UncheckedIOException;
|
||||
import org.autojs.autojs.project.ProjectConfig;
|
||||
import org.autojs.autojs.storage.file.TmpScriptFiles;
|
||||
import org.autojs.autojs.ui.filechooser.FileChooserDialogBuilder;
|
||||
import org.autojs.autojs.ui.shortcut.ShortcutCreateActivity;
|
||||
@@ -421,13 +423,14 @@ public class ScriptOperations {
|
||||
|
||||
public void deleteWithoutConfirm(final ScriptFile scriptFile) {
|
||||
boolean isDir = scriptFile.isDirectory();
|
||||
boolean isProject = ProjectConfig.isProject(scriptFile);
|
||||
Observable.fromPublisher((Publisher<Boolean>) s -> s.onNext(PFiles.deleteRecursively(scriptFile)))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(deleted -> {
|
||||
if (deleted) {
|
||||
showMessage(R.string.text_already_deleted);
|
||||
notifyFileRemoved(isDir, scriptFile);
|
||||
notifyFileRemoved(isProject, isDir, scriptFile);
|
||||
} else {
|
||||
showMessage(R.string.text_failed_to_delete);
|
||||
}
|
||||
@@ -440,8 +443,10 @@ public class ScriptOperations {
|
||||
showMessage(R.string.text_done);
|
||||
}
|
||||
|
||||
private void notifyFileRemoved(boolean isDir, ScriptFile scriptFile) {
|
||||
if (isDir) {
|
||||
private void notifyFileRemoved(boolean isProject, boolean isDir, ScriptFile scriptFile) {
|
||||
if (isProject) {
|
||||
mExplorer.notifyItemRemoved(new ExplorerProjectPage(scriptFile, mExplorerPage));
|
||||
} else if (isDir) {
|
||||
mExplorer.notifyItemRemoved(new ExplorerDirPage(scriptFile, mExplorerPage));
|
||||
} else {
|
||||
mExplorer.notifyItemRemoved(new ExplorerFileItem(scriptFile, mExplorerPage));
|
||||
@@ -504,8 +509,8 @@ public class ScriptOperations {
|
||||
private class InputCallback implements MaterialDialog.InputCallback {
|
||||
|
||||
private final String mExcluded;
|
||||
private boolean mIsFirstTextChanged = true;
|
||||
private final String mExtension;
|
||||
private boolean mIsFirstTextChanged = true;
|
||||
|
||||
InputCallback(@Nullable String ext, @Nullable String excluded) {
|
||||
mExtension = ext == null ? null : "." + ext;
|
||||
|
||||
@@ -124,8 +124,9 @@ public class ExplorerProjectToolbar extends CardView {
|
||||
return;
|
||||
}
|
||||
ExplorerItem item = event.getItem();
|
||||
if ((event.getAction() == ExplorerChangeEvent.ALL)
|
||||
|| (item != null && mDirectory.getPath().equals(item.getPath()))) {
|
||||
if (event.getAction() == ExplorerChangeEvent.ALL) {
|
||||
refresh();
|
||||
} else if (item != null && mDirectory.getPath().equals(item.getPath())) {
|
||||
refresh();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ class ExplorerItemManager(private val mContext: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
private fun <T> remove(list: ArrayList<*>, o: T): Int {
|
||||
private fun <T> remove(list: ArrayList<T>, o: T): Int {
|
||||
return list.indexOf(o).also { i ->
|
||||
list.takeUnless { i < 0 }?.removeAt(i)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user