添加喜欢列表
This commit is contained in:
parent
298585b602
commit
e8594793cd
@ -2,6 +2,7 @@ package com.all.pdfreader.pro.app.ui.dialog
|
|||||||
|
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.util.Log
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
@ -13,7 +14,9 @@ import com.all.pdfreader.pro.app.model.PrintResult
|
|||||||
import com.all.pdfreader.pro.app.model.RenameType
|
import com.all.pdfreader.pro.app.model.RenameType
|
||||||
import com.all.pdfreader.pro.app.room.entity.PdfDocumentEntity
|
import com.all.pdfreader.pro.app.room.entity.PdfDocumentEntity
|
||||||
import com.all.pdfreader.pro.app.ui.act.SplitPdfActivity
|
import com.all.pdfreader.pro.app.ui.act.SplitPdfActivity
|
||||||
|
import com.all.pdfreader.pro.app.ui.fragment.FavoriteFrag
|
||||||
import com.all.pdfreader.pro.app.ui.fragment.HomeFrag
|
import com.all.pdfreader.pro.app.ui.fragment.HomeFrag
|
||||||
|
import com.all.pdfreader.pro.app.ui.fragment.RecentlyFrag
|
||||||
import com.all.pdfreader.pro.app.util.AppUtils.dpToPx
|
import com.all.pdfreader.pro.app.util.AppUtils.dpToPx
|
||||||
import com.all.pdfreader.pro.app.util.AppUtils.printPdfFile
|
import com.all.pdfreader.pro.app.util.AppUtils.printPdfFile
|
||||||
import com.all.pdfreader.pro.app.util.AppUtils.setClickWithAnimation
|
import com.all.pdfreader.pro.app.util.AppUtils.setClickWithAnimation
|
||||||
@ -73,12 +76,16 @@ class ListMoreDialogFragment(val filePath: String) : BottomSheetDialogFragment()
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initUi() {
|
private fun initUi() {
|
||||||
if (tag == HomeFrag().tag) {
|
when (tag) {
|
||||||
|
HomeFrag.FRAG_TAG -> {
|
||||||
binding.removeRecentBtn.visibility = View.GONE
|
binding.removeRecentBtn.visibility = View.GONE
|
||||||
} else {
|
}
|
||||||
if (pdfDocument.lastOpenedTime > 0) {
|
|
||||||
|
RecentlyFrag.FRAG_TAG -> {
|
||||||
binding.removeRecentBtn.visibility = View.VISIBLE
|
binding.removeRecentBtn.visibility = View.VISIBLE
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
FavoriteFrag.FRAG_TAG -> {
|
||||||
binding.removeRecentBtn.visibility = View.GONE
|
binding.removeRecentBtn.visibility = View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -108,8 +115,7 @@ class ListMoreDialogFragment(val filePath: String) : BottomSheetDialogFragment()
|
|||||||
}
|
}
|
||||||
binding.renameFileBtn.setOnClickListener {
|
binding.renameFileBtn.setOnClickListener {
|
||||||
RenameDialogFragment(RenameType.FILE).show(
|
RenameDialogFragment(RenameType.FILE).show(
|
||||||
parentFragmentManager,
|
parentFragmentManager, "ListMoreDialogFragment"
|
||||||
"ListMoreDialogFragment"
|
|
||||||
)
|
)
|
||||||
dismiss()
|
dismiss()
|
||||||
}
|
}
|
||||||
@ -135,9 +141,7 @@ class ListMoreDialogFragment(val filePath: String) : BottomSheetDialogFragment()
|
|||||||
when (result) {
|
when (result) {
|
||||||
PrintResult.DeviceNotSupported -> {
|
PrintResult.DeviceNotSupported -> {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context, R.string.device_does_not_support_printing, Toast.LENGTH_LONG
|
||||||
R.string.device_does_not_support_printing,
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,9 +157,7 @@ class ListMoreDialogFragment(val filePath: String) : BottomSheetDialogFragment()
|
|||||||
|
|
||||||
PrintResult.PasswordRequired -> {
|
PrintResult.PasswordRequired -> {
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
context,
|
context, R.string.pdf_cant_print_password_protected, Toast.LENGTH_LONG
|
||||||
R.string.pdf_cant_print_password_protected,
|
|
||||||
Toast.LENGTH_LONG
|
|
||||||
).show()
|
).show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,10 +5,26 @@ import android.view.LayoutInflater
|
|||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import androidx.fragment.app.Fragment
|
import androidx.fragment.app.Fragment
|
||||||
|
import androidx.lifecycle.Lifecycle
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.lifecycle.repeatOnLifecycle
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.all.pdfreader.pro.app.databinding.FragmentFavoriteBinding
|
import com.all.pdfreader.pro.app.databinding.FragmentFavoriteBinding
|
||||||
|
import com.all.pdfreader.pro.app.room.repository.PdfRepository
|
||||||
|
import com.all.pdfreader.pro.app.ui.act.PdfViewActivity
|
||||||
|
import com.all.pdfreader.pro.app.ui.adapter.PdfAdapter
|
||||||
|
import com.all.pdfreader.pro.app.ui.dialog.ListMoreDialogFragment
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
|
class FavoriteFrag : BaseFrag() {
|
||||||
|
override val TAG: String = "FavoriteFrag"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FRAG_TAG = "FavoriteFrag"
|
||||||
|
}
|
||||||
|
|
||||||
class FavoriteFrag : Fragment() {
|
|
||||||
private lateinit var binding: FragmentFavoriteBinding
|
private lateinit var binding: FragmentFavoriteBinding
|
||||||
|
private lateinit var adapter: PdfAdapter
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?
|
||||||
@ -20,9 +36,41 @@ class FavoriteFrag : Fragment() {
|
|||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
super.onViewCreated(view, savedInstanceState)
|
super.onViewCreated(view, savedInstanceState)
|
||||||
initView()
|
initView()
|
||||||
|
observeDocuments()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initView() {
|
private fun initView() {
|
||||||
|
adapter = PdfAdapter(pdfList = mutableListOf(), onItemClick = { pdf ->
|
||||||
|
val intent = PdfViewActivity.createIntent(requireContext(), pdf.filePath)
|
||||||
|
startActivity(intent)
|
||||||
|
}, onMoreClick = { pdf ->
|
||||||
|
ListMoreDialogFragment(pdf.filePath).show(parentFragmentManager, FRAG_TAG)
|
||||||
|
})
|
||||||
|
|
||||||
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
binding.recyclerView.adapter = adapter
|
||||||
|
|
||||||
|
// 下拉刷新示例
|
||||||
|
binding.swipeRefreshLayout.setOnRefreshListener {
|
||||||
|
observeDocuments {
|
||||||
|
binding.swipeRefreshLayout.isRefreshing = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun observeDocuments(onComplete: () -> Unit = {}) {
|
||||||
|
lifecycleScope.launch {
|
||||||
|
viewLifecycleOwner.lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||||
|
PdfRepository.getInstance().getFavoriteDocuments().collect { list ->
|
||||||
|
if (list.isNotEmpty()) {
|
||||||
|
adapter.updateData(list)
|
||||||
|
onComplete()
|
||||||
|
binding.noFilesLayout.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.noFilesLayout.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -21,6 +21,11 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
class HomeFrag : BaseFrag(), MainActivity.SortableFragment {
|
class HomeFrag : BaseFrag(), MainActivity.SortableFragment {
|
||||||
override val TAG: String = "HomeFrag"
|
override val TAG: String = "HomeFrag"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FRAG_TAG = "HomeFrag"
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var binding: FragmentHomeBinding
|
private lateinit var binding: FragmentHomeBinding
|
||||||
private lateinit var adapter: PdfAdapter
|
private lateinit var adapter: PdfAdapter
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
@ -41,7 +46,7 @@ class HomeFrag : BaseFrag(), MainActivity.SortableFragment {
|
|||||||
val intent = PdfViewActivity.createIntent(requireContext(), pdf.filePath)
|
val intent = PdfViewActivity.createIntent(requireContext(), pdf.filePath)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}, onMoreClick = { pdf ->
|
}, onMoreClick = { pdf ->
|
||||||
ListMoreDialogFragment(pdf.filePath).show(parentFragmentManager, TAG)
|
ListMoreDialogFragment(pdf.filePath).show(parentFragmentManager, FRAG_TAG)
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
|
|||||||
@ -17,6 +17,11 @@ import kotlinx.coroutines.launch
|
|||||||
|
|
||||||
class RecentlyFrag : BaseFrag() {
|
class RecentlyFrag : BaseFrag() {
|
||||||
override val TAG: String = "RecentlyFrag"
|
override val TAG: String = "RecentlyFrag"
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
const val FRAG_TAG = "RecentlyFrag"
|
||||||
|
}
|
||||||
|
|
||||||
private lateinit var binding: FragmentRecentlyBinding
|
private lateinit var binding: FragmentRecentlyBinding
|
||||||
private lateinit var adapter: PdfAdapter
|
private lateinit var adapter: PdfAdapter
|
||||||
|
|
||||||
@ -38,7 +43,7 @@ class RecentlyFrag : BaseFrag() {
|
|||||||
val intent = PdfViewActivity.createIntent(requireContext(), pdf.filePath)
|
val intent = PdfViewActivity.createIntent(requireContext(), pdf.filePath)
|
||||||
startActivity(intent)
|
startActivity(intent)
|
||||||
}, onMoreClick = { pdf ->
|
}, onMoreClick = { pdf ->
|
||||||
ListMoreDialogFragment(pdf.filePath).show(parentFragmentManager, TAG)
|
ListMoreDialogFragment(pdf.filePath).show(parentFragmentManager, FRAG_TAG)
|
||||||
})
|
})
|
||||||
|
|
||||||
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
binding.recyclerView.layoutManager = LinearLayoutManager(requireContext())
|
||||||
@ -63,7 +68,6 @@ class RecentlyFrag : BaseFrag() {
|
|||||||
} else {
|
} else {
|
||||||
binding.noFilesLayout.visibility = View.VISIBLE
|
binding.noFilesLayout.visibility = View.VISIBLE
|
||||||
}
|
}
|
||||||
logDebug("更新adapter数据")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,9 +10,40 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp" />
|
android:layout_height="0dp" />
|
||||||
|
|
||||||
<TextView
|
<LinearLayout
|
||||||
|
android:id="@+id/noFilesLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical"
|
||||||
|
android:visibility="gone">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="@string/favorite"/>
|
android:src="@mipmap/img_no_files_yet" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
style="@style/TextViewFont_PopMedium"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/no_files_yet"
|
||||||
|
android:textColor="#B6BFCC"
|
||||||
|
android:textSize="20sp" />
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
|
||||||
|
android:id="@+id/swipeRefreshLayout"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
android:id="@+id/recyclerView"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:paddingBottom="40dp" />
|
||||||
|
|
||||||
|
</androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
Loading…
Reference in New Issue
Block a user