Commit a4d8ecd3 authored by wanglei's avatar wanglei

...

parent fbfacf33
...@@ -32,6 +32,7 @@ object ConstObject { ...@@ -32,6 +32,7 @@ object ConstObject {
const val UI_MODE_NORMAL = "ui_mode_normal" const val UI_MODE_NORMAL = "ui_mode_normal"
const val UI_MODE_SELECT = "ui_mode_select" const val UI_MODE_SELECT = "ui_mode_select"
const val UI_MODE_SEARCH = "ui_mode_search"
var ifAgreePrivacy = false var ifAgreePrivacy = false
get() { get() {
......
...@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.ui.main ...@@ -2,6 +2,7 @@ package com.base.pdfviewerscannerwhite.ui.main
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.view.View import android.view.View
import android.view.inputmethod.EditorInfo
import androidx.core.content.ContextCompat import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter import androidx.viewpager2.adapter.FragmentStateAdapter
...@@ -13,19 +14,26 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.BOOKMARK_UI_TYPE ...@@ -13,19 +14,26 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.BOOKMARK_UI_TYPE
import com.base.pdfviewerscannerwhite.bean.ConstObject.DOCUMENT_UI_TYPE import com.base.pdfviewerscannerwhite.bean.ConstObject.DOCUMENT_UI_TYPE
import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_UI_TYPE import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_UI_TYPE
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_MODE_NORMAL import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_MODE_NORMAL
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_MODE_SEARCH
import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_MODE_SELECT import com.base.pdfviewerscannerwhite.bean.ConstObject.UI_MODE_SELECT
import com.base.pdfviewerscannerwhite.bean.DocumentBean import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.FragmentDocumentBinding import com.base.pdfviewerscannerwhite.databinding.FragmentDocumentBinding
import com.base.pdfviewerscannerwhite.helper.BaseFragment import com.base.pdfviewerscannerwhite.helper.BaseFragment
import com.base.pdfviewerscannerwhite.ui.adapter.DocumentAdapter
import com.base.pdfviewerscannerwhite.ui.main.MainActivity.Companion.jumpDocument
import com.base.pdfviewerscannerwhite.utils.KeyBoardUtils.hideKeyboard
import com.base.pdfviewerscannerwhite.utils.KeyBoardUtils.showKeyBoard
import com.base.pdfviewerscannerwhite.utils.LogEx
class DocumentFragment( class DocumentFragment(
val type: String = "" val type: String = ""
) : BaseFragment<FragmentDocumentBinding>() { ) : BaseFragment<FragmentDocumentBinding>() {
private val TAG = "DocumentFragment"
private val pdfPage: DocumentPageFragment by lazy { private val pdfPage: DocumentPageFragment by lazy {
DocumentPageFragment(DocumentBean.TYPE_PDF) DocumentPageFragment(DocumentBean.TYPE_PDF)
} }
private val wordPage: DocumentPageFragment by lazy { private val wordPage: DocumentPageFragment by lazy {
DocumentPageFragment(DocumentBean.TYPE_WORD) DocumentPageFragment(DocumentBean.TYPE_WORD)
} }
...@@ -43,6 +51,8 @@ class DocumentFragment( ...@@ -43,6 +51,8 @@ class DocumentFragment(
override val binding: FragmentDocumentBinding by lazy { override val binding: FragmentDocumentBinding by lazy {
FragmentDocumentBinding.inflate(layoutInflater) FragmentDocumentBinding.inflate(layoutInflater)
} }
private lateinit var searchAdapter: DocumentAdapter
var uiMode = UI_MODE_NORMAL var uiMode = UI_MODE_NORMAL
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
...@@ -64,6 +74,21 @@ class DocumentFragment( ...@@ -64,6 +74,21 @@ class DocumentFragment(
} }
initPageViewer() initPageViewer()
initTabLayout() initTabLayout()
initSearchAdapter()
}
private fun initSearchAdapter() {
searchAdapter = DocumentAdapter()
binding.rvSearch.adapter = searchAdapter
searchAdapter.moreAction = { item ->
if (currentFragment is DocumentPageFragment) {
(currentFragment as DocumentPageFragment).documentMoreAction.invoke(item)
}
}
searchAdapter.itemClick = {
requireActivity().jumpDocument(it)
}
} }
override fun setListener() { override fun setListener() {
...@@ -73,55 +98,22 @@ class DocumentFragment( ...@@ -73,55 +98,22 @@ class DocumentFragment(
(requireActivity() as MainActivity).onBackPressedDispatcher.onBackPressed() (requireActivity() as MainActivity).onBackPressedDispatcher.onBackPressed()
} }
binding.ivXuanze.setOnClickListener { binding.ivXuanze.setOnClickListener {
changeSelectUI() changeSelectUI(true)
}
binding.ivSearch.setOnClickListener {
changeSearchUI(true)
} }
binding.ivAllSelector.setOnClickListener { binding.ivAllSelector.setOnClickListener {
binding.ivAllSelector.isSelected = !binding.ivAllSelector.isSelected binding.ivAllSelector.isSelected = !binding.ivAllSelector.isSelected
changePageSelect(binding.ivAllSelector.isSelected) changePageSelect(binding.ivAllSelector.isSelected)
} }
} binding.editSearch.setOnEditorActionListener { v, actionId, event ->
private fun changeSelectUI() {
binding.viewPager2.isUserInputEnabled = false
(requireActivity() as MainActivity).callback.isEnabled = true
uiMode = UI_MODE_SELECT
binding.ivPaixu.visibility = View.INVISIBLE
binding.ivXuanze.visibility = View.INVISIBLE
binding.ivSearch.visibility = View.INVISIBLE
binding.tvTittle.visibility = View.INVISIBLE
binding.flFanhui.visibility = View.VISIBLE
binding.ivAllSelector.visibility = View.VISIBLE
(requireActivity() as MainActivity).changeSelectUI()
if (currentFragment is DocumentPageFragment) {
(currentFragment as DocumentPageFragment).changeSelectUi(true)
}
}
fun cancelSelectUI() {
binding.viewPager2.isUserInputEnabled = true
(requireActivity() as MainActivity).callback.isEnabled = false
uiMode = UI_MODE_NORMAL
binding.flFanhui.visibility = View.INVISIBLE
binding.ivAllSelector.visibility = View.INVISIBLE
if (type != RECENT_UI_TYPE) {
binding.ivPaixu.visibility = View.VISIBLE
}
binding.ivXuanze.visibility = View.VISIBLE
binding.ivSearch.visibility = View.VISIBLE
binding.tvTittle.visibility = View.VISIBLE
(requireActivity() as MainActivity).cancelSelectUI()
}
private fun changePageSelect(select: Boolean) { if (actionId == EditorInfo.IME_ACTION_DONE) {
if (currentFragment is DocumentPageFragment) { LogEx.logDebug(TAG, "IME_ACTION_DONE")
(currentFragment as DocumentPageFragment).changItemSelect(select) searchDocument()
}
false
} }
} }
...@@ -205,5 +197,102 @@ class DocumentFragment( ...@@ -205,5 +197,102 @@ class DocumentFragment(
ViewPager2Delegate.install(binding.viewPager2, binding.tabLayoutDocument) ViewPager2Delegate.install(binding.viewPager2, binding.tabLayoutDocument)
} }
fun changeSelectUI(show: Boolean) {
if (show) {
binding.viewPager2.isUserInputEnabled = false
(requireActivity() as MainActivity).callback.isEnabled = true
uiMode = UI_MODE_SELECT
binding.ivPaixu.visibility = View.INVISIBLE
binding.ivXuanze.visibility = View.INVISIBLE
binding.ivSearch.visibility = View.INVISIBLE
binding.tvTittle.visibility = View.INVISIBLE
binding.flFanhui.visibility = View.VISIBLE
binding.ivAllSelector.visibility = View.VISIBLE
(requireActivity() as MainActivity).changeSelectUI(true)
if (currentFragment is DocumentPageFragment) {
(currentFragment as DocumentPageFragment).changeSelectUi(true)
}
} else {
binding.viewPager2.isUserInputEnabled = true
(requireActivity() as MainActivity).callback.isEnabled = false
uiMode = UI_MODE_NORMAL
binding.flFanhui.visibility = View.INVISIBLE
binding.ivAllSelector.visibility = View.INVISIBLE
if (type != RECENT_UI_TYPE) {
binding.ivPaixu.visibility = View.VISIBLE
}
binding.ivXuanze.visibility = View.VISIBLE
binding.ivSearch.visibility = View.VISIBLE
binding.tvTittle.visibility = View.VISIBLE
(requireActivity() as MainActivity).changeSelectUI(false)
}
}
private fun changePageSelect(select: Boolean) {
if (currentFragment is DocumentPageFragment) {
(currentFragment as DocumentPageFragment).changItemSelect(select)
}
}
fun changeSearchUI(show: Boolean) {
if (show) {
uiMode = UI_MODE_SEARCH
(requireActivity() as MainActivity).callback.isEnabled = true
binding.tvTittle.visibility = View.INVISIBLE
binding.ivPaixu.visibility = View.INVISIBLE
binding.ivXuanze.visibility = View.INVISIBLE
binding.llMainContent.visibility = View.INVISIBLE
binding.flFanhui.visibility = View.VISIBLE
binding.editSearch.visibility = View.VISIBLE
(requireActivity() as MainActivity).changeSearchUI(true)
requireContext().showKeyBoard(binding.editSearch)
} else {
uiMode = UI_MODE_NORMAL
(requireActivity() as MainActivity).callback.isEnabled = false
binding.editSearch.visibility = View.INVISIBLE
binding.flFanhui.visibility = View.INVISIBLE
binding.tvTittle.visibility = View.VISIBLE
binding.ivPaixu.visibility = View.VISIBLE
binding.ivXuanze.visibility = View.VISIBLE
binding.llMainContent.visibility = View.VISIBLE
(requireActivity() as MainActivity).changeSearchUI(false)
requireContext().hideKeyboard(binding.editSearch)
}
}
private fun searchDocument() {
if (binding.editSearch.text.isNotEmpty()) {
val search = binding.editSearch.text.toString()
if (currentFragment is DocumentPageFragment) {
val item = (currentFragment as DocumentPageFragment).getSearchItems(search)
if (item.isNotEmpty()) {
item.map { it.uiType = 4 }
searchAdapter.submitList(item)
} else {
binding.llEmpty.visibility = View.VISIBLE
}
}
}
}
} }
\ No newline at end of file
...@@ -20,6 +20,7 @@ import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity ...@@ -20,6 +20,7 @@ import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSelectActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSplitActivity import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfSplitActivity
import com.base.pdfviewerscannerwhite.ui.document.ppt.PptActivity import com.base.pdfviewerscannerwhite.ui.document.ppt.PptActivity
import com.base.pdfviewerscannerwhite.ui.document.word.WordActivity import com.base.pdfviewerscannerwhite.ui.document.word.WordActivity
import com.base.pdfviewerscannerwhite.ui.main.MainActivity.Companion.jumpDocument
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentHomeMoreDialog import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentHomeMoreDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfHomeMoreDialog import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfHomeMoreDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
...@@ -192,42 +193,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu ...@@ -192,42 +193,6 @@ class DocumentPageFragment() : BaseFragment<FragmentDocumentPageBinding>(), Docu
} }
} }
companion object {
fun Activity.jumpDocument(item: DocumentBean) {
if (item.type == TYPE_PDF) {
if (item.state == 0) {
startActivity(Intent(this, PdfActivity::class.java).apply {
putExtra("path", item.path)
})
}
if (item.state == 1) {
showPdfPwdDialog(
state = item.state,
path = item.path,
isCheckPwd = true,
verificationAction = { pwd ->
startActivity(Intent(this, PdfActivity::class.java).apply {
putExtra("path", item.path)
putExtra("pwd", pwd)
})
})
}
}
if (item.type == TYPE_WORD) {
WordActivity.wordDocumentBean = item
WordActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
if (item.type == TYPE_EXCEL) {
ExcelActivity.excelDocumentBean = item
ExcelActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
if (item.type == TYPE_PPT) {
PptActivity.pptDocumentBean = item
PptActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
}
}
} }
\ No newline at end of file
package com.base.pdfviewerscannerwhite.ui.main package com.base.pdfviewerscannerwhite.ui.main
import android.app.Activity
import android.content.Intent
import android.net.Uri import android.net.Uri
import android.view.View import android.view.View
import androidx.activity.OnBackPressedCallback import androidx.activity.OnBackPressedCallback
...@@ -12,7 +14,12 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_UI_TYPE ...@@ -12,7 +14,12 @@ import com.base.pdfviewerscannerwhite.bean.ConstObject.RECENT_UI_TYPE
import com.base.pdfviewerscannerwhite.bean.DocumentBean import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityMain2Binding import com.base.pdfviewerscannerwhite.databinding.ActivityMain2Binding
import com.base.pdfviewerscannerwhite.helper.BaseActivity import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.document.excel.ExcelActivity
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfActivity
import com.base.pdfviewerscannerwhite.ui.document.ppt.PptActivity
import com.base.pdfviewerscannerwhite.ui.document.word.WordActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDeleteDialog import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDeleteDialog
import com.base.pdfviewerscannerwhite.ui.view.PdfDialog.showPdfPwdDialog
import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareMutDocuments import com.base.pdfviewerscannerwhite.utils.IntentShareUtils.shareMutDocuments
class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView { class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView {
...@@ -54,7 +61,10 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView { ...@@ -54,7 +61,10 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView {
if (currentFragment is DocumentFragment) { if (currentFragment is DocumentFragment) {
val documentFragment = (currentFragment as DocumentFragment) val documentFragment = (currentFragment as DocumentFragment)
if (documentFragment.uiMode == ConstObject.UI_MODE_SELECT) { if (documentFragment.uiMode == ConstObject.UI_MODE_SELECT) {
documentFragment.cancelSelectUI() documentFragment.changeSelectUI(false)
}
if (documentFragment.uiMode == ConstObject.UI_MODE_SEARCH) {
documentFragment.changeSearchUI(false)
} }
} }
...@@ -162,26 +172,26 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView { ...@@ -162,26 +172,26 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView {
} }
fun changeSelectUI() { fun changeSelectUI(show: Boolean) {
binding.ivScan.visibility = View.INVISIBLE if (show) {
binding.llDocument.visibility = View.INVISIBLE binding.ivScan.visibility = View.INVISIBLE
binding.llRecent.visibility = View.INVISIBLE binding.llDocument.visibility = View.INVISIBLE
binding.llBookmark.visibility = View.INVISIBLE binding.llRecent.visibility = View.INVISIBLE
binding.llTool.visibility = View.INVISIBLE binding.llBookmark.visibility = View.INVISIBLE
binding.llTool.visibility = View.INVISIBLE
binding.llDelete.visibility = View.VISIBLE
binding.llShare.visibility = View.VISIBLE
}
fun cancelSelectUI() { binding.llDelete.visibility = View.VISIBLE
binding.llDelete.visibility = View.INVISIBLE binding.llShare.visibility = View.VISIBLE
binding.llShare.visibility = View.INVISIBLE } else {
binding.llDelete.visibility = View.INVISIBLE
binding.llShare.visibility = View.INVISIBLE
binding.ivScan.visibility = View.VISIBLE binding.ivScan.visibility = View.VISIBLE
binding.llDocument.visibility = View.VISIBLE binding.llDocument.visibility = View.VISIBLE
binding.llRecent.visibility = View.VISIBLE binding.llRecent.visibility = View.VISIBLE
binding.llBookmark.visibility = View.VISIBLE binding.llBookmark.visibility = View.VISIBLE
binding.llTool.visibility = View.VISIBLE binding.llTool.visibility = View.VISIBLE
}
} }
...@@ -197,4 +207,52 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView { ...@@ -197,4 +207,52 @@ class MainActivity : BaseActivity<ActivityMain2Binding>(), MainView {
} }
fun changeSearchUI(show: Boolean) {
if (show) {
binding.ivScan.visibility = View.INVISIBLE
binding.llBottom.visibility = View.INVISIBLE
} else {
binding.ivScan.visibility = View.VISIBLE
binding.llBottom.visibility = View.VISIBLE
}
}
companion object {
fun Activity.jumpDocument(item: DocumentBean) {
if (item.type == DocumentBean.TYPE_PDF) {
if (item.state == 0) {
startActivity(Intent(this, PdfActivity::class.java).apply {
putExtra("path", item.path)
})
}
if (item.state == 1) {
showPdfPwdDialog(
state = item.state,
path = item.path,
isCheckPwd = true,
verificationAction = { pwd ->
startActivity(Intent(this, PdfActivity::class.java).apply {
putExtra("path", item.path)
putExtra("pwd", pwd)
})
})
}
}
if (item.type == DocumentBean.TYPE_WORD) {
WordActivity.wordDocumentBean = item
WordActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
if (item.type == DocumentBean.TYPE_EXCEL) {
ExcelActivity.excelDocumentBean = item
ExcelActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
if (item.type == DocumentBean.TYPE_PPT) {
PptActivity.pptDocumentBean = item
PptActivity.launchDocViewer(this, 3, item.path, -1, 100)
}
}
}
} }
\ No newline at end of file
...@@ -207,5 +207,50 @@ ...@@ -207,5 +207,50 @@
</LinearLayout> </LinearLayout>
<FrameLayout
android:id="@+id/fl_search"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/white"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@id/cl_top">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_search"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
tools:listitem="@layout/item_document" />
<LinearLayout
android:id="@+id/ll_empty"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="60dp"
android:orientation="vertical"
android:visibility="gone"
tools:ignore="UseCompoundDrawables,UselessParent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/empty"
tools:ignore="ContentDescription" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
android:text="Empty"
android:textColor="#B1B4B9"
android:textSize="16sp"
tools:ignore="HardcodedText" />
</LinearLayout>
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>
\ 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