Commit b8318b76 authored by wanglei's avatar wanglei

...处理方法并发

parent 8d6f9119
......@@ -104,6 +104,12 @@
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<activity
android:name=".ui.excel.ExcelActivity"
android:exported="true"
android:launchMode="singleTop"
android:screenOrientation="portrait"
tools:ignore="DiscouragedApi,LockedOrientationActivity" />
<provider
android:name="androidx.core.content.FileProvider"
......
......@@ -20,6 +20,7 @@ import com.base.pdfoneread.bean.DocumentBean.Companion.TYPE_WORD
import com.base.pdfoneread.databinding.ActivityDocumentBinding
import com.base.pdfoneread.ui.BaseActivity
import com.base.pdfoneread.ui.pdf.PdfActivity
import com.base.pdfoneread.ui.pdf.PdfActivity.Companion.jumpOtherDocument
import com.base.pdfoneread.ui.views.DialogCallBack
import com.base.pdfoneread.ui.views.DocumentDialog.showDeleteDialog
import com.base.pdfoneread.ui.views.DocumentDialog.showDocumentHomeMoreDialog
......@@ -93,7 +94,7 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
if (item.type == TYPE_PDF) {
PdfActivity.jumpPdfActivity(this, item)
} else {
PdfActivity.jumpOtherDocument(this, item)
}
}
adapter?.moreAction = { item: DocumentBean ->
......@@ -168,10 +169,11 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
initData()
}
initPreData()
lifecycleScope.launch {
isRefreshOver.collectLatest { value ->
LogEx.logDebug(TAG, "value=$value")
initData()
initPreData()
//刷新结束不再监听
cancel()
}
......@@ -252,7 +254,7 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
}
runOnUI(list)
runOnUI(list, true)
}
private fun initData() = lifecycleScope.launch(Dispatchers.IO) {
......@@ -268,16 +270,21 @@ class DocumentActivity : BaseActivity<ActivityDocumentBinding>(), DialogCallBack
runOnUI(list)
}
private fun runOnUI(list: List<DocumentBean>) {
private fun runOnUI(list: List<DocumentBean>, isPreload: Boolean = false) {
lifecycleScope.launch(Dispatchers.Main) {
if (list.isEmpty()) {
binding.llEmpty.visibility = View.VISIBLE
if (isPreload) {
binding.swipeRefreshLayout.isRefreshing = true
} else {
binding.llEmpty.visibility = View.VISIBLE
binding.swipeRefreshLayout.isRefreshing = false
}
adapter?.submitList(listOf())
} else {
binding.llEmpty.visibility = View.GONE
adapter?.submitList(getRvAdList(list))
binding.swipeRefreshLayout.isRefreshing = false
}
binding.swipeRefreshLayout.isRefreshing = false
}
}
......
......@@ -137,6 +137,8 @@ fun getPPtDemo(context: Context): DocumentBean {
return demoDocumentBean
}
@Synchronized
fun getAllDocument(context: Context): MutableList<DocumentBean> {
context.upDateDemoStore()
if (!ConstObject.haveSaveDemo) {
......
......@@ -187,9 +187,8 @@ class HomeFragment() : Fragment() {
private var isRefreshing: AtomicBoolean = AtomicBoolean(false)
private fun refreshData(where: String = "") {
if (isRefreshing.get()) return
isRefreshing.set(true)
LogEx.logDebug(TAG, "refreshData where=$where")
isRefreshing.compareAndSet(false, true)
kotlin.runCatching {
lifecycleScope.launch(Dispatchers.IO) {
getAllDocument(requireContext())
......@@ -212,7 +211,7 @@ class HomeFragment() : Fragment() {
adapter.submitList(groupList)
binding.swipeRefreshLayout.isRefreshing = false
isRefreshing.compareAndSet(true, false)
isRefreshing.set(false)
}
}
}
......
......@@ -21,6 +21,7 @@ import com.base.pdfoneread.ui.search.SearchActivity
import com.base.pdfoneread.ui.views.MainDialog.showAppExitDialog
import com.base.pdfoneread.ui.views.MainDialog.showStoragePermission
import com.base.pdfoneread.utils.BarUtils
import com.base.pdfoneread.utils.LogEx
import com.base.pdfoneread.utils.PermissionUtils.checkStorePermission
import com.base.pdfoneread.utils.SpannableUtils.colorSpanner
import kotlinx.coroutines.Dispatchers
......
......@@ -10,6 +10,7 @@ import com.base.pdfoneread.bean.DocumentBean
import com.base.pdfoneread.databinding.FragmentSettingBinding
import com.base.pdfoneread.ui.document.getTypeByMimeType
import com.base.pdfoneread.ui.pdf.PdfActivity
import com.base.pdfoneread.ui.views.RateDialog.showRateDialog
import com.base.pdfoneread.utils.LogEx
import com.base.pdfoneread.utils.PdfBoxUtils.checkPdfEncryption
import com.base.pdfoneread.utils.SafUtils.jumpOpenDocumentThenPersistable
......@@ -54,6 +55,9 @@ class SettingFragment : Fragment() {
}
}
binding.llRate.setOnClickListener {
requireContext().showRateDialog(true)
}
}
companion object {
......
......@@ -659,19 +659,19 @@ class PdfActivity : BaseActivity<ActivityPdfBinding>() {
}
}
fun Activity.jumpOtherDocument(item: DocumentBean) {
fun jumpOtherDocument(activity: Activity, item: DocumentBean) {
if (item.type == TYPE_WORD) {
WordActivity.wordDocumentBean = item
WordActivity.launchDocViewer(this, 3, item.path, -1, 100)
WordActivity.launchDocViewer(activity, 3, item.path, -1, 100)
}
if (item.type == TYPE_EXCEL) {
ExcelActivity.excelDocumentBean = item
ExcelActivity.launchDocViewer(this, 3, item.path, -1, 100)
ExcelActivity.launchDocViewer(activity, 3, item.path, -1, 100)
}
if (item.type == TYPE_PPT) {
PptActivity.pptDocumentBean = item
PptActivity.launchDocViewer(this, 3, item.path, -1, 100)
PptActivity.launchDocViewer(activity, 3, item.path, -1, 100)
}
}
......
package com.base.pdfoneread.ui.views
import android.annotation.SuppressLint
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.view.LayoutInflater
import android.view.View
import com.base.pdfoneread.R
import com.base.pdfoneread.databinding.DialogRateStarBinding
import com.base.pdfoneread.utils.AppPreferences
import com.google.android.material.bottomsheet.BottomSheetBehavior
import com.google.android.material.bottomsheet.BottomSheetDialog
object RateDialog {
fun Context.showRateDialog(mustShow: Boolean = false) {
if (!mustShow) {
if (AppPreferences.getInstance().getBoolean("isRated", false)) {
return
}
}
val dialog = BottomSheetDialog(this, R.style.BottomSheetDialog)
val binding = DialogRateStarBinding.inflate(LayoutInflater.from(this))
dialog.setContentView(binding.root)
dialog.setCanceledOnTouchOutside(true)
dialog.show()
val parentView = binding.root.parent as View
val behavior = BottomSheetBehavior.from(parentView)
//展开
behavior.state = BottomSheetBehavior.STATE_EXPANDED
listOf(
binding.iv1,
binding.iv2,
binding.iv3,
binding.iv4,
binding.iv5
).forEachIndexed { index, it ->
it.setOnClickListener {
setStar(binding, index)
}
}
binding.tvSubmit.setOnClickListener {
if (star >= 5) {
AppPreferences.getInstance().put("isRated", true)
try {
val uri =
Uri.parse("https://play.google.com/store/apps/details?id=" + this.packageName)
val intent = Intent(Intent.ACTION_VIEW, uri)
this.startActivity(intent)
} catch (_: Exception) {
}
}
dialog.dismiss()
}
dialog.setOnDismissListener {
AppPreferences.getInstance().put("isRated", true)
}
}
private var star = 5
@SuppressLint("SetTextI18n")
private fun setStar(binding: DialogRateStarBinding, star: Int) {
val context = binding.root.context
this.star = star + 1
// if (this.star < 3) {
// binding.ivFace.setImageResource(R.mipmap.pingfeniconk)
// } else {
// binding.ivFace.setImageResource(R.mipmap.pingfenicon)
// }
listOf(
binding.iv1,
binding.iv2,
binding.iv3,
binding.iv4,
binding.iv5
).forEachIndexed { index, it ->
it.setImageResource(
if (index <= star) {
if (index == 4) {
R.mipmap.pdf_start_s
} else {
R.mipmap.pdf_start
}
} else {
if (index == 4) {
R.mipmap.pdf_star_n1
} else {
R.mipmap.pdf_star_n
}
}
)
}
when (this.star) {
in 1..2 -> {
// binding.tv1.text = context.getString(R.string.oh_no)
// binding.tv2.text = context.getString(R.string.leave_us_your_feedback)
// binding.ivFace.setImageResource(R.mipmap.pdf_expression2)
}
in 3..4 -> {
// binding.tv1.text = context.getString(R.string.oh_we_are_sorry)
// binding.tv2.text = context.getString(R.string.leave_us_your_feedback)
// binding.ivFace.setImageResource(R.mipmap.pdf_expression1)
}
5 -> {
// binding.tv1.text = context.getString(R.string.much_appreciated)
// binding.tv2.text = context.getString(R.string.your_support_is_our_motivation)
// binding.ivFace.setImageResource(R.mipmap.pdf_expression3)
}
}
}
}
\ No newline at end of file
......@@ -62,7 +62,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="13dp"
android:src="@mipmap/pdf_Page"
android:src="@mipmap/pdf_page"
tools:ignore="ContentDescription" />
<TextView
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:background="@drawable/bg_ffffff_tlr15"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="60dp"
android:textColor="#333333"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText"
tools:text="We like you too! " />
<TextView
android:id="@+id/tv_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Thanks for your feedback"
android:textColor="#333333"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@id/tv_1"
app:layout_constraintTop_toBottomOf="@id/tv_1"
tools:ignore="HardcodedText" />
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_best"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_2">
<TextView
android:id="@+id/tv_best"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/the_best_we_can_get"
android:textColor="#FF310E"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="MissingConstraints" />
<ImageView
android:id="@+id/iv_best"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="50dp"
android:src="@mipmap/pdf_arrowhead"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:id="@+id/ll_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/cl_best">
<ImageView
android:id="@+id/iv_1"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@mipmap/pdf_start"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_2"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@mipmap/pdf_start"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_3"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@mipmap/pdf_start"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_4"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@mipmap/pdf_start"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/iv_5"
android:layout_width="38dp"
android:layout_height="38dp"
android:layout_margin="10dp"
android:src="@mipmap/pdf_start_s"
tools:ignore="ContentDescription" />
</LinearLayout>
<TextView
android:id="@+id/tv_submit"
android:layout_width="338dp"
android:layout_height="48dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="24dp"
android:background="@drawable/bg_ff5910_10"
android:gravity="center"
android:text="@string/rate"
android:textColor="@color/white"
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ll_star"
tools:ignore="HardcodedText" />
</androidx.constraintlayout.widget.ConstraintLayout>
<ImageView
android:id="@+id/iv_face"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/pdf_expression"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
......@@ -48,7 +48,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal">
android:orientation="horizontal"
android:visibility="gone">
<ImageView
android:layout_width="wrap_content"
......@@ -81,6 +82,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/ll_rate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
......@@ -117,6 +119,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/ll_feedback"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
......@@ -153,6 +156,7 @@
</LinearLayout>
<LinearLayout
android:id="@+id/ll_privacy"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
......
......@@ -67,5 +67,7 @@
<string name="go">Go</string>
<string name="you_can_open_files_through_nfile_manager">You can open files through\n\"File Manager\".</string>
<string name="your_full_document_reader">Your full document reader</string>
<string name="the_best_we_can_get">The best we can get :)</string>
<string name="rate">Rate</string>
</resources>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment