From 3ccb0a0a23bbe4647744406d47c71374d718e598 Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 29 Nov 2024 23:09:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=E6=8A=BD=E5=B1=89=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/deploymentTargetSelector.xml | 3 + app/build.gradle | 2 + .../github/zerorooot/nap511/MainActivity.kt | 269 +++++++++++++++--- .../nap511/activity/OfflineTaskActivity.kt | 15 +- .../nap511/activity/TorrentTaskActivity.kt | 1 + .../java/github/zerorooot/nap511/bean/Bean.kt | 30 +- .../zerorooot/nap511/screen/AlertDialog.kt | 19 +- .../nap511/screen/AllWebViewScreen.kt | 15 +- .../zerorooot/nap511/screen/FileScreen.kt | 2 +- .../nap511/screen/OfflineFileScreen.kt | 6 +- .../zerorooot/nap511/screen/SettingScreen.kt | 2 +- .../java/github/zerorooot/nap511/util/App.kt | 8 +- .../zerorooot/nap511/util/ConfigUtil.kt | 18 +- .../nap511/viewmodel/OfflineFileViewModel.kt | 10 +- app/src/main/res/drawable/avatar.xml | 13 + ...4.xml => baseline_magent_moderator_24.xml} | 0 .../drawable/baseline_video_moderator_24.xml | 10 + 17 files changed, 340 insertions(+), 83 deletions(-) create mode 100644 app/src/main/res/drawable/avatar.xml rename app/src/main/res/drawable/{baseline_add_moderator_24.xml => baseline_magent_moderator_24.xml} (100%) create mode 100644 app/src/main/res/drawable/baseline_video_moderator_24.xml diff --git a/.idea/deploymentTargetSelector.xml b/.idea/deploymentTargetSelector.xml index b268ef3..56e009b 100644 --- a/.idea/deploymentTargetSelector.xml +++ b/.idea/deploymentTargetSelector.xml @@ -5,6 +5,9 @@ + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 927995b..6bf934c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,6 +51,8 @@ android { } dependencies { + //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 diff --git a/app/src/main/java/github/zerorooot/nap511/MainActivity.kt b/app/src/main/java/github/zerorooot/nap511/MainActivity.kt index 0c93bf2..1517f73 100644 --- a/app/src/main/java/github/zerorooot/nap511/MainActivity.kt +++ b/app/src/main/java/github/zerorooot/nap511/MainActivity.kt @@ -1,31 +1,79 @@ package github.zerorooot.nap511 import android.annotation.SuppressLint +import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.BackHandler import androidx.activity.compose.setContent import androidx.activity.viewModels -import androidx.compose.foundation.layout.* -import androidx.compose.material3.* -import androidx.compose.runtime.* +import androidx.compose.foundation.Image +import androidx.compose.foundation.layout.Column +import androidx.compose.foundation.layout.Spacer +import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width +import androidx.compose.foundation.shape.CircleShape +import androidx.compose.foundation.shape.RoundedCornerShape +import androidx.compose.material.LinearProgressIndicator +import androidx.compose.material3.DrawerValue +import androidx.compose.material3.ExperimentalMaterial3Api +import androidx.compose.material3.Icon +import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalDrawerSheet +import androidx.compose.material3.ModalNavigationDrawer +import androidx.compose.material3.NavigationDrawerItem +import androidx.compose.material3.NavigationDrawerItemDefaults +import androidx.compose.material3.Surface +import androidx.compose.material3.Text +import androidx.compose.material3.rememberDrawerState +import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue +import androidx.compose.runtime.mutableStateOf +import androidx.compose.runtime.remember +import androidx.compose.runtime.rememberCoroutineScope +import androidx.compose.runtime.setValue +import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clip +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.compose.ui.unit.dp +import androidx.core.content.IntentCompat import androidx.work.Data import androidx.work.ExistingWorkPolicy import androidx.work.OneTimeWorkRequest import androidx.work.WorkInfo import androidx.work.WorkManager import androidx.work.WorkQuery +import coil.compose.rememberAsyncImagePainter +import coil.request.CachePolicy +import coil.request.ImageRequest import com.google.accompanist.systemuicontroller.rememberSystemUiController import com.google.gson.Gson +import com.google.gson.JsonObject import com.google.gson.reflect.TypeToken +import com.jakewharton.processphoenix.ProcessPhoenix import github.zerorooot.nap511.activity.OfflineTaskWorker -import github.zerorooot.nap511.bean.TorrentFileBean -import github.zerorooot.nap511.bean.TorrentFileListWeb +import github.zerorooot.nap511.bean.AvatarBean +import github.zerorooot.nap511.bean.InfoBean import github.zerorooot.nap511.factory.CookieViewModelFactory -import github.zerorooot.nap511.screen.* +import github.zerorooot.nap511.screen.CaptchaVideoWebViewScreen +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.LoginWebViewScreen +import github.zerorooot.nap511.screen.MyPhotoScreen +import github.zerorooot.nap511.screen.OfflineDownloadScreen +import github.zerorooot.nap511.screen.OfflineFileScreen +import github.zerorooot.nap511.screen.RecycleScreen +import github.zerorooot.nap511.screen.SettingScreen +import github.zerorooot.nap511.screen.WebViewScreen import github.zerorooot.nap511.ui.theme.Nap511Theme import github.zerorooot.nap511.util.App import github.zerorooot.nap511.util.ConfigUtil @@ -34,6 +82,12 @@ import github.zerorooot.nap511.viewmodel.FileViewModel import github.zerorooot.nap511.viewmodel.OfflineFileViewModel import github.zerorooot.nap511.viewmodel.RecycleViewModel import kotlinx.coroutines.launch +import okhttp3.Call +import okhttp3.Interceptor +import okhttp3.OkHttpClient +import okhttp3.Request +import okhttp3.Response +import okio.IOException import kotlin.concurrent.thread @@ -60,9 +114,20 @@ class MainActivity : ComponentActivity() { App.instance.goToNotificationSetting(this) } //直接添加磁力,但提示请验证账号;跳转到验证账号界面 + if (intent.action == "check") { + App.selectedItem = ConfigUtil.VERIFY_MAGNET_LINK_ACCOUNT + } + //跳转到默认下载目录 if (intent.action == "jump") { - App.selectedItem = "验证账号" + viewModels().value.getFiles( + DataStoreUtil.getData( + ConfigUtil.defaultOfflineCid, + "0" + ) + ) } + //检测未上传的磁力链接 + checkOfflineTask(cookie) } } } @@ -92,15 +157,12 @@ class MainActivity : ComponentActivity() { rememberSystemUiController().apply { isSystemBarsVisible = visible } - BackHandler(App.selectedItem == "photo" || App.selectedItem == "webView") { - App.selectedItem = "我的文件" + BackHandler(App.selectedItem == ConfigUtil.PHOTO || App.selectedItem == ConfigUtil.WEB) { + App.selectedItem = ConfigUtil.MY_FILE visible = true } MyNavigationDrawer(fileViewModel, offlineFileViewModel, recycleViewModel) - - checkOfflineTask(cookie) - } /** @@ -146,7 +208,6 @@ class MainActivity : ComponentActivity() { val request: OneTimeWorkRequest = OneTimeWorkRequest.Builder(OfflineTaskWorker::class.java).setInputData(data) .build() -// WorkManager.getInstance(applicationContext).enqueue(request) WorkManager.getInstance(applicationContext) .enqueueUniqueWork( "addOfflineTaskByCount", @@ -168,22 +229,26 @@ class MainActivity : ComponentActivity() { App.drawerState = drawerState App.scope = scope val itemMap = linkedMapOf( - R.drawable.baseline_login_24 to "登录", - R.drawable.baseline_cloud_24 to "我的文件", - R.drawable.baseline_cloud_download_24 to "离线下载", - R.drawable.baseline_cloud_done_24 to "离线列表", -// R.drawable.baseline_add_moderator_24 to "验证video账号", -// R.drawable.baseline_web_24 to "网页版", - R.drawable.ic_baseline_delete_24 to "回收站", - R.drawable.baseline_settings_24 to "高级设置", - R.drawable.android_exit to "退出应用" + R.drawable.baseline_login_24 to ConfigUtil.LOGIN, + R.drawable.baseline_cloud_24 to ConfigUtil.MY_FILE, + R.drawable.baseline_cloud_download_24 to ConfigUtil.OFFLINE_DOWNLOAD, + R.drawable.baseline_cloud_done_24 to ConfigUtil.OFFLINE_LIST, + R.drawable.baseline_video_moderator_24 to ConfigUtil.VERIFY_VIDEO_ACCOUNT, + R.drawable.baseline_magent_moderator_24 to ConfigUtil.VERIFY_MAGNET_LINK_ACCOUNT, +// R.drawable.baseline_web_24 to "ConfigUtil.WEB", + R.drawable.ic_baseline_delete_24 to ConfigUtil.RECYCLE_BIN, + R.drawable.baseline_settings_24 to ConfigUtil.ADVANCED_SETTINGS, + R.drawable.android_exit to ConfigUtil.EXIT_APPLICATION ) - ModalNavigationDrawer(gesturesEnabled = App.gesturesEnabled, drawerState = drawerState, drawerContent = { ModalDrawerSheet { - Spacer(Modifier.height(12.dp)) + Spacer(Modifier.height(6.dp)) + //头像 + Avatar() + //菜单栏 + Spacer(Modifier.height(6.dp)) itemMap.forEach { (t, u) -> NavigationDrawerItem(icon = { Icon( @@ -200,33 +265,155 @@ class MainActivity : ComponentActivity() { }, content = { when (App.selectedItem) { - "登录" -> Login() - "我的文件" -> MyFileScreen(fileViewModel) - "离线下载" -> OfflineDownloadScreen(offlineFileViewModel, fileViewModel) - "离线列表" -> OfflineFileScreen(offlineFileViewModel, fileViewModel) - "网页版" -> WebViewScreen() - "回收站" -> RecycleScreen(recycleViewModel) - "高级设置" -> SettingScreen() - "验证账号" -> { - App.captchaUrl = - "https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis() + ConfigUtil.LOGIN -> Login() + ConfigUtil.MY_FILE -> MyFileScreen(fileViewModel) + ConfigUtil.OFFLINE_DOWNLOAD -> OfflineDownloadScreen( + offlineFileViewModel, + fileViewModel + ) + + ConfigUtil.OFFLINE_LIST -> OfflineFileScreen( + offlineFileViewModel, + fileViewModel + ) + + ConfigUtil.WEB -> WebViewScreen() + ConfigUtil.RECYCLE_BIN -> RecycleScreen(recycleViewModel) + ConfigUtil.ADVANCED_SETTINGS -> SettingScreen() + ConfigUtil.VERIFY_MAGNET_LINK_ACCOUNT -> { CaptchaWebViewScreen() } - "验证video账号" -> { + ConfigUtil.VERIFY_VIDEO_ACCOUNT -> { CaptchaVideoWebViewScreen() } - "退出应用" -> ExitApp() - "captchaWebView" -> CaptchaWebViewScreen() - "loginWebView" -> LoginWebViewScreen() - "photo" -> { + ConfigUtil.EXIT_APPLICATION -> ExitApp() + ConfigUtil.PHOTO -> { MyPhotoScreen(fileViewModel) } } }) } + /** + * 头像、网名、uid、已用空间 + */ + @Composable + private fun Avatar() { + val avatarBean = remember { mutableStateOf(AvatarBean()) } + val avatarUrl = "https://my.115.com/proapi/3.0/index.php?method=user_info&uid=${App.uid}" + val okHttpClient = OkHttpClient().newBuilder() + .addInterceptor(Interceptor { chain -> + chain.proceed( + chain.request().newBuilder() + .addHeader("Cookie", App.cookie) + .addHeader( + "User-Agent", + "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 115Browser/23.9.3.6" + ) + .build() + ); + }).build() + + val infoUrl = "https://webapi.115.com/files/index_info?count_space_nums=1" + + val avatarRequest: Request = Request.Builder().url(avatarUrl).get().build() + okHttpClient.newCall(avatarRequest).enqueue(object : okhttp3.Callback { + override fun onFailure(call: Call, e: IOException) { + App.instance.toast(e.message + "") + } + + override fun onResponse(call: Call, response: Response) { + val body = response.body.string() + //{"state":true,"data":{"space_info":{"all_total":{"size":11111,"size_format":"1TB"},"all_remain":{"size":1111,"size_format":"1TB"},"all_use":{"size":1111,"size_format":"1TB"}}},"error":"","code":0} +// println(body) + avatarBean.value = Gson().fromJson(body, AvatarBean::class.java) + } + }) + + val infoBean = remember { mutableStateOf(InfoBean()) } + val infoRequest: Request = Request.Builder().url(infoUrl).get().build() + okHttpClient.newCall(infoRequest).enqueue(object : okhttp3.Callback { + override fun onFailure(call: Call, e: IOException) { + App.instance.toast(e.message + "") + } + + override fun onResponse(call: Call, response: Response) { + val body = response.body.string() + val spaceInfo = + Gson().fromJson(body, JsonObject::class.java).getAsJsonObject("data") + .getAsJsonObject("space_info") + val allUse = spaceInfo.getAsJsonObject("all_use").get("size").asLong + val allUseString = spaceInfo.getAsJsonObject("all_use").get("size_format").asString + val allTotal = spaceInfo.getAsJsonObject("all_total").get("size").asLong + val allTotalString = + spaceInfo.getAsJsonObject("all_total").get("size_format").asString + val allRemain = spaceInfo.getAsJsonObject("all_remain").get("size").asLong + val allRemainString = + spaceInfo.getAsJsonObject("all_remain").get("size_format").asString + + infoBean.value = InfoBean( + allRemain, + allRemainString, + allTotal, + allTotalString, + allUse, + allUseString + ) + } + }) + + Column( + modifier = Modifier.fillMaxWidth(), + horizontalAlignment = Alignment.CenterHorizontally, // 水平居中 + ) { + //头像 + Image( + painter = rememberAsyncImagePainter( + ImageRequest.Builder(LocalContext.current) + .data(avatarBean.value.data.user_face) + .memoryCachePolicy(CachePolicy.ENABLED) + .diskCachePolicy(CachePolicy.ENABLED) + .networkCachePolicy(CachePolicy.ENABLED) + .apply(block = fun ImageRequest.Builder.() { + scale(coil.size.Scale.FILL) + placeholder(R.drawable.avatar) + }).build() + ), + modifier = Modifier + .height(100.dp) + .width(100.dp) + //圆形裁剪 + .clip(CircleShape), + contentScale = ContentScale.Crop, + contentDescription = "", + ) + Spacer(Modifier.height(6.dp)) + //用户名 + Text( + text = avatarBean.value.data.user_name, + style = MaterialTheme.typography.titleMedium + ) + //uid + Text(text = App.uid) + Spacer(Modifier.height(6.dp)) + //已用空间 + Text( + text = "总计${infoBean.value.allTotalString},已用${infoBean.value.allUseString},剩余${infoBean.value.allRemainString}", + style = MaterialTheme.typography.titleSmall + ) + //进度条 + LinearProgressIndicator( + progress = (infoBean.value.allUse.toDouble() / infoBean.value.allTotal).toFloat(), + color = Color.Cyan, + modifier = Modifier + .fillMaxWidth(0.7f) + .clip(shape = RoundedCornerShape(100.dp)) + ) + } + } + @SuppressLint("UnrememberedMutableState") @Composable @@ -252,8 +439,8 @@ class MainActivity : ComponentActivity() { DataStoreUtil.putData(ConfigUtil.cookie, replace) DataStoreUtil.putData(ConfigUtil.uid, checkLogin) App.cookie = replace -// App.isInit = true - "登陆成功,请重启应用!" + ProcessPhoenix.triggerRebirth(applicationContext); + "登陆成功,重启中~" } App.instance.toast(message) } diff --git a/app/src/main/java/github/zerorooot/nap511/activity/OfflineTaskActivity.kt b/app/src/main/java/github/zerorooot/nap511/activity/OfflineTaskActivity.kt index ab2578a..a8d8c05 100644 --- a/app/src/main/java/github/zerorooot/nap511/activity/OfflineTaskActivity.kt +++ b/app/src/main/java/github/zerorooot/nap511/activity/OfflineTaskActivity.kt @@ -36,6 +36,7 @@ import okhttp3.OkHttpClient import okhttp3.Request import java.util.StringJoiner import java.util.concurrent.TimeUnit +import kotlin.system.exitProcess class OfflineTaskActivity : Activity() { @@ -85,6 +86,7 @@ class OfflineTaskActivity : Activity() { val clip = ClipData.newPlainText("label", intent.getStringExtra("link")) clipboard?.setPrimaryClip(clip) } + moveTaskToBack(true); finishAndRemoveTask() } @@ -211,10 +213,11 @@ class OfflineTaskWorker( setStyle(NotificationCompat.BigTextStyle().bigText(message)) } + val pendingIntent: PendingIntent if (message.contains("任务添加失败")) { - val pendingIntent = if (message.contains("请验证账号")) { + pendingIntent = if (message.contains("请验证账号")) { val intent = Intent(this.applicationContext, MainActivity::class.java) - intent.action = "jump" + intent.action = "check" notification.setContentText("$message。点我跳转验证账号页面") PendingIntent.getActivity( this.applicationContext, 0, intent, PendingIntent.FLAG_IMMUTABLE @@ -230,12 +233,16 @@ class OfflineTaskWorker( this.applicationContext, 0, intent, PendingIntent.FLAG_IMMUTABLE ) } - - notification.setContentIntent(pendingIntent) } else { + val intent = Intent(this.applicationContext, MainActivity::class.java) + intent.action = "jump" notification.setContentText(message) + pendingIntent = PendingIntent.getActivity( + this.applicationContext, 0, intent, PendingIntent.FLAG_IMMUTABLE + ) } + notification.setContentIntent(pendingIntent) notificationManager.notify(notificationId, notification.build()) } diff --git a/app/src/main/java/github/zerorooot/nap511/activity/TorrentTaskActivity.kt b/app/src/main/java/github/zerorooot/nap511/activity/TorrentTaskActivity.kt index b57b815..0130298 100644 --- a/app/src/main/java/github/zerorooot/nap511/activity/TorrentTaskActivity.kt +++ b/app/src/main/java/github/zerorooot/nap511/activity/TorrentTaskActivity.kt @@ -36,6 +36,7 @@ class TorrentTaskActivity : Activity() { val defaultOfflineCid = DataStoreUtil.getData(ConfigUtil.defaultOfflineCid, "0") initUpload(torrentFile, App.cookie, uid, defaultOfflineCid) } + moveTaskToBack(true); finishAndRemoveTask() } diff --git a/app/src/main/java/github/zerorooot/nap511/bean/Bean.kt b/app/src/main/java/github/zerorooot/nap511/bean/Bean.kt index e08a5a7..a2f901d 100644 --- a/app/src/main/java/github/zerorooot/nap511/bean/Bean.kt +++ b/app/src/main/java/github/zerorooot/nap511/bean/Bean.kt @@ -25,17 +25,8 @@ data class LoginCookie( data class LoginData( var user_id: String = "0", - var user_name: String? = null, - var email: String? = null, - var mobile: String? = null, - var country: String? = null, - var is_vip: Int = 0, - var mark: Int = 0, - var alert: String? = null, -// var is_chang_passwd: Int = 0, -// var is_first_login: Int = 0, -// var bind_mobile: Int = 0, -// var passwd_reset: Int = 0, + var user_name: String = "TestTest", + var user_face: String = "", var cookie: LoginCookie? = null, ) @@ -47,6 +38,23 @@ data class LoginBean( var message: String = "" ) +data class AvatarBean( + var state: Boolean = false, + @SerializedName("data") + var data: LoginData = LoginData(), + var message: String = "" +) + +data class InfoBean( + var allRemain: Long = 1L, + var allRemainString: String = "", + var allTotal: Long = 1L, + var allTotalString: String = "", + var allUse: Long = 1L, + var allUseString: String = "", +) + + data class FilesBean( @SerializedName("data") var fileBeanList: ArrayList, var cid: String, diff --git a/app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt b/app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt index 2368958..8e3f177 100644 --- a/app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt +++ b/app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt @@ -1,15 +1,20 @@ package github.zerorooot.nap511.screen import android.app.Activity +import androidx.compose.foundation.Image import androidx.compose.foundation.clickable +import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row +import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.fillMaxSize import androidx.compose.foundation.layout.fillMaxWidth +import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.heightIn import androidx.compose.foundation.layout.offset import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.width import androidx.compose.foundation.lazy.LazyColumn import androidx.compose.foundation.lazy.itemsIndexed import androidx.compose.foundation.lazy.rememberLazyListState @@ -31,6 +36,10 @@ import androidx.compose.material3.ExperimentalMaterial3Api import androidx.compose.material3.Icon import androidx.compose.material3.LocalTextStyle import androidx.compose.material3.MaterialTheme +import androidx.compose.material3.ModalDrawerSheet +import androidx.compose.material3.ModalNavigationDrawer +import androidx.compose.material3.NavigationDrawerItem +import androidx.compose.material3.NavigationDrawerItemDefaults import androidx.compose.material3.OutlinedTextField import androidx.compose.material3.Text import androidx.compose.material3.TextButton @@ -48,7 +57,10 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.focus.FocusRequester import androidx.compose.ui.focus.focusRequester import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.vector.ImageVector +import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.platform.LocalContext +import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringArrayResource import androidx.compose.ui.semantics.Role import androidx.compose.ui.text.TextRange @@ -73,7 +85,9 @@ import github.zerorooot.nap511.viewmodel.FileViewModel import github.zerorooot.nap511.viewmodel.OfflineFileViewModel import github.zerorooot.nap511.viewmodel.RecycleViewModel import kotlinx.coroutines.delay +import kotlinx.coroutines.launch import java.io.File +import kotlin.system.exitProcess @Composable fun CreateFolderDialog(fileViewModel: FileViewModel, enter: (String) -> Unit) { @@ -159,10 +173,11 @@ fun ExitApp() { InfoDialog( onDismissRequest = { isOpen = false - App.selectedItem = "我的文件" + App.selectedItem = ConfigUtil.MY_FILE }, onConfirmation = { - activity.finish() + android.os.Process.killProcess(android.os.Process.myPid()); + exitProcess(1); }, dialogTitle = "是否离开Nap511?", ) diff --git a/app/src/main/java/github/zerorooot/nap511/screen/AllWebViewScreen.kt b/app/src/main/java/github/zerorooot/nap511/screen/AllWebViewScreen.kt index d0b1e93..4f11f93 100644 --- a/app/src/main/java/github/zerorooot/nap511/screen/AllWebViewScreen.kt +++ b/app/src/main/java/github/zerorooot/nap511/screen/AllWebViewScreen.kt @@ -28,6 +28,7 @@ import com.acsbendi.requestinspectorwebview.RequestInspectorWebViewClient import com.acsbendi.requestinspectorwebview.WebViewRequest import com.google.gson.Gson import com.google.gson.reflect.TypeToken +import com.jakewharton.processphoenix.ProcessPhoenix import github.zerorooot.nap511.R import github.zerorooot.nap511.activity.OfflineTaskWorker import github.zerorooot.nap511.ui.theme.Purple80 @@ -80,7 +81,7 @@ fun BaseWebViewScreen( settings.domStorageEnabled = true;//开启DOM缓存,关闭的话H5自身的一些操作是无效的 settings.cacheMode = WebSettings.LOAD_DEFAULT; // Allow mixed content for WebSocket connections (optional, if needed) - settings.mixedContentMode= WebSettings.MIXED_CONTENT_ALWAYS_ALLOW + settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW settings.userAgentString = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36" } @@ -173,7 +174,7 @@ fun loginWebViewClient(webView: WebView): WebViewClient { // val c2 = App().checkLogin(matches[1].replace(" ", "")) // println() // } - message = "登陆成功,请重启应用!" + message = "登陆成功,请重启中~" cookie = matches[1].replace(" ", "") val uid = UrlQuerySanitizer(url).getValue("user_id") @@ -182,6 +183,8 @@ fun loginWebViewClient(webView: WebView): WebViewClient { App.cookie = cookie App.gesturesEnabled = true App.instance.toast(message) + //restart + ProcessPhoenix.triggerRebirth(App.instance); } return super.shouldInterceptRequest(view, webViewRequest) } @@ -199,12 +202,12 @@ fun CaptchaWebViewScreen() { } cookieManager.flush() BaseWebViewScreen( - titleText = "验证码", + titleText = "磁力链接验证码", topAppBarActionButtonOnClick = { App.instance.openDrawerState() }, webViewClient = { captchaWebViewClient(it) }, - loadUrl = App.captchaUrl + loadUrl = "https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis() ) } @@ -218,7 +221,7 @@ fun CaptchaVideoWebViewScreen() { } cookieManager.flush() BaseWebViewScreen( - titleText = "验证码", + titleText = "视频播放验证码", topAppBarActionButtonOnClick = { App.instance.openDrawerState() }, @@ -247,7 +250,7 @@ fun captchaWebViewClient(webView: WebView): WebViewClient { val response = httpClient.newCall(a.build()).execute() val string = response.body.string() if (string.contains("{\"state\":true}")) { - App.selectedItem = "我的文件" + App.selectedItem = ConfigUtil.MY_FILE addTask() App.instance.toast("验证账号成功~,重新添加链接中.......") } diff --git a/app/src/main/java/github/zerorooot/nap511/screen/FileScreen.kt b/app/src/main/java/github/zerorooot/nap511/screen/FileScreen.kt index 00fb652..6dd3b75 100644 --- a/app/src/main/java/github/zerorooot/nap511/screen/FileScreen.kt +++ b/app/src/main/java/github/zerorooot/nap511/screen/FileScreen.kt @@ -188,7 +188,7 @@ fun FileScreen( fileViewModel.photoFileBeanList.clear() fileViewModel.photoFileBeanList.addAll(photoFileBeanList) fileViewModel.photoIndexOf = photoFileBeanList.indexOf(fileBean) - App.selectedItem = "photo" + App.selectedItem = ConfigUtil.PHOTO } // 打开种子文件 if (fileBean.fileIco == R.drawable.torrent) { diff --git a/app/src/main/java/github/zerorooot/nap511/screen/OfflineFileScreen.kt b/app/src/main/java/github/zerorooot/nap511/screen/OfflineFileScreen.kt index b96289c..c781628 100644 --- a/app/src/main/java/github/zerorooot/nap511/screen/OfflineFileScreen.kt +++ b/app/src/main/java/github/zerorooot/nap511/screen/OfflineFileScreen.kt @@ -27,6 +27,7 @@ import androidx.core.content.ContextCompat.getSystemService import github.zerorooot.nap511.R import github.zerorooot.nap511.screenitem.OfflineCellItem import github.zerorooot.nap511.util.App +import github.zerorooot.nap511.util.ConfigUtil import github.zerorooot.nap511.viewmodel.FileViewModel import github.zerorooot.nap511.viewmodel.OfflineFileViewModel import java.util.* @@ -51,7 +52,7 @@ fun OfflineFileScreen( val itemOnClick = { i: Int -> val offlineTask = offlineList[i] val cid = if (offlineTask.fileId == "") offlineTask.wpPathId else offlineTask.fileId - App.selectedItem = "我的文件" + App.selectedItem = ConfigUtil.MY_FILE fileViewModel.getFiles(cid) } val menuOnClick = { name: String, index: Int -> @@ -71,7 +72,8 @@ fun OfflineFileScreen( offlineList.forEach { i -> stringJoiner.add(i.url) } copyDownloadUrl(context, stringJoiner.toString()) } - "ModalNavigationDrawerMenu" -> App.instance.openDrawerState() + + "ModalNavigationDrawerMenu" -> App.instance.openDrawerState() } } diff --git a/app/src/main/java/github/zerorooot/nap511/screen/SettingScreen.kt b/app/src/main/java/github/zerorooot/nap511/screen/SettingScreen.kt index 931d74e..d693f40 100644 --- a/app/src/main/java/github/zerorooot/nap511/screen/SettingScreen.kt +++ b/app/src/main/java/github/zerorooot/nap511/screen/SettingScreen.kt @@ -108,7 +108,7 @@ fun SettingScreen() { if (DataStoreUtil.getData( ConfigUtil.offlineMethod, - false + true ) ) { prefsItem { diff --git a/app/src/main/java/github/zerorooot/nap511/util/App.kt b/app/src/main/java/github/zerorooot/nap511/util/App.kt index 0aa00b7..cee6110 100644 --- a/app/src/main/java/github/zerorooot/nap511/util/App.kt +++ b/app/src/main/java/github/zerorooot/nap511/util/App.kt @@ -28,14 +28,11 @@ class App : Application() { var uid by mutableStateOf("0") //页面导航 - var selectedItem by mutableStateOf("我的文件") + var selectedItem by mutableStateOf(ConfigUtil.MY_FILE) //页面手势 var gesturesEnabled by mutableStateOf(true) - //验证账号网址 - var captchaUrl by mutableStateOf("") - //每次请求文件数 var requestLimitCount: Int = 100 lateinit var drawerState: DrawerState @@ -72,7 +69,8 @@ class App : Application() { "https://passportapi.115.com/app/1.0/web/1.0/check/sso?_${System.currentTimeMillis() / 1000}" val okHttpClient = OkHttpClient() val request: Request = Request.Builder().url(url).addHeader("cookie", cookie) - .addHeader("Content-Type", "application/json; Charset=UTF-8").addHeader( + .addHeader("Content-Type", "application/json; Charset=UTF-8") + .addHeader( "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36 115Browser/23.9.3.6" ).get().build() diff --git a/app/src/main/java/github/zerorooot/nap511/util/ConfigUtil.kt b/app/src/main/java/github/zerorooot/nap511/util/ConfigUtil.kt index e8b9f67..3bf09b3 100644 --- a/app/src/main/java/github/zerorooot/nap511/util/ConfigUtil.kt +++ b/app/src/main/java/github/zerorooot/nap511/util/ConfigUtil.kt @@ -12,16 +12,30 @@ class ConfigUtil { const val command = "command" const val sentToAria2 = "sentToAria2" const val autoRotate = "autoRotate" + //默认离线位置 - const val defaultOfflineCid = "0" + const val defaultOfflineCid = "defaultOfflineCid" const val requestLimitCount = "requestLimitCount" const val defaultOfflineCount = "defaultOfflineCount" const val currentOfflineTask = "" const val offlineMethod = "offlineMethod" const val defaultOfflineTime = "defaultOfflineTime" const val errorDownloadCid = "errorDownloadCid" + //提前加载上下两个文件夹 - const val earlyLoading="EarlyLoading" + const val earlyLoading = "EarlyLoading" + + const val VERIFY_MAGNET_LINK_ACCOUNT = "磁力链接验证" + const val VERIFY_VIDEO_ACCOUNT = "视频播放验证" + const val LOGIN = "登录" + const val MY_FILE = "我的文件" + const val OFFLINE_DOWNLOAD = "离线下载" + const val OFFLINE_LIST = "离线列表" + const val WEB = "网页版" + const val RECYCLE_BIN="回收站" + const val ADVANCED_SETTINGS = "高级设置" + const val EXIT_APPLICATION = "退出应用" + const val PHOTO = "照片模式" } } \ No newline at end of file diff --git a/app/src/main/java/github/zerorooot/nap511/viewmodel/OfflineFileViewModel.kt b/app/src/main/java/github/zerorooot/nap511/viewmodel/OfflineFileViewModel.kt index e5efc7d..b824927 100644 --- a/app/src/main/java/github/zerorooot/nap511/viewmodel/OfflineFileViewModel.kt +++ b/app/src/main/java/github/zerorooot/nap511/viewmodel/OfflineFileViewModel.kt @@ -1,7 +1,6 @@ package github.zerorooot.nap511.viewmodel -import android.app.Activity import android.app.Application import android.widget.Toast import androidx.compose.runtime.getValue @@ -108,10 +107,8 @@ class OfflineFileViewModel(private val cookie: String, private val application: "任务添加成功,文件已保存至 /云下载/${torrentFileBean.torrentName}" } else { if (addTorrentTask.errorMsg.contains("请验证账号")) { - App.captchaUrl = - "https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis() //打开验证页面 - App.selectedItem = "captchaWebView" + App.selectedItem = ConfigUtil.VERIFY_MAGNET_LINK_ACCOUNT } "任务添加失败,${addTorrentTask.errorMsg}" } @@ -203,10 +200,7 @@ class OfflineFileViewModel(private val cookie: String, private val application: "任务添加成功" } else { if (addTask.errorMsg.contains("请验证账号") && !close) { - App.captchaUrl = - "https://captchaapi.115.com/?ac=security_code&type=web&cb=Close911_" + System.currentTimeMillis() - //打开验证页面 - App.selectedItem = "captchaWebView" + App.selectedItem = ConfigUtil.VERIFY_MAGNET_LINK_ACCOUNT } //把失败的离线链接保存起来 val currentOfflineTaskList = diff --git a/app/src/main/res/drawable/avatar.xml b/app/src/main/res/drawable/avatar.xml new file mode 100644 index 0000000..1a3d964 --- /dev/null +++ b/app/src/main/res/drawable/avatar.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_add_moderator_24.xml b/app/src/main/res/drawable/baseline_magent_moderator_24.xml similarity index 100% rename from app/src/main/res/drawable/baseline_add_moderator_24.xml rename to app/src/main/res/drawable/baseline_magent_moderator_24.xml diff --git a/app/src/main/res/drawable/baseline_video_moderator_24.xml b/app/src/main/res/drawable/baseline_video_moderator_24.xml new file mode 100644 index 0000000..b2cdc2c --- /dev/null +++ b/app/src/main/res/drawable/baseline_video_moderator_24.xml @@ -0,0 +1,10 @@ + + +