fix: invalid project cause ProjectConfigActivity and ExplorerToolbar crash
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -11,4 +11,5 @@
|
|||||||
/captures
|
/captures
|
||||||
.externalNativeBuild
|
.externalNativeBuild
|
||||||
*.apk
|
*.apk
|
||||||
*.exe
|
*.exe
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import android.content.Context;
|
|||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import android.support.v7.widget.CardView;
|
import android.support.v7.widget.CardView;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
|
||||||
import android.widget.FrameLayout;
|
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
@@ -14,7 +11,6 @@ import com.stardust.autojs.project.ProjectConfig;
|
|||||||
import com.stardust.autojs.project.ProjectLauncher;
|
import com.stardust.autojs.project.ProjectLauncher;
|
||||||
import com.stardust.pio.PFile;
|
import com.stardust.pio.PFile;
|
||||||
|
|
||||||
import org.androidannotations.annotations.Click;
|
|
||||||
import org.autojs.autojs.R;
|
import org.autojs.autojs.R;
|
||||||
import org.autojs.autojs.autojs.AutoJs;
|
import org.autojs.autojs.autojs.AutoJs;
|
||||||
import org.autojs.autojs.model.explorer.ExplorerChangeEvent;
|
import org.autojs.autojs.model.explorer.ExplorerChangeEvent;
|
||||||
@@ -59,15 +55,19 @@ public class ExplorerProjectToolbar extends CardView {
|
|||||||
setOnClickListener(view -> edit());
|
setOnClickListener(view -> edit());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setProject(PFile dir, ProjectConfig config) {
|
public void setProject(PFile dir) {
|
||||||
|
mProjectConfig = ProjectConfig.fromProjectDir(dir.getPath());
|
||||||
|
if(mProjectConfig == null){
|
||||||
|
setVisibility(GONE);
|
||||||
|
return;
|
||||||
|
}
|
||||||
mDirectory = dir;
|
mDirectory = dir;
|
||||||
mProjectConfig = config;
|
mProjectName.setText(mProjectConfig.getName());
|
||||||
mProjectName.setText(config.getName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
if (mDirectory != null) {
|
if (mDirectory != null) {
|
||||||
setProject(mDirectory, ProjectConfig.fromProjectDir(mDirectory.getPath()));
|
setProject(mDirectory);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -111,7 +111,7 @@ public class ExplorerView extends ThemeColorSwipeRefreshLayout implements SwipeR
|
|||||||
mCurrentPageState = currentPageState;
|
mCurrentPageState = currentPageState;
|
||||||
if (mCurrentPageState.page instanceof ExplorerProjectPage) {
|
if (mCurrentPageState.page instanceof ExplorerProjectPage) {
|
||||||
mProjectToolbar.setVisibility(VISIBLE);
|
mProjectToolbar.setVisibility(VISIBLE);
|
||||||
mProjectToolbar.setProject(currentPageState.page.toScriptFile(), ((ExplorerProjectPage) currentPageState.page).getProjectConfig());
|
mProjectToolbar.setProject(currentPageState.page.toScriptFile());
|
||||||
} else {
|
} else {
|
||||||
mProjectToolbar.setVisibility(GONE);
|
mProjectToolbar.setVisibility(GONE);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import android.widget.ImageView;
|
|||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.stardust.autojs.project.ProjectConfig;
|
import com.stardust.autojs.project.ProjectConfig;
|
||||||
|
import com.stardust.autojs.runtime.api.Dialogs;
|
||||||
import com.stardust.pio.PFiles;
|
import com.stardust.pio.PFiles;
|
||||||
|
|
||||||
import org.androidannotations.annotations.AfterViews;
|
import org.androidannotations.annotations.AfterViews;
|
||||||
@@ -24,6 +25,7 @@ import org.autojs.autojs.model.explorer.ExplorerFileItem;
|
|||||||
import org.autojs.autojs.model.explorer.ExplorerItem;
|
import org.autojs.autojs.model.explorer.ExplorerItem;
|
||||||
import org.autojs.autojs.model.explorer.Explorers;
|
import org.autojs.autojs.model.explorer.Explorers;
|
||||||
import org.autojs.autojs.model.project.ProjectTemplate;
|
import org.autojs.autojs.model.project.ProjectTemplate;
|
||||||
|
import org.autojs.autojs.theme.dialog.ThemeColorMaterialDialogBuilder;
|
||||||
import org.autojs.autojs.ui.BaseActivity;
|
import org.autojs.autojs.ui.BaseActivity;
|
||||||
import org.autojs.autojs.ui.widget.SimpleTextWatcher;
|
import org.autojs.autojs.ui.widget.SimpleTextWatcher;
|
||||||
|
|
||||||
@@ -89,11 +91,21 @@ public class ProjectConfigActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
mDirectory = new File(dir);
|
mDirectory = new File(dir);
|
||||||
mProjectConfig = ProjectConfig.fromProjectDir(dir);
|
mProjectConfig = ProjectConfig.fromProjectDir(dir);
|
||||||
|
if (mProjectConfig == null) {
|
||||||
|
new ThemeColorMaterialDialogBuilder(this)
|
||||||
|
.title(R.string.text_invalid_project)
|
||||||
|
.positiveText(R.string.ok)
|
||||||
|
.dismissListener(dialogInterface -> finish())
|
||||||
|
.show();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@AfterViews
|
@AfterViews
|
||||||
void setupViews() {
|
void setupViews() {
|
||||||
|
if (mProjectConfig == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
setToolbarAsBack(mNewProject ? getString(R.string.text_new_project) : mProjectConfig.getName());
|
setToolbarAsBack(mNewProject ? getString(R.string.text_new_project) : mProjectConfig.getName());
|
||||||
if (mNewProject) {
|
if (mNewProject) {
|
||||||
mAppName.addTextChangedListener(new SimpleTextWatcher(s ->
|
mAppName.addTextChangedListener(new SimpleTextWatcher(s ->
|
||||||
|
|||||||
@@ -397,4 +397,5 @@
|
|||||||
<string name="text_project_location">项目位置</string>
|
<string name="text_project_location">项目位置</string>
|
||||||
<string name="text_new_project">新建项目</string>
|
<string name="text_new_project">新建项目</string>
|
||||||
<string name="text_js_file">js文件</string>
|
<string name="text_js_file">js文件</string>
|
||||||
|
<string name="text_invalid_project">无效项目</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user