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"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
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
android:allowBackup="true"
@ -21,6 +12,11 @@
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".compose.SearchActivity"
android:exported="false"
android:label="@string/title_activity_search"
android:theme="@style/Theme.MyApplication" />
<activity
android:name=".compose.RequirePermissionActivity"
android:exported="true"
@ -34,36 +30,27 @@
<activity
android:name=".compose.ViewFileActivity"
android:exported="false" />
<activity
android:name=".main_page"
android:exported="false" />
<activity
android:name=".store_page"
android:exported="false" />
<activity
android:name=".document_page_search"
android:exported="false" />
<activity
android:name=".document_page"
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
android:name=".picture_page"
android:exported="false" />
<activity
android:name=".video_page"
android:exported="false" />
<activity
android:name=".music_page"
android:exported="false" />
<provider
android:name="androidx.core.content.FileProvider"
@ -75,4 +62,15 @@
android:resource="@xml/provider_paths" />
</provider>
</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>

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
class PasteHelper {
companion object{
companion object {
fun copyDirectory(sourceDir: File, destDir: File) {
// creates the destination directory if it does not exist
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()) {
destFile.createNewFile()
}

View file

@ -44,7 +44,8 @@ class RequirePermissionActivity : ComponentActivity() {
window.statusBarColor = getColor(R.color.WhiteSmoke)
setContent {
Column(
modifier = Modifier.statusBarsPadding()
modifier = Modifier
.statusBarsPadding()
.fillMaxHeight(0.9f)
.fillMaxWidth(),
horizontalAlignment = Alignment.CenterHorizontally,
@ -72,7 +73,11 @@ class RequirePermissionActivity : ComponentActivity() {
startActivity(intent)
}
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(
activity, perm33, 101
)
@ -96,7 +101,6 @@ class RequirePermissionActivity : ComponentActivity() {
}
}
}
}
override fun onResume() {
@ -119,7 +123,11 @@ fun checkPermissions(context: Context): Boolean {
return false
}
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 {
if (context.checkSelfPermission(it) != PackageManager.PERMISSION_GRANTED) {
return false
@ -137,7 +145,7 @@ fun checkPermissions(context: Context): Boolean {
return true
}
fun initSystem(){
fun initSystem() {
ImageLister.instance.initialize()
VideoLister.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 =
intent.extras?.getString("folder") ?: Environment.getExternalStorageDirectory().path
val file = File(path)
if (!file.isDirectory){
if (!file.isDirectory) {
path = Environment.getExternalStorageDirectory().path
}
enableEdgeToEdge()
@ -30,7 +30,7 @@ class ViewFileActivity : ComponentActivity() {
modifier = Modifier
.fillMaxSize()
.background(Color(getColor(R.color.WhiteSmoke)))
){
) {
FileColumn(this).Draw(path)
}
}

View file

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

View file

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

View file

@ -6,7 +6,7 @@ import android.os.Environment
import android.os.storage.StorageManager
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 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()
mime = if (f.isDirectory){
mime = if (f.isDirectory) {
"dir"
}else {
} else {
guessMime(f.extension)
}
}
@ -131,11 +131,11 @@ class WrappedFile(private val f: File, skipCalculateDirectorySize: Boolean = fal
fun getSizeString(): String {
if (size == 0L) {
if (type == Type.DIRECTORY) {
if (!isSizeCalculated){
if (!isSizeCalculated) {
// Calculate Size
size = getFolderSize(f)
isSizeCalculated = true
}else{
} else {
return "0B"
}
} else {

View file

@ -10,7 +10,8 @@ import java.io.File
class MusicLister : Lister() {
companion object {
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()
}

View file

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

View file

@ -96,7 +96,7 @@ public class main_page extends AppCompatActivity {
Intent intent = new Intent(context, ViewFileActivity.class);
Bundle bundle = new Bundle();
bundle.putString("folder",
Environment.getExternalStorageDirectory().getPath() + "/Download");
Environment.getExternalStorageDirectory().getPath() + "/Download");
intent.putExtras(bundle);
startActivity(intent);
}
@ -104,7 +104,7 @@ public class main_page extends AppCompatActivity {
Intent intent = new Intent(context, ViewFileActivity.class);
Bundle bundle = new Bundle();
bundle.putString("folder",
Environment.getExternalStorageDirectory().getPath() + "/Documents");
Environment.getExternalStorageDirectory().getPath() + "/Documents");
intent.putExtras(bundle);
startActivity(intent);
}
@ -112,7 +112,7 @@ public class main_page extends AppCompatActivity {
Intent intent = new Intent(context, ViewFileActivity.class);
Bundle bundle = new Bundle();
bundle.putString("folder",
Environment.getExternalStorageDirectory().getPath() + "/Recordings");
Environment.getExternalStorageDirectory().getPath() + "/Recordings");
intent.putExtras(bundle);
startActivity(intent);
}

View file

@ -1,10 +1,10 @@
package com.example.myapplication
import android.annotation.SuppressLint
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
import android.os.Environment
import android.util.Log
import android.view.View
import android.widget.AdapterView
import android.widget.GridView
@ -20,11 +20,10 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.MusicAdapter
import com.example.myapplication.adapters.MusicModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
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.regex
import com.example.myapplication.utils.AlertHelper
import com.example.myapplication.utils.ClipHelper
import kotlinx.coroutines.CoroutineScope
@ -71,9 +70,12 @@ class music_page : AppCompatActivity() {
searchImageView.setOnClickListener { v: View? ->
val intent =
Intent(
this@music_page,
music_page_search::class.java
this,
SearchActivity::class.java
)
val bundle = Bundle()
bundle.putString("type", "music")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面
}
@ -110,7 +112,7 @@ class music_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) }
launch { loadingText(loadingTextView, defaultText) }
musicList = instance.dateOrderedList()
val models = ArrayList<MusicModel>()
for (path in musicList) {
@ -118,8 +120,7 @@ class music_page : AppCompatActivity() {
}
runOnUiThread {
val adapter = MusicAdapter(this@music_page, models)
val grid = findViewById<GridView>(R.id.MusicGrid)
grid.setAdapter(adapter)
musicGrid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
}
}
@ -142,7 +143,7 @@ class music_page : AppCompatActivity() {
}
val name = uri.path?.split('/')?.last() ?: "somePastedItem"
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)
.show()
return@showItemAlert
@ -186,12 +187,17 @@ class music_page : AppCompatActivity() {
when (which) {
0 -> {
listOrderType = 0
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.VISIBLE
}
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) }
CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update {
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.GONE
Toast.makeText(
this@music_page,
@ -204,12 +210,17 @@ class music_page : AppCompatActivity() {
1 -> {
listOrderType = 1
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.VISIBLE
}
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) }
CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update {
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.GONE
Toast.makeText(
this@music_page,
@ -227,7 +238,7 @@ class music_page : AppCompatActivity() {
.show()
}
private fun update(runSomethingMore: (()->Unit)? = null) {
private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize {
musicList = when (listOrderType) {
0 -> instance.dateOrderedList()
@ -247,6 +258,7 @@ class music_page : AppCompatActivity() {
}
}
@SuppressLint("SetTextI18n")
private fun loadingText(
loadingTextView: TextView,
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
import android.annotation.SuppressLint
import android.content.DialogInterface
import android.content.Intent
import android.os.Bundle
@ -19,11 +20,10 @@ import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsCompat.Type
import com.example.myapplication.adapters.ImageAdapter
import com.example.myapplication.adapters.ImageModel
import com.example.myapplication.compose.SearchActivity
import com.example.myapplication.fileSystem.CutHelper
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.regex
import com.example.myapplication.utils.AlertHelper
import com.example.myapplication.utils.ClipHelper
import kotlinx.coroutines.CoroutineScope
@ -73,8 +73,11 @@ class picture_page : AppCompatActivity() {
val intent =
Intent(
this@picture_page,
picture_page_search::class.java
SearchActivity::class.java
)
val bundle = Bundle()
bundle.putString("type", "image")
intent.putExtras(bundle)
startActivity(intent) // 跳转到搜索页面
}
@ -111,7 +114,7 @@ class picture_page : AppCompatActivity() {
CoroutineScope(Dispatchers.Default).launch {
val loadingTextView = findViewById<TextView>(R.id.LoadingBlankText)
val defaultText = loadingTextView.text
launch { loadingText(loadingTextView,defaultText) }
launch { loadingText(loadingTextView, defaultText) }
imageList = instance.dateOrderedList()
val imageModels = ArrayList<ImageModel>()
for (path in imageList) {
@ -119,8 +122,7 @@ class picture_page : AppCompatActivity() {
}
runOnUiThread {
val adapter = ImageAdapter(this@picture_page, imageModels)
val grid = findViewById<GridView>(R.id.PicturePageGrid)
grid.setAdapter(adapter)
pictureGrid.setAdapter(adapter)
findViewById<TextView>(R.id.LoadingBlankText).visibility = View.GONE
}
}
@ -143,7 +145,7 @@ class picture_page : AppCompatActivity() {
}
val name = uri.path?.split('/')?.last() ?: "somePastedItem"
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)
.show()
return@showItemAlert
@ -187,12 +189,17 @@ class picture_page : AppCompatActivity() {
when (which) {
0 -> {
imageListOrderType = 0
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.VISIBLE
}
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) }
CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update {
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.GONE
Toast.makeText(
this@picture_page,
@ -205,12 +212,17 @@ class picture_page : AppCompatActivity() {
1 -> {
imageListOrderType = 1
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.VISIBLE
}
CoroutineScope(Dispatchers.IO).launch { loadingText(loadingTextView,loadingTextView.text) }
CoroutineScope(Dispatchers.IO).launch {
loadingText(
loadingTextView,
loadingTextView.text
)
}
update {
runOnUiThread{
runOnUiThread {
loadingTextView.visibility = View.GONE
Toast.makeText(
this@picture_page,
@ -228,7 +240,7 @@ class picture_page : AppCompatActivity() {
.show()
}
private fun update(runSomethingMore: (()->Unit)? = null) {
private fun update(runSomethingMore: (() -> Unit)? = null) {
instance.initialize {
imageList = when (imageListOrderType) {
0 -> instance.dateOrderedList()
@ -248,6 +260,7 @@ class picture_page : AppCompatActivity() {
}
}
@SuppressLint("SetTextI18n")
private fun loadingText(
loadingTextView: TextView,
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 documentSize = DocumentLister.instance.getFullSize()
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)
runOnUiThread{
runOnUiThread {
findViewById<TextView>(R.id.pictureStorage).text = imageSizeString
findViewById<TextView>(R.id.videoStorage).text = videoSizeString
findViewById<TextView>(R.id.audioStorage).text = musicSizeString

View file

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

View file

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

View file

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