按首字母排序文件夹

This commit is contained in:
coldmint 2022-07-19 22:32:02 +08:00
parent 18b5e28367
commit d8bf779c8f
33 changed files with 123 additions and 158 deletions

Binary file not shown.

View File

@ -68,6 +68,7 @@ android {
dependencies { dependencies {
implementation 'me.zhanghai.android.fastscroll:library:1.1.8'
// https://github.com/getActivity/MultiLanguages // https://github.com/getActivity/MultiLanguages
implementation 'com.github.getActivity:MultiLanguages:8.0' implementation 'com.github.getActivity:MultiLanguages:8.0'
// //

View File

@ -122,7 +122,7 @@ class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
finalPlanAdapter.setCoupon(null) finalPlanAdapter.setCoupon(null)
finalPlanAdapter.setCoupon(data) finalPlanAdapter.setCoupon(data)
selectItemAndLoadInfo( selectItemAndLoadInfo(
finalPlanAdapter.dataList[0], finalPlanAdapter.getItemData(0),
finalPlanAdapter, finalPlanAdapter,
0 0
) )
@ -138,7 +138,7 @@ class ActivateActivity : BaseActivity<ActivityActivateBinding>() {
viewBinding.couponDescribeView.text = viewBinding.couponDescribeView.text =
getString(R.string.coupon_not_use) getString(R.string.coupon_not_use)
selectItemAndLoadInfo( selectItemAndLoadInfo(
finalPlanAdapter.dataList[0], finalPlanAdapter.getItemData(0),
finalPlanAdapter, finalPlanAdapter,
0 0
) )

View File

@ -29,6 +29,7 @@ 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.viewmodel.FileManagerViewModel import com.coldmint.rust.pro.viewmodel.FileManagerViewModel
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import me.zhanghai.android.fastscroll.FastScrollerBuilder
import java.io.File import java.io.File
import java.lang.Exception import java.lang.Exception
import java.util.* import java.util.*
@ -878,6 +879,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
// initAction() // initAction()
// } // }
// } // }
private lateinit var menuBinding: MenuBinding
private val viewModel: FileManagerViewModel by lazy { private val viewModel: FileManagerViewModel by lazy {
ViewModelProvider(this).get(FileManagerViewModel::class.java) ViewModelProvider(this).get(FileManagerViewModel::class.java)
} }
@ -890,6 +892,12 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity) viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity)
loadTitle() loadTitle()
loadObserve() loadObserve()
FastScrollerBuilder(viewBinding.recyclerView).useMd2Style()
.setPopupTextProvider(adapter).build()
viewBinding.swipeRefreshLayout.setOnRefreshListener {
viewModel.loadFiles(viewModel.getCurrentPath())
viewBinding.swipeRefreshLayout.isRefreshing = false
}
viewModel.loadFiles() viewModel.loadFiles()
} else { } else {
val bundle = intent.getBundleExtra("data") val bundle = intent.getBundleExtra("data")
@ -907,6 +915,11 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
} }
} }
override fun onCreateOptionsMenu(menu: Menu): Boolean {
menuBinding = MenuBinding.inflate(menu, menuInflater)
return true
}
/** /**
* 加载观察者 * 加载观察者
*/ */
@ -926,7 +939,6 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
if (file == null) { if (file == null) {
viewModel.returnDirects() viewModel.returnDirects()
} else { } else {
Toast.makeText(this,file.absolutePath,Toast.LENGTH_SHORT).show()
if (file.isDirectory) { if (file.isDirectory) {
viewModel.currentPathLiveData.value = file.absolutePath viewModel.currentPathLiveData.value = file.absolutePath
} else { } else {
@ -940,7 +952,7 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
adapter?.setNewDataList(it) adapter?.setNewDataList(it)
} }
} }
viewModel.currentPathLiveData.observe(this){ viewModel.currentPathLiveData.observe(this) {
viewModel.loadFiles(it) viewModel.loadFiles(it)
} }
} }
@ -962,4 +974,25 @@ class FileManagerActivity : BaseActivity<ActivityFileBinding>() {
override fun getViewBindingObject(): ActivityFileBinding { override fun getViewBindingObject(): ActivityFileBinding {
return ActivityFileBinding.inflate(layoutInflater) return ActivityFileBinding.inflate(layoutInflater)
} }
class MenuBinding private constructor(
val menu: Menu,
val reloadFileItem: MenuItem,
val photoAlbumItem: MenuItem,
val systemFileManagerItem: MenuItem
) {
companion object {
//填充
fun inflate(menu: Menu, inflater: MenuInflater): MenuBinding {
inflater.inflate(R.menu.menu_files, menu)
return MenuBinding(
menu,
menu.findItem(R.id.reloadFile),
menu.findItem(R.id.photo_album),
menu.findItem(R.id.system_file_manager)
)
}
}
}
} }

View File

@ -63,7 +63,6 @@ class RecyclingStationActivity : BaseActivity<ActivityRecyclingStationBinding>()
} }
if (fileArrayList.size > 0) { if (fileArrayList.size > 0) {
val fileAdapter = FileAdapter(this@RecyclingStationActivity, fileArrayList) val fileAdapter = FileAdapter(this@RecyclingStationActivity, fileArrayList)
fileAdapter.setSortType(FileAdapter.SortType.ModifyDate)
fileAdapter.setItemEvent { i, fileItemBinding, viewHolder, file -> fileAdapter.setItemEvent { i, fileItemBinding, viewHolder, file ->
fileItemBinding.more.setOnClickListener { fileItemBinding.more.setOnClickListener {
if (file == null) { if (file == null) {

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, var dataList: MutableList<Bookmark>) : class BookmarkAdapter(val 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, val dataList: MutableList<WebModCommentData.Data>) : class CommentAdapter(val context: Context, dataList: MutableList<WebModCommentData.Data>) :
BaseAdapter<ItemCommentBinding, WebModCommentData.Data>(context, dataList) { BaseAdapter<ItemCommentBinding, WebModCommentData.Data>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(

View File

@ -14,7 +14,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
*/ */
class CommunityServiceAdapter( class CommunityServiceAdapter(
val context: Context, val context: Context,
val dataList: MutableList<CommunityServiceInfo> dataList: MutableList<CommunityServiceInfo>
) : ) :
BaseAdapter<ItemServiceBinding, CommunityServiceInfo>(context, dataList) { BaseAdapter<ItemServiceBinding, CommunityServiceInfo>(context, dataList) {

View File

@ -14,14 +14,16 @@ import com.bumptech.glide.Glide
import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.base.BaseAdapter
import com.coldmint.rust.pro.databinding.FileItemBinding import com.coldmint.rust.pro.databinding.FileItemBinding
import com.github.promeg.pinyinhelper.Pinyin
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import me.zhanghai.android.fastscroll.PopupTextProvider
import java.io.File import java.io.File
import java.lang.StringBuilder 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, private var dataList: MutableList<File?>) : class FileAdapter(private val context: Context, dataList: MutableList<File?>) :
BaseAdapter<FileItemBinding, File?>(context, dataList) { BaseAdapter<FileItemBinding, File?>(context, dataList), PopupTextProvider {
/** /**
* 获取选中目录 * 获取选中目录
@ -39,73 +41,6 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
var isCopyFile = false var isCopyFile = false
private set private set
enum class SortType {
FileName, ModifyDate, FileVolume
}
/**
* 设置排序方式
* @param type SortType?
*/
fun setSortType(type: SortType?) {
when (type) {
SortType.FileName -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
dataList.sortedWith(java.util.Comparator<File?> { o1, o2 ->
if (o1 == null) {
return@Comparator -1
}
if (o2 == null) {
return@Comparator 1
}
if (o1.isDirectory && o2.isFile) {
-1
} else if (o1.isFile && o2.isDirectory) {
1
} else {
o1.name.compareTo(o2.name)
}
})
}
SortType.ModifyDate -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
dataList.sortedWith(java.util.Comparator<File?> { o1, o2 ->
if (o1 == null) {
return@Comparator -1
}
if (o2 == null) {
return@Comparator 1
}
val diff = o1.lastModified() - o2.lastModified()
if (diff > 0) {
1
} else if (diff < 0) {
-1
} else {
0
}
})
}
SortType.FileVolume -> if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
dataList.sortedWith(java.util.Comparator<File?> { o1, o2 ->
if (o1 == null) {
return@Comparator -1
}
if (o2 == null) {
return@Comparator 1
}
val diff = o1.length() - o2.length()
if (diff > 0) {
1
} else if (diff < 0) {
-1
} else {
0
}
})
}
else -> {}
}
}
/** /**
* 清除选中目录 * 清除选中目录
@ -131,22 +66,22 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
} }
companion object { // /**
/** // *
* 转换后符号将id数组转换为字符串数组 // * @param isDescend Boolean
* // */
* @param context 上下文环境 // fun sortData(isDescend : Boolean){
* @param ints 数组 // dataList.sortByDescending {
* @return 数据数组 //
*/ // }
fun conversionSymbol(context: Context, ints: IntArray): Array<String> { // }
val list: MutableList<String> = ArrayList()
for (r in ints) { override fun setNewDataList(dataList: MutableList<File?>) {
val s = context.getText(r).toString() dataList.sortBy {
list.add(s) val name = it?.name ?: "#"
} getInitial(name)
return list.toTypedArray()
} }
super.setNewDataList(dataList)
} }
override fun getViewBindingObject( override fun getViewBindingObject(
@ -160,7 +95,7 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
override fun onBingView( override fun onBingView(
data: File?, data: File?,
viewBinding: FileItemBinding, viewBinding: FileItemBinding,
viewviewBinding: BaseAdapter.ViewHolder<FileItemBinding>, viewHolder: BaseAdapter.ViewHolder<FileItemBinding>,
position: Int position: Int
) { ) {
if (data == null) { if (data == null) {
@ -171,22 +106,11 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
} else { } else {
viewBinding.more.isVisible = true viewBinding.more.isVisible = true
viewBinding.fileName.text = data.name viewBinding.fileName.text = data.name
val update_time = data.lastModified()
val timeStringBuilder = StringBuilder()
val formatter = SimpleDateFormat("yyyy-MM-dd HH:mm:ss")
timeStringBuilder.append(formatter.format(update_time))
if (data.isDirectory) { if (data.isDirectory) {
val tem = data.listFiles() val tem = data.listFiles()
if (tem != null) { if (tem != null) {
val fileNum = data.listFiles().size val fileNum = data.listFiles().size
if (fileNum > 0) { if (fileNum > 0) {
timeStringBuilder.append(" ")
timeStringBuilder.append(
String.format(
(context.getText(R.string.filenum) as String),
fileNum
)
)
viewBinding.fileIcon.setImageDrawable( viewBinding.fileIcon.setImageDrawable(
GlobalMethod.tintDrawable( GlobalMethod.tintDrawable(
context.getDrawable( context.getDrawable(
@ -233,4 +157,11 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
} }
} }
} }
override fun getPopupText(position: Int): String {
val file = dataList[position]
val name = file?.name ?: "#"
return getInitial(name).toString()
}
} }

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, val dataList: MutableList<FunctionInfo>) : class FunAdapter(val 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

@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.ModListItemBinding
/*模组适配器 /*模组适配器
* 此适配器只能使用于ModFragment成员变量按需传递 * 此适配器只能使用于ModFragment成员变量按需传递
* */ * */
class ModAdapter(private val context: Context, var dataList: MutableList<ModClass>) : class ModAdapter(private val context: Context, dataList: MutableList<ModClass>) :
BaseAdapter<ModListItemBinding, ModClass>(context, dataList) { BaseAdapter<ModListItemBinding, ModClass>(context, dataList) {
init { init {

View File

@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod
* @author Cold Mint * @author Cold Mint
* @date 2021/12/19 20:32 * @date 2021/12/19 20:32
*/ */
class PlanAdapter(context: Context, val dataList: MutableList<PlanDataBean.Data>) : class PlanAdapter(context: Context, dataList: MutableList<PlanDataBean.Data>) :
BaseAdapter<ItemPlanBinding, PlanDataBean.Data>(context, dataList) { BaseAdapter<ItemPlanBinding, PlanDataBean.Data>(context, dataList) {
private val money: String = context.getString(R.string.money) private val money: String = context.getString(R.string.money)

View File

@ -28,7 +28,7 @@ import java.lang.StringBuilder
*/ */
class ReportAdapter( class ReportAdapter(
val context: Context, val context: Context,
val dataList: MutableList<ReportItemDataBean.Data> dataList: MutableList<ReportItemDataBean.Data>
) : ) :
BaseAdapter<ItemReportBinding, ReportItemDataBean.Data>(context, dataList) { BaseAdapter<ItemReportBinding, ReportItemDataBean.Data>(context, dataList) {
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/11/20 18:38 * @date 2021/11/20 18:38
*/ */
class ScreenshotAdapter(val context: Context, val dataList: ArrayList<String>) : class ScreenshotAdapter(val context: Context, dataList: ArrayList<String>) :
BaseAdapter<ScreenshotItemBinding, String>(context, dataList) { BaseAdapter<ScreenshotItemBinding, String>(context, dataList) {

View File

@ -11,7 +11,7 @@ import com.coldmint.rust.pro.databinding.ModActionItemBinding
* @property mutableList MutableList<String> * @property mutableList MutableList<String>
* @constructor * @constructor
*/ */
class TemplateActionAdapter(context: Context, val dataList: MutableList<String>) : class TemplateActionAdapter(context: Context, dataList: MutableList<String>) :
BaseAdapter<ModActionItemBinding, String>(context, dataList) { BaseAdapter<ModActionItemBinding, String>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(
@ -29,8 +29,5 @@ class TemplateActionAdapter(context: Context, val dataList: MutableList<String>)
position: Int position: Int
) { ) {
viewBinding.operation.text = data viewBinding.operation.text = data
// holder.modActionItemBinding.root.setOnClickListener {
// actionListener?.onClickItem(string)
// }
} }
} }

View File

@ -26,7 +26,7 @@ import java.io.File
class TemplateListAdapter( class TemplateListAdapter(
val context: Context, val context: Context,
val dataList: ArrayList<TemplatePackage>, dataList: ArrayList<TemplatePackage>,
private val language: String, private val language: String,
private val rootPath: String private val rootPath: String
) : BaseAdapter<TemplateListItemBinding, TemplatePackage>(context, dataList) { ) : BaseAdapter<TemplateListItemBinding, TemplatePackage>(context, dataList) {

View File

@ -30,7 +30,7 @@ import java.util.ArrayList
//模板制作适配器 //模板制作适配器
class TemplateMakerAdapter(val context: Context, private val dataList: MutableList<CodeData>) : class TemplateMakerAdapter(val 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

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

View File

@ -13,7 +13,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import java.lang.StringBuilder import java.lang.StringBuilder
import java.util.ArrayList import java.util.ArrayList
class ValueAdapter(context: Context, var dataList: ArrayList<ValueTypeDataBean>) : class ValueAdapter(context: Context, dataList: ArrayList<ValueTypeDataBean>) :
BaseAdapter<ValueItemBinding, ValueTypeDataBean>(context, dataList) { BaseAdapter<ValueItemBinding, ValueTypeDataBean>(context, dataList) {
override fun getViewBindingObject( override fun getViewBindingObject(

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, val dataList: MutableList<WebModListData.Data>) : class WebModAdapter(val 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

@ -3,11 +3,8 @@ package com.coldmint.rust.pro.base
import android.content.Context import android.content.Context
import android.graphics.Color import android.graphics.Color
import android.graphics.Typeface import android.graphics.Typeface
import android.icu.text.CaseMap
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.renderscript.Element
import android.text.SpannableString
import android.text.SpannableStringBuilder import android.text.SpannableStringBuilder
import android.text.Spanned import android.text.Spanned
import android.view.LayoutInflater import android.view.LayoutInflater
@ -15,20 +12,17 @@ import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding import androidx.viewbinding.ViewBinding
import com.coldmint.rust.pro.R import com.coldmint.rust.pro.R
import com.coldmint.rust.pro.databinding.ActivityWebModInfoBinding
import com.coldmint.rust.pro.interfaces.ItemChangeEvent import com.coldmint.rust.pro.interfaces.ItemChangeEvent
import com.coldmint.rust.pro.interfaces.ItemEvent import com.coldmint.rust.pro.interfaces.ItemEvent
import android.text.style.ForegroundColorSpan import android.text.style.ForegroundColorSpan
import android.text.style.StyleSpan import android.text.style.StyleSpan
import androidx.appcompat.app.AlertDialog
import androidx.core.text.toSpannable
import com.coldmint.dialog.CoreDialog import com.coldmint.dialog.CoreDialog
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.github.promeg.pinyinhelper.Pinyin
abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>( abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
private val context: Context, private val context: Context,
private var dataList: MutableList<DataType> protected var dataList: MutableList<DataType>
) : ) :
RecyclerView.Adapter<BaseAdapter.ViewHolder<ViewBindingType>>() { RecyclerView.Adapter<BaseAdapter.ViewHolder<ViewBindingType>>() {
private val layoutInflater: LayoutInflater = LayoutInflater.from(context) private val layoutInflater: LayoutInflater = LayoutInflater.from(context)
@ -42,6 +36,23 @@ abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
private val bold = StyleSpan(Typeface.BOLD) private val bold = StyleSpan(Typeface.BOLD)
/**
* 获取列表项目的首字母
*/
fun getInitial(string: String): Char {
return if (string.isBlank()) {
'#'
} else {
val char = string[0]
if (Pinyin.isChinese(char)) {
val pinyin = Pinyin.toPinyin(char)
pinyin[0].uppercaseChar()
} else {
char.uppercaseChar()
}
}
}
/** /**
* 建立搜索标题注意当[BaseAdapter.keyWord]为空时永远返回null * 建立搜索标题注意当[BaseAdapter.keyWord]为空时永远返回null
* @param title String 标题 * @param title String 标题
@ -78,11 +89,22 @@ abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
} }
/** /**
* 设置数据列表 * 设置数据列表(会刷新列表代价很大)
* @param dataList MutableList<DataType> * @param dataList MutableList<DataType>
*/ */
fun setNewDataList(dataList: MutableList<DataType>) { open fun setNewDataList(dataList: MutableList<DataType>) {
this.dataList = dataList this.dataList = dataList
handler.post {
notifyDataSetChanged()
}
}
/**
* 获取列表项目数据
* @return MutableList<DataType>
*/
fun getItemData(index: Int): DataType {
return dataList[index]
} }
/** /**
@ -171,32 +193,6 @@ abstract class BaseAdapter<ViewBindingType : ViewBinding, DataType>(
} }
} }
}.show() }.show()
// var checked = false
// val dialog = MaterialAlertDialogBuilder(context)
// if (checkBoxPrompt != null) {
// dialog.checkBoxPrompt(text = checkBoxPrompt, onToggle = {
// checked = it
// })
// }
// dialog.title(R.string.delete_title).message(
// text = String.format(
// context.getString(R.string.delete_prompt),
// name
// )
// ).positiveButton(R.string.dialog_ok).positiveButton {
// if (onClickPositiveButton == null) {
// removeItem(index)
// } else {
// if (onClickPositiveButton.invoke(dialog, checked)) {
// removeItem(index)
// }
// }
// }.negativeButton(R.string.dialog_cancel).cancelable(cancelable)
// handler.post {
// dialog.show()
// }
// return dialog
} }
/** /**

View File

@ -25,13 +25,21 @@ class FileManagerViewModel : BaseViewModel() {
private var rootPath: String = directs private var rootPath: String = directs
/** /**
* 当前打开的目录 * 当前打开的目录(获取目录的话请使用[FileManagerViewModel.getCurrentPath]方法])
*/ */
val currentPathLiveData: MutableLiveData<String> by lazy { val currentPathLiveData: MutableLiveData<String> by lazy {
MutableLiveData(rootPath) MutableLiveData(rootPath)
} }
/**
* 获取当前打开的目录
* @return String
*/
fun getCurrentPath(): String {
return currentPathLiveData.value ?: rootPath
}
/** /**
* 加载状态 * 加载状态
*/ */
@ -58,7 +66,7 @@ class FileManagerViewModel : BaseViewModel() {
/** /**
* 加载文件列表 * 加载文件列表
* @param path String * @param path String 默认加载根目录
*/ */
fun loadFiles(path: String = rootPath) { fun loadFiles(path: String = rootPath) {
viewModelScope.launch { viewModelScope.launch {

View File

@ -4,5 +4,5 @@
# Location of the SDK. This is only used by Gradle. # Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the # For customization when using a Version Control System, please read the
# header note. # header note.
#Tue Jul 19 19:07:29 CST 2022 #Tue Jul 19 20:26:21 CST 2022
sdk.dir=D\:\\Android_SDK sdk.dir=D\:\\Document\\AndroidSdk