From 3f9b2484bbed366853b95c7001894bcb126cfd6a Mon Sep 17 00:00:00 2001 From: Cold-Mint Date: Tue, 11 Feb 2025 18:17:34 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E6=B7=BB=E5=8A=A0=E7=9B=B8?= =?UTF-8?q?=E5=86=8C=E5=BF=AB=E6=8D=B7=E5=85=A5=E5=8F=A3=E5=B9=B6=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E6=96=87=E4=BB=B6=E7=AE=A1=E7=90=86=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在菜单栏添加相册快捷入口,提高用户体验 - 移除冗余代码,优化文件管理活动- 更新菜单资源,增加相册快捷项 - 添加相册图标资源 - 修正版权年份为动态显示 --- .../com/coldmint/rust/pro/AboutActivity.kt | 5 +- .../coldmint/rust/pro/FileManagerActivity.kt | 269 ++---------------- .../res/drawable/outline_photo_album_24.xml | 12 + app/src/main/res/menu/menu_files.xml | 28 +- app/src/main/res/values/strings.xml | 4 +- 5 files changed, 55 insertions(+), 263 deletions(-) create mode 100644 app/src/main/res/drawable/outline_photo_album_24.xml diff --git a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt index e795f12..72dc89c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/AboutActivity.kt @@ -70,9 +70,8 @@ class AboutActivity : BaseActivity() { } - override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityAboutBinding { - return ActivityAboutBinding.inflate(layoutInflater) - } + override fun getViewBindingObject(layoutInflater: LayoutInflater): ActivityAboutBinding = + ActivityAboutBinding.inflate(layoutInflater) override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index c3b2d8d..bdf199f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -41,128 +41,30 @@ import java.io.File class FileManagerActivity : BaseActivity() { -// -// /** -// * 编辑模板 -// * @param file File -// */ -// fun editTemplate(file: File) { -// val intent = Intent(this, TemplateMakerActivity::class.java) -// val bundle = Bundle() -// intent.putExtra("data", bundle) -// bundle.putString("path", file.absolutePath) -// bundle.putBoolean("loadTemplate", true) -// bundle.putString("templatePath", additionalData) -// startActivity(intent) -// } -// -// /** -// * 编辑文本 -// * @param file File -// */ -// fun editText(file: File) { -// val bundle = Bundle() -// bundle.putString("path", file.absolutePath) -// bundle.putString( -// "modPath", -// FileOperator.getSuperDirectory(file) -// ) -// val intent = Intent( -// this@FileManagerActivity, -// EditActivity::class.java -// ) -// intent.putExtra("data", bundle) -// this@FileManagerActivity.startActivity(intent) -// } - -// override fun onPause() { -// viewModel.getBookmarkManager().save() -// super.onPause() -// } - override fun onResume() { viewModel.getBookmarkManager().load() loadMineBookmarksMenu() super.onResume() } - override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { - super.onActivityResult(requestCode, resultCode, data) - if (resultCode == RESULT_OK) { - if (viewModel.startTypeData == FileManagerViewModel.StartType.SELECT_FILE && requestCode == 1) { -// val path = FileOperator.parsePicturePath(this@FileManagerActivity, data) -// if (path != null) { -// val intent = Intent() -// intent.putExtra("File", path) -// setResult(RESULT_OK, intent) -// finish() -// } - } else if (viewModel.startTypeData == FileManagerViewModel.StartType.SELECT_FILE && requestCode == 2) { -// val path = viewModel.parseFilePath(this@FileManagerActivity, data) -// if (path != null) { -// val intent = Intent() -// intent.putExtra("File", path) -// setResult(RESULT_OK, intent) -//// bookmarkManager.save() -// finish() -// } - } - // else if (requestCode == 3) { - //新建源文件 -// loadFiles(directs) -// } else if (requestCode == 4) { -// val file = File(data!!.getStringExtra("File")) -// val copyResult = -// FileOperator.copyFile(file, File(directs.toString() + "/" + file.name)) -// if (!copyResult) { -// Snackbar.make( -// viewBinding.fab, -// getText(R.string.copy_file_error), -// Snackbar.LENGTH_SHORT -// ).show() -// } else { -// loadFiles(directs) -// } -// } - } - } - lateinit var photoAlbumResultLauncher: ActivityResultLauncher lateinit var systemFileManagerResultLauncher: ActivityResultLauncher - // override fun onOptionsItemSelected(item: MenuItem): Boolean { val id = item.itemId when (id) { android.R.id.home -> { -// bookmarkManager.save() finish() return true } + R.id.reloadFile -> { viewModel.loadFiles(viewModel.getCurrentPath()) return true } -// R.id.photo_album -> { -// this@FileManagerActivity.startActivityForResult( -// Intent( -// Intent.ACTION_PICK, -// MediaStore.Images.Media.EXTERNAL_CONTENT_URI -// ), 1 -// ) -// return true -// } -// R.id.system_file_manager -> { -// val intent = Intent(Intent.ACTION_GET_CONTENT) -// intent.type = "*/*" -// intent.addCategory(Intent.CATEGORY_OPENABLE) -// this@FileManagerActivity.startActivityForResult(intent, 2) -// return true -// } } -// loadBook(item.title) return super.onOptionsItemSelected(item) } @@ -182,33 +84,6 @@ class FileManagerActivity : BaseActivity() { viewBinding.fab.setOnClickListener { val startType = viewModel.startTypeData when (startType) { -// "exportFile" -> { -// val oldFile = File(additionalData) -// val result = FileOperator.copyFile( -// oldFile, -// File(directs.absolutePath + "/" + oldFile.name) -// ) -// if (result) { -// setResult(RESULT_OK) -// } -// finish() -// } -// "selectDirectents" -> { -// intent.putExtra("Directents", directs.absolutePath) -// setResult(RESULT_OK, intent) -// bookmarkManager.save() -// finish() -// } -// "selectFile" -> { -// intent.putExtra("File", filePath) -// setResult(RESULT_OK, intent) -// bookmarkManager.save() -// finish() -// } - -// FileManagerViewModel.StartType.SELECT_FILE -> { -// -// } FileManagerViewModel.StartType.DEFAULT, FileManagerViewModel.StartType.SELECT_FILE, FileManagerViewModel.StartType.SELECT_DIRECTORY -> { var popupMenu = GlobalMethod.createPopMenu(viewBinding.fab) if (adapter != null) { @@ -226,7 +101,6 @@ class FileManagerActivity : BaseActivity() { popupMenu.menu.add(R.string.select_file) popupMenu.setOnMenuItemClickListener { item -> val title = item.title -// val handler = Handler(Looper.getMainLooper()) when (title) { getText(R.string.create_unit) -> { val intent = @@ -237,6 +111,7 @@ class FileManagerActivity : BaseActivity() { intent.putExtra("data", bundle) startActivityForResult(intent, 3) } + getText(R.string.select_file) -> { val bundle = Bundle() val intent = @@ -249,9 +124,11 @@ class FileManagerActivity : BaseActivity() { intent.putExtra("data", bundle) startActivityForResult(intent, 4) } + getText(R.string.create_folder) -> { createFolderAction() } + getText(R.string.copy_to_this) -> { val job = Job() val handler = Handler(Looper.getMainLooper()) @@ -281,6 +158,7 @@ class FileManagerActivity : BaseActivity() { } } } + getText(R.string.cut_to_this) -> { val job = Job() val handler = Handler(Looper.getMainLooper()) @@ -314,126 +192,14 @@ class FileManagerActivity : BaseActivity() { } popupMenu.show() } + else -> { } } } } -// -// /** -// * 创建文件夹活动 -// */ -// private fun createFolderAction() { -// MaterialDialog(this).show { -// title(R.string.create_folder) -// input( -// maxLength = 255, -// waitForPositiveButton = false -// ) { dialog, text -> -// if (text.length in 1..255) { -// dialog.setActionButtonEnabled(WhichButton.POSITIVE, true) -// } -// }.positiveButton(R.string.dialog_ok, null) { dialog -> -// val string = dialog.getInputField().text.toString() -// val file = File("$directs/$string") -// if (file.exists()) { -// Toast.makeText( -// this@FileManagerActivity, -// R.string.folder_error, -// Toast.LENGTH_SHORT -// ).show() -// } else { -// file.mkdirs() -// loadFiles(directs) -// } -// }.negativeButton(R.string.dialog_close) -// } -// } -// -// - // -// private fun getPath(context: Context, uri: Uri?): String? { -// val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT -// -// // DocumentProvider -// if (isKitKat && DocumentsContract.isDocumentUri(context, uri)) { -// // ExternalStorageProvider -// if (isExternalStorageDocument(uri)) { -// val docId = DocumentsContract.getDocumentId(uri) -// val split = docId.split(":").toTypedArray() -// val type = split[0] -// if ("primary".equals(type, ignoreCase = true)) { -// return Environment.getExternalStorageDirectory().toString() + "/" + split[1] -// } -// } else if (isDownloadsDocument(uri)) { -// val id = DocumentsContract.getDocumentId(uri) -// val contentUri = ContentUris.withAppendedId( -// Uri.parse("content://downloads/public_downloads"), -// java.lang.Long.valueOf(id) -// ) -// return getDataColumn(context, contentUri, null, null) -// } else if (isMediaDocument(uri)) { -// val docId = DocumentsContract.getDocumentId(uri) -// val split = docId.split(":").toTypedArray() -// val type = split[0] -// var contentUri: Uri? = null -// if ("image" == type) { -// contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI -// } else if ("video" == type) { -// contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI -// } else if ("audio" == type) { -// contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI -// } -// val selection = "_id=?" -// val selectionArgs = arrayOf(split[1]) -// return getDataColumn(context, contentUri, selection, selectionArgs) -// } -// } else if ("content".equals(uri!!.scheme, ignoreCase = true)) { -// return getDataColumn(context, uri, null, null) -// } else if ("file".equals(uri.scheme, ignoreCase = true)) { -// uri.path -// } -// return null -// } -// -// private fun isMediaDocument(uri: Uri?): Boolean { -// return "com.android.providers.media.documents" == uri!!.authority -// } -// -// private fun isExternalStorageDocument(uri: Uri?): Boolean { -// return "com.android.externalstorage.documents" == uri!!.authority -// } -// -// private fun isDownloadsDocument(uri: Uri?): Boolean { -// return "com.android.providers.downloads.documents" == uri!!.authority -// } -// -// private fun getDataColumn( -// context: Context, -// uri: Uri?, -// selection: String?, -// selectionArgs: Array? -// ): String? { -// var cursor: Cursor? = null -// val column = "_data" -// val projection = arrayOf(column) -// try { -// cursor = context.contentResolver.query( -// uri!!, projection, selection, selectionArgs, -// null -// ) -// if (cursor != null && cursor.moveToFirst()) { -// val column_index = cursor.getColumnIndexOrThrow(column) -// return cursor.getString(column_index) -// } -// } finally { -// cursor?.close() -// } -// return null -// } -// private lateinit var menuBinding: MenuBinding private val viewModel: FileManagerViewModel by lazy { ViewModelProvider(this).get(FileManagerViewModel::class.java) @@ -493,7 +259,8 @@ class FileManagerActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { setReturnButton() - viewBinding.recyclerView.layoutManager = StableLinearLayoutManager(this@FileManagerActivity) + viewBinding.recyclerView.layoutManager = + StableLinearLayoutManager(this@FileManagerActivity) val linearLayoutManager = StableLinearLayoutManager(this) linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL viewBinding.fileTabNav.layoutManager = linearLayoutManager @@ -539,6 +306,7 @@ class FileManagerActivity : BaseActivity() { }.setGestureInsetBottomIgnored(true).show() FileManagerViewModel.StartType.SELECT_DIRECTORY } + "exportFile" -> { Snackbar.make( viewBinding.fab, @@ -557,9 +325,11 @@ class FileManagerActivity : BaseActivity() { }.setGestureInsetBottomIgnored(true).show() FileManagerViewModel.StartType.EXPORT_FILE } + "selectFile" -> { FileManagerViewModel.StartType.SELECT_FILE } + else -> { FileManagerViewModel.StartType.DEFAULT } @@ -586,7 +356,7 @@ class FileManagerActivity : BaseActivity() { systemFileManagerResultLauncher.launch("*/*") true } - menuBinding.photoAlbumItem.setOnMenuItemClickListener { + val photoAlbumOnMenuItemClickListener = { _: MenuItem -> val intent = Intent( Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI @@ -594,6 +364,10 @@ class FileManagerActivity : BaseActivity() { photoAlbumResultLauncher.launch(intent) true } + menuBinding.photoAlbumItemShortcut.setOnMenuItemClickListener( + photoAlbumOnMenuItemClickListener + ) + menuBinding.photoAlbumItem.setOnMenuItemClickListener(photoAlbumOnMenuItemClickListener) menuBinding.actionSortByType.setOnMenuItemClickListener { viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_TYPE true @@ -776,6 +550,7 @@ class FileManagerActivity : BaseActivity() { viewModel.getBookmarkManager().save() loadMineBookmarksMenu() } + R.id.renameAction -> { val finalFile = adapter!!.getItemData(viewHolder.absoluteAdapterPosition) @@ -798,6 +573,7 @@ class FileManagerActivity : BaseActivity() { }.setCancelable(false).show() } + R.id.deleteAction -> { val finalFile = adapter!!.getItemData(viewHolder.absoluteAdapterPosition) @@ -816,11 +592,13 @@ class FileManagerActivity : BaseActivity() { }.show() } + R.id.copyAction -> { val finalFile = adapter!!.getItemData(viewHolder.absoluteAdapterPosition) adapter!!.setSelectPath(finalFile!!.absolutePath, true) } + R.id.cutOffAction -> { val finalFile = adapter!!.getItemData(viewHolder.absoluteAdapterPosition) @@ -889,15 +667,19 @@ class FileManagerActivity : BaseActivity() { FileManagerViewModel.SortType.BY_NAME -> { menuBinding.actionSortByName.isChecked = true } + FileManagerViewModel.SortType.BY_SIZE -> { menuBinding.actionSortBySize.isChecked = true } + FileManagerViewModel.SortType.BY_LAST_MODIFIED -> { menuBinding.actionSortByLastModified.isChecked = true } + FileManagerViewModel.SortType.BY_TYPE -> { menuBinding.actionSortByType.isChecked = true } + else -> { menuBinding.actionSortByName.isChecked = true } @@ -916,6 +698,7 @@ class FileManagerActivity : BaseActivity() { FileManagerViewModel.StartType.DEFAULT -> { getString(R.string.file_manager) } + else -> { getString(R.string.file_manager) } @@ -931,6 +714,7 @@ class FileManagerActivity : BaseActivity() { val menu: Menu, val reloadFileItem: MenuItem, val photoAlbumItem: MenuItem, + val photoAlbumItemShortcut: MenuItem, val systemFileManagerItem: MenuItem, val actionSortByName: MenuItem, val actionSortByType: MenuItem, @@ -947,6 +731,7 @@ class FileManagerActivity : BaseActivity() { menu, menu.findItem(R.id.reloadFile), menu.findItem(R.id.photo_album), + menu.findItem(R.id.photo_album_shortcut), menu.findItem(R.id.system_file_manager), menu.findItem(R.id.action_sort_by_name), menu.findItem(R.id.action_sort_by_type), diff --git a/app/src/main/res/drawable/outline_photo_album_24.xml b/app/src/main/res/drawable/outline_photo_album_24.xml new file mode 100644 index 0000000..af4a9e8 --- /dev/null +++ b/app/src/main/res/drawable/outline_photo_album_24.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/app/src/main/res/menu/menu_files.xml b/app/src/main/res/menu/menu_files.xml index ce7ab4f..84d1a11 100644 --- a/app/src/main/res/menu/menu_files.xml +++ b/app/src/main/res/menu/menu_files.xml @@ -1,12 +1,16 @@ - + + + + android:showAsAction="ifRoom" + android:title="@string/soft"> - + android:showAsAction="ifRoom" + android:title="@string/bookmark_manager"> - + @@ -49,14 +53,6 @@ - diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a5dc786..68a4aa5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -129,7 +129,7 @@ 复制绝对路径错误。 创建文件夹 相册 - 文件管理器 + 系统文件管理器 刷新 制作模板 测试此单位 @@ -305,7 +305,7 @@ 已完成设置 编辑 全部还原 - Copyright ©coldmint 2020-%1$d All Rights Reserved. + Copyright ©Cold-Mint 2020-%1$d All Rights Reserved. 关于 附加项 打包完成后删除源文件