Skip to content

Commit

Permalink
更改抽屉页面
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 29, 2024
1 parent 33db40f commit 3ccb0a0
Show file tree
Hide file tree
Showing 17 changed files with 340 additions and 83 deletions.
3 changes: 3 additions & 0 deletions .idea/deploymentTargetSelector.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
269 changes: 228 additions & 41 deletions app/src/main/java/github/zerorooot/nap511/MainActivity.kt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -85,6 +86,7 @@ class OfflineTaskActivity : Activity() {
val clip = ClipData.newPlainText("label", intent.getStringExtra("link"))
clipboard?.setPrimaryClip(clip)
}
moveTaskToBack(true);
finishAndRemoveTask()
}

Expand Down Expand Up @@ -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
Expand All @@ -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())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class TorrentTaskActivity : Activity() {
val defaultOfflineCid = DataStoreUtil.getData(ConfigUtil.defaultOfflineCid, "0")
initUpload(torrentFile, App.cookie, uid, defaultOfflineCid)
}
moveTaskToBack(true);
finishAndRemoveTask()
}

Expand Down
30 changes: 19 additions & 11 deletions app/src/main/java/github/zerorooot/nap511/bean/Bean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand All @@ -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<FileBean>,
var cid: String,
Expand Down
19 changes: 17 additions & 2 deletions app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -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?",
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
}
Expand Down Expand Up @@ -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")
Expand All @@ -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)
}
Expand All @@ -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()
)

}
Expand All @@ -218,7 +221,7 @@ fun CaptchaVideoWebViewScreen() {
}
cookieManager.flush()
BaseWebViewScreen(
titleText = "验证码",
titleText = "视频播放验证码",
topAppBarActionButtonOnClick = {
App.instance.openDrawerState()
},
Expand Down Expand Up @@ -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("验证账号成功~,重新添加链接中.......")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand All @@ -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 ->
Expand All @@ -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()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ fun SettingScreen() {

if (DataStoreUtil.getData(
ConfigUtil.offlineMethod,
false
true
)
) {
prefsItem {
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/github/zerorooot/nap511/util/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 16 additions & 2 deletions app/src/main/java/github/zerorooot/nap511/util/ConfigUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "照片模式"

}
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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}"
}
Expand Down Expand Up @@ -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 =
Expand Down
Loading

0 comments on commit 3ccb0a0

Please sign in to comment.