Skip to content

Commit

Permalink
add ScriptsLogTextView,add Init.sh(execute at startup)
Browse files Browse the repository at this point in the history
  • Loading branch information
PangBaiWork committed May 1, 2024
1 parent 59588ee commit 00adc9e
Show file tree
Hide file tree
Showing 21 changed files with 541 additions and 257 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/scripts/hexo/Init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git status
1 change: 1 addition & 0 deletions app/src/main/assets/scripts/hugo/Init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
git status
3 changes: 1 addition & 2 deletions app/src/main/java/com/pangbai/terminal/TerminalSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ public TerminalEmulator getEmulator() {
}

/** Notify the {@link #mClient} that the screen has changed. */
private void notifyScreenUpdate() {
public void notifyScreenUpdate() {
mClient.onTextChanged(this);
}

Expand Down Expand Up @@ -388,7 +388,6 @@ public void handleMessage(Message msg) {
int bytesRead = mProcessToTerminalIOQueue.read(mReceiveBuffer, false);
if (bytesRead > 0) {
mEmulator.append(mReceiveBuffer, bytesRead);

notifyScreenUpdate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import com.pangbai.terminal.TerminalSessionClient;
import com.pangbai.weblog.tool.Init;

import java.nio.charset.StandardCharsets;

import br.tiagohm.markdownview.MarkdownView;


Expand Down Expand Up @@ -125,7 +127,9 @@ public boolean setProcess(String cmd, String cwd, String[] argv, String[] envp,
public void setKeyView(ExtraKeysView keys){
this.mkeys=keys;
}

public void executeInTerminal(String cmd){
mTerminalSession.writeDe(cmd);
}

public boolean runProcess() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public boolean deleteSurroundingText(int leftLength, int rightLength) {


//发送文本
void sendTextToTerminal(CharSequence text) {
public void sendTextToTerminal(CharSequence text) {
stopTextSelectionMode();
final int textLengthInChars = text.length();
for (int i = 0; i < textLengthInChars; i++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package com.pangbai.weblog.activity;

import android.view.View;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.tabs.TabLayout;
import com.pangbai.weblog.R;
import com.pangbai.weblog.databinding.ActivityMainBinding;
import com.pangbai.weblog.databinding.LayoutTerminalBinding;
import com.pangbai.weblog.view.MainViewPagerAdapter;

public class BottomTabControl extends BottomSheetBehavior.BottomSheetCallback implements TabLayout.OnTabSelectedListener {
TabLayout tabLayout;
ActivityMainBinding binding;
LayoutTerminalBinding cmdBinding;
BottomSheetBehavior behavior;

public BottomTabControl(ActivityMainBinding binding, LayoutTerminalBinding cmdBinding, MainViewPagerAdapter fragmentAdapter){
this.binding=binding;
this.tabLayout=binding.tabLayout;
this.cmdBinding=cmdBinding;
binding.viewpager.setAdapter(fragmentAdapter);

}
public void setup(){
//Repair pager content reconstruction
binding.viewpager.setOffscreenPageLimit(2);

// tabLayout跟viewpager关联
tabLayout.setupWithViewPager(binding.viewpager);

behavior = BottomSheetBehavior.from(binding.bottomSheet);
behavior.setHalfExpandedRatio(0.3F);
behavior.addBottomSheetCallback(this);
tabLayout.addOnTabSelectedListener(this);
}
@Override
public void onStateChanged(@NonNull View bottomSheet, int newState) {
if (newState == BottomSheetBehavior.STATE_COLLAPSED) {
binding.bottomBar.setVisibility(View.VISIBLE);
} else {
binding.bottomBar.setVisibility(View.GONE);
}
// focus on cmdview;
if (newState == BottomSheetBehavior.STATE_EXPANDED) {
if (tabLayout.getSelectedTabPosition() == 0) {
cmdBinding.terminal.requestFocus();
}
}
}

@Override
public void onSlide(@NonNull View bottomSheet, float slideOffset) {
}

@Override
public void onTabSelected(TabLayout.Tab tab) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
// focus on cmdview;
if (tab.getPosition() == 1) {
cmdBinding.terminal.requestFocus();
}
}

@Override
public void onTabUnselected(TabLayout.Tab tab) {
}

@Override
public void onTabReselected(TabLayout.Tab tab) {
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.pangbai.weblog.activity;

import static com.pangbai.weblog.tool.util.runOnUiThread;

import android.content.Context;
import android.renderscript.ScriptGroup;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.google.android.material.snackbar.Snackbar;
import com.pangbai.weblog.R;
import com.pangbai.weblog.databinding.ActivityMainBinding;
import com.pangbai.weblog.execute.cmdExer;
import com.pangbai.weblog.project.Project;
import com.pangbai.weblog.tool.DialogUtils;
import com.pangbai.weblog.tool.ThreadUtil;
import com.pangbai.weblog.tool.util;
import com.pangbai.weblog.view.ScriptsLogTextView;

import java.util.List;

public class ExecuteStateControl {
public enum executeStatus {
SUCCESSFUL ,
FAILED,
EXECUTING

}

ActivityMainBinding binding;
ScriptsLogTextView logTextView;
List<String> scripts;
Project project;

public ExecuteStateControl(ActivityMainBinding binding, ScriptsLogTextView logTextView, Project project) {
this.binding = binding;
this.logTextView = logTextView;
this.project=project;
}


void runScripts(List<String> scripts){
binding.progressbar.setIndeterminate(true);
binding.executionStatus.setText(executeStatus.EXECUTING+scripts.toString());
//Snackbar.make(binding.getRoot(), "Excuting", Snackbar.LENGTH_SHORT).show();
logTextView.appendScriptText(scripts);
ThreadUtil.thread(() -> {
boolean cmd = cmdExer.executeScripts(scripts, project.getScriptPath(), true) == 0;
runOnUiThread(() -> {

binding.progressbar.setIndeterminate(false);

logTextView.appendLogText(cmdExer.result);
if (cmd) {
binding.executionStatus.setText(executeStatus.SUCCESSFUL+scripts.toString());
// Snackbar.make(binding.getRoot(), "Success", Snackbar.LENGTH_SHORT).show();
} else {
Context context=binding.getRoot().getContext();
binding.executionStatus.setText(executeStatus.FAILED+scripts.toString());
DialogUtils.showConfirmationDialog(context, context.getString(R.string.scripts_execution_failed), cmdExer.result,context.getString(android.R.string.copy),context.getString(R.string.cancle), () -> {
util.copyToClipboard(context, cmdExer.result);}, null);
}
});
});
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ public void onClick(View v) {
AlertDialog dialog = DialogUtils.showLoadingDialog(this);
ThreadUtil.thread(() -> {
boolean clone = cmdExer.execute("git clone " + userInput + " " + file.getAbsolutePath(), false) == 0;
if (clone) {
boolean setSafeDir = cmdExer.execute("git config --global --add safe.directory " + file.getAbsolutePath(), false) == 0;
if (clone&&setSafeDir) {
ProjectManager.Type type = checkType(file);
if (type == null) {
runOnUiThread(() -> Snackbar.make(binding.getRoot(), "Is not a hexo or hugo project", Snackbar.LENGTH_SHORT).show());
Expand Down
Loading

0 comments on commit 00adc9e

Please sign in to comment.