Skip to content

Commit

Permalink
支持显示会员到期时间(从老版本升级上来的,需要重新登陆才能正常显示)
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed Nov 30, 2024
1 parent 3ccb0a0 commit 5cbdd28
Show file tree
Hide file tree
Showing 19 changed files with 467 additions and 372 deletions.
204 changes: 80 additions & 124 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 @@ -8,7 +8,6 @@ import android.app.NotificationManager
import android.app.PendingIntent
import android.content.ClipData
import android.content.ClipboardManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.os.Bundle
Expand All @@ -29,14 +28,13 @@ import github.zerorooot.nap511.R
import github.zerorooot.nap511.bean.BaseReturnMessage
import github.zerorooot.nap511.bean.SignBean
import github.zerorooot.nap511.util.App
import github.zerorooot.nap511.util.ConfigUtil
import github.zerorooot.nap511.util.ConfigKeyUtil
import github.zerorooot.nap511.util.DataStoreUtil
import okhttp3.FormBody
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 @@ -64,15 +62,15 @@ class OfflineTaskActivity : Activity() {
//非空列表
if (urlList.isNotEmpty()) {
val currentOfflineTaskList =
DataStoreUtil.getData(ConfigUtil.currentOfflineTask, "")
DataStoreUtil.getData(ConfigKeyUtil.CURRENT_OFFLINE_TASK, "")
.split("\n")
.filter { i -> i != "" && i != " " }
.toSet()
.toMutableSet()
//添加所有
currentOfflineTaskList.addAll(urlList)
//离线任务缓存方式,true为x分钟后统一下载,false为集满后统一下载
if (DataStoreUtil.getData(ConfigUtil.offlineMethod, true)) {
if (DataStoreUtil.getData(ConfigKeyUtil.OFFLINE_METHOD, true)) {
addOfflineTaskByTime(currentOfflineTaskList.toList())
} else {
addOfflineTaskByCount(currentOfflineTaskList.toList())
Expand All @@ -86,23 +84,27 @@ class OfflineTaskActivity : Activity() {
val clip = ClipData.newPlainText("label", intent.getStringExtra("link"))
clipboard?.setPrimaryClip(clip)
}
moveTaskToBack(true);
//通过ACTION_PROCESS_TEXT添加磁力链接时,如果moveTaskToBack(true),当前应用会回到桌面
if (intent.action != Intent.ACTION_PROCESS_TEXT){
moveTaskToBack(true);
}

finishAndRemoveTask()
}

@SuppressLint("EnqueueWork")
private fun addOfflineTaskByTime(currentOfflineTaskList: List<String>) {
//检查离线任务时间
val offlineTime = try {
DataStoreUtil.getData(ConfigUtil.defaultOfflineTime, "5").toLong()
DataStoreUtil.getData(ConfigKeyUtil.DEFAULT_OFFLINE_TIME, "5").toLong()
} catch (e: Exception) {
5L
}
val stringJoiner = StringJoiner("\n")
currentOfflineTaskList.toSet().forEach { stringJoiner.add(it) }
//写入缓存
DataStoreUtil.putData(
ConfigUtil.currentOfflineTask,
ConfigKeyUtil.CURRENT_OFFLINE_TASK,
stringJoiner.toString()
)

Expand All @@ -127,7 +129,7 @@ class OfflineTaskActivity : Activity() {
private fun addOfflineTaskByCount(currentOfflineTaskList: List<String>) {
//检查离线任务缓存数
val offlineCount = try {
DataStoreUtil.getData(ConfigUtil.defaultOfflineCount, "5").toInt()
DataStoreUtil.getData(ConfigKeyUtil.DEFAULT_OFFLINE_COUNT, "5").toInt()
} catch (e: Exception) {
5
}
Expand All @@ -153,7 +155,7 @@ class OfflineTaskActivity : Activity() {
currentOfflineTaskList.forEach { stringJoiner.add(it) }
//写入缓存
DataStoreUtil.putData(
ConfigUtil.currentOfflineTask,
ConfigKeyUtil.CURRENT_OFFLINE_TASK,
stringJoiner.toString()
)
App.instance.toast("已添加${currentOfflineTaskList.size}个链接到缓存中,剩余${offlineCount - currentOfflineTaskList.size}")
Expand All @@ -175,7 +177,7 @@ class OfflineTaskWorker(
if (message.contains("任务添加成功")) {
//清空缓存
DataStoreUtil.putData(
ConfigUtil.currentOfflineTask,
ConfigKeyUtil.CURRENT_OFFLINE_TASK,
""
)
}
Expand Down Expand Up @@ -248,9 +250,9 @@ class OfflineTaskWorker(

private fun addTask(urlList: List<String>, cookie: String): Data {
val resultMessage = StringJoiner("\n")
val errorDownloadCid = DataStoreUtil.getData(ConfigUtil.errorDownloadCid, "")
val errorDownloadCid = DataStoreUtil.getData(ConfigKeyUtil.ERROR_DOWNLOAD_CID, "")
val cid = if (errorDownloadCid == "") {
DataStoreUtil.getData(ConfigUtil.defaultOfflineCid, "")
DataStoreUtil.getData(ConfigKeyUtil.DEFAULT_OFFLINE_CID, "")
} else {
errorDownloadCid
}
Expand All @@ -261,7 +263,7 @@ class OfflineTaskWorker(
val map = HashMap<String, String>()
map["savepath"] = ""
map["wp_path_id"] = cid
map["uid"] = DataStoreUtil.getData(ConfigUtil.uid, "")
map["uid"] = DataStoreUtil.getData(ConfigKeyUtil.UID, "")
map["sign"] = getSign(cookie).sign
map["time"] = (System.currentTimeMillis() / 1000).toString()
urlList.forEachIndexed { index, s ->
Expand All @@ -270,7 +272,7 @@ class OfflineTaskWorker(
val addTask = addTask(cookie, map)
val message = if (addTask.state) {
//清除下载失败的cid
DataStoreUtil.putData(ConfigUtil.errorDownloadCid, "")
DataStoreUtil.putData(ConfigKeyUtil.ERROR_DOWNLOAD_CID, "")
"任务添加成功"
} else {
"任务添加失败,${addTask.errorMsg}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import com.google.gson.Gson
import github.zerorooot.nap511.bean.BaseReturnMessage
import github.zerorooot.nap511.bean.InitUploadBean
import github.zerorooot.nap511.util.App
import github.zerorooot.nap511.util.ConfigUtil
import github.zerorooot.nap511.util.ConfigKeyUtil
import github.zerorooot.nap511.util.DataStoreUtil
import okhttp3.Call
import okhttp3.Callback
Expand All @@ -33,7 +33,7 @@ class TorrentTaskActivity : Activity() {
if (intent.action == Intent.ACTION_VIEW && intent.data != null) {
val torrentFile = fileFromContentUri(this, intent.data!!)
val uid = App.uid
val defaultOfflineCid = DataStoreUtil.getData(ConfigUtil.defaultOfflineCid, "0")
val defaultOfflineCid = DataStoreUtil.getData(ConfigKeyUtil.DEFAULT_OFFLINE_CID, "0")
initUpload(torrentFile, App.cookie, uid, defaultOfflineCid)
}
moveTaskToBack(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package github.zerorooot.nap511.activity
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.addCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.lifecycleScope
Expand All @@ -13,7 +12,7 @@ import com.shuyu.gsyvideoplayer.player.PlayerFactory
import com.shuyu.gsyvideoplayer.utils.OrientationUtils
import github.zerorooot.nap511.R
import github.zerorooot.nap511.service.VideoService
import github.zerorooot.nap511.util.ConfigUtil
import github.zerorooot.nap511.util.ConfigKeyUtil
import github.zerorooot.nap511.util.DataStoreUtil
import kotlinx.coroutines.launch
import tv.danmaku.ijk.media.exo2.Exo2PlayerManager
Expand Down Expand Up @@ -66,7 +65,7 @@ class VideoActivity : AppCompatActivity() {

videoPlayer.startPlayLogic()

if (DataStoreUtil.getData(ConfigUtil.autoRotate, false)){
if (DataStoreUtil.getData(ConfigKeyUtil.AUTO_ROTATE, false)){
//设置竖屏
lifecycleScope.launch {
val videoInfo = videoService.videoInfo(pickCode)
Expand Down
48 changes: 11 additions & 37 deletions app/src/main/java/github/zerorooot/nap511/bean/Bean.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,49 +9,23 @@ import okhttp3.RequestBody
import okhttp3.RequestBody.Companion.toRequestBody


data class LoginCookie(
@SerializedName("UID")
var uID: String? = null,
@SerializedName("CID")
var cID: String? = null,
@SerializedName("SEID")
var sEID: String? = null,
) {
override fun toString(): String {
return "UID=$uID;CID=$cID;SEID=$sEID"
}
}


data class LoginData(
var user_id: String = "0",
var user_name: String = "TestTest",
var user_face: String = "",
var cookie: LoginCookie? = null,
)


data class LoginBean(
var state: Int = 0,
@SerializedName("data")
var data: LoginData = LoginData(),
var message: String = ""
)

data class AvatarBean(
var state: Boolean = false,
@SerializedName("data")
var data: LoginData = LoginData(),
var message: String = ""
var expire: Long = 1L,
var expireString: String = "1970-01-01 08:00:00",
@SerializedName("user_name")
var userName: String = "Test",
var face: String = "https://my.115.com/static/2014v1.0/personal/head/80/male/male034.png",
@SerializedName("user_id")
var userId: String = "0"
)

data class InfoBean(
data class RemainingSpaceBean(
var allRemain: Long = 1L,
var allRemainString: String = "",
var allRemainString: String = "1T",
var allTotal: Long = 1L,
var allTotalString: String = "",
var allTotalString: String = "1T",
var allUse: Long = 1L,
var allUseString: String = "",
var allUseString: String = "1T",
)


Expand Down
33 changes: 4 additions & 29 deletions app/src/main/java/github/zerorooot/nap511/screen/AlertDialog.kt
Original file line number Diff line number Diff line change
@@ -1,53 +1,35 @@
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
import androidx.compose.foundation.selection.selectable
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Delete
import androidx.compose.material.icons.outlined.CheckBox
import androidx.compose.material.icons.outlined.CheckBoxOutlineBlank
import androidx.compose.material.icons.outlined.CheckCircle
import androidx.compose.material.icons.outlined.RadioButtonUnchecked
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Button
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
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableLongStateOf
import androidx.compose.runtime.mutableStateMapOf
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -57,10 +39,6 @@ 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 @@ -80,13 +58,11 @@ import github.zerorooot.nap511.bean.TorrentFileBean
import github.zerorooot.nap511.bean.TorrentFileListWeb
import github.zerorooot.nap511.screenitem.AutoSizableTextField
import github.zerorooot.nap511.util.App
import github.zerorooot.nap511.util.ConfigUtil
import github.zerorooot.nap511.util.ConfigKeyUtil
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
Expand Down Expand Up @@ -168,12 +144,11 @@ fun ExitApp() {
mutableStateOf(true)
}

val activity = LocalContext.current as Activity
if (isOpen) {
InfoDialog(
onDismissRequest = {
isOpen = false
App.selectedItem = ConfigUtil.MY_FILE
App.selectedItem = ConfigKeyUtil.MY_FILE
},
onConfirmation = {
android.os.Process.killProcess(android.os.Process.myPid());
Expand Down Expand Up @@ -242,8 +217,8 @@ fun Aria2Dialog(fileViewModel: FileViewModel, context: String, enter: (String) -
}, confirmButton = {
Button(onClick = {
val jsonObject = JsonObject()
jsonObject.addProperty(ConfigUtil.aria2Url, urlText.text)
jsonObject.addProperty(ConfigUtil.aria2Token, tokenText.text)
jsonObject.addProperty(ConfigKeyUtil.ARIA2_URL, urlText.text)
jsonObject.addProperty(ConfigKeyUtil.ARIA2_TOKEN, tokenText.text)
enter.invoke(jsonObject.toString())
urlText = TextFieldValue("")
tokenText = TextFieldValue("")
Expand Down
Loading

0 comments on commit 5cbdd28

Please sign in to comment.