Skip to content

Commit

Permalink
支持复制无头磁力链接
Browse files Browse the repository at this point in the history
  • Loading branch information
Your Name committed May 24, 2024
1 parent ff22832 commit 91d0987
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
4 changes: 1 addition & 3 deletions app/src/main/java/github/zerorooot/nap511/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package github.zerorooot.nap511

import android.annotation.SuppressLint
import android.app.Activity
import android.app.AppOpsManager
import android.content.Context
import android.content.Intent
Expand All @@ -14,7 +13,6 @@ import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.google.accompanist.systemuicontroller.rememberSystemUiController
Expand Down Expand Up @@ -273,7 +271,7 @@ class MainActivity : ComponentActivity() {
"selectToDown" -> fileViewModel.selectToDown()
"cut" -> fileViewModel.cut()
//具体实现在FileScreen#CreateDialogs()里
"search" -> fileViewModel.isSearch = true
"search" -> fileViewModel.isOpenSearchDialog = true
"delete" -> fileViewModel.deleteMultiple()
"selectAll" -> fileViewModel.selectAll()
"selectReverse" -> fileViewModel.selectReverse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ class OfflineTaskActivity : Activity() {
if (intent.action == Intent.ACTION_VIEW || intent.action == Intent.ACTION_PROCESS_TEXT) {
val urlList = (intent.dataString ?: run {
intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT)
} ?: run { "" }).split("\n").filter { i ->
} ?: run { "" }).split("\n").map { i ->
//支持复制无头磁力链接
val a = i.replace(Regex("&dn=.*"), "")
if (a.length == 40 && Regex("^[a-z0-9A-Z]+\$").matches(a)) {
"magnet:?xt=urn:btih:$i"
} else {
i
}
}.filter { i ->
i.startsWith("http", true) || i.startsWith(
"ftp", true
) || i.startsWith("magnet", true) || i.startsWith("ed2k", true)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package github.zerorooot.nap511.screen

import android.app.Activity
import android.app.Application
import androidx.compose.animation.*
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.*
import androidx.compose.foundation.selection.selectable
Expand Down Expand Up @@ -37,7 +35,6 @@ import github.zerorooot.nap511.viewmodel.FileViewModel
import github.zerorooot.nap511.viewmodel.OfflineFileViewModel
import github.zerorooot.nap511.viewmodel.RecycleViewModel
import kotlinx.coroutines.delay
import kotlin.system.exitProcess

@Composable
fun CreateFolderDialog(fileViewModel: FileViewModel, enter: (String) -> Unit) {
Expand All @@ -48,7 +45,7 @@ fun CreateFolderDialog(fileViewModel: FileViewModel, enter: (String) -> Unit) {

@Composable
fun SearchDialog(fileViewModel: FileViewModel, enter: (String) -> Unit) {
if (fileViewModel.isSearch) {
if (fileViewModel.isOpenSearchDialog) {
BaseDialog("在当前目录下搜索", "关键字", enter = enter)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.togetherWith
import androidx.compose.animation.with
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -370,7 +369,7 @@ fun CreateDialogs(fileViewModel: FileViewModel) {
if (it != "") {
fileViewModel.search(it)
}
fileViewModel.isSearch = false
fileViewModel.isOpenSearchDialog = false
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class FileViewModel(private val cookie: String, private val application: Applica
var isOpenAria2Dialog by mutableStateOf(false)
var selectIndex by mutableIntStateOf(0)

var isSearch by mutableStateOf(false)
var isOpenSearchDialog by mutableStateOf(false)


//图片浏览相关
Expand Down Expand Up @@ -349,7 +349,7 @@ class FileViewModel(private val cookie: String, private val application: Applica
isCutState = false
return
}

isCutState = false
viewModelScope.launch {
val hashMapOf = hashMapOf<String, String>()
hashMapOf["pid"] = currentCid
Expand All @@ -376,7 +376,6 @@ class FileViewModel(private val cookie: String, private val application: Applica
} else {
"移动失败~"
}
isCutState = false
Toast.makeText(application, message, Toast.LENGTH_SHORT).show()
}
}
Expand Down Expand Up @@ -513,7 +512,7 @@ class FileViewModel(private val cookie: String, private val application: Applica
setFileBeanProperty(files.fileBeanList)
fileBeanList.clear()
fileBeanList.addAll(files.fileBeanList)
appBarTitle = "搜索"
appBarTitle = "搜索-$searchKey"
}
}

Expand Down

0 comments on commit 91d0987

Please sign in to comment.