Skip to content

Commit

Permalink
change env install, add feature : search text
Browse files Browse the repository at this point in the history
  • Loading branch information
PangBaiWork committed Feb 28, 2024
1 parent e9dc699 commit ae452f8
Show file tree
Hide file tree
Showing 113 changed files with 338 additions and 203 deletions.
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {
}
defaultConfig {
applicationId "com.pangbai.weblog"
minSdk 24
minSdk 26
//noinspection EditedTargetSdkVersion
targetSdk 34
ndkVersion "24.0.8215888"
Expand Down Expand Up @@ -80,6 +80,7 @@ android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
// isCoreLibraryDesugaringEnabled true
// kotlinCompilerExtensionVersion = "1.1.1"

}
Expand Down Expand Up @@ -113,9 +114,8 @@ dependencies {

implementation(platform("io.github.Rosemoe.sora-editor:bom:0.22.1"))
implementation("io.github.Rosemoe.sora-editor:editor")

implementation("io.github.Rosemoe.sora-editor:language-textmate")

// coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
// implementation("androidx.appcompat:appcompat:1.6.1")

implementation project(path: ':markdownView')
Expand Down
Binary file added app/src/main/assets/busybox
Binary file not shown.
Binary file not shown.
Binary file added app/src/main/assets/libexec.so
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public SuperTerminalView(Context context, AttributeSet attributes) {
}

public void setTerminal(String cwd) {
String[] n = {"sh"};
// Log.e("weblog",path);
setProcess(Init.busyboxPath, cwd, n, Init.envp, 0);
String[] n = {Init.linker,Init.busyboxPath,"sh"};
setProcess(Init.linker, cwd, n,Init.envp, 0);
// setProcess(Init.shell, cwd, null,new String[]{ "PATH=" + Init.binDir}, 0);
runProcess();
//cmdView.requestFocus();
}
Expand Down
53 changes: 41 additions & 12 deletions app/src/main/java/com/pangbai/weblog/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.search.SearchView;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;

import com.pangbai.weblog.R;
import com.pangbai.weblog.databinding.ActivityMainBinding;
import com.pangbai.weblog.databinding.FileListBinding;
import com.pangbai.weblog.databinding.LayoutTerminalBinding;
import com.pangbai.weblog.editor.SearchHandle;
import com.pangbai.weblog.editor.TextMate;
import com.pangbai.weblog.execute.BlogCmd;
import com.pangbai.weblog.execute.HexoExer;
Expand Down Expand Up @@ -62,8 +64,12 @@

import br.tiagohm.markdownview.MarkdownView;
import br.tiagohm.markdownview.css.styles.Github;
import io.github.rosemoe.sora.event.EventReceiver;
import io.github.rosemoe.sora.event.PublishSearchResultEvent;
import io.github.rosemoe.sora.event.Unsubscribe;
import io.github.rosemoe.sora.text.Content;
import io.github.rosemoe.sora.text.ContentIO;
import io.github.rosemoe.sora.widget.EditorSearcher;


public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
Expand All @@ -76,6 +82,7 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
Project project;
Process livePreview;
FilesListAdapter filesListAdapter;
SearchHandle handle;

@SuppressLint("ResourceType")
@Override
Expand Down Expand Up @@ -145,6 +152,7 @@ void setEditor() {
}

void setCodeText(File file) {
handle.stopSearch();
TextMate.setLanguage(binding.editor, file.getName());
ThreadUtil.thread(() -> {
try {
Expand Down Expand Up @@ -172,9 +180,9 @@ void setLayout() {
binding.drawerLayout.addDrawerListener(new DrawerAnim(binding.navigationView));


//状态栏中的文字颜色和图标颜色,需要android系统6.0以上,而且目前只有一种可以修改(一种是深色,一种是浅色即白色)
//修改为深色,因为我们把状态栏的背景色修改为主题色白色,默认的文字及图标颜色为白色,导致看不到了。

/// SearchHandle search= (SearchHandle) ((MenuItem) binding.toolbar.findViewById(R.id.menu_search)).getActionView();
handle= new SearchHandle(binding.editor.getSearcher());
handle.bind(binding.searchBar);

binding.toolbar.setOnMenuItemClickListener(item -> {

Expand All @@ -192,8 +200,8 @@ void setLayout() {
binding.progressbar.setIndeterminate(false);
if (cmd) {
Snackbar.make(binding.getRoot(), "Success", Snackbar.LENGTH_SHORT).show();
}else {
DialogUtils.showConfirmationDialog(this,getString(R.string.scripts_execution_failed),cmdExer.result,null,null);
} else {
DialogUtils.showConfirmationDialog(this, getString(R.string.scripts_execution_failed), cmdExer.result, null, null);
}
});
});
Expand All @@ -208,6 +216,23 @@ void setLayout() {
binding.editor.redo();
} else if (id == R.id.menu_save) {
saveFile();
} else if (id == R.id.menu_search) {

DialogUtils.showInputDialog(this, getString(R.string.search_in_editor), userInput -> {
binding.searchBar.getRoot().setVisibility(View.GONE);
binding.editor.getSearcher().search(userInput, new EditorSearcher.SearchOptions(true, true));
binding.progressbar.setIndeterminate(true);
binding.editor.subscribeEvent(PublishSearchResultEvent.class, (event, unsubscribe) -> {
if (!handle.isSearching())
return;
binding.progressbar.setIndeterminate(false);
if (event.getSearcher().getMatchedPositionCount() == 0) {
Snackbar.make(binding.getRoot(), "Text not found", Snackbar.LENGTH_SHORT).show();
} else {
binding.searchBar.getRoot().setVisibility(View.VISIBLE);
}
});
});
}
return false;
});
Expand Down Expand Up @@ -384,14 +409,14 @@ public boolean onNavigationItemSelected(@NonNull MenuItem item) {
util.startActivity(this, HomeActivity.class, false);
finish();
} else if (id == R.id.global_setting) {
util.startActivity(this, SettingsActivity.class,false);
util.startActivity(this, SettingsActivity.class, false);
} else if (id == R.id.global_env) {
Snackbar.make(binding.navigationView, "Checking", Snackbar.LENGTH_SHORT).show();
Snackbar.make(binding.navigationView, "Checking", Snackbar.LENGTH_SHORT).show();
ThreadUtil.thread(() -> {
String res= BlogCmd.checkEnvironment();
runOnUiThread(() -> {
DialogUtils.showConfirmationDialog(this,getString(R.string.environment),res,null,null);
});
String res = BlogCmd.checkEnvironment();
runOnUiThread(() -> {
DialogUtils.showConfirmationDialog(this, getString(R.string.environment), res, null, null);
});
});
}
return false;
Expand All @@ -415,5 +440,9 @@ void checkProcess(MenuItem item) {

}


@Override
protected void onDestroy() {
binding.editor.release();
super.onDestroy();
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/pangbai/weblog/editor/SearchHandle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.pangbai.weblog.editor;

import android.content.Context;
import android.view.View;

import com.google.android.material.snackbar.Snackbar;
import com.pangbai.weblog.R;
import com.pangbai.weblog.databinding.EditorSearcherBinding;
import com.pangbai.weblog.tool.DialogUtils;

import io.github.rosemoe.sora.widget.EditorSearcher;

public class SearchHandle implements View.OnClickListener {
EditorSearcherBinding binding;
EditorSearcher searcher;

public SearchHandle( EditorSearcher searcher){
this.searcher=searcher;
}
public void bind( EditorSearcherBinding binding){
this.binding=binding;
binding.searchNext.setOnClickListener(this);
binding.searchPrevious.setOnClickListener(this);
binding.searchReplace.setOnClickListener(this);
binding.searchClose.setOnClickListener(this);

}


@Override
public void onClick(View v) {
if (v==binding.searchPrevious){
searcher.gotoPrevious();
} else if (v==binding.searchNext) {
searcher.gotoNext();
} else if (v==binding.searchClose) {
stopSearch();
} else if (v==binding.searchReplace) {
Context context=binding.getRoot().getContext();
DialogUtils.showInputDialog(context, context.getString(R.string.search_replace),userInput -> {
if (userInput==null)
userInput="";
searcher.replaceAll(userInput, () -> {
Snackbar.make(binding.getRoot(),"Replacement successful",Snackbar.LENGTH_SHORT).show();
});
});

}
}

public void stopSearch(){
binding.getRoot().setVisibility(View.GONE);
if (searcher.hasQuery())
searcher.stopSearch();
}
public boolean isSearching(){
return searcher.hasQuery();
}

}
11 changes: 6 additions & 5 deletions app/src/main/java/com/pangbai/weblog/execute/cmdExer.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static int execute(String command, boolean su, boolean wait) {
shell = "sh";

ProcessBuilder processBuilder = new ProcessBuilder();
Map<String, String> environment = processBuilder.environment();
// Map<String, String> environment = processBuilder.environment();
if (cwd != null)
processBuilder.directory(new File(cwd));
for (String env : Init.envp) {
Expand All @@ -59,20 +59,21 @@ public static int execute(String command, boolean su, boolean wait) {
// 设置环境变量
// environment.put("LD_LIBRARY_PATH", Init.filesDirPath + "/usr/lib");

processBuilder.command(shell, "-c", command);
processBuilder.command(Init.linker,Init.busyboxPath,shell, "-c",command);
processBuilder.redirectErrorStream(true);
try {

try {

process = processBuilder.start();
process = processBuilder.start();
if (!wait)
return 0;
reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
Log.e("exer", line);

result += line + "\n";
lastLine = line;
Log.e("exer", line);
}

return process.waitFor();
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/com/pangbai/weblog/tool/IO.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,17 @@ public static void copyAssetsDirToSDCard(Context context, String assetsDirName,
// finalByte= inputStream.available();
byte[] mByte = new byte[1024];
int bt = 0;
File file = new File(sdCardPath + File.separator + assetsDirName.substring(assetsDirName.lastIndexOf('/')));

int index=assetsDirName.lastIndexOf('/');
File file;
if (index!=-1) {
file = new File(sdCardPath + File.separator + assetsDirName.substring(index));
}else {
file = new File(sdCardPath + File.separator + assetsDirName);
}
File dir=new File(sdCardPath);
if (!dir.exists())dir.mkdirs();
if (!file.exists()) {
file.createNewFile();
} else {
return;
}
FileOutputStream fos = new FileOutputStream(file);
while ((bt = inputStream.read(mByte)) != -1) {
Expand Down
Loading

0 comments on commit ae452f8

Please sign in to comment.