文件管理器升级
This commit is contained in:
parent
1ff0aae33b
commit
ed85d46f01
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -14,6 +14,7 @@ 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.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.lang.StringBuilder
|
import java.lang.StringBuilder
|
||||||
import java.text.SimpleDateFormat
|
import java.text.SimpleDateFormat
|
||||||
|
@ -167,7 +168,6 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
|
||||||
viewBinding.fileIcon.setImageDrawable(drawable)
|
viewBinding.fileIcon.setImageDrawable(drawable)
|
||||||
viewBinding.fileName.setText(R.string.return_directents)
|
viewBinding.fileName.setText(R.string.return_directents)
|
||||||
viewBinding.more.isVisible = false
|
viewBinding.more.isVisible = false
|
||||||
viewBinding.fileTime.isVisible = false
|
|
||||||
} else {
|
} else {
|
||||||
viewBinding.more.isVisible = true
|
viewBinding.more.isVisible = true
|
||||||
viewBinding.fileName.text = data.name
|
viewBinding.fileName.text = data.name
|
||||||
|
@ -219,16 +219,17 @@ class FileAdapter(private val context: Context, private var dataList: MutableLis
|
||||||
ColorStateList.valueOf(GlobalMethod.getColorPrimary(context))
|
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 -> {
|
else -> {
|
||||||
viewBinding.fileIcon.setImageDrawable(context.getDrawable(R.drawable.file))
|
viewBinding.fileIcon.setImageDrawable(context.getDrawable(R.drawable.file))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
viewBinding.fileTime.text = timeStringBuilder.toString()
|
|
||||||
if (selectPath != null && data.absolutePath == selectPath) {
|
if (selectPath != null && data.absolutePath == selectPath) {
|
||||||
viewBinding.fileName.setTextColor(Color.GREEN)
|
viewBinding.fileName.setTextColor(
|
||||||
viewBinding.fileTime.setTextColor(Color.GREEN)
|
ColorStateList.valueOf(GlobalMethod.getColorPrimary(context))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -156,7 +156,6 @@ object GlobalMethod {
|
||||||
* @param resId 资源id
|
* @param resId 资源id
|
||||||
* @return 成功返回值,失败返回-1
|
* @return 成功返回值,失败返回-1
|
||||||
*/
|
*/
|
||||||
@Deprecated("废弃")
|
|
||||||
fun getThemeColor(context: Context, resId: Int): Int {
|
fun getThemeColor(context: Context, resId: Int): Int {
|
||||||
val typedValue = TypedValue()
|
val typedValue = TypedValue()
|
||||||
return if (context.theme.resolveAttribute(resId, typedValue, true)) {
|
return if (context.theme.resolveAttribute(resId, typedValue, true)) {
|
||||||
|
@ -172,7 +171,6 @@ object GlobalMethod {
|
||||||
* @param context 上下文环境
|
* @param context 上下文环境
|
||||||
* @return 整数
|
* @return 整数
|
||||||
*/
|
*/
|
||||||
@Deprecated("废弃")
|
|
||||||
fun getColorPrimary(context: Context): Int {
|
fun getColorPrimary(context: Context): Int {
|
||||||
return getThemeColor(context, R.attr.colorPrimary)
|
return getThemeColor(context, R.attr.colorPrimary)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
10
app/src/main/res/drawable/ic_outline_sort_24.xml
Normal file
10
app/src/main/res/drawable/ic_outline_sort_24.xml
Normal 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>
|
|
@ -26,12 +26,20 @@
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
app:layout_behavior="com.google.android.material.appbar.AppBarLayout$ScrollingViewBehavior">
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipeRefreshLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/fileList"
|
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" />
|
android:visibility="gone" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:id="@+id/progressBar"
|
android:id="@+id/progressBar"
|
||||||
style="?android:attr/progressBarStyle"
|
style="?android:attr/progressBarStyle"
|
||||||
|
@ -40,10 +48,12 @@
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/fileError"
|
android:id="@+id/fileError"
|
||||||
|
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"
|
||||||
android:text="@string/loading_files" />
|
android:text="@string/loading_files"
|
||||||
|
android:visibility="gone" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
@ -4,22 +4,23 @@
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:padding="5dp"
|
|
||||||
android:id="@+id/file_icon"
|
android:id="@+id/file_icon"
|
||||||
android:layout_width="60dp"
|
android:layout_width="56dp"
|
||||||
android:layout_height="60dp"
|
android:layout_height="56dp"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentStart="true"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginStart="8dp"
|
||||||
|
android:padding="5dp"
|
||||||
android:src="@drawable/file" />
|
android:src="@drawable/file" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
android:id="@+id/contentView"
|
android:id="@+id/contentView"
|
||||||
android:layout_centerVertical="true"
|
android:layout_centerVertical="true"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_toRightOf="@id/file_icon"
|
android:layout_toEndOf="@id/file_icon"
|
||||||
android:layout_toLeftOf="@id/more"
|
android:layout_toStartOf="@id/more"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
@ -27,15 +28,7 @@
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="文件名"
|
android:text="文件名"
|
||||||
android:textSize="16dp" />
|
style="@style/TextAppearance.Material3.TitleMedium" />
|
||||||
|
|
||||||
<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" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
@ -46,6 +39,6 @@
|
||||||
android:layout_height="48dp"
|
android:layout_height="48dp"
|
||||||
android:padding="12dp"
|
android:padding="12dp"
|
||||||
android:src="@drawable/more"
|
android:src="@drawable/more"
|
||||||
android:layout_alignParentRight="true"/>
|
android:layout_alignParentEnd="true"/>
|
||||||
|
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
|
@ -11,23 +11,24 @@
|
||||||
|
|
||||||
<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:textColor="@color/black"
|
android:textColor="@color/black" />
|
||||||
android:textSize="14sp" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/priceView"
|
android:id="@+id/priceView"
|
||||||
|
style="@style/TextAppearance.Material3.TitleSmall"
|
||||||
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"
|
||||||
android:text="@string/money"
|
android:text="@string/money"
|
||||||
android:textColor="?colorPrimary"
|
android:textColor="?colorPrimary" />
|
||||||
android:textSize="16sp" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
|
style="@style/TextAppearance.Material3.BodyMedium"
|
||||||
android:id="@+id/originalPriceView"
|
android:id="@+id/originalPriceView"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|
|
@ -1,5 +1,30 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?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
|
<item
|
||||||
android:id="@+id/reloadFile"
|
android:id="@+id/reloadFile"
|
||||||
android:title="@string/reload_files" />
|
android:title="@string/reload_files" />
|
||||||
|
|
|
@ -849,6 +849,11 @@
|
||||||
<string name="search_type_purchase_plan">套餐</string>
|
<string name="search_type_purchase_plan">套餐</string>
|
||||||
<string name="search_type_mod_all">全部</string>
|
<string name="search_type_mod_all">全部</string>
|
||||||
<string name="hotSearch">热门搜索</string>
|
<string name="hotSearch">热门搜索</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_null">无搜索建议。</string>-->
|
||||||
<!-- <string name="search_suggestions_number">共%1$d个搜索建议。</string>-->
|
<!-- <string name="search_suggestions_number">共%1$d个搜索建议。</string>-->
|
||||||
|
|
||||||
|
|
|
@ -4,10 +4,8 @@ import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.widget.Toast
|
|
||||||
import com.coldmint.rust.core.R
|
import com.coldmint.rust.core.R
|
||||||
import kotlin.Throws
|
import kotlin.Throws
|
||||||
import androidx.documentfile.provider.DocumentFile
|
|
||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.provider.MediaStore
|
import android.provider.MediaStore
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
@ -563,16 +561,15 @@ object FileOperator {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*获取文件上级目录*/
|
/*获取文件上级目录*/
|
||||||
fun getSuperDirectory(file: File, root: File): String {
|
fun getSuperDirectory(filePath: String, rootPath: String): String {
|
||||||
val path = file.absolutePath
|
return if (filePath == rootPath) {
|
||||||
return if (path == root.absolutePath) {
|
filePath
|
||||||
path
|
|
||||||
} else {
|
} else {
|
||||||
val endNum = path.lastIndexOf("/")
|
val endNum = filePath.lastIndexOf("/")
|
||||||
if (endNum > 0) {
|
if (endNum > 0) {
|
||||||
path.substring(0, endNum)
|
filePath.substring(0, endNum)
|
||||||
} else {
|
} else {
|
||||||
path
|
filePath
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user