mirror of
https://github.com/gedoor/legado.git
synced 2024-09-03 09:55:00 +08:00
增加内置文件管理器,未完成
This commit is contained in:
parent
a15aace1b4
commit
fe641239ca
@ -11,21 +11,27 @@ import io.legado.app.base.adapter.ItemViewHolder
|
||||
import io.legado.app.base.adapter.RecyclerAdapter
|
||||
import io.legado.app.databinding.ActivityFileManageBinding
|
||||
import io.legado.app.databinding.ItemFileBinding
|
||||
import io.legado.app.lib.theme.backgroundColor
|
||||
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.applyTint
|
||||
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 viewModel by viewModels<FileManageViewModel>()
|
||||
private val searchView: SearchView by lazy {
|
||||
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()
|
||||
}
|
||||
|
||||
@ -35,9 +41,11 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
||||
}
|
||||
|
||||
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.adapter = adapter
|
||||
binding.recyclerView.adapter = fileAdapter
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
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 {
|
||||
TODO("Not yet implemented")
|
||||
return ItemFileBinding.inflate(inflater, parent, false)
|
||||
}
|
||||
|
||||
override fun registerListener(holder: ItemViewHolder, binding: ItemFileBinding) {
|
||||
TODO("Not yet implemented")
|
||||
|
||||
}
|
||||
|
||||
override fun convert(
|
||||
@ -76,7 +93,7 @@ class FileManageActivity : VMBaseActivity<ActivityFileManageBinding, FileManageV
|
||||
item: FileDoc,
|
||||
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
|
||||
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())
|
||||
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())!!
|
||||
private val primaryTextColor = context.getPrimaryTextColor(!AppConfig.isNightTheme)
|
||||
private val disabledTextColor = context.getPrimaryDisabledTextColor(!AppConfig.isNightTheme)
|
||||
|
||||
@ -39,22 +39,22 @@ class FileAdapter(context: Context, val callBack: CallBack) :
|
||||
currentPath = path
|
||||
if (callBack.isShowHomeDir) {
|
||||
//添加“返回主目录”
|
||||
val fileRoot = FileItem()
|
||||
fileRoot.isDirectory = true
|
||||
fileRoot.icon = homeIcon
|
||||
fileRoot.name = DIR_ROOT
|
||||
fileRoot.size = 0
|
||||
fileRoot.path = rootPath ?: path
|
||||
val fileRoot = FileItem(
|
||||
isDirectory = true,
|
||||
icon = homeIcon,
|
||||
name = DIR_ROOT,
|
||||
path = rootPath ?: path
|
||||
)
|
||||
data.add(fileRoot)
|
||||
}
|
||||
if (callBack.isShowUpDir && path != PathAdapter.sdCardDirectory) {
|
||||
//添加“返回上一级目录”
|
||||
val fileParent = FileItem()
|
||||
fileParent.isDirectory = true
|
||||
fileParent.icon = upIcon
|
||||
fileParent.name = DIR_PARENT
|
||||
fileParent.size = 0
|
||||
fileParent.path = File(path).parent ?: ""
|
||||
val fileParent = FileItem(
|
||||
isDirectory = true,
|
||||
icon = upIcon,
|
||||
name = DIR_PARENT,
|
||||
path = File(path).parent ?: ""
|
||||
)
|
||||
data.add(fileParent)
|
||||
}
|
||||
currentPath?.let { currentPath ->
|
||||
@ -64,18 +64,22 @@ class FileAdapter(context: Context, val callBack: CallBack) :
|
||||
if (!callBack.isShowHideDir && file.name.startsWith(".")) {
|
||||
continue
|
||||
}
|
||||
val fileItem = FileItem()
|
||||
val isDirectory = file.isDirectory
|
||||
fileItem.isDirectory = isDirectory
|
||||
if (isDirectory) {
|
||||
fileItem.icon = folderIcon
|
||||
fileItem.size = 0
|
||||
val fileItem = if (file.isDirectory) {
|
||||
FileItem(
|
||||
name = file.name,
|
||||
icon = folderIcon,
|
||||
path = file.absolutePath,
|
||||
isDirectory = true
|
||||
)
|
||||
} else {
|
||||
fileItem.icon = fileIcon
|
||||
fileItem.size = file.length()
|
||||
FileItem(
|
||||
name = file.name,
|
||||
icon = fileIcon,
|
||||
path = file.absolutePath,
|
||||
size = file.length(),
|
||||
isDirectory = true
|
||||
)
|
||||
}
|
||||
fileItem.name = file.name
|
||||
fileItem.path = file.absolutePath
|
||||
data.add(fileItem)
|
||||
}
|
||||
}
|
||||
|
@ -4,14 +4,11 @@ import android.graphics.drawable.Drawable
|
||||
|
||||
/**
|
||||
* 文件项信息
|
||||
*
|
||||
* @author 李玉江[QQ:1032694760]
|
||||
* @since 2014-05-23 18:02
|
||||
*/
|
||||
class FileItem : JavaBean() {
|
||||
var icon: Drawable? = null
|
||||
var name: String? = null
|
||||
var path = "/"
|
||||
var size: Long = 0
|
||||
var isDirectory = false
|
||||
}
|
||||
data class FileItem(
|
||||
var icon: Drawable,
|
||||
var name: String,
|
||||
var path: String = "/",
|
||||
var size: Long = 0,
|
||||
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" />
|
||||
|
||||
<!--path-->
|
||||
<LinearLayout
|
||||
android:id="@+id/lay_top"
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rv_path"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/background"
|
||||
android:elevation="1dp"
|
||||
android:gravity="center_vertical"
|
||||
android:minHeight="36dp"
|
||||
android:orientation="horizontal"
|
||||
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>
|
||||
android:layout_height="24dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:background="@color/background_card"
|
||||
android:elevation="5dp"
|
||||
app:layout_constraintTop_toBottomOf="@+id/titleBar" />
|
||||
|
||||
<io.legado.app.ui.widget.anima.RefreshProgressBar
|
||||
android:id="@+id/refresh_progress_bar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="2dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/lay_top" />
|
||||
app:layout_constraintTop_toBottomOf="@id/rv_path" />
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user