Skip to content

Commit

Permalink
add autosave
Browse files Browse the repository at this point in the history
  • Loading branch information
PangBaiWork committed Jun 10, 2024
1 parent 25fe309 commit 912c6d4
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 18 deletions.
20 changes: 20 additions & 0 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"version": 3,
"artifactType": {
"type": "APK",
"kind": "Directory"
},
"applicationId": "com.pangbai.weblog",
"variantName": "release",
"elements": [
{
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 3,
"versionName": "1.2",
"outputFile": "app-release.apk"
}
],
"elementType": "File"
}
Binary file modified app/src/main/assets/env.tar.xz
Binary file not shown.
14 changes: 12 additions & 2 deletions app/src/main/java/com/pangbai/weblog/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,12 @@ protected void onCreate(Bundle savedInstanceState) {
binding.editor.setText("No file be Displayed\n" + getString(R.string.how_to_open_terminal));

}
List<String> init=new ArrayList<>(){{add("Init.sh");}};
executeStateControl.runScripts(init);
if (Config.getBool(PrefManager.Keys.bl_script_init)) {
List<String> init = new ArrayList<>() {{
add("Init.sh");
}};
executeStateControl.runScripts(init);
}



Expand Down Expand Up @@ -153,6 +157,7 @@ void setEditor() {
binding.executionStatus.setVisibility(View.VISIBLE);
binding.editSymbolParent.setVisibility(View.GONE);
//keyboard down
if (Config.getBool(PrefManager.Keys.bl_editor_autosave))saveFile();
view.setVisibility(View.VISIBLE);
}
});
Expand All @@ -175,6 +180,9 @@ void setEditor() {
});





}

public void setCodeText(File file) {
Expand Down Expand Up @@ -365,11 +373,13 @@ public void onWindowFocusChanged(boolean hasFocus) {
} else {
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING);
}
if (Config.getBool(PrefManager.Keys.bl_editor_autosave))saveFile();
super.onWindowFocusChanged(hasFocus);
}

@Override
protected void onDestroy() {
if (Config.getBool(PrefManager.Keys.bl_editor_autosave))saveFile();
//binding.editor.setEditorLanguage(null);
if (binding!=null) {
binding.editor.release();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public enum Keys {
first_launch_mark,
bl_interface_undo_button_display,
bl_artical_title_to_md5,
bl_editor_autosave,
bl_script_init

}

Expand All @@ -41,6 +43,7 @@ public static boolean isFirstOrReinstall(Context context) {
if (!mark.equals(marked)) {
putString(Keys.first_launch_mark,mark);
isFirstOrReinstall_flag=marked.equals(defaults)?1:2;
// 1 for first install,2 for reinstall
return true;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/pangbai/weblog/tool/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ public static boolean copyFileOrFolder(File source, String target) {
return result == 0;
}

public static boolean deleteFileOrFolder(File folder) {
int result = cmdExer.execute("rm -rf " + folder.getAbsolutePath(), false);
public static boolean deleteFileOrFolder(String path) {
int result = cmdExer.execute("rm -rf " + path, false);
return result == 0;
}

Expand Down
15 changes: 7 additions & 8 deletions app/src/main/java/com/pangbai/weblog/tool/Init.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Init(Activity ct) {



if (PrefManager.isFirstOrReinstall_flag==1) {
if (PrefManager.isFirstOrReinstall_flag!=0) {
//First installation
dialog = DialogUtils.showLoadingDialog(ct, ct.getString(R.string.load_resources));
ThreadUtil.thread(() -> {
Expand All @@ -96,8 +96,8 @@ public Init(Activity ct) {
result = false;
}

if (PrefManager.isFirstOrReinstall_flag==1) initScript(ct);

initScript(ct);
dialog.dismiss();
util.runOnUiThread(() -> {
if (result)
Expand All @@ -122,18 +122,15 @@ public Init(Activity ct) {
}
);

} else if (PrefManager.isFirstOrReinstall_flag==2) {
//reinstalltion in case of test and update
initScript(ct);
checkPermission(ct);
}


}

@SuppressLint("SuspiciousIndentation")
boolean installEnv(Context context) throws IOException, InterruptedException {
// String name = "busybox";
IO.deleteFileOrFolder(filesDirPath+"/usr");
//new File(filesDirPath).mkdirs();
IO.copyAssetsDirToSDCard(context, "busybox", binDir);
IO.copyAssetsDirToSDCard(context, "libexec.so", libDir);
new File(busyboxPath).setExecutable(true);
Expand Down Expand Up @@ -186,10 +183,12 @@ void initScript(Context context) {
void installHexo(Activity ct) {
ThreadUtil.thread(() -> {
cmdExer.execute("npm config set registry https://npmreg.proxy.ustclug.org", false);
cmdExer.execute("npm config set ignore-scripts true" ,false);
cmdExer.execute("npm config set bin-links false",false);
boolean result = cmdExer.execute("npm install -g hexo-cli", false) == 0;
dialog.dismiss();
util.runOnUiThread(() -> {
Toast.makeText(ct, result ? "Success" : "Failed", Toast.LENGTH_SHORT).show();
Toast.makeText(ct, result ? "Success" : "Failed to install hexo", Toast.LENGTH_SHORT).show();
checkPermission(ct);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Holder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
@Override
public void run() {
// use shell to delete for better speed
IO.deleteFileOrFolder(targetFile);
IO.deleteFileOrFolder(targetFile.getAbsolutePath());
util.runOnUiThread(() -> {
setList(Objects.requireNonNull(targetFile.getParentFile()));
});
Expand Down
30 changes: 25 additions & 5 deletions app/src/main/res/xml/header_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@
app:summaryOn="Always visible"
app:icon="@drawable/ic_file_previous"
app:title="Undo float action button" />
<EditTextPreference
app:key="interface_font"
app:summary="Custom Font"
android:dialogTitle="Please input font Path"
app:title="Set Font"/>


</PreferenceCategory>
<PreferenceCategory app:title="Artical">
Expand All @@ -24,6 +20,30 @@
app:icon="@drawable/ic_setting_markdown"
app:title="Convert the file name to md5" />
</PreferenceCategory>

<PreferenceCategory app:title="Scripts">
<SwitchPreferenceCompat
android:defaultValue="true"
app:key="bl_script_init"
app:summaryOff="Execute initialization script Init.sh"
app:summaryOn="Execute initialization script Init.sh"
app:icon="@drawable/ic_script"
app:title="Init.sh" />
</PreferenceCategory>

<PreferenceCategory app:title="Editor">
<EditTextPreference
app:key="interface_font"
app:summary="Custom Font"
android:dialogTitle="Please input font Path"
app:title="set font"/>
<SwitchPreferenceCompat
android:defaultValue="true"
app:key="bl_editor_autosave"
app:summaryOff="Automatically save files in the editor"
app:summaryOn="Automatically save files in the editor"
app:title="auto save" />
</PreferenceCategory>
<!--
<Preference
app:fragment="com.pangbai.weblog.activity.SettingsActivity$MessagesFragment"
Expand Down

0 comments on commit 912c6d4

Please sign in to comment.