Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
3.1.2-dev
Browse files Browse the repository at this point in the history
  • Loading branch information
mzdluo123 committed Apr 6, 2021
1 parent f97a26e commit 007a1a5
Show file tree
Hide file tree
Showing 9 changed files with 99 additions and 57 deletions.
10 changes: 6 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ apply plugin: 'kotlin-kapt'
apply plugin: 'kotlinx-serialization'


def CORE_VERSION = "2.5.1"
def CONSOLE_VERSION = "2.5.1"
def CORE_VERSION = "2.6-M2"
def CONSOLE_VERSION = "2.6-M2"
def LUAMIRAI_VERSION = "2.0.8"

android {
Expand All @@ -17,8 +17,8 @@ android {
applicationId "io.github.mzdluo123.mirai.android"
minSdkVersion 26
targetSdkVersion 30
versionCode 44
versionName "3.1.1"
versionCode 45
versionName "3.1.2-dev"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "COREVERSION", "\"$CORE_VERSION\"")
buildConfigField("String", "CONSOLEVERSION", "\"$CONSOLE_VERSION\"")
Expand Down Expand Up @@ -165,6 +165,8 @@ dependencies {
//test
implementation 'androidx.test.espresso:espresso-idling-resource:3.3.0'

implementation 'com.fanjun:keeplive:1.1.22'

// fuck!! 他不能在Android平台工作
// implementation 'org.codehaus.groovy:groovy:2.4.6:grooid'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ object AppSettings : Preferences("setting") {
var refreshPerMinute by IntPrefSaveAsStr("status_refresh_count", 15)
var startOnBoot by BoolPref("start_on_boot_preference", false)
var waitingDebugger by BoolPref("waiting_debugger_preference", false)

var keepLive by BoolPref("keeplive_preference", false)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Process
import com.fanjun.keeplive.KeepLive
import com.fanjun.keeplive.config.ForegroundNotification
import com.fanjun.keeplive.config.KeepLiveService
import io.github.mzdluo123.mirai.android.NotificationFactory.initNotification
import io.github.mzdluo123.mirai.android.activity.CrashReportActivity
import io.github.mzdluo123.mirai.android.crash.MiraiAndroidReportSenderFactory
Expand Down Expand Up @@ -73,7 +76,22 @@ class BotApplication : Application() {
return null
}

internal fun keepLive() {
val notification = ForegroundNotification("MiraiAndroid", "保活服务已启动", R.mipmap.ic_launcher)
KeepLive.startWork(this, KeepLive.RunMode.ROGUE, notification, object : KeepLiveService {
override fun onWorking() {
startBotService()
}

override fun onStop() {
stopBotService()
}

})
}

internal fun startBotService() {

val account = getSharedPreferences("account", Context.MODE_PRIVATE)
this.startService(Intent(this, BotService::class.java).apply {
putExtra("action", BotService.START_SERVICE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ import androidx.navigation.ui.AppBarConfiguration
import androidx.navigation.ui.navigateUp
import androidx.navigation.ui.setupActionBarWithNavController
import androidx.navigation.ui.setupWithNavController
import io.github.mzdluo123.mirai.android.BotApplication
import io.github.mzdluo123.mirai.android.BuildConfig
import io.github.mzdluo123.mirai.android.NotificationFactory
import io.github.mzdluo123.mirai.android.R
import io.github.mzdluo123.mirai.android.*
import io.github.mzdluo123.mirai.android.utils.RequestUtil
import io.github.mzdluo123.mirai.android.utils.SafeDns
import io.github.mzdluo123.mirai.android.utils.shareText
Expand Down Expand Up @@ -69,6 +66,9 @@ class MainActivity : AppCompatActivity() {
(application as BotApplication).startBotService()
setupListeners()
crashCheck()
if (AppSettings.keepLive) {
BotApplication.context.keepLive()
}
// if (BuildConfig.DEBUG) toast("跳过更新检查")
// else updateCheck()
updateCheck()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,19 @@ fun logException(err: Throwable?) {
MiraiAndroidLogger.error(stringWriter.toString())
}

internal fun processHTMLLog(log: String): String =
log.replace("\n", "<br>")
.replace("<", "&lt;")
.replace(">", "&gt")
.replace("&", "&amp;")
.replace("\"", "&quot")

object MiraiAndroidLogger :
SimpleLogger(LOGGER_IDENTITY, { priority: LogPriority, message: String?, e: Throwable? ->
val log = "[${priority.name}] ${message ?: e}"
val colorLog =
"<font color=\"${LogColor.valueOf(priority.name).color}\">[${priority.name}]</font> ${
message?.replace(
"\n",
"<br>"
) ?: "发生错误"
processHTMLLog(message ?: "")
}"

synchronized(this) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.mzdluo123.mirai.android.ui.tools

import android.annotation.SuppressLint
import android.content.ComponentName
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
Expand Down Expand Up @@ -60,18 +59,18 @@ class ToolsFragment : Fragment() {
getDeviceFile()?.delete() ?: return@setOnClickListener
toast("成功")
}
btn_open_data_folder.setOnClickListener {
val intent = Intent()

intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
intent.component = ComponentName(
"com.android.documentsui",
"com.android.documentsui.files.FilesActivity"
)

requireContext().startActivity(intent)

}
// btn_open_data_folder.setOnClickListener {
// val intent = Intent()
//
// intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
// intent.component = ComponentName(
// "com.android.documentsui",
// "com.android.documentsui.files.FilesActivity"
// )
//
// requireContext().startActivity(intent)
//
// }
}

private fun getDeviceFile(): File? {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_baseline_new_releases_24.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M23,12l-2.44,-2.78 0.34,-3.68 -3.61,-0.82 -1.89,-3.18L12,3 8.6,1.54 6.71,4.72l-3.61,0.81 0.34,3.68L1,12l2.44,2.78 -0.34,3.69 3.61,0.82 1.89,3.18L12,21l3.4,1.46 1.89,-3.18 3.61,-0.82 -0.34,-3.68L23,12zM13,17h-2v-2h2v2zM13,13h-2L11,7h2v6z" />
</vector>
64 changes: 32 additions & 32 deletions app/src/main/res/layout/fragment_tools.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,38 +30,38 @@

</androidx.cardview.widget.CardView>

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="数据工具"
android:textSize="18sp"
android:textStyle="bold" />


<Button
android:id="@+id/btn_open_data_folder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="8dp"
android:text="打开系统文件管理器" />


</LinearLayout>

</androidx.cardview.widget.CardView>
<!-- <androidx.cardview.widget.CardView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginStart="8dp"-->
<!-- android:layout_marginTop="8dp"-->
<!-- android:layout_marginEnd="8dp">-->

<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:orientation="vertical">-->

<!-- <TextView-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_margin="10dp"-->
<!-- android:text="数据工具"-->
<!-- android:textSize="18sp"-->
<!-- android:textStyle="bold" />-->


<!-- <Button-->
<!-- android:id="@+id/btn_open_data_folder"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginHorizontal="8dp"-->
<!-- android:text="打开系统文件管理器" />-->


<!-- </LinearLayout>-->

<!-- </androidx.cardview.widget.CardView>-->

<androidx.cardview.widget.CardView
android:layout_width="match_parent"
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/xml/setting_screen.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@
android:key="start_on_boot_preference"
android:summary="请加入开机自启白名单以确保能够正常开机启动"
android:title="开机启动" />

<SwitchPreference
android:defaultValue="false"
android:icon="@drawable/ic_baseline_new_releases_24"
android:key="keeplive_preference"
android:summary="降低MiraiAndroid被系统杀死的可能性,不保证效果"
android:title="启用保活服务" />
<!-- <SwitchPreference-->
<!-- android:defaultValue="false"-->
<!-- android:icon="@drawable/ic_battery_alert_24"-->
Expand Down

0 comments on commit 007a1a5

Please sign in to comment.