编辑框升级前同步

This commit is contained in:
coldmint 2022-08-10 17:27:38 +08:00
parent 2414f36fe7
commit f2da30d523
88 changed files with 1314 additions and 561 deletions

Binary file not shown.

View File

@ -95,6 +95,7 @@ dependencies {
implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9' implementation 'com.kongzue.stacklabel:stacklabelview:1.1.9'
implementation files('libs/editor_0.8.aar') implementation files('libs/editor_0.8.aar')
implementation project(path: ':assistantCoreLibrary') implementation project(path: ':assistantCoreLibrary')
implementation project(path: ':turretsDragView')
implementation project(path: ':dialog') implementation project(path: ':dialog')
implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0' implementation 'com.afollestad.material-dialogs:bottomsheets:3.3.0'
implementation 'com.afollestad.material-dialogs:input:3.3.0' implementation 'com.afollestad.material-dialogs:input:3.3.0'

View File

@ -13,11 +13,13 @@ import android.view.MenuItem
import android.view.View import android.view.View
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.view.isVisible import androidx.core.view.isVisible
import com.coldmint.dialog.CoreDialog
import com.coldmint.rust.pro.adapters.BookmarkAdapter import com.coldmint.rust.pro.adapters.BookmarkAdapter
import com.coldmint.rust.pro.base.BaseActivity import com.coldmint.rust.pro.base.BaseActivity
import com.coldmint.rust.pro.databean.Bookmark import com.coldmint.rust.pro.databean.Bookmark
import com.coldmint.rust.pro.databinding.ActivityBookmarkManagerBinding import com.coldmint.rust.pro.databinding.ActivityBookmarkManagerBinding
import com.coldmint.rust.pro.databinding.EditBookmarkBinding import com.coldmint.rust.pro.databinding.EditBookmarkBinding
import com.coldmint.rust.pro.dialog.BookmarkDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File import java.io.File
@ -26,8 +28,26 @@ import java.util.ArrayList
class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() { class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
private lateinit var bookmarkManager: BookmarkManager private lateinit var bookmarkManager: BookmarkManager
lateinit var bookmarkAdapter: BookmarkAdapter lateinit var bookmarkAdapter: BookmarkAdapter
private lateinit var pathView: EditText lateinit var bookmarkDialog :BookmarkDialog
private lateinit var nameView: EditText
/**
* 重新构建对话框实例化一个对话框并使成员变量指向他
*/
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<ActivityBookmarkManagerBinding>() {
attachFileItemBinding.root.setOnLongClickListener { attachFileItemBinding.root.setOnLongClickListener {
bookmarkAdapter.showDeleteItemDialog( bookmarkAdapter.showDeleteItemDialog(
bookmark.name, bookmark.name,
viewHolder.adapterPosition, onClickPositiveButton = { i:Int, b -> viewHolder.absoluteAdapterPosition,
onClickPositiveButton = { i: Int, b ->
bookmarkManager.removeBookmark(bookmark) bookmarkManager.removeBookmark(bookmark)
if (list.isEmpty()) { if (list.isEmpty()) {
showNoBookmarkToView() showNoBookmarkToView()
@ -88,50 +109,39 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
* @param path 路径 * @param path 路径
*/ */
fun showEditView(title: String, name: String?, path: String?) { fun showEditView(title: String, name: String?, path: String?) {
val editBookmarkBinding = EditBookmarkBinding.inflate(layoutInflater) recreateBookmarkDialog()
nameView = editBookmarkBinding.nameView
pathView = editBookmarkBinding.pathEdit
if (path != null) { if (path != null) {
editBookmarkBinding.pathEdit.setText(path) bookmarkDialog.setPathViewText(path)
} }
if (name != null) { if (name != null) {
editBookmarkBinding.nameView.setText(name) bookmarkDialog.setNameViewText(name)
} }
bookmarkDialog.setTitle(title).setAutoDismiss(false).setCancelable(false)
editBookmarkBinding.button.setOnClickListener { bookmarkDialog.setPositiveButton(R.string.dialog_ok) { editBookmarkBinding ->
val bundle = Bundle() val newPath = editBookmarkBinding.pathEdit.text.toString()
val intent = val newName = editBookmarkBinding.nameView.text.toString()
Intent(this@BookmarkManagerActivity, FileManagerActivity::class.java)
bundle.putString("type", "selectDirectents")
val thisPath = pathView.text.toString()
if (thisPath.isNotEmpty()) {
bundle.putString("path", thisPath)
}
//bundle.putString("rootpath", mRootPath);
intent.putExtra("data", bundle)
startActivityForResult(intent, 1)
}
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()) { if (newName.isEmpty()) {
setErrorAndInput(nameView, getString(R.string.enter_bookmark_name)) setErrorAndInput(
editBookmarkBinding.nameView,
getString(R.string.enter_bookmark_name), editBookmarkBinding.nameInputLayout
)
return@setPositiveButton return@setPositiveButton
} }
if (newPath.isEmpty()) { if (newPath.isEmpty()) {
setErrorAndInput(pathView, getString(R.string.enter_file_path)) setErrorAndInput(
editBookmarkBinding.pathEdit,
getString(R.string.enter_file_path),
editBookmarkBinding.pathInputLayout
)
return@setPositiveButton return@setPositiveButton
} }
val file = File(newPath) val file = File(newPath)
if (!file.exists()) { if (!file.exists()) {
setErrorAndInput(pathView, getString(R.string.bookmark_jump_failed)) setErrorAndInput(
editBookmarkBinding.pathEdit,
getString(R.string.bookmark_jump_failed),
editBookmarkBinding.pathInputLayout
)
return@setPositiveButton return@setPositiveButton
} }
if (name == null) { if (name == null) {
@ -141,13 +151,14 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
} else { } else {
setErrorAndInput( setErrorAndInput(
pathView, editBookmarkBinding.pathEdit,
getString(R.string.bookmark_already_exists) getString(R.string.bookmark_already_exists),
editBookmarkBinding.pathInputLayout
) )
} }
} else { } else {
if (name == newName && path == newPath) { if (name == newName && path == newPath) {
dialog?.dismiss() bookmarkDialog.dismiss()
} else { } else {
if (path != null) { if (path != null) {
val oldBookmark = Bookmark(path, name) val oldBookmark = Bookmark(path, name)
@ -156,22 +167,22 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
bookmarkManager.replaceBookmark(oldBookmark, newBookmark) bookmarkManager.replaceBookmark(oldBookmark, newBookmark)
if (addBookmark) { if (addBookmark) {
updateView(bookmarkManager.list()) updateView(bookmarkManager.list())
dialog?.dismiss() bookmarkDialog.dismiss()
} else { } else {
setErrorAndInput( setErrorAndInput(
pathView, editBookmarkBinding.pathEdit,
getString(R.string.bookmark_already_exists) getString(R.string.bookmark_already_exists),
editBookmarkBinding.pathInputLayout
) )
} }
} }
} }
} }
} }
.setNegativeButton(R.string.dialog_close) { i, i2 -> bookmarkDialog.setNegativeButton(R.string.dialog_close) {
dialog?.dismiss() bookmarkDialog.dismiss()
} }
.setCancelable(false) bookmarkDialog.show()
dialog = materialAlertDialogBuilder.show()
} }
@ -180,15 +191,15 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
when (requestCode) { when (requestCode) {
1 -> if (resultCode == RESULT_OK) { 1 -> if (resultCode == RESULT_OK) {
val path = data!!.getStringExtra("Directents") val path = data!!.getStringExtra("Directents")
pathView.setText(path) bookmarkDialog.setPathViewText(path)
val oldName = nameView.text.toString() val oldName = bookmarkDialog.getName()
if (oldName.isEmpty()) { if (oldName.isEmpty()) {
val endIndex = path!!.lastIndexOf("/") val endIndex = path!!.lastIndexOf("/")
if (endIndex > -1) { if (endIndex > -1) {
val name = path.substring(endIndex + 1, path.length) val name = path.substring(endIndex + 1, path.length)
nameView.setText(name) bookmarkDialog.setNameViewText(name)
} else { } else {
nameView.setText(path) bookmarkDialog.setNameViewText(path)
} }
} }
} }
@ -238,6 +249,7 @@ class BookmarkManagerActivity : BaseActivity<ActivityBookmarkManagerBinding>() {
null null
) )
} }
} }
} }
} }

View File

@ -456,10 +456,10 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
if (need) { if (need) {
viewModel.saveAllFile( viewModel.saveAllFile(
viewBinding.tabLayout.selectedTabPosition, viewBinding.tabLayout.selectedTabPosition,
viewBinding.codeEditor.text.toString(), { viewBinding.codeEditor.text.toString()
) {
Toast.makeText(this, R.string.auto_save_toast, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.auto_save_toast, Toast.LENGTH_SHORT).show()
} }
)
} }
} }
super.onPause() super.onPause()
@ -692,13 +692,13 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
val popupMenu = PopupMenu(this@EditActivity, it) val popupMenu = PopupMenu(this@EditActivity, it)
val cutBoardMenu = popupMenu.menu.addSubMenu(R.string.cut_board_operation) val cutBoardMenu = popupMenu.menu.addSubMenu(R.string.cut_board_operation)
val fileMenu = popupMenu.menu.addSubMenu(R.string.file_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_name)
cutBoardMenu.add(R.string.copy_file_path) cutBoardMenu.add(R.string.copy_file_path)
cutBoardMenu.add(R.string.copy_file_absolutely_path) cutBoardMenu.add(R.string.copy_file_absolutely_path)
fileMenu.add(R.string.copy) fileMenu.add(R.string.copy)
fileMenu.add(R.string.cut_off) fileMenu.add(R.string.cut_off)
fileMenu.add(R.string.mod_action9) fileMenu.add(R.string.rename)
fileMenu.add(R.string.del_mod) fileMenu.add(R.string.del_mod)
val bookmarkManager = editStartViewModel.bookmarkManager val bookmarkManager = editStartViewModel.bookmarkManager
if (bookmarkManager.contains(file)) { if (bookmarkManager.contains(file)) {
@ -814,7 +814,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
return@OnMenuItemClickListener false return@OnMenuItemClickListener false
} }
fileAdapter?.setSelectPath(file.absolutePath, 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 val absolutePath = file.absolutePath
var canRename = true var canRename = true
if (viewModel.openedSourceFileListLiveData.value.isNotEmpty()) { if (viewModel.openedSourceFileListLiveData.value.isNotEmpty()) {
@ -835,7 +835,7 @@ class EditActivity : BaseActivity<ActivityEditBinding>() {
} }
val oldName = file.name val oldName = file.name
MaterialDialog(this@EditActivity).show { MaterialDialog(this@EditActivity).show {
title(R.string.mod_action9) title(R.string.rename)
input( input(
maxLength = 255, maxLength = 255,
waitForPositiveButton = false, prefill = oldName waitForPositiveButton = false, prefill = oldName

View File

@ -75,7 +75,7 @@ class EditModInfoActivity : BaseActivity<ActivityEditModInfoBinding>() {
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
viewBinding.toolbar.title = getText(R.string.mod_action2) title = getText(R.string.mod_action2)
setReturnButton() setReturnButton()
val intent = intent val intent = intent
val bundle = intent.getBundleExtra("data") val bundle = intent.getBundleExtra("data")

View File

@ -23,13 +23,20 @@ import com.afollestad.materialdialogs.actions.setActionButtonEnabled
import com.afollestad.materialdialogs.input.getInputField import com.afollestad.materialdialogs.input.getInputField
import com.afollestad.materialdialogs.input.input import com.afollestad.materialdialogs.input.input
import com.afollestad.materialdialogs.list.listItems 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.FileOperator
import com.coldmint.rust.core.tool.LineParser
import com.coldmint.rust.pro.adapters.FileAdapter 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.databinding.ActivityFileBinding
import com.coldmint.rust.pro.interfaces.BookmarkListener import com.coldmint.rust.pro.interfaces.BookmarkListener
import com.coldmint.rust.pro.tool.AppSettings import com.coldmint.rust.pro.tool.AppSettings
import com.coldmint.rust.pro.viewmodel.FileManagerViewModel 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.dialog.MaterialAlertDialogBuilder
import com.google.android.material.snackbar.SnackbarContentLayout
import me.zhanghai.android.fastscroll.FastScrollerBuilder import me.zhanghai.android.fastscroll.FastScrollerBuilder
import java.io.File import java.io.File
import java.lang.Exception import java.lang.Exception
@ -42,15 +49,13 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// private var mRoot = directs // private var mRoot = directs
// var filePath = "" // var filePath = ""
// //
// //哈希表映射(名称,路径)
// val bookmarkMap = HashMap<String, String>()
// val executorService = Executors.newSingleThreadExecutor() // val executorService = Executors.newSingleThreadExecutor()
// //
// //type可为默认default选择文件夹selectDirectents选择文件selectFile // //type可为默认default选择文件夹selectDirectents选择文件selectFile
// var mStartType: String? = "default" // var mStartType: String? = "default"
// private var mFileAdapter: FileAdapter? = null // private var mFileAdapter: FileAdapter? = null
// private var mProcessFiles = false // private var mProcessFiles = false
// private val bookmarkManager: BookmarkManager by lazy { BookmarkManager(this) }
// private var additionalData: String? = null // private var additionalData: String? = null
// private fun initView() { // private fun initView() {
// title = getString(R.string.file_manager) // title = getString(R.string.file_manager)
@ -409,25 +414,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// } // }
// //
// //
// /**
// * 添加书签菜单
// */
// 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)
// }
//
// })
// }
//
// /** // /**
// * 点击书签项目 // * 点击书签项目
// */ // */
@ -435,14 +422,14 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// if (bookmarkMap.containsKey(menuTitle)) { // if (bookmarkMap.containsKey(menuTitle)) {
// val path = bookmarkMap[menuTitle] // val path = bookmarkMap[menuTitle]
// if (path != null) { // if (path != null) {
// val rootPath = mRoot.absolutePath // val rootPath = viewModel.getRootPath()
// if (path.startsWith(rootPath)) { // if (path.startsWith(rootPath)) {
// val newFile = File(path) // val newFile = File(path)
// if (newFile.exists()) { // if (newFile.exists()) {
// if (newFile.isDirectory) { // if (newFile.isDirectory) {
// loadFiles(newFile) // viewModel.loadFiles(newFile.absolutePath)
// } else { // } else {
// tryOpenFile(newFile) //// tryOpenFile(newFile)
// } // }
// } else { // } else {
// Snackbar.make( // Snackbar.make(
@ -465,71 +452,45 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// //
// //
// override fun onPause() { // override fun onPause() {
// bookmarkManager.save() // viewModel.getBookmarkManager().save()
// super.onPause() // super.onPause()
// } // }
//
// override fun onResume() { override fun onResume() {
// bookmarkManager.load() viewModel.getBookmarkManager().load()
// super.onResume() 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?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
// super.onActivityResult(requestCode, resultCode, data) super.onActivityResult(requestCode, resultCode, data)
// if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
// if (mStartType == "selectFile" && requestCode == 1) { if (viewModel.startTypeData == FileManagerViewModel.StartType.SELECT_FILE && requestCode == 1) {
// val path = FileOperator.parsePicturePath(this@FileManagerActivity, data) val path = FileOperator.parsePicturePath(this@FileManagerActivity, data)
// if (path != null) { if (path != null) {
// val intent = Intent() val intent = Intent()
// intent.putExtra("File", path) intent.putExtra("File", path)
// setResult(RESULT_OK, intent) setResult(RESULT_OK, intent)
// bookmarkManager.save() // bookmarkManager.save()
// finish() finish()
// } }
// } else if (mStartType == "selectFile" && requestCode == 2) { } else if (viewModel.startTypeData == FileManagerViewModel.StartType.SELECT_FILE && requestCode == 2) {
// val path = parseFilePath(this@FileManagerActivity, data) val path = viewModel.parseFilePath(this@FileManagerActivity, data)
// if (path != null) { if (path != null) {
// val intent = Intent() val intent = Intent()
// intent.putExtra("File", path) intent.putExtra("File", path)
// setResult(RESULT_OK, intent) setResult(RESULT_OK, intent)
// bookmarkManager.save() // bookmarkManager.save()
// finish() finish()
// } }
// } else if (requestCode == 3) { } else {
// //新建源文件 Toast.makeText(this, "未设置的操作", Toast.LENGTH_SHORT).show()
}
// else if (requestCode == 3) {
//新建源文件
// loadFiles(directs) // loadFiles(directs)
// } else if (requestCode == 4) { // } else if (requestCode == 4) {
// val file = File(data!!.getStringExtra("File")) // val file = File(data!!.getStringExtra("File"))
@ -545,58 +506,60 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// loadFiles(directs) // loadFiles(directs)
// } // }
// } // }
// } }
// } }
// //
// override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
// val id = item.itemId val id = item.itemId
// when (id) { when (id) {
// android.R.id.home -> { android.R.id.home -> {
// bookmarkManager.save() // bookmarkManager.save()
// finish() finish()
// return true return true
// } }
// R.id.reloadFile -> { R.id.reloadFile -> {
// loadFiles(directs) viewModel.loadFiles(viewModel.getCurrentPath())
// return true return true
// } }
// R.id.photo_album -> { R.id.photo_album -> {
// this@FileManagerActivity.startActivityForResult( this@FileManagerActivity.startActivityForResult(
// Intent( Intent(
// Intent.ACTION_PICK, Intent.ACTION_PICK,
// MediaStore.Images.Media.EXTERNAL_CONTENT_URI MediaStore.Images.Media.EXTERNAL_CONTENT_URI
// ), 1 ), 1
// ) )
// return true return true
// } }
// R.id.system_file_manager -> { R.id.system_file_manager -> {
// val intent = Intent(Intent.ACTION_GET_CONTENT) val intent = Intent(Intent.ACTION_GET_CONTENT)
// intent.type = "*/*" intent.type = "*/*"
// intent.addCategory(Intent.CATEGORY_OPENABLE) intent.addCategory(Intent.CATEGORY_OPENABLE)
// this@FileManagerActivity.startActivityForResult(intent, 2) this@FileManagerActivity.startActivityForResult(intent, 2)
// return true return true
// } }
// R.id.creteFolder -> { R.id.creteFolder -> {
// createFolderAction() // createFolderAction()
// return true return true
// } }
// } }
// loadBook(item.title) // loadBook(item.title)
// return super.onOptionsItemSelected(item) return super.onOptionsItemSelected(item)
// } }
//
// override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
// return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) { return if (keyCode == KeyEvent.KEYCODE_BACK && event.action == KeyEvent.ACTION_DOWN) {
// if (directs.absolutePath == mRoot.absolutePath) { if (viewModel.getCurrentPath() == viewModel.getRootPath()) {
// bookmarkManager.save() // bookmarkManager.save()
// finish() finish()
// true true
// } else { } else {
// returnDirects() viewModel.returnDirects()
// false false
// } }
// } else super.onKeyDown(keyCode, event) } else super.onKeyDown(keyCode, event)
// } }
// //
// override fun onCreateOptionsMenu(menu: Menu): Boolean { // override fun onCreateOptionsMenu(menu: Menu): Boolean {
// val inflater = menuInflater // val inflater = menuInflater
@ -615,10 +578,11 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// loadFiles(file) // loadFiles(file)
// } // }
// //
// fun initAction() { fun initAction() {
// viewBinding.fab.setOnClickListener { viewBinding.fab.setOnClickListener {
// val intent = Intent() val intent = Intent()
// when (mStartType) { val startType = viewModel.startTypeData
when (startType) {
// "exportFile" -> { // "exportFile" -> {
// val oldFile = File(additionalData) // val oldFile = File(additionalData)
// val result = FileOperator.copyFile( // val result = FileOperator.copyFile(
@ -642,8 +606,11 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// bookmarkManager.save() // bookmarkManager.save()
// finish() // finish()
// } // }
// "default" -> { FileManagerViewModel.StartType.SELECT_FILE -> {
// val popupMenu = PopupMenu(this@FileManagerActivity, viewBinding.fab)
}
FileManagerViewModel.StartType.DEFAULT -> {
val popupMenu = PopupMenu(this@FileManagerActivity, viewBinding.fab)
// if (mFileAdapter != null) { // if (mFileAdapter != null) {
// val selectPath = mFileAdapter!!.selectPath // val selectPath = mFileAdapter!!.selectPath
// if (selectPath != null && mProcessFiles == false) { // if (selectPath != null && mProcessFiles == false) {
@ -654,37 +621,37 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// } // }
// } // }
// } // }
// popupMenu.menu.add(R.string.create_unit) popupMenu.menu.add(R.string.create_unit)
// popupMenu.menu.add(R.string.create_folder) popupMenu.menu.add(R.string.create_folder)
// popupMenu.menu.add(R.string.select_file) popupMenu.menu.add(R.string.select_file)
// popupMenu.setOnMenuItemClickListener { item -> popupMenu.setOnMenuItemClickListener { item ->
// val title = item.title val title = item.title
// val handler = Handler(Looper.getMainLooper()) // val handler = Handler(Looper.getMainLooper())
// when (title) { when (title) {
// getText(R.string.create_unit) -> { getText(R.string.create_unit) -> {
// val intent = val intent =
// Intent(this@FileManagerActivity, CreateUnitActivity::class.java) Intent(this@FileManagerActivity, CreateUnitActivity::class.java)
// val bundle = Bundle() val bundle = Bundle()
// bundle.putString("modPath", directs.absolutePath) bundle.putString("modPath", viewModel.getCurrentPath())
// bundle.putString("createPath", directs.absolutePath) bundle.putString("createPath", viewModel.getCurrentPath())
// intent.putExtra("data", bundle) intent.putExtra("data", bundle)
// startActivityForResult(intent, 3) startActivityForResult(intent, 3)
// } }
// getText(R.string.select_file) -> { getText(R.string.select_file) -> {
// val bundle = Bundle() val bundle = Bundle()
// val intent = val intent =
// Intent( Intent(
// this@FileManagerActivity, this@FileManagerActivity,
// FileManagerActivity::class.java FileManagerActivity::class.java
// ) )
// bundle.putString("type", "selectFile") bundle.putString("type", "selectFile")
// //bundle.putString("path", modClass.getModFile().getAbsolutePath()); //bundle.putString("path", modClass.getModFile().getAbsolutePath());
// intent.putExtra("data", bundle) intent.putExtra("data", bundle)
// startActivityForResult(intent, 4) startActivityForResult(intent, 4)
// } }
// getText(R.string.create_folder) -> { getText(R.string.create_folder) -> {
// createFolderAction() createFolderAction()
// } }
// getText(R.string.copy_to_this) -> { // getText(R.string.copy_to_this) -> {
// Thread { // Thread {
// mProcessFiles = true // mProcessFiles = true
@ -731,14 +698,17 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// } // }
// }.start() // }.start()
// } // }
// } }
// false false
// } }
// popupMenu.show() popupMenu.show()
// } }
// } else -> {
// }
// } }
}
}
}
// //
// /** // /**
// * 创建文件夹活动 // * 创建文件夹活动
@ -771,24 +741,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// } // }
// //
// //
// /**
// * 获取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? { // private fun getPath(context: Context, uri: Uri?): String? {
// val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT // val isKitKat = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
@ -885,20 +838,50 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
ViewModelProvider(this).get(FileManagerViewModel::class.java) 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 private var adapter: FileAdapter? = null
override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) { override fun whenCreateActivity(savedInstanceState: Bundle?, canUseView: Boolean) {
if (canUseView) { if (canUseView) {
setReturnButton() setReturnButton()
viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity) viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity)
val linearLayoutManager = LinearLayoutManager(this)
linearLayoutManager.orientation = LinearLayoutManager.HORIZONTAL
viewBinding.fileTabNav.layoutManager = linearLayoutManager
loadTitle() loadTitle()
loadObserve() loadObserve()
initAction()
FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() FastScrollerBuilder(viewBinding.recyclerView).useMd2Style()
.setPopupTextProvider(adapter).build() .setPopupTextProvider(adapter).build()
viewBinding.swipeRefreshLayout.setOnRefreshListener { viewBinding.swipeRefreshLayout.setOnRefreshListener {
viewModel.loadFiles(viewModel.getCurrentPath()) viewModel.loadFiles(viewModel.getCurrentPath())
viewBinding.swipeRefreshLayout.isRefreshing = false viewBinding.swipeRefreshLayout.isRefreshing = false
} }
viewModel.initBookmarkManager(this)
viewModel.loadFiles() viewModel.loadFiles()
viewModel.loadSortType(this) viewModel.loadSortType(this)
} else { } else {
@ -911,6 +894,17 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
if (bundle.containsKey("path")) { if (bundle.containsKey("path")) {
viewModel.currentPathLiveData.value = bundle.getString("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")) { if (bundle.containsKey("rootpath")) {
viewModel.setRootPath(bundle.getString("rootpath")) viewModel.setRootPath(bundle.getString("rootpath"))
} }
@ -923,6 +917,9 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
if (value != null) { if (value != null) {
setSortType(value) setSortType(value)
} }
if (viewModel.startTypeData != FileManagerViewModel.StartType.SELECT_FILE) {
menu.removeItem(R.id.selectFile)
}
menuBinding.actionSortByType.setOnMenuItemClickListener { menuBinding.actionSortByType.setOnMenuItemClickListener {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_TYPE viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_TYPE
true true
@ -939,16 +936,41 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_LAST_MODIFIED viewModel.sortTypeLiveData.value = FileManagerViewModel.SortType.BY_LAST_MODIFIED
true true
} }
loadMineBookmarksMenu()
menuBinding.bookmarkManagerItem.setOnMenuItemClickListener {
val intent = Intent(this, BookmarkManagerActivity::class.java)
startActivity(intent)
true
}
return 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() { fun loadObserve() {
viewModel.loadStateLiveData.observe(this) { viewModel.loadStateLiveData.observe(this) {
viewBinding.recyclerView.isVisible = !it viewBinding.fileTabNav.isVisible = !it
viewBinding.swipeRefreshLayout.isVisible = !it viewBinding.swipeRefreshLayout.isVisible = !it
viewBinding.fileError.isVisible = it viewBinding.fileError.isVisible = it
viewBinding.progressBar.isVisible = it viewBinding.progressBar.isVisible = it
@ -967,13 +989,106 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
} else { } else {
if (file.isDirectory) { if (file.isDirectory) {
viewModel.currentPathLiveData.value = file.absolutePath viewModel.currentPathLiveData.value = file.absolutePath
} else { }
}
}
fileItemBinding.more.setOnClickListener { fileItemBinding.more.setOnClickListener {
if (file == null) {
return@setOnClickListener
}
val finalFile = file
val popupMenu = PopupMenu(this, fileItemBinding.more) val popupMenu = PopupMenu(this, fileItemBinding.more)
popupMenu.inflate(R.menu.menu_files) 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.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<ActivityFileBinding>() {
} }
} }
viewModel.currentPathLiveData.observe(this) { 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<FileTab>()
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) viewModel.loadFiles(it)
} }
} }
@ -1042,7 +1184,10 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
val systemFileManagerItem: MenuItem, val systemFileManagerItem: MenuItem,
val actionSortByName: MenuItem, val actionSortByName: MenuItem,
val actionSortByType: 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 { companion object {
//填充 //填充
@ -1056,7 +1201,10 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
menu.findItem(R.id.action_sort_by_name), menu.findItem(R.id.action_sort_by_name),
menu.findItem(R.id.action_sort_by_type), menu.findItem(R.id.action_sort_by_type),
menu.findItem(R.id.action_sort_by_size), 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)
) )
} }
} }

View File

@ -39,7 +39,7 @@ import kotlin.concurrent.thread
* @constructor * @constructor
*/ */
class ApplicationListAdapter( class ApplicationListAdapter(
val context: Context, dataList: MutableList<PackageInfo> context: Context, dataList: MutableList<PackageInfo>
) : BaseAdapter<ApplicationItemBinding, PackageInfo>(context, dataList) { ) : BaseAdapter<ApplicationItemBinding, PackageInfo>(context, dataList) {
val handler: Handler by lazy { val handler: Handler by lazy {

View File

@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.AttachFileItemBinding
import java.io.File import java.io.File
import java.util.ArrayList import java.util.ArrayList
class AttachFileAdapter(val context: Context, dataList: MutableList<File>) : class AttachFileAdapter( context: Context, dataList: MutableList<File>) :
BaseAdapter<AttachFileItemBinding, File>(context, dataList) { BaseAdapter<AttachFileItemBinding, File>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,

View File

@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2022/1/10 8:49 * @date 2022/1/10 8:49
*/ */
class AuditModAdapter(val context: Context, dataList: MutableList<WebModListData.Data>) : class AuditModAdapter( context: Context, dataList: MutableList<WebModListData.Data>) :
BaseAdapter<ItemAuditModBinding, WebModListData.Data>(context, dataList) { BaseAdapter<ItemAuditModBinding, WebModListData.Data>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,

View File

@ -7,7 +7,7 @@ import com.coldmint.rust.pro.base.BaseAdapter
import com.coldmint.rust.pro.databean.Bookmark import com.coldmint.rust.pro.databean.Bookmark
import com.coldmint.rust.pro.databinding.AttachFileItemBinding import com.coldmint.rust.pro.databinding.AttachFileItemBinding
class BookmarkAdapter(val context: Context, dataList: MutableList<Bookmark>) : class BookmarkAdapter( context: Context, dataList: MutableList<Bookmark>) :
BaseAdapter<AttachFileItemBinding, Bookmark>(context, dataList) { BaseAdapter<AttachFileItemBinding, Bookmark>(context, dataList) {
/** /**

View File

@ -18,7 +18,7 @@ import com.coldmint.rust.pro.tool.TextStyleMaker
* @author Cold Mint * @author Cold Mint
* @date 2021/12/12 20:50 * @date 2021/12/12 20:50
*/ */
class CommentAdapter(val context: Context, dataList: MutableList<WebModCommentData.Data>) : class CommentAdapter(context: Context, dataList: MutableList<WebModCommentData.Data>) :
BaseAdapter<ItemCommentBinding, WebModCommentData.Data>(context, dataList) { BaseAdapter<ItemCommentBinding, WebModCommentData.Data>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
@ -37,7 +37,8 @@ class CommentAdapter(val context: Context, dataList: MutableList<WebModCommentD
) { ) {
val icon = data.headIcon val icon = data.headIcon
if (icon != null) { if (icon != null) {
Glide.with(context).load(ServerConfiguration.getRealLink(icon)).apply(GlobalMethod.getRequestOptions(true)) Glide.with(context).load(ServerConfiguration.getRealLink(icon))
.apply(GlobalMethod.getRequestOptions(true))
.into(viewBinding.iconView) .into(viewBinding.iconView)
} }
viewBinding.nameView.text = data.userName viewBinding.nameView.text = data.userName

View File

@ -13,7 +13,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
*社区服务适配器 *社区服务适配器
*/ */
class CommunityServiceAdapter( class CommunityServiceAdapter(
val context: Context, context: Context,
dataList: MutableList<CommunityServiceInfo> dataList: MutableList<CommunityServiceInfo>
) : ) :
BaseAdapter<ItemServiceBinding, CommunityServiceInfo>(context, dataList) { BaseAdapter<ItemServiceBinding, CommunityServiceInfo>(context, dataList) {

View File

@ -17,7 +17,7 @@ import com.coldmint.rust.pro.databinding.LogItemBinding
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
//编译日志适配器 //编译日志适配器
class CompileLogAdapter(val context: Context, analysisResults: MutableList<AnalysisResult>) : class CompileLogAdapter( context: Context, analysisResults: MutableList<AnalysisResult>) :
BaseAdapter<LogItemBinding, AnalysisResult>(context, analysisResults) { BaseAdapter<LogItemBinding, AnalysisResult>(context, analysisResults) {
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -13,7 +13,7 @@ import kotlin.math.roundToInt
* @author Cold Mint * @author Cold Mint
* @date 2022/1/10 20:47 * @date 2022/1/10 20:47
*/ */
class CouponAdapter(val context: Context, dataList: MutableList<CouponListDataBean.Data>) : class CouponAdapter( context: Context, dataList: MutableList<CouponListDataBean.Data>) :
BaseAdapter<ItemCouponBinding, CouponListDataBean.Data>(context, dataList) { BaseAdapter<ItemCouponBinding, CouponListDataBean.Data>(context, dataList) {
val timeLimit: String by lazy { val timeLimit: String by lazy {
context.getString(R.string.time_limit) context.getString(R.string.time_limit)

View File

@ -29,7 +29,7 @@ import org.w3c.dom.Text
* @author Cold Mint * @author Cold Mint
* @date 2021/12/28 18:29 * @date 2021/12/28 18:29
*/ */
class DynamicAdapter(val context: Context, dataList: MutableList<DynamicItemDataBean.Data>) : class DynamicAdapter( context: Context, dataList: MutableList<DynamicItemDataBean.Data>) :
BaseAdapter<ItemDynamicBinding, DynamicItemDataBean.Data>(context, dataList) { BaseAdapter<ItemDynamicBinding, DynamicItemDataBean.Data>(context, dataList) {

View File

@ -12,7 +12,7 @@ import com.coldmint.rust.pro.databean.ErrorInfo
import com.coldmint.rust.pro.databinding.ItemErrorInfoBinding import com.coldmint.rust.pro.databinding.ItemErrorInfoBinding
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
class ErrorInfoAdapter(val context: Context, dataList: ArrayList<ErrorInfo>) : class ErrorInfoAdapter( context: Context, dataList: ArrayList<ErrorInfo>) :
BaseAdapter<ItemErrorInfoBinding, ErrorInfo>(context, dataList) { BaseAdapter<ItemErrorInfoBinding, ErrorInfo>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,

View File

@ -24,7 +24,7 @@ import java.lang.StringBuilder
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.ArrayList import java.util.ArrayList
class FileAdapter(private val context: Context, dataList: MutableList<File?>) : class FileAdapter( context: Context, dataList: MutableList<File?>) :
BaseAdapter<FileItemBinding, File?>(context, dataList), PopupTextProvider { BaseAdapter<FileItemBinding, File?>(context, dataList), PopupTextProvider {
/** /**

View File

@ -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<FileTab>) :
BaseAdapter<ItemFileTabBinding, FileTab>(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<ItemFileTabBinding>,
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)
}
}
}

View File

@ -9,7 +9,7 @@ import com.coldmint.rust.pro.databean.FunctionInfo
import com.coldmint.rust.pro.databinding.ItemFunBinding import com.coldmint.rust.pro.databinding.ItemFunBinding
import com.coldmint.rust.pro.databinding.ItemServiceBinding import com.coldmint.rust.pro.databinding.ItemServiceBinding
class FunAdapter(val context: Context, dataList: MutableList<FunctionInfo>) : class FunAdapter( context: Context, dataList: MutableList<FunctionInfo>) :
BaseAdapter<ItemFunBinding, FunctionInfo>(context, dataList) { BaseAdapter<ItemFunBinding, FunctionInfo>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,

View File

@ -18,7 +18,7 @@ import com.coldmint.rust.pro.databinding.ItemLibBinding
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.util.ArrayList import java.util.ArrayList
class LibAdapter(val context: Context, dataList: ArrayList<LibInfo>) : class LibAdapter(context: Context, dataList: ArrayList<LibInfo>) :
BaseAdapter<ItemLibBinding, LibInfo>(context, dataList) { BaseAdapter<ItemLibBinding, LibInfo>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -13,7 +13,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2022/1/5 11:05 * @date 2022/1/5 11:05
*/ */
class MapAdapter(val context: Context, dataList: MutableList<MapClass>) : class MapAdapter(context: Context, dataList: MutableList<MapClass>) :
BaseAdapter<ItemMapBinding, MapClass>(context, dataList) { BaseAdapter<ItemMapBinding, MapClass>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,
@ -31,7 +31,8 @@ class MapAdapter(val context: Context, dataList: MutableList<MapClass>) :
) { ) {
val icon = data.getIconFile() val icon = data.getIconFile()
if (icon != null) { 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.mapUpTime.text = data.lastModificationTime
viewBinding.mapNameView.text = data.getName() viewBinding.mapNameView.text = data.getName()

View File

@ -16,7 +16,7 @@ import com.coldmint.rust.pro.databinding.MapAndMusicItemBinding
import java.io.File import java.io.File
import java.util.ArrayList import java.util.ArrayList
class MapAndMusicAdapter(val context: Context, dataList: ArrayList<File>, val isMusic: Boolean) : class MapAndMusicAdapter(context: Context, dataList: ArrayList<File>, val isMusic: Boolean) :
BaseAdapter<MapAndMusicItemBinding, File>(context, dataList) { BaseAdapter<MapAndMusicItemBinding, File>(context, dataList) {
val prefixName = "[noloop]" val prefixName = "[noloop]"
@ -36,7 +36,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList<File>, val is
popupMenu.menu.add(R.string.disabled_loop) 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.menu.add(R.string.delete_title)
popupMenu.setOnMenuItemClickListener { item -> popupMenu.setOnMenuItemClickListener { item ->
val title = item.title.toString() val title = item.title.toString()
@ -71,7 +71,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList<File>, val is
} }
} }
removeItem(position) removeItem(position)
} else if (title == context.getString(R.string.mod_action9)) { } else if (title == context.getString(R.string.rename)) {
var iconFile: File? = null var iconFile: File? = null
if (!isMusic) { if (!isMusic) {
val path = targetFile.absolutePath val path = targetFile.absolutePath
@ -84,7 +84,7 @@ class MapAndMusicAdapter(val context: Context, dataList: ArrayList<File>, val is
val oldName = fileName val oldName = fileName
val finalIconFile = iconFile val finalIconFile = iconFile
MaterialDialog(context).show { MaterialDialog(context).show {
title(R.string.mod_action9) title(R.string.rename)
input( input(
maxLength = 255, maxLength = 255,
waitForPositiveButton = false, prefill = oldName waitForPositiveButton = false, prefill = oldName

View File

@ -25,6 +25,7 @@ import android.view.View
import android.view.inputmethod.InputMethodManager import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContentProviderCompat.requireContext import androidx.core.content.ContentProviderCompat.requireContext
import com.coldmint.dialog.InputDialog
import com.coldmint.rust.core.* import com.coldmint.rust.core.*
import com.google.android.material.snackbar.Snackbar import com.google.android.material.snackbar.Snackbar
import com.coldmint.rust.core.dataBean.CompileConfiguration 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.databinding.ModActionItemBinding
import com.coldmint.rust.pro.fragments.ModFragment import com.coldmint.rust.pro.fragments.ModFragment
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.gson.Gson import com.google.gson.Gson
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job import kotlinx.coroutines.Job
@ -118,7 +120,7 @@ class ModActionAdapter(
mContext.getString(R.string.mod_action2) -> { mContext.getString(R.string.mod_action2) -> {
editInfoItem() editInfoItem()
} }
mContext.getString(R.string.mod_action9) -> { mContext.getString(R.string.rename) -> {
renameItem() renameItem()
} }
mContext.getString(R.string.release) -> { mContext.getString(R.string.release) -> {
@ -441,46 +443,20 @@ class ModActionAdapter(
* 点击了重命名 * 点击了重命名
*/ */
private fun renameItem() { private fun renameItem() {
val builder = AlertDialog.Builder(
mContext
)
val dialogview = LayoutInflater.from(mContext).inflate(R.layout.input_dialog, null, false)
val editText = dialogview.findViewById<EditText>(R.id.dialog_edit)
val mod_file = File(mModpath) val mod_file = File(mModpath)
val oldname = ModClass(mod_file).modName val oldname = ModClass(mod_file).modName
editText.setText(oldname) InputDialog(mContext).setInputCanBeEmpty(false).setTitle(R.string.rename).setMaxNumber(255)
editText.postDelayed(object : Runnable { .setHint(R.string.file_name).setText(oldname)
override fun run() { .setPositiveButton(R.string.dialog_ok) { string ->
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()
}
}
}, 180)
val okview = dialogview.findViewById<TextView>(R.id.completion_button)
val calview = dialogview.findViewById<TextView>(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) { if (string.isNotEmpty() && string != oldname) {
val newFile = File(FileOperator.getSuperDirectory(mod_file) + "/" + string) val newFile = File(FileOperator.getSuperDirectory(mod_file) + "/" + string)
mod_file.renameTo(newFile) mod_file.renameTo(newFile)
mModFragment.loadMods() mModFragment.loadMods()
} }
alertDialog.dismiss() true
} }.setNegativeButton(R.string.dialog_cancel) {
}.setCancelable(false).show()
} }
/** /**
@ -489,7 +465,7 @@ class ModActionAdapter(
private fun editInfoItem() { private fun editInfoItem() {
val fileBundle = Bundle() val fileBundle = Bundle()
val infoIntent = Intent(mContext, EditModInfoActivity::class.java) 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("infoPath", modClass.getInfoFile().getAbsolutePath());
fileBundle.putString("modPath", mModpath) fileBundle.putString("modPath", mModpath)
infoIntent.putExtra("data", fileBundle) infoIntent.putExtra("data", fileBundle)

View File

@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.ModListItemBinding
/*模组适配器 /*模组适配器
* 此适配器只能使用于ModFragment成员变量按需传递 * 此适配器只能使用于ModFragment成员变量按需传递
* */ * */
class ModAdapter(private val context: Context, dataList: MutableList<ModClass>) : class ModAdapter(context: Context, dataList: MutableList<ModClass>) :
BaseAdapter<ModListItemBinding, ModClass>(context, dataList) { BaseAdapter<ModListItemBinding, ModClass>(context, dataList) {
init { init {
@ -68,7 +68,8 @@ class ModAdapter(private val context: Context, dataList: MutableList<ModClass>)
) )
) )
} else { } 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 { } else {
val drawable = context.getDrawable(R.drawable.file) val drawable = context.getDrawable(R.drawable.file)

View File

@ -27,7 +27,7 @@ import java.lang.StringBuilder
* @date 2022/1/9 11:03 * @date 2022/1/9 11:03
*/ */
class ReportAdapter( class ReportAdapter(
val context: Context, context: Context,
dataList: MutableList<ReportItemDataBean.Data> dataList: MutableList<ReportItemDataBean.Data>
) : ) :
BaseAdapter<ItemReportBinding, ReportItemDataBean.Data>(context, dataList) { BaseAdapter<ItemReportBinding, ReportItemDataBean.Data>(context, dataList) {

View File

@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2021/11/20 18:38 * @date 2021/11/20 18:38
*/ */
class ScreenshotAdapter(val context: Context, dataList: ArrayList<String>) : class ScreenshotAdapter( context: Context, dataList: ArrayList<String>) :
BaseAdapter<ScreenshotItemBinding, String>(context, dataList) { BaseAdapter<ScreenshotItemBinding, String>(context, dataList) {

View File

@ -24,7 +24,7 @@ import java.util.*
* @constructor * @constructor
*/ */
class SearchResultAdapter( class SearchResultAdapter(
val context: Context, context: Context,
val keyWord: String, val keyWord: String,
dataList: MutableList<SearchResultDataBean.Data.Total> dataList: MutableList<SearchResultDataBean.Data.Total>
) : ) :

View File

@ -25,7 +25,7 @@ import com.google.android.material.bottomsheet.BottomSheetDialog
import java.io.File import java.io.File
class TemplateListAdapter( class TemplateListAdapter(
val context: Context, context: Context,
dataList: ArrayList<TemplatePackage>, dataList: ArrayList<TemplatePackage>,
private val language: String, private val language: String,
private val rootPath: String private val rootPath: String

View File

@ -30,7 +30,7 @@ import java.util.ArrayList
//模板制作适配器 //模板制作适配器
class TemplateMakerAdapter(val context: Context, dataList: MutableList<CodeData>) : class TemplateMakerAdapter( context: Context, dataList: MutableList<CodeData>) :
BaseAdapter<MarkItemBinding, CodeData>(context, dataList) { BaseAdapter<MarkItemBinding, CodeData>(context, dataList) {
private var tags = ArrayList<String>() private var tags = ArrayList<String>()

View File

@ -15,7 +15,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2022/1/3 19:39 * @date 2022/1/3 19:39
*/ */
class ThanksAdapter(val context: Context, dataList: MutableList<ThanksDataBean>) : class ThanksAdapter(context: Context, dataList: MutableList<ThanksDataBean>) :
BaseAdapter<ItemThanksBinding, ThanksDataBean>(context, dataList) { BaseAdapter<ItemThanksBinding, ThanksDataBean>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -18,7 +18,7 @@ import java.util.*
import kotlin.Exception import kotlin.Exception
class UnitAdapter( class UnitAdapter(
private val context: Context, context: Context,
dataList: MutableList<SourceFile>, dataList: MutableList<SourceFile>,
val key: String val key: String
) : BaseAdapter<UnitItemBinding, SourceFile>(context, dataList) { ) : BaseAdapter<UnitItemBinding, SourceFile>(context, dataList) {

View File

@ -17,7 +17,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2021/12/23 22:44 * @date 2021/12/23 22:44
*/ */
class UserAdapter(val context: Context, dataList: MutableList<FollowUserListData.Data>) : class UserAdapter( context: Context, dataList: MutableList<FollowUserListData.Data>) :
BaseAdapter<ItemUserBinding, FollowUserListData.Data>(context, dataList) { BaseAdapter<ItemUserBinding, FollowUserListData.Data>(context, dataList) {
val defaultIntroduced = context.getString(R.string.defaultIntroduced) val defaultIntroduced = context.getString(R.string.defaultIntroduced)
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2021/12/28 10:59 * @date 2021/12/28 10:59
*/ */
class UserHeadAdapter(val context: Context, list: MutableList<FollowUserListData.Data>) : class UserHeadAdapter( context: Context, list: MutableList<FollowUserListData.Data>) :
BaseAdapter<ItemUserHeadBinding, FollowUserListData.Data>(context, list) { BaseAdapter<ItemUserHeadBinding, FollowUserListData.Data>(context, list) {
override fun getViewBindingObject( override fun getViewBindingObject(
layoutInflater: LayoutInflater, layoutInflater: LayoutInflater,

View File

@ -12,7 +12,7 @@ import com.coldmint.rust.pro.base.BaseAdapter
import com.coldmint.rust.pro.databinding.WebModItemBinding import com.coldmint.rust.pro.databinding.WebModItemBinding
import com.coldmint.rust.pro.tool.GlobalMethod import com.coldmint.rust.pro.tool.GlobalMethod
class WebModAdapter(val context: Context, dataList: MutableList<WebModListData.Data>) : class WebModAdapter( context: Context, dataList: MutableList<WebModListData.Data>) :
BaseAdapter<WebModItemBinding, WebModListData.Data>(context, dataList) { BaseAdapter<WebModItemBinding, WebModListData.Data>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -23,7 +23,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @date 2022/1/4 10:59 * @date 2022/1/4 10:59
*/ */
class WebModAllInfoAdapter( class WebModAllInfoAdapter(
val context: Context, context: Context,
list: MutableList<WebModAllInfoData.Data> list: MutableList<WebModAllInfoData.Data>
) : ) :
BaseAdapter<ItemWebmodAllInfoBinding, WebModAllInfoData.Data>(context, list) { BaseAdapter<ItemWebmodAllInfoBinding, WebModAllInfoData.Data>(context, list) {

View File

@ -21,7 +21,7 @@ import com.github.promeg.pinyinhelper.Pinyin
abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>( abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
private val context: Context, protected val context: Context,
protected var dataList: MutableList<DataType> protected var dataList: MutableList<DataType>
) : ) :
RecyclerView.Adapter<BaseAdapter.ViewHolder<ViewBindingType>>() { RecyclerView.Adapter<BaseAdapter.ViewHolder<ViewBindingType>>() {

View File

@ -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)

View File

@ -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<BookmarkDialog>(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
}
}

View File

@ -299,7 +299,7 @@ class ModFragment : BaseFragment<ModFragmentBinding>() {
} }
} else { } 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.mod_action8))
} }
works.add(getString(R.string.share_mod)) works.add(getString(R.string.share_mod))

View File

@ -1,7 +1,11 @@
package com.coldmint.rust.pro.viewmodel package com.coldmint.rust.pro.viewmodel
import android.content.Context import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Environment import android.os.Environment
import android.provider.MediaStore
import android.util.Log import android.util.Log
import androidx.lifecycle.MutableLiveData import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope 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.R
import com.coldmint.rust.pro.base.BaseViewModel import com.coldmint.rust.pro.base.BaseViewModel
import com.coldmint.rust.pro.tool.AppSettings 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 kotlinx.coroutines.launch
import java.io.File import java.io.File
import java.util.HashMap
class FileManagerViewModel : BaseViewModel() { class FileManagerViewModel : BaseViewModel() {
@ -23,6 +30,31 @@ class FileManagerViewModel : BaseViewModel() {
DEFAULT, SELECT_DIRECTORY, EXPORT_FILE, SELECT_FILE 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
}
/** /**
* 文件排序方式 * 文件排序方式
*/ */
@ -140,6 +172,63 @@ class FileManagerViewModel : BaseViewModel() {
rootPath = path ?: directs 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 默认加载根目录 * @param path String 默认加载根目录

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15,7v12.97l-4.21,-1.81 -0.79,-0.34 -0.79,0.34L5,19.97L5,7h10m4,-6L8.99,1C7.89,1 7,1.9 7,3h10c1.1,0 2,0.9 2,2v13l2,1L21,3c0,-1.1 -0.9,-2 -2,-2zM15,5L5,5c-1.1,0 -2,0.9 -2,2v16l7,-3 7,3L17,7c0,-1.1 -0.9,-2 -2,-2z"/>
</vector>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
</selector>

View File

@ -31,7 +31,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:gravity="center_horizontal" android:gravity="center_horizontal"
android:orientation="vertical"> android:orientation="vertical">

View File

@ -44,7 +44,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
@ -71,7 +71,7 @@
style="@style/Widget.Material3.CardView.Filled" style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"> android:layout_marginTop="16dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -106,7 +106,7 @@
style="@style/Widget.Material3.CardView.Filled" style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:layout_marginBottom="60dp"> android:layout_marginBottom="60dp">
<LinearLayout <LinearLayout

View File

@ -44,6 +44,7 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<TextView <TextView
style="@style/TextAppearance.Material3.TitleMedium"
android:id="@+id/fileError" android:id="@+id/fileError"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@ -32,31 +32,32 @@
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical"> android:orientation="vertical">
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/messages_header" android:text="@string/messages_header" />
android:textSize="16sp" />
<!--模组图标--> <!--模组图标-->
<LinearLayout <LinearLayout
android:layout_marginTop="8dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:gravity="center_vertical"> android:gravity="center_vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/mod_icon" /> android:text="@string/mod_icon" />
@ -114,59 +115,58 @@
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:animateLayoutChanges="true"> android:animateLayoutChanges="true">
<TextView <TextView
android:id="@+id/backgroundMusicView" android:id="@+id/backgroundMusicView"
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/background_music" android:text="@string/background_music" />
android:textSize="16sp" />
<TextView <TextView
android:id="@+id/musicPathView" android:id="@+id/musicPathView"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:text="未启用" /> android:text="未启用" />
<TextView <Button
android:id="@+id/enabledMusic" android:id="@+id/enabledMusic"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/backgroundMusicView" android:layout_below="@id/backgroundMusicView"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/enabled" android:text="@string/enabled" />
android:textColor="?attr/colorPrimary" />
<TextView <Button
android:id="@+id/addMusic" android:id="@+id/addMusic"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@id/enabledMusic" android:layout_alignBottom="@id/enabledMusic"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_toEndOf="@id/enabledMusic" android:layout_toEndOf="@id/enabledMusic"
android:text="@string/add" android:text="@string/add" />
android:textColor="?attr/colorPrimary" />
<ImageView <ImageView
android:id="@+id/expandMusicList" android:id="@+id/expandMusicList"
android:layout_width="20dp" android:layout_width="32dp"
android:layout_height="20dp" android:layout_height="32dp"
android:layout_below="@id/musicPathView" android:layout_below="@id/musicPathView"
android:layout_alignBottom="@id/enabledMusic" android:layout_alignBottom="@id/enabledMusic"
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
@ -201,62 +201,61 @@
</RelativeLayout> </RelativeLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:animateLayoutChanges="true"> android:animateLayoutChanges="true">
<TextView <TextView
android:id="@+id/mapView" android:id="@+id/mapView"
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/map" android:text="@string/map" />
android:textSize="16dp" />
<TextView <TextView
android:id="@+id/mapPathView" android:id="@+id/mapPathView"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:text="未启用" /> android:text="未启用" />
<TextView <Button
android:id="@+id/enabledMap" android:id="@+id/enabledMap"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/mapView" android:layout_below="@id/mapView"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:text="@string/enabled" android:text="@string/enabled" />
android:textColor="?attr/colorPrimary" />
<TextView <Button
android:id="@+id/addMap" android:id="@+id/addMap"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="@id/enabledMap" android:layout_alignBottom="@id/enabledMap"
android:layout_marginStart="16dp" android:layout_marginStart="16dp"
android:layout_toEndOf="@id/enabledMap" android:layout_toEndOf="@id/enabledMap"
android:text="@string/add" android:text="@string/add" />
android:textColor="?attr/colorPrimary" />
<ImageView <ImageView
android:id="@+id/expandMapList" android:id="@+id/expandMapList"
android:layout_width="20dp" android:layout_width="32dp"
android:layout_height="20dp" android:layout_height="32dp"
android:layout_below="@id/mapPathView" android:layout_below="@id/mapPathView"
android:layout_alignBottom="@id/enabledMap" android:layout_alignBottom="@id/enabledMap"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:src="@drawable/expand_icon" android:src="@drawable/expand_icon"
app:tint="?android:colorControlNormal" /> app:tint="?android:colorControlNormal" />
@ -288,7 +287,7 @@
</RelativeLayout> </RelativeLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>

View File

@ -77,7 +77,7 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="5dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<ScrollView <ScrollView

View File

@ -16,6 +16,13 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" /> android:layout_height="?attr/actionBarSize" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fileTabNav"
android:layout_marginHorizontal="16dp"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
@ -31,11 +38,18 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content"> android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView" android:id="@+id/recyclerView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent" />
android:visibility="gone" /> </LinearLayout>
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
@ -61,9 +75,11 @@
<com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/fab" android:id="@+id/fab"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="44dp"
android:layout_gravity="bottom|end" android:layout_gravity="bottom|end"
android:layout_margin="16dp" android:layout_margin="16dp"
app:icon="@drawable/add" /> app:icon="@drawable/add" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -21,7 +21,6 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -36,23 +35,22 @@
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:orientation="vertical"> android:orientation="vertical">
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/rule" android:text="@string/rule" />
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/ruleInputLayout" android:id="@+id/ruleInputLayout"
@ -85,16 +83,15 @@
android:text="@string/find" /> android:text="@string/find" />
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
android:id="@+id/operationCard" android:id="@+id/operationCard"
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:visibility="gone" android:visibility="gone">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -104,10 +101,10 @@
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/operation" android:text="@string/operation" />
android:textSize="16sp" />
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -173,29 +170,28 @@
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
android:id="@+id/resultCard" android:id="@+id/resultCard"
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:visibility="gone" android:visibility="gone">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
android:id="@+id/titleView" android:id="@+id/titleView"
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/affect_list" android:text="@string/affect_list" />
android:textSize="16sp" />
<TextView <TextView
android:id="@+id/listTipView" android:id="@+id/listTipView"
@ -211,7 +207,7 @@
android:layout_marginTop="8dp" /> android:layout_marginTop="8dp" />
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>

View File

@ -21,7 +21,6 @@
</com.google.android.material.appbar.AppBarLayout> </com.google.android.material.appbar.AppBarLayout>
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
@ -69,29 +68,29 @@
</androidx.cardview.widget.CardView> </androidx.cardview.widget.CardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/additional_selection" android:text="@string/additional_selection" />
android:textSize="16sp" />
<CheckBox <CheckBox
android:id="@+id/deleteSourceFile" android:id="@+id/deleteSourceFile"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/delete_source_file" /> android:text="@string/delete_source_file" />
<CheckBox <CheckBox
@ -120,26 +119,25 @@
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/configuration" android:text="@string/configuration" />
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -180,28 +178,27 @@
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
<androidx.cardview.widget.CardView <com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Elevated"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="16dp"
android:layout_marginBottom="60dp" android:layout_marginBottom="16dp">
app:cardElevation="2dp"
card_view:cardCornerRadius="2dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_margin="8dp" android:layout_margin="16dp"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
style="@style/TextAppearance.Material3.HeadlineSmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/about" android:text="@string/about" />
android:textSize="16sp" />
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -258,19 +255,19 @@
android:entries="@array/update_type_entries" /> android:entries="@array/update_type_entries" />
</RelativeLayout> </RelativeLayout>
</LinearLayout> </LinearLayout>
</androidx.cardview.widget.CardView> </com.google.android.material.card.MaterialCardView>
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>
<Button <com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
android:id="@+id/packButton" android:id="@+id/packButton"
android:layout_width="match_parent" app:icon="@drawable/zip"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="bottom" android:layout_gravity="bottom|right"
android:layout_marginLeft="16dp" android:layout_margin="16dp"
android:layout_marginRight="16dp"
android:text="@string/packmod" /> android:text="@string/packmod" />
</androidx.coordinatorlayout.widget.CoordinatorLayout> </androidx.coordinatorlayout.widget.CoordinatorLayout>

View File

@ -2,84 +2,91 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:paddingTop="8dp" android:orientation="vertical"
android:paddingLeft="8dp" android:padding="24dp">
android:paddingRight="8dp"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView <TextView
android:id="@+id/titleView"
style="@style/MaterialAlertDialog.Material3.Title.Text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/name" /> android:text="@string/title" />
<EditText <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/nameInputLayout"
android:layout_marginTop="24dp"
android:hint="@string/name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/nameView" android:id="@+id/nameView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" /> android:layout_height="wrap_content"
android:imeOptions="actionNext"
android:inputType="text" />
</com.google.android.material.textfield.TextInputLayout>
</LinearLayout>
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/pathView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_marginTop="16dp">
android:layout_centerVertical="true"
android:text="@string/path" />
<EditText <com.google.android.material.textfield.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pathInputLayout"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/button"
android:hint="@string/path">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/pathEdit" android:id="@+id/pathEdit"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_centerVertical="true" android:imeOptions="actionDone"
android:layout_toLeftOf="@id/button" android:inputType="textMultiLine" />
android:layout_toRightOf="@id/pathView" />
</com.google.android.material.textfield.TextInputLayout>
<Button <Button
android:id="@+id/button" android:id="@+id/button"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentRight="true" android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp" android:layout_centerVertical="true"
android:layout_marginStart="8dp"
android:text="@string/select_directents" /> android:text="@string/select_directents" />
</RelativeLayout> </RelativeLayout>
<!-- <RelativeLayout--> <RelativeLayout
<!-- android:layout_marginTop="8dp"--> android:id="@+id/buttonContainer"
<!-- android:layout_marginBottom="16dp"--> android:layout_width="match_parent"
<!-- android:layout_width="match_parent"--> android:layout_height="wrap_content"
<!-- android:layout_height="wrap_content">--> android:layout_marginTop="24dp">
<!-- <TextView--> <Button
<!-- android:id="@+id/cancelView"--> android:id="@+id/negativeButton"
<!-- android:layout_width="wrap_content"--> style="@style/Widget.Material3.Button.TextButton.Dialog.Flush"
<!-- android:layout_height="wrap_content"--> android:layout_width="wrap_content"
<!-- android:layout_marginRight="24dp"--> android:layout_height="wrap_content"
<!-- android:layout_toLeftOf="@id/saveView"--> android:layout_toStartOf="@id/positiveButton"
<!-- android:padding="6dp"--> android:text="@string/title" />
<!-- android:text="@string/dialog_cancel"-->
<!-- android:textColor="?colorPrimary" />-->
<!-- <TextView--> <Button
<!-- android:id="@+id/saveView"--> android:id="@+id/positiveButton"
<!-- android:layout_width="wrap_content"--> style="@style/Widget.Material3.Button.TextButton.Dialog.Flush"
<!-- android:layout_height="wrap_content"--> android:layout_width="wrap_content"
<!-- android:layout_alignParentRight="true"--> android:layout_height="wrap_content"
<!-- android:layout_marginRight="24dp"--> android:layout_alignParentEnd="true"
<!-- android:padding="6dp"--> android:layout_marginStart="8dp"
<!-- android:text="@string/edit_function"--> android:text="@string/title" />
<!-- android:textColor="?colorPrimary" />-->
<!-- </RelativeLayout>--> </RelativeLayout>
</LinearLayout> </LinearLayout>

View File

@ -20,8 +20,7 @@
android:id="@+id/myHomeView" android:id="@+id/myHomeView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:layout_marginHorizontal="8dp" android:layout_margin="16dp"
android:layout_marginVertical="16dp"
android:animateLayoutChanges="true" android:animateLayoutChanges="true"
android:orientation="horizontal"> android:orientation="horizontal">

View File

@ -10,9 +10,10 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dp"> android:layout_margin="16dp">
<ImageView <ImageView
android:layout_centerVertical="true"
android:id="@+id/mod_icon" android:id="@+id/mod_icon"
android:layout_width="60dp" android:layout_width="60dp"
android:layout_height="60dp" android:layout_height="60dp"
@ -58,6 +59,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <LinearLayout
android:layout_marginTop="8dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/infoLayout" android:layout_below="@id/infoLayout"

View File

@ -35,13 +35,14 @@
<TextView <TextView
android:id="@+id/titleView" android:id="@+id/titleView"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/mod_title" android:text="@string/mod_title" />
android:textSize="16sp" />
<TextView <TextView
android:id="@+id/descriptionView" android:id="@+id/descriptionView"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
@ -49,6 +50,7 @@
<TextView <TextView
android:id="@+id/expirationTimeView" android:id="@+id/expirationTimeView"
style="@style/TextAppearance.Material3.BodySmall"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"

View File

@ -8,7 +8,7 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="8dp"> android:layout_margin="16dp">
<ImageView <ImageView
android:id="@+id/headIconView" android:id="@+id/headIconView"

View File

@ -8,13 +8,14 @@
<TextView <TextView
android:id="@+id/timeView" android:id="@+id/timeView"
android:textSize="16sp" style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/mod_title" /> android:text="@string/mod_title" />
<TextView <TextView
android:id="@+id/describeView" android:id="@+id/describeView"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<com.google.android.material.button.MaterialButton
android:id="@+id/button"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
app:icon="@drawable/ic_baseline_chevron_right_24"
app:iconGravity="end" />
</LinearLayout>

View File

@ -5,12 +5,12 @@
style="@style/Widget.Material3.CardView.Filled" style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="8dp"> android:layout_marginBottom="16dp">
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:padding="16dp"> android:layout_margin="16dp">
<ImageView <ImageView
android:id="@+id/headIconView" android:id="@+id/headIconView"

View File

@ -24,6 +24,28 @@
</group> </group>
</menu> </menu>
</item> </item>
<item
android:id="@+id/action_bookmark"
android:icon="@drawable/ic_outline_bookmarks_24"
android:title="@string/bookmark_manager"
app:showAsAction="ifRoom">
<menu>
<item
android:id="@+id/bookmark_manager"
android:title="@string/bookmark_manager" />
<item
android:id="@+id/mine_bookmarks"
android:title="@string/mine_bookmarks">
<menu>
<!-- 书签列表-->
</menu>
</item>
</menu>
</item>
<item <item
android:id="@+id/reloadFile" android:id="@+id/reloadFile"

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<item
android:id="@+id/cutOffAction"
android:title="@string/cut_off" />
<item
android:id="@+id/copyAction"
android:title="@string/copy" />
<item
android:id="@+id/renameAction"
android:title="@string/rename" />
<item
android:id="@+id/deleteAction"
android:title="@string/delete_title" />
<item
android:id="@+id/bookmarkAction"
android:title="@string/add_bookmark" />
</menu>

View File

@ -52,7 +52,7 @@
<string name="dialog_unziping">Extracting %1$s…</string> <string name="dialog_unziping">Extracting %1$s…</string>
<string name="not_find_mod">no mods</string> <string name="not_find_mod">no mods</string>
<string name="menu_title1">Mod</string> <string name="menu_title1">Mod</string>
<string name="file_name">file name:</string> <string name="file_name">file name</string>
<string name="file">document</string> <string name="file">document</string>
<string name="menu_title3">data set</string> <string name="menu_title3">data set</string>
<string name="data_array">Data array (separated by \\"|\\"):</string> <string name="data_array">Data array (separated by \\"|\\"):</string>

View File

@ -51,7 +51,7 @@
<string name="dialog_unziping">%1$sを引き出しています…</string> <string name="dialog_unziping">%1$sを引き出しています…</string>
<string name="not_find_mod">モジュールがない</string> <string name="not_find_mod">モジュールがない</string>
<string name="menu_title1">同じ組の</string> <string name="menu_title1">同じ組の</string>
<string name="file_name">ファイル名:</string> <string name="file_name">ファイル名</string>
<string name="file">ファイル</string> <string name="file">ファイル</string>
<string name="menu_title3">データセット</string> <string name="menu_title3">データセット</string>
<string name="data_array">データの配列(\ \" | \分割で):</string> <string name="data_array">データの配列(\ \" | \分割で):</string>

View File

@ -51,7 +51,7 @@
<string name="dialog_unziping">Мы извлекаем 10%...</string> <string name="dialog_unziping">Мы извлекаем 10%...</string>
<string name="not_find_mod">Нет модуля.</string> <string name="not_find_mod">Нет модуля.</string>
<string name="menu_title1">модул</string> <string name="menu_title1">модул</string>
<string name="file_name">Имя файла:</string> <string name="file_name">Имя файла</string>
<string name="file">документ</string> <string name="file">документ</string>
<string name="menu_title3">Набор данных</string> <string name="menu_title3">Набор данных</string>
<string name="data_array">Массив Дан (\ \"- да \\" раздел) :</string> <string name="data_array">Массив Дан (\ \"- да \\" раздел) :</string>

View File

@ -44,12 +44,11 @@
<string name="create_uniting">正在構建單位...</string> <string name="create_uniting">正在構建單位...</string>
<string name="dialog_title2">解壓</string> <string name="dialog_title2">解壓</string>
<string name="dialog_unziping">正在解壓%1$s...</string> <string name="dialog_unziping">正在解壓%1$s...</string>
<string name="file_name">文件名:</string> <string name="file_name">文件名</string>
<string name="del_moding">正在刪除</string> <string name="del_moding">正在刪除</string>
<string name="file_manager">文件管理器</string> <string name="file_manager">文件管理器</string>
<string name="unit_error">無法創建,此單位已存在。</string> <string name="unit_error">無法創建,此單位已存在。</string>
<string name="folder_error">無法創建,此文件夾已存在。</string> <string name="folder_error">無法創建,此文件夾已存在。</string>
<string name="mod_action9">重命名</string>
<string name="open_action1">編輯文本</string> <string name="open_action1">編輯文本</string>
<string name="open_action3">解壓文件</string> <string name="open_action3">解壓文件</string>
<string name="open_action4">系統默認方式打開</string> <string name="open_action4">系統默認方式打開</string>

View File

@ -12,6 +12,7 @@
<string name="select_directents">选择目录</string> <string name="select_directents">选择目录</string>
<string name="select_file">选择文件</string> <string name="select_file">选择文件</string>
<string name="select_file_ok">已选\"%1$s\"</string> <string name="select_file_ok">已选\"%1$s\"</string>
<string name="root_path">根目录</string>
<string name="select_image">选择图像</string> <string name="select_image">选择图像</string>
<string name="change_image">更换图像</string> <string name="change_image">更换图像</string>
<string name="del_image">移除图像</string> <string name="del_image">移除图像</string>
@ -52,7 +53,7 @@
<string name="dialog_unziping">正在提取%1$s...</string> <string name="dialog_unziping">正在提取%1$s...</string>
<string name="not_find_mod">没有模组</string> <string name="not_find_mod">没有模组</string>
<string name="menu_title1">模组</string> <string name="menu_title1">模组</string>
<string name="file_name">文件名:</string> <string name="file_name">文件名</string>
<string name="file">文件</string> <string name="file">文件</string>
<string name="menu_title3">数据集</string> <string name="menu_title3">数据集</string>
<string name="data_array">数据数组(以\"|\"分割):</string> <string name="data_array">数据数组(以\"|\"分割):</string>
@ -114,7 +115,7 @@
<string name="mod_action1">编辑单位</string> <string name="mod_action1">编辑单位</string>
<string name="mod_action2">编辑信息</string> <string name="mod_action2">编辑信息</string>
<string name="mod_action8">解压</string> <string name="mod_action8">解压</string>
<string name="mod_action9">重命名</string> <string name="rename">重命名</string>
<string name="mod_action10">修复信息文件</string> <string name="mod_action10">修复信息文件</string>
<string name="open_action1">编辑文本</string> <string name="open_action1">编辑文本</string>
@ -427,7 +428,7 @@
<string name="pack_directory">打包目录</string> <string name="pack_directory">打包目录</string>
<string name="info">信息</string> <string name="info">信息</string>
<string name="cut_board_operation">剪切板操作</string> <string name="cut_board_operation">剪切板操作</string>
<string name="bookmarks_operation">书签操作</string> <string name="mine_bookmarks">我的书签</string>
<string name="bookmark_manager">书签管理器</string> <string name="bookmark_manager">书签管理器</string>
<string name="jump_a_bookmark">跳转书签</string> <string name="jump_a_bookmark">跳转书签</string>
<string name="remove_bookmark">移除书签</string> <string name="remove_bookmark">移除书签</string>

View File

@ -7,6 +7,7 @@
<item name="android:popupMenuStyle">@style/Widget.MaterialFiles.Material3.Preference.SimpleMenuPreference.PopupMenu</item> <item name="android:popupMenuStyle">@style/Widget.MaterialFiles.Material3.Preference.SimpleMenuPreference.PopupMenu</item>
</style> </style>
<style name="Widget.MaterialFiles.Material3.Preference.SimpleMenuPreference.PopupMenu" parent="Widget.Preference.SimpleMenuPreference.PopupMenu"> <style name="Widget.MaterialFiles.Material3.Preference.SimpleMenuPreference.PopupMenu" parent="Widget.Preference.SimpleMenuPreference.PopupMenu">
<item name="android:popupBackground">@drawable/m3_popupmenu_background_overlay</item>
</style> </style>
<!-- <style name="TextAppearance.MaterialFiles.Material3.ListItem" parent="TextAppearance.Material3.TitleMedium">--> <!-- <style name="TextAppearance.MaterialFiles.Material3.ListItem" parent="TextAppearance.Material3.TitleMedium">-->

View File

@ -40,12 +40,10 @@
<item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item> <item name="colorOnSurfaceInverse">@color/md_theme_light_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item> <item name="colorSurfaceInverse">@color/md_theme_light_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item> <item name="colorPrimaryInverse">@color/md_theme_light_inversePrimary</item>
<item name="android:popupBackground" tools:ignore="PrivateResource"> <item name="popupMenuStyle">@style/Widget.Material3.PopupMenu</item>
@drawable/m3_popupmenu_background_overlay
</item>
</style> </style>
<style name="Base.rust.Dark.Concept" parent="Theme.Material3.Dark.NoActionBar"> <style name="Base.rust.Dark.Concept" parent="Theme.Material3.Dark.NoActionBar">
<item name="colorPrimary">@color/md_theme_dark_primary</item> <item name="colorPrimary">@color/md_theme_dark_primary</item>
<item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item> <item name="colorOnPrimary">@color/md_theme_dark_onPrimary</item>
@ -73,9 +71,6 @@
<item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item> <item name="colorOnSurfaceInverse">@color/md_theme_dark_inverseOnSurface</item>
<item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item> <item name="colorSurfaceInverse">@color/md_theme_dark_inverseSurface</item>
<item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item> <item name="colorPrimaryInverse">@color/md_theme_dark_inversePrimary</item>
<item name="android:popupBackground" tools:ignore="PrivateResource">
@drawable/m3_popupmenu_background_overlay
</item>
</style> </style>
<!--设置标签为小写--> <!--设置标签为小写-->

View File

@ -16,6 +16,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
MaterialAlertDialogBuilder(context) MaterialAlertDialogBuilder(context)
} }
//是否自动关闭
protected var autoDismiss : Boolean = true
protected lateinit var dialog: AlertDialog protected lateinit var dialog: AlertDialog
@ -51,6 +54,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setPositiveButton(text: String, func: () -> Unit): DialogType { override fun setPositiveButton(text: String, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setPositiveButton(text) { i, i2 -> materialAlertDialogBuilder.setPositiveButton(text) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -58,6 +64,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setPositiveButton(textRes: Int, func: () -> Unit): DialogType { override fun setPositiveButton(textRes: Int, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setPositiveButton(textRes) { i, i2 -> materialAlertDialogBuilder.setPositiveButton(textRes) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -65,6 +74,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setNegativeButton(text: String, func: () -> Unit): DialogType { override fun setNegativeButton(text: String, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setNegativeButton(text) { i, i2 -> materialAlertDialogBuilder.setNegativeButton(text) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -72,6 +84,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setNegativeButton(textRes: Int, func: () -> Unit): DialogType { override fun setNegativeButton(textRes: Int, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setNegativeButton(textRes) { i, i2 -> materialAlertDialogBuilder.setNegativeButton(textRes) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -79,6 +94,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setNeutralButton(text: String, func: () -> Unit): DialogType { override fun setNeutralButton(text: String, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setNeutralButton(text) { i, i2 -> materialAlertDialogBuilder.setNeutralButton(text) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -86,6 +104,9 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
override fun setNeutralButton(textRes: Int, func: () -> Unit): DialogType { override fun setNeutralButton(textRes: Int, func: () -> Unit): DialogType {
materialAlertDialogBuilder.setNeutralButton(textRes) { i, i2 -> materialAlertDialogBuilder.setNeutralButton(textRes) { i, i2 ->
func.invoke() func.invoke()
if (autoDismiss){
dialog.dismiss()
}
} }
return this as DialogType return this as DialogType
} }
@ -112,6 +133,7 @@ abstract class BaseAppDialog<DialogType : AppDialog>(context: Context) :
} }
override fun setAutoDismiss(enable: Boolean): DialogType { override fun setAutoDismiss(enable: Boolean): DialogType {
autoDismiss = enable
return this as DialogType return this as DialogType
} }

View File

@ -17,7 +17,6 @@ class CoreDialog(context: Context) : BaseAppDialog<CoreDialog>(context) {
DialogCoreBinding.inflate(LayoutInflater.from(context)) DialogCoreBinding.inflate(LayoutInflater.from(context))
} }
private var autoDismiss: Boolean = true
init { init {
setView(dialogCoreBinding.root) setView(dialogCoreBinding.root)

View File

@ -20,7 +20,6 @@ class InputDialog(context: Context) : BaseAppDialog<InputDialog>(context) {
DialogInputBinding.inflate(LayoutInflater.from(context)) DialogInputBinding.inflate(LayoutInflater.from(context))
} }
private var autoDismiss: Boolean = true
private var inputCanBeEmpty: Boolean = true private var inputCanBeEmpty: Boolean = true
private var errorTipFunction: ((String, TextInputLayout) -> Unit)? = null private var errorTipFunction: ((String, TextInputLayout) -> Unit)? = null
@ -74,8 +73,11 @@ class InputDialog(context: Context) : BaseAppDialog<InputDialog>(context) {
*/ */
fun setInputCanBeEmpty(can: Boolean): InputDialog { fun setInputCanBeEmpty(can: Boolean): InputDialog {
inputCanBeEmpty = can inputCanBeEmpty = can
if (!can) {
//如果不可空检查是否需要禁用
val text = dialogInputBinding.textInputEditText.text.toString() val text = dialogInputBinding.textInputEditText.text.toString()
dialogInputBinding.positiveButton.isEnabled = text.isNotBlank() dialogInputBinding.positiveButton.isEnabled = text.isNotBlank()
}
return this return this
} }
@ -98,10 +100,12 @@ class InputDialog(context: Context) : BaseAppDialog<InputDialog>(context) {
} else { } else {
dialogInputBinding.positiveButton.isEnabled = dialogInputBinding.positiveButton.isEnabled =
!(text.isBlank() && !inputCanBeEmpty) !(text.isBlank() && !inputCanBeEmpty)
return
} }
//如果启用计数并且,超过最大字数 //如果启用计数并且,超过最大字数
if (dialogInputBinding.textInputLayout.isCounterEnabled && text.length > dialogInputBinding.textInputLayout.counterMaxLength) { if (dialogInputBinding.textInputLayout.isCounterEnabled && text.length > dialogInputBinding.textInputLayout.counterMaxLength) {
dialogInputBinding.textInputLayout.isErrorEnabled = true dialogInputBinding.textInputLayout.isErrorEnabled = true
return
} }
//如果处于错误状态禁用按钮 //如果处于错误状态禁用按钮
dialogInputBinding.positiveButton.isEnabled = dialogInputBinding.positiveButton.isEnabled =

View File

@ -36,6 +36,7 @@
<com.google.android.material.textfield.TextInputEditText <com.google.android.material.textfield.TextInputEditText
android:id="@+id/textInputEditText" android:id="@+id/textInputEditText"
android:layout_width="match_parent" android:layout_width="match_parent"
android:inputType="text"
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
</com.google.android.material.textfield.TextInputLayout> </com.google.android.material.textfield.TextInputLayout>

View File

@ -2,3 +2,4 @@ include ':app'
rootProject.name = "铁锈助手" rootProject.name = "铁锈助手"
include ':assistantCoreLibrary' include ':assistantCoreLibrary'
include ':dialog' include ':dialog'
include ':turretsDragView'

1
turretsDragView/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/build

View File

@ -0,0 +1,40 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}
android {
compileSdk 32
defaultConfig {
minSdk 21
targetSdk 32
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = '1.8'
}
}
dependencies {
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.3.0'
implementation 'com.google.android.material:material:1.4.0'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

View File

21
turretsDragView/proguard-rules.pro vendored Normal file
View File

@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html
# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable
# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile

View File

@ -0,0 +1,24 @@
package com.coldmint.turretsdragview
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.Assert.*
/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.coldmint.turretsdragview.test", appContext.packageName)
}
}

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.coldmint.turretsdragview">
</manifest>

View File

@ -0,0 +1,11 @@
package com.coldmint.turretsdragview
/**
* 炮塔数据
* @property name String
* @property x Int
* @property y Int
* @constructor
*/
data class TurretData(val name: String, val x: Int, val y: Int)

View File

@ -0,0 +1,84 @@
package com.coldmint.turretsdragview
import android.content.Context
import android.graphics.*
import android.util.Log
import android.view.View
/**
* 炮塔拖拽视图
*/
class TurretsDragView(context: Context) : View(context) {
val key = "炮塔拖拽视图"
//主要位图变量
private var baseBitmap: Bitmap? = null
//画布
private var canvas: Canvas? = null
//画笔
private val paint by lazy {
Paint()
}
//路径与位图之间的映射
val map = HashMap<String, Bitmap>()
/**
* 获取位图
* 优先从映射里读取
* @param path String
* @return Bitmap
*/
fun getBitmap(path: String): Bitmap {
var bitmap = map[path]
if (bitmap == null) {
bitmap = BitmapFactory.decodeFile(path)
map[path] = bitmap
}
return bitmap!!
}
/**
* 设置主体图像
*/
fun setBaseImage(path: String) {
baseBitmap = getBitmap(path)
}
/**
* 炮塔列表数据
*/
private val turretList by lazy {
ArrayList<TurretData>()
}
/**
* 当测量视图
* @param widthMeasureSpec Int
* @param heightMeasureSpec Int
*/
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
/**
* 当绘制视图
* @param canvas Canvas
*/
override fun onDraw(canvas: Canvas?) {
super.onDraw(canvas)
this.canvas = canvas
if (baseBitmap == null) {
Log.e(key, "未设置炮塔主体图像")
throw NullPointerException("未设置炮塔主体图像")
}else{
val matrix = Matrix()
canvas!!.drawBitmap(baseBitmap!!,matrix, paint)
}
}
}

View File

@ -0,0 +1,17 @@
package com.coldmint.turretsdragview
import org.junit.Test
import org.junit.Assert.*
/**
* Example local unit test, which will execute on the development machine (host).
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
class ExampleUnitTest {
@Test
fun addition_isCorrect() {
assertEquals(4, 2 + 2)
}
}