Skip to content

Commit

Permalink
Merge pull request #792 from LYS86/dev-test
Browse files Browse the repository at this point in the history
修复bug
  • Loading branch information
kkevsekk1 authored Jan 14, 2024
2 parents 3a01a08 + c6dd536 commit 763a220
Show file tree
Hide file tree
Showing 10 changed files with 141 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ public static void viewContent(Context context, String name, String content, boo
private static Intent newIntent(Context context, boolean newTask) {
Intent intent = new Intent(context, EditActivity_.class);
if (newTask || !(context instanceof Activity)) {
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// 添加 FLAG_ACTIVITY_CLEAR_TASK 标志
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
}
return intent;
}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/org/autojs/autojs/ui/edit/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@

import java.io.File;
import java.util.List;
import java.util.Objects;

import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
Expand Down Expand Up @@ -657,8 +658,11 @@ public void onHintClick(CodeCompletions completions, int pos) {
@Override
public void onHintLongClick(CodeCompletions completions, int pos) {
CodeCompletion completion = completions.get(pos);
if (completion.getUrl() == null)
if (Objects.equals(completion.getHint(), "/")) {
getEditor().toggleComment();
return;
}
if (completion.getUrl() == null) return;
showManual(completion.getUrl(), completion.getHint());
}

Expand Down
35 changes: 35 additions & 0 deletions app/src/main/java/org/autojs/autojs/ui/edit/editor/CodeEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.content.Context;
import android.graphics.Canvas;
import android.text.Editable;
import android.text.Layout;
import android.util.AttributeSet;
import android.view.MotionEvent;
Expand All @@ -20,6 +21,7 @@
import org.autojs.autoxjs.R;

import java.util.LinkedHashMap;
import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
Expand Down Expand Up @@ -155,10 +157,15 @@ public void deleteLine() {

public void jumpToStart() {
mCodeEditText.setSelection(0);
smoothScrollTo(0, 0);
}

public void jumpToEnd() {
mCodeEditText.setSelection(mCodeEditText.getText().length());

int lastLine = mCodeEditText.getLayout().getLineCount() - 1;
int lineTop = mCodeEditText.getLayout().getLineTop(lastLine);
smoothScrollTo(0, lineTop);
}

public void jumpToLineStart() {
Expand Down Expand Up @@ -218,6 +225,9 @@ public void jumpTo(int line, int col) {
return;
}
mCodeEditText.setSelection(mCodeEditText.getLayout().getLineStart(line) + col);

int lineTop = mCodeEditText.getLayout().getLineTop(line);
smoothScrollTo(0, lineTop);
}

public void setReadOnly(boolean readOnly) {
Expand Down Expand Up @@ -454,9 +464,34 @@ public Breakpoint(int line) {
}
}

public void toggleComment() {
final String COMMENT_PREFIX = "//";
Editable editText = Objects.requireNonNull(mCodeEditText.getText());
int selectionStart = mCodeEditText.getSelectionStart();
int selectionEnd = mCodeEditText.getSelectionEnd();

int startLine = LayoutHelper.getLineOfChar(mCodeEditText.getLayout(), selectionStart);
int endLine = LayoutHelper.getLineOfChar(mCodeEditText.getLayout(), selectionEnd);

for (int currentLine = startLine; currentLine <= endLine; currentLine++) {
int lineStart = mCodeEditText.getLayout().getLineStart(currentLine);
int lineEnd = mCodeEditText.getLayout().getLineEnd(currentLine);

String currentLineText = editText.toString().substring(lineStart, lineEnd);
String modifiedLineText = currentLineText.replaceAll("^\\s*(/{2,})", "");

if (!currentLineText.trim().startsWith(COMMENT_PREFIX)) {
modifiedLineText = COMMENT_PREFIX + modifiedLineText;
}

editText.replace(lineStart, lineEnd, modifiedLineText);
}
}

public interface BreakpointChangeListener {
void onBreakpointChange(int line, boolean enabled);

void onAllBreakpointRemoved(int count);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,6 @@ private fun ProjectAddress(context: Context) {

@Composable
private fun CheckForUpdate(model: DrawerViewModel = viewModel()) {
val context = LocalContext.current
var showDialog by rememberSaveable {
mutableStateOf(false)
}
Expand Down Expand Up @@ -250,10 +249,9 @@ private fun CheckForUpdate(model: DrawerViewModel = viewModel()) {
}
},
confirmButton = {
val url = DOWNLOAD_ADDRESS
TextButton(onClick = {
showDialog = false
IntentUtil.browse(context, url)
model.downloadApk()
}) {
Text(text = stringResource(id = R.string.text_download))
}
Expand Down
111 changes: 81 additions & 30 deletions app/src/main/java/org/autojs/autojs/ui/main/drawer/DrawerViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,34 @@
package org.autojs.autojs.ui.main.drawer

import android.app.Application
import android.app.DownloadManager
import android.content.Context
import android.net.Uri
import android.os.Build
import android.widget.Toast
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.setValue
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import org.autojs.autoxjs.R
import kotlinx.coroutines.withContext
import org.autojs.autojs.Pref
import org.autojs.autojs.network.VersionService2
import org.autojs.autojs.network.entity.GithubReleaseInfo
import org.autojs.autojs.network.entity.isLatestVersion
import org.autojs.autoxjs.R
import java.io.File

class DrawerViewModel(private val context: Application) : AndroidViewModel(context) {

var githubReleaseInfo by mutableStateOf<GithubReleaseInfo?>(null)
private set

fun checkUpdate(onUpdate: () -> Unit = {},onComplete: () -> Unit = {}) {
fun checkUpdate(onUpdate: () -> Unit = {}, onComplete: () -> Unit = {}) {
kotlin.runCatching { }
Toast.makeText(
context,
context.getString(R.string.text_checking_for_updates),
Toast.LENGTH_SHORT
).show()
showToast(context.getString(R.string.text_checking_for_updates))
viewModelScope.launch {
try {
var releaseInfo = VersionService2.gitUpdateCheckApi.getGithubLastReleaseInfo()
Expand All @@ -33,54 +37,101 @@ class DrawerViewModel(private val context: Application) : AndroidViewModel(conte
if (isLatestVersion == null) {
//Get release list
VersionService2.gitUpdateCheckApi.getGithubReleaseInfoList()
.firstOrNull { it.targetCommitish == "dev-test" && !it.prerelease }
?.let {
.firstOrNull { it.targetCommitish == "dev-test" && !it.prerelease }?.let {
releaseInfo = it
isLatestVersion = releaseInfo.isLatestVersion()
}
}
if (isLatestVersion == null) {
//Can't find information
versionInformationNotFound()
showToast(
context.getString(
R.string.text_check_update_error,
context.getString(R.string.text_update_information_not_found)
)
)
return@launch
}
if (isLatestVersion == true) {
//is the latest version
Toast.makeText(
context,
context.getString(R.string.text_is_latest_version),
Toast.LENGTH_SHORT
).show()
showToast(context.getString(R.string.text_is_latest_version))
} else {
//new version
githubReleaseInfo = releaseInfo
onUpdate()
}
} catch (e: Exception) {
e.printStackTrace()
Toast.makeText(
context,
showToast(
context.getString(
R.string.text_check_update_error,
e.localizedMessage ?: ""
),
Toast.LENGTH_SHORT
).show()
}finally {
)
)
} finally {
onComplete()
}
}

}

private fun versionInformationNotFound() {
Toast.makeText(
context,
context.getString(
R.string.text_check_update_error,
context.getString(R.string.text_update_information_not_found)
),
Toast.LENGTH_SHORT
).show()

private fun getApkNameAndDownloadLink(): Pair<String, String?> {
val specificAsset = githubReleaseInfo?.assets?.firstOrNull {
it.browserDownloadUrl.contains(
getUserArch(), ignoreCase = true
)
}

return Pair(
specificAsset?.name.orEmpty(), specificAsset?.browserDownloadUrl ?: getUniversalLink()
)
}

private fun getUserArch(): String {
return Build.SUPPORTED_ABIS.firstOrNull().orEmpty()
}

private fun getUniversalLink(): String {
return githubReleaseInfo?.assets?.firstOrNull {
it.browserDownloadUrl.contains(
"universal", ignoreCase = true
)
}?.browserDownloadUrl.orEmpty()
}

fun downloadApk() {
val (fileName, url) = getApkNameAndDownloadLink()
val filePath = File(Pref.getScriptDirPath(), fileName).path
val downloadManager =
context.getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager
val file = File(filePath)
if (file.exists()) {
showToast("文件已存在:$fileName")
return
}

val request = DownloadManager.Request(Uri.parse(url)).setTitle(fileName).setDescription(url)
.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED)
.setDestinationUri(Uri.fromFile(file))

viewModelScope.launch {
try {
withContext(Dispatchers.IO) {
downloadManager.enqueue(request)
}
showToast("正在下载$fileName")
} catch (e: Exception) {
e.printStackTrace()
showToast("下载出错: ${e.localizedMessage}")

}
}

}

private fun showToast(message: String) {
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
}

}
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_debug_toolbar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
android:id="@+id/resume_script"
android:layout_width="40dp"
android:layout_height="match_parent"
app:icon_color="@android:color/white"
app:icon="@drawable/ic_play_fill"
app:text="@string/text_debug_resume_script"/>

Expand Down
10 changes: 5 additions & 5 deletions autojs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ dependencies {
// libs
api(fileTree("../app/libs"){include("dx.jar", "rhino-1.7.14-jdk7.jar")})
api("cz.adaptech:tesseract4android:4.1.1")
api("com.google.mlkit:text-recognition:16.0.0-beta5")
api("com.google.mlkit:text-recognition-chinese:16.0.0-beta5")
api("com.google.mlkit:text-recognition-devanagari:16.0.0-beta5")
api("com.google.mlkit:text-recognition-japanese:16.0.0-beta5")
api("com.google.mlkit:text-recognition-korean:16.0.0-beta5")
api(libs.text.recognition)
api(libs.text.recognition.chinese)
api(libs.text.recognition.devanagari)
api(libs.text.recognition.japanese)
api(libs.text.recognition.korean)
}

6 changes: 3 additions & 3 deletions autojs/src/main/assets/modules/__console__.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ module.exports = function (runtime, scope) {

console.rawInput = rtConsole.rawInput.bind(rtConsole);

console.input = function (data, param) {
return eval(console.rawInput.call(console, [].slice(arguments)) + "");
}
console.input = function () {
return eval(console.rawInput.apply(console, arguments) + '');
};

console.log = function () {
rtConsole.log(util.format.apply(util, arguments));
Expand Down
2 changes: 1 addition & 1 deletion autojs/src/main/assets/modules/__dialogs__.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ module.exports = function(__runtime__, scope){
input = input.toString();
builder.dialog.emit("input_change", builder.dialog, input);
})
.alwaysCallInputCallback();
// .alwaysCallInputCallback();
}
if(properties.items != undefined){
var itemsSelectMode = properties.itemsSelectMode;
Expand Down
7 changes: 7 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ espresso-core = "3.5.1"
appcompat = "1.4.2"
material = "1.9.0"
accompanist-version = "0.24.13-rc"
text-recognition = "16.0.0-beta6"
text-recognition-chinese = "16.0.0"

[libraries]

Expand Down Expand Up @@ -75,6 +77,11 @@ material = { group = "com.google.android.material", name = "material", version.r
andserver-processor = { module = "com.yanzhenjie.andserver:processor", version.ref = "andserver" }
andserver-api = { module = "com.yanzhenjie.andserver:api", version.ref = "andserver" }
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version = "2.1.4" }
text-recognition = { module = "com.google.mlkit:text-recognition", version.ref = "text-recognition" }
text-recognition-chinese = { module = "com.google.mlkit:text-recognition-chinese", version.ref = "text-recognition-chinese" }
text-recognition-korean = { module = "com.google.mlkit:text-recognition-korean", version.ref = "text-recognition" }
text-recognition-japanese = { module = "com.google.mlkit:text-recognition-japanese", version.ref = "text-recognition" }
text-recognition-devanagari = { module = "com.google.mlkit:text-recognition-devanagari", version.ref = "text-recognition" }
[plugins]

[bundles]
Expand Down

0 comments on commit 763a220

Please sign in to comment.