增加内置文件管理器,未完成
This commit is contained in:
@@ -11,21 +11,27 @@ import io.legado.app.base.adapter.ItemViewHolder
|
|||||||
import io.legado.app.base.adapter.RecyclerAdapter
|
import io.legado.app.base.adapter.RecyclerAdapter
|
||||||
import io.legado.app.databinding.ActivityFileManageBinding
|
import io.legado.app.databinding.ActivityFileManageBinding
|
||||||
import io.legado.app.databinding.ItemFileBinding
|
import io.legado.app.databinding.ItemFileBinding
|
||||||
import io.legado.app.lib.theme.backgroundColor
|
|
||||||
import io.legado.app.lib.theme.primaryTextColor
|
import io.legado.app.lib.theme.primaryTextColor
|
||||||
|
import io.legado.app.ui.document.adapter.PathAdapter
|
||||||
|
import io.legado.app.ui.document.utils.FilePickerIcon
|
||||||
|
import io.legado.app.ui.widget.recycler.VerticalDivider
|
||||||
|
import io.legado.app.utils.ConvertUtils
|
||||||
import io.legado.app.utils.FileDoc
|
import io.legado.app.utils.FileDoc
|
||||||
import io.legado.app.utils.applyTint
|
import io.legado.app.utils.applyTint
|
||||||
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
import io.legado.app.utils.viewbindingdelegate.viewBinding
|
||||||
|
|
||||||
class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageViewModel>() {
|
class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageViewModel>(),
|
||||||
|
PathAdapter.CallBack {
|
||||||
|
|
||||||
override val binding by viewBinding(ActivityFileManageBinding::inflate)
|
override val binding by viewBinding(ActivityFileManageBinding::inflate)
|
||||||
override val viewModel by viewModels<FileManageViewModel>()
|
override val viewModel by viewModels<FileManageViewModel>()
|
||||||
private val searchView: SearchView by lazy {
|
private val searchView: SearchView by lazy {
|
||||||
binding.titleBar.findViewById(R.id.search_view)
|
binding.titleBar.findViewById(R.id.search_view)
|
||||||
}
|
}
|
||||||
private val adapter by lazy {
|
private val pathAdapter by lazy {
|
||||||
|
PathAdapter(this, this)
|
||||||
|
}
|
||||||
|
private val fileAdapter by lazy {
|
||||||
FileAdapter()
|
FileAdapter()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -35,9 +41,11 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
binding.layTop.setBackgroundColor(backgroundColor)
|
binding.rvPath.layoutManager = LinearLayoutManager(this)
|
||||||
|
binding.rvPath.addItemDecoration(VerticalDivider(this))
|
||||||
|
binding.rvPath.adapter = pathAdapter
|
||||||
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
binding.recyclerView.layoutManager = LinearLayoutManager(this)
|
||||||
binding.recyclerView.adapter = adapter
|
binding.recyclerView.adapter = fileAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initSearchView() {
|
private fun initSearchView() {
|
||||||
@@ -58,16 +66,25 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPathClick(position: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
inner class FileAdapter : RecyclerAdapter<FileDoc, ItemFileBinding>(this@FileManageActivity) {
|
inner class FileAdapter : RecyclerAdapter<FileDoc, ItemFileBinding>(this@FileManageActivity) {
|
||||||
|
private var rootPath: String? = null
|
||||||
|
var currentPath: String? = null
|
||||||
|
private set
|
||||||
|
private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHome())!!
|
||||||
|
private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir())!!
|
||||||
|
private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder())!!
|
||||||
|
private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile())!!
|
||||||
|
|
||||||
override fun getViewBinding(parent: ViewGroup): ItemFileBinding {
|
override fun getViewBinding(parent: ViewGroup): ItemFileBinding {
|
||||||
TODO("Not yet implemented")
|
return ItemFileBinding.inflate(inflater, parent, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun registerListener(holder: ItemViewHolder, binding: ItemFileBinding) {
|
override fun registerListener(holder: ItemViewHolder, binding: ItemFileBinding) {
|
||||||
TODO("Not yet implemented")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun convert(
|
override fun convert(
|
||||||
@@ -76,7 +93,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
|||||||
item: FileDoc,
|
item: FileDoc,
|
||||||
payloads: MutableList<Any>
|
payloads: MutableList<Any>
|
||||||
) {
|
) {
|
||||||
TODO("Not yet implemented")
|
binding.imageView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,10 @@ class FileAdapter(context: Context, val callBack: CallBack) :
|
|||||||
private var rootPath: String? = null
|
private var rootPath: String? = null
|
||||||
var currentPath: String? = null
|
var currentPath: String? = null
|
||||||
private set
|
private set
|
||||||
private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHome())
|
private val homeIcon = ConvertUtils.toDrawable(FilePickerIcon.getHome())!!
|
||||||
private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir())
|
private val upIcon = ConvertUtils.toDrawable(FilePickerIcon.getUpDir())!!
|
||||||
private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder())
|
private val folderIcon = ConvertUtils.toDrawable(FilePickerIcon.getFolder())!!
|
||||||
private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile())
|
private val fileIcon = ConvertUtils.toDrawable(FilePickerIcon.getFile())!!
|
||||||
private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme)
|
private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme)
|
||||||
private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme)
|
private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme)
|
||||||
|
|
||||||
@@ -39,22 +39,22 @@ class FileAdapter(context: Context, val callBack: CallBack) :
|
|||||||
currentPath = path
|
currentPath = path
|
||||||
if (callBack.isShowHomeDir) {
|
if (callBack.isShowHomeDir) {
|
||||||
//添加“返回主目录”
|
//添加“返回主目录”
|
||||||
val fileRoot = FileItem()
|
val fileRoot = FileItem(
|
||||||
fileRoot.isDirectory = true
|
isDirectory = true,
|
||||||
fileRoot.icon = homeIcon
|
icon = homeIcon,
|
||||||
fileRoot.name = DIR_ROOT
|
name = DIR_ROOT,
|
||||||
fileRoot.size = 0
|
path = rootPath ?: path
|
||||||
fileRoot.path = rootPath ?: path
|
)
|
||||||
data.add(fileRoot)
|
data.add(fileRoot)
|
||||||
}
|
}
|
||||||
if (callBack.isShowUpDir && path != PathAdapter.sdCardDirectory) {
|
if (callBack.isShowUpDir && path != PathAdapter.sdCardDirectory) {
|
||||||
//添加“返回上一级目录”
|
//添加“返回上一级目录”
|
||||||
val fileParent = FileItem()
|
val fileParent = FileItem(
|
||||||
fileParent.isDirectory = true
|
isDirectory = true,
|
||||||
fileParent.icon = upIcon
|
icon = upIcon,
|
||||||
fileParent.name = DIR_PARENT
|
name = DIR_PARENT,
|
||||||
fileParent.size = 0
|
path = File(path).parent ?: ""
|
||||||
fileParent.path = File(path).parent ?: ""
|
)
|
||||||
data.add(fileParent)
|
data.add(fileParent)
|
||||||
}
|
}
|
||||||
currentPath?.let { currentPath ->
|
currentPath?.let { currentPath ->
|
||||||
@@ -64,18 +64,22 @@ class FileAdapter(context: Context, val callBack: CallBack) :
|
|||||||
if (!callBack.isShowHideDir && file.name.startsWith(".")) {
|
if (!callBack.isShowHideDir && file.name.startsWith(".")) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
val fileItem = FileItem()
|
val fileItem = if (file.isDirectory) {
|
||||||
val isDirectory = file.isDirectory
|
FileItem(
|
||||||
fileItem.isDirectory = isDirectory
|
name = file.name,
|
||||||
if (isDirectory) {
|
icon = folderIcon,
|
||||||
fileItem.icon = folderIcon
|
path = file.absolutePath,
|
||||||
fileItem.size = 0
|
isDirectory = true
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
fileItem.icon = fileIcon
|
FileItem(
|
||||||
fileItem.size = file.length()
|
name = file.name,
|
||||||
|
icon = fileIcon,
|
||||||
|
path = file.absolutePath,
|
||||||
|
size = file.length(),
|
||||||
|
isDirectory = true
|
||||||
|
)
|
||||||
}
|
}
|
||||||
fileItem.name = file.name
|
|
||||||
fileItem.path = file.absolutePath
|
|
||||||
data.add(fileItem)
|
data.add(fileItem)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,14 +4,11 @@ import android.graphics.drawable.Drawable
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 文件项信息
|
* 文件项信息
|
||||||
*
|
|
||||||
* @author 李玉江[QQ:1032694760]
|
|
||||||
* @since 2014-05-23 18:02
|
|
||||||
*/
|
*/
|
||||||
class FileItem : JavaBean() {
|
data class FileItem(
|
||||||
var icon: Drawable? = null
|
var icon: Drawable,
|
||||||
var name: String? = null
|
var name: String,
|
||||||
var path = "/"
|
var path: String = "/",
|
||||||
var size: Long = 0
|
var size: Long = 0,
|
||||||
var isDirectory = false
|
var isDirectory: Boolean = false,
|
||||||
}
|
)
|
||||||
|
|||||||
@@ -1,51 +0,0 @@
|
|||||||
package io.legado.app.ui.document.entity
|
|
||||||
|
|
||||||
import java.io.Serializable
|
|
||||||
import java.lang.reflect.Field
|
|
||||||
import java.lang.reflect.Modifier
|
|
||||||
|
|
||||||
/**
|
|
||||||
* JavaBean类
|
|
||||||
*
|
|
||||||
* @author 李玉江[QQ:1032694760]
|
|
||||||
* @since 2014-04-23 16:14
|
|
||||||
*/
|
|
||||||
open class JavaBean : Serializable {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 反射出所有字段值
|
|
||||||
*/
|
|
||||||
override fun toString(): String {
|
|
||||||
val list = ArrayList<Field>()
|
|
||||||
var clazz: Class<*>? = javaClass
|
|
||||||
list.addAll(listOf(*clazz!!.declaredFields))//得到自身的所有字段
|
|
||||||
val sb = StringBuilder()
|
|
||||||
while (clazz != Any::class.java) {
|
|
||||||
clazz = clazz!!.superclass//得到继承自父类的字段
|
|
||||||
val fields = clazz!!.declaredFields
|
|
||||||
for (field in fields) {
|
|
||||||
val modifier = field.modifiers
|
|
||||||
if (Modifier.isPublic(modifier) || Modifier.isProtected(modifier)) {
|
|
||||||
list.add(field)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
val fields = list.toTypedArray()
|
|
||||||
for (field in fields) {
|
|
||||||
val fieldName = field.name
|
|
||||||
kotlin.runCatching {
|
|
||||||
val obj = field.get(this)
|
|
||||||
sb.append(fieldName)
|
|
||||||
sb.append("=")
|
|
||||||
sb.append(obj)
|
|
||||||
sb.append("\n")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return sb.toString()
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
private const val serialVersionUID = -6111323241670458039L
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -14,51 +14,21 @@
|
|||||||
app:contentLayout="@layout/view_search" />
|
app:contentLayout="@layout/view_search" />
|
||||||
|
|
||||||
<!--path-->
|
<!--path-->
|
||||||
<LinearLayout
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/lay_top"
|
android:id="@+id/rv_path"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="24dp"
|
||||||
android:background="@color/background"
|
android:paddingLeft="10dp"
|
||||||
android:elevation="1dp"
|
android:paddingRight="10dp"
|
||||||
android:gravity="center_vertical"
|
android:background="@color/background_card"
|
||||||
android:minHeight="36dp"
|
android:elevation="5dp"
|
||||||
android:orientation="horizontal"
|
app:layout_constraintTop_toBottomOf="@+id/titleBar" />
|
||||||
android:padding="8dp"
|
|
||||||
app:layout_constraintTop_toBottomOf="@id/titleBar">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/tv_path"
|
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_weight="1"
|
|
||||||
android:focusable="true"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:singleLine="true"
|
|
||||||
android:textColor="@color/secondaryText"
|
|
||||||
android:textSize="13sp"
|
|
||||||
tools:text="/" />
|
|
||||||
|
|
||||||
<io.legado.app.ui.widget.text.StrokeTextView
|
|
||||||
android:id="@+id/tv_go_back"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_gravity="center"
|
|
||||||
android:layout_margin="4dp"
|
|
||||||
android:gravity="center"
|
|
||||||
android:paddingLeft="16dp"
|
|
||||||
android:paddingRight="16dp"
|
|
||||||
android:text="@string/go_back"
|
|
||||||
android:textFontWeight="800"
|
|
||||||
android:textSize="14sp"
|
|
||||||
app:cornerRadius="5dp"
|
|
||||||
tools:ignore="UnusedAttribute" />
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
<io.legado.app.ui.widget.anima.RefreshProgressBar
|
<io.legado.app.ui.widget.anima.RefreshProgressBar
|
||||||
android:id="@+id/refresh_progress_bar"
|
android:id="@+id/refresh_progress_bar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="2dp"
|
android:layout_height="2dp"
|
||||||
app:layout_constraintTop_toBottomOf="@id/lay_top" />
|
app:layout_constraintTop_toBottomOf="@id/rv_path" />
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user