添加文件详情展示dialog
This commit is contained in:
parent
82270adb07
commit
23e7e8f97b
@ -0,0 +1,58 @@
|
||||
package com.all.pdfreader.pro.app.ui.dialog
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.Toast
|
||||
import androidx.fragment.app.activityViewModels
|
||||
import com.all.pdfreader.pro.app.R
|
||||
import com.all.pdfreader.pro.app.databinding.DialogFileDetailsBinding
|
||||
import com.all.pdfreader.pro.app.room.entity.PdfDocumentEntity
|
||||
import com.all.pdfreader.pro.app.util.FileUtils.toFormatFileSize
|
||||
import com.all.pdfreader.pro.app.util.FileUtils.toSlashDateTime
|
||||
import com.all.pdfreader.pro.app.viewmodel.PdfViewModel
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
|
||||
class FileDetailsDialogFragment() : BottomSheetDialogFragment() {
|
||||
|
||||
private lateinit var binding: DialogFileDetailsBinding
|
||||
private val viewModel: PdfViewModel by activityViewModels()
|
||||
private lateinit var pdfDocument: PdfDocumentEntity
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||
): View? {
|
||||
binding = DialogFileDetailsBinding.inflate(layoutInflater)
|
||||
return binding.root
|
||||
}
|
||||
|
||||
override fun onStart() {
|
||||
super.onStart()
|
||||
dialog?.window?.findViewById<View>(com.google.android.material.R.id.design_bottom_sheet)
|
||||
?.setBackgroundResource(R.drawable.dr_rounded_corner_12_bg_white)
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
viewModel.pdfDocument.value?.let {
|
||||
pdfDocument = it
|
||||
initView()
|
||||
} ?: run {
|
||||
showToast(getString(R.string.file_not))
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun initView() {
|
||||
binding.fileNameTv.text = pdfDocument.fileName
|
||||
binding.pathTv.text = pdfDocument.filePath
|
||||
binding.lastModifiedTv.text = pdfDocument.lastModified.toSlashDateTime()
|
||||
binding.lastViewedTv.text = pdfDocument.lastOpenedTime.toSlashDateTime()
|
||||
binding.sizeTv.text = pdfDocument.fileSize.toFormatFileSize()
|
||||
}
|
||||
|
||||
private fun showToast(message: String) {
|
||||
Toast.makeText(requireActivity(), message, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
@ -93,6 +93,10 @@ class ListMoreDialogFragment(val filePath: String) : BottomSheetDialogFragment()
|
||||
DeleteDialogFragment().show(parentFragmentManager, "DeleteDialogFragment")
|
||||
dismiss()
|
||||
}
|
||||
binding.detailsBtn.setOnClickListener {
|
||||
FileDetailsDialogFragment().show(parentFragmentManager, "FileDetailsDialogFragment")
|
||||
dismiss()
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateCollectUi(b: Boolean) {
|
||||
|
||||
@ -321,6 +321,11 @@ object FileUtils {
|
||||
return sdf.format(Date(this))
|
||||
}
|
||||
|
||||
fun Long.toSlashDateTime(): String {
|
||||
val sdf = SimpleDateFormat("M/d/yyyy HH:mm", Locale.ENGLISH)
|
||||
return sdf.format(Date(this))
|
||||
}
|
||||
|
||||
|
||||
data class FileInfo(
|
||||
val name: String, val size: Long, val uri: Uri
|
||||
|
||||
139
app/src/main/res/layout/dialog_file_details.xml
Normal file
139
app/src/main/res/layout/dialog_file_details.xml
Normal file
@ -0,0 +1,139 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center">
|
||||
|
||||
<View
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="4dp"
|
||||
android:background="@drawable/dr_dialog_indicator_bg" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/file_information"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="18sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/file_information_desc"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:background="@color/line_color" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/file_name"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/fileNameTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/file_name"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/path"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/pathTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/path"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/last_modified"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lastModifiedTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/last_modified"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/last_viewed"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/lastViewedTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/last_viewed"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@font/poppins_regular"
|
||||
android:text="@string/size"
|
||||
android:textColor="@color/black_60"
|
||||
android:textSize="12sp" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/sizeTv"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:fontFamily="@font/poppins_medium"
|
||||
android:text="@string/size"
|
||||
android:textColor="@color/black"
|
||||
android:textSize="14sp" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
@ -146,6 +146,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/detailsBtn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
<string name="ok">OK</string>
|
||||
<string name="sort_by">Sort by</string>
|
||||
<string name="created_date">Created Date</string>
|
||||
<string name="path">Path</string>
|
||||
<string name="file_name">File Name</string>
|
||||
<string name="file_size">File Size</string>
|
||||
<string name="ascending">Ascending</string>
|
||||
@ -78,4 +79,9 @@
|
||||
<string name="error_cannot_delete_protected_directory">Cannot delete protected system directory</string>
|
||||
<string name="delete_file_title">Delete this file permanently?</string>
|
||||
<string name="delete_file_desc">Deleting this file will remove it permanently from your device.</string>
|
||||
<string name="file_information">File Information</string>
|
||||
<string name="file_information_desc">Everything you need to know about the file.</string>
|
||||
<string name="last_modified">Last Modified</string>
|
||||
<string name="last_viewed">Last Viewed</string>
|
||||
<string name="size">Size</string>
|
||||
</resources>
|
||||
Loading…
Reference in New Issue
Block a user