This commit is contained in:
Kagura 2024-10-10 13:01:51 +08:00
parent 3242c9f4a0
commit f133a4446b
32 changed files with 260 additions and 459 deletions

View file

@ -1,15 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> 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" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO"/>
<application <application
android:allowBackup="true" android:allowBackup="true"
@ -21,6 +12,11 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.MyApplication" android:theme="@style/Theme.MyApplication"
tools:targetApi="31"> tools:targetApi="31">
<activity
android:name=".compose.SearchActivity"
android:exported="false"
android:label="@string/title_activity_search"
android:theme="@style/Theme.MyApplication" />
<activity <activity
android:name=".compose.RequirePermissionActivity" android:name=".compose.RequirePermissionActivity"
android:exported="true" android:exported="true"
@ -34,36 +30,27 @@
<activity <activity
android:name=".compose.ViewFileActivity" android:name=".compose.ViewFileActivity"
android:exported="false" /> android:exported="false" />
<activity
android:name=".main_page"
android:exported="false" />
<activity <activity
android:name=".store_page" android:name=".store_page"
android:exported="false" /> android:exported="false" />
<activity
android:name=".document_page_search"
android:exported="false" />
<activity <activity
android:name=".document_page" android:name=".document_page"
android:exported="false" /> android:exported="false" />
<activity
android:name=".music_page_search"
android:exported="false" />
<activity
android:name=".music_page"
android:exported="false" />
<activity
android:name=".video_page_search"
android:exported="false" />
<activity
android:name=".picture_page_search"
android:exported="false" />
<activity
android:name=".main_page"
android:exported="false" />
<activity <activity
android:name=".picture_page" android:name=".picture_page"
android:exported="false" /> android:exported="false" />
<activity <activity
android:name=".video_page" android:name=".video_page"
android:exported="false" /> android:exported="false" />
<activity
android:name=".music_page"
android:exported="false" />
<provider <provider
android:name="androidx.core.content.FileProvider" android:name="androidx.core.content.FileProvider"
@ -75,4 +62,15 @@
android:resource="@xml/provider_paths" /> android:resource="@xml/provider_paths" />
</provider> </provider>
</application> </application>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission
android:name="android.permission.MANAGE_EXTERNAL_STORAGE"
tools:ignore="ScopedStorage" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
</manifest> </manifest>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

View file

@ -6,7 +6,7 @@ import java.io.FileOutputStream
import java.nio.channels.FileChannel import java.nio.channels.FileChannel
class PasteHelper { class PasteHelper {
companion object{ companion object {
fun copyDirectory(sourceDir: File, destDir: File) { fun copyDirectory(sourceDir: File, destDir: File) {
// creates the destination directory if it does not exist // creates the destination directory if it does not exist
if (!destDir.exists()) { if (!destDir.exists()) {
@ -40,7 +40,7 @@ class PasteHelper {
} }
} }
private fun copySingleFile(sourceFile: File, destFile: File){ private fun copySingleFile(sourceFile: File, destFile: File) {
if (!destFile.exists()) { if (!destFile.exists()) {
destFile.createNewFile() destFile.createNewFile()
} }

View file

@ -44,7 +44,8 @@ class RequirePermissionActivity : ComponentActivity() {
window.statusBarColor = getColor(R.color.WhiteSmoke) window.statusBarColor = getColor(R.color.WhiteSmoke)
setContent { setContent {
Column( Column(
modifier = Modifier.statusBarsPadding() modifier = Modifier
.statusBarsPadding()
.fillMaxHeight(0.9f) .fillMaxHeight(0.9f)
.fillMaxWidth(), .fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally, horizontalAlignment = Alignment.CenterHorizontally,
@ -72,7 +73,11 @@ class RequirePermissionActivity : ComponentActivity() {
startActivity(intent) startActivity(intent)
} }
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
val perm33 = arrayOf(permission.READ_MEDIA_AUDIO,permission.READ_MEDIA_VIDEO,permission.READ_MEDIA_IMAGES) val perm33 = arrayOf(
permission.READ_MEDIA_AUDIO,
permission.READ_MEDIA_VIDEO,
permission.READ_MEDIA_IMAGES
)
ActivityCompat.requestPermissions( ActivityCompat.requestPermissions(
activity, perm33, 101 activity, perm33, 101
) )
@ -96,7 +101,6 @@ class RequirePermissionActivity : ComponentActivity() {
} }
} }
} }
} }
override fun onResume() { override fun onResume() {
@ -119,7 +123,11 @@ fun checkPermissions(context: Context): Boolean {
return false return false
} }
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) { if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
val perm33 = arrayOf(permission.READ_MEDIA_AUDIO,permission.READ_MEDIA_VIDEO,permission.READ_MEDIA_IMAGES) val perm33 = arrayOf(
permission.READ_MEDIA_AUDIO,
permission.READ_MEDIA_VIDEO,
permission.READ_MEDIA_IMAGES
)
perm33.forEach { perm33.forEach {
if (context.checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED) { if (context.checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED) {
return false return false
@ -137,7 +145,7 @@ fun checkPermissions(context: Context): Boolean {
return true return true
} }
fun initSystem(){ fun initSystem() {
ImageLister.instance.initialize() ImageLister.instance.initialize()
VideoLister.instance.initialize() VideoLister.instance.initialize()
MusicLister.instance.initialize() MusicLister.instance.initialize()

View file

@ -0,0 +1,29 @@
package com.example.myapplication.compose
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister
import com.example.myapplication.fileSystem.byTypeFileLister.ImageLister
import com.example.myapplication.fileSystem.byTypeFileLister.MusicLister
import com.example.myapplication.fileSystem.byTypeFileLister.VideoLister
class SearchActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val type = intent.extras?.getString("type")
val searchTypeRegex: Regex? = when (type) {
"music" -> MusicLister.regex
"image" -> ImageLister.regex
"video" -> VideoLister.regex
"document" -> DocumentLister.regex
else -> null
}
enableEdgeToEdge()
setContent {
}
}
}

View file

@ -20,7 +20,7 @@ class ViewFileActivity : ComponentActivity() {
var path = var path =
intent.extras?.getString("folder") ?: Environment.getExternalStorageDirectory().path intent.extras?.getString("folder") ?: Environment.getExternalStorageDirectory().path
val file = File(path) val file = File(path)
if (!file.isDirectory){ if (!file.isDirectory) {
path = Environment.getExternalStorageDirectory().path path = Environment.getExternalStorageDirectory().path
} }
enableEdgeToEdge() enableEdgeToEdge()
@ -30,7 +30,7 @@ class ViewFileActivity : ComponentActivity() {
modifier = Modifier modifier = Modifier
.fillMaxSize() .fillMaxSize()
.background(Color(getColor(R.color.WhiteSmoke))) .background(Color(getColor(R.color.WhiteSmoke)))
){ ) {
FileColumn(this).Draw(path) FileColumn(this).Draw(path)
} }
} }

View file

@ -1,5 +1,6 @@
package com.example.myapplication.compose.ui package com.example.myapplication.compose.ui
import android.annotation.SuppressLint
import android.content.ClipData import android.content.ClipData
import android.content.ClipDescription import android.content.ClipDescription
import android.content.Context import android.content.Context
@ -160,7 +161,7 @@ class FileColumn(val context: Context) {
} }
} }
private companion object{ private companion object {
var dropTarget: String? = null var dropTarget: String? = null
} }
@ -177,7 +178,7 @@ class FileColumn(val context: Context) {
object : DragAndDropTarget { object : DragAndDropTarget {
override fun onDrop(event: DragAndDropEvent): Boolean { override fun onDrop(event: DragAndDropEvent): Boolean {
val target = File(dropTarget ?: return false) val target = File(dropTarget ?: return false)
if (!target.exists()){ if (!target.exists()) {
return false.also { return false.also {
dropTarget = null dropTarget = null
} }
@ -197,7 +198,7 @@ class FileColumn(val context: Context) {
} }
} }
if (source.path == target.path){ if (source.path == target.path) {
dropTarget = null dropTarget = null
return false return false
} }
@ -206,14 +207,14 @@ class FileColumn(val context: Context) {
if (source.isFile) { if (source.isFile) {
val dir = source.parent ?: return false val dir = source.parent ?: return false
val f = File("$dir/合并文件夹") val f = File("$dir/合并文件夹")
if (!f.exists()){ if (!f.exists()) {
f.mkdir() f.mkdir()
} }
ClipHelper.getInstance(context).copy(source,context) ClipHelper.getInstance(context).copy(source, context)
val sourceUri = ClipHelper.getInstance(context).paste() ?: return false val sourceUri = ClipHelper.getInstance(context).paste() ?: return false
val inputStream = try { val inputStream = try {
context.contentResolver.openInputStream(sourceUri) context.contentResolver.openInputStream(sourceUri)
}catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
return false.also { return false.also {
dropTarget = null dropTarget = null
} }
@ -223,7 +224,7 @@ class FileColumn(val context: Context) {
actualFile.writeBytes(IOUtils.toByteArray(inputStream)) actualFile.writeBytes(IOUtils.toByteArray(inputStream))
inputStream.close() inputStream.close()
} }
ClipHelper.getInstance(context).copy(target,context) ClipHelper.getInstance(context).copy(target, context)
val targetUri = ClipHelper.getInstance(context).paste() ?: return false val targetUri = ClipHelper.getInstance(context).paste() ?: return false
val inputStream2 = context.contentResolver.openInputStream(targetUri) val inputStream2 = context.contentResolver.openInputStream(targetUri)
if (inputStream2 != null) { if (inputStream2 != null) {
@ -237,13 +238,13 @@ class FileColumn(val context: Context) {
Toast.LENGTH_SHORT Toast.LENGTH_SHORT
).show() ).show()
} else if (source.isDirectory) { } else if (source.isDirectory) {
ClipHelper.getInstance(context).copy(target,context) ClipHelper.getInstance(context).copy(target, context)
val sourceUri = ClipHelper.getInstance(context).paste() ?: return false.also { val sourceUri = ClipHelper.getInstance(context).paste() ?: return false.also {
dropTarget = null dropTarget = null
} }
val inputStream = try { val inputStream = try {
context.contentResolver.openInputStream(sourceUri) context.contentResolver.openInputStream(sourceUri)
}catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
return false.also { return false.also {
dropTarget = null dropTarget = null
} }
@ -261,13 +262,13 @@ class FileColumn(val context: Context) {
} }
} else if (target.isDirectory) { } else if (target.isDirectory) {
if (source.isFile) { if (source.isFile) {
ClipHelper.getInstance(context).copy(source,context) ClipHelper.getInstance(context).copy(source, context)
val sourceUri = ClipHelper.getInstance(context).paste() ?: return false.also { val sourceUri = ClipHelper.getInstance(context).paste() ?: return false.also {
dropTarget = null dropTarget = null
} }
val inputStream = try { val inputStream = try {
context.contentResolver.openInputStream(sourceUri) context.contentResolver.openInputStream(sourceUri)
}catch (e: FileNotFoundException) { } catch (e: FileNotFoundException) {
return false.also { return false.also {
dropTarget = null dropTarget = null
} }
@ -349,8 +350,7 @@ class FileColumn(val context: Context) {
) )
) )
}) })
} },
,
dragAndDropCallBack = dragAndDropCallBack, dragAndDropCallBack = dragAndDropCallBack,
onItemClick = onItemClick onItemClick = onItemClick
) )
@ -367,7 +367,7 @@ class FileColumn(val context: Context) {
forceName: String? = null, forceName: String? = null,
forceParent: String? = null, forceParent: String? = null,
update: (() -> Unit)? = null, update: (() -> Unit)? = null,
dragAndDrop: Modifier = Modifier, @SuppressLint("ModifierParameter") dragAndDrop: Modifier = Modifier,
dragAndDropCallBack: DragAndDropTarget? = null, dragAndDropCallBack: DragAndDropTarget? = null,
onItemClick: ((String) -> Unit)? = null onItemClick: ((String) -> Unit)? = null
) { ) {
@ -443,7 +443,8 @@ class FileColumn(val context: Context) {
.padding(vertical = 3.dp) .padding(vertical = 3.dp)
.clickable { .clickable {
onItemClick?.invoke(file.path) onItemClick?.invoke(file.path)
}.then( }
.then(
if (dragAndDropCallBack != null) { if (dragAndDropCallBack != null) {
Modifier.dragAndDropTarget( Modifier.dragAndDropTarget(
shouldStartDragAndDrop = { event -> shouldStartDragAndDrop = { event ->
@ -456,12 +457,10 @@ class FileColumn(val context: Context) {
result result
}, target = dragAndDropCallBack }, target = dragAndDropCallBack
) )
}else{ } else {
Modifier Modifier
} }
) ),
,
verticalAlignment = Alignment.CenterVertically, verticalAlignment = Alignment.CenterVertically,
) { ) {
Image( Image(
@ -509,9 +508,6 @@ class FileColumn(val context: Context) {
if (f.isFile) { if (f.isFile) {
ClipHelper.getInstance(context).copy(f, context) ClipHelper.getInstance(context).copy(f, context)
} }
},
onPaste = {
}, },
onDelete = { onDelete = {
AlertHelper.showDeleteAlert(context, file.path) { AlertHelper.showDeleteAlert(context, file.path) {
@ -533,9 +529,6 @@ class FileColumn(val context: Context) {
if (f.isDirectory) { if (f.isDirectory) {
ClipHelper.getInstance(context).copyFolder(f.path) ClipHelper.getInstance(context).copyFolder(f.path)
} }
},
onPaste = {
}, },
onDelete = { onDelete = {
AlertHelper.showDeleteAlert(context, file.path) { AlertHelper.showDeleteAlert(context, file.path) {

View file

@ -1,11 +1,11 @@
package com.example.myapplication package com.example.myapplication
import android.annotation.SuppressLint
import android.content.ActivityNotFoundException import android.content.ActivityNotFoundException
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.util.Log
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.GridView import android.widget.GridView
@ -21,6 +21,7 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.DocumentAdapter import com.example.myapplication.adapters.DocumentAdapter
import com.example.myapplication.adapters.DocumentModel import com.example.myapplication.adapters.DocumentModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion.instance import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion.instance
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion.regex import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion.regex
@ -71,9 +72,12 @@ class document_page : AppCompatActivity() {
searchImageView.setOnClickListener { v: View? -> searchImageView.setOnClickListener { v: View? ->
val intent = val intent =
Intent( Intent(
this@document_page, this,
document_page_search::class.java SearchActivity::class.java
) )
val bundle = Bundle()
bundle.putString("type", "document")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面 startActivity(intent) // 跳转到搜索页面
} }
@ -93,7 +97,8 @@ class document_page : AppCompatActivity() {
file file
) )
val intent = Intent(Intent.ACTION_VIEW) val intent = Intent(Intent.ACTION_VIEW)
intent.setDataAndType(uri, when(file.extension){ intent.setDataAndType(
uri, when (file.extension) {
"xls" -> "application/vnd.ms-excel" "xls" -> "application/vnd.ms-excel"
"xlsx" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" "xlsx" -> "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
"doc" -> "application/msword" "doc" -> "application/msword"
@ -101,15 +106,18 @@ class document_page : AppCompatActivity() {
"ppt" -> "application/vnd.ms-powerpoint" "ppt" -> "application/vnd.ms-powerpoint"
"pptx" -> "application/vnd.openxmlformats-officedocument.presentationml.presentation" "pptx" -> "application/vnd.openxmlformats-officedocument.presentationml.presentation"
"txt" -> "text/plain" "txt" -> "text/plain"
"htm","html" -> "text/html" "htm", "html" -> "text/html"
"pdf" -> "application/pdf" "pdf" -> "application/pdf"
else -> "application/*" else -> "application/*"
}) }
)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION) intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
try { startActivity(intent) } try {
catch (e: ActivityNotFoundException){ startActivity(intent)
Toast.makeText(baseContext,"没有安装可以打开此类型文件的应用",Toast.LENGTH_SHORT).show() } catch (e: ActivityNotFoundException) {
Toast.makeText(baseContext, "没有安装可以打开此类型文件的应用", Toast.LENGTH_SHORT)
.show()
} }
} }
} }
@ -125,7 +133,7 @@ class document_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText) val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) } launch { loadingText(loadingTextView, defaultText) }
documentList = instance.dateOrderedList() documentList = instance.dateOrderedList()
val models = ArrayList<DocumentModel>() val models = ArrayList<DocumentModel>()
for (path in documentList) { for (path in documentList) {
@ -133,8 +141,7 @@ class document_page : AppCompatActivity() {
} }
runOnUiThread { runOnUiThread {
val adapter = DocumentAdapter(this@document_page, models) val adapter = DocumentAdapter(this@document_page, models)
val grid = findViewById<GridView>(R.id.DocumentGrid) documentGrid.setAdapter(adapter)
grid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
} }
} }
@ -157,7 +164,7 @@ class document_page : AppCompatActivity() {
} }
val name = uri.path?.split('/')?.last() ?: "somePastedItem" val name = uri.path?.split('/')?.last() ?: "somePastedItem"
val ext = name.split('.').last() val ext = name.split('.').last()
if (!"$ext.".matches(regex)){ if (!"$ext.".matches(regex)) {
Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT)
.show() .show()
return@showItemAlert return@showItemAlert
@ -201,12 +208,17 @@ class document_page : AppCompatActivity() {
when (which) { when (which) {
0 -> { 0 -> {
listOrderType = 0 listOrderType = 0
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@document_page, this@document_page,
@ -219,12 +231,17 @@ class document_page : AppCompatActivity() {
1 -> { 1 -> {
listOrderType = 1 listOrderType = 1
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@document_page, this@document_page,
@ -242,7 +259,7 @@ class document_page : AppCompatActivity() {
.show() .show()
} }
private fun update(runSomethingMore: (()->Unit)? = null) { private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize { instance.initialize {
documentList = when (listOrderType) { documentList = when (listOrderType) {
0 -> instance.dateOrderedList() 0 -> instance.dateOrderedList()
@ -262,6 +279,7 @@ class document_page : AppCompatActivity() {
} }
} }
@SuppressLint("SetTextI18n")
private fun loadingText( private fun loadingText(
loadingTextView: TextView, loadingTextView: TextView,
defaultText: CharSequence, defaultText: CharSequence,

View file

@ -1,44 +0,0 @@
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class document_page_search extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.document_page_search);
// 设置左箭头的点击事件返回上一级页面
ImageView leftArrowImageView = findViewById(R.id.leftArrowImageView);
leftArrowImageView.setOnClickListener(v -> {
Intent intent = new Intent(document_page_search.this, document_page.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
});
SearchView searchView = findViewById(R.id.searchDocument); // 确保使用正确的 ID
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// 处理搜索提交
Toast.makeText(document_page_search.this, "搜索: " + query, Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// 处理搜索文本变化
// 可以在这里添加过滤逻辑
return false;
}
});
}
}

View file

@ -7,23 +7,23 @@ import com.example.myapplication.utils.ClipHelper
import java.io.File import java.io.File
class DeleteHelper { class DeleteHelper {
companion object{ companion object {
fun delete(path: String){ fun delete(path: String) {
val file = File(path) val file = File(path)
if (file.isFile){ if (file.isFile) {
file.delete() file.delete()
}else if (file.isDirectory){ } else if (file.isDirectory) {
file.deleteRecursively() file.deleteRecursively()
} }
} }
} }
} }
class CutHelper{ class CutHelper {
companion object { companion object {
fun cut(context: Context, file: File){ fun cut(context: Context, file: File) {
val cacheDir = File("${Environment.getExternalStorageDirectory()}/.copy") val cacheDir = File("${Environment.getExternalStorageDirectory()}/.copy")
if (!cacheDir.exists()){ if (!cacheDir.exists()) {
cacheDir.mkdir() cacheDir.mkdir()
} }
@ -36,15 +36,15 @@ class CutHelper{
} }
} }
fun cutFolder(context: Context,folder: File){ fun cutFolder(context: Context, folder: File) {
val cacheDir = File("${Environment.getExternalStorageDirectory()}/.copy") val cacheDir = File("${Environment.getExternalStorageDirectory()}/.copy")
if (!cacheDir.exists()){ if (!cacheDir.exists()) {
cacheDir.mkdir() cacheDir.mkdir()
} }
if (folder.exists()) { if (folder.exists()) {
val tempFolder = File("${Environment.getExternalStorageDirectory()}/.copy", folder.name) val tempFolder = File("${Environment.getExternalStorageDirectory()}/.copy", folder.name)
PasteHelper.copyDirectory(folder,tempFolder) PasteHelper.copyDirectory(folder, tempFolder)
ClipHelper.getInstance(context).copyFolder(tempFolder.path) ClipHelper.getInstance(context).copyFolder(tempFolder.path)
DeleteHelper.delete(folder.path) DeleteHelper.delete(folder.path)
} }

View file

@ -6,7 +6,7 @@ import android.os.Environment
import android.os.storage.StorageManager import android.os.storage.StorageManager
import java.io.IOException import java.io.IOException
class SystemStorageInfo(private val context: Context) { class SystemStorageInfo(context: Context) {
private val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager private val storageManager = context.getSystemService(Context.STORAGE_SERVICE) as StorageManager
private val storageStatsManager = private val storageStatsManager =
context.getSystemService(Context.STORAGE_STATS_SERVICE) as StorageStatsManager context.getSystemService(Context.STORAGE_STATS_SERVICE) as StorageStatsManager
@ -34,6 +34,7 @@ class SystemStorageInfo(private val context: Context) {
} }
} }
fun getUsedPercentage(): Int = 100 - Math.round(freeStorage.toDouble() * 100 / totalStorage.toDouble()).toInt() fun getUsedPercentage(): Int =
100 - Math.round(freeStorage.toDouble() * 100 / totalStorage.toDouble()).toInt()
} }

View file

@ -121,9 +121,9 @@ class WrappedFile(private val f: File, skipCalculateDirectorySize: Boolean = fal
) )
lastModifiedTime = attr.lastModifiedTime().toInstant() lastModifiedTime = attr.lastModifiedTime().toInstant()
mime = if (f.isDirectory){ mime = if (f.isDirectory) {
"dir" "dir"
}else { } else {
guessMime(f.extension) guessMime(f.extension)
} }
} }
@ -131,11 +131,11 @@ class WrappedFile(private val f: File, skipCalculateDirectorySize: Boolean = fal
fun getSizeString(): String { fun getSizeString(): String {
if (size == 0L) { if (size == 0L) {
if (type == Type.DIRECTORY) { if (type == Type.DIRECTORY) {
if (!isSizeCalculated){ if (!isSizeCalculated) {
// Calculate Size // Calculate Size
size = getFolderSize(f) size = getFolderSize(f)
isSizeCalculated = true isSizeCalculated = true
}else{ } else {
return "0B" return "0B"
} }
} else { } else {

View file

@ -10,7 +10,8 @@ import java.io.File
class MusicLister : Lister() { class MusicLister : Lister() {
companion object { companion object {
val instance by lazy { MusicLister() } val instance by lazy { MusicLister() }
val directories = listOf("Recordings", "Download", "Audiobooks", "Music", "Podcasts", "Ringtones") val directories =
listOf("Recordings", "Download", "Audiobooks", "Music", "Podcasts", "Ringtones")
val regex = "\\.(mp3|ogg|aac|wav)".toRegex() val regex = "\\.(mp3|ogg|aac|wav)".toRegex()
} }

View file

@ -2,8 +2,13 @@ package com.example.myapplication.fileSystem.byTypeFileLister
import java.io.File import java.io.File
fun Lister.walkDir(directory: File,list: MutableList<String>,pattern: Regex ,ignoreDotFile: Boolean = true){ fun Lister.walkDir(
if (!directory.exists() || !directory.isDirectory){ directory: File,
list: MutableList<String>,
pattern: Regex,
ignoreDotFile: Boolean = true
) {
if (!directory.exists() || !directory.isDirectory) {
return return
} }
directory.listFiles()?.forEach { directory.listFiles()?.forEach {

View file

@ -1,10 +1,10 @@
package com.example.myapplication package com.example.myapplication
import android.annotation.SuppressLint
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.util.Log
import android.view.View import android.view.View
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.GridView import android.widget.GridView
@ -20,11 +20,10 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.MusicAdapter import com.example.myapplication.adapters.MusicAdapter
import com.example.myapplication.adapters.MusicModel import com.example.myapplication.adapters.MusicModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion
import com.example.myapplication.fileSystem.byTypeFileLister.MusicLister.Companion.instance import com.example.myapplication.fileSystem.byTypeFileLister.MusicLister.Companion.instance
import com.example.myapplication.fileSystem.byTypeFileLister.MusicLister.Companion.regex
import com.example.myapplication.utils.AlertHelper import com.example.myapplication.utils.AlertHelper
import com.example.myapplication.utils.ClipHelper import com.example.myapplication.utils.ClipHelper
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -71,9 +70,12 @@ class music_page : AppCompatActivity() {
searchImageView.setOnClickListener { v: View? -> searchImageView.setOnClickListener { v: View? ->
val intent = val intent =
Intent( Intent(
this@music_page, this,
music_page_search::class.java SearchActivity::class.java
) )
val bundle = Bundle()
bundle.putString("type", "music")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面 startActivity(intent) // 跳转到搜索页面
} }
@ -110,7 +112,7 @@ class music_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText) val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) } launch { loadingText(loadingTextView, defaultText) }
musicList = instance.dateOrderedList() musicList = instance.dateOrderedList()
val models = ArrayList<MusicModel>() val models = ArrayList<MusicModel>()
for (path in musicList) { for (path in musicList) {
@ -118,8 +120,7 @@ class music_page : AppCompatActivity() {
} }
runOnUiThread { runOnUiThread {
val adapter = MusicAdapter(this@music_page, models) val adapter = MusicAdapter(this@music_page, models)
val grid = findViewById<GridView>(R.id.MusicGrid) musicGrid.setAdapter(adapter)
grid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
} }
} }
@ -142,7 +143,7 @@ class music_page : AppCompatActivity() {
} }
val name = uri.path?.split('/')?.last() ?: "somePastedItem" val name = uri.path?.split('/')?.last() ?: "somePastedItem"
val ext = name.split('.').last() val ext = name.split('.').last()
if (!"$ext.".matches(DocumentLister.regex)){ if (!"$ext.".matches(DocumentLister.regex)) {
Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT)
.show() .show()
return@showItemAlert return@showItemAlert
@ -186,12 +187,17 @@ class music_page : AppCompatActivity() {
when (which) { when (which) {
0 -> { 0 -> {
listOrderType = 0 listOrderType = 0
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@music_page, this@music_page,
@ -204,12 +210,17 @@ class music_page : AppCompatActivity() {
1 -> { 1 -> {
listOrderType = 1 listOrderType = 1
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@music_page, this@music_page,
@ -227,7 +238,7 @@ class music_page : AppCompatActivity() {
.show() .show()
} }
private fun update(runSomethingMore: (()->Unit)? = null) { private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize { instance.initialize {
musicList = when (listOrderType) { musicList = when (listOrderType) {
0 -> instance.dateOrderedList() 0 -> instance.dateOrderedList()
@ -247,6 +258,7 @@ class music_page : AppCompatActivity() {
} }
} }
@SuppressLint("SetTextI18n")
private fun loadingText( private fun loadingText(
loadingTextView: TextView, loadingTextView: TextView,
defaultText: CharSequence, defaultText: CharSequence,

View file

@ -1,43 +0,0 @@
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class music_page_search extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.music_page_search);
// 设置左箭头的点击事件返回上一级页面
ImageView leftArrowImageView = findViewById(R.id.leftArrowImageView);
leftArrowImageView.setOnClickListener(v -> {
Intent intent = new Intent(music_page_search.this, music_page.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
});
SearchView searchView = findViewById(R.id.searchMusic); // 确保使用正确的 ID
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// 处理搜索提交
Toast.makeText(music_page_search.this, "搜索: " + query, Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// 处理搜索文本变化
// 可以在这里添加过滤逻辑
return false;
}
});
}
}

View file

@ -1,5 +1,6 @@
package com.example.myapplication package com.example.myapplication
import android.annotation.SuppressLint
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
@ -19,11 +20,10 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.ImageAdapter import com.example.myapplication.adapters.ImageAdapter
import com.example.myapplication.adapters.ImageModel import com.example.myapplication.adapters.ImageModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion
import com.example.myapplication.fileSystem.byTypeFileLister.ImageLister.Companion.instance import com.example.myapplication.fileSystem.byTypeFileLister.ImageLister.Companion.instance
import com.example.myapplication.fileSystem.byTypeFileLister.ImageLister.Companion.regex
import com.example.myapplication.utils.AlertHelper import com.example.myapplication.utils.AlertHelper
import com.example.myapplication.utils.ClipHelper import com.example.myapplication.utils.ClipHelper
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
@ -73,8 +73,11 @@ class picture_page : AppCompatActivity() {
val intent = val intent =
Intent( Intent(
this@picture_page, this@picture_page,
picture_page_search::class.java SearchActivity::class.java
) )
val bundle = Bundle()
bundle.putString("type", "image")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面 startActivity(intent) // 跳转到搜索页面
} }
@ -111,7 +114,7 @@ class picture_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText) val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) } launch { loadingText(loadingTextView, defaultText) }
imageList = instance.dateOrderedList() imageList = instance.dateOrderedList()
val imageModels = ArrayList<ImageModel>() val imageModels = ArrayList<ImageModel>()
for (path in imageList) { for (path in imageList) {
@ -119,8 +122,7 @@ class picture_page : AppCompatActivity() {
} }
runOnUiThread { runOnUiThread {
val adapter = ImageAdapter(this@picture_page, imageModels) val adapter = ImageAdapter(this@picture_page, imageModels)
val grid = findViewById<GridView>(R.id.PicturePageGrid) pictureGrid.setAdapter(adapter)
grid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
} }
} }
@ -143,7 +145,7 @@ class picture_page : AppCompatActivity() {
} }
val name = uri.path?.split('/')?.last() ?: "somePastedItem" val name = uri.path?.split('/')?.last() ?: "somePastedItem"
val ext = name.split('.').last() val ext = name.split('.').last()
if (!"$ext.".matches(DocumentLister.regex)){ if (!"$ext.".matches(DocumentLister.regex)) {
Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT)
.show() .show()
return@showItemAlert return@showItemAlert
@ -187,12 +189,17 @@ class picture_page : AppCompatActivity() {
when (which) { when (which) {
0 -> { 0 -> {
imageListOrderType = 0 imageListOrderType = 0
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@picture_page, this@picture_page,
@ -205,12 +212,17 @@ class picture_page : AppCompatActivity() {
1 -> { 1 -> {
imageListOrderType = 1 imageListOrderType = 1
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@picture_page, this@picture_page,
@ -228,7 +240,7 @@ class picture_page : AppCompatActivity() {
.show() .show()
} }
private fun update(runSomethingMore: (()->Unit)? = null) { private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize { instance.initialize {
imageList = when (imageListOrderType) { imageList = when (imageListOrderType) {
0 -> instance.dateOrderedList() 0 -> instance.dateOrderedList()
@ -248,6 +260,7 @@ class picture_page : AppCompatActivity() {
} }
} }
@SuppressLint("SetTextI18n")
private fun loadingText( private fun loadingText(
loadingTextView: TextView, loadingTextView: TextView,
defaultText: CharSequence, defaultText: CharSequence,

View file

@ -1,43 +0,0 @@
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class picture_page_search extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.picture_page_search);
// 设置左箭头的点击事件返回上一级页面
ImageView leftArrowImageView = findViewById(R.id.leftArrowImageView);
leftArrowImageView.setOnClickListener(v -> {
Intent intent = new Intent(picture_page_search.this, picture_page.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
});
SearchView searchView = findViewById(R.id.searchPicture); // 确保使用正确的 ID
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// 处理搜索提交
Toast.makeText(picture_page_search.this, "搜索: " + query, Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// 处理搜索文本变化
// 可以在这里添加过滤逻辑
return false;
}
});
}
}

View file

@ -58,9 +58,10 @@ class store_page : AppCompatActivity() {
val musicSizeString = WrappedFile.getSizeString(musicSize) val musicSizeString = WrappedFile.getSizeString(musicSize)
val documentSize = DocumentLister.instance.getFullSize() val documentSize = DocumentLister.instance.getFullSize()
val documentSizeString = WrappedFile.getSizeString(documentSize) val documentSizeString = WrappedFile.getSizeString(documentSize)
val otherSize = systemStorageInfo.getTotalStorageSize() - systemStorageInfo.getFreeStorageSize() - imageSize - musicSize - documentSize val otherSize =
systemStorageInfo.getTotalStorageSize() - systemStorageInfo.getFreeStorageSize() - imageSize - musicSize - documentSize
val otherSizeString = WrappedFile.getSizeString(otherSize) val otherSizeString = WrappedFile.getSizeString(otherSize)
runOnUiThread{ runOnUiThread {
findViewById<TextView>(R.id.pictureStorage).text = imageSizeString findViewById<TextView>(R.id.pictureStorage).text = imageSizeString
findViewById<TextView>(R.id.videoStorage).text = videoSizeString findViewById<TextView>(R.id.videoStorage).text = videoSizeString
findViewById<TextView>(R.id.audioStorage).text = musicSizeString findViewById<TextView>(R.id.audioStorage).text = musicSizeString

View file

@ -59,7 +59,6 @@ class AlertHelper {
fun showNoPasteAlert( fun showNoPasteAlert(
context: Context, context: Context,
onCopy: () -> Unit, onCopy: () -> Unit,
onPaste: () -> Unit,
onDelete: () -> Unit, onDelete: () -> Unit,
onCut: () -> Unit, onCut: () -> Unit,
onInfo: () -> Unit onInfo: () -> Unit
@ -117,8 +116,8 @@ class AlertHelper {
when (which) { when (which) {
0 -> onPaste() 0 -> onPaste()
1 -> onInfo() 1 -> onInfo()
2-> onNewFile() 2 -> onNewFile()
3-> onNewFolder() 3 -> onNewFolder()
} }
} }
.setNegativeButton(context.getString(R.string.action_cancel)) .setNegativeButton(context.getString(R.string.action_cancel))

View file

@ -47,8 +47,8 @@ class ClipHelper private constructor(context: Context) {
return null return null
} }
fun copyFolder(folder: String){ fun copyFolder(folder: String) {
val clip = ClipData.newPlainText("SingleFolderCopy","$ENCODE_LABEL:${folder}") val clip = ClipData.newPlainText("SingleFolderCopy", "$ENCODE_LABEL:${folder}")
clipboard.setPrimaryClip(clip) clipboard.setPrimaryClip(clip)
} }
@ -58,8 +58,8 @@ class ClipHelper private constructor(context: Context) {
val item: ClipData.Item = getItemAt(0) val item: ClipData.Item = getItemAt(0)
item.text item.text
} }
if (content != null){ if (content != null) {
if (content.startsWith(ENCODE_LABEL)){ if (content.startsWith(ENCODE_LABEL)) {
return content.split(':').last() return content.split(':').last()
} }
} }

View file

@ -1,5 +1,6 @@
package com.example.myapplication package com.example.myapplication
import android.annotation.SuppressLint
import android.content.DialogInterface import android.content.DialogInterface
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
@ -17,14 +18,11 @@ import androidx.core.content.FileProvider
import androidx.core.view.ViewCompat import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.ImageAdapter
import com.example.myapplication.adapters.ImageModel
import com.example.myapplication.adapters.VideoAdapter import com.example.myapplication.adapters.VideoAdapter
import com.example.myapplication.adapters.VideoModel import com.example.myapplication.adapters.VideoModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper import com.example.myapplication.fileSystem.CutHelper
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister
import com.example.myapplication.fileSystem.byTypeFileLister.DocumentLister.Companion
import com.example.myapplication.fileSystem.byTypeFileLister.VideoLister.Companion.regex
import com.example.myapplication.fileSystem.byTypeFileLister.VideoLister.Companion.instance import com.example.myapplication.fileSystem.byTypeFileLister.VideoLister.Companion.instance
import com.example.myapplication.utils.AlertHelper import com.example.myapplication.utils.AlertHelper
import com.example.myapplication.utils.ClipHelper import com.example.myapplication.utils.ClipHelper
@ -73,9 +71,12 @@ class video_page : AppCompatActivity() {
searchImageView.setOnClickListener { v: View? -> searchImageView.setOnClickListener { v: View? ->
val intent = val intent =
Intent( Intent(
this@video_page, this,
video_page_search::class.java SearchActivity::class.java
) )
val bundle = Bundle()
bundle.putString("type", "video")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面 startActivity(intent) // 跳转到搜索页面
} }
@ -112,7 +113,7 @@ class video_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch { CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText) val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) } launch { loadingText(loadingTextView, defaultText) }
videoList = instance.dateOrderedList() videoList = instance.dateOrderedList()
val videoModels = ArrayList<VideoModel>() val videoModels = ArrayList<VideoModel>()
for (path in videoList) { for (path in videoList) {
@ -120,8 +121,7 @@ class video_page : AppCompatActivity() {
} }
runOnUiThread { runOnUiThread {
val adapter = VideoAdapter(this@video_page, videoModels) val adapter = VideoAdapter(this@video_page, videoModels)
val grid = findViewById<GridView>(R.id.VideoGrid) videoGrid.setAdapter(adapter)
grid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
} }
} }
@ -144,7 +144,7 @@ class video_page : AppCompatActivity() {
} }
val name = uri.path?.split('/')?.last() ?: "somePastedItem" val name = uri.path?.split('/')?.last() ?: "somePastedItem"
val ext = name.split('.').last() val ext = name.split('.').last()
if (!"$ext.".matches(DocumentLister.regex)){ if (!"$ext.".matches(DocumentLister.regex)) {
Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT) Toast.makeText(this, getString(R.string.error_nothing_to_paste), Toast.LENGTH_SHORT)
.show() .show()
return@showItemAlert return@showItemAlert
@ -188,12 +188,17 @@ class video_page : AppCompatActivity() {
when (which) { when (which) {
0 -> { 0 -> {
videoListOrderType = 0 videoListOrderType = 0
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@video_page, this@video_page,
@ -206,12 +211,17 @@ class video_page : AppCompatActivity() {
1 -> { 1 -> {
videoListOrderType = 1 videoListOrderType = 1
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.VISIBLE loadingTextView.visibility = View.VISIBLE
} }
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) } CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update { update {
runOnUiThread{ runOnUiThread {
loadingTextView.visibility = View.GONE loadingTextView.visibility = View.GONE
Toast.makeText( Toast.makeText(
this@video_page, this@video_page,
@ -229,7 +239,7 @@ class video_page : AppCompatActivity() {
.show() .show()
} }
private fun update(runSomethingMore: (()->Unit)? = null) { private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize { instance.initialize {
videoList = when (videoListOrderType) { videoList = when (videoListOrderType) {
0 -> instance.dateOrderedList() 0 -> instance.dateOrderedList()
@ -249,6 +259,7 @@ class video_page : AppCompatActivity() {
} }
} }
@SuppressLint("SetTextI18n")
private fun loadingText( private fun loadingText(
loadingTextView: TextView, loadingTextView: TextView,
defaultText: CharSequence, defaultText: CharSequence,

View file

@ -1,43 +0,0 @@
package com.example.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.SearchView;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class video_page_search extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.video_page_search);
// 设置左箭头的点击事件返回上一级页面
ImageView leftArrowImageView = findViewById(R.id.leftArrowImageView);
leftArrowImageView.setOnClickListener(v -> {
Intent intent = new Intent(video_page_search.this, video_page.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
});
SearchView searchView = findViewById(R.id.searchVideo); // 确保使用正确的 ID
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// 处理搜索提交
Toast.makeText(video_page_search.this, "搜索: " + query, Toast.LENGTH_SHORT).show();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
// 处理搜索文本变化
// 可以在这里添加过滤逻辑
return false;
}
});
}
}

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/leftArrowImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="left_arrow"
android:layout_marginTop="45dp"
android:src="@drawable/ic_left_arrow" />
<SearchView
android:id="@+id/searchDocument"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_border"
android:iconifiedByDefault="false"
android:padding="10dp"
android:queryHint="搜索文件"
android:textColor="@color/black" />
</LinearLayout>

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/leftArrowImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="left_arrow"
android:layout_marginTop="45dp"
android:src="@drawable/ic_left_arrow" />
<SearchView
android:id="@+id/searchMusic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_border"
android:iconifiedByDefault="false"
android:padding="10dp"
android:queryHint="搜索音乐"
android:textColor="@color/black" />
</LinearLayout>

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/leftArrowImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="left_arrow"
android:layout_marginTop="45dp"
android:src="@drawable/ic_left_arrow" />
<SearchView
android:id="@+id/searchPicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_border"
android:iconifiedByDefault="false"
android:padding="10dp"
android:queryHint="搜索图片"
android:textColor="@color/black" />
</LinearLayout>

View file

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:padding="10dp">
<ImageView
android:id="@+id/leftArrowImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="left_arrow"
android:layout_marginTop="45dp"
android:src="@drawable/ic_left_arrow" />
<SearchView
android:id="@+id/searchVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginStart="20dp"
android:background="@drawable/search_border"
android:iconifiedByDefault="false"
android:padding="10dp"
android:queryHint="搜索视频"
android:textColor="@color/black" />
</LinearLayout>

View file

@ -127,4 +127,5 @@
<string name="error_need_input_name">请输入名称</string> <string name="error_need_input_name">请输入名称</string>
<string name="error_already_exist">已存在此文件(夹)</string> <string name="error_already_exist">已存在此文件(夹)</string>
<string name="title_activity_view_file">ViewFileActivity</string> <string name="title_activity_view_file">ViewFileActivity</string>
<string name="title_activity_search">SearchActivity</string>
</resources> </resources>