diff --git a/.gradle/7.3.3/checksums/checksums.lock b/.gradle/7.3.3/checksums/checksums.lock index 242edbd..7f2e6ba 100644 Binary files a/.gradle/7.3.3/checksums/checksums.lock and b/.gradle/7.3.3/checksums/checksums.lock differ diff --git a/.gradle/7.3.3/checksums/md5-checksums.bin b/.gradle/7.3.3/checksums/md5-checksums.bin index 409d3f2..169bdcb 100644 Binary files a/.gradle/7.3.3/checksums/md5-checksums.bin and b/.gradle/7.3.3/checksums/md5-checksums.bin differ diff --git a/.gradle/7.3.3/checksums/sha1-checksums.bin b/.gradle/7.3.3/checksums/sha1-checksums.bin index 62e778b..c6fbaf2 100644 Binary files a/.gradle/7.3.3/checksums/sha1-checksums.bin and b/.gradle/7.3.3/checksums/sha1-checksums.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.bin b/.gradle/7.3.3/executionHistory/executionHistory.bin index e665853..e9c5ca5 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.bin and b/.gradle/7.3.3/executionHistory/executionHistory.bin differ diff --git a/.gradle/7.3.3/executionHistory/executionHistory.lock b/.gradle/7.3.3/executionHistory/executionHistory.lock index 04d8594..9ba13d1 100644 Binary files a/.gradle/7.3.3/executionHistory/executionHistory.lock and b/.gradle/7.3.3/executionHistory/executionHistory.lock differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.bin b/.gradle/7.3.3/fileHashes/fileHashes.bin index ca71ee2..8da7b66 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.bin and b/.gradle/7.3.3/fileHashes/fileHashes.bin differ diff --git a/.gradle/7.3.3/fileHashes/fileHashes.lock b/.gradle/7.3.3/fileHashes/fileHashes.lock index 33bd0af..9a2646c 100644 Binary files a/.gradle/7.3.3/fileHashes/fileHashes.lock and b/.gradle/7.3.3/fileHashes/fileHashes.lock differ diff --git a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin index 16404f4..f94c399 100644 Binary files a/.gradle/7.3.3/fileHashes/resourceHashesCache.bin and b/.gradle/7.3.3/fileHashes/resourceHashesCache.bin differ diff --git a/.gradle/buildOutputCleanup/buildOutputCleanup.lock b/.gradle/buildOutputCleanup/buildOutputCleanup.lock index 6908c66..709aa33 100644 Binary files a/.gradle/buildOutputCleanup/buildOutputCleanup.lock and b/.gradle/buildOutputCleanup/buildOutputCleanup.lock differ diff --git a/.gradle/buildOutputCleanup/outputFiles.bin b/.gradle/buildOutputCleanup/outputFiles.bin index a3e1bd1..0bffaad 100644 Binary files a/.gradle/buildOutputCleanup/outputFiles.bin and b/.gradle/buildOutputCleanup/outputFiles.bin differ diff --git a/.gradle/file-system.probe b/.gradle/file-system.probe index 149c0c7..b319919 100644 Binary files a/.gradle/file-system.probe and b/.gradle/file-system.probe differ diff --git a/app/build.gradle b/app/build.gradle index 7131c76..c77daee 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -68,6 +68,7 @@ android { dependencies { + implementation 'me.zhanghai.android.fastscroll:library:1.1.8' // 语种切换框架:https://github.com/getActivity/MultiLanguages implementation 'com.github.getActivity:MultiLanguages:8.0' //权限申请 diff --git a/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt b/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt index b91e0b3..901fa0c 100644 --- a/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/ActivateActivity.kt @@ -122,7 +122,7 @@ class ActivateActivity : BaseActivity() { finalPlanAdapter.setCoupon(null) finalPlanAdapter.setCoupon(data) selectItemAndLoadInfo( - finalPlanAdapter.dataList[0], + finalPlanAdapter.getItemData(0), finalPlanAdapter, 0 ) @@ -138,7 +138,7 @@ class ActivateActivity : BaseActivity() { viewBinding.couponDescribeView.text = getString(R.string.coupon_not_use) selectItemAndLoadInfo( - finalPlanAdapter.dataList[0], + finalPlanAdapter.getItemData(0), finalPlanAdapter, 0 ) diff --git a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt index 1d5d704..aaa4a77 100644 --- a/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/FileManagerActivity.kt @@ -29,6 +29,7 @@ import com.coldmint.rust.pro.databinding.ActivityFileBinding import com.coldmint.rust.pro.interfaces.BookmarkListener import com.coldmint.rust.pro.viewmodel.FileManagerViewModel import com.google.android.material.dialog.MaterialAlertDialogBuilder +import me.zhanghai.android.fastscroll.FastScrollerBuilder import java.io.File import java.lang.Exception import java.util.* @@ -878,6 +879,7 @@ class FileManagerActivity : BaseActivity() { // initAction() // } // } + private lateinit var menuBinding: MenuBinding private val viewModel: FileManagerViewModel by lazy { ViewModelProvider(this).get(FileManagerViewModel::class.java) } @@ -890,6 +892,12 @@ class FileManagerActivity : BaseActivity() { viewBinding.recyclerView.layoutManager = LinearLayoutManager(this@FileManagerActivity) loadTitle() loadObserve() + FastScrollerBuilder(viewBinding.recyclerView).useMd2Style() + .setPopupTextProvider(adapter).build() + viewBinding.swipeRefreshLayout.setOnRefreshListener { + viewModel.loadFiles(viewModel.getCurrentPath()) + viewBinding.swipeRefreshLayout.isRefreshing = false + } viewModel.loadFiles() } else { val bundle = intent.getBundleExtra("data") @@ -907,6 +915,11 @@ class FileManagerActivity : BaseActivity() { } } + override fun onCreateOptionsMenu(menu: Menu): Boolean { + menuBinding = MenuBinding.inflate(menu, menuInflater) + return true + } + /** * 加载观察者 */ @@ -926,7 +939,6 @@ class FileManagerActivity : BaseActivity() { if (file == null) { viewModel.returnDirects() } else { - Toast.makeText(this,file.absolutePath,Toast.LENGTH_SHORT).show() if (file.isDirectory) { viewModel.currentPathLiveData.value = file.absolutePath } else { @@ -940,7 +952,7 @@ class FileManagerActivity : BaseActivity() { adapter?.setNewDataList(it) } } - viewModel.currentPathLiveData.observe(this){ + viewModel.currentPathLiveData.observe(this) { viewModel.loadFiles(it) } } @@ -962,4 +974,25 @@ class FileManagerActivity : BaseActivity() { override fun getViewBindingObject(): ActivityFileBinding { 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) + ) + } + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt b/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt index fd0857c..5864214 100644 --- a/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt +++ b/app/src/main/java/com/coldmint/rust/pro/RecyclingStationActivity.kt @@ -63,7 +63,6 @@ class RecyclingStationActivity : BaseActivity() } if (fileArrayList.size > 0) { val fileAdapter = FileAdapter(this@RecyclingStationActivity, fileArrayList) - fileAdapter.setSortType(FileAdapter.SortType.ModifyDate) fileAdapter.setItemEvent { i, fileItemBinding, viewHolder, file -> fileItemBinding.more.setOnClickListener { if (file == null) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt index 2ffabe0..99ea8b0 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/BookmarkAdapter.kt @@ -7,7 +7,7 @@ import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databean.Bookmark import com.coldmint.rust.pro.databinding.AttachFileItemBinding -class BookmarkAdapter(val context: Context, var dataList: MutableList) : +class BookmarkAdapter(val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { /** diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt index 504c55e..f7a9aa2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CommentAdapter.kt @@ -18,7 +18,7 @@ import com.coldmint.rust.pro.tool.TextStyleMaker * @author Cold Mint * @date 2021/12/12 20:50 */ -class CommentAdapter(val context: Context, val dataList: MutableList) : +class CommentAdapter(val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityServiceAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityServiceAdapter.kt index 581ce8b..d6690c7 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityServiceAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/CommunityServiceAdapter.kt @@ -14,7 +14,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod */ class CommunityServiceAdapter( val context: Context, - val dataList: MutableList + dataList: MutableList ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt index f3d0a85..821f782 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FileAdapter.kt @@ -14,14 +14,16 @@ import com.bumptech.glide.Glide import com.coldmint.rust.core.tool.FileOperator import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.FileItemBinding +import com.github.promeg.pinyinhelper.Pinyin import com.google.android.material.dialog.MaterialAlertDialogBuilder +import me.zhanghai.android.fastscroll.PopupTextProvider import java.io.File import java.lang.StringBuilder import java.text.SimpleDateFormat import java.util.ArrayList -class FileAdapter(private val context: Context, private var dataList: MutableList) : - BaseAdapter(context, dataList) { +class FileAdapter(private val context: Context, dataList: MutableList) : + BaseAdapter(context, dataList), PopupTextProvider { /** * 获取选中目录 @@ -39,73 +41,6 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis var isCopyFile = false 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 { 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 { 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 { 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 context 上下文环境 - * @param ints 数组 - * @return 数据数组 - */ - fun conversionSymbol(context: Context, ints: IntArray): Array { - val list: MutableList = ArrayList() - for (r in ints) { - val s = context.getText(r).toString() - list.add(s) - } - return list.toTypedArray() +// /** +// * +// * @param isDescend Boolean +// */ +// fun sortData(isDescend : Boolean){ +// dataList.sortByDescending { +// +// } +// } + + override fun setNewDataList(dataList: MutableList) { + dataList.sortBy { + val name = it?.name ?: "#" + getInitial(name) } + super.setNewDataList(dataList) } override fun getViewBindingObject( @@ -160,7 +95,7 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis override fun onBingView( data: File?, viewBinding: FileItemBinding, - viewviewBinding: BaseAdapter.ViewHolder, + viewHolder: BaseAdapter.ViewHolder, position: Int ) { if (data == null) { @@ -171,22 +106,11 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis } else { viewBinding.more.isVisible = true 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) { val tem = data.listFiles() if (tem != null) { val fileNum = data.listFiles().size if (fileNum > 0) { - timeStringBuilder.append(" ") - timeStringBuilder.append( - String.format( - (context.getText(R.string.filenum) as String), - fileNum - ) - ) viewBinding.fileIcon.setImageDrawable( GlobalMethod.tintDrawable( 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() + } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt index 582b14f..de03a6d 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/FunAdapter.kt @@ -9,7 +9,7 @@ import com.coldmint.rust.pro.databean.FunctionInfo import com.coldmint.rust.pro.databinding.ItemFunBinding import com.coldmint.rust.pro.databinding.ItemServiceBinding -class FunAdapter(val context: Context, val dataList: MutableList) : +class FunAdapter(val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( layoutInflater: LayoutInflater, diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt index f085a2a..b53cb7a 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ModAdapter.kt @@ -15,7 +15,7 @@ import com.coldmint.rust.pro.databinding.ModListItemBinding /*模组适配器 * 此适配器只能使用于ModFragment成员变量按需传递。 * */ -class ModAdapter(private val context: Context, var dataList: MutableList) : +class ModAdapter(private val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { init { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/PlanAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/PlanAdapter.kt index f20e65c..861f49f 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/PlanAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/PlanAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2021/12/19 20:32 */ -class PlanAdapter(context: Context, val dataList: MutableList) : +class PlanAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { private val money: String = context.getString(R.string.money) diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt index ef9a00b..8a275cd 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ReportAdapter.kt @@ -28,7 +28,7 @@ import java.lang.StringBuilder */ class ReportAdapter( val context: Context, - val dataList: MutableList + dataList: MutableList ) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt index b170ac9..19b49ea 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ScreenshotAdapter.kt @@ -16,7 +16,7 @@ import com.coldmint.rust.pro.tool.GlobalMethod * @author Cold Mint * @date 2021/11/20 18:38 */ -class ScreenshotAdapter(val context: Context, val dataList: ArrayList) : +class ScreenshotAdapter(val context: Context, dataList: ArrayList) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateActionAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateActionAdapter.kt index c595659..ea8ce52 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateActionAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateActionAdapter.kt @@ -11,7 +11,7 @@ import com.coldmint.rust.pro.databinding.ModActionItemBinding * @property mutableList MutableList * @constructor */ -class TemplateActionAdapter(context: Context, val dataList: MutableList) : +class TemplateActionAdapter(context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( @@ -29,8 +29,5 @@ class TemplateActionAdapter(context: Context, val dataList: MutableList) position: Int ) { viewBinding.operation.text = data -// holder.modActionItemBinding.root.setOnClickListener { -// actionListener?.onClickItem(string) -// } } } \ No newline at end of file diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt index 4ce875f..9a058c9 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateListAdapter.kt @@ -26,7 +26,7 @@ import java.io.File class TemplateListAdapter( val context: Context, - val dataList: ArrayList, + dataList: ArrayList, private val language: String, private val rootPath: String ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt index 4b87a8a..8ff6dd2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/TemplateMakerAdapter.kt @@ -30,7 +30,7 @@ import java.util.ArrayList //模板制作适配器 -class TemplateMakerAdapter(val context: Context, private val dataList: MutableList) : +class TemplateMakerAdapter(val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { private var tags = ArrayList() diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt index c8a073d..5037baf 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/UnitAdapter.kt @@ -19,7 +19,7 @@ import kotlin.Exception class UnitAdapter( private val context: Context, - private val dataList: MutableList, + dataList: MutableList, val key: String ) : BaseAdapter(context, dataList) { diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/ValueAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/ValueAdapter.kt index 8e10c15..516c295 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/ValueAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/ValueAdapter.kt @@ -13,7 +13,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import java.lang.StringBuilder import java.util.ArrayList -class ValueAdapter(context: Context, var dataList: ArrayList) : +class ValueAdapter(context: Context, dataList: ArrayList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt index 76ff0b4..01830ef 100644 --- a/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/adapters/WebModAdapter.kt @@ -12,7 +12,7 @@ import com.coldmint.rust.pro.base.BaseAdapter import com.coldmint.rust.pro.databinding.WebModItemBinding import com.coldmint.rust.pro.tool.GlobalMethod -class WebModAdapter(val context: Context, val dataList: MutableList) : +class WebModAdapter(val context: Context, dataList: MutableList) : BaseAdapter(context, dataList) { override fun getViewBindingObject( diff --git a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt index f9f9e0f..bad30d1 100644 --- a/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt +++ b/app/src/main/java/com/coldmint/rust/pro/base/BaseAdapter.kt @@ -3,11 +3,8 @@ package com.coldmint.rust.pro.base import android.content.Context import android.graphics.Color import android.graphics.Typeface -import android.icu.text.CaseMap import android.os.Handler import android.os.Looper -import android.renderscript.Element -import android.text.SpannableString import android.text.SpannableStringBuilder import android.text.Spanned import android.view.LayoutInflater @@ -15,20 +12,17 @@ import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import androidx.viewbinding.ViewBinding 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.ItemEvent import android.text.style.ForegroundColorSpan import android.text.style.StyleSpan -import androidx.appcompat.app.AlertDialog -import androidx.core.text.toSpannable import com.coldmint.dialog.CoreDialog -import com.google.android.material.dialog.MaterialAlertDialogBuilder +import com.github.promeg.pinyinhelper.Pinyin abstract class BaseAdapter( private val context: Context, - private var dataList: MutableList + protected var dataList: MutableList ) : RecyclerView.Adapter>() { private val layoutInflater: LayoutInflater = LayoutInflater.from(context) @@ -42,6 +36,23 @@ abstract class BaseAdapter( 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 * @param title String 标题 @@ -78,11 +89,22 @@ abstract class BaseAdapter( } /** - * 设置数据列表 + * 设置数据列表(会刷新列表代价很大) * @param dataList MutableList */ - fun setNewDataList(dataList: MutableList) { + open fun setNewDataList(dataList: MutableList) { this.dataList = dataList + handler.post { + notifyDataSetChanged() + } + } + + /** + * 获取列表项目数据 + * @return MutableList + */ + fun getItemData(index: Int): DataType { + return dataList[index] } /** @@ -171,32 +193,6 @@ abstract class BaseAdapter( } } }.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 } /** diff --git a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt index 2b0a19a..93380e2 100644 --- a/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt +++ b/app/src/main/java/com/coldmint/rust/pro/viewmodel/FileManagerViewModel.kt @@ -25,13 +25,21 @@ class FileManagerViewModel : BaseViewModel() { private var rootPath: String = directs /** - * 当前打开的目录 + * 当前打开的目录(获取目录的话,请使用[FileManagerViewModel.getCurrentPath]方法]) */ val currentPathLiveData: MutableLiveData by lazy { 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) { viewModelScope.launch { diff --git a/local.properties b/local.properties index 88610fe..b137a96 100644 --- a/local.properties +++ b/local.properties @@ -4,5 +4,5 @@ # Location of the SDK. This is only used by Gradle. # For customization when using a Version Control System, please read the # header note. -#Tue Jul 19 19:07:29 CST 2022 -sdk.dir=D\:\\Android_SDK +#Tue Jul 19 20:26:21 CST 2022 +sdk.dir=D\:\\Document\\AndroidSdk