Skip to content

Commit

Permalink
Merge pull request #712 from aiselp/editor2
Browse files Browse the repository at this point in the history
添加新编辑器
  • Loading branch information
kkevsekk1 authored Nov 4, 2023
2 parents 575b355 + 32c4d11 commit 70b79b3
Show file tree
Hide file tree
Showing 34 changed files with 1,139 additions and 61 deletions.
21 changes: 7 additions & 14 deletions apkbuilder/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,14 @@ android {
}

dependencies {
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("androidx.core:core-ktx:1.8.0")
}
dependencies {
testImplementation("org.springframework.boot:spring-boot-starter-test") {
exclude("junit", "junit")
}
androidTestImplementation("androidx.test.espresso:espresso-core:3.1.1-alpha01") {
exclude(group = "com.android.support", module = "support-annotations")
}
testImplementation("junit:junit:4.13.2")
api(fileTree("libs") { include("*.jar") })

implementation(libs.okhttp)
androidTestImplementation(libs.androidx.test.ext.junit)
androidTestImplementation(libs.espresso.core)
testImplementation(libs.junit)
api(files("libs/tiny-sign-0.9.jar"))
api(files("libs/commons-io-2.5.jar"))
implementation("androidx.core:core-ktx:1.8.0")
api(libs.commons.io)
implementation(libs.core.ktx)
}
repositories {
mavenCentral()
Expand Down
Binary file removed apkbuilder/libs/commons-io-2.5.jar
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.stardust.autojs.apkbuilder;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -19,7 +19,7 @@ public class ExampleInstrumentedTest {
@Test
public void useAppContext() throws Exception {
// Context of the app under test.
Context appContext = InstrumentationRegistry.getTargetContext();
Context appContext = InstrumentationRegistry.getInstrumentation().getContext();

assertEquals("com.stardust.autojs.apkbuilder.test", appContext.getPackageName());
}
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ dependencies {
//MultiLevelListView
implementation("com.github.hyb1996:android-multi-level-listview:1.1")
//Licenses Dialog
implementation("de.psdev.licensesdialog:licensesdialog:1.9.0")
implementation("de.psdev.licensesdialog:licensesdialog:2.2.0")
//Expandable RecyclerView
implementation("com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1")
//FlexibleDivider
Expand Down Expand Up @@ -282,6 +282,7 @@ dependencies {
implementation(project(":common"))
implementation(project(":autojs"))
implementation(project(":apkbuilder"))
implementation(project(":codeeditor"))
implementation("androidx.multidex:multidex:2.0.1")

val lifecycle_version = "2.5.1"
Expand Down
18 changes: 13 additions & 5 deletions app/src/main/java/org/autojs/autojs/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.autojs.autojs.ui.main
import android.Manifest
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.widget.Toast
import androidx.activity.compose.setContent
Expand All @@ -24,6 +25,7 @@ import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.widget.ViewPager2
import com.aiselp.autojs.codeeditor.EditActivity
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import com.google.accompanist.systemuicontroller.rememberSystemUiController
Expand All @@ -47,10 +49,9 @@ import org.autojs.autojs.ui.main.components.LogButton
import org.autojs.autojs.ui.main.drawer.DrawerPage
import org.autojs.autojs.ui.main.scripts.ScriptListFragment
import org.autojs.autojs.ui.main.task.TaskManagerFragmentKt
import org.autojs.autojs.ui.main.web.WebViewFragment
import org.autojs.autojs.ui.main.web.EditorAppManager
import org.autojs.autojs.ui.widget.fillMaxSize
import org.autojs.autoxjs.R

data class BottomNavigationItem(val icon: Int, val label: String)

class MainActivity : FragmentActivity() {
Expand All @@ -62,7 +63,7 @@ class MainActivity : FragmentActivity() {

private val scriptListFragment by lazy { ScriptListFragment() }
private val taskManagerFragment by lazy { TaskManagerFragmentKt() }
private val webViewFragment by lazy { WebViewFragment() }
private val webViewFragment by lazy { EditorAppManager() }
private var lastBackPressedTime = 0L
private var drawerState: DrawerState? = null
private val viewPager: ViewPager2 by lazy { ViewPager2(this) }
Expand Down Expand Up @@ -142,7 +143,7 @@ fun MainPage(
activity: FragmentActivity,
scriptListFragment: ScriptListFragment,
taskManagerFragment: TaskManagerFragmentKt,
webViewFragment: WebViewFragment,
webViewFragment: EditorAppManager,
onDrawerState: (DrawerState) -> Unit,
viewPager: ViewPager2
) {
Expand Down Expand Up @@ -318,7 +319,7 @@ private fun TopBar(
requestOpenDrawer: () -> Unit,
onSearch: (String) -> Unit,
scriptListFragment: ScriptListFragment,
webViewFragment: WebViewFragment,
webViewFragment: EditorAppManager,
) {
var isSearch by remember {
mutableStateOf(false)
Expand Down Expand Up @@ -422,6 +423,13 @@ fun TopAppBarMenu(
NewFile(context, scriptListFragment, onDismissRequest)
ImportFile(context, scriptListFragment, onDismissRequest)
NewProject(context, scriptListFragment, onDismissRequest)
DropdownMenuItem(onClick = {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
context.startActivity(Intent(context,EditActivity::class.java))
}
}) {
Text(text = "打开新编辑器")
}
// DropdownMenuItem(onClick = { /*TODO*/ }) {
// MyIcon(
// painter = painterResource(id = R.drawable.ic_timed_task),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import org.autojs.autojs.ui.main.scripts.ScriptListFragment
import org.autojs.autojs.ui.main.task.TaskManagerFragmentKt
import org.autojs.autojs.ui.main.web.WebViewFragment
import org.autojs.autojs.ui.main.web.EditorAppManager

class ViewPager2Adapter(
fragmentActivity: FragmentActivity,
private val scriptListFragment: ScriptListFragment,
private val taskManagerFragment: TaskManagerFragmentKt,
private val webViewFragment: WebViewFragment
private val webViewFragment: EditorAppManager
) : FragmentStateAdapter(fragmentActivity) {

override fun createFragment(position: Int): Fragment {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.autojs.autojs.ui.main.scripts

import android.content.Context
import android.os.Build
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -25,6 +26,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.viewinterop.AndroidView
import androidx.fragment.app.Fragment
import androidx.preference.PreferenceManager
import com.aiselp.autojs.codeeditor.EditActivity
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.leinardi.android.speeddial.compose.FabWithLabel
import com.leinardi.android.speeddial.compose.SpeedDial
Expand All @@ -46,6 +48,7 @@ import org.autojs.autojs.ui.main.showExternalStoragePermissionToast
import org.autojs.autojs.ui.viewmodel.ExplorerItemList.SortConfig
import org.autojs.autojs.ui.widget.fillMaxSize
import org.autojs.autoxjs.R
import java.io.File

/**
* Created by wilinz on 2022/7/15.
Expand Down Expand Up @@ -237,7 +240,9 @@ class ScriptListFragment : Fragment() {
setOnItemClickListener { _, item ->
item?.let {
if (item.isEditable) {
edit(requireContext(), item.toScriptFile())
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
EditActivity.editFile(requireContext(), File(item.path))
} else edit(requireContext(), item.toScriptFile())
} else {
IntentUtil.viewFile(get(), item.path, AppFileProvider.AUTHORITY)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.autojs.autojs.ui.widget.SwipeRefreshWebView
import org.autojs.autojs.ui.widget.WebDataKt
import org.autojs.autojs.ui.widget.fillMaxSize

class WebViewFragment : Fragment() {
class EditorAppManager : Fragment() {

val swipeRefreshWebView by lazy { SwipeRefreshWebView(requireContext()) }

Expand Down
33 changes: 33 additions & 0 deletions app/src/main/java/org/autojs/autojs/ui/settings/LicenseInfo.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.autojs.autojs.ui.settings

import android.content.Context
import de.psdev.licensesdialog.LicenseResolver
import de.psdev.licensesdialog.licenses.License
import org.autojs.autoxjs.R

object LicenseInfo {
fun install(){
LicenseResolver.registerLicense(MozillaPublicLicense20())
}

}
class MozillaPublicLicense20 : License() {
override fun getName(): String {
return "Mozilla Public License 2.0"
}
override fun readSummaryTextFromResources(context: Context): String {
return getContent(context, R.raw.mpl_20_summary)
}

override fun readFullTextFromResources(context: Context): String {
return getContent(context, R.raw.mpl_20_full)
}

override fun getVersion(): String {
return "2.0"
}

override fun getUrl(): String {
return "https://www.mozilla.org/en-US/MPL/2.0/"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
@EActivity(R.layout.activity_settings)
public class SettingsActivity extends BaseActivity {

static {
LicenseInfo.INSTANCE.install();
}
private static final List<Pair<Integer, Integer>> COLOR_ITEMS = new ListBuilder<Pair<Integer, Integer>>()
.add(new Pair<>(R.color.theme_color_red, R.string.theme_color_red))
.add(new Pair<>(R.color.theme_color_pink, R.string.theme_color_pink))
Expand Down Expand Up @@ -140,7 +143,6 @@ public boolean onPreferenceTreeClick(Preference preference) {
}

private void showLicenseDialog() {
LicenseResolver.registerLicense(MozillaPublicLicense20.instance);
new LicensesDialog.Builder(getActivity())
.setNotices(R.raw.licenses)
.setIncludeOwnLicense(true)
Expand All @@ -158,35 +160,5 @@ private void showLicenseDialog2() {
.show();
}

public static class MozillaPublicLicense20 extends License {

public static MozillaPublicLicense20 instance = new MozillaPublicLicense20();

@Override
public String getName() {
return "Mozilla Public License 2.0";
}

@Override
public String readSummaryTextFromResources(Context context) {
return getContent(context, R.raw.mpl_20_summary);
}

@Override
public String readFullTextFromResources(Context context) {
return getContent(context, R.raw.mpl_20_full);
}

@Override
public String getVersion() {
return "2.0";
}

@Override
public String getUrl() {
return "https://www.mozilla.org/en-US/MPL/2.0/";
}
}

}
}
12 changes: 12 additions & 0 deletions app/src/main/res/raw/licenses.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,16 @@
<url>https://github.com/paddlepaddle/paddle</url>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>AndServer</name>
<copyright />
<url>https://github.com/yanzhenjie/AndServer/</url>
<license>Apache Software License 2.0</license>
</notice>
<notice>
<name>vscode-mobile</name>
<copyright/>
<url>https://github.com/aiselp/vscode-mobile</url>
<license>Apache Software License 2.0</license>
</notice>
</notices>
6 changes: 3 additions & 3 deletions autojs/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ dependencies {
testImplementation(libs.junit)
implementation(libs.documentfile)
implementation("androidx.preference:preference-ktx:1.2.0")
api("org.greenrobot:eventbus:3.3.1")
api(libs.eventbus)
api("net.lingala.zip4j:zip4j:1.3.2")
api("com.afollestad.material-dialogs:core:0.9.2.3"){
exclude(group = "com.android.support")
}
api("com.google.android.material:material:1.7.0-beta01")
api(libs.material)
api("com.github.hyb1996:EnhancedFloaty:0.31")
api("com.makeramen:roundedimageview:2.3.0")
// OkHttp
Expand All @@ -51,7 +51,7 @@ dependencies {
// RootShell
api("com.github.Stericson:RootShell:1.6")
// Gson
api("com.google.code.gson:gson:2.9.1")
api(libs.google.gson)
// log4j
api(group = "de.mindpipe.android", name = "android-logging-log4j", version = "1.0.3")
api(group = "log4j", name = "log4j", version = "1.2.17")
Expand Down
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ buildscript {
classpath(kotlin("gradle-plugin", version = "$kotlin_version"))
classpath("com.jakewharton:butterknife-gradle-plugin:10.2.3")
classpath("org.codehaus.groovy:groovy-json:3.0.8")
classpath("com.yanzhenjie.andserver:plugin:2.1.12")
}
}

Expand Down
2 changes: 2 additions & 0 deletions codeeditor/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/src/main/assets/codeeditor
Loading

0 comments on commit 70b79b3

Please sign in to comment.