Skip to content

Commit

Permalink
新增日志页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Dec 15, 2024
1 parent b4068ab commit 6e20c15
Show file tree
Hide file tree
Showing 12 changed files with 282 additions and 21 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,12 @@ android {
}

dependencies {
//log
implementation 'com.elvishew:xlog:1.11.1'

implementation 'com.github.nanihadesuka:LazyColumnScrollbar:2.2.0'
//restart app
implementation 'com.jakewharton:process-phoenix:3.0.0'
// implementation 'org.java-websocket:Java-WebSocket:1.5.6'
// implementation 'com.pusher:pusher-java-client:0.3.1'
//setting screen
// implementation "com.github.JamalMulla:ComposePrefs3:1.0.3"
implementation "com.github.JamalMulla:ComposePrefs:1.0.6"
Expand Down Expand Up @@ -107,7 +108,7 @@ dependencies {
implementation("androidx.lifecycle:lifecycle-viewmodel-compose:$lifecycle_version")
// LiveData
implementation("androidx.lifecycle:lifecycle-livedata-ktx:$lifecycle_version")

implementation 'androidx.work:work-runtime-ktx:2.10.0'

implementation 'androidx.core:core-ktx:1.15.0'
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
Expand All @@ -14,6 +19,7 @@
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:requestLegacyExternalStorage="true"
android:supportsRtl="true"
android:theme="@style/Theme.Nap511"
android:usesCleartextTraffic="true"
Expand All @@ -26,11 +32,12 @@
tools:ignore="AppLinkUrlError">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

<data android:scheme="magnet" />
<!-- <data android:scheme="http" />-->
<!-- <data android:scheme="http" />-->
<data android:scheme="ftp" />
<data android:scheme="ed2k" />
</intent-filter>
Expand All @@ -48,6 +55,7 @@
tools:ignore="AppLinkUrlError">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

Expand All @@ -61,6 +69,7 @@
https://github.com/LibreOffice/online/blob/d0edfeabbdc969a9a66cf90976a63c2f4403a6d3/android/app/src/main/AndroidManifest.xml#L119-L129 -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />

Expand Down
25 changes: 14 additions & 11 deletions app/src/main/java/github/zerorooot/nap511/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.BackHandler
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -54,6 +53,7 @@ import androidx.work.WorkQuery
import coil.compose.rememberAsyncImagePainter
import coil.request.CachePolicy
import coil.request.ImageRequest
import com.elvishew.xlog.XLog
import com.google.accompanist.systemuicontroller.rememberSystemUiController
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
Expand All @@ -66,6 +66,7 @@ import github.zerorooot.nap511.screen.CaptchaWebViewScreen
import github.zerorooot.nap511.screen.CookieDialog
import github.zerorooot.nap511.screen.ExitApp
import github.zerorooot.nap511.screen.FileScreen
import github.zerorooot.nap511.screen.LogScreen
import github.zerorooot.nap511.screen.LoginWebViewScreen
import github.zerorooot.nap511.screen.MyPhotoScreen
import github.zerorooot.nap511.screen.OfflineDownloadScreen
Expand Down Expand Up @@ -165,24 +166,29 @@ class MainActivity : ComponentActivity() {
if (intent.action == "check") {
App.selectedItem = ConfigKeyUtil.VERIFY_MAGNET_LINK_ACCOUNT
intent.action = ""
XLog.d("handleIntent check $intent")
}
//跳转到默认下载目录
if (intent.action == "jump") {
viewModels<FileViewModel>().value.getFiles(
val fileViewModel: FileViewModel by viewModels()
fileViewModel.getFiles(
DataStoreUtil.getData(
ConfigKeyUtil.DEFAULT_OFFLINE_CID,
"0"
)
)
//清除action,不然会一直跳转到默认下载目录
intent.action = ""
XLog.d("handleIntent jump $intent $fileViewModel ${fileViewModel.remainingSpace}")
}
if (intent.action == "copy") {
val clipboard = ContextCompat.getSystemService(this, ClipboardManager::class.java)
val clip = ClipData.newPlainText("label", intent.getStringExtra("link"))
clipboard?.setPrimaryClip(clip)
intent.action = ""
XLog.d("handleIntent copy $intent")
}

}

/**
Expand All @@ -204,10 +210,6 @@ class MainActivity : ComponentActivity() {
val workInfos: List<WorkInfo> =
WorkManager.getInstance(applicationContext).getWorkInfos(workQuery).get()
val size = workInfos.size
Log.d(
"nap511 main activity",
"checkOfflineTask workManager size $size workInfos $workInfos"
)
if (size != 0) {
return
}
Expand All @@ -217,15 +219,13 @@ class MainActivity : ComponentActivity() {
.filter { i -> i != "" && i != " " }
.toSet()
.toMutableList()
Log.d(
"nap511 main activity",
"checkOfflineTask currentOfflineTask size ${currentOfflineTask.size}"
)

//currentOfflineTask等于0,证明没有离线链接缓存
if (currentOfflineTask.isEmpty()) {
return
}
XLog.d(
"checkOfflineTask workManager workInfos $workInfos currentOfflineTask size ${currentOfflineTask.size}"
)
//添加离线链接
val listType = object : TypeToken<List<String?>?>() {}.type
val list = Gson().toJson(currentOfflineTask, listType)
Expand Down Expand Up @@ -259,6 +259,7 @@ class MainActivity : ComponentActivity() {
// R.drawable.baseline_web_24 to "ConfigUtil.WEB",
R.drawable.ic_baseline_delete_24 to ConfigKeyUtil.RECYCLE_BIN,
R.drawable.baseline_settings_24 to ConfigKeyUtil.ADVANCED_SETTINGS,
R.drawable.baseline_log_24 to ConfigKeyUtil.LOG_SCREEN,
R.drawable.android_exit to ConfigKeyUtil.EXIT_APPLICATION
)
ModalNavigationDrawer(gesturesEnabled = App.gesturesEnabled,
Expand Down Expand Up @@ -314,7 +315,9 @@ class MainActivity : ComponentActivity() {
CaptchaVideoWebViewScreen()
}

ConfigKeyUtil.LOG_SCREEN -> LogScreen()
ConfigKeyUtil.EXIT_APPLICATION -> ExitApp()

ConfigKeyUtil.PHOTO -> {
MyPhotoScreen(fileViewModel)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
Expand All @@ -25,17 +24,14 @@ import github.zerorooot.nap511.MainActivity
import github.zerorooot.nap511.R
import github.zerorooot.nap511.bean.BaseReturnMessage
import github.zerorooot.nap511.bean.SignBean
import github.zerorooot.nap511.factory.CookieViewModelFactory
import github.zerorooot.nap511.util.App
import github.zerorooot.nap511.util.ConfigKeyUtil
import github.zerorooot.nap511.util.DataStoreUtil
import github.zerorooot.nap511.viewmodel.OfflineFileViewModel
import okhttp3.FormBody
import okhttp3.OkHttpClient
import okhttp3.Request
import java.util.StringJoiner
import java.util.concurrent.TimeUnit
import kotlin.getValue


class OfflineTaskActivity : ComponentActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import androidx.work.OneTimeWorkRequest
import androidx.work.WorkManager
import com.acsbendi.requestinspectorwebview.RequestInspectorWebViewClient
import com.acsbendi.requestinspectorwebview.WebViewRequest
import com.elvishew.xlog.XLog
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.jakewharton.processphoenix.ProcessPhoenix
Expand Down Expand Up @@ -163,11 +164,12 @@ fun loginWebViewClient(webView: WebView): WebViewClient {
if (url.startsWith("https://webapi.115.com/label/list") || url.startsWith("https://115.com/?cid=0&offset=0&mode=wangpan")) {
val message = "登录失败~,请重试"
val cookie = webViewRequest.headers["cookie"]
XLog.d("loginWebViewClient $cookie")
if (cookie == null) {
App.instance.toast(message)
return super.shouldInterceptRequest(view, webViewRequest)
}
println(cookie)

//USERSESSIONID=xx; UID=xx; CID=xx; SEID=xx; PHPSESSID=xx; acw_tc=xx; UID=xx; CID=xx; SEID=xx
val uidRegex = Regex("UID=\\w+")
val cidRegex = Regex("CID=\\w+")
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/java/github/zerorooot/nap511/screen/AppTopBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,30 @@ fun AppTopBarOfflineFile(title: String, onClick: (name: String) -> Unit) {
}
)
}
@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun AppTopBarLogScreen(title: String, onClick: (name: String) -> Unit) {
// val contextForToast = LocalContext.current.applicationContext
TopAppBar(
title = {
Text(text = title)
},
colors = TopAppBarDefaults.topAppBarColors(containerColor = Purple80),
navigationIcon = {
TopAppBarActionButton(
imageVector = Icons.Rounded.Menu,
description = "navigationIcon"
) {
onClick.invoke("ModalNavigationDrawerMenu")
}
},
actions = {
LogScreenTopBarDropdownMenu(onClick = { itemValue, _ ->
onClick.invoke(itemValue)
})
}
)
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,12 @@ fun OfflineFileAppTopBarDropdownMenu(onClick: (String, Int) -> Unit) {
val listOf = stringArrayResource(id = R.array.offlineFileAppBarMenu).toList()
BaseAppTorBarMenu(listOf = listOf, onClick = onClick)
}

@Composable
fun LogScreenTopBarDropdownMenu(onClick: (String, Int) -> Unit) {
val listOf = stringArrayResource(id = R.array.logScreenAppBarMenu).toList()
// val listOf = listOf("滚动顶部", "滚动底部", "清空日志","导出日志")
BaseAppTorBarMenu(listOf = listOf, onClick = onClick)
}
@Composable
fun RecycleAppTopBarDropdownMenu(onClick: (String, Int) -> Unit) {
val listOf = listOf("清空所有文件")
Expand Down
Loading

0 comments on commit 6e20c15

Please sign in to comment.