Commit 1a74a546 authored by wanglei's avatar wanglei

...

parent bcb64c57
......@@ -59,6 +59,7 @@ dependencies {
//第三方UI
implementation("io.github.cymchad:BaseRecyclerViewAdapterHelper4:4.1.4")
implementation("com.h6ah4i.android.widget.verticalseekbar:verticalseekbar:1.0.0")
implementation("com.github.angcyo.DslTablayout:TabLayout:3.5.5")
//mlkit
implementation("com.google.android.gms:play-services-mlkit-document-scanner:16.0.0-beta1")
......
......@@ -14,5 +14,8 @@ data class DocumentBean(
companion object {
const val TYPE_PDF = "type_pdf"
const val TYPE_WORD = "type_word"
const val TYPE_EXCEL = "type_excel"
const val TYPE_PPT = "type_ppt"
}
}
......@@ -8,7 +8,10 @@ import android.widget.ImageView
import androidx.recyclerview.widget.RecyclerView.ViewHolder
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_EXCEL
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PDF
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_PPT
import com.base.pdfviewerscannerwhite.bean.DocumentBean.Companion.TYPE_WORD
import com.base.pdfviewerscannerwhite.databinding.ItemDocumentBinding
import com.base.pdfviewerscannerwhite.ui.document.pdf.PdfBoxUtils
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatSize
......@@ -60,6 +63,15 @@ class DocumentAdapter : BaseQuickAdapter<DocumentBean, DocumentAdapter.DocumentV
binding.iv.setImageResource(res)
}
}
if (item.type == TYPE_WORD) {
binding.iv.setImageResource(R.mipmap.h_wordfiocn)
}
if (item.type == TYPE_EXCEL) {
binding.iv.setImageResource(R.mipmap.h_exceliocn)
}
if (item.type == TYPE_PPT) {
binding.iv.setImageResource(R.mipmap.h_pptfiocn)
}
val file = File(item.path)
binding.tvName.text = file.name
......
......@@ -36,7 +36,6 @@ class DocumentFragment() : BaseFragment<FragmentDocumentBinding>(), DocumentView
override fun setView() {
documentPresenter = DocumentPresenter(requireContext(), this, type, lifecycleScope)
initAdapter()
}
override fun onResume() {
......
......@@ -23,6 +23,16 @@ class DocumentPresenter(
if (type == DocumentBean.TYPE_PDF) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PDF)
}
if (type == DocumentBean.TYPE_WORD) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_DOC, ConstObject.MIME_TYPE_DOCX)
}
if (type == DocumentBean.TYPE_EXCEL) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_XLS, ConstObject.MIME_TYPE_XLSX)
}
if (type == DocumentBean.TYPE_PPT) {
selectionArgs = arrayOf(ConstObject.MIME_TYPE_PPT, ConstObject.MIME_TYPE_PPTX)
}
val bookmarkList = SpStringUtils.getSpStringList(SpStringUtils.BOOKMARK_KEY)
val list = context.getMediaFile(selectionArgs = selectionArgs)
......
......@@ -7,14 +7,17 @@ import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.angcyo.tablayout.DslTabIndicator
import com.base.pdfviewerscannerwhite.BuildConfig
import com.base.pdfviewerscannerwhite.R
import com.base.pdfviewerscannerwhite.bean.DocumentBean
import com.base.pdfviewerscannerwhite.databinding.ActivityMainBinding
import com.base.pdfviewerscannerwhite.helper.BaseActivity
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showDocumentRenameDialog
import com.base.pdfviewerscannerwhite.ui.view.DialogView.showStoragePermission
import com.base.pdfviewerscannerwhite.ui.view.RateDialog.showRateDialog
import com.base.pdfviewerscannerwhite.utils.KotlinExt.toFormatTime2
import com.base.pdfviewerscannerwhite.utils.LogEx
import com.base.pdfviewerscannerwhite.utils.PermissionUtils.checkStorePermission
import com.base.pdfviewerscannerwhite.utils.ToastUtils.toast
......@@ -29,7 +32,16 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
}
private val pdfFragment: DocumentFragment by lazy {
DocumentFragment()
DocumentFragment(DocumentBean.TYPE_PDF)
}
private val wordFragment: DocumentFragment by lazy {
DocumentFragment(DocumentBean.TYPE_WORD)
}
private val excelFragment: DocumentFragment by lazy {
DocumentFragment(DocumentBean.TYPE_EXCEL)
}
private val pptFragment: DocumentFragment by lazy {
DocumentFragment(DocumentBean.TYPE_PPT)
}
private val toolFragment: ToolFragment by lazy {
ToolFragment()
......@@ -37,16 +49,15 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
private var currentFragment: Fragment = pdfFragment
private val fragments by lazy {
mutableListOf(pdfFragment, toolFragment)
mutableListOf(pdfFragment, wordFragment, excelFragment, pptFragment, toolFragment)
}
override fun initView() {
mainPresenter = MainPresenter(this)
mainPresenter.initScannerLauncher(this)
binding.viewPager2.offscreenPageLimit = 4
binding.viewPager2.run {
isUserInputEnabled = false
adapter = object : FragmentStateAdapter(this@MainActivity) {
......@@ -66,11 +77,69 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
}
})
initTabLayout()
if (!checkStorePermission()) {
showStoragePermission(launcher)
}
}
private fun initTabLayout() {
val colorPdf = ContextCompat.getColor(this, R.color.color_f02f2b)
val colorWord = ContextCompat.getColor(this, R.color.color_0592ee)
val colorExcel = ContextCompat.getColor(this, R.color.color_149b55)
val colorPpt = ContextCompat.getColor(this, R.color.color_ffa127)
binding.tabLayoutDocument.apply {
tabIndicator.indicatorWidth =
this.resources.getDimensionPixelOffset(R.dimen.dp_50)
tabIndicator.indicatorHeight =
this.resources.getDimensionPixelOffset(R.dimen.dp_4)
tabIndicator.indicatorStyle =
DslTabIndicator.INDICATOR_STYLE_BOTTOM
configTabLayoutConfig {
onSelectIndexChange = { fromIndex, selectIndexList, reselect, fromUser ->
val toIndex = selectIndexList.first()
LogEx.logDebug(
TAG,
"toIndex=$toIndex fromIndex=$fromIndex selectIndexList=$selectIndexList reselect=$reselect fromUser=$fromUser"
)
when (toIndex) {
0 -> {
tabSelectColor = colorPdf
tabIndicator.indicatorColor = colorPdf
binding.viewPager2.currentItem = 0
}
1 -> {
tabSelectColor = colorWord
tabIndicator.indicatorColor = colorWord
binding.viewPager2.currentItem = 1
}
2 -> {
tabSelectColor = colorExcel
tabIndicator.indicatorColor = colorExcel
binding.viewPager2.currentItem = 2
}
3 -> {
tabSelectColor = colorPpt
tabIndicator.indicatorColor = colorPpt
binding.viewPager2.currentItem = 3
}
}
dslSelector.updateStyle()
}
}
}
}
var latViewPagerIndex = -1
@SuppressLint("ClickableViewAccessibility", "SetTextI18n")
override fun initListener() {
......@@ -79,32 +148,37 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
binding.llDocument.setOnClickListener {
binding.tvTittle.text = "Document"
binding.clTabLayout.visibility = View.VISIBLE
binding.viewPager2.setCurrentItem(latViewPagerIndex, false)
changeTabSelect(it)
binding.ivScan.visibility = View.VISIBLE
binding.clAction.visibility = View.VISIBLE
binding.ivPaixu.visibility = View.VISIBLE
binding.viewPager2.currentItem = 0
if (currentFragment is DocumentFragment) {
(currentFragment as DocumentFragment).setAllList()
}
}
binding.llRecent.setOnClickListener {
binding.tvTittle.text = "Document"
binding.clTabLayout.visibility = View.VISIBLE
binding.viewPager2.setCurrentItem(latViewPagerIndex, false)
binding.ivScan.visibility = View.VISIBLE
binding.clAction.visibility = View.VISIBLE
binding.ivPaixu.visibility = View.GONE
changeTabSelect(it)
binding.viewPager2.currentItem = 0
if (currentFragment is DocumentFragment) {
(currentFragment as DocumentFragment).setRecentList()
}
}
binding.llBookmark.setOnClickListener {
binding.tvTittle.text = "Document"
binding.clTabLayout.visibility = View.VISIBLE
binding.viewPager2.setCurrentItem(latViewPagerIndex, false)
binding.ivScan.visibility = View.VISIBLE
binding.clAction.visibility = View.VISIBLE
changeTabSelect(it)
binding.viewPager2.currentItem = 0
if (currentFragment is DocumentFragment) {
(currentFragment as DocumentFragment).setBookmarkList()
}
......@@ -112,8 +186,10 @@ class MainActivity : BaseActivity<ActivityMainBinding>(), MainView {
binding.llTool.setOnClickListener {
binding.tvTittle.text = "Tool"
binding.ivScan.visibility = View.GONE
binding.clTabLayout.visibility = View.GONE
changeTabSelect(it)
binding.viewPager2.currentItem = 1
latViewPagerIndex = binding.viewPager2.currentItem
binding.viewPager2.setCurrentItem(5, false)
binding.clAction.visibility = View.GONE
}
......
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#0592EE" android:state_selected="true" />
<item android:color="#B4B9BD" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#159B56" android:state_selected="true" />
<item android:color="#B4B9BD" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#F02F2B" android:state_selected="true" />
<item android:color="#B4B9BD" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="#FFA127" android:state_selected="true" />
<item android:color="#B4B9BD" android:state_selected="false" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="2dp" />
<!-- <solid android:color="@color/colorPrimary" />-->
<gradient
android:endColor="#FAF8D1"
android:startColor="#FAD4E7"
android:type="linear" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#99FAAB85">
android:color="#20000000">
<item
android:id="@android:id/mask"
android:width="110dp"
android:height="110dp"
android:gravity="center">
<shape android:shape="rectangle">
<solid android:color="#99FAAB85" />
<corners android:radius="110dp" />
</shape>
</item>
</ripple>
\ No newline at end of file
......@@ -94,6 +94,78 @@
app:layout_constraintBottom_toTopOf="@id/ll_bottom"
app:layout_constraintTop_toBottomOf="@id/cl_top">
<!-- 外层FrameLayout设置背景用来限定水波纹大小-->
<FrameLayout
android:id="@+id/cl_tabLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000">
<com.angcyo.tablayout.DslTabLayout
android:id="@+id/tabLayout_document"
android:layout_width="match_parent"
android:layout_height="50dp"
app:tab_badge_gravity="center"
app:tab_badge_offset_x="20dp"
app:tab_draw_indicator="true"
app:tab_enable_text_color="true"
app:tab_indicator_drawable="@drawable/indicator_bottom_line"
app:tab_indicator_height="3dp"
app:tab_item_is_equ_width="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ripple_select"
android:clipChildren="false"
android:clipToPadding="false"
android:gravity="center"
android:text="PDF"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@drawable/ripple_select"
android:clipChildren="false"
android:clipToPadding="false"
android:gravity="center"
android:paddingVertical="5dp"
android:text="Word"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ripple_select"
android:clipChildren="false"
android:clipToPadding="false"
android:gravity="center"
android:text="Excel"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ripple_select"
android:clipChildren="false"
android:clipToPadding="false"
android:gravity="center"
android:text="PPT"
android:textSize="16sp"
android:textStyle="bold"
tools:ignore="HardcodedText" />
</com.angcyo.tablayout.DslTabLayout>
</FrameLayout>
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/viewPager2"
......
......@@ -2,4 +2,8 @@
<resources>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="color_f02f2b">#F02F2B</color>
<color name="color_0592ee">#0592EE</color>
<color name="color_149b55">#149B55</color>
<color name="color_ffa127">#FFA127</color>
</resources>
\ No newline at end of file
<resources>
<dimen name="fab_margin">16dp</dimen>
<dimen name="dp_50">50dp</dimen>
<dimen name="dp_4">4dp</dimen>
</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