diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index 5597b43..2652fd4 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 47633ad..5b0d58a 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index 1e76ba9..215853c 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 09e3164..0759443 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index 5d3db14..96a1e02 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 1fa2c92..0ef1419 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index 00dce4b..a577f49 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 35f356e..6a3077c 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/app/build.gradle b/app/build.gradle index 7b87520..d2a449f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -95,6 +95,7 @@ dependencies { implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9' implementation files('libs/editor_0.8.aar') implementation project(path: ':assistantCoreLibrary') + implementation project(path: ':turretsDragView') implementation project(path: ':dialog') implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0' implementation 'com.afollestad.material-dialogs:input:3.3.0' diff --git a/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt index 198e5e8..103b6ea 100644 --- a/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/BookmarkManagerActivity.kt @@ -13,11 +13,13 @@ import android.view.MenuItem import android.view.View import androidx.appcompat.app.AlertDialog import androidx.core.view.isVisible +import com.coldmint.dialog.CoreDialog import com.coldmint.rust.pro.adapters.BookmarkAdapter import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.databean.Bookmark import com.coldmint.rust.pro.databinding.ActivityBookmarkManagerBinding import com.coldmint.rust.pro.databinding.EditBookmarkBinding +import com.coldmint.rust.pro.dialog.BookmarkDialog import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.io.File @@ -26,8 +28,26 @@ import java.util.ArrayList class BookmarkManagerActivity : BaseActivity() { private lateinit var bookmarkManager: BookmarkManager lateinit var bookmarkAdapter: BookmarkAdapter - private lateinit var pathView: EditText - private lateinit var nameView: EditText + lateinit var bookmarkDialog :BookmarkDialog + + /** + * 重新构建对话框(实例化一个对话框,并使成员变量指向他) + */ + fun recreateBookmarkDialog(){ + bookmarkDialog = BookmarkDialog(this) + bookmarkDialog.setButtonAction { + val bundle = Bundle() + val intent = + Intent(this, FileManagerActivity::class.java) + bundle.putString("type", "selectDirectents") + val thisPath = bookmarkDialog.getPath() + if (thisPath.isNotEmpty()) { + bundle.putString("path", thisPath) + } + intent.putExtra("data", bundle) + startActivityForResult(intent, 1) + } + } /** * 升级视图 @@ -46,7 +66,8 @@ class BookmarkManagerActivity : BaseActivity() { attachFileItemBinding.root.setOnLongClickListener { bookmarkAdapter.showDeleteItemDialog( bookmark.name, - viewHolder.adapterPosition, onClickPositiveButton = { i:Int, b -> + viewHolder.absoluteAdapterPosition, + onClickPositiveButton = { i: Int, b -> bookmarkManager.removeBookmark(bookmark) if (list.isEmpty()) { showNoBookmarkToView() @@ -88,90 +109,80 @@ class BookmarkManagerActivity : BaseActivity() { * @param path 路径 */ fun showEditView(title: String, name: String?, path: String?) { - val editBookmarkBinding = EditBookmarkBinding.inflate(layoutInflater) - nameView = editBookmarkBinding.nameView - pathView = editBookmarkBinding.pathEdit - + recreateBookmarkDialog() if (path != null) { - editBookmarkBinding.pathEdit.setText(path) + bookmarkDialog.setPathViewText(path) } if (name != null) { - editBookmarkBinding.nameView.setText(name) + bookmarkDialog.setNameViewText(name) } - - editBookmarkBinding.button.setOnClickListener { - val bundle = Bundle() - val intent = - Intent(this@BookmarkManagerActivity, FileManagerActivity::class.java) - bundle.putString("type", "selectDirectents") - val thisPath = pathView.text.toString() - if (thisPath.isNotEmpty()) { - bundle.putString("path", thisPath) + bookmarkDialog.setTitle(title).setAutoDismiss(false).setCancelable(false) + bookmarkDialog.setPositiveButton(R.string.dialog_ok) { editBookmarkBinding -> + val newPath = editBookmarkBinding.pathEdit.text.toString() + val newName = editBookmarkBinding.nameView.text.toString() + if (newName.isEmpty()) { + setErrorAndInput( + editBookmarkBinding.nameView, + getString(R.string.enter_bookmark_name), editBookmarkBinding.nameInputLayout + ) + return@setPositiveButton } - //bundle.putString("rootpath", mRootPath); - intent.putExtra("data", bundle) - startActivityForResult(intent, 1) - } + if (newPath.isEmpty()) { + setErrorAndInput( + editBookmarkBinding.pathEdit, + getString(R.string.enter_file_path), + editBookmarkBinding.pathInputLayout + ) + return@setPositiveButton + } + val file = File(newPath) + if (!file.exists()) { + setErrorAndInput( + editBookmarkBinding.pathEdit, + getString(R.string.bookmark_jump_failed), + editBookmarkBinding.pathInputLayout + ) + return@setPositiveButton + } + if (name == null) { + val addBookmark = bookmarkManager.addBookmark(newPath, newName) + if (addBookmark) { + updateView(bookmarkManager.list()) - var dialog: AlertDialog? = null - val materialAlertDialogBuilder = MaterialAlertDialogBuilder(this) - .setView(editBookmarkBinding.root) - .setTitle(title) - .setPositiveButton(R.string.dialog_ok) - { i, i2 -> - val newPath = pathView.text.toString() - val newName = nameView.text.toString() - if (newName.isEmpty()) { - setErrorAndInput(nameView, getString(R.string.enter_bookmark_name)) - return@setPositiveButton - } - if (newPath.isEmpty()) { - setErrorAndInput(pathView, getString(R.string.enter_file_path)) - return@setPositiveButton - } - val file = File(newPath) - if (!file.exists()) { - setErrorAndInput(pathView, getString(R.string.bookmark_jump_failed)) - return@setPositiveButton - } - if (name == null) { - val addBookmark = bookmarkManager.addBookmark(newPath, newName) - if (addBookmark) { - updateView(bookmarkManager.list()) - - } else { - setErrorAndInput( - pathView, - getString(R.string.bookmark_already_exists) - ) - } } else { - if (name == newName && path == newPath) { - dialog?.dismiss() - } else { - if (path != null) { - val oldBookmark = Bookmark(path, name) - val newBookmark = Bookmark(newPath, newName) - val addBookmark = - bookmarkManager.replaceBookmark(oldBookmark, newBookmark) - if (addBookmark) { - updateView(bookmarkManager.list()) - dialog?.dismiss() - } else { - setErrorAndInput( - pathView, - getString(R.string.bookmark_already_exists) - ) - } + setErrorAndInput( + editBookmarkBinding.pathEdit, + getString(R.string.bookmark_already_exists), + editBookmarkBinding.pathInputLayout + ) + } + } else { + if (name == newName && path == newPath) { + bookmarkDialog.dismiss() + } else { + if (path != null) { + val oldBookmark = Bookmark(path, name) + val newBookmark = Bookmark(newPath, newName) + val addBookmark = + bookmarkManager.replaceBookmark(oldBookmark, newBookmark) + if (addBookmark) { + updateView(bookmarkManager.list()) + bookmarkDialog.dismiss() + } else { + setErrorAndInput( + editBookmarkBinding.pathEdit, + getString(R.string.bookmark_already_exists), + editBookmarkBinding.pathInputLayout + ) } } } } - .setNegativeButton(R.string.dialog_close) { i, i2 -> - dialog?.dismiss() - } - .setCancelable(false) - dialog = materialAlertDialogBuilder.show() + } + bookmarkDialog.setNegativeButton(R.string.dialog_close) { + bookmarkDialog.dismiss() + } + bookmarkDialog.show() } @@ -180,15 +191,15 @@ class BookmarkManagerActivity : BaseActivity() { when (requestCode) { 1 -> if (resultCode == RESULT_OK) { val path = data!!.getStringExtra("Directents") - pathView.setText(path) - val oldName = nameView.text.toString() + bookmarkDialog.setPathViewText(path) + val oldName = bookmarkDialog.getName() if (oldName.isEmpty()) { val endIndex = path!!.lastIndexOf("/") if (endIndex > -1) { val name = path.substring(endIndex + 1, path.length) - nameView.setText(name) + bookmarkDialog.setNameViewText(name) } else { - nameView.setText(path) + bookmarkDialog.setNameViewText(path) } } } @@ -238,6 +249,7 @@ class BookmarkManagerActivity : BaseActivity() { null ) } + } } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt index caf9120..c9d0dd9 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditActivity.kt @@ -456,10 +456,10 @@ class EditActivity : BaseActivity() { if (need) { viewModel.saveAllFile( viewBinding.tabLayout.selectedTabPosition, - viewBinding.codeEditor.text.toString(), { - Toast.makeText(this, R.string.auto_save_toast, Toast.LENGTH_SHORT).show() - } - ) + viewBinding.codeEditor.text.toString() + ) { + Toast.makeText(this, R.string.auto_save_toast, Toast.LENGTH_SHORT).show() + } } } super.onPause() @@ -692,13 +692,13 @@ class EditActivity : BaseActivity() { val popupMenu = PopupMenu(this@EditActivity, it) val cutBoardMenu = popupMenu.menu.addSubMenu(R.string.cut_board_operation) val fileMenu = popupMenu.menu.addSubMenu(R.string.file_operation) - val bookmarksMenu = popupMenu.menu.addSubMenu(R.string.bookmarks_operation) + val bookmarksMenu = popupMenu.menu.addSubMenu(R.string.mine_bookmarks) cutBoardMenu.add(R.string.copy_file_name) cutBoardMenu.add(R.string.copy_file_path) cutBoardMenu.add(R.string.copy_file_absolutely_path) fileMenu.add(R.string.copy) fileMenu.add(R.string.cut_off) - fileMenu.add(R.string.mod_action9) + fileMenu.add(R.string.rename) fileMenu.add(R.string.del_mod) val bookmarkManager = editStartViewModel.bookmarkManager if (bookmarkManager.contains(file)) { @@ -814,7 +814,7 @@ class EditActivity : BaseActivity() { return@OnMenuItemClickListener false } fileAdapter?.setSelectPath(file.absolutePath, false) - } else if (title == getText(R.string.mod_action9)) { + } else if (title == getText(R.string.rename)) { val absolutePath = file.absolutePath var canRename = true if (viewModel.openedSourceFileListLiveData.value.isNotEmpty()) { @@ -835,7 +835,7 @@ class EditActivity : BaseActivity() { } val oldName = file.name MaterialDialog(this@EditActivity).show { - title(R.string.mod_action9) + title(R.string.rename) input( maxLength = 255, waitForPositiveButton = false, prefill = oldName diff --git a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt index 2b1a643..cfef658 100644 --- a/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/EditModInfoActivity.kt @@ -75,7 +75,7 @@ class EditModInfoActivity : BaseActivity() { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { - viewBinding.toolbar.title = getText(R.string.mod_action2) + title = getText(R.string.mod_action2) setReturnButton() val intent = intent val bundle = intent.getBundleExtra("data") 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 9e69bd3..2c82a38 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -23,13 +23,20 @@ import com.afollestad.materialdialogs.actions.setActionButtonEnabled import com.afollestad.materialdialogs.input.getInputField import com.afollestad.materialdialogs.input.input import com.afollestad.materialdialogs.list.listItems +import com.coldmint.dialog.CoreDialog +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.tool.FileOperator +import com.coldmint.rust.core.tool.LineParser import com.coldmint.rust.pro.adapters.FileAdapter +import com.coldmint.rust.pro.adapters.FileTabAdapter +import com.coldmint.rust.pro.databean.FileTab import com.coldmint.rust.pro.databinding.ActivityFileBinding import com.coldmint.rust.pro.interfaces.BookmarkListener import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.viewmodel.FileManagerViewModel +import com.google.android.material.chip.Chip import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.google.android.material.snackbar.SnackbarContentLayout import me.zhanghai.android.fastscroll.FastScrollerBuilder import java.io.File import java.lang.Exception @@ -42,15 +49,13 @@ class FileManagerActivity : BaseActivity() { // private var mRoot = directs // var filePath = "" // -// //哈希表映射(名称,路径) -// val bookmarkMap = HashMap() -// val executorService = Executors.newSingleThreadExecutor() + + // val executorService = Executors.newSingleThreadExecutor() // // //type可为默认default,选择文件夹selectDirectents,选择文件selectFile // var mStartType: String? = "default" // private var mFileAdapter: FileAdapter? = null // private var mProcessFiles = false -// private val bookmarkManager: BookmarkManager by lazy { BookmarkManager(this) } // private var additionalData: String? = null // private fun initView() { // title = getString(R.string.file_manager) @@ -409,40 +414,22 @@ class FileManagerActivity : BaseActivity() { // } // // -// /** -// * 添加书签菜单 -// */ -// fun addJumpBookMenu(menu: Menu) { -// val bookmarkContent: SubMenu? = if (bookmarkManager.size > 0) { -// menu.addSubMenu(R.string.jump_a_bookmark) -// } else { -// null -// } -// bookmarkMap.clear() -// bookmarkManager.fromList(object : BookmarkListener { -// override fun find(path: String, name: String) { -// bookmarkMap[name] = path -// bookmarkContent!!.add(name) -// } -// -// }) -// } -// -// /** + + // /** // * 点击书签项目 // */ // fun loadBook(menuTitle: CharSequence) { // if (bookmarkMap.containsKey(menuTitle)) { // val path = bookmarkMap[menuTitle] // if (path != null) { -// val rootPath = mRoot.absolutePath +// val rootPath = viewModel.getRootPath() // if (path.startsWith(rootPath)) { // val newFile = File(path) // if (newFile.exists()) { // if (newFile.isDirectory) { -// loadFiles(newFile) +// viewModel.loadFiles(newFile.absolutePath) // } else { -// tryOpenFile(newFile) +//// tryOpenFile(newFile) // } // } else { // Snackbar.make( @@ -465,71 +452,45 @@ class FileManagerActivity : BaseActivity() { // // // override fun onPause() { -// bookmarkManager.save() +// viewModel.getBookmarkManager().save() // super.onPause() // } -// -// override fun onResume() { -// bookmarkManager.load() -// super.onResume() -// } + + override fun onResume() { + viewModel.getBookmarkManager().load() + loadMineBookmarksMenu() + super.onResume() + } // // -// /** -// * 解析文件路径 -// * -// * @param context 上下文环境 -// * @param intent 意图 -// * @return 成功返回文件路径,失败返回null -// */ -// private fun parseFilePath(context: Context, intent: Intent?): String? { -// return try { -// if (intent != null) { -// val uri = intent.data -// var chooseFilePath: String? = null -// if ("file".equals(uri!!.scheme, ignoreCase = true)) { //使用第三方应用打开 -// chooseFilePath = uri.path -// Toast.makeText(context, chooseFilePath, Toast.LENGTH_SHORT).show() -// return chooseFilePath -// } -// chooseFilePath = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { //4.4以后 -// getPath(context, uri) -// } else { //4.4以下下系统调用方法 -// getRealPathFromURI(context, uri) -// } -// return chooseFilePath -// } -// null -// } catch (e: Exception) { -// Snackbar.make(viewBinding.fab, R.string.parse_file_exception, Snackbar.LENGTH_SHORT) -// .show() -// null -// } -// } -// -// override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { -// super.onActivityResult(requestCode, resultCode, data) -// if (resultCode == RESULT_OK) { -// if (mStartType == "selectFile" && requestCode == 1) { -// val path = FileOperator.parsePicturePath(this@FileManagerActivity, data) -// if (path != null) { -// val intent = Intent() -// intent.putExtra("File", path) -// setResult(RESULT_OK, intent) + + // + 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) // bookmarkManager.save() -// finish() -// } -// } else if (mStartType == "selectFile" && requestCode == 2) { -// val path = parseFilePath(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) { -// //新建源文件 + finish() + } + } else { + Toast.makeText(this, "未设置的操作", Toast.LENGTH_SHORT).show() + } + // else if (requestCode == 3) { + //新建源文件 // loadFiles(directs) // } else if (requestCode == 4) { // val file = File(data!!.getStringExtra("File")) @@ -545,59 +506,61 @@ class FileManagerActivity : BaseActivity() { // loadFiles(directs) // } // } -// } -// } -// -// override fun onOptionsItemSelected(item: MenuItem): Boolean { -// val id = item.itemId -// when (id) { -// android.R.id.home -> { + } + } + + // + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + when (id) { + android.R.id.home -> { // bookmarkManager.save() -// finish() -// return true -// } -// R.id.reloadFile -> { -// loadFiles(directs) -// 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 -// } -// R.id.creteFolder -> { + 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 + } + R.id.creteFolder -> { // createFolderAction() -// return true -// } -// } + return true + } + } // loadBook(item.title) -// return super.onOptionsItemSelected(item) -// } -// -// override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { -// return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { -// if (directs.absolutePath == mRoot.absolutePath) { + return super.onOptionsItemSelected(item) + } + + override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { + return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { + if (viewModel.getCurrentPath() == viewModel.getRootPath()) { // bookmarkManager.save() -// finish() -// true -// } else { -// returnDirects() -// false -// } -// } else super.onKeyDown(keyCode, event) -// } -// + finish() + true + } else { + viewModel.returnDirects() + false + } + } else super.onKeyDown(keyCode, event) + } + + // // override fun onCreateOptionsMenu(menu: Menu): Boolean { // val inflater = menuInflater // inflater.inflate(R.menu.menu_files, menu) @@ -615,10 +578,11 @@ class FileManagerActivity : BaseActivity() { // loadFiles(file) // } // -// fun initAction() { -// viewBinding.fab.setOnClickListener { -// val intent = Intent() -// when (mStartType) { + fun initAction() { + viewBinding.fab.setOnClickListener { + val intent = Intent() + val startType = viewModel.startTypeData + when (startType) { // "exportFile" -> { // val oldFile = File(additionalData) // val result = FileOperator.copyFile( @@ -642,8 +606,11 @@ class FileManagerActivity : BaseActivity() { // bookmarkManager.save() // finish() // } -// "default" -> { -// val popupMenu = PopupMenu(this@FileManagerActivity, viewBinding.fab) + FileManagerViewModel.StartType.SELECT_FILE -> { + + } + FileManagerViewModel.StartType.DEFAULT -> { + val popupMenu = PopupMenu(this@FileManagerActivity, viewBinding.fab) // if (mFileAdapter != null) { // val selectPath = mFileAdapter!!.selectPath // if (selectPath != null && mProcessFiles == false) { @@ -654,37 +621,37 @@ class FileManagerActivity : BaseActivity() { // } // } // } -// popupMenu.menu.add(R.string.create_unit) -// popupMenu.menu.add(R.string.create_folder) -// popupMenu.menu.add(R.string.select_file) -// popupMenu.setOnMenuItemClickListener { item -> -// val title = item.title + popupMenu.menu.add(R.string.create_unit) + popupMenu.menu.add(R.string.create_folder) + 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 = -// Intent(this@FileManagerActivity, CreateUnitActivity::class.java) -// val bundle = Bundle() -// bundle.putString("modPath", directs.absolutePath) -// bundle.putString("createPath", directs.absolutePath) -// intent.putExtra("data", bundle) -// startActivityForResult(intent, 3) -// } -// getText(R.string.select_file) -> { -// val bundle = Bundle() -// val intent = -// Intent( -// this@FileManagerActivity, -// FileManagerActivity::class.java -// ) -// bundle.putString("type", "selectFile") -// //bundle.putString("path", modClass.getModFile().getAbsolutePath()); -// intent.putExtra("data", bundle) -// startActivityForResult(intent, 4) -// } -// getText(R.string.create_folder) -> { -// createFolderAction() -// } + when (title) { + getText(R.string.create_unit) -> { + val intent = + Intent(this@FileManagerActivity, CreateUnitActivity::class.java) + val bundle = Bundle() + bundle.putString("modPath", viewModel.getCurrentPath()) + bundle.putString("createPath", viewModel.getCurrentPath()) + intent.putExtra("data", bundle) + startActivityForResult(intent, 3) + } + getText(R.string.select_file) -> { + val bundle = Bundle() + val intent = + Intent( + this@FileManagerActivity, + FileManagerActivity::class.java + ) + bundle.putString("type", "selectFile") + //bundle.putString("path", modClass.getModFile().getAbsolutePath()); + intent.putExtra("data", bundle) + startActivityForResult(intent, 4) + } + getText(R.string.create_folder) -> { + createFolderAction() + } // getText(R.string.copy_to_this) -> { // Thread { // mProcessFiles = true @@ -731,14 +698,17 @@ class FileManagerActivity : BaseActivity() { // } // }.start() // } -// } -// false -// } -// popupMenu.show() -// } -// } -// } -// } + } + false + } + popupMenu.show() + } + else -> { + + } + } + } + } // // /** // * 创建文件夹活动 @@ -771,25 +741,8 @@ class FileManagerActivity : BaseActivity() { // } // // -// /** -// * 获取uri的绝对路径 -// * -// * @param context 上下文环境 -// * @param contentUri uri -// * @return 文件路径 -// */ -// private fun getRealPathFromURI(context: Context, contentUri: Uri?): String? { -// var res: String? = null -// val proj = arrayOf(MediaStore.Images.Media.DATA) -// val cursor = context.contentResolver.query(contentUri!!, proj, null, null, null) -// if (null != cursor && cursor.moveToFirst()) { -// val column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) -// res = cursor.getString(column_index) -// cursor.close() -// } -// return res -// } -// + + // // private fun getPath(context: Context, uri: Uri?): String? { // val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT // @@ -885,20 +838,50 @@ class FileManagerActivity : BaseActivity() { ViewModelProvider(this).get(FileManagerViewModel::class.java) } + + /** + * 创建文件夹活动 + */ + fun createFolderAction() { + InputDialog(this).setTitle(R.string.create_folder).setHint(R.string.file_name) + .setCancelable(false).setInputCanBeEmpty(false).setMaxNumber(255) + .setErrorTip { s, textInputLayout -> + val newFolder = File(viewModel.getCurrentPath() + "/" + s) + if (newFolder.exists()) { + textInputLayout.error = getString(R.string.folder_error) + } else { + textInputLayout.isErrorEnabled = false + } + }.setPositiveButton(R.string.dialog_ok) { i -> + val newFolder = File(viewModel.getCurrentPath() + "/" + i) + val res = newFolder.mkdirs() + adapter?.addItem(newFolder) + res + }.setNegativeButton(R.string.dialog_cancel) { + + }.show() + } + + private var adapter: FileAdapter? = null override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { if (canUseView) { setReturnButton() viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity) + val linearLayoutManager = LinearLayoutManager(this) + linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL + viewBinding.fileTabNav.layoutManager = linearLayoutManager loadTitle() loadObserve() + initAction() FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() .setPopupTextProvider(adapter).build() viewBinding.swipeRefreshLayout.setOnRefreshListener { viewModel.loadFiles(viewModel.getCurrentPath()) viewBinding.swipeRefreshLayout.isRefreshing = false } + viewModel.initBookmarkManager(this) viewModel.loadFiles() viewModel.loadSortType(this) } else { @@ -911,6 +894,17 @@ class FileManagerActivity : BaseActivity() { if (bundle.containsKey("path")) { viewModel.currentPathLiveData.value = bundle.getString("path") } + if (bundle.containsKey("type")) { + val type = bundle.getString("type") + viewModel.startTypeData = when (type) { + "selectDirectents" -> { + FileManagerViewModel.StartType.SELECT_DIRECTORY + } + else -> { + FileManagerViewModel.StartType.DEFAULT + } + } + } if (bundle.containsKey("rootpath")) { viewModel.setRootPath(bundle.getString("rootpath")) } @@ -923,6 +917,9 @@ class FileManagerActivity : BaseActivity() { if (value != null) { setSortType(value) } + if (viewModel.startTypeData != FileManagerViewModel.StartType.SELECT_FILE) { + menu.removeItem(R.id.selectFile) + } menuBinding.actionSortByType.setOnMenuItemClickListener { viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_TYPE true @@ -939,16 +936,41 @@ class FileManagerActivity : BaseActivity() { viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_LAST_MODIFIED true } + loadMineBookmarksMenu() + menuBinding.bookmarkManagerItem.setOnMenuItemClickListener { + val intent = Intent(this, BookmarkManagerActivity::class.java) + startActivity(intent) + true + } return true } + /** + * 加载我的书签列表 + */ + fun loadMineBookmarksMenu() { + if (this::menuBinding.isInitialized) { + menuBinding.mineBookmarksMenu.subMenu.clear() + viewModel.getBookmarkManager().fromList(object : BookmarkListener { + override fun find(path: String, name: String) { + val item = menuBinding.mineBookmarksMenu.subMenu.add(name) + item.setOnMenuItemClickListener { + viewModel.currentPathLiveData.value = path + true + } + } + }) + } + } + + /** * 加载观察者 */ fun loadObserve() { viewModel.loadStateLiveData.observe(this) { - viewBinding.recyclerView.isVisible = !it + viewBinding.fileTabNav.isVisible = !it viewBinding.swipeRefreshLayout.isVisible = !it viewBinding.fileError.isVisible = it viewBinding.progressBar.isVisible = it @@ -967,13 +989,106 @@ class FileManagerActivity : BaseActivity() { } else { if (file.isDirectory) { viewModel.currentPathLiveData.value = file.absolutePath - } else { - fileItemBinding.more.setOnClickListener { - val popupMenu = PopupMenu(this, fileItemBinding.more) - popupMenu.inflate(R.menu.menu_files) - popupMenu.show() + } + } + } + fileItemBinding.more.setOnClickListener { + if (file == null) { + return@setOnClickListener + } + val finalFile = file + val popupMenu = PopupMenu(this, fileItemBinding.more) + popupMenu.inflate(R.menu.menu_files_actions) + val bookAction = popupMenu.menu.findItem(R.id.bookmarkAction) + bookAction.title = if (viewModel.getBookmarkManager().contains(finalFile)) { + getString(R.string.remove_bookmark) + } else { + getString(R.string.add_bookmark) + } + popupMenu.show() + popupMenu.setOnMenuItemClickListener { + when (it.itemId) { + R.id.bookmarkAction -> { + if (viewModel.getBookmarkManager().contains(finalFile)) { + val remove = + viewModel.getBookmarkManager() + .removeBookmark(finalFile.absolutePath) + if (remove) { + Snackbar.make( + viewBinding.fab, + R.string.remove_bookmark_success, + Snackbar.LENGTH_SHORT + ).show() + } else { + Snackbar.make( + viewBinding.fab, + R.string.remove_bookmark_fail, + Snackbar.LENGTH_SHORT + ).show() + } + } else { + val add = + viewModel.getBookmarkManager() + .addBookmark(finalFile.absolutePath, finalFile.name) + if (add) { + Snackbar.make( + viewBinding.fab, + R.string.add_bookmark_success, + Snackbar.LENGTH_SHORT + ).show() + } else { + Snackbar.make( + viewBinding.fab, + R.string.add_bookmark_fail, + Snackbar.LENGTH_SHORT + ).show() + } + } + viewModel.getBookmarkManager().save() + loadMineBookmarksMenu() + } + R.id.renameAction -> { + val finalFile = + adapter!!.getItemData(viewHolder.absoluteAdapterPosition) + val oldname = finalFile!!.name + InputDialog(this).setInputCanBeEmpty(false) + .setTitle(R.string.rename).setMaxNumber(255) + .setHint(R.string.file_name).setText(oldname) + .setPositiveButton(R.string.dialog_ok) { string -> + if (string.isNotEmpty() && string != oldname) { + val newFile = + File(FileOperator.getSuperDirectory(finalFile) + "/" + string) + finalFile.renameTo(newFile) + adapter?.replaceItem( + newFile, + viewHolder.absoluteAdapterPosition + ) + } + true + }.setNegativeButton(R.string.dialog_cancel) { + + }.setCancelable(false).show() + } + R.id.deleteAction -> { + val finalFile = + adapter!!.getItemData(viewHolder.absoluteAdapterPosition) + val tip = String.format( + getString(R.string.delete_prompt), + finalFile!!.name + ) + CoreDialog(this).setTitle(R.string.delete_title) + .setMessage(tip) + .setPositiveButton(R.string.delete_title) { + val delete = FileOperator.delete_files(finalFile) + if (delete) { + adapter?.removeItem(i) + } + }.setNegativeButton(R.string.dialog_cancel) { + + }.show() } } + true } } } @@ -983,6 +1098,33 @@ class FileManagerActivity : BaseActivity() { } } viewModel.currentPathLiveData.observe(this) { + val root = getString(R.string.root_path) + val path = root + it.substring(viewModel.getRootPath().length) + val lineParser = LineParser(path) + lineParser.symbol = "/" + lineParser.parserSymbol = true + val fileTabList = ArrayList() + val stringBuilder = StringBuilder() + lineParser.analyse { lineNum, lineData, isEnd -> + stringBuilder.append(lineData) + if (lineData.isNotBlank() && lineData != lineParser.symbol) { + val tab = FileTab( + lineData, + viewModel.getRootPath() + stringBuilder.toString().substring(root.length) + ) + fileTabList.add(tab) + } + true + } + val adapter = FileTabAdapter(this, fileTabList) + adapter.setItemEvent { i, itemFileTabBinding, viewHolder, fileTab -> + itemFileTabBinding.button.setOnClickListener { + viewModel.currentPathLiveData.value = fileTab.path + } + } + val manager = viewBinding.fileTabNav.layoutManager as LinearLayoutManager + manager.scrollToPosition(fileTabList.size - 1) + viewBinding.fileTabNav.adapter = adapter viewModel.loadFiles(it) } } @@ -1042,7 +1184,10 @@ class FileManagerActivity : BaseActivity() { val systemFileManagerItem: MenuItem, val actionSortByName: MenuItem, val actionSortByType: MenuItem, - val actionSortBySize: MenuItem, val actionSortByLastModified: MenuItem + val actionSortBySize: MenuItem, + val actionSortByLastModified: MenuItem, + val bookmarkItem: MenuItem, + val bookmarkManagerItem: MenuItem, val mineBookmarksMenu: MenuItem ) { companion object { //填充 @@ -1056,7 +1201,10 @@ class FileManagerActivity : BaseActivity() { menu.findItem(R.id.action_sort_by_name), menu.findItem(R.id.action_sort_by_type), menu.findItem(R.id.action_sort_by_size), - menu.findItem(R.id.action_sort_by_last_modified) + menu.findItem(R.id.action_sort_by_last_modified), + menu.findItem(R.id.action_bookmark), + menu.findItem(R.id.bookmark_manager), + menu.findItem(R.id.mine_bookmarks) ) } } diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt index 031d181..d788b7a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ApplicationListAdapter.kt @@ -39,7 +39,7 @@ import kotlin.concurrent.thread * @constructor */ class ApplicationListAdapter( - val context: Context, dataList: MutableList + context: Context, dataList: MutableList ) : BaseAdapter(context, dataList) { val handler: Handler by lazy { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/AttachFileAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/AttachFileAdapter.kt index 06b6a47..eaa5de0 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/AttachFileAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/AttachFileAdapter.kt @@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.AttachFileItemBinding import java.io.File import java.util.ArrayList -class AttachFileAdapter(val context: Context, dataList: MutableList) : +class AttachFileAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/AuditModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/AuditModAdapter.kt index 8cfd6f8..9684b43 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/AuditModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/AuditModAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2022/1/10 8:49 */ -class AuditModAdapter(val context: Context, dataList: MutableList) : +class AuditModAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt index 99ea8b0..7ee27bf 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt @@ -7,7 +7,7 @@ import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databean.Bookmark import com.coldmint.rust.pro.databinding.AttachFileItemBinding -class BookmarkAdapter(val context: Context, dataList: MutableList) : +class BookmarkAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { /** diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt index f7a9aa2..ea415a1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt @@ -18,7 +18,7 @@ import com.coldmint.rust.pro.tool.TextStyleMaker * @author Cold Mint * @date 2021/12/12 20:50 */ -class CommentAdapter(val context: Context, dataList: MutableList) : +class CommentAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( @@ -37,7 +37,8 @@ class CommentAdapter(val context: Context, dataList: MutableList ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt index 63d9b78..4a1d3c5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CompileLogAdapter.kt @@ -17,7 +17,7 @@ import com.coldmint.rust.pro.databinding.LogItemBinding import com.coldmint.rust.pro.tool.GlobalMethod //编译日志适配器 -class CompileLogAdapter(val context: Context, analysisResults: MutableList) : +class CompileLogAdapter( context: Context, analysisResults: MutableList) : BaseAdapter(context, analysisResults) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CouponAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CouponAdapter.kt index 5b9ed74..e50900f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CouponAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CouponAdapter.kt @@ -13,7 +13,7 @@ import kotlin.math.roundToInt * @author Cold Mint * @date 2022/1/10 20:47 */ -class CouponAdapter(val context: Context, dataList: MutableList) : +class CouponAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { val timeLimit: String by lazy { context.getString(R.string.time_limit) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt index 22ab4de..67c1b14 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/DynamicAdapter.kt @@ -29,7 +29,7 @@ import org.w3c.dom.Text * @author Cold Mint * @date 2021/12/28 18:29 */ -class DynamicAdapter(val context: Context, dataList: MutableList) : +class DynamicAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt index 2eb9cf5..5b365eb 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ErrorInfoAdapter.kt @@ -12,7 +12,7 @@ import com.coldmint.rust.pro.databean.ErrorInfo import com.coldmint.rust.pro.databinding.ItemErrorInfoBinding import com.coldmint.rust.pro.tool.GlobalMethod -class ErrorInfoAdapter(val context: Context, dataList: ArrayList) : +class ErrorInfoAdapter( context: Context, dataList: ArrayList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt index 856b054..ccdddd5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt @@ -24,7 +24,7 @@ import java.lang.StringBuilder import java.text.SimpleDateFormat import java.util.ArrayList -class FileAdapter(private val context: Context, dataList: MutableList) : +class FileAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList), PopupTextProvider { /** diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FileTabAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FileTabAdapter.kt new file mode 100644 index 0000000..a679885 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FileTabAdapter.kt @@ -0,0 +1,35 @@ +package com.coldmint.rust.pro.adapters + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import com.coldmint.rust.pro.R +import com.coldmint.rust.pro.base.BaseAdapter +import com.coldmint.rust.pro.databean.FileTab +import com.coldmint.rust.pro.databinding.ItemFileTabBinding + +class FileTabAdapter(context: Context, dataList: MutableList) : + BaseAdapter(context, dataList) { + override fun getViewBindingObject( + layoutInflater: LayoutInflater, + parent: ViewGroup, + viewType: Int + ): ItemFileTabBinding { + return ItemFileTabBinding.inflate(layoutInflater, parent, false) + } + + override fun onBingView( + data: FileTab, + viewBinding: ItemFileTabBinding, + viewHolder: ViewHolder, + position: Int + ) { + viewBinding.button.text = data.name + val isEnd = position == dataList.size - 1 + viewBinding.button.icon = if (isEnd) { + null + } else { + context.getDrawable(R.drawable.ic_baseline_chevron_right_24) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt index de03a6d..535a5b5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt @@ -9,7 +9,7 @@ import com.coldmint.rust.pro.databean.FunctionInfo import com.coldmint.rust.pro.databinding.ItemFunBinding import com.coldmint.rust.pro.databinding.ItemServiceBinding -class FunAdapter(val context: Context, dataList: MutableList) : +class FunAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt index 7f5fcf5..f99fdc0 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/LibAdapter.kt @@ -18,7 +18,7 @@ import com.coldmint.rust.pro.databinding.ItemLibBinding import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.util.ArrayList -class LibAdapter(val context: Context, dataList: ArrayList) : +class LibAdapter(context: Context, dataList: ArrayList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/MapAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/MapAdapter.kt index b8a6642..6aed3ed 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/MapAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/MapAdapter.kt @@ -13,7 +13,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2022/1/5 11:05 */ -class MapAdapter(val context: Context, dataList: MutableList) : +class MapAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, @@ -31,7 +31,8 @@ class MapAdapter(val context: Context, dataList: MutableList) : ) { val icon = data.getIconFile() if (icon != null) { - Glide.with(context).load(icon).apply(GlobalMethod.getRequestOptions()).into(viewBinding.mapIcon) + Glide.with(context).load(icon).apply(GlobalMethod.getRequestOptions()) + .into(viewBinding.mapIcon) } viewBinding.mapUpTime.text = data.lastModificationTime viewBinding.mapNameView.text = data.getName() diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/MapAndMusicAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/MapAndMusicAdapter.kt index 66d82bf..caf2a73 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/MapAndMusicAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/MapAndMusicAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.databinding.MapAndMusicItemBinding import java.io.File import java.util.ArrayList -class MapAndMusicAdapter(val context: Context, dataList: ArrayList, val isMusic: Boolean) : +class MapAndMusicAdapter(context: Context, dataList: ArrayList, val isMusic: Boolean) : BaseAdapter(context, dataList) { val prefixName = "[noloop]" @@ -36,7 +36,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList, val is popupMenu.menu.add(R.string.disabled_loop) } } - popupMenu.menu.add(R.string.mod_action9) + popupMenu.menu.add(R.string.rename) popupMenu.menu.add(R.string.delete_title) popupMenu.setOnMenuItemClickListener { item -> val title = item.title.toString() @@ -71,7 +71,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList, val is } } removeItem(position) - } else if (title == context.getString(R.string.mod_action9)) { + } else if (title == context.getString(R.string.rename)) { var iconFile: File? = null if (!isMusic) { val path = targetFile.absolutePath @@ -84,7 +84,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList, val is val oldName = fileName val finalIconFile = iconFile MaterialDialog(context).show { - title(R.string.mod_action9) + title(R.string.rename) input( maxLength = 255, waitForPositiveButton = false, prefill = oldName diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt index ea6a358..5c3129d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModActionAdapter.kt @@ -25,6 +25,7 @@ import android.view.View import android.view.inputmethod.InputMethodManager import androidx.appcompat.app.AlertDialog import androidx.core.content.ContentProviderCompat.requireContext +import com.coldmint.dialog.InputDialog import com.coldmint.rust.core.* import com.google.android.material.snackbar.Snackbar import com.coldmint.rust.core.dataBean.CompileConfiguration @@ -38,6 +39,7 @@ import com.coldmint.rust.pro.R import com.coldmint.rust.pro.databinding.ModActionItemBinding import com.coldmint.rust.pro.fragments.ModFragment import com.coldmint.rust.pro.tool.GlobalMethod +import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.gson.Gson import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Job @@ -118,7 +120,7 @@ class ModActionAdapter( mContext.getString(R.string.mod_action2) -> { editInfoItem() } - mContext.getString(R.string.mod_action9) -> { + mContext.getString(R.string.rename) -> { renameItem() } mContext.getString(R.string.release) -> { @@ -441,46 +443,20 @@ class ModActionAdapter( * 点击了重命名 */ private fun renameItem() { - val builder = AlertDialog.Builder( - mContext - ) - val dialogview = LayoutInflater.from(mContext).inflate(R.layout.input_dialog, null, false) - val editText = dialogview.findViewById(R.id.dialog_edit) val mod_file = File(mModpath) val oldname = ModClass(mod_file).modName - editText.setText(oldname) - editText.postDelayed(object : Runnable { - override fun run() { - editText.requestFocus() - val imm = - mContext.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - val a = imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) - if (!a) { - Toast.makeText(mContext, R.string.unexpected_error, Toast.LENGTH_SHORT).show() + InputDialog(mContext).setInputCanBeEmpty(false).setTitle(R.string.rename).setMaxNumber(255) + .setHint(R.string.file_name).setText(oldname) + .setPositiveButton(R.string.dialog_ok) { string -> + if (string.isNotEmpty() && string != oldname) { + val newFile = File(FileOperator.getSuperDirectory(mod_file) + "/" + string) + mod_file.renameTo(newFile) + mModFragment.loadMods() } - } - }, 180) - val okview = dialogview.findViewById(R.id.completion_button) - val calview = dialogview.findViewById(R.id.cancel_button_view) - builder.setTitle(R.string.mod_action9) - builder.setCancelable(false) - builder.setView(dialogview) - val alertDialog = builder.create() - alertDialog.show() - calview.setOnClickListener(object : View.OnClickListener { - override fun onClick(v: View) { - alertDialog.dismiss() - } - }) - okview.setOnClickListener { - val string = editText.text.toString() - if (string.isNotEmpty() && string != oldname) { - val newFile = File(FileOperator.getSuperDirectory(mod_file) + "/" + string) - mod_file.renameTo(newFile) - mModFragment.loadMods() - } - alertDialog.dismiss() - } + true + }.setNegativeButton(R.string.dialog_cancel) { + + }.setCancelable(false).show() } /** @@ -489,7 +465,7 @@ class ModActionAdapter( private fun editInfoItem() { val fileBundle = Bundle() val infoIntent = Intent(mContext, EditModInfoActivity::class.java) - val modClass = ModClass(File(mModpath)) +// val modClass = ModClass(File(mModpath)) //fileBundle.putString("infoPath", modClass.getInfoFile().getAbsolutePath()); fileBundle.putString("modPath", mModpath) infoIntent.putExtra("data", fileBundle) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt index b53cb7a..94fa7b5 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt @@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.ModListItemBinding /*模组适配器 * 此适配器只能使用于ModFragment成员变量按需传递。 * */ -class ModAdapter(private val context: Context, dataList: MutableList) : +class ModAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { init { @@ -68,7 +68,8 @@ class ModAdapter(private val context: Context, dataList: MutableList) ) ) } else { - Glide.with(context).load(data.modIcon).apply(GlobalMethod.getRequestOptions()).into(viewBinding.modIcon) + Glide.with(context).load(data.modIcon).apply(GlobalMethod.getRequestOptions()) + .into(viewBinding.modIcon) } } else { val drawable = context.getDrawable(R.drawable.file) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt index 8a275cd..689fd40 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt @@ -27,7 +27,7 @@ import java.lang.StringBuilder * @date 2022/1/9 11:03 */ class ReportAdapter( - val context: Context, + context: Context, dataList: MutableList ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt index 19b49ea..e8f7b4a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2021/11/20 18:38 */ -class ScreenshotAdapter(val context: Context, dataList: ArrayList) : +class ScreenshotAdapter( context: Context, dataList: ArrayList) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt index 30520e7..9c58a9b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/SearchResultAdapter.kt @@ -24,7 +24,7 @@ import java.util.* * @constructor */ class SearchResultAdapter( - val context: Context, + context: Context, val keyWord: String, dataList: MutableList ) : diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt index 9a058c9..2845f43 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt @@ -25,7 +25,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog import java.io.File class TemplateListAdapter( - val context: Context, + context: Context, dataList: ArrayList, private val language: String, private val rootPath: String diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt index 8ff6dd2..c29301b 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt @@ -30,7 +30,7 @@ import java.util.ArrayList //模板制作适配器 -class TemplateMakerAdapter(val context: Context, dataList: MutableList) : +class TemplateMakerAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { private var tags = ArrayList() diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ThanksAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ThanksAdapter.kt index 7c0cd05..6f9a29f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ThanksAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ThanksAdapter.kt @@ -15,7 +15,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2022/1/3 19:39 */ -class ThanksAdapter(val context: Context, dataList: MutableList) : +class ThanksAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt index 5037baf..d5b9291 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt @@ -18,7 +18,7 @@ import java.util.* import kotlin.Exception class UnitAdapter( - private val context: Context, + context: Context, dataList: MutableList, val key: String ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UserAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UserAdapter.kt index c74b239..790e54d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UserAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UserAdapter.kt @@ -17,7 +17,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2021/12/23 22:44 */ -class UserAdapter(val context: Context, dataList: MutableList) : +class UserAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { val defaultIntroduced = context.getString(R.string.defaultIntroduced) override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UserHeadAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UserHeadAdapter.kt index 077ed2d..6c262bd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UserHeadAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UserHeadAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2021/12/28 10:59 */ -class UserHeadAdapter(val context: Context, list: MutableList) : +class UserHeadAdapter( context: Context, list: MutableList) : BaseAdapter(context, list) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt index 01830ef..700e993 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt @@ -12,7 +12,7 @@ import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.WebModItemBinding import com.coldmint.rust.pro.tool.GlobalMethod -class WebModAdapter(val context: Context, dataList: MutableList) : +class WebModAdapter( context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt index 1bf7141..c576ed8 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAllInfoAdapter.kt @@ -23,7 +23,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @date 2022/1/4 10:59 */ class WebModAllInfoAdapter( - val context: Context, + context: Context, list: MutableList ) : BaseAdapter(context, list) { diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt index bad30d1..18ad473 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt @@ -21,7 +21,7 @@ import com.github.promeg.pinyinhelper.Pinyin abstract class BaseAdapter( - private val context: Context, + protected val context: Context, protected var dataList: MutableList ) : RecyclerView.Adapter>() { diff --git a/app/src/main/java/com/coldmint/rust/pro/databean/FileTab.kt b/app/src/main/java/com/coldmint/rust/pro/databean/FileTab.kt new file mode 100644 index 0000000..49ce239 --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/databean/FileTab.kt @@ -0,0 +1,9 @@ +package com.coldmint.rust.pro.databean + +/** + * 文件标签 + * @property name String + * @property path String + * @constructor + */ +data class FileTab(val name: String, val path: String) \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/dialog/BookmarkDialog.kt b/app/src/main/java/com/coldmint/rust/pro/dialog/BookmarkDialog.kt new file mode 100644 index 0000000..3c4531d --- /dev/null +++ b/app/src/main/java/com/coldmint/rust/pro/dialog/BookmarkDialog.kt @@ -0,0 +1,167 @@ +package com.coldmint.rust.pro.dialog + +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.text.Editable +import android.text.TextWatcher +import android.view.LayoutInflater +import android.widget.Button +import android.widget.Toast +import androidx.core.app.ActivityCompat.startActivityForResult +import com.coldmint.dialog.BaseAppDialog +import com.coldmint.rust.pro.FileManagerActivity +import com.coldmint.rust.pro.databinding.EditBookmarkBinding + +class BookmarkDialog(context: Context) : BaseAppDialog(context) { + + + private val editBookmarkBinding: EditBookmarkBinding by lazy { + EditBookmarkBinding.inflate(LayoutInflater.from(context)) + } + + init { + setView(editBookmarkBinding.root) + editBookmarkBinding.pathEdit.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + + } + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + } + + override fun afterTextChanged(p0: Editable?) { + editBookmarkBinding.pathInputLayout.isErrorEnabled = false + } + }) + editBookmarkBinding.nameView.addTextChangedListener(object : TextWatcher { + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + + } + + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) { + + } + + override fun afterTextChanged(p0: Editable?) { + editBookmarkBinding.nameInputLayout.isErrorEnabled = false + } + + }) + } + + /** + * 设置按钮点击事件 + * @param func Function1<[@kotlin.ParameterName] EditBookmarkBinding, Unit> + */ + fun setButtonAction(func: ((editBookmarkBinding: EditBookmarkBinding) -> Unit)) { + editBookmarkBinding.button.setOnClickListener { + func.invoke(editBookmarkBinding) + } + } + + /** + * 设置路径文本 + * @param text String + */ + fun setPathViewText(text: String?) { + editBookmarkBinding.pathEdit.setText(text) + } + + + /** + * 返回路径名称 + * @return String + */ + fun getPath(): String { + return editBookmarkBinding.pathEdit.text.toString() + } + + /** + * 获取名称输入框内容 + */ + fun getName(): String { + return editBookmarkBinding.nameView.text.toString() + } + + /** + * 设置名称输入框文本 + * @param text String? + */ + fun setNameViewText(text: String?) { + editBookmarkBinding.nameView.setText(text) + } + + + override fun setTitle(string: String): BookmarkDialog { + editBookmarkBinding.titleView.text = string + return this + } + + override fun setTitle(stringRes: Int): BookmarkDialog { + editBookmarkBinding.titleView.setText(stringRes) + return this + } + + + @Deprecated("已废弃,请改用带参调用") + override fun setPositiveButton(text: String, func: () -> Unit): BookmarkDialog { + return super.setPositiveButton(text, func) + } + + @Deprecated("已废弃,请改用带参调用") + override fun setPositiveButton(textRes: Int, func: () -> Unit): BookmarkDialog { + return super.setPositiveButton(textRes, func) + } + + fun setPositiveButton( + text: String, + func: (EditBookmarkBinding) -> Unit + ): BookmarkDialog { + editBookmarkBinding.positiveButton.text = text + editBookmarkBinding.positiveButton.setOnClickListener { + func.invoke(editBookmarkBinding) + if (autoDismiss) { + dialog.dismiss() + } + } + return this + } + + fun setPositiveButton( + textRes: Int, + func: (EditBookmarkBinding) -> Unit + ): BookmarkDialog { + editBookmarkBinding.positiveButton.setText(textRes) + editBookmarkBinding.positiveButton.setOnClickListener { + func.invoke(editBookmarkBinding) + if (autoDismiss) { + dialog.dismiss() + } + } + return this + } + + + override fun setNegativeButton(text: String, func: () -> Unit): BookmarkDialog { + editBookmarkBinding.negativeButton.text = text + editBookmarkBinding.negativeButton.setOnClickListener { + func.invoke() + if (autoDismiss) { + dialog.dismiss() + } + } + return this + } + + override fun setNegativeButton(textRes: Int, func: () -> Unit): BookmarkDialog { + editBookmarkBinding.negativeButton.setText(textRes) + editBookmarkBinding.negativeButton.setOnClickListener { + func.invoke() + if (autoDismiss) { + dialog.dismiss() + } + } + return this + } +} \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt index 6790fe0..75cae96 100644 --- a/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt +++ b/app/src/main/java/com/coldmint/rust/pro/fragments/ModFragment.kt @@ -299,7 +299,7 @@ class ModFragment : BaseFragment() { } } else { - works.add(getString(R.string.mod_action9)) + works.add(getString(R.string.rename)) works.add(getString(R.string.mod_action8)) } works.add(getString(R.string.share_mod)) diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt index c93180f..9fa38b1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt @@ -1,7 +1,11 @@ package com.coldmint.rust.pro.viewmodel import android.content.Context +import android.content.Intent +import android.net.Uri +import android.os.Build import android.os.Environment +import android.provider.MediaStore import android.util.Log import androidx.lifecycle.MutableLiveData import androidx.lifecycle.viewModelScope @@ -10,8 +14,11 @@ import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.pro.R import com.coldmint.rust.pro.base.BaseViewModel import com.coldmint.rust.pro.tool.AppSettings +import com.coldmint.rust.pro.tool.BookmarkManager +import com.yalantis.ucrop.util.FileUtils.getPath import kotlinx.coroutines.launch import java.io.File +import java.util.HashMap class FileManagerViewModel : BaseViewModel() { @@ -23,6 +30,31 @@ class FileManagerViewModel : BaseViewModel() { DEFAULT, SELECT_DIRECTORY, EXPORT_FILE, SELECT_FILE } + private lateinit var bookmarkManager: BookmarkManager + + /** + * 初始化书签管理器 + * @param context Context + * @return Boolean 返回是否初始化成功 + */ + fun initBookmarkManager(context: Context): Boolean { + return if (!this::bookmarkManager.isInitialized) { + bookmarkManager = BookmarkManager(context) + bookmarkManager.load() + } else { + false + } + } + + + /** + * 获取书签管理器 + * @return BookmarkManager + */ + fun getBookmarkManager(): BookmarkManager { + return bookmarkManager + } + /** * 文件排序方式 */ @@ -83,7 +115,7 @@ class FileManagerViewModel : BaseViewModel() { * @param context Context * @return Boolean */ - fun saveSortType(context: Context):Boolean { + fun saveSortType(context: Context): Boolean { val appSettings = AppSettings.getInstance(context) val value = sortTypeLiveData.value ?: SortType.BY_NAME @@ -104,7 +136,7 @@ class FileManagerViewModel : BaseViewModel() { context.getString(R.string.setting_file_list_action_sort_by_name) } } - return appSettings.setValue(AppSettings.Setting.FileSortType,text) + return appSettings.setValue(AppSettings.Setting.FileSortType, text) } /** @@ -140,6 +172,63 @@ class FileManagerViewModel : BaseViewModel() { rootPath = path ?: directs } + /** + * 获取Root目录 + * @return String + */ + fun getRootPath(): String { + return rootPath + } + + // /** +// * 解析文件路径 +// * +// * @param context 上下文环境 +// * @param intent 意图 +// * @return 成功返回文件路径,失败返回null +// */ + fun parseFilePath(context: Context, intent: Intent?): String? { + return try { + if (intent != null) { + val uri = intent.data + var chooseFilePath: String? = null + if ("file".equals(uri!!.scheme, ignoreCase = true)) { //使用第三方应用打开 + chooseFilePath = uri.path + return chooseFilePath + } + chooseFilePath = if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) { //4.4以后 + getPath(context, uri) + } else { //4.4以下下系统调用方法 + getRealPathFromURI(context, uri) + } + return chooseFilePath + } + null + } catch (e: Exception) { + e.printStackTrace() + null + } + } + + /** + * 获取uri的绝对路径 + * + * @param context 上下文环境 + * @param contentUri uri + * @return 文件路径 + */ + private fun getRealPathFromURI(context: Context, contentUri: Uri?): String? { + var res: String? = null + val proj = arrayOf(MediaStore.Images.Media.DATA) + val cursor = context.contentResolver.query(contentUri!!, proj, null, null, null) + if (null != cursor && cursor.moveToFirst()) { + val column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA) + res = cursor.getString(column_index) + cursor.close() + } + return res + } + /** * 加载文件列表 * @param path String 默认加载根目录 diff --git a/app/src/main/res/drawable/ic_outline_bookmarks_24.xml b/app/src/main/res/drawable/ic_outline_bookmarks_24.xml new file mode 100644 index 0000000..24082d9 --- /dev/null +++ b/app/src/main/res/drawable/ic_outline_bookmarks_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/popupmenu_background.xml b/app/src/main/res/drawable/popupmenu_background.xml new file mode 100644 index 0000000..a8b409b --- /dev/null +++ b/app/src/main/res/drawable/popupmenu_background.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml index 34c7b74..9c1d3f4 100644 --- a/app/src/main/res/layout/activity_about.xml +++ b/app/src/main/res/layout/activity_about.xml @@ -31,7 +31,7 @@ diff --git a/app/src/main/res/layout/activity_activate.xml b/app/src/main/res/layout/activity_activate.xml index 1a2c1d2..b8582e7 100644 --- a/app/src/main/res/layout/activity_activate.xml +++ b/app/src/main/res/layout/activity_activate.xml @@ -44,7 +44,7 @@ + android:layout_marginTop="16dp"> - + android:layout_height="wrap_content"> + android:text="@string/messages_header" /> @@ -114,59 +115,58 @@ - + - + android:layout_marginTop="16dp"> + android:text="@string/background_music" /> - + android:text="@string/enabled" /> - + android:text="@string/add" /> - + - + android:layout_marginTop="16dp"> + android:text="@string/map" /> - + android:text="@string/enabled" /> - + android:text="@string/add" /> @@ -288,7 +287,7 @@ - + diff --git a/app/src/main/res/layout/activity_error.xml b/app/src/main/res/layout/activity_error.xml index 9b0f8a7..88ef135 100644 --- a/app/src/main/res/layout/activity_error.xml +++ b/app/src/main/res/layout/activity_error.xml @@ -77,7 +77,7 @@ + + @@ -31,11 +38,18 @@ android:layout_width="match_parent" android:layout_height="wrap_content"> - + android:orientation="vertical"> + + + + + @@ -61,9 +75,11 @@ + + diff --git a/app/src/main/res/layout/activity_global_operations.xml b/app/src/main/res/layout/activity_global_operations.xml index 59f5e87..90570d9 100644 --- a/app/src/main/res/layout/activity_global_operations.xml +++ b/app/src/main/res/layout/activity_global_operations.xml @@ -21,7 +21,6 @@ - - + android:layout_height="wrap_content"> + android:text="@string/rule" /> - + - + android:layout_marginTop="16dp" + android:visibility="gone"> + android:text="@string/operation" /> - + - + android:layout_marginTop="16dp" + android:visibility="gone"> + android:text="@string/affect_list" /> - + diff --git a/app/src/main/res/layout/activity_pack.xml b/app/src/main/res/layout/activity_pack.xml index a98489a..fb8bfcb 100644 --- a/app/src/main/res/layout/activity_pack.xml +++ b/app/src/main/res/layout/activity_pack.xml @@ -21,7 +21,6 @@ - - + android:layout_marginTop="8dp"> + android:text="@string/additional_selection" /> - + - + android:layout_marginTop="16dp"> + android:text="@string/configuration" /> - + - + android:layout_marginTop="16dp" + android:layout_marginBottom="16dp"> + android:text="@string/about" /> - + -