文件管理器升级

This commit is contained in:
coldmint 2022-07-19 07:59:32 +08:00
parent 1ff0aae33b
commit ed85d46f01
19 changed files with 1068 additions and 850 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ 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.google.android.material.dialog.MaterialAlertDialogBuilder
import java.io.File
import java.lang.StringBuilder
import java.text.SimpleDateFormat
@ -167,7 +168,6 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
viewBinding.fileIcon.setImageDrawable(drawable)
viewBinding.fileName.setText(R.string.return_directents)
viewBinding.more.isVisible = false
viewBinding.fileTime.isVisible = false
} else {
viewBinding.more.isVisible = true
viewBinding.fileName.text = data.name
@ -219,16 +219,17 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
ColorStateList.valueOf(GlobalMethod.getColorPrimary(context))
)
)
"png", "jpg", "bmp" -> Glide.with(context).load(data).apply(GlobalMethod.getRequestOptions()).into(viewBinding.fileIcon)
"png", "jpg", "bmp" -> Glide.with(context).load(data)
.apply(GlobalMethod.getRequestOptions()).into(viewBinding.fileIcon)
else -> {
viewBinding.fileIcon.setImageDrawable(context.getDrawable(R.drawable.file))
}
}
}
viewBinding.fileTime.text = timeStringBuilder.toString()
if (selectPath != null && data.absolutePath == selectPath) {
viewBinding.fileName.setTextColor(Color.GREEN)
viewBinding.fileTime.setTextColor(Color.GREEN)
viewBinding.fileName.setTextColor(
ColorStateList.valueOf(GlobalMethod.getColorPrimary(context))
)
}
}
}

View File

@ -156,7 +156,6 @@ object GlobalMethod {
* @param resId 资源id
* @return 成功返回值失败返回-1
*/
@Deprecated("废弃")
fun getThemeColor(context: Context, resId: Int): Int {
val typedValue = TypedValue()
return if (context.theme.resolveAttribute(resId, typedValue, true)) {
@ -172,7 +171,6 @@ object GlobalMethod {
* @param context 上下文环境
* @return 整数
*/
@Deprecated("废弃")
fun getColorPrimary(context: Context): Int {
return getThemeColor(context, R.attr.colorPrimary)
}

View File

@ -0,0 +1,92 @@
package com.coldmint.rust.pro.viewmodel
import android.os.Environment
import android.util.Log
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.coldmint.rust.core.tool.FileOperator
import com.coldmint.rust.pro.base.BaseViewModel
import kotlinx.coroutines.launch
import java.io.File
class FileManagerViewModel : BaseViewModel() {
/**
* 启动模式枚举类
* 默认选择目录导出文件选择文件
*/
enum class StartType {
DEFAULT, SELECT_DIRECTORY, EXPORT_FILE, SELECT_FILE
}
private var directs = Environment.getExternalStorageDirectory().absolutePath
//根目录
private var rootPath: String = directs
/**
* 当前打开的目录
*/
val currentPathLiveData: MutableLiveData<String> by lazy {
MutableLiveData(rootPath)
}
/**
* 加载状态
*/
val loadStateLiveData: MutableLiveData<Boolean> by lazy {
MutableLiveData(true)
}
/**
* 文件列表数据
*/
val fileListLiveData: MutableLiveData<MutableList<File?>> by lazy {
MutableLiveData()
}
var startTypeData: StartType = StartType.DEFAULT
/**
* 设置根目录
* @param path String?
*/
fun setRootPath(path: String?) {
rootPath = path ?: directs
}
/**
* 加载文件列表
* @param path String
*/
fun loadFiles(path: String = rootPath) {
viewModelScope.launch {
loadStateLiveData.value = true
val folder = File(path)
if (!folder.exists()) {
return@launch
}
val arrayList = ArrayList<File?>()
Log.d("文件管理器", "当前路径" + path + "根路径" + rootPath + "添加返回" + (path != rootPath))
if (path != rootPath) {
//如果不是根目录添加返回
arrayList.add(null)
}
folder.listFiles()?.forEach {
arrayList.add(it)
}
fileListLiveData.value = arrayList
loadStateLiveData.value = false
}
}
/**
* 返回上级目录
*/
fun returnDirects() {
currentPathLiveData.value =
FileOperator.getSuperDirectory(currentPathLiveData.value ?: rootPath, rootPath)
}
}

View File

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@android:color/white"
android:pathData="M3,18h6v-2L3,16v2zM3,6v2h18L21,6L3,6zM3,13h12v-2L3,11v2z" />
</vector>

View File

@ -26,11 +26,19 @@
android:orientation="vertical"
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/fileList"
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
android:layout_height="wrap_content">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
<ProgressBar
android:id="@+id/progressBar"
@ -40,10 +48,12 @@
<TextView
android:id="@+id/fileError"
style="@style/TextAppearance.Material3.BodyMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/loading_files" />
android:text="@string/loading_files"
android:visibility="gone" />
</LinearLayout>

View File

@ -4,22 +4,23 @@
android:layout_height="wrap_content">
<ImageView
android:padding="5dp"
android:id="@+id/file_icon"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentLeft="true"
android:layout_width="56dp"
android:layout_height="56dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_marginLeft="8dp"
android:layout_marginStart="8dp"
android:padding="5dp"
android:src="@drawable/file" />
<LinearLayout
android:layout_marginStart="16dp"
android:id="@+id/contentView"
android:layout_centerVertical="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/file_icon"
android:layout_toLeftOf="@id/more"
android:layout_toEndOf="@id/file_icon"
android:layout_toStartOf="@id/more"
android:orientation="vertical">
<TextView
@ -27,15 +28,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="文件名"
android:textSize="16dp" />
<TextView
android:id="@+id/file_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:text="创建时间"
android:textSize="14dp" />
style="@style/TextAppearance.Material3.TitleMedium" />
</LinearLayout>
@ -46,6 +39,6 @@
android:layout_height="48dp"
android:padding="12dp"
android:src="@drawable/more"
android:layout_alignParentRight="true"/>
android:layout_alignParentEnd="true"/>
</RelativeLayout>

View File

@ -11,23 +11,24 @@
<TextView
android:id="@+id/titleView"
style="@style/TextAppearance.Material3.TitleMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/mod_title"
android:textColor="@color/black"
android:textSize="14sp" />
android:textColor="@color/black" />
<TextView
android:id="@+id/priceView"
style="@style/TextAppearance.Material3.TitleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="@string/money"
android:textColor="?colorPrimary"
android:textSize="16sp" />
android:textColor="?colorPrimary" />
<TextView
style="@style/TextAppearance.Material3.BodyMedium"
android:id="@+id/originalPriceView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -1,5 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_soft"
android:icon="@drawable/ic_outline_sort_24"
android:title="@string/soft"
app:showAsAction="always">
<menu>
<group android:checkableBehavior="single">
<item
android:id="@+id/action_sort_by_name"
android:title="@string/file_list_action_sort_by_name" />
<item
android:id="@+id/action_sort_by_type"
android:title="@string/file_list_action_sort_by_type" />
<item
android:id="@+id/action_sort_by_size"
android:title="@string/file_list_action_sort_by_size" />
<item
android:id="@+id/action_sort_by_last_modified"
android:title="@string/file_list_action_sort_by_last_modified" />
</group>
</menu>
</item>
<item
android:id="@+id/reloadFile"
android:title="@string/reload_files" />

View File

@ -849,7 +849,12 @@
<string name="search_type_purchase_plan">套餐</string>
<string name="search_type_mod_all">全部</string>
<string name="hotSearch">热门搜索</string>
<!-- <string name="search_suggestions_null">无搜索建议。</string>-->
<string name="soft">排序</string>
<string name="file_list_action_sort_by_name">名称</string>
<string name="file_list_action_sort_by_type">类型</string>
<string name="file_list_action_sort_by_size">大小</string>
<string name="file_list_action_sort_by_last_modified">修改时间</string>
<!-- <string name="search_suggestions_null">无搜索建议。</string>-->
<!-- <string name="search_suggestions_number">共%1$d个搜索建议。</string>-->
</resources>

View File

@ -4,10 +4,8 @@ import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.widget.Toast
import com.coldmint.rust.core.R
import kotlin.Throws
import androidx.documentfile.provider.DocumentFile
import android.os.Environment
import android.provider.MediaStore
import androidx.core.content.FileProvider
@ -563,16 +561,15 @@ object FileOperator {
}
/*获取文件上级目录*/
fun getSuperDirectory(file: File, root: File): String {
val path = file.absolutePath
return if (path == root.absolutePath) {
path
fun getSuperDirectory(filePath: String, rootPath: String): String {
return if (filePath == rootPath) {
filePath
} else {
val endNum = path.lastIndexOf("/")
val endNum = filePath.lastIndexOf("/")
if (endNum > 0) {
path.substring(0, endNum)
filePath.substring(0, endNum)
} else {
path
filePath
}
}
}