From e4f4fe05ce80680e50077719e41ddf8062eb9476 Mon Sep 17 00:00:00 2001 From: gedoor Date: Sat, 26 Dec 2020 16:48:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 22 +- .../bookshelf/base/BaseTabActivity.java | 6 +- .../kunfei/bookshelf/base/MBaseFragment.java | 13 - .../base/adapter/CommonRecyclerAdapter.kt | 425 ---------------- .../base/adapter/DiffRecyclerAdapter.kt | 209 ++++++++ .../base/adapter/InfiniteScrollListener.kt | 32 -- .../bookshelf/base/adapter/ItemAnimation.kt | 29 +- .../base/adapter/ItemViewDelegate.kt | 14 - .../bookshelf/base/adapter/ItemViewHolder.kt | 5 +- .../bookshelf/base/adapter/RecyclerAdapter.kt | 392 +++++++++++++++ .../base/adapter/SimpleRecyclerAdapter.kt | 22 - .../view/activity/AboutActivity.java | 92 +--- .../view/activity/BookCoverEditActivity.java | 36 +- .../view/activity/BookDetailActivity.java | 175 +++---- .../view/activity/BookInfoEditActivity.java | 91 ++-- .../view/activity/BookSourceActivity.java | 60 +-- .../view/activity/ChapterListActivity.java | 20 +- .../view/activity/ChoiceBookActivity.java | 35 +- .../view/activity/DonateActivity.java | 46 +- .../view/activity/DownloadActivity.java | 27 +- .../view/activity/ImportBookActivity.java | 64 +-- .../bookshelf/view/activity/MainActivity.java | 64 +-- .../view/activity/QRCodeScanActivity.java | 45 +- .../view/activity/ReadBookActivity.java | 476 ++++++++---------- .../view/activity/ReadStyleActivity.java | 77 +-- .../view/activity/ReplaceRuleActivity.java | 29 +- .../view/activity/SearchBookActivity.java | 161 +++--- .../view/activity/SettingActivity.java | 17 +- .../view/activity/SourceDebugActivity.java | 45 +- .../view/activity/SourceEditActivity.java | 63 +-- .../view/activity/SourceLoginActivity.java | 34 +- .../view/activity/ThemeSettingActivity.java | 18 +- .../view/activity/TxtChapterRuleActivity.java | 28 +- .../view/activity/WelcomeActivity.java | 21 +- .../view/adapter/ChapterListAdapter.java | 2 +- .../view/fragment/BookListFragment.java | 89 ++-- .../view/fragment/BookmarkFragment.java | 25 +- .../view/fragment/ChapterListFragment.java | 53 +- .../view/fragment/FileCategoryFragment.java | 67 ++- .../view/fragment/FindBookFragment.java | 90 ++-- .../view/fragment/LocalBookFragment.java | 36 +- .../view/popupwindow/KeyboardToolPop.kt | 36 +- .../view/popupwindow/MediaPlayerPop.java | 79 +-- .../view/popupwindow/MoreSettingPop.kt | 98 ++-- .../view/popupwindow/ReadAdjustMarginPop.kt | 136 +++-- .../view/popupwindow/ReadAdjustPop.java | 104 ++-- .../view/popupwindow/ReadBottomMenu.java | 120 ++--- .../view/popupwindow/ReadInterfacePop.java | 154 ++---- .../view/popupwindow/ReadLongPressPop.java | 28 +- .../widget/modialog/PageKeyDialog.kt | 26 +- .../recycler/refresh/RefreshRecyclerView.java | 137 +++-- .../main/res/layout/activity_book_detail.xml | 11 +- app/src/main/res/layout/activity_main.xml | 4 +- .../main/res/layout/activity_source_debug.xml | 2 +- .../main/res/layout/fragment_book_find.xml | 4 +- .../main/res/layout/fragment_book_list.xml | 6 +- app/src/main/res/layout/pop_media_player.xml | 2 +- build.gradle | 4 +- 58 files changed, 1793 insertions(+), 2413 deletions(-) delete mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/CommonRecyclerAdapter.kt create mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/DiffRecyclerAdapter.kt delete mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/InfiniteScrollListener.kt delete mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewDelegate.kt create mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/RecyclerAdapter.kt delete mode 100644 app/src/main/java/com/kunfei/bookshelf/base/adapter/SimpleRecyclerAdapter.kt diff --git a/app/build.gradle b/app/build.gradle index 7b67b0176b..b9ef474d2d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,6 +1,5 @@ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' -apply plugin: 'kotlin-android-extensions' apply plugin: 'org.greenrobot.greendao' apply plugin: 'com.google.firebase.crashlytics' apply plugin: "de.timfreiheit.resourceplaceholders" @@ -35,7 +34,9 @@ android { multiDexEnabled true } - + buildFeatures { + viewBinding true + } lintOptions { abortOnError false } @@ -73,8 +74,8 @@ resourcePlaceholders { } dependencies { - coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.0.10' - testImplementation 'junit:junit:4.13' + coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.1' + testImplementation 'junit:junit:4.13.1' implementation fileTree(dir: 'libs', include: ['*.jar']) implementation project(':basemvplib') @@ -87,14 +88,14 @@ dependencies { implementation "org.jetbrains.anko:anko-sdk27-listeners:$anko_version" //fireBase - implementation 'com.google.firebase:firebase-analytics:17.6.0' - implementation 'com.google.firebase:firebase-crashlytics:17.2.2' + implementation 'com.google.firebase:firebase-analytics:18.0.0' + implementation 'com.google.firebase:firebase-crashlytics:17.3.0' //androidX implementation 'androidx.multidex:multidex:2.0.1' - implementation 'androidx.constraintlayout:constraintlayout:2.0.2' + implementation 'androidx.constraintlayout:constraintlayout:2.0.4' implementation 'androidx.cardview:cardview:1.0.0' - implementation 'androidx.media:media:1.2.0' + implementation 'androidx.media:media:1.2.1' implementation 'androidx.legacy:legacy-support-v4:1.0.0' //google @@ -135,11 +136,6 @@ dependencies { //CircleImageView implementation 'de.hdodenhof:circleimageview:3.1.0' - //bind view - //noinspection AnnotationProcessorOnCompilePath - implementation 'com.jakewharton:butterknife:10.2.1' - annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.1' - //webServer implementation 'org.nanohttpd:nanohttpd:2.3.1' implementation 'org.nanohttpd:nanohttpd-websocket:2.3.1' diff --git a/app/src/main/java/com/kunfei/bookshelf/base/BaseTabActivity.java b/app/src/main/java/com/kunfei/bookshelf/base/BaseTabActivity.java index 6635629a6b..1eb839f955 100644 --- a/app/src/main/java/com/kunfei/bookshelf/base/BaseTabActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/base/BaseTabActivity.java @@ -13,17 +13,13 @@ import java.util.List; -import butterknife.BindView; - /** * Created by newbiechen on 17-4-24. */ public abstract class BaseTabActivity extends MBaseActivity { /**************View***************/ - @BindView(R.id.tab_tl_indicator) protected TabLayout mTlIndicator; - @BindView(R.id.tab_vp) protected ViewPager mVp; /**************Adapter***************/ protected TabFragmentPageAdapter tabFragmentPageAdapter; @@ -39,6 +35,8 @@ public abstract class BaseTabActivity extends MBaseActivit @Override protected void bindView() { super.bindView(); + mTlIndicator = findViewById(R.id.tab_tl_indicator); + mVp = findViewById(R.id.tab_vp); setUpTabLayout(); } diff --git a/app/src/main/java/com/kunfei/bookshelf/base/MBaseFragment.java b/app/src/main/java/com/kunfei/bookshelf/base/MBaseFragment.java index fc75bd3f4c..e2442a56dd 100644 --- a/app/src/main/java/com/kunfei/bookshelf/base/MBaseFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/base/MBaseFragment.java @@ -2,9 +2,6 @@ import android.content.SharedPreferences; import android.os.Bundle; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; import android.widget.Toast; import androidx.annotation.Nullable; @@ -25,22 +22,12 @@ public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } - @Override - protected View createView(LayoutInflater inflater, ViewGroup container) { - return inflater.inflate(createLayoutId(), container, false); - } - @Override public void onDestroy() { super.onDestroy(); detachView(); } - /** - * @return LayoutId - */ - public abstract int createLayoutId(); - /** * P层绑定 若无则返回null; */ diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/CommonRecyclerAdapter.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/CommonRecyclerAdapter.kt deleted file mode 100644 index 9a396c6653..0000000000 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/CommonRecyclerAdapter.kt +++ /dev/null @@ -1,425 +0,0 @@ -package com.kunfei.bookshelf.base.adapter - -import android.content.Context -import android.util.SparseArray -import android.view.LayoutInflater -import android.view.View -import android.view.ViewGroup -import androidx.recyclerview.widget.GridLayoutManager -import androidx.recyclerview.widget.RecyclerView -import java.util.* - - -/** - * Created by Invincible on 2017/11/24. - * - * 通用的adapter 可添加header,footer,以及不同类型item - */ -abstract class CommonRecyclerAdapter(protected val context: Context) : RecyclerView.Adapter() { - - constructor(context: Context, vararg delegates: Pair>) : this(context) { - addItemViewDelegates(*delegates) - } - - constructor(context: Context, vararg delegates: ItemViewDelegate) : this(context) { - addItemViewDelegates(*delegates) - } - - private val inflater: LayoutInflater = LayoutInflater.from(context) - - private var headerItems: SparseArray? = null - private var footerItems: SparseArray? = null - - private val itemDelegates: HashMap> = hashMapOf() - private val items: MutableList = mutableListOf() - - private val lock = Object() - - private var itemClickListener: ((holder: ItemViewHolder, item: ITEM) -> Unit)? = null - private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null - - private var itemAnimation: ItemAnimation? = null - - fun setOnItemClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Unit) { - itemClickListener = listener - } - - fun setOnItemLongClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Boolean) { - itemLongClickListener = listener - } - - fun bindToRecyclerView(recyclerView: RecyclerView) { - recyclerView.adapter = this - } - - fun > addItemViewDelegate(viewType: Int, delegate: DELEGATE) { - itemDelegates[viewType] = delegate - } - - fun > addItemViewDelegate(delegate: DELEGATE) { - itemDelegates[itemDelegates.size] = delegate - } - - fun > addItemViewDelegates(vararg delegates: DELEGATE) { - delegates.forEach { - addItemViewDelegate(it) - } - } - - fun addItemViewDelegates(vararg delegates: Pair>) { - delegates.forEach { - addItemViewDelegate(it.first, it.second) - } - } - - fun addHeaderView(header: View) { - synchronized(lock) { - if (headerItems == null) { - headerItems = SparseArray() - } - headerItems?.let { - val index = it.size() - it.put(TYPE_HEADER_VIEW + it.size(), header) - notifyItemInserted(index) - } - } - } - - fun addFooterView(footer: View) { - synchronized(lock) { - if (footerItems == null) { - footerItems = SparseArray() - } - footerItems?.let { - val index = getActualItemCount() + it.size() - it.put(TYPE_FOOTER_VIEW + it.size(), footer) - notifyItemInserted(index) - } - } - } - - fun removeHeaderView(header: View) { - synchronized(lock) { - headerItems?.let { - val index = it.indexOfValue(header) - if (index >= 0) { - it.remove(index) - notifyItemRemoved(index) - } - } - } - } - - fun removeFooterView(footer: View) { - synchronized(lock) { - footerItems?.let { - val index = it.indexOfValue(footer) - if (index >= 0) { - it.remove(index) - notifyItemRemoved(getActualItemCount() + index - 2) - } - } - } - } - - fun setItemsNoNotify(items: List?) { - synchronized(lock) { - if (this.items.isNotEmpty()) { - this.items.clear() - } - if (items != null) { - this.items.addAll(items) - } - } - } - - fun setItems(items: List?) { - synchronized(lock) { - if (this.items.isNotEmpty()) { - this.items.clear() - } - if (items != null) { - this.items.addAll(items) - } - notifyDataSetChanged() - } - } - - fun setItem(position: Int, item: ITEM) { - synchronized(lock) { - val oldSize = getActualItemCount() - if (position in 0 until oldSize) { - this.items[position] = item - notifyItemChanged(position + getHeaderCount()) - } - } - } - - fun addItem(item: ITEM) { - synchronized(lock) { - val oldSize = getActualItemCount() - if (this.items.add(item)) { - notifyItemInserted(oldSize + getHeaderCount()) - } - } - } - - fun addItems(position: Int, newItems: List) { - synchronized(lock) { - if (this.items.addAll(position, newItems)) { - notifyItemRangeInserted(position + getHeaderCount(), newItems.size) - } - } - } - - fun addItems(newItems: List) { - synchronized(lock) { - val oldSize = getActualItemCount() - if (this.items.addAll(newItems)) { - notifyItemRangeInserted(oldSize + getHeaderCount(), newItems.size) - } - } - } - - fun removeItem(position: Int) { - synchronized(lock) { - if (this.items.removeAt(position) != null) { - notifyItemRemoved(position + getHeaderCount()) - } - } - } - - fun removeItem(item: ITEM) { - synchronized(lock) { - if (this.items.remove(item)) { - notifyItemRemoved(this.items.indexOf(item) + getHeaderCount()) - } - } - } - - fun removeItems(items: List) { - synchronized(lock) { - if (this.items.removeAll(items)) { - notifyDataSetChanged() - } - } - } - - fun swapItem(oldPosition: Int, newPosition: Int) { - synchronized(lock) { - val size = getActualItemCount() - if (oldPosition in 0 until size && newPosition in 0 until size) { - val srcPosition = oldPosition + getHeaderCount() - val targetPosition = newPosition + getHeaderCount() - Collections.swap(this.items, srcPosition, targetPosition) - notifyItemChanged(srcPosition) - notifyItemChanged(targetPosition) - } - } - } - - fun updateItem(item: ITEM) { - synchronized(lock) { - val index = this.items.indexOf(item) - if (index >= 0) { - this.items[index] = item - notifyItemChanged(index) - } - } - } - - fun updateItem(position: Int, payload: Any) { - synchronized(lock) { - val size = getActualItemCount() - if (position in 0 until size) { - notifyItemChanged(position + getHeaderCount(), payload) - } - } - } - - fun updateItems(fromPosition: Int, toPosition: Int, payloads: Any) { - synchronized(lock) { - val size = getActualItemCount() - if (fromPosition in 0 until size && toPosition in 0 until size) { - notifyItemRangeChanged(fromPosition + getHeaderCount(), toPosition - fromPosition + 1, payloads) - } - } - } - - fun clearItems() { - synchronized(lock) { - this.items.clear() - notifyDataSetChanged() - } - } - - fun isEmpty(): Boolean { - return items.isEmpty() - } - - fun isNotEmpty(): Boolean { - return items.isNotEmpty() - } - - /** - * 除去header和footer - */ - fun getActualItemCount(): Int { - return items.size - } - - fun getHeaderCount(): Int { - return headerItems?.size() ?: 0 - } - - fun getFooterCount(): Int { - return footerItems?.size() ?: 0 - } - - fun getItem(position: Int): ITEM? = if (position in 0 until items.size) items[position] else null - - fun getItems(): List = items - - protected open fun getItemViewType(item: ITEM, position: Int): Int { - return 0 - } - - /** - * grid 模式下使用 - */ - protected open fun getSpanSize(item: ITEM, viewType: Int, position: Int): Int { - return 1 - } - - final override fun getItemCount(): Int { - return getActualItemCount() + getHeaderCount() + getFooterCount() - } - - final override fun getItemViewType(position: Int): Int { - return when { - isHeader(position) -> TYPE_HEADER_VIEW + position - isFooter(position) -> TYPE_FOOTER_VIEW + position - getActualItemCount() - getHeaderCount() - else -> getItem(getActualPosition(position))?.let { getItemViewType(it, getActualPosition(position)) } - ?: 0 - } - } - - override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { - return when { - viewType < TYPE_HEADER_VIEW + getHeaderCount() -> { - ItemViewHolder(headerItems!!.get(viewType)) - } - - viewType >= TYPE_FOOTER_VIEW -> { - ItemViewHolder(footerItems!!.get(viewType)) - } - - else -> { - val holder = ItemViewHolder(inflater.inflate(itemDelegates.getValue(viewType).layoutId, parent, false)) - - if (itemClickListener != null) { - holder.itemView.setOnClickListener { - getItem(holder.layoutPosition)?.let { - itemClickListener?.invoke(holder, it) - } - } - } - - if (itemLongClickListener != null) { - holder.itemView.setOnLongClickListener { - getItem(holder.layoutPosition)?.let { - itemLongClickListener?.invoke(holder, it) ?: true - } ?: true - } - } - - holder - } - } - } - - - final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) { - } - - final override fun onBindViewHolder(holder: ItemViewHolder, position: Int, payloads: MutableList) { - if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) { - getItem(holder.layoutPosition - getHeaderCount())?.let { - itemDelegates.getValue(getItemViewType(holder.layoutPosition)) - .convert(holder, it, payloads) - } - } - } - - override fun onViewAttachedToWindow(holder: ItemViewHolder) { - super.onViewAttachedToWindow(holder) - if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) { - addAnimation(holder) - } - } - - override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { - super.onAttachedToRecyclerView(recyclerView) - val manager = recyclerView.layoutManager - if (manager is GridLayoutManager) { - manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { - override fun getSpanSize(position: Int): Int { - return getItem(position)?.let { - if (isHeader(position) || isFooter(position)) manager.spanCount else getSpanSize( - it, getItemViewType(position), position - ) - } ?: manager.spanCount - } - } - } - } - - fun setItemAnimation(item: ItemAnimation) { - itemAnimation = item - } - - private fun isHeader(position: Int): Boolean { - return position < getHeaderCount() - } - - private fun isFooter(position: Int): Boolean { - return position >= getActualItemCount() + getHeaderCount() - } - - private fun getActualPosition(position: Int): Int { - return position - getHeaderCount() - } - - private fun addAnimation(holder: ItemViewHolder) { - if (itemAnimation == null) { - itemAnimation = ItemAnimation.create().enabled(true) - } - - itemAnimation?.let { - if (it.itemAnimEnabled) { - if (!it.itemAnimFirstOnly || holder.layoutPosition > it.itemAnimStartPosition) { - startAnimation(holder, it) - it.itemAnimStartPosition = holder.layoutPosition - } - } - } - } - - - protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) { - for (anim in item.itemAnimation.getAnimators(holder.itemView)) { - anim.setDuration(item.itemAnimDuration).start() - anim.interpolator = item.itemAnimInterpolator - } - } - - companion object { - private const val TYPE_HEADER_VIEW = Int.MIN_VALUE - private const val TYPE_FOOTER_VIEW = Int.MAX_VALUE - 999 - } - -} - - - - diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/DiffRecyclerAdapter.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/DiffRecyclerAdapter.kt new file mode 100644 index 0000000000..57de1ef8c4 --- /dev/null +++ b/app/src/main/java/com/kunfei/bookshelf/base/adapter/DiffRecyclerAdapter.kt @@ -0,0 +1,209 @@ +package com.kunfei.bookshelf.base.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.AsyncListDiffer +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import androidx.viewbinding.ViewBinding + +/** + * Created by Invincible on 2017/12/15. + */ +@Suppress("unused", "MemberVisibilityCanBePrivate") +abstract class DiffRecyclerAdapter(protected val context: Context) : + RecyclerView.Adapter() { + + val inflater: LayoutInflater = LayoutInflater.from(context) + + private val asyncListDiffer: AsyncListDiffer by lazy { + AsyncListDiffer(this, diffItemCallback).apply { + addListListener { _, _ -> + onCurrentListChanged() + } + } + } + + private val lock = Object() + + private var itemClickListener: ((holder: ItemViewHolder, item: ITEM) -> Unit)? = null + private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null + + var itemAnimation: ItemAnimation? = null + + abstract val diffItemCallback: DiffUtil.ItemCallback + + fun setOnItemClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Unit) { + itemClickListener = listener + } + + fun setOnItemLongClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Boolean) { + itemLongClickListener = listener + } + + fun bindToRecyclerView(recyclerView: RecyclerView) { + recyclerView.adapter = this + } + + fun setItems(items: List?) { + synchronized(lock) { + asyncListDiffer.submitList(items) + } + } + + fun setItem(position: Int, item: ITEM) { + synchronized(lock) { + val list = ArrayList(asyncListDiffer.currentList) + list[position] = item + asyncListDiffer.submitList(list) + } + } + + fun updateItem(item: ITEM) = + synchronized(lock) { + val index = asyncListDiffer.currentList.indexOf(item) + if (index >= 0) { + asyncListDiffer.currentList[index] = item + notifyItemChanged(index) + } + } + + fun updateItem(position: Int, payload: Any) = + synchronized(lock) { + val size = itemCount + if (position in 0 until size) { + notifyItemChanged(position, payload) + } + } + + fun updateItems(fromPosition: Int, toPosition: Int, payloads: Any) = + synchronized(lock) { + val size = itemCount + if (fromPosition in 0 until size && toPosition in 0 until size) { + notifyItemRangeChanged( + fromPosition, + toPosition - fromPosition + 1, + payloads + ) + } + } + + fun isEmpty() = asyncListDiffer.currentList.isEmpty() + + fun isNotEmpty() = asyncListDiffer.currentList.isNotEmpty() + + fun getItem(position: Int): ITEM? = asyncListDiffer.currentList.getOrNull(position) + + fun getItems(): List = asyncListDiffer.currentList + + /** + * grid 模式下使用 + */ + protected open fun getSpanSize(viewType: Int, position: Int) = 1 + + final override fun getItemCount() = getItems().size + + final override fun getItemViewType(position: Int): Int { + return 0 + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ItemViewHolder { + val holder = ItemViewHolder(getViewBinding(parent)) + + @Suppress("UNCHECKED_CAST") + registerListener(holder, (holder.binding as VB)) + + if (itemClickListener != null) { + holder.itemView.setOnClickListener { + getItem(holder.layoutPosition)?.let { + itemClickListener?.invoke(holder, it) + } + } + } + + if (itemLongClickListener != null) { + holder.itemView.setOnLongClickListener { + getItem(holder.layoutPosition)?.let { + itemLongClickListener?.invoke(holder, it) ?: true + } ?: true + } + } + + return holder + } + + protected abstract fun getViewBinding(parent: ViewGroup): VB + + final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {} + + open fun onCurrentListChanged() { + + } + + @Suppress("UNCHECKED_CAST") + final override fun onBindViewHolder( + holder: ItemViewHolder, + position: Int, + payloads: MutableList + ) { + getItem(holder.layoutPosition)?.let { + convert(holder, (holder.binding as VB), it, payloads) + } + } + + override fun onViewAttachedToWindow(holder: ItemViewHolder) { + super.onViewAttachedToWindow(holder) + addAnimation(holder) + } + + override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { + super.onAttachedToRecyclerView(recyclerView) + val manager = recyclerView.layoutManager + if (manager is GridLayoutManager) { + manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { + override fun getSpanSize(position: Int): Int { + return getSpanSize(getItemViewType(position), position) + } + } + } + } + + private fun addAnimation(holder: ItemViewHolder) { + itemAnimation?.let { + if (it.itemAnimEnabled) { + if (!it.itemAnimFirstOnly || holder.layoutPosition > it.itemAnimStartPosition) { + startAnimation(holder, it) + it.itemAnimStartPosition = holder.layoutPosition + } + } + } + } + + protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) { + item.itemAnimation?.let { + for (anim in it.getAnimators(holder.itemView)) { + anim.setDuration(item.itemAnimDuration).start() + anim.interpolator = item.itemAnimInterpolator + } + } + } + + /** + * 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题, + * 使用getItem(holder.layoutPosition)来获取item + */ + abstract fun convert( + holder: ItemViewHolder, + binding: VB, + item: ITEM, + payloads: MutableList + ) + + /** + * 注册事件 + */ + abstract fun registerListener(holder: ItemViewHolder, binding: VB) + +} \ No newline at end of file diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/InfiniteScrollListener.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/InfiniteScrollListener.kt deleted file mode 100644 index 23dc91aed7..0000000000 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/InfiniteScrollListener.kt +++ /dev/null @@ -1,32 +0,0 @@ -package com.kunfei.bookshelf.base.adapter - -import androidx.recyclerview.widget.LinearLayoutManager -import androidx.recyclerview.widget.RecyclerView - -/** - * Created by Invincible on 2017/12/15. - * - * 上拉加载更多 - */ -abstract class InfiniteScrollListener() : RecyclerView.OnScrollListener() { - private val loadMoreRunnable = Runnable { onLoadMore() } - - override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { -// if (dy < 0 || dataLoading.isDataLoading()) return - - val layoutManager: LinearLayoutManager = recyclerView.layoutManager as LinearLayoutManager - val visibleItemCount = recyclerView.childCount - val totalItemCount = layoutManager.itemCount - val firstVisibleItem = layoutManager.findFirstVisibleItemPosition() - - if (totalItemCount - visibleItemCount <= firstVisibleItem + VISIBLE_THRESHOLD) { - recyclerView.post(loadMoreRunnable) - } - } - - abstract fun onLoadMore() - - companion object { - private const val VISIBLE_THRESHOLD = 5 - } -} diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemAnimation.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemAnimation.kt index c767a896a5..90b809602d 100644 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemAnimation.kt +++ b/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemAnimation.kt @@ -7,31 +7,29 @@ import com.kunfei.bookshelf.base.adapter.animations.* /** * Created by Invincible on 2017/12/15. */ +@Suppress("unused") class ItemAnimation private constructor() { var itemAnimEnabled = false var itemAnimFirstOnly = true - var itemAnimation: BaseAnimation = SlideInBottomAnimation() + var itemAnimation: BaseAnimation? = null var itemAnimInterpolator: Interpolator = LinearInterpolator() var itemAnimDuration: Long = 300L var itemAnimStartPosition: Int = -1 - fun interpolator(interpolator: Interpolator): ItemAnimation { + fun interpolator(interpolator: Interpolator) = apply { itemAnimInterpolator = interpolator - return this } - fun duration(duration: Long): ItemAnimation { + fun duration(duration: Long) = apply { itemAnimDuration = duration - return this } - fun startPostion(startPos: Int): ItemAnimation { + fun startPosition(startPos: Int) = apply { itemAnimStartPosition = startPos - return this } - fun animation(animationType: Int = FADE_IN, animation: BaseAnimation? = null): ItemAnimation { + fun animation(animationType: Int = NONE, animation: BaseAnimation? = null) = apply { if (animation != null) { itemAnimation = animation } else { @@ -43,20 +41,18 @@ class ItemAnimation private constructor() { RIGHT_SLIDE_IN -> itemAnimation = SlideInRightAnimation() } } - return this } - fun enabled(enabled: Boolean): ItemAnimation { + fun enabled(enabled: Boolean) = apply { itemAnimEnabled = enabled - return this } - fun firstOnly(firstOnly: Boolean): ItemAnimation { + fun firstOnly(firstOnly: Boolean) = apply { itemAnimFirstOnly = firstOnly - return this } companion object { + const val NONE: Int = 0x00000000 /** * Use with [.openLoadAnimation] @@ -70,17 +66,18 @@ class ItemAnimation private constructor() { * Use with [.openLoadAnimation] */ const val BOTTOM_SLIDE_IN: Int = 0x00000003 + /** * Use with [.openLoadAnimation] */ const val LEFT_SLIDE_IN: Int = 0x00000004 + /** * Use with [.openLoadAnimation] */ const val RIGHT_SLIDE_IN: Int = 0x00000005 - fun create(): ItemAnimation { - return ItemAnimation() - } + fun create() = ItemAnimation() + } } \ No newline at end of file diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewDelegate.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewDelegate.kt deleted file mode 100644 index 75432a3fc0..0000000000 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewDelegate.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.kunfei.bookshelf.base.adapter - -import android.content.Context - -/** - * Created by Invincible on 2017/11/24. - * - * item代理, - */ -abstract class ItemViewDelegate(protected val context: Context, val layoutId: Int) { - - abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) - -} \ No newline at end of file diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewHolder.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewHolder.kt index f7d5d6fa3a..5b1b690a0d 100644 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewHolder.kt +++ b/app/src/main/java/com/kunfei/bookshelf/base/adapter/ItemViewHolder.kt @@ -1,9 +1,10 @@ package com.kunfei.bookshelf.base.adapter -import android.view.View import androidx.recyclerview.widget.RecyclerView +import androidx.viewbinding.ViewBinding /** * Created by Invincible on 2017/11/28. */ -class ItemViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) \ No newline at end of file +@Suppress("MemberVisibilityCanBePrivate") +class ItemViewHolder(val binding: ViewBinding) : RecyclerView.ViewHolder(binding.root) \ No newline at end of file diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/RecyclerAdapter.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/RecyclerAdapter.kt new file mode 100644 index 0000000000..8a5ad94e4c --- /dev/null +++ b/app/src/main/java/com/kunfei/bookshelf/base/adapter/RecyclerAdapter.kt @@ -0,0 +1,392 @@ +package com.kunfei.bookshelf.base.adapter + +import android.content.Context +import android.util.SparseArray +import android.view.LayoutInflater +import android.view.ViewGroup +import androidx.recyclerview.widget.DiffUtil +import androidx.recyclerview.widget.GridLayoutManager +import androidx.recyclerview.widget.RecyclerView +import androidx.viewbinding.ViewBinding +import java.util.* + +/** + * Created by Invincible on 2017/11/24. + * + * 通用的adapter 可添加header,footer,以及不同类型item + */ +@Suppress("unused", "MemberVisibilityCanBePrivate") +abstract class RecyclerAdapter(protected val context: Context) : + RecyclerView.Adapter() { + + val inflater: LayoutInflater = LayoutInflater.from(context) + + private val headerItems: SparseArray<(parent: ViewGroup) -> ViewBinding> by lazy { SparseArray() } + private val footerItems: SparseArray<(parent: ViewGroup) -> ViewBinding> by lazy { SparseArray() } + + private val items: MutableList = mutableListOf() + + private val lock = Object() + + private var itemClickListener: ((holder: ItemViewHolder, item: ITEM) -> Unit)? = null + private var itemLongClickListener: ((holder: ItemViewHolder, item: ITEM) -> Boolean)? = null + + var itemAnimation: ItemAnimation? = null + + fun setOnItemClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Unit) { + itemClickListener = listener + } + + fun setOnItemLongClickListener(listener: (holder: ItemViewHolder, item: ITEM) -> Boolean) { + itemLongClickListener = listener + } + + fun bindToRecyclerView(recyclerView: RecyclerView) { + recyclerView.adapter = this + } + + fun addHeaderView(header: ((parent: ViewGroup) -> ViewBinding)) { + synchronized(lock) { + val index = headerItems.size() + headerItems.put(TYPE_HEADER_VIEW + headerItems.size(), header) + notifyItemInserted(index) + } + } + + fun addFooterView(footer: ((parent: ViewGroup) -> ViewBinding)) = + synchronized(lock) { + val index = getActualItemCount() + footerItems.size() + footerItems.put(TYPE_FOOTER_VIEW + footerItems.size(), footer) + notifyItemInserted(index) + } + + + fun removeHeaderView(header: ((parent: ViewGroup) -> ViewBinding)) = + synchronized(lock) { + val index = headerItems.indexOfValue(header) + if (index >= 0) { + headerItems.remove(index) + notifyItemRemoved(index) + } + } + + fun removeFooterView(footer: ((parent: ViewGroup) -> ViewBinding)) = + synchronized(lock) { + val index = footerItems.indexOfValue(footer) + if (index >= 0) { + footerItems.remove(index) + notifyItemRemoved(getActualItemCount() + index - 2) + } + } + + fun setItems(items: List?) { + synchronized(lock) { + if (this.items.isNotEmpty()) { + this.items.clear() + } + if (items != null) { + this.items.addAll(items) + } + notifyDataSetChanged() + onCurrentListChanged() + } + } + + fun setItems(items: List?, diffResult: DiffUtil.DiffResult) { + synchronized(lock) { + if (this.items.isNotEmpty()) { + this.items.clear() + } + if (items != null) { + this.items.addAll(items) + } + diffResult.dispatchUpdatesTo(this) + onCurrentListChanged() + } + } + + fun setItem(position: Int, item: ITEM) { + synchronized(lock) { + val oldSize = getActualItemCount() + if (position in 0 until oldSize) { + this.items[position] = item + notifyItemChanged(position + getHeaderCount()) + } + onCurrentListChanged() + } + } + + fun addItem(item: ITEM) { + synchronized(lock) { + val oldSize = getActualItemCount() + if (this.items.add(item)) { + notifyItemInserted(oldSize + getHeaderCount()) + } + onCurrentListChanged() + } + } + + fun addItems(position: Int, newItems: List) { + synchronized(lock) { + if (this.items.addAll(position, newItems)) { + notifyItemRangeInserted(position + getHeaderCount(), newItems.size) + } + onCurrentListChanged() + } + } + + fun addItems(newItems: List) { + synchronized(lock) { + val oldSize = getActualItemCount() + if (this.items.addAll(newItems)) { + if (oldSize == 0 && getHeaderCount() == 0) { + notifyDataSetChanged() + } else { + notifyItemRangeInserted(oldSize + getHeaderCount(), newItems.size) + } + } + onCurrentListChanged() + } + } + + fun removeItem(position: Int) { + synchronized(lock) { + if (this.items.removeAt(position) != null) { + notifyItemRemoved(position + getHeaderCount()) + } + onCurrentListChanged() + } + } + + fun removeItem(item: ITEM) { + synchronized(lock) { + if (this.items.remove(item)) { + notifyItemRemoved(this.items.indexOf(item) + getHeaderCount()) + } + onCurrentListChanged() + } + } + + fun removeItems(items: List) { + synchronized(lock) { + if (this.items.removeAll(items)) { + notifyDataSetChanged() + } + onCurrentListChanged() + } + } + + fun swapItem(oldPosition: Int, newPosition: Int) { + synchronized(lock) { + val size = getActualItemCount() + if (oldPosition in 0 until size && newPosition in 0 until size) { + val srcPosition = oldPosition + getHeaderCount() + val targetPosition = newPosition + getHeaderCount() + Collections.swap(this.items, srcPosition, targetPosition) + notifyItemMoved(srcPosition, targetPosition) + } + onCurrentListChanged() + } + } + + fun updateItem(item: ITEM) = + synchronized(lock) { + val index = this.items.indexOf(item) + if (index >= 0) { + this.items[index] = item + notifyItemChanged(index) + } + onCurrentListChanged() + } + + fun updateItem(position: Int, payload: Any) = + synchronized(lock) { + val size = getActualItemCount() + if (position in 0 until size) { + notifyItemChanged(position + getHeaderCount(), payload) + } + } + + fun updateItems(fromPosition: Int, toPosition: Int, payloads: Any) = + synchronized(lock) { + val size = getActualItemCount() + if (fromPosition in 0 until size && toPosition in 0 until size) { + notifyItemRangeChanged( + fromPosition + getHeaderCount(), + toPosition - fromPosition + 1, + payloads + ) + } + } + + fun clearItems() = synchronized(lock) { + this.items.clear() + notifyDataSetChanged() + onCurrentListChanged() + } + + fun isEmpty() = items.isEmpty() + + fun isNotEmpty() = items.isNotEmpty() + + /** + * 除去header和footer + */ + fun getActualItemCount() = items.size + + + fun getHeaderCount() = headerItems.size() + + + fun getFooterCount() = footerItems.size() + + fun getItem(position: Int): ITEM? = items.getOrNull(position) + + fun getItemByLayoutPosition(position: Int) = items.getOrNull(position - getHeaderCount()) + + fun getItems(): List = items + + protected open fun getItemViewType(item: ITEM, position: Int) = 0 + + /** + * grid 模式下使用 + */ + protected open fun getSpanSize(viewType: Int, position: Int) = 1 + + final override fun getItemCount() = getActualItemCount() + getHeaderCount() + getFooterCount() + + final override fun getItemViewType(position: Int) = when { + isHeader(position) -> TYPE_HEADER_VIEW + position + isFooter(position) -> TYPE_FOOTER_VIEW + position - getActualItemCount() - getHeaderCount() + else -> getItem(getActualPosition(position))?.let { + getItemViewType(it, getActualPosition(position)) + } ?: 0 + } + + open fun onCurrentListChanged() { + + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int) = when { + viewType < TYPE_HEADER_VIEW + getHeaderCount() -> { + ItemViewHolder(headerItems.get(viewType).invoke(parent)) + } + + viewType >= TYPE_FOOTER_VIEW -> { + ItemViewHolder(footerItems.get(viewType).invoke(parent)) + } + + else -> { + val holder = ItemViewHolder(getViewBinding(parent)) + + @Suppress("UNCHECKED_CAST") + registerListener(holder, (holder.binding as VB)) + + if (itemClickListener != null) { + holder.itemView.setOnClickListener { + getItem(holder.layoutPosition)?.let { + itemClickListener?.invoke(holder, it) + } + } + } + + if (itemLongClickListener != null) { + holder.itemView.setOnLongClickListener { + getItem(holder.layoutPosition)?.let { + itemLongClickListener?.invoke(holder, it) ?: true + } ?: true + } + } + + holder + } + } + + protected abstract fun getViewBinding(parent: ViewGroup): VB + + final override fun onBindViewHolder(holder: ItemViewHolder, position: Int) {} + + @Suppress("UNCHECKED_CAST") + final override fun onBindViewHolder( + holder: ItemViewHolder, + position: Int, + payloads: MutableList + ) { + if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) { + getItem(holder.layoutPosition - getHeaderCount())?.let { + convert(holder, (holder.binding as VB), it, payloads) + } + } + } + + override fun onViewAttachedToWindow(holder: ItemViewHolder) { + super.onViewAttachedToWindow(holder) + if (!isHeader(holder.layoutPosition) && !isFooter(holder.layoutPosition)) { + addAnimation(holder) + } + } + + override fun onAttachedToRecyclerView(recyclerView: RecyclerView) { + super.onAttachedToRecyclerView(recyclerView) + val manager = recyclerView.layoutManager + if (manager is GridLayoutManager) { + manager.spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { + override fun getSpanSize(position: Int): Int { + return getSpanSize(getItemViewType(position), position) + } + } + } + } + + private fun isHeader(position: Int) = position < getHeaderCount() + + private fun isFooter(position: Int) = position >= getActualItemCount() + getHeaderCount() + + private fun getActualPosition(position: Int) = position - getHeaderCount() + + private fun addAnimation(holder: ItemViewHolder) { + itemAnimation?.let { + if (it.itemAnimEnabled) { + if (!it.itemAnimFirstOnly || holder.layoutPosition > it.itemAnimStartPosition) { + startAnimation(holder, it) + it.itemAnimStartPosition = holder.layoutPosition + } + } + } + } + + protected open fun startAnimation(holder: ItemViewHolder, item: ItemAnimation) { + item.itemAnimation?.let { + for (anim in it.getAnimators(holder.itemView)) { + anim.setDuration(item.itemAnimDuration).start() + anim.interpolator = item.itemAnimInterpolator + } + } + } + + /** + * 如果使用了事件回调,回调里不要直接使用item,会出现不更新的问题, + * 使用getItem(holder.layoutPosition)来获取item + */ + abstract fun convert( + holder: ItemViewHolder, + binding: VB, + item: ITEM, + payloads: MutableList + ) + + /** + * 注册事件 + */ + abstract fun registerListener(holder: ItemViewHolder, binding: VB) + + companion object { + private const val TYPE_HEADER_VIEW = Int.MIN_VALUE + private const val TYPE_FOOTER_VIEW = Int.MAX_VALUE - 999 + } + +} + + + + diff --git a/app/src/main/java/com/kunfei/bookshelf/base/adapter/SimpleRecyclerAdapter.kt b/app/src/main/java/com/kunfei/bookshelf/base/adapter/SimpleRecyclerAdapter.kt deleted file mode 100644 index 1166bcec45..0000000000 --- a/app/src/main/java/com/kunfei/bookshelf/base/adapter/SimpleRecyclerAdapter.kt +++ /dev/null @@ -1,22 +0,0 @@ -package com.kunfei.bookshelf.base.adapter - -import android.content.Context - -/** - * Created by Invincible on 2017/12/15. - */ -abstract class SimpleRecyclerAdapter(context: Context, private val layoutId: Int) : - CommonRecyclerAdapter(context) { - - init { - addItemViewDelegate(object : ItemViewDelegate(context, layoutId) { - - override fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) { - this@SimpleRecyclerAdapter.convert(holder, item, payloads) - } - - }) - } - - abstract fun convert(holder: ItemViewHolder, item: ITEM, payloads: MutableList) -} \ No newline at end of file diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/AboutActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/AboutActivity.java index 39e73f452e..eb68f2ea73 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/AboutActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/AboutActivity.java @@ -9,13 +9,9 @@ import android.os.Bundle; import android.view.KeyEvent; import android.view.MenuItem; -import android.widget.LinearLayout; import android.widget.PopupMenu; -import android.widget.TextView; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import androidx.cardview.widget.CardView; import com.google.zxing.EncodeHintType; import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel; @@ -24,12 +20,11 @@ import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.base.observer.MySingleObserver; +import com.kunfei.bookshelf.databinding.ActivityAboutBinding; import com.kunfei.bookshelf.utils.RxUtils; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.widget.modialog.MoDialogHUD; -import butterknife.BindView; -import butterknife.ButterKnife; import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; @@ -40,63 +35,10 @@ */ public class AboutActivity extends MBaseActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.tv_version) - TextView tvVersion; - @BindView(R.id.vw_version) - CardView vwVersion; - @BindView(R.id.tv_donate) - TextView tvDonate; - @BindView(R.id.vw_donate) - CardView vwDonate; - @BindView(R.id.tv_scoring) - TextView tvScoring; - @BindView(R.id.vw_scoring) - CardView vwScoring; - @BindView(R.id.tv_git) - TextView tvGit; - @BindView(R.id.vw_git) - CardView vwGit; - @BindView(R.id.tv_disclaimer) - TextView tvDisclaimer; - @BindView(R.id.vw_disclaimer) - CardView vwDisclaimer; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.tv_mail) - TextView tvMail; - @BindView(R.id.vw_mail) - CardView vwMail; - @BindView(R.id.tv_update) - TextView tvUpdate; - @BindView(R.id.vw_update) - CardView vwUpdate; - @BindView(R.id.tv_qq) - TextView tvQq; - @BindView(R.id.vw_qq) - CardView vwQq; - @BindView(R.id.tv_app_summary) - TextView tvAppSummary; - @BindView(R.id.tv_update_log) - TextView tvUpdateLog; - @BindView(R.id.vw_update_log) - CardView vwUpdateLog; - @BindView(R.id.tv_home_page) - TextView tvHomePage; - @BindView(R.id.vw_home_page) - CardView vwHomePage; - @BindView(R.id.tv_faq) - TextView tvFaq; - @BindView(R.id.vw_faq) - CardView vwFaq; - @BindView(R.id.tv_share) - TextView tvShare; - @BindView(R.id.vw_share) - CardView vwShare; private MoDialogHUD moDialogHUD; private String[] allQQ = new String[]{"(公众号)开源阅读", "(QQ群)701903217", "(QQ群)805192012", "(QQ群)773736122", "(QQ群)981838750"}; + private ActivityAboutBinding binding; public static void startThis(Context context) { Intent intent = new Intent(context, AboutActivity.class); @@ -117,7 +59,8 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_about); + binding = ActivityAboutBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -127,22 +70,21 @@ protected void initData() { @Override protected void bindView() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); - tvVersion.setText(getString(R.string.version_name, MApplication.getVersionName())); + binding.tvVersion.setText(getString(R.string.version_name, MApplication.getVersionName())); } @Override protected void bindEvent() { - vwDonate.setOnClickListener(view -> DonateActivity.startThis(this)); - vwScoring.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, "market://details?id=" + getPackageName())); - vwMail.setOnClickListener(view -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com")); - vwGit.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))); - vwDisclaimer.setOnClickListener(view -> moDialogHUD.showAssetMarkdown("disclaimer.md")); - vwUpdate.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.latest_release_url))); - vwHomePage.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.home_page_url))); - vwQq.setOnClickListener(view -> { + binding.vwDonate.setOnClickListener(view -> DonateActivity.startThis(this)); + binding.vwScoring.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, "market://details?id=" + getPackageName())); + binding.vwMail.setOnClickListener(view -> openIntent(Intent.ACTION_SENDTO, "mailto:kunfei.ge@gmail.com")); + binding.vwGit.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.this_github_url))); + binding.vwDisclaimer.setOnClickListener(view -> moDialogHUD.showAssetMarkdown("disclaimer.md")); + binding.vwUpdate.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.latest_release_url))); + binding.vwHomePage.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, getString(R.string.home_page_url))); + binding.vwQq.setOnClickListener(view -> { PopupMenu popupMenu = new PopupMenu(AboutActivity.this, view); for (String qq : allQQ) { popupMenu.getMenu().add(qq); @@ -153,9 +95,9 @@ protected void bindEvent() { }); popupMenu.show(); }); - vwUpdateLog.setOnClickListener(view -> moDialogHUD.showAssetMarkdown("updateLog.md")); - vwFaq.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, "https://mp.weixin.qq.com/s?__biz=MzU2NjU0NjM1Mg==&mid=100000032&idx=1&sn=53e52168caf1ad9e507ab56381c45f1f&chksm=7cab9bff4bdc12e925e282effc1d4993a8652c248abc6169bd31d6fac133628fad54cf516043&mpshare=1&scene=1&srcid=0321CjdEk21qy8WjDgZ0I6sW&key=08039a5457341b11b054342370cc5462829ae3b54e4b265c42e28361773a6fa0e3105d706160d75b097b3ae41148dda265e2416b88f6b6a2391c1f33ec9f0bc62ea9edc86b75344494b598842ad620ac&ascene=1&uin=NzUwMTUxNzIx&devicetype=Windows+10&version=62060739&lang=zh_CN&pass_ticket=%2FD6keuc%2Fx%2Ba8YhupUUvefch8Gm07zVHa34Df5m1waxWQuCOohBN70NNcDEJsKE%2BV")); - vwShare.setOnClickListener(view -> { + binding.vwUpdateLog.setOnClickListener(view -> moDialogHUD.showAssetMarkdown("updateLog.md")); + binding.vwFaq.setOnClickListener(view -> openIntent(Intent.ACTION_VIEW, "https://mp.weixin.qq.com/s?__biz=MzU2NjU0NjM1Mg==&mid=100000032&idx=1&sn=53e52168caf1ad9e507ab56381c45f1f&chksm=7cab9bff4bdc12e925e282effc1d4993a8652c248abc6169bd31d6fac133628fad54cf516043&mpshare=1&scene=1&srcid=0321CjdEk21qy8WjDgZ0I6sW&key=08039a5457341b11b054342370cc5462829ae3b54e4b265c42e28361773a6fa0e3105d706160d75b097b3ae41148dda265e2416b88f6b6a2391c1f33ec9f0bc62ea9edc86b75344494b598842ad620ac&ascene=1&uin=NzUwMTUxNzIx&devicetype=Windows+10&version=62060739&lang=zh_CN&pass_ticket=%2FD6keuc%2Fx%2Ba8YhupUUvefch8Gm07zVHa34Df5m1waxWQuCOohBN70NNcDEJsKE%2BV")); + binding.vwShare.setOnClickListener(view -> { String url = "https://www.coolapk.com/apk/com.gedoor.monkeybook"; Single.create((SingleOnSubscribe) emitter -> { QRCodeEncoder.HINTS.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.H); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookCoverEditActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookCoverEditActivity.java index 08cff34b39..007d47b46e 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookCoverEditActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookCoverEditActivity.java @@ -9,10 +9,8 @@ import android.widget.TextView; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.bumptech.glide.Glide; import com.kunfei.basemvplib.impl.IPresenter; @@ -24,6 +22,7 @@ import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.bean.SearchBookBean; import com.kunfei.bookshelf.dao.SearchBookBeanDao; +import com.kunfei.bookshelf.databinding.ActivityBookCoverEditBinding; import com.kunfei.bookshelf.model.BookSourceManager; import com.kunfei.bookshelf.model.SearchBookModel; import com.kunfei.bookshelf.utils.RxUtils; @@ -33,20 +32,11 @@ import java.util.ArrayList; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; public class BookCoverEditActivity extends MBaseActivity { - - @BindView(R.id.rf_rv_change_cover) - RecyclerView changeCover; - @BindView(R.id.swipe_refresh_layout) - SwipeRefreshLayout swipeRefreshLayout; - @BindView(R.id.toolbar) - Toolbar toolbar; - + private ActivityBookCoverEditBinding binding; private SearchBookModel searchBookModel; private String name; private String author; @@ -57,9 +47,9 @@ public class BookCoverEditActivity extends MBaseActivity { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_book_cover_edit); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivityBookCoverEditBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -90,17 +80,17 @@ protected void initData() { name = getIntent().getStringExtra("name"); author = getIntent().getStringExtra("author"); ChangeCoverAdapter changeCoverAdapter = new ChangeCoverAdapter(); - changeCover.setLayoutManager(new GridLayoutManager(this, 3)); - changeCover.setAdapter(changeCoverAdapter); + binding.rfRvChangeCover.setLayoutManager(new GridLayoutManager(this, 3)); + binding.rfRvChangeCover.setAdapter(changeCoverAdapter); SearchBookModel.OnSearchListener searchListener = new SearchBookModel.OnSearchListener() { @Override public void refreshSearchBook() { - swipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayout.setRefreshing(true); } @Override public void refreshFinish(Boolean value) { - swipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayout.setRefreshing(false); isLoading = false; } @@ -127,7 +117,7 @@ public void loadMoreSearchBook(List value) { @Override public void searchBookError(Throwable throwable) { - swipeRefreshLayout.setRefreshing(false); + binding.swipeRefreshLayout.setRefreshing(false); isLoading = false; } @@ -137,8 +127,8 @@ public int getItemCount() { } }; searchBookModel = new SearchBookModel(searchListener); - swipeRefreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); - swipeRefreshLayout.setOnRefreshListener(() -> { + binding.swipeRefreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); + binding.swipeRefreshLayout.setOnRefreshListener(() -> { if (!isLoading) { isLoading = true; long time = System.currentTimeMillis(); @@ -166,7 +156,7 @@ public int getItemCount() { @Override public void onSuccess(Boolean aBoolean) { if (urls.isEmpty()) { - swipeRefreshLayout.setRefreshing(true); + binding.swipeRefreshLayout.setRefreshing(true); long time = System.currentTimeMillis(); searchBookModel.setSearchTime(time); searchBookModel.search(name, time, new ArrayList<>(), false); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java index f750771e41..81abea145b 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookDetailActivity.java @@ -18,14 +18,10 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.View; -import android.widget.ImageView; import android.widget.PopupMenu; import android.widget.RadioButton; -import android.widget.RadioGroup; -import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.appcompat.widget.AppCompatImageView; import androidx.core.content.FileProvider; import com.bumptech.glide.RequestBuilder; @@ -46,6 +42,7 @@ import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.bean.SearchBookBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivityBookDetailBinding; import com.kunfei.bookshelf.help.BlurTransformation; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.help.ImageLoader; @@ -55,15 +52,12 @@ import com.kunfei.bookshelf.presenter.contract.BookDetailContract; import com.kunfei.bookshelf.utils.RxUtils; import com.kunfei.bookshelf.utils.StringUtils; -import com.kunfei.bookshelf.widget.image.CoverImageView; import com.kunfei.bookshelf.widget.modialog.ChangeSourceDialog; import com.kunfei.bookshelf.widget.modialog.MoDialogHUD; import java.io.File; import java.io.FileOutputStream; -import butterknife.BindView; -import butterknife.ButterKnife; import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; @@ -71,41 +65,7 @@ import static com.kunfei.bookshelf.presenter.BookDetailPresenter.FROM_BOOKSHELF; public class BookDetailActivity extends MBaseActivity implements BookDetailContract.View { - @BindView(R.id.ifl_content) - View vwContent; - @BindView(R.id.book_info_main) - View bookInfoMain; - @BindView(R.id.iv_menu) - ImageView ivMenu; - @BindView(R.id.iv_blur_cover) - AppCompatImageView ivBlurCover; - @BindView(R.id.iv_cover) - CoverImageView ivCover; - @BindView(R.id.tv_name) - TextView tvName; - @BindView(R.id.tv_author) - TextView tvAuthor; - @BindView(R.id.tv_origin) - TextView tvOrigin; - @BindView(R.id.iv_web) - ImageView ivWeb; - @BindView(R.id.tv_chapter) - TextView tvChapter; - @BindView(R.id.tv_intro) - TextView tvIntro; - @BindView(R.id.tv_shelf) - TextView tvShelf; - @BindView(R.id.tv_read) - TextView tvRead; - @BindView(R.id.tv_loading) - TextView tvLoading; - @BindView(R.id.tv_change_origin) - TextView tvChangeOrigin; - @BindView(R.id.rg_book_group) - RadioGroup rgBookGroup; - @BindView(R.id.tv_chapter_size) - TextView tvChapterSize; - + private ActivityBookDetailBinding binding; private MoDialogHUD moDialogHUD; private String author; private BookShelfBean bookShelfBean; @@ -125,7 +85,8 @@ protected BookDetailContract.Presenter initInjector() { @Override protected void onCreateActivity() { setTheme(R.style.CAppTransparentTheme); - setContentView(R.layout.activity_book_detail); + binding = ActivityBookDetailBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -144,33 +105,32 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void bindView() { - ButterKnife.bind(this); //弹窗 moDialogHUD = new MoDialogHUD(this); - tvIntro.setMovementMethod(ScrollingMovementMethod.getInstance()); + binding.tvIntro.setMovementMethod(ScrollingMovementMethod.getInstance()); if (mPresenter.getOpenFrom() == FROM_BOOKSHELF) { updateView(); } else { if (mPresenter.getSearchBook() == null) return; SearchBookBean searchBookBean = mPresenter.getSearchBook(); upImageView(searchBookBean.getCoverUrl(), searchBookBean.getName(), searchBookBean.getAuthor()); - tvName.setText(searchBookBean.getName()); + binding.tvName.setText(searchBookBean.getName()); author = searchBookBean.getAuthor(); - tvAuthor.setText(TextUtils.isEmpty(author) ? "未知" : author); + binding.tvAuthor.setText(TextUtils.isEmpty(author) ? "未知" : author); bookUrl = searchBookBean.getNoteUrl(); String origin = TextUtils.isEmpty(searchBookBean.getOrigin()) ? "未知" : searchBookBean.getOrigin(); - tvOrigin.setText(origin); - tvChapter.setText(searchBookBean.getLastChapter()); // newest - tvIntro.setText(StringUtils.formatHtml2Intor(searchBookBean.getIntroduce())); - tvShelf.setText(R.string.add_to_shelf); - tvRead.setText(R.string.start_read); - tvRead.setOnClickListener(v -> { + binding.tvOrigin.setText(origin); + binding.tvChapter.setText(searchBookBean.getLastChapter()); // newest + binding.tvIntro.setText(StringUtils.formatHtml2Intor(searchBookBean.getIntroduce())); + binding.tvShelf.setText(R.string.add_to_shelf); + binding.tvRead.setText(R.string.start_read); + binding.tvRead.setOnClickListener(v -> { //放入书架 }); - tvIntro.setVisibility(View.INVISIBLE); - tvLoading.setVisibility(View.VISIBLE); - tvLoading.setText(R.string.loading); - tvLoading.setOnClickListener(null); + binding.tvIntro.setVisibility(View.INVISIBLE); + binding.tvLoading.setVisibility(View.VISIBLE); + binding.tvLoading.setText(R.string.loading); + binding.tvLoading.setOnClickListener(null); } } @@ -180,46 +140,46 @@ public void updateView() { BookInfoBean bookInfoBean; if (null != bookShelfBean) { if (BookShelfBean.LOCAL_TAG.equals(bookShelfBean.getTag())) { - ivMenu.setVisibility(View.GONE); + binding.ivMenu.setVisibility(View.GONE); } else { - ivMenu.setVisibility(View.VISIBLE); + binding.ivMenu.setVisibility(View.VISIBLE); } bookInfoBean = bookShelfBean.getBookInfoBean(); - tvName.setText(bookInfoBean.getName()); + binding.tvName.setText(bookInfoBean.getName()); author = bookInfoBean.getAuthor(); - tvAuthor.setText(TextUtils.isEmpty(author) ? "未知" : author); + binding.tvAuthor.setText(TextUtils.isEmpty(author) ? "未知" : author); bookUrl = bookInfoBean.getNoteUrl(); - ((RadioButton) rgBookGroup.getChildAt(bookShelfBean.getGroup())).setChecked(true); + ((RadioButton) binding.rgBookGroup.getChildAt(bookShelfBean.getGroup())).setChecked(true); if (mPresenter.getInBookShelf()) { - tvChapter.setText(bookShelfBean.getDurChapterName()); // last - tvShelf.setText(R.string.remove_from_bookshelf); - tvRead.setText(R.string.continue_read); - tvShelf.setOnClickListener(v -> { + binding.tvChapter.setText(bookShelfBean.getDurChapterName()); // last + binding.tvShelf.setText(R.string.remove_from_bookshelf); + binding.tvRead.setText(R.string.continue_read); + binding.tvShelf.setOnClickListener(v -> { //从书架移出 mPresenter.removeFromBookShelf(); }); } else { if (!TextUtils.isEmpty(bookShelfBean.getLastChapterName())) { - tvChapter.setText(bookShelfBean.getLastChapterName()); // last + binding.tvChapter.setText(bookShelfBean.getLastChapterName()); // last } - tvShelf.setText(R.string.add_to_shelf); - tvRead.setText(R.string.start_read); - tvShelf.setOnClickListener(v -> { + binding.tvShelf.setText(R.string.add_to_shelf); + binding.tvRead.setText(R.string.start_read); + binding.tvShelf.setOnClickListener(v -> { //放入书架 mPresenter.addToBookShelf(); }); } - tvIntro.setText(StringUtils.formatHtml2Intor(bookInfoBean.getIntroduce())); - if (tvIntro.getVisibility() != View.VISIBLE) { - tvIntro.setVisibility(View.VISIBLE); + binding.tvIntro.setText(StringUtils.formatHtml2Intor(bookInfoBean.getIntroduce())); + if (binding.tvIntro.getVisibility() != View.VISIBLE) { + binding.tvIntro.setVisibility(View.VISIBLE); } String origin = bookInfoBean.getOrigin(); if (!TextUtils.isEmpty(origin)) { - ivWeb.setVisibility(View.VISIBLE); - tvOrigin.setText(origin); + binding.ivWeb.setVisibility(View.VISIBLE); + binding.tvOrigin.setText(origin); } else { - ivWeb.setVisibility(View.INVISIBLE); - tvOrigin.setVisibility(View.INVISIBLE); + binding.ivWeb.setVisibility(View.INVISIBLE); + binding.tvOrigin.setVisibility(View.INVISIBLE); } if (!TextUtils.isEmpty(bookShelfBean.getCustomCoverPath())) { upImageView(bookShelfBean.getCustomCoverPath(), bookInfoBean.getName(), bookInfoBean.getAuthor()); @@ -227,35 +187,35 @@ public void updateView() { upImageView(bookInfoBean.getCoverUrl(), bookInfoBean.getName(), bookInfoBean.getAuthor()); } if (bookShelfBean.getTag().equals(BookShelfBean.LOCAL_TAG)) { - tvChangeOrigin.setVisibility(View.INVISIBLE); + binding.tvChangeOrigin.setVisibility(View.INVISIBLE); } else { - tvChangeOrigin.setVisibility(View.VISIBLE); + binding.tvChangeOrigin.setVisibility(View.VISIBLE); } upChapterSizeTv(); } - tvLoading.setVisibility(View.GONE); - tvLoading.setOnClickListener(null); + binding.tvLoading.setVisibility(View.GONE); + binding.tvLoading.setOnClickListener(null); } @Override public void getBookShelfError() { - tvLoading.setVisibility(View.VISIBLE); - tvLoading.setText(R.string.load_error_retry); - tvLoading.setOnClickListener(v -> { - tvLoading.setText(R.string.loading); - tvLoading.setOnClickListener(null); + binding.tvLoading.setVisibility(View.VISIBLE); + binding.tvLoading.setText(R.string.load_error_retry); + binding.tvLoading.setOnClickListener(v -> { + binding.tvLoading.setText(R.string.loading); + binding.tvLoading.setOnClickListener(null); mPresenter.getBookShelfInfo(); }); } private void upImageView(String path, String name, String author) { - ivCover.load(path, name, author); + binding.ivCover.load(path, name, author); ImageLoader.INSTANCE.load(this, path) .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) .centerCrop() .apply(RequestOptions.bitmapTransform(new BlurTransformation(this, 25))) - .into(ivBlurCover); //模糊、渐变、缩小效果 + .into(binding.ivBlurCover); //模糊、渐变、缩小效果 } private RequestBuilder defaultCover() { @@ -264,9 +224,9 @@ private RequestBuilder defaultCover() { } private void refresh() { - tvLoading.setVisibility(View.VISIBLE); - tvLoading.setText(R.string.loading); - tvLoading.setOnClickListener(null); + binding.tvLoading.setVisibility(View.VISIBLE); + binding.tvLoading.setText(R.string.loading); + binding.tvLoading.setOnClickListener(null); mPresenter.getBookShelf().getBookInfoBean().setBookInfoHtml(null); mPresenter.getBookShelf().getBookInfoBean().setChapterListHtml(null); mPresenter.getBookShelfInfo(); @@ -275,7 +235,7 @@ private void refresh() { @SuppressLint("ClickableViewAccessibility") @Override protected void bindEvent() { - tvName.setOnClickListener(v -> { + binding.tvName.setOnClickListener(v -> { if (bookShelfBean == null) return; if (TextUtils.isEmpty(bookShelfBean.getBookInfoBean().getName())) return; if (!AppActivityManager.getInstance().isExist(SearchBookActivity.class)) { @@ -285,16 +245,18 @@ protected void bindEvent() { } finish(); }); - ivBlurCover.setOnClickListener(null); - vwContent.setOnClickListener(v -> finish()); - - tvChangeOrigin.setOnClickListener(view -> + binding.ivBlurCover.setOnClickListener(null); + binding.iflContent.setOnClickListener(v -> finish()); + binding.tvToc.setOnClickListener(v -> { + ChapterListActivity.startThis(this, mPresenter.getBookShelf(), mPresenter.getChapterList()); + }); + binding.tvChangeOrigin.setOnClickListener(view -> ChangeSourceDialog.builder(BookDetailActivity.this, mPresenter.getBookShelf()) .setCallback(searchBookBean -> { - tvOrigin.setText(searchBookBean.getOrigin()); - tvLoading.setVisibility(View.VISIBLE); - tvLoading.setText(R.string.loading); - tvLoading.setOnClickListener(null); + binding.tvOrigin.setText(searchBookBean.getOrigin()); + binding.tvLoading.setVisibility(View.VISIBLE); + binding.tvLoading.setText(R.string.loading); + binding.tvLoading.setOnClickListener(null); if (mPresenter.getOpenFrom() == FROM_BOOKSHELF) { mPresenter.changeBookSource(searchBookBean); } else { @@ -303,7 +265,7 @@ protected void bindEvent() { } }).show()); - tvRead.setOnClickListener(v -> { + binding.tvRead.setOnClickListener(v -> { if (!mPresenter.getInBookShelf()) { BookshelfHelp.saveBookToShelf(mPresenter.getBookShelf()); if (mPresenter.getChapterList() != null) @@ -331,7 +293,7 @@ protected void bindEvent() { } }); - ivMenu.setOnClickListener(view -> { + binding.ivMenu.setOnClickListener(view -> { PopupMenu popupMenu = new PopupMenu(this, view, Gravity.END); if (!mPresenter.getBookShelf().getTag().equals(BookShelfBean.LOCAL_TAG)) { popupMenu.getMenu().add(Menu.NONE, R.id.menu_refresh, Menu.NONE, R.string.refresh); @@ -386,13 +348,13 @@ protected void bindEvent() { popupMenu.show(); }); - ivCover.setOnClickListener(view -> { + binding.ivCover.setOnClickListener(view -> { if (mPresenter.getOpenFrom() == FROM_BOOKSHELF) { BookInfoEditActivity.startThis(this, mPresenter.getBookShelf().getNoteUrl()); } }); - tvAuthor.setOnClickListener(view -> { + binding.tvAuthor.setOnClickListener(view -> { if (TextUtils.isEmpty(author)) return; if (!AppActivityManager.getInstance().isExist(SearchBookActivity.class)) { SearchBookActivity.startByKey(this, author); @@ -402,7 +364,7 @@ protected void bindEvent() { finish(); }); - rgBookGroup.setOnCheckedChangeListener((radioGroup, i) -> { + binding.rgBookGroup.setOnCheckedChangeListener((radioGroup, i) -> { View checkView = radioGroup.findViewById(i); if (!checkView.isPressed()) { return; @@ -432,7 +394,6 @@ private void upChapterSizeTv() { if (newChapterNum > 0) chapterSize = String.format("(+%d)", newChapterNum); } - tvChapterSize.setText(chapterSize); } @Override @@ -488,7 +449,7 @@ else if (url.length() > 100) public void onSuccess(Bitmap bitmap2) { try { - File file = new File(BookDetailActivity.this.getExternalCacheDir(), tvName.getText().toString() + ".png"); + File file = new File(BookDetailActivity.this.getExternalCacheDir(), binding.tvName.getText().toString() + ".png"); FileOutputStream fOut = new FileOutputStream(file); bitmap2.compress(Bitmap.CompressFormat.PNG, 80, fOut); fOut.flush(); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookInfoEditActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookInfoEditActivity.java index 2ee516e0a2..961c6e532c 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookInfoEditActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookInfoEditActivity.java @@ -7,64 +7,31 @@ import android.view.KeyEvent; import android.view.Menu; import android.view.MenuItem; -import android.widget.EditText; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import com.google.android.material.textfield.TextInputLayout; import com.hwangjr.rxbus.RxBus; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivityBookInfoEditBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; import com.kunfei.bookshelf.utils.FileUtils; import com.kunfei.bookshelf.utils.SoftInputUtil; import com.kunfei.bookshelf.utils.theme.ThemeStore; -import com.kunfei.bookshelf.widget.image.CoverImageView; import com.kunfei.bookshelf.widget.modialog.MoDialogHUD; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; public class BookInfoEditActivity extends MBaseActivity { private final int ResultSelectCover = 103; private final int ResultEditCover = 104; - - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.iv_cover) - CoverImageView ivCover; - @BindView(R.id.tie_book_name) - EditText tieBookName; - @BindView(R.id.til_book_name) - TextInputLayout tilBookName; - @BindView(R.id.tie_book_author) - EditText tieBookAuthor; - @BindView(R.id.til_book_author) - TextInputLayout tilBookAuthor; - @BindView(R.id.tie_cover_url) - EditText tieCoverUrl; - @BindView(R.id.til_cover_url) - TextInputLayout tilCoverUrl; - @BindView(R.id.tv_select_cover) - TextView tvSelectCover; - @BindView(R.id.tv_change_cover) - TextView tvChangeCover; - @BindView(R.id.tv_refresh_cover) - TextView tvRefreshCover; - @BindView(R.id.tie_book_jj) - EditText tieBookJj; - @BindView(R.id.til_book_jj) - TextInputLayout tilBookJj; - + private ActivityBookInfoEditBinding binding; private String noteUrl; private BookShelfBean book; private MoDialogHUD moDialogHUD; @@ -105,14 +72,14 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_book_info_edit); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivityBookInfoEditBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); - tilBookName.setHint(getString(R.string.book_name)); - tilBookAuthor.setHint(getString(R.string.author)); - tilCoverUrl.setHint(getString(R.string.cover_path)); - tilBookJj.setHint(getString(R.string.book_intro)); + binding.tilBookName.setHint(getString(R.string.book_name)); + binding.tilBookAuthor.setHint(getString(R.string.author)); + binding.tilCoverUrl.setHint(getString(R.string.cover_path)); + binding.tilBookJj.setHint(getString(R.string.book_intro)); moDialogHUD = new MoDialogHUD(this); } @@ -127,13 +94,13 @@ protected void initData() { if (!TextUtils.isEmpty(noteUrl)) { book = BookshelfHelp.getBook(noteUrl); if (book != null) { - tieBookName.setText(book.getBookInfoBean().getName()); - tieBookAuthor.setText(book.getBookInfoBean().getAuthor()); - tieBookJj.setText(book.getBookInfoBean().getIntroduce()); + binding.tieBookName.setText(book.getBookInfoBean().getName()); + binding.tieBookAuthor.setText(book.getBookInfoBean().getAuthor()); + binding.tieBookJj.setText(book.getBookInfoBean().getIntroduce()); if (TextUtils.isEmpty(book.getCustomCoverPath())) { - tieCoverUrl.setText(book.getBookInfoBean().getCoverUrl()); + binding.tieCoverUrl.setText(book.getBookInfoBean().getCoverUrl()); } else { - tieCoverUrl.setText(book.getCustomCoverPath()); + binding.tieCoverUrl.setText(book.getCustomCoverPath()); } } initCover(); @@ -146,15 +113,15 @@ protected void initData() { @Override protected void bindEvent() { super.bindEvent(); - tvSelectCover.setOnClickListener(view -> selectCover()); - tvChangeCover.setOnClickListener(view ->{ + binding.tvSelectCover.setOnClickListener(view -> selectCover()); + binding.tvChangeCover.setOnClickListener(view -> { Intent intent = new Intent(BookInfoEditActivity.this, BookCoverEditActivity.class); - intent.putExtra("name",book.getBookInfoBean().getName()); - intent.putExtra("author",book.getBookInfoBean().getAuthor()); + intent.putExtra("name", book.getBookInfoBean().getName()); + intent.putExtra("author", book.getBookInfoBean().getAuthor()); startActivityForResult(intent, ResultEditCover); - }); - tvRefreshCover.setOnClickListener(view -> { - book.setCustomCoverPath(tieCoverUrl.getText().toString()); + }); + binding.tvRefreshCover.setOnClickListener(view -> { + book.setCustomCoverPath(binding.tieCoverUrl.getText().toString()); initCover(); }); } @@ -175,7 +142,7 @@ private void selectCover() { private void initCover() { if (!this.isFinishing() && book != null) { - ivCover.load(book.getCoverPath(), book.getName(), book.getAuthor()); + binding.ivCover.load(book.getCoverPath(), book.getName(), book.getAuthor()); } } @@ -213,10 +180,10 @@ public boolean onOptionsItemSelected(MenuItem item) { private void saveInfo() { if (book != null) { - book.getBookInfoBean().setName(tieBookName.getText().toString()); - book.getBookInfoBean().setAuthor(tieBookAuthor.getText().toString()); - book.getBookInfoBean().setIntroduce(tieBookJj.getText().toString()); - book.setCustomCoverPath(tieCoverUrl.getText().toString()); + book.getBookInfoBean().setName(binding.tieBookName.getText().toString()); + book.getBookInfoBean().setAuthor(binding.tieBookAuthor.getText().toString()); + book.getBookInfoBean().setIntroduce(binding.tieBookJj.getText().toString()); + book.setCustomCoverPath(binding.tieCoverUrl.getText().toString()); initCover(); BookshelfHelp.saveBookToShelf(book); RxBus.get().post(RxBusTag.HAD_ADD_BOOK, book); @@ -244,15 +211,15 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case ResultSelectCover: if (resultCode == RESULT_OK && null != data) { - tieCoverUrl.setText(FileUtils.getPath(this, data.getData())); - book.setCustomCoverPath(tieCoverUrl.getText().toString()); + binding.tieCoverUrl.setText(FileUtils.getPath(this, data.getData())); + book.setCustomCoverPath(binding.tieCoverUrl.getText().toString()); initCover(); } break; case ResultEditCover: if (resultCode == RESULT_OK && null != data) { String url = data.getStringExtra("url"); - tieCoverUrl.setText(url); + binding.tieCoverUrl.setText(url); book.setCustomCoverPath(url); initCover(); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookSourceActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookSourceActivity.java index 67c8f1190d..c5aa1ae62b 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/BookSourceActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/BookSourceActivity.java @@ -14,11 +14,9 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; import com.kunfei.bookshelf.DbHelper; @@ -26,6 +24,7 @@ import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.dao.BookSourceBeanDao; +import com.kunfei.bookshelf.databinding.ActivityBookSourceBinding; import com.kunfei.bookshelf.help.ItemTouchCallback; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; @@ -46,8 +45,6 @@ import java.util.Arrays; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; /** @@ -58,16 +55,7 @@ public class BookSourceActivity extends MBaseActivity implements BookSourceContract.View { private final int IMPORT_SOURCE = 102; private final int REQUEST_QR = 202; - - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - @BindView(R.id.searchView) - SearchView searchView; - + private ActivityBookSourceBinding binding; private ItemTouchCallback itemTouchCallback; private boolean selectAll = true; private MenuItem groupItem; @@ -93,9 +81,9 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_book_source); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivityBookSourceBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -128,12 +116,12 @@ protected void firstRequest() { } private void initSearchView() { - mSearchAutoComplete = searchView.findViewById(R.id.search_src_text); + mSearchAutoComplete = binding.searchView.findViewById(R.id.search_src_text); mSearchAutoComplete.setTextSize(16); - searchView.setQueryHint(getString(R.string.search_book_source)); - searchView.onActionViewExpanded(); - searchView.clearFocus(); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + binding.searchView.setQueryHint(getString(R.string.search_book_source)); + binding.searchView.onActionViewExpanded(); + binding.searchView.clearFocus(); + binding.searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { return false; @@ -149,14 +137,14 @@ public boolean onQueryTextChange(String newText) { } private void initRecyclerView() { - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); adapter = new BookSourceAdapter(this); - recyclerView.setAdapter(adapter); + binding.recyclerView.setAdapter(adapter); itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); - itemTouchHelper.attachToRecyclerView(recyclerView); + itemTouchHelper.attachToRecyclerView(binding.recyclerView); setDragEnable(getSort()); } @@ -165,11 +153,7 @@ private void setDragEnable(int sort) { return; } adapter.setSort(sort); - if (sort == 0) { - itemTouchCallback.setDragEnable(true); - } else { - itemTouchCallback.setDragEnable(false); - } + itemTouchCallback.setDragEnable(sort == 0); } public void upDateSelectAll() { @@ -202,21 +186,21 @@ private void revertSelection() { } public void upSearchView(int size) { - searchView.setQueryHint(getString(R.string.search_book_source_num, size)); + binding.searchView.setQueryHint(getString(R.string.search_book_source_num, size)); } @Override public void refreshBookSource() { if (isSearch) { List sourceBeanList; - if (searchView.getQuery().toString().equals("enabled")) { + if (binding.searchView.getQuery().toString().equals("enabled")) { sourceBeanList = DbHelper.getDaoSession().getBookSourceBeanDao().queryBuilder() .where(BookSourceBeanDao.Properties.Enable.eq(1)) .orderRaw(BookSourceManager.getBookSourceSort()) .orderAsc(BookSourceBeanDao.Properties.SerialNumber) .list(); } else { - String term = "%" + searchView.getQuery() + "%"; + String term = "%" + binding.searchView.getQuery() + "%"; sourceBeanList = DbHelper.getDaoSession().getBookSourceBeanDao().queryBuilder() .whereOr(BookSourceBeanDao.Properties.BookSourceName.like(term), BookSourceBeanDao.Properties.BookSourceGroup.like(term), @@ -314,7 +298,7 @@ public boolean onOptionsItemSelected(MenuItem item) { upSourceSort(2); break; case R.id.show_enabled: - searchView.setQuery("enabled", false); + binding.searchView.setQuery("enabled", false); break; case R.id.action_share_wifi: ShareService.startThis(this, adapter.getSelectDataList()); @@ -324,7 +308,7 @@ public boolean onOptionsItemSelected(MenuItem item) { break; } if (item.getGroupId() == R.id.source_group) { - searchView.setQuery(item.getTitle(), true); + binding.searchView.setQuery(item.getTitle(), true); } return super.onOptionsItemSelected(item); } @@ -490,12 +474,12 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public Snackbar getSnackBar(String msg, int length) { - return Snackbar.make(llContent, msg, length); + return Snackbar.make(binding.llContent, msg, length); } @Override public void showSnackBar(String msg, int length) { - super.showSnackBar(llContent, msg, length); + super.showSnackBar(binding.llContent, msg, length); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ChapterListActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ChapterListActivity.java index 8ebbd3cb14..8ca02841d1 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ChapterListActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ChapterListActivity.java @@ -10,7 +10,6 @@ import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import com.hwangjr.rxbus.RxBus; @@ -20,6 +19,7 @@ import com.kunfei.bookshelf.base.BaseTabActivity; import com.kunfei.bookshelf.bean.BookChapterBean; import com.kunfei.bookshelf.bean.BookShelfBean; +import com.kunfei.bookshelf.databinding.ActivityChapterlistBinding; import com.kunfei.bookshelf.help.ReadBookControl; import com.kunfei.bookshelf.utils.ColorUtil; import com.kunfei.bookshelf.utils.theme.ATH; @@ -31,17 +31,12 @@ import java.util.Arrays; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; - import static android.view.View.GONE; import static android.view.View.VISIBLE; public class ChapterListActivity extends BaseTabActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - + private ActivityChapterlistBinding binding; private ReadBookControl readBookControl = ReadBookControl.getInstance(); private SearchView searchView; private BookShelfBean bookShelf; @@ -94,9 +89,14 @@ protected void onDestroy() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_chapterlist); - ButterKnife.bind(this); + binding = ActivityChapterlistBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); setupActionBar(); + } + + @Override + protected void bindView() { + super.bindView(); mTlIndicator.setSelectedTabIndicatorColor(ThemeStore.accentColor(this)); mTlIndicator.setTabTextColors(ColorUtil.isColorLight(ThemeStore.primaryColor(this)) ? Color.BLACK : Color.WHITE, ThemeStore.accentColor(this)); @@ -175,7 +175,7 @@ public void onBackPressed() { //设置ToolBar private void setupActionBar() { - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setDisplayHomeAsUpEnabled(true); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ChoiceBookActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ChoiceBookActivity.java index 7e62fcb0c2..4ac306c1a7 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ChoiceBookActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ChoiceBookActivity.java @@ -9,32 +9,25 @@ import android.widget.TextView; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; import com.kunfei.basemvplib.BitIntentDataManager; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.SearchBookBean; +import com.kunfei.bookshelf.databinding.ActivityBookChoiceBinding; import com.kunfei.bookshelf.presenter.BookDetailPresenter; import com.kunfei.bookshelf.presenter.ChoiceBookPresenter; import com.kunfei.bookshelf.presenter.contract.ChoiceBookContract; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.adapter.ChoiceBookAdapter; import com.kunfei.bookshelf.widget.recycler.refresh.OnLoadMoreListener; -import com.kunfei.bookshelf.widget.recycler.refresh.RefreshRecyclerView; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; - public class ChoiceBookActivity extends MBaseActivity implements ChoiceBookContract.View { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.rfRv_search_books) - RefreshRecyclerView rfRvSearchBooks; + private ActivityBookChoiceBinding binding; private ChoiceBookAdapter searchBookAdapter; private View viewRefreshError; @@ -46,7 +39,8 @@ protected ChoiceBookContract.Presenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_book_choice); + binding = ActivityBookChoiceBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -67,11 +61,10 @@ protected void initData() { @SuppressLint("InflateParams") @Override protected void bindView() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); - rfRvSearchBooks.setRefreshRecyclerViewAdapter(searchBookAdapter, new LinearLayoutManager(this)); + binding.rfRvSearchBooks.setRefreshRecyclerViewAdapter(searchBookAdapter, new LinearLayoutManager(this)); viewRefreshError = LayoutInflater.from(this).inflate(R.layout.view_refresh_error, null); viewRefreshError.findViewById(R.id.tv_refresh_again).setOnClickListener(v -> { @@ -81,7 +74,7 @@ protected void bindView() { mPresenter.toSearchBooks(null); startRefreshAnim(); }); - rfRvSearchBooks.setNoDataAndRefreshErrorView(LayoutInflater.from(this).inflate(R.layout.view_refresh_no_data, null), + binding.rfRvSearchBooks.setNoDataAndRefreshErrorView(LayoutInflater.from(this).inflate(R.layout.view_refresh_no_data, null), viewRefreshError); } @@ -115,12 +108,12 @@ protected void bindEvent() { startActivityByAnim(intent, android.R.anim.fade_in, android.R.anim.fade_out); }); - rfRvSearchBooks.setBaseRefreshListener(() -> { + binding.rfRvSearchBooks.setBaseRefreshListener(() -> { mPresenter.initPage(); mPresenter.toSearchBooks(null); startRefreshAnim(); }); - rfRvSearchBooks.setLoadMoreListener(new OnLoadMoreListener() { + binding.rfRvSearchBooks.setLoadMoreListener(new OnLoadMoreListener() { @Override public void startLoadMore() { mPresenter.toSearchBooks(null); @@ -140,12 +133,12 @@ public void refreshSearchBook(List books) { @Override public void refreshFinish(Boolean isAll) { - rfRvSearchBooks.finishRefresh(isAll, true); + binding.rfRvSearchBooks.finishRefresh(isAll, true); } @Override public void loadMoreFinish(Boolean isAll) { - rfRvSearchBooks.finishLoadMore(isAll, true); + binding.rfRvSearchBooks.finishLoadMore(isAll, true); } @Override @@ -161,10 +154,10 @@ public void loadMoreSearchBook(final List books) { @Override public void searchBookError(String msg) { if (mPresenter.getPage() > 1) { - rfRvSearchBooks.finishLoadMore(true, true); + binding.rfRvSearchBooks.finishLoadMore(true, true); } else { //刷新失败 - rfRvSearchBooks.refreshError(); + binding.rfRvSearchBooks.refreshError(); if (msg != null) { ((TextView) viewRefreshError.findViewById(R.id.tv_error_msg)).setText(msg); } else { @@ -186,7 +179,7 @@ public void addBookShelfFailed(String massage) { @Override public void startRefreshAnim() { - rfRvSearchBooks.startRefresh(); + binding.rfRvSearchBooks.startRefresh(); } @Override diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/DonateActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/DonateActivity.java index 96859d4ee0..d0c36758bf 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/DonateActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/DonateActivity.java @@ -8,22 +8,18 @@ import android.net.Uri; import android.os.Bundle; import android.view.MenuItem; -import android.widget.LinearLayout; import android.widget.Toast; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import androidx.cardview.widget.CardView; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.MApplication; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; +import com.kunfei.bookshelf.databinding.ActivityDonateBinding; import com.kunfei.bookshelf.help.Donate; import com.kunfei.bookshelf.utils.theme.ThemeStore; -import butterknife.BindView; -import butterknife.ButterKnife; /** * Created by GKF on 2018/1/13. @@ -31,24 +27,8 @@ */ public class DonateActivity extends MBaseActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.cv_wx_gzh) - CardView cvWxGzh; - @BindView(R.id.vw_zfb_tz) - CardView vwZfbTz; - @BindView(R.id.vw_zfb_hb) - CardView vwZfbHb; - @BindView(R.id.vw_zfb_rwm) - CardView vwZfbRwm; - @BindView(R.id.vw_wx_rwm) - CardView vwWxRwm; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.vw_qq_rwm) - CardView vwQqRwm; - @BindView(R.id.vw_zfb_hb_ssm) - CardView vwZfbHbSsm; + + private ActivityDonateBinding binding; public static void startThis(Context context) { Intent intent = new Intent(context, DonateActivity.class); @@ -69,13 +49,13 @@ protected IPresenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_donate); + binding = ActivityDonateBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override protected void bindView() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -86,8 +66,8 @@ protected void initData() { @Override protected void bindEvent() { - vwZfbTz.setOnClickListener(view -> Donate.aliDonate(this)); - cvWxGzh.setOnClickListener(view -> { + binding.vwZfbTz.setOnClickListener(view -> Donate.aliDonate(this)); + binding.cvWxGzh.setOnClickListener(view -> { ClipboardManager clipboard = (ClipboardManager) this.getSystemService(Context.CLIPBOARD_SERVICE); ClipData clipData = ClipData.newPlainText(null, "开源阅读"); if (clipboard != null) { @@ -95,11 +75,11 @@ protected void bindEvent() { toast(R.string.copy_complete); } }); - vwZfbHb.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png")); - vwZfbRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg")); - vwWxRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/wxskrwm.jpg")); - vwQqRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/qqskrwm.jpg")); - vwZfbHbSsm.setOnClickListener(view -> getZfbHb(this)); + binding.vwZfbHb.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbhbrwm.png")); + binding.vwZfbRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/zfbskrwm.jpg")); + binding.vwWxRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/wxskrwm.jpg")); + binding.vwQqRwm.setOnClickListener(view -> openActionViewIntent("https://gitee.com/gekunfei/Donate/raw/master/qqskrwm.jpg")); + binding.vwZfbHbSsm.setOnClickListener(view -> getZfbHb(this)); } public static void getZfbHb(Context context) { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/DownloadActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/DownloadActivity.java index 10f70aa7e5..97f24f9a1d 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/DownloadActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/DownloadActivity.java @@ -8,17 +8,15 @@ import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; -import android.widget.LinearLayout; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.DownloadBookBean; +import com.kunfei.bookshelf.databinding.ActivityRecyclerVewBinding; import com.kunfei.bookshelf.service.DownloadService; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.adapter.DownloadAdapter; @@ -26,9 +24,6 @@ import java.lang.ref.WeakReference; import java.util.ArrayList; -import butterknife.BindView; -import butterknife.ButterKnife; - import static com.kunfei.bookshelf.service.DownloadService.addDownloadAction; import static com.kunfei.bookshelf.service.DownloadService.finishDownloadAction; import static com.kunfei.bookshelf.service.DownloadService.obtainDownloadListAction; @@ -37,13 +32,7 @@ public class DownloadActivity extends MBaseActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - @BindView(R.id.ll_content) - LinearLayout llContent; - + private ActivityRecyclerVewBinding binding; private DownloadAdapter adapter; private DownloadReceiver receiver; @@ -80,9 +69,9 @@ protected IPresenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_recycler_vew); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivityRecyclerVewBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -107,10 +96,10 @@ protected void bindView() { } private void initRecyclerView() { - recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new DownloadAdapter(this); - recyclerView.setAdapter(adapter); - recyclerView.setItemAnimator(null); + binding.recyclerView.setAdapter(adapter); + binding.recyclerView.setItemAnimator(null); DownloadService.obtainDownloadList(this); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ImportBookActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ImportBookActivity.java index d2d37afca4..68b5ad0247 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ImportBookActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ImportBookActivity.java @@ -1,17 +1,15 @@ package com.kunfei.bookshelf.view.activity; import android.view.MenuItem; -import android.widget.CheckBox; -import android.widget.TextView; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.BaseTabActivity; +import com.kunfei.bookshelf.databinding.ActivityImportBookBinding; import com.kunfei.bookshelf.presenter.ImportBookPresenter; import com.kunfei.bookshelf.presenter.contract.ImportBookContract; import com.kunfei.bookshelf.utils.theme.ThemeStore; @@ -23,9 +21,6 @@ import java.util.Arrays; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; - /** * 导入本地书籍 @@ -33,16 +28,7 @@ public class ImportBookActivity extends BaseTabActivity implements ImportBookContract.View { private static final String TAG = "ImportBookActivity"; - @BindView(R.id.file_system_cb_selected_all) - CheckBox mCbSelectAll; - @BindView(R.id.file_system_btn_delete) - TextView mBtnDelete; - @BindView(R.id.file_system_btn_add_book) - TextView mBtnAddBook; - @BindView(R.id.toolbar) - Toolbar toolbar; - - + private ActivityImportBookBinding binding; private LocalBookFragment mLocalFragment; private FileCategoryFragment mCategoryFragment; private BaseFileFragment mCurFragment; @@ -73,9 +59,9 @@ protected ImportBookContract.Presenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_import_book); - ButterKnife.bind(this); - setSupportActionBar(toolbar); + binding = ActivityImportBookBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -100,10 +86,10 @@ protected List createTabTitles() { @Override protected void bindEvent() { - mCbSelectAll.setOnClickListener( + binding.fileSystemCbSelectedAll.setOnClickListener( (view) -> { //设置全选状态 - boolean isChecked = mCbSelectAll.isChecked(); + boolean isChecked = binding.fileSystemCbSelectedAll.isChecked(); mCurFragment.setCheckedAll(isChecked); //改变菜单状态 changeMenuStatus(); @@ -129,7 +115,7 @@ public void onPageScrollStateChanged(int state) { } }); - mBtnAddBook.setOnClickListener( + binding.fileSystemBtnAddBook.setOnClickListener( (v) -> { //获取选中的文件 List files = mCurFragment.getCheckedFiles(); @@ -138,7 +124,7 @@ public void onPageScrollStateChanged(int state) { } ); - mBtnDelete.setOnClickListener( + binding.fileSystemBtnDelete.setOnClickListener( (v) -> { //弹出,确定删除文件吗。 new AlertDialog.Builder(this) @@ -190,17 +176,17 @@ private void changeMenuStatus() { //点击、删除状态的设置 if (mCurFragment.getCheckedCount() == 0) { - mBtnAddBook.setText(getString(R.string.nb_file_add_shelf)); + binding.fileSystemBtnAddBook.setText(getString(R.string.nb_file_add_shelf)); //设置某些按钮的是否可点击 setMenuClickable(false); - if (mCbSelectAll.isChecked()) { + if (binding.fileSystemCbSelectedAll.isChecked()) { mCurFragment.setChecked(false); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } } else { - mBtnAddBook.setText(getString(R.string.nb_file_add_shelves, mCurFragment.getCheckedCount())); + binding.fileSystemBtnAddBook.setText(getString(R.string.nb_file_add_shelves, mCurFragment.getCheckedCount())); setMenuClickable(true); //全选状态的设置 @@ -209,20 +195,20 @@ private void changeMenuStatus() { if (mCurFragment.getCheckedCount() == mCurFragment.getCheckableCount()) { //设置为全选 mCurFragment.setChecked(true); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } //如果曾今是全选则替换 else if (mCurFragment.isCheckedAll()) { mCurFragment.setChecked(false); - mCbSelectAll.setChecked(mCurFragment.isCheckedAll()); + binding.fileSystemCbSelectedAll.setChecked(mCurFragment.isCheckedAll()); } } //重置全选的文字 if (mCurFragment.isCheckedAll()) { - mCbSelectAll.setText(R.string.cancel); + binding.fileSystemCbSelectedAll.setText(R.string.cancel); } else { - mCbSelectAll.setText(getString(R.string.select_all)); + binding.fileSystemCbSelectedAll.setText(getString(R.string.select_all)); } } @@ -230,12 +216,12 @@ else if (mCurFragment.isCheckedAll()) { private void setMenuClickable(boolean isClickable) { //设置是否可删除 - mBtnDelete.setEnabled(isClickable); - mBtnDelete.setClickable(isClickable); + binding.fileSystemBtnDelete.setEnabled(isClickable); + binding.fileSystemBtnDelete.setClickable(isClickable); //设置是否可添加书籍 - mBtnAddBook.setEnabled(isClickable); - mBtnAddBook.setClickable(isClickable); + binding.fileSystemBtnAddBook.setEnabled(isClickable); + binding.fileSystemBtnAddBook.setClickable(isClickable); } /** @@ -247,11 +233,11 @@ private void changeCheckedAllStatus() { //设置是否能够全选 if (count > 0) { - mCbSelectAll.setClickable(true); - mCbSelectAll.setEnabled(true); + binding.fileSystemCbSelectedAll.setClickable(true); + binding.fileSystemCbSelectedAll.setEnabled(true); } else { - mCbSelectAll.setClickable(false); - mCbSelectAll.setEnabled(false); + binding.fileSystemCbSelectedAll.setClickable(false); + binding.fileSystemCbSelectedAll.setEnabled(false); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/MainActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/MainActivity.java index 43dd92d233..567b9b6ff8 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/MainActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/MainActivity.java @@ -23,16 +23,11 @@ import androidx.appcompat.app.ActionBarDrawerToggle; import androidx.appcompat.app.AlertDialog; import androidx.appcompat.widget.AppCompatImageView; -import androidx.appcompat.widget.Toolbar; -import androidx.cardview.widget.CardView; -import androidx.coordinatorlayout.widget.CoordinatorLayout; import androidx.core.view.GravityCompat; -import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.viewpager.widget.ViewPager; import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.navigation.NavigationView; import com.google.android.material.tabs.TabLayout; import com.hwangjr.rxbus.RxBus; import com.kunfei.bookshelf.BuildConfig; @@ -41,6 +36,7 @@ import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.BaseTabActivity; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivityMainBinding; import com.kunfei.bookshelf.help.FileHelp; import com.kunfei.bookshelf.help.ProcessTextHelp; import com.kunfei.bookshelf.help.permission.Permissions; @@ -64,8 +60,6 @@ import java.util.List; import java.util.Objects; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; import static com.kunfei.bookshelf.utils.NetworkUtils.isNetWorkAvailable; @@ -76,17 +70,7 @@ public class MainActivity extends BaseTabActivity implem private String[] mTitles; private final int REQUEST_QR = 202; - @BindView(R.id.drawer) - DrawerLayout drawer; - @BindView(R.id.navigation_view) - NavigationView navigationView; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.main_view) - CoordinatorLayout mainView; - @BindView(R.id.card_search) - CardView cardSearch; - + private ActivityMainBinding binding; private AppCompatImageView vwNightTheme; private int group; private ActionBarDrawerToggle mDrawerToggle; @@ -118,8 +102,8 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_main); - ButterKnife.bind(this); + binding = ActivityMainBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -204,20 +188,20 @@ protected List createTabTitles() { @Override protected void bindView() { super.bindView(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.mainView.toolbar); setupActionBar(); - cardSearch.setCardBackgroundColor(ThemeStore.primaryColorDark(this)); + binding.mainView.cardSearch.setCardBackgroundColor(ThemeStore.primaryColorDark(this)); initDrawer(); initTabLayout(); upGroup(group); moDialogHUD = new MoDialogHUD(this); if (!preferences.getBoolean("behaviorMain", true)) { - AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) toolbar.getLayoutParams(); + AppBarLayout.LayoutParams params = (AppBarLayout.LayoutParams) binding.mainView.toolbar.getLayoutParams(); params.setScrollFlags(0); } //点击跳转搜索页 - cardSearch.setOnClickListener(view -> startActivityByAnim(new Intent(this, SearchBookActivity.class), - toolbar, "sharedView", android.R.anim.fade_in, android.R.anim.fade_out)); + binding.mainView.cardSearch.setOnClickListener(view -> startActivityByAnim(new Intent(this, SearchBookActivity.class), + binding.mainView.toolbar, "sharedView", android.R.anim.fade_in, android.R.anim.fade_out)); } //初始化TabLayout和ViewPager @@ -473,10 +457,10 @@ public void delete(String value) { } break; case android.R.id.home: - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawers(); + if (binding.drawer.isDrawerOpen(GravityCompat.START)) { + binding.drawer.closeDrawers(); } else { - drawer.openDrawer(GravityCompat.START, !MApplication.isEInkMode); + binding.drawer.openDrawer(GravityCompat.START, !MApplication.isEInkMode); } break; } @@ -493,9 +477,9 @@ private void setupActionBar() { //初始化侧边栏 private void initDrawer() { - mDrawerToggle = new ActionBarDrawerToggle(this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close); + mDrawerToggle = new ActionBarDrawerToggle(this, binding.drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close); mDrawerToggle.syncState(); - drawer.addDrawerListener(mDrawerToggle); + binding.drawer.addDrawerListener(mDrawerToggle); setUpNavigationView(); } @@ -525,19 +509,19 @@ private void upGroup(int group) { * 侧边栏按钮 */ private void setUpNavigationView() { - navigationView.setBackgroundColor(ThemeStore.backgroundColor(this)); - NavigationViewUtil.setItemIconColors(navigationView, getResources().getColor(R.color.tv_text_default), ThemeStore.accentColor(this)); - NavigationViewUtil.disableScrollbar(navigationView); + binding.navigationView.setBackgroundColor(ThemeStore.backgroundColor(this)); + NavigationViewUtil.setItemIconColors(binding.navigationView, getResources().getColor(R.color.tv_text_default), ThemeStore.accentColor(this)); + NavigationViewUtil.disableScrollbar(binding.navigationView); @SuppressLint("InflateParams") View headerView = LayoutInflater.from(this).inflate(R.layout.navigation_header, null); AppCompatImageView imageView = headerView.findViewById(R.id.iv_read); imageView.setColorFilter(ThemeStore.accentColor(this)); - navigationView.addHeaderView(headerView); - Menu drawerMenu = navigationView.getMenu(); + binding.navigationView.addHeaderView(headerView); + Menu drawerMenu = binding.navigationView.getMenu(); vwNightTheme = drawerMenu.findItem(R.id.action_theme).getActionView().findViewById(R.id.iv_theme_day_night); upThemeVw(); vwNightTheme.setOnClickListener(view -> setNightTheme(!isNightTheme())); - navigationView.setNavigationItemSelectedListener(menuItem -> { - drawer.closeDrawer(GravityCompat.START, !MApplication.isEInkMode); + binding.navigationView.setNavigationItemSelectedListener(menuItem -> { + binding.drawer.closeDrawer(GravityCompat.START, !MApplication.isEInkMode); switch (menuItem.getItemId()) { case R.id.action_book_source_manage: handler.postDelayed(() -> BookSourceActivity.startThis(this, requestSource), 200); @@ -647,8 +631,8 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { return true; } else { if (keyCode == KeyEvent.KEYCODE_BACK) { - if (drawer.isDrawerOpen(GravityCompat.START)) { - drawer.closeDrawer(GravityCompat.START, !MApplication.isEInkMode); + if (binding.drawer.isDrawerOpen(GravityCompat.START)) { + binding.drawer.closeDrawer(GravityCompat.START, !MApplication.isEInkMode); return true; } exit(); @@ -663,7 +647,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { */ public void exit() { if ((System.currentTimeMillis() - exitTime) > 2000) { - showSnackBar(toolbar, getString(R.string.double_click_exit)); + showSnackBar(binding.mainView.toolbar, getString(R.string.double_click_exit)); exitTime = System.currentTimeMillis(); } else { finish(); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/QRCodeScanActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/QRCodeScanActivity.java index 3d4d2ea666..dbfe6b4ead 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/QRCodeScanActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/QRCodeScanActivity.java @@ -8,22 +8,17 @@ import android.view.View; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; +import com.kunfei.bookshelf.databinding.ActivityQrcodeCaptureBinding; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; import com.kunfei.bookshelf.utils.FileUtils; import com.kunfei.bookshelf.widget.filepicker.picker.FilePicker; -import butterknife.BindView; -import butterknife.ButterKnife; import cn.bingoogolapple.qrcode.core.QRCodeView; -import cn.bingoogolapple.qrcode.zxing.ZXingView; import kotlin.Unit; /** @@ -32,15 +27,7 @@ public class QRCodeScanActivity extends MBaseActivity implements QRCodeView.Delegate { - @BindView(R.id.zxingview) - ZXingView zxingview; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.action_bar) - AppBarLayout actionBar; - @BindView(R.id.fab_flashlight) - FloatingActionButton fabFlashlight; - + private ActivityQrcodeCaptureBinding binding; private final int REQUEST_QR_IMAGE = 202; private boolean flashlightIsOpen; @@ -62,9 +49,9 @@ protected IPresenter initInjector() { */ @Override protected void onCreateActivity() { - setContentView(R.layout.activity_qrcode_capture); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivityQrcodeCaptureBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -73,14 +60,14 @@ protected void onCreateActivity() { */ @Override protected void initData() { - zxingview.setDelegate(this); - fabFlashlight.setOnClickListener(view -> { + binding.zxingview.setDelegate(this); + binding.fabFlashlight.setOnClickListener(view -> { if (flashlightIsOpen) { flashlightIsOpen = false; - zxingview.closeFlashlight(); + binding.zxingview.closeFlashlight(); } else { flashlightIsOpen = true; - zxingview.openFlashlight(); + binding.zxingview.openFlashlight(); } }); } @@ -96,8 +83,8 @@ private void startCamera() { .addPermissions(Permissions.CAMERA) .rationale(R.string.qr_per) .onGranted((requestCode) -> { - zxingview.setVisibility(View.VISIBLE); - zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 + binding.zxingview.setVisibility(View.VISIBLE); + binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 return Unit.INSTANCE; }) .request(); @@ -105,13 +92,13 @@ private void startCamera() { @Override protected void onStop() { - zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框 + binding.zxingview.stopCamera(); // 关闭摄像头预览,并且隐藏扫描框 super.onStop(); } @Override protected void onDestroy() { - zxingview.onDestroy(); // 销毁二维码扫描控件 + binding.zxingview.onDestroy(); // 销毁二维码扫描控件 super.onDestroy(); } @@ -175,12 +162,12 @@ public boolean onOptionsItemSelected(MenuItem item) { protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 + binding.zxingview.startSpotAndShowRect(); // 显示扫描框,并开始识别 if (resultCode == Activity.RESULT_OK && requestCode == REQUEST_QR_IMAGE) { final String picturePath = FileUtils.getPath(this, data.getData()); // 本来就用到 QRCodeView 时可直接调 QRCodeView 的方法,走通用的回调 - zxingview.decodeQRCode(picturePath); + binding.zxingview.decodeQRCode(picturePath); } } @@ -195,7 +182,7 @@ private void chooseFromGallery() { picker.setBackgroundColor(getResources().getColor(R.color.background)); picker.setTopBackgroundColor(getResources().getColor(R.color.background)); picker.setItemHeight(30); - picker.setOnFilePickListener(currentPath -> zxingview.decodeQRCode(currentPath)); + picker.setOnFilePickListener(currentPath -> binding.zxingview.decodeQRCode(currentPath)); picker.show(); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadBookActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadBookActivity.java index fffa43266c..d12335731b 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadBookActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadBookActivity.java @@ -1,8 +1,6 @@ //Copyright (c) 2017. 章钦豪. All rights reserved. package com.kunfei.bookshelf.view.activity; -import java.util.regex.Matcher; - import android.annotation.SuppressLint; import android.content.BroadcastReceiver; import android.content.ClipData; @@ -28,18 +26,11 @@ import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.AnimationUtils; -import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.ProgressBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.Toolbar; -import com.google.android.material.appbar.AppBarLayout; import com.kunfei.basemvplib.AppActivityManager; import com.kunfei.basemvplib.BitIntentDataManager; import com.kunfei.bookshelf.DbHelper; @@ -53,6 +44,7 @@ import com.kunfei.bookshelf.bean.ReplaceRuleBean; import com.kunfei.bookshelf.bean.TxtChapterRuleBean; import com.kunfei.bookshelf.dao.TxtChapterRuleBeanDao; +import com.kunfei.bookshelf.databinding.ActivityBookReadBinding; import com.kunfei.bookshelf.help.ChapterContentHelp; import com.kunfei.bookshelf.help.ReadBookControl; import com.kunfei.bookshelf.help.permission.Permissions; @@ -74,7 +66,6 @@ import com.kunfei.bookshelf.utils.theme.ATH; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.popupwindow.CheckAddShelfPop; -import com.kunfei.bookshelf.view.popupwindow.MediaPlayerPop; import com.kunfei.bookshelf.view.popupwindow.MoreSettingPop; import com.kunfei.bookshelf.view.popupwindow.ReadAdjustMarginPop; import com.kunfei.bookshelf.view.popupwindow.ReadAdjustPop; @@ -99,8 +90,6 @@ import java.util.Objects; import java.util.regex.Pattern; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; @@ -109,49 +98,7 @@ */ public class ReadBookActivity extends MBaseActivity implements ReadBookContract.View, View.OnTouchListener { - @BindView(R.id.fl_content) - FrameLayout flContent; - @BindView(R.id.fl_menu) - FrameLayout flMenu; - @BindView(R.id.v_menu_bg) - View vMenuBg; - @BindView(R.id.read_menu_bottom) - ReadBottomMenu readBottomMenu; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.tv_chapter_name) - TextView tvChapterName; - @BindView(R.id.tv_chapter_url) - TextView tvUrl; - @BindView(R.id.atv_line) - View atvLine; - @BindView(R.id.ll_menu_top) - LinearLayout llMenuTop; - @BindView(R.id.appBar) - AppBarLayout appBar; - @BindView(R.id.ll_ISB) - LinearLayout llISB; - @BindView(R.id.pageView) - PageView pageView; - @BindView(R.id.readAdjustPop) - ReadAdjustPop readAdjustPop; - @BindView(R.id.readAdjustMarginPop) - ReadAdjustMarginPop readAdjustMarginPop; - @BindView(R.id.readInterfacePop) - ReadInterfacePop readInterfacePop; - @BindView(R.id.moreSettingPop) - MoreSettingPop moreSettingPop; - @BindView(R.id.pb_nextPage) - ProgressBar progressBarNextPage; - @BindView(R.id.mediaPlayerPop) - MediaPlayerPop mediaPlayerPop; - @BindView(R.id.cursor_left) - ImageView cursorLeft; - @BindView(R.id.cursor_right) - ImageView cursorRight; - @BindView(R.id.readLongPress) - ReadLongPressPop readLongPress; - + private ActivityBookReadBinding binding; private Animation menuTopIn; private Animation menuTopOut; private Animation menuBottomIn; @@ -200,7 +147,8 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreateActivity() { setOrientation(readBookControl.getScreenDirection()); - setContentView(R.layout.activity_book_read); + binding = ActivityBookReadBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && readBookControl.getToLh()) { if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { WindowManager.LayoutParams lp = getWindow().getAttributes(); @@ -243,11 +191,11 @@ protected void initImmersionBar() { if (readBookControl.getHideNavigationBar()) { mImmersionBar.fullScreen(true); if (ImmersionBar.hasNavigationBar(this)) { - readBottomMenu.setNavigationBarHeight(ImmersionBar.getNavigationBarHeight(this)); + binding.readMenuBottom.setNavigationBarHeight(ImmersionBar.getNavigationBarHeight(this)); } } - if (readBottomMenu.getVisibility() == View.VISIBLE) { + if (binding.readMenuBottom.getVisibility() == View.VISIBLE) { if (isImmersionBarEnabled() && !isNightTheme()) { mImmersionBar.statusBarDarkFont(true, 0.2f); } else { @@ -292,11 +240,11 @@ private void changeNavigationBarColor(boolean hideBarDivider) { mImmersionBar.showBarDivider(); } int barColorType = readBookControl.getNavBarColor(); - if (readBottomMenu.getVisibility() == View.VISIBLE - || readAdjustPop.getVisibility() == View.VISIBLE - || readInterfacePop.getVisibility() == View.VISIBLE - || readAdjustMarginPop.getVisibility() == View.VISIBLE - || moreSettingPop.getVisibility() == View.VISIBLE) { + if (binding.readMenuBottom.getVisibility() == View.VISIBLE + || binding.readAdjustPop.getVisibility() == View.VISIBLE + || binding.readInterfacePop.getVisibility() == View.VISIBLE + || binding.readAdjustMarginPop.getVisibility() == View.VISIBLE + || binding.moreSettingPop.getVisibility() == View.VISIBLE) { barColorType = 0; } switch (barColorType) { @@ -361,17 +309,17 @@ private void autoPage() { mHandler.removeCallbacks(upHpbNextPage); mHandler.removeCallbacks(autoPageRunnable); if (autoPage) { - progressBarNextPage.setVisibility(View.VISIBLE); + binding.pbNextPage.setVisibility(View.VISIBLE); //每页按字数计算一次时间 nextPageTime = mPageLoader.curPageLength() * 60 * 1000 / readBookControl.getCPM(); if (0 == nextPageTime) nextPageTime = 1000; - progressBarNextPage.setMax(nextPageTime); + binding.pbNextPage.setMax(nextPageTime); mHandler.postDelayed(upHpbNextPage, upHpbInterval); mHandler.postDelayed(autoPageRunnable, nextPageTime); } else { - progressBarNextPage.setVisibility(View.INVISIBLE); + binding.pbNextPage.setVisibility(View.INVISIBLE); } - readBottomMenu.setAutoPage(autoPage); + binding.readMenuBottom.setAutoPage(autoPage); } /** @@ -379,7 +327,7 @@ private void autoPage() { */ private void upHpbNextPage() { nextPageTime = nextPageTime - upHpbInterval; - progressBarNextPage.setProgress(nextPageTime); + binding.pbNextPage.setProgress(nextPageTime); mHandler.postDelayed(upHpbNextPage, upHpbInterval); } @@ -416,7 +364,7 @@ public void onAnimationStart(Animation animation) { @Override public void onAnimationEnd(Animation animation) { - vMenuBg.setOnClickListener(v -> popMenuOut()); + binding.vMenuBg.setOnClickListener(v -> popMenuOut()); initImmersionBar(); } @@ -434,7 +382,7 @@ public void onAnimationStart(Animation animation) { @Override public void onAnimationEnd(Animation animation) { - vMenuBg.setOnClickListener(v -> popMenuOut()); + binding.vMenuBg.setOnClickListener(v -> popMenuOut()); } @Override @@ -448,19 +396,19 @@ public void onAnimationRepeat(Animation animation) { menuTopOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { - vMenuBg.setOnClickListener(null); + binding.vMenuBg.setOnClickListener(null); initImmersionBar(); } @Override public void onAnimationEnd(Animation animation) { - flMenu.setVisibility(View.INVISIBLE); - llMenuTop.setVisibility(View.INVISIBLE); - readBottomMenu.setVisibility(View.INVISIBLE); - readAdjustPop.setVisibility(View.INVISIBLE); - readAdjustMarginPop.setVisibility(View.INVISIBLE); - readInterfacePop.setVisibility(View.INVISIBLE); - moreSettingPop.setVisibility(View.INVISIBLE); + binding.flMenu.setVisibility(View.INVISIBLE); + binding.llMenuTop.setVisibility(View.INVISIBLE); + binding.readMenuBottom.setVisibility(View.INVISIBLE); + binding.readAdjustPop.setVisibility(View.INVISIBLE); + binding.readAdjustMarginPop.setVisibility(View.INVISIBLE); + binding.readInterfacePop.setVisibility(View.INVISIBLE); + binding.moreSettingPop.setVisibility(View.INVISIBLE); initImmersionBar(); } @@ -473,19 +421,19 @@ public void onAnimationRepeat(Animation animation) { menuBottomOut.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { - vMenuBg.setOnClickListener(null); + binding.vMenuBg.setOnClickListener(null); initImmersionBar(); } @Override public void onAnimationEnd(Animation animation) { - flMenu.setVisibility(View.INVISIBLE); - llMenuTop.setVisibility(View.INVISIBLE); - readBottomMenu.setVisibility(View.INVISIBLE); - readAdjustPop.setVisibility(View.INVISIBLE); - readAdjustMarginPop.setVisibility(View.INVISIBLE); - readInterfacePop.setVisibility(View.INVISIBLE); - moreSettingPop.setVisibility(View.INVISIBLE); + binding.flMenu.setVisibility(View.INVISIBLE); + binding.llMenuTop.setVisibility(View.INVISIBLE); + binding.readMenuBottom.setVisibility(View.INVISIBLE); + binding.readAdjustPop.setVisibility(View.INVISIBLE); + binding.readAdjustMarginPop.setVisibility(View.INVISIBLE); + binding.readInterfacePop.setVisibility(View.INVISIBLE); + binding.moreSettingPop.setVisibility(View.INVISIBLE); initImmersionBar(); } @@ -504,13 +452,12 @@ public void onAnimationRepeat(Animation animation) { @Override protected void bindView() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); mPresenter.initData(this); - appBar.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, 0); - appBar.setBackgroundColor(ThemeStore.primaryColor(this)); - readBottomMenu.setFabNightTheme(isNightTheme()); + binding.appBar.setPadding(0, ScreenUtils.getStatusBarHeight(), 0, 0); + binding.appBar.setBackgroundColor(ThemeStore.primaryColor(this)); + binding.readMenuBottom.setFabNightTheme(isNightTheme()); //弹窗 moDialogHUD = new MoDialogHUD(this); initBottomMenu(); @@ -520,39 +467,39 @@ protected void bindView() { initMoreSettingPop(); initMediaPlayer(); initReadLongPressPop(); - pageView.setBackground(readBookControl.getTextBackground(this)); - cursorLeft.getDrawable().setColorFilter(ThemeStore.accentColor(this), PorterDuff.Mode.SRC_ATOP); - cursorRight.getDrawable().setColorFilter(ThemeStore.accentColor(this), PorterDuff.Mode.SRC_ATOP); + binding.pageView.setBackground(readBookControl.getTextBackground(this)); + binding.cursorLeft.getDrawable().setColorFilter(ThemeStore.accentColor(this), PorterDuff.Mode.SRC_ATOP); + binding.cursorRight.getDrawable().setColorFilter(ThemeStore.accentColor(this), PorterDuff.Mode.SRC_ATOP); } /** * 初始化播放界面 */ private void initMediaPlayer() { - mediaPlayerPop.setIvChapterClickListener(v -> ChapterListActivity.startThis(ReadBookActivity.this, mPresenter.getBookShelf(), mPresenter.getChapterList())); - mediaPlayerPop.setIvTimerClickListener(v -> ReadAloudService.setTimer(getContext(), 10)); - mediaPlayerPop.setIvCoverBgClickListener(v -> { - flMenu.setVisibility(View.VISIBLE); - llMenuTop.setVisibility(View.VISIBLE); - llMenuTop.startAnimation(menuTopIn); + binding.mediaPlayerPop.setIvChapterClickListener(v -> ChapterListActivity.startThis(ReadBookActivity.this, mPresenter.getBookShelf(), mPresenter.getChapterList())); + binding.mediaPlayerPop.setIvTimerClickListener(v -> ReadAloudService.setTimer(getContext(), 10)); + binding.mediaPlayerPop.setIvCoverBgClickListener(v -> { + binding.flMenu.setVisibility(View.VISIBLE); + binding.llMenuTop.setVisibility(View.VISIBLE); + binding.llMenuTop.startAnimation(menuTopIn); }); - mediaPlayerPop.setPlayClickListener(v -> onMediaButton(ReadAloudService.ActionMediaPlay)); - mediaPlayerPop.setPrevClickListener(v -> { + binding.mediaPlayerPop.setPlayClickListener(v -> onMediaButton(ReadAloudService.ActionMediaPlay)); + binding.mediaPlayerPop.setPrevClickListener(v -> { mPresenter.getBookShelf().setDurChapterPage(0); mPageLoader.skipToPrePage(); }); - mediaPlayerPop.setNextClickListener(v -> { + binding.mediaPlayerPop.setNextClickListener(v -> { mPresenter.getBookShelf().setDurChapterPage(0); mPageLoader.skipToNextPage(); }); - mediaPlayerPop.setCallback(dur -> ReadAloudService.setProgress(ReadBookActivity.this, dur)); + binding.mediaPlayerPop.setCallback(dur -> ReadAloudService.setProgress(ReadBookActivity.this, dur)); } /** * 初始化底部菜单 */ private void initBottomMenu() { - readBottomMenu.setListener(new ReadBottomMenu.Callback() { + binding.readMenuBottom.setListener(new ReadBottomMenu.Callback() { @Override public void skipToPage(int page) { if (mPageLoader != null) { @@ -643,7 +590,7 @@ public void dismiss() { * 初始化调节 */ private void initReadAdjustPop() { - readAdjustPop.setListener(this, new ReadAdjustPop.Callback() { + binding.readAdjustPop.setListener(this, new ReadAdjustPop.Callback() { @Override public void speechRateFollowSys() { if (ReadAloudService.running) { @@ -665,7 +612,7 @@ public void changeSpeechRate(int speechRate) { * 初始化调节 */ private void initReadAdjustMarginPop() { - readAdjustMarginPop.setListener(this, new ReadAdjustMarginPop.Callback() { + binding.readAdjustMarginPop.setListener(this, new ReadAdjustMarginPop.Callback() { @Override public void upTextSize() { @@ -695,7 +642,7 @@ public void refresh() { * 初始化界面设置 */ private void initReadInterfacePop() { - readInterfacePop.setListener(this, new ReadInterfacePop.Callback() { + binding.readInterfacePop.setListener(this, new ReadInterfacePop.Callback() { @Override public void upPageMode() { @@ -721,7 +668,7 @@ public void upMargin() { @Override public void bgChange() { readBookControl.initTextDrawableIndex(); - pageView.setBackground(readBookControl.getTextBackground(ReadBookActivity.this)); + binding.pageView.setBackground(readBookControl.getTextBackground(ReadBookActivity.this)); initImmersionBar(); if (mPageLoader != null) { mPageLoader.refreshUi(); @@ -742,7 +689,7 @@ public void refresh() { * 初始化其它设置 */ private void initMoreSettingPop() { - moreSettingPop.setListener(new MoreSettingPop.Callback() { + binding.moreSettingPop.setListener(new MoreSettingPop.Callback() { @Override public void upBar() { initImmersionBar(); @@ -771,15 +718,15 @@ public void refreshPage() { @SuppressLint("ClickableViewAccessibility") @Override protected void bindEvent() { - tvChapterName.setOnClickListener(v -> { + binding.tvChapterName.setOnClickListener(v -> { if (mPresenter.getBookSource() != null) { SourceEditActivity.startThis(this, mPresenter.getBookSource()); } }); //打开URL - tvUrl.setOnClickListener(view -> { + binding.tvChapterUrl.setOnClickListener(view -> { try { - String url = tvUrl.getText().toString(); + String url = binding.tvChapterUrl.getText().toString(); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse(url)); startActivity(intent); @@ -788,9 +735,9 @@ protected void bindEvent() { } }); - cursorLeft.setOnTouchListener(this); - cursorRight.setOnTouchListener(this); - flContent.setOnTouchListener(this); + binding.cursorLeft.setOnTouchListener(this); + binding.cursorRight.setOnTouchListener(this); + binding.flContent.setOnTouchListener(this); } /** @@ -799,7 +746,7 @@ protected void bindEvent() { @Override public void startLoadingBook() { initPageView(); - mediaPlayerPop.setCover(mPresenter.getBookShelf().getCustomCoverPath() != null ? mPresenter.getBookShelf().getCustomCoverPath() + binding.mediaPlayerPop.setCover(mPresenter.getBookShelf().getCustomCoverPath() != null ? mPresenter.getBookShelf().getCustomCoverPath() : mPresenter.getBookShelf().getBookInfoBean().getCoverUrl()); } @@ -807,7 +754,7 @@ public void startLoadingBook() { * 加载阅读页面 */ private void initPageView() { - mPageLoader = pageView.getPageLoader(this, mPresenter.getBookShelf(), + mPageLoader = binding.pageView.getPageLoader(this, mPresenter.getBookShelf(), new PageLoader.Callback() { @Override public List getChapterList() { @@ -824,29 +771,29 @@ public void onChapterChange(int pos) { mPresenter.getBookShelf().setDurChapterName(mPresenter.getChapterList().get(pos).getDurChapterName()); actionBar.setTitle(mPresenter.getBookShelf().getBookInfoBean().getName()); if (mPresenter.getBookShelf().getChapterListSize() > 0) { - tvChapterName.setVisibility(View.VISIBLE); - tvChapterName.setText(mPresenter.getChapterList().get(pos).getDurChapterName()); - tvUrl.setVisibility(View.VISIBLE); - tvUrl.setText(NetworkUtils.getAbsoluteURL(mPresenter.getBookShelf().getBookInfoBean().getChapterUrl(), + binding.tvChapterName.setVisibility(View.VISIBLE); + binding.tvChapterName.setText(mPresenter.getChapterList().get(pos).getDurChapterName()); + binding.tvChapterUrl.setVisibility(View.VISIBLE); + binding.tvChapterUrl.setText(NetworkUtils.getAbsoluteURL(mPresenter.getBookShelf().getBookInfoBean().getChapterUrl(), mPresenter.getChapterList().get(pos).getDurChapterUrl())); } else { - tvChapterName.setVisibility(View.GONE); - tvUrl.setVisibility(View.GONE); + binding.tvChapterName.setVisibility(View.GONE); + binding.tvChapterUrl.setVisibility(View.GONE); } if (mPresenter.getBookShelf().getChapterListSize() == 1) { - readBottomMenu.setTvPre(false); - readBottomMenu.setTvNext(false); + binding.readMenuBottom.setTvPre(false); + binding.readMenuBottom.setTvNext(false); } else { if (pos == 0) { - readBottomMenu.setTvPre(false); - readBottomMenu.setTvNext(true); + binding.readMenuBottom.setTvPre(false); + binding.readMenuBottom.setTvNext(true); } else if (pos == mPresenter.getBookShelf().getChapterListSize() - 1) { - readBottomMenu.setTvPre(true); - readBottomMenu.setTvNext(false); + binding.readMenuBottom.setTvPre(true); + binding.readMenuBottom.setTvNext(false); } else { - readBottomMenu.setTvPre(true); - readBottomMenu.setTvNext(true); + binding.readMenuBottom.setTvPre(true); + binding.readMenuBottom.setTvNext(true); } } } @@ -868,14 +815,14 @@ public void onCategoryFinish(List chapters) { */ @Override public void onPageCountChange(int count) { - readBottomMenu.getReadProgress().setMax(Math.max(0, count - 1)); - readBottomMenu.getReadProgress().setProgress(0); + binding.readMenuBottom.getReadProgress().setMax(Math.max(0, count - 1)); + binding.readMenuBottom.getReadProgress().setProgress(0); // 如果处于错误状态,那么就冻结使用 if (mPageLoader.getPageStatus() == TxtChapter.Status.LOADING || mPageLoader.getPageStatus() == TxtChapter.Status.ERROR) { - readBottomMenu.getReadProgress().setEnabled(false); + binding.readMenuBottom.getReadProgress().setEnabled(false); } else { - readBottomMenu.getReadProgress().setEnabled(true); + binding.readMenuBottom.getReadProgress().setEnabled(true); } } @@ -887,20 +834,20 @@ public void onPageChange(int chapterIndex, int pageIndex, boolean resetReadAloud mPresenter.getBookShelf().setDurChapter(chapterIndex); mPresenter.getBookShelf().setDurChapterPage(pageIndex); mPresenter.saveProgress(); - readBottomMenu.getReadProgress().post( - () -> readBottomMenu.getReadProgress().setProgress(pageIndex) + binding.readMenuBottom.getReadProgress().post( + () -> binding.readMenuBottom.getReadProgress().setProgress(pageIndex) ); Long end = mPresenter.getDurChapter().getEnd(); int audioSize = end != null ? end.intValue() : 0; - mediaPlayerPop.upAudioSize(audioSize); - mediaPlayerPop.upAudioDur(mPresenter.getBookShelf().getDurChapterPage()); + binding.mediaPlayerPop.upAudioSize(audioSize); + binding.mediaPlayerPop.upAudioDur(mPresenter.getBookShelf().getDurChapterPage()); if (mPresenter.getBookShelf().isAudio() && mPageLoader.getPageStatus() == TxtChapter.Status.FINISH) { - if (mediaPlayerPop.getVisibility() != View.VISIBLE) { - mediaPlayerPop.setVisibility(View.VISIBLE); + if (binding.mediaPlayerPop.getVisibility() != View.VISIBLE) { + binding.mediaPlayerPop.setVisibility(View.VISIBLE); } } else { - if (mediaPlayerPop.getVisibility() == View.VISIBLE) { - mediaPlayerPop.setVisibility(View.GONE); + if (binding.mediaPlayerPop.getVisibility() == View.VISIBLE) { + binding.mediaPlayerPop.setVisibility(View.GONE); } } if ((ReadAloudService.running)) { @@ -952,7 +899,7 @@ public void vipPop() { } ); mPageLoader.updateBattery(BatteryUtil.getLevel(this)); - pageView.setTouchListener(new PageView.TouchListener() { + binding.pageView.setTouchListener(new PageView.TouchListener() { @Override public void onTouch() { screenOffTimerStart(); @@ -965,16 +912,16 @@ public void center() { @Override public void onTouchClearCursor() { - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); - readLongPress.setVisibility(View.INVISIBLE); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); + binding.readLongPress.setVisibility(View.INVISIBLE); } @Override public void onLongPress() { - if (!pageView.isRunning()) { + if (!binding.pageView.isRunning()) { selectTextCursorShow(); - showAction(cursorLeft); + showAction(binding.cursorLeft); } } }); @@ -994,7 +941,7 @@ public boolean onTouch(View v, MotionEvent event) { lastX = (int) event.getRawX();// 获取触摸事件触摸位置的原始X坐标 lastY = (int) event.getRawY(); - readLongPress.setVisibility(View.INVISIBLE); + binding.readLongPress.setVisibility(View.INVISIBLE); break; case MotionEvent.ACTION_MOVE: @@ -1011,18 +958,18 @@ public boolean onTouch(View v, MotionEvent event) { v.postInvalidate(); //移动过程中要画线 - pageView.setSelectMode(PageView.SelectMode.SelectMoveForward); + binding.pageView.setSelectMode(PageView.SelectMode.SelectMoveForward); - int hh = cursorLeft.getHeight(); - int ww = cursorLeft.getWidth(); + int hh = binding.cursorLeft.getHeight(); + int ww = binding.cursorLeft.getWidth(); if (v.getId() == R.id.cursor_left) { - pageView.setFirstSelectTxtChar(pageView.getCurrentTxtChar(lastX + ww, lastY - hh)); + binding.pageView.setFirstSelectTxtChar(binding.pageView.getCurrentTxtChar(lastX + ww, lastY - hh)); } else { - pageView.setLastSelectTxtChar(pageView.getCurrentTxtChar(lastX - ww, lastY - hh)); + binding.pageView.setLastSelectTxtChar(binding.pageView.getCurrentTxtChar(lastX - ww, lastY - hh)); } - pageView.invalidate(); + binding.pageView.invalidate(); break; case MotionEvent.ACTION_UP: @@ -1038,20 +985,20 @@ public boolean onTouch(View v, MotionEvent event) { public void showAction(View clickView) { - readLongPress.setVisibility(View.VISIBLE); + binding.readLongPress.setVisibility(View.VISIBLE); //如果太靠右,则靠左 int[] aa = ScreenUtils.getScreenSize(this); - if ((cursorLeft.getX() + ScreenUtils.dpToPx(200)) > aa[0]) { - readLongPress.setX(aa[0] - ScreenUtils.dpToPx(200)); + if ((binding.cursorLeft.getX() + ScreenUtils.dpToPx(200)) > aa[0]) { + binding.readLongPress.setX(aa[0] - ScreenUtils.dpToPx(200)); } else { - readLongPress.setX(cursorLeft.getX() + cursorLeft.getWidth() + ScreenUtils.dpToPx(5)); + binding.readLongPress.setX(binding.cursorLeft.getX() + binding.cursorLeft.getWidth() + ScreenUtils.dpToPx(5)); } //如果太靠上 - if ((cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize()) - ScreenUtils.dpToPx(60)) < 0) { - readLongPress.setY(cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize())); + if ((binding.cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize()) - ScreenUtils.dpToPx(60)) < 0) { + binding.readLongPress.setY(binding.cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize())); } else { - readLongPress.setY(cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize()) - ScreenUtils.dpToPx(40)); + binding.readLongPress.setY(binding.cursorLeft.getY() - ScreenUtils.spToPx(readBookControl.getTextSize()) - ScreenUtils.dpToPx(40)); } } @@ -1060,28 +1007,27 @@ public void showAction(View clickView) { * 显示 */ private void selectTextCursorShow() { - if (pageView.getFirstSelectTxtChar() == null || pageView.getLastSelectTxtChar() == null) + if (binding.pageView.getFirstSelectTxtChar() == null || binding.pageView.getLastSelectTxtChar() == null) return; //show Cursor on current position cursorShow(); //set current word selected - pageView.invalidate(); - + binding.pageView.invalidate(); hideSnackBar(); } private void cursorShow() { - cursorLeft.setVisibility(View.VISIBLE); - cursorRight.setVisibility(View.VISIBLE); - int hh = cursorLeft.getHeight(); - int ww = cursorLeft.getWidth(); - if (pageView.getFirstSelectTxtChar() != null) { - cursorLeft.setX(pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); - cursorLeft.setY(pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); - cursorRight.setX(pageView.getFirstSelectTxtChar().getBottomRightPosition().x); - cursorRight.setY(pageView.getFirstSelectTxtChar().getBottomRightPosition().y); + binding.cursorLeft.setVisibility(View.VISIBLE); + binding.cursorRight.setVisibility(View.VISIBLE); + int hh = binding.cursorLeft.getHeight(); + int ww = binding.cursorLeft.getWidth(); + if (binding.pageView.getFirstSelectTxtChar() != null) { + binding.cursorLeft.setX(binding.pageView.getFirstSelectTxtChar().getTopLeftPosition().x - ww); + binding.cursorLeft.setY(binding.pageView.getFirstSelectTxtChar().getBottomLeftPosition().y); + binding.cursorRight.setX(binding.pageView.getFirstSelectTxtChar().getBottomRightPosition().x); + binding.cursorRight.setY(binding.pageView.getFirstSelectTxtChar().getBottomRightPosition().y); } } @@ -1089,29 +1035,29 @@ private void cursorShow() { * 长按选择按钮 */ private void initReadLongPressPop() { - readLongPress.setListener(new ReadLongPressPop.OnBtnClickListener() { + binding.readLongPress.setListener(new ReadLongPressPop.OnBtnClickListener() { @Override public void copySelect() { ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clipData = ClipData.newPlainText(null, pageView.getSelectStr()); + ClipData clipData = ClipData.newPlainText(null, binding.pageView.getSelectStr()); if (clipboard != null) { clipboard.setPrimaryClip(clipData); toast("所选内容已经复制到剪贴板"); } - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); - readLongPress.setVisibility(View.INVISIBLE); - pageView.clearSelect(); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); + binding.readLongPress.setVisibility(View.INVISIBLE); + binding.pageView.clearSelect(); } @Override public void replaceSelect() { ReplaceRuleBean oldRuleBean = new ReplaceRuleBean(); - oldRuleBean.setReplaceSummary(pageView.getSelectStr().trim()); + oldRuleBean.setReplaceSummary(binding.pageView.getSelectStr().trim()); oldRuleBean.setEnable(true); - oldRuleBean.setRegex(pageView.getSelectStr().trim()); + oldRuleBean.setRegex(binding.pageView.getSelectStr().trim()); oldRuleBean.setIsRegex(false); oldRuleBean.setReplacement(""); oldRuleBean.setSerialNumber(0); @@ -1123,11 +1069,11 @@ public void replaceSelect() { .subscribe(new MySingleObserver() { @Override public void onSuccess(Boolean aBoolean) { - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); - readLongPress.setVisibility(View.INVISIBLE); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); + binding.readLongPress.setVisibility(View.INVISIBLE); - pageView.setSelectMode(PageView.SelectMode.Normal); + binding.pageView.setSelectMode(PageView.SelectMode.Normal); moDialogHUD.dismiss(); @@ -1138,7 +1084,7 @@ public void onSuccess(Boolean aBoolean) { @Override public void replaceSelectAd() { - String selectString = pageView.getSelectStr(); + String selectString = binding.pageView.getSelectStr(); if (selectString != null) { @@ -1181,11 +1127,11 @@ public void replaceSelectAd() { .subscribe(new MySingleObserver() { @Override public void onSuccess(Boolean aBoolean) { - cursorLeft.setVisibility(View.INVISIBLE); - cursorRight.setVisibility(View.INVISIBLE); - readLongPress.setVisibility(View.INVISIBLE); + binding.cursorLeft.setVisibility(View.INVISIBLE); + binding.cursorRight.setVisibility(View.INVISIBLE); + binding.readLongPress.setVisibility(View.INVISIBLE); - pageView.setSelectMode(PageView.SelectMode.Normal); + binding.pageView.setSelectMode(PageView.SelectMode.Normal); moDialogHUD.dismiss(); @@ -1473,49 +1419,49 @@ private void setTextChapterRegex() { * 显示调节 */ private void readAdjustIn() { - flMenu.setVisibility(View.VISIBLE); - readAdjustPop.show(); - readAdjustPop.setVisibility(View.VISIBLE); - readAdjustPop.startAnimation(menuBottomIn); + binding.flMenu.setVisibility(View.VISIBLE); + binding.readAdjustPop.show(); + binding.readAdjustPop.setVisibility(View.VISIBLE); + binding.readAdjustPop.startAnimation(menuBottomIn); } /** * 显示自定义边界调节 */ public void readAdjustMarginIn() { - flMenu.setVisibility(View.VISIBLE); - readAdjustMarginPop.show(); - readAdjustMarginPop.setVisibility(View.VISIBLE); - readAdjustMarginPop.startAnimation(menuBottomIn); + binding.flMenu.setVisibility(View.VISIBLE); + binding.readAdjustMarginPop.show(); + binding.readAdjustMarginPop.setVisibility(View.VISIBLE); + binding.readAdjustMarginPop.startAnimation(menuBottomIn); } /** * 显示界面设置 */ private void readInterfaceIn() { - flMenu.setVisibility(View.VISIBLE); - readInterfacePop.setVisibility(View.VISIBLE); - readInterfacePop.startAnimation(menuBottomIn); + binding.flMenu.setVisibility(View.VISIBLE); + binding.readInterfacePop.setVisibility(View.VISIBLE); + binding.readInterfacePop.startAnimation(menuBottomIn); } /** * 显示更多设置 */ private void moreSettingIn() { - flMenu.setVisibility(View.VISIBLE); - moreSettingPop.setVisibility(View.VISIBLE); - moreSettingPop.startAnimation(menuBottomIn); + binding.flMenu.setVisibility(View.VISIBLE); + binding.moreSettingPop.setVisibility(View.VISIBLE); + binding.moreSettingPop.startAnimation(menuBottomIn); } /** * 显示菜单 */ private void popMenuIn() { - flMenu.setVisibility(View.VISIBLE); - llMenuTop.setVisibility(View.VISIBLE); - readBottomMenu.setVisibility(View.VISIBLE); - llMenuTop.startAnimation(menuTopIn); - readBottomMenu.startAnimation(menuBottomIn); + binding.flMenu.setVisibility(View.VISIBLE); + binding.llMenuTop.setVisibility(View.VISIBLE); + binding.readMenuBottom.setVisibility(View.VISIBLE); + binding.llMenuTop.startAnimation(menuTopIn); + binding.readMenuBottom.startAnimation(menuBottomIn); hideSnackBar(); } @@ -1523,24 +1469,24 @@ private void popMenuIn() { * 隐藏菜单 */ private void popMenuOut() { - if (flMenu.getVisibility() == View.VISIBLE) { - if (llMenuTop.getVisibility() == View.VISIBLE) { - llMenuTop.startAnimation(menuTopOut); + if (binding.flMenu.getVisibility() == View.VISIBLE) { + if (binding.llMenuTop.getVisibility() == View.VISIBLE) { + binding.llMenuTop.startAnimation(menuTopOut); } - if (readBottomMenu.getVisibility() == View.VISIBLE) { - readBottomMenu.startAnimation(menuBottomOut); + if (binding.readMenuBottom.getVisibility() == View.VISIBLE) { + binding.readMenuBottom.startAnimation(menuBottomOut); } - if (moreSettingPop.getVisibility() == View.VISIBLE) { - moreSettingPop.startAnimation(menuBottomOut); + if (binding.moreSettingPop.getVisibility() == View.VISIBLE) { + binding.moreSettingPop.startAnimation(menuBottomOut); } - if (readAdjustPop.getVisibility() == View.VISIBLE) { - readAdjustPop.startAnimation(menuBottomOut); + if (binding.readAdjustPop.getVisibility() == View.VISIBLE) { + binding.readAdjustPop.startAnimation(menuBottomOut); } - if (readInterfacePop.getVisibility() == View.VISIBLE) { - readInterfacePop.startAnimation(menuBottomOut); + if (binding.readInterfacePop.getVisibility() == View.VISIBLE) { + binding.readInterfacePop.startAnimation(menuBottomOut); } - if (readAdjustMarginPop.getVisibility() == View.VISIBLE) { - readAdjustMarginPop.startAnimation(menuBottomOut); + if (binding.readAdjustMarginPop.getVisibility() == View.VISIBLE) { + binding.readAdjustMarginPop.startAnimation(menuBottomOut); } } } @@ -1590,7 +1536,7 @@ public void clickAddShelf() { }); } if (!checkAddShelfPop.isShowing()) { - checkAddShelfPop.showAtLocation(flContent, Gravity.CENTER, 0, 0); + checkAddShelfPop.showAtLocation(binding.flContent, Gravity.CENTER, 0, 0); } return false; } @@ -1614,26 +1560,26 @@ public void upAloudState(ReadAloudService.Status status) { } break; case PLAY: - readBottomMenu.setFabReadAloudImage(R.drawable.ic_pause_outline_24dp); - readBottomMenu.setReadAloudTimer(true); - mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_pause_24dp); - mediaPlayerPop.setSeekBarEnable(true); + binding.readMenuBottom.setFabReadAloudImage(R.drawable.ic_pause_outline_24dp); + binding.readMenuBottom.setReadAloudTimer(true); + binding.mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_pause_24dp); + binding.mediaPlayerPop.setSeekBarEnable(true); break; case PAUSE: - readBottomMenu.setFabReadAloudImage(R.drawable.ic_play_outline_24dp); - readBottomMenu.setReadAloudTimer(true); - mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_play_24dp); - mediaPlayerPop.setSeekBarEnable(false); + binding.readMenuBottom.setFabReadAloudImage(R.drawable.ic_play_outline_24dp); + binding.readMenuBottom.setReadAloudTimer(true); + binding.mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_play_24dp); + binding.mediaPlayerPop.setSeekBarEnable(false); break; default: - readBottomMenu.setFabReadAloudImage(R.drawable.ic_read_aloud); - readBottomMenu.setReadAloudTimer(false); - mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_play_24dp); - pageView.drawPage(0); - pageView.invalidate(); - pageView.drawPage(-1); - pageView.drawPage(1); - pageView.invalidate(); + binding.readMenuBottom.setFabReadAloudImage(R.drawable.ic_read_aloud); + binding.readMenuBottom.setReadAloudTimer(false); + binding.mediaPlayerPop.setFabReadAloudImage(R.drawable.ic_play_24dp); + binding.pageView.drawPage(0); + binding.pageView.invalidate(); + binding.pageView.drawPage(-1); + binding.pageView.drawPage(1); + binding.pageView.invalidate(); } } @@ -1642,7 +1588,7 @@ public void upAloudState(ReadAloudService.Status status) { */ @Override public void upAloudTimer(String text) { - readBottomMenu.setReadAloudTimer(text); + binding.readMenuBottom.setReadAloudTimer(text); } /** @@ -1674,11 +1620,11 @@ public void refresh(boolean recreate) { if (recreate) { recreate(); } else { - flContent.setBackground(readBookControl.getTextBackground(this)); + binding.flContent.setBackground(readBookControl.getTextBackground(this)); if (mPageLoader != null) { mPageLoader.refreshUi(); } - readInterfacePop.setBg(); + binding.readInterfacePop.setBg(); initImmersionBar(); } } @@ -1708,13 +1654,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { return true; } else { if (keyCode == KeyEvent.KEYCODE_BACK) { - if (readInterfacePop.getVisibility() == View.VISIBLE - || readAdjustPop.getVisibility() == View.VISIBLE - || readAdjustMarginPop.getVisibility() == View.VISIBLE - || moreSettingPop.getVisibility() == View.VISIBLE) { + if (binding.readInterfacePop.getVisibility() == View.VISIBLE + || binding.readAdjustPop.getVisibility() == View.VISIBLE + || binding.readAdjustMarginPop.getVisibility() == View.VISIBLE + || binding.moreSettingPop.getVisibility() == View.VISIBLE) { popMenuOut(); return true; - } else if (flMenu.getVisibility() == View.VISIBLE) { + } else if (binding.flMenu.getVisibility() == View.VISIBLE) { finish(); return true; } else if (ReadAloudService.running && aloudStatus == ReadAloudService.Status.PLAY) { @@ -1728,13 +1674,13 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { return true; } } else if (keyCode == KeyEvent.KEYCODE_MENU) { - if (flMenu.getVisibility() == View.VISIBLE) { + if (binding.flMenu.getVisibility() == View.VISIBLE) { popMenuOut(); } else { popMenuIn(); } return true; - } else if (flMenu.getVisibility() != View.VISIBLE) { + } else if (binding.flMenu.getVisibility() != View.VISIBLE) { if (keyCode == preferences.getInt("nextKeyCode", 0)) { if (mPageLoader != null && keyCode != 0) { mPageLoader.skipToNextPage(); @@ -1768,7 +1714,7 @@ public boolean onKeyDown(int keyCode, KeyEvent event) { @Override public boolean onKeyUp(int keyCode, KeyEvent event) { - if (flMenu.getVisibility() != View.VISIBLE) { + if (binding.flMenu.getVisibility() != View.VISIBLE) { if (readBookControl.getCanKeyTurn(aloudStatus == ReadAloudService.Status.PLAY) && keyCode != 0 && (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN @@ -1789,11 +1735,11 @@ public void upMenu() { if (menu == null) return; boolean onLine = mPresenter.getBookShelf() != null && !mPresenter.getBookShelf().getTag().equals(BookShelfBean.LOCAL_TAG); if (onLine) { - tvUrl.setVisibility(View.VISIBLE); - atvLine.setVisibility(View.VISIBLE); + binding.tvChapterUrl.setVisibility(View.VISIBLE); + binding.atvLine.setVisibility(View.VISIBLE); } else { - tvUrl.setVisibility(View.GONE); - atvLine.setVisibility(View.GONE); + binding.tvChapterUrl.setVisibility(View.GONE); + binding.atvLine.setVisibility(View.GONE); } for (int i = 0; i < menu.size(); i++) { switch (menu.getItem(i).getGroupId()) { @@ -1811,11 +1757,7 @@ public void upMenu() { menu.getItem(i).setEnabled(isTxt); break; case R.id.menu_login: - if (mPresenter.getBookSource() != null && !TextUtils.isEmpty(mPresenter.getBookSource().getLoginUrl())) { - menu.getItem(i).setVisible(true); - } else { - menu.getItem(i).setVisible(false); - } + menu.getItem(i).setVisible(mPresenter.getBookSource() != null && !TextUtils.isEmpty(mPresenter.getBookSource().getLoginUrl())); break; } if (menu.getItem(i).getItemId() == R.id.enable_replace) { @@ -1834,7 +1776,7 @@ public void upMenu() { */ @Override public void upAudioSize(int audioSize) { - mediaPlayerPop.upAudioSize(audioSize); + binding.mediaPlayerPop.upAudioSize(audioSize); } /** @@ -1842,7 +1784,7 @@ public void upAudioSize(int audioSize) { */ @Override public void upAudioDur(int audioDur) { - mediaPlayerPop.upAudioDur(audioDur); + binding.mediaPlayerPop.upAudioDur(audioDur); mPresenter.getBookShelf().setDurChapterPage(audioDur); mPresenter.saveProgress(); } @@ -1888,7 +1830,7 @@ public void onMediaButton(String cmd) { switch (cmd) { case ReadAloudService.ActionMediaPlay: ReadAloudService.resume(this); - readBottomMenu.setFabReadAloudText(getString(R.string.read_aloud)); + binding.readMenuBottom.setFabReadAloudText(getString(R.string.read_aloud)); break; case ReadAloudService.ActionMediaPrev: //停止倒计时 @@ -1902,7 +1844,7 @@ public void onMediaButton(String cmd) { mPageLoader.skipPreChapter(); } ReadAloudService.resume(this); - readBottomMenu.setFabReadAloudText(getString(R.string.read_aloud)); + binding.readMenuBottom.setFabReadAloudText(getString(R.string.read_aloud)); break; } break; @@ -1910,7 +1852,7 @@ public void onMediaButton(String cmd) { switch (cmd) { case ReadAloudService.ActionMediaPlay: ReadAloudService.pause(this); - readBottomMenu.setFabReadAloudText(getString(R.string.read_aloud_pause)); + binding.readMenuBottom.setFabReadAloudText(getString(R.string.read_aloud_pause)); break; case ReadAloudService.ActionMediaPrev: //倒计时增加 diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadStyleActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadStyleActivity.java index a7655b7da9..4f6cde7b57 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadStyleActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReadStyleActivity.java @@ -20,12 +20,9 @@ import android.view.ViewGroup; import android.widget.BaseAdapter; import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.Switch; import android.widget.TextView; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import com.hwangjr.rxbus.RxBus; import com.jaredrummler.android.colorpicker.ColorPickerDialog; @@ -34,6 +31,7 @@ import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivityReadStyleBinding; import com.kunfei.bookshelf.help.ReadBookControl; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; @@ -41,7 +39,6 @@ import com.kunfei.bookshelf.utils.FileUtils; import com.kunfei.bookshelf.utils.MeUtils; import com.kunfei.bookshelf.utils.bar.ImmersionBar; -import com.kunfei.bookshelf.widget.HorizontalListView; import com.kunfei.bookshelf.widget.filepicker.picker.FilePicker; import java.io.IOException; @@ -49,8 +46,6 @@ import java.util.Collections; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; public class ReadStyleActivity extends MBaseActivity implements ColorPickerDialogListener { @@ -58,28 +53,7 @@ public class ReadStyleActivity extends MBaseActivity implements Colo private final int SELECT_TEXT_COLOR = 201; private final int SELECT_BG_COLOR = 301; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.ll_bottom) - LinearLayout llBottom; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.tv_content) - TextView tvContent; - @BindView(R.id.tvSelectTextColor) - TextView tvSelectTextColor; - @BindView(R.id.tvSelectBgColor) - TextView tvSelectBgColor; - @BindView(R.id.tvSelectBgImage) - TextView tvSelectBgImage; - @BindView(R.id.tvDefault) - TextView tvDefault; - @BindView(R.id.sw_darkStatusIcon) - Switch swDarkStatusIcon; - - @BindView(R.id.bgImgList) - HorizontalListView bgImgList; - + private ActivityReadStyleBinding binding; private ReadBookControl readBookControl = ReadBookControl.getInstance(); private int textDrawableIndex; private int textColor; @@ -108,10 +82,10 @@ protected IPresenter initInjector() { */ @Override protected void onCreateActivity() { - setContentView(R.layout.activity_read_style); - ButterKnife.bind(this); - llContent.setPadding(0, ImmersionBar.getStatusBarHeight(this), 0, 0); - this.setSupportActionBar(toolbar); + binding = ActivityReadStyleBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + binding.llContent.setPadding(0, ImmersionBar.getStatusBarHeight(this), 0, 0); + this.setSupportActionBar(binding.toolbar); setupActionBar(); setTextKind(readBookControl); } @@ -121,11 +95,7 @@ protected void initImmersionBar() { super.initImmersionBar(); if (!isImmersionBarEnabled()) { mImmersionBar.statusBarDarkFont(false); - } else if (darkStatusIcon) { - mImmersionBar.statusBarDarkFont(true); - } else { - mImmersionBar.statusBarDarkFont(false); - } + } else mImmersionBar.statusBarDarkFont(darkStatusIcon); mImmersionBar.init(); } @@ -155,20 +125,21 @@ protected void initData() { */ @Override protected void bindEvent() { - swDarkStatusIcon.setChecked(darkStatusIcon); - swDarkStatusIcon.setOnCheckedChangeListener((compoundButton, b) -> { + binding.swDarkStatusIcon.setChecked(darkStatusIcon); + binding.swDarkStatusIcon.setOnCheckedChangeListener((compoundButton, b) -> { darkStatusIcon = b; initImmersionBar(); }); //文字背景点击事件 - llContent.setOnClickListener((view) -> { - if (llBottom.getVisibility() == View.GONE) { - llBottom.setVisibility(View.VISIBLE); + binding.llContent.setOnClickListener((view) -> { + if (binding.llBottom.getVisibility() == View.GONE) { + binding.llBottom.setVisibility(View.VISIBLE); } else { - llBottom.setVisibility(View.GONE); - }}); + binding.llBottom.setVisibility(View.GONE); + } + }); //选择文字颜色 - tvSelectTextColor.setOnClickListener(view -> + binding.tvSelectTextColor.setOnClickListener(view -> ColorPickerDialog.newBuilder() .setColor(textColor) .setShowAlphaSlider(false) @@ -176,7 +147,7 @@ protected void bindEvent() { .setDialogId(SELECT_TEXT_COLOR) .show(ReadStyleActivity.this)); //选择背景颜色 - tvSelectBgColor.setOnClickListener(view -> + binding.tvSelectBgColor.setOnClickListener(view -> ColorPickerDialog.newBuilder() .setColor(bgColor) .setShowAlphaSlider(false) @@ -187,8 +158,8 @@ protected void bindEvent() { //背景图列表 bgImgListAdapter = new BgImgListAdapter(this); bgImgListAdapter.initList(); - bgImgList.setAdapter(bgImgListAdapter); - bgImgList.setOnItemClickListener((adapterView, view, i, l) -> { + binding.bgImgList.setAdapter(bgImgListAdapter); + binding.bgImgList.setOnItemClickListener((adapterView, view, i, l) -> { if (i == 0) { selectImage(); } else { @@ -198,10 +169,10 @@ protected void bindEvent() { }); //选择背景图片 - tvSelectBgImage.setOnClickListener(view -> selectImage()); + binding.tvSelectBgImage.setOnClickListener(view -> selectImage()); //恢复默认 - tvDefault.setOnClickListener(view -> { + binding.tvDefault.setOnClickListener(view -> { bgCustom = 0; textColor = readBookControl.getDefaultTextColor(textDrawableIndex); bgDrawable = readBookControl.getDefaultBgDrawable(textDrawableIndex, this); @@ -285,15 +256,15 @@ private void saveStyle() { } private void setTextKind(ReadBookControl readBookControl) { - tvContent.setTextSize(readBookControl.getTextSize()); + binding.tvContent.setTextSize(readBookControl.getTextSize()); } private void upText() { - tvContent.setTextColor(textColor); + binding.tvContent.setTextColor(textColor); } private void upBg() { - llContent.setBackground(bgDrawable); + binding.llContent.setBackground(bgDrawable); } /** diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReplaceRuleActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReplaceRuleActivity.java index eec5791c99..d548ecff72 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ReplaceRuleActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ReplaceRuleActivity.java @@ -10,11 +10,9 @@ import android.widget.LinearLayout; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; import com.hwangjr.rxbus.RxBus; @@ -25,6 +23,7 @@ import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.bean.ReplaceRuleBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivityRecyclerVewBinding; import com.kunfei.bookshelf.help.ItemTouchCallback; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; @@ -45,8 +44,6 @@ import java.util.Arrays; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; /** @@ -57,13 +54,7 @@ public class ReplaceRuleActivity extends MBaseActivity implements ReplaceRuleContract.View { private final int IMPORT_SOURCE = 102; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - + private ActivityRecyclerVewBinding binding; private BookShelfBean bookShelfBean; private MoDialogHUD moDialogHUD; private ReplaceRuleAdapter adapter; @@ -90,7 +81,8 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_recycler_vew); + binding = ActivityRecyclerVewBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -99,8 +91,7 @@ protected void initData() { if (!TextUtils.isEmpty(dataKey)) { bookShelfBean = (BookShelfBean) BitIntentDataManager.getInstance().getData(dataKey); } - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); initRecyclerView(); moDialogHUD = new MoDialogHUD(this); @@ -108,15 +99,15 @@ protected void initData() { } private void initRecyclerView() { - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.addItemDecoration(new DividerItemDecoration(this, LinearLayout.VERTICAL)); adapter = new ReplaceRuleAdapter(this); - recyclerView.setAdapter(adapter); + binding.recyclerView.setAdapter(adapter); ItemTouchCallback itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); itemTouchCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); - itemTouchHelper.attachToRecyclerView(recyclerView); + itemTouchHelper.attachToRecyclerView(binding.recyclerView); } public void editReplaceRule(ReplaceRuleBean replaceRuleBean) { @@ -298,6 +289,6 @@ protected void onDestroy() { @Override public Snackbar getSnackBar(String msg, int length) { - return Snackbar.make(llContent, msg, length); + return Snackbar.make(binding.llContent, msg, length); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/SearchBookActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/SearchBookActivity.java index 6806a9c3ef..5502e3ac91 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/SearchBookActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/SearchBookActivity.java @@ -19,14 +19,9 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.Toolbar; -import androidx.cardview.widget.CardView; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.flexbox.FlexboxLayout; import com.google.android.flexbox.FlexboxLayoutManager; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.hwangjr.rxbus.RxBus; import com.kunfei.basemvplib.BitIntentDataManager; import com.kunfei.bookshelf.MApplication; @@ -36,6 +31,7 @@ import com.kunfei.bookshelf.bean.SearchBookBean; import com.kunfei.bookshelf.bean.SearchHistoryBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivitySearchBookBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.model.BookSourceManager; import com.kunfei.bookshelf.presenter.BookDetailPresenter; @@ -49,39 +45,15 @@ import com.kunfei.bookshelf.view.adapter.SearchBookshelfAdapter; import com.kunfei.bookshelf.widget.explosion_field.ExplosionField; import com.kunfei.bookshelf.widget.recycler.refresh.OnLoadMoreListener; -import com.kunfei.bookshelf.widget.recycler.refresh.RefreshRecyclerView; import java.util.List; import java.util.Objects; -import butterknife.BindView; -import butterknife.ButterKnife; - public class SearchBookActivity extends MBaseActivity implements SearchBookContract.View, SearchBookshelfAdapter.CallBack { private final int requestSource = 14; - @BindView(R.id.searchView) - SearchView searchView; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.card_search) - CardView cardSearch; - @BindView(R.id.ll_search_history) - LinearLayout llSearchHistory; - @BindView(R.id.tv_search_history_clean) - TextView tvSearchHistoryClean; - @BindView(R.id.tfl_search_history) - FlexboxLayout flSearchHistory; - @BindView(R.id.rfRv_search_books) - RefreshRecyclerView rfRvSearchBooks; - @BindView(R.id.fabSearchStop) - FloatingActionButton fabSearchStop; - @BindView(R.id.tv_bookshelf) - TextView tvBookshelf; - @BindView(R.id.rv_bookshelf) - RecyclerView rvBookshelf; - + private ActivitySearchBookBinding binding; private View refreshErrorView; private ExplosionField mExplosionField; private SearchBookAdapter searchBookAdapter; @@ -110,8 +82,8 @@ protected SearchBookContract.Presenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_search_book); - ButterKnife.bind(this); + binding = ActivitySearchBookBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -124,23 +96,23 @@ protected void initData() { @SuppressLint("InflateParams") @Override protected void bindView() { - cardSearch.setCardBackgroundColor(ThemeStore.primaryColorDark(this)); + binding.cardSearch.setCardBackgroundColor(ThemeStore.primaryColorDark(this)); initSearchView(); - setSupportActionBar(toolbar); + setSupportActionBar(binding.toolbar); setupActionBar(); - fabSearchStop.hide(); - fabSearchStop.setBackgroundTintList(Selector.colorBuild() + binding.fabSearchStop.hide(); + binding.fabSearchStop.setBackgroundTintList(Selector.colorBuild() .setDefaultColor(ThemeStore.accentColor(this)) .setPressedColor(ColorUtil.darkenColor(ThemeStore.accentColor(this))) .create()); - llSearchHistory.setOnClickListener(null); - rfRvSearchBooks.setRefreshRecyclerViewAdapter(searchBookAdapter, new LinearLayoutManager(this)); + binding.llSearchHistory.setOnClickListener(null); + binding.rfRvSearchBooks.setRefreshRecyclerViewAdapter(searchBookAdapter, new LinearLayoutManager(this)); refreshErrorView = LayoutInflater.from(this).inflate(R.layout.view_refresh_error, null); refreshErrorView.findViewById(R.id.tv_refresh_again).setOnClickListener(v -> { //刷新失败 ,重试 toSearch(); }); - rfRvSearchBooks.setNoDataAndRefreshErrorView(LayoutInflater.from(this).inflate(R.layout.view_refresh_no_data, null), + binding.rfRvSearchBooks.setNoDataAndRefreshErrorView(LayoutInflater.from(this).inflate(R.layout.view_refresh_no_data, null), refreshErrorView); searchBookAdapter.setItemClickListener((view, position) -> { @@ -152,12 +124,12 @@ protected void bindView() { startActivityByAnim(intent, android.R.anim.fade_in, android.R.anim.fade_out); }); - fabSearchStop.setOnClickListener(view -> { - fabSearchStop.hide(); + binding.fabSearchStop.setOnClickListener(view -> { + binding.fabSearchStop.hide(); mPresenter.stopSearch(); }); - rvBookshelf.setLayoutManager(new FlexboxLayoutManager(this)); - rvBookshelf.setAdapter(searchBookshelfAdapter); + binding.rvBookshelf.setLayoutManager(new FlexboxLayoutManager(this)); + binding.rvBookshelf.setAdapter(searchBookshelfAdapter); } //设置ToolBar @@ -205,15 +177,15 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void initSearchView() { - mSearchAutoComplete = searchView.findViewById(R.id.search_src_text); - searchView.setQueryHint(getString(R.string.search_book_key)); + mSearchAutoComplete = binding.searchView.findViewById(R.id.search_src_text); + binding.searchView.setQueryHint(getString(R.string.search_book_key)); //获取到TextView的控件 mSearchAutoComplete.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14); mSearchAutoComplete.setPadding(15, 0, 0, 0); - searchView.onActionViewExpanded(); - LinearLayout editFrame = searchView.findViewById(R.id.search_edit_frame); - ImageView closeButton = searchView.findViewById(R.id.search_close_btn); - ImageView goButton = searchView.findViewById(R.id.search_go_btn); + binding.searchView.onActionViewExpanded(); + LinearLayout editFrame = binding.searchView.findViewById(R.id.search_edit_frame); + ImageView closeButton = binding.searchView.findViewById(R.id.search_close_btn); + ImageView goButton = binding.searchView.findViewById(R.id.search_go_btn); LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) editFrame.getLayoutParams(); params.setMargins(20, 0, 10, 0); editFrame.setLayoutParams(params); @@ -221,8 +193,8 @@ private void initSearchView() { closeButton.setScaleY(0.9f); closeButton.setPadding(0, 0, 0, 0); goButton.setPadding(0, 0, 0, 0); - searchView.setSubmitButtonEnabled(true); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + binding.searchView.setSubmitButtonEnabled(true); + binding.searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (TextUtils.isEmpty(query)) @@ -230,13 +202,12 @@ public boolean onQueryTextSubmit(String query) { searchKey = query.trim(); if (!searchKey.toLowerCase().startsWith("set:")) { toSearch(); - searchView.clearFocus(); - return false; + binding.searchView.clearFocus(); } else { parseSecretCode(searchKey); finish(); - return false; } + return false; } @Override @@ -245,15 +216,15 @@ public boolean onQueryTextChange(String newText) { List beans = BookshelfHelp.searchBookInfo(newText); searchBookshelfAdapter.setItems(beans); if (beans.size() > 0) { - tvBookshelf.setVisibility(View.VISIBLE); - rvBookshelf.setVisibility(View.VISIBLE); + binding.tvBookshelf.setVisibility(View.VISIBLE); + binding.rvBookshelf.setVisibility(View.VISIBLE); } else { - tvBookshelf.setVisibility(View.GONE); - rvBookshelf.setVisibility(View.GONE); + binding.tvBookshelf.setVisibility(View.GONE); + binding.rvBookshelf.setVisibility(View.GONE); } } else { - tvBookshelf.setVisibility(View.GONE); - rvBookshelf.setVisibility(View.GONE); + binding.tvBookshelf.setVisibility(View.GONE); + binding.rvBookshelf.setVisibility(View.GONE); } if (!newText.toLowerCase().startsWith("set")) { mPresenter.querySearchHistory(newText); @@ -263,13 +234,13 @@ public boolean onQueryTextChange(String newText) { return false; } }); - searchView.setOnQueryTextFocusChangeListener((view, b) -> { + binding.searchView.setOnQueryTextFocusChangeListener((view, b) -> { showHistory = b; - if (!b && searchView.getQuery().toString().trim().equals("")) { + if (!b && binding.searchView.getQuery().toString().trim().equals("")) { finish(); } if (showHistory) { - fabSearchStop.hide(); + binding.fabSearchStop.hide(); mPresenter.stopSearch(); } openOrCloseHistory(showHistory); @@ -278,21 +249,21 @@ public boolean onQueryTextChange(String newText) { @Override protected void bindEvent() { - tvSearchHistoryClean.setOnClickListener(v -> { - mExplosionField.explode(flSearchHistory, true); + binding.tvSearchHistoryClean.setOnClickListener(v -> { + mExplosionField.explode(binding.tflSearchHistory, true); mPresenter.cleanSearchHistory(); }); - rfRvSearchBooks.setLoadMoreListener(new OnLoadMoreListener() { + binding.rfRvSearchBooks.setLoadMoreListener(new OnLoadMoreListener() { @Override public void startLoadMore() { - fabSearchStop.show(); + binding.fabSearchStop.show(); mPresenter.toSearchBooks(null, false); } @Override public void loadMoreErrorTryAgain() { - fabSearchStop.show(); + binding.fabSearchStop.show(); mPresenter.toSearchBooks(null, true); } }); @@ -308,7 +279,7 @@ protected void firstRequest() { @Override public void onPause() { super.onPause(); - showHistory = llSearchHistory.getVisibility() == View.VISIBLE; + showHistory = binding.llSearchHistory.getVisibility() == View.VISIBLE; } @Override @@ -320,7 +291,7 @@ public void onResume() { @Override public void searchBook(String searchKey) { if (!TextUtils.isEmpty(searchKey)) { - searchView.setQuery(searchKey, true); + binding.searchView.setQuery(searchKey, true); showHistory = false; } else { showHistory = true; @@ -356,19 +327,19 @@ private void initMenu() { } private void showHideSetting() { - flSearchHistory.removeAllViews(); + binding.tflSearchHistory.removeAllViews(); TextView tagView; String[] hideSettings = {"show_nav_shelves", "fade_tts", "use_regex_in_new_rule", "blur_sim_back", "async_draw", "disable_scroll_click_turn"}; for (String text : hideSettings) { - tagView = (TextView) getLayoutInflater().inflate(R.layout.item_search_history, flSearchHistory, false); + tagView = (TextView) getLayoutInflater().inflate(R.layout.item_search_history, binding.tflSearchHistory, false); tagView.setTag(text); tagView.setText(text); tagView.setOnClickListener(view -> { String key = "set:" + view.getTag(); - searchView.setQuery(key, false); + binding.searchView.setQuery(key, false); }); - flSearchHistory.addView(tagView); + binding.tflSearchHistory.addView(tagView); } } @@ -420,8 +391,8 @@ private void toSearch() { //执行搜索请求 new Handler().postDelayed(() -> { mPresenter.initPage(); - rfRvSearchBooks.startRefresh(); - fabSearchStop.show(); + binding.rfRvSearchBooks.startRefresh(); + binding.fabSearchStop.show(); mPresenter.toSearchBooks(searchKey, false); }, 300); } @@ -429,32 +400,28 @@ private void toSearch() { private void openOrCloseHistory(Boolean open) { if (open) { - if (llSearchHistory.getVisibility() != View.VISIBLE) { - llSearchHistory.setVisibility(View.VISIBLE); + if (binding.llSearchHistory.getVisibility() != View.VISIBLE) { + binding.llSearchHistory.setVisibility(View.VISIBLE); } } else { - if (llSearchHistory.getVisibility() == View.VISIBLE) { - llSearchHistory.setVisibility(View.GONE); + if (binding.llSearchHistory.getVisibility() == View.VISIBLE) { + binding.llSearchHistory.setVisibility(View.GONE); } } } private void addNewHistories(List historyBeans) { - flSearchHistory.removeAllViews(); + binding.tflSearchHistory.removeAllViews(); if (historyBeans != null) { TextView tagView; for (SearchHistoryBean searchHistoryBean : historyBeans) { - tagView = (TextView) getLayoutInflater().inflate(R.layout.item_search_history, flSearchHistory, false); + tagView = (TextView) getLayoutInflater().inflate(R.layout.item_search_history, binding.tflSearchHistory, false); tagView.setTag(searchHistoryBean); tagView.setText(searchHistoryBean.getContent()); tagView.setOnClickListener(view -> { SearchHistoryBean historyBean = (SearchHistoryBean) view.getTag(); List beans = BookshelfHelp.searchBookInfo(historyBean.getContent()); - if (beans.isEmpty()) { - searchView.setQuery(historyBean.getContent(), true); - } else { - searchView.setQuery(historyBean.getContent(), false); - } + binding.searchView.setQuery(historyBean.getContent(), beans.isEmpty()); }); tagView.setOnLongClickListener(view -> { SearchHistoryBean historyBean = (SearchHistoryBean) view.getTag(); @@ -463,7 +430,7 @@ private void addNewHistories(List historyBeans) { mPresenter.cleanSearchHistory(historyBean); return true; }); - flSearchHistory.addView(tagView); + binding.tflSearchHistory.addView(tagView); } } } @@ -477,10 +444,10 @@ public void insertSearchHistorySuccess(SearchHistoryBean searchHistoryBean) { @Override public void querySearchHistorySuccess(List data) { addNewHistories(data); - if (flSearchHistory.getChildCount() > 0) { - tvSearchHistoryClean.setVisibility(View.VISIBLE); + if (binding.tflSearchHistory.getChildCount() > 0) { + binding.tvSearchHistoryClean.setVisibility(View.VISIBLE); } else { - tvSearchHistoryClean.setVisibility(View.INVISIBLE); + binding.tvSearchHistoryClean.setVisibility(View.INVISIBLE); } } @@ -491,23 +458,23 @@ public void refreshSearchBook() { @Override public void refreshFinish(Boolean isAll) { - fabSearchStop.hide(); - rfRvSearchBooks.finishRefresh(isAll, true); + binding.fabSearchStop.hide(); + binding.rfRvSearchBooks.finishRefresh(isAll, true); } @Override public void loadMoreFinish(Boolean isAll) { - fabSearchStop.hide(); - rfRvSearchBooks.finishLoadMore(isAll, true); + binding.fabSearchStop.hide(); + binding.rfRvSearchBooks.finishLoadMore(isAll, true); } @Override public void searchBookError(Throwable throwable) { if (searchBookAdapter.getICount() == 0) { ((TextView) refreshErrorView.findViewById(R.id.tv_error_msg)).setText(throwable.getMessage()); - rfRvSearchBooks.refreshError(); + binding.rfRvSearchBooks.refreshError(); } else { - rfRvSearchBooks.loadMoreError(); + binding.rfRvSearchBooks.loadMoreError(); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/SettingActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/SettingActivity.java index 57e7c626b0..0881688ad8 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/SettingActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/SettingActivity.java @@ -3,33 +3,26 @@ import android.content.Context; import android.content.Intent; import android.view.MenuItem; -import android.widget.LinearLayout; import androidx.annotation.Nullable; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; +import com.kunfei.bookshelf.databinding.ActivitySettingsBinding; import com.kunfei.bookshelf.help.storage.BackupRestoreUi; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.fragment.SettingsFragment; -import butterknife.BindView; -import butterknife.ButterKnife; - /** * Created by GKF on 2017/12/16. * 设置 */ public class SettingActivity extends MBaseActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_content) - LinearLayout llContent; + private ActivitySettingsBinding binding; private SettingsFragment settingsFragment = new SettingsFragment(); public static void startThis(Context context) { @@ -44,9 +37,9 @@ protected IPresenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_settings); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivitySettingsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(getString(R.string.setting)); getFragmentManager().beginTransaction() diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceDebugActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceDebugActivity.java index f89014e91e..ea24008f99 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceDebugActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceDebugActivity.java @@ -9,11 +9,8 @@ import androidx.appcompat.app.ActionBar; import androidx.appcompat.widget.SearchView; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.appbar.AppBarLayout; import com.hwangjr.rxbus.RxBus; import com.hwangjr.rxbus.annotation.Subscribe; import com.hwangjr.rxbus.annotation.Tag; @@ -22,31 +19,19 @@ import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.ActivitySourceDebugBinding; import com.kunfei.bookshelf.model.content.Debug; import com.kunfei.bookshelf.utils.SoftInputUtil; import com.kunfei.bookshelf.utils.StringUtils; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.adapter.SourceDebugAdapter; -import com.kunfei.bookshelf.widget.RotateLoading; -import butterknife.BindView; -import butterknife.ButterKnife; import io.reactivex.disposables.CompositeDisposable; public class SourceDebugActivity extends MBaseActivity { private final int REQUEST_QR = 202; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.searchView) - SearchView searchView; - @BindView(R.id.loading) - RotateLoading loading; - @BindView(R.id.action_bar) - AppBarLayout actionBar; - @BindView(R.id.lv_log) - RecyclerView recyclerView; - + private ActivitySourceDebugBinding binding; private SourceDebugAdapter adapter; private CompositeDisposable compositeDisposable; private String sourceTag; @@ -89,7 +74,8 @@ protected void onDestroy() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_source_debug); + binding = ActivitySourceDebugBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } /** @@ -103,26 +89,25 @@ protected void initData() { @Override protected void bindView() { super.bindView(); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); initSearchView(); adapter = new SourceDebugAdapter(this); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.setAdapter(adapter); } private void initSearchView() { - searchView.setQueryHint(getString(R.string.debug_hint)); - searchView.onActionViewExpanded(); - searchView.setSubmitButtonEnabled(true); - searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { + binding.searchView.setQueryHint(getString(R.string.debug_hint)); + binding.searchView.onActionViewExpanded(); + binding.searchView.setSubmitButtonEnabled(true); + binding.searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { if (TextUtils.isEmpty(query)) return false; startDebug(query); - SoftInputUtil.hideIMM(searchView); + SoftInputUtil.hideIMM(binding.searchView); return true; } @@ -142,7 +127,7 @@ private void startDebug(String key) { compositeDisposable.dispose(); } compositeDisposable = new CompositeDisposable(); - loading.start(); + binding.loading.start(); adapter.clearData(); Debug.newDebug(sourceTag, key, compositeDisposable); } @@ -189,7 +174,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == REQUEST_QR) { String result = data.getStringExtra("result"); if (!StringUtils.isTrimEmpty(result)) { - searchView.setQuery(result, true); + binding.searchView.setQuery(result, true); } } } @@ -199,7 +184,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) { public void printDebugLog(String msg) { adapter.addData(msg); if (msg.equals("finish")) { - loading.stop(); + binding.loading.stop(); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceEditActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceEditActivity.java index 7a748c32c1..4a92d96294 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceEditActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceEditActivity.java @@ -17,20 +17,15 @@ import android.view.View; import android.view.ViewTreeObserver; import android.widget.EditText; -import android.widget.LinearLayout; import android.widget.PopupWindow; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AlertDialog; -import androidx.appcompat.widget.Toolbar; import androidx.core.content.FileProvider; import androidx.fragment.app.Fragment; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; -import com.google.android.material.appbar.AppBarLayout; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.zxing.EncodeHintType; @@ -43,6 +38,7 @@ import com.kunfei.bookshelf.base.observer.MySingleObserver; import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.constant.BookType; +import com.kunfei.bookshelf.databinding.ActivitySourceEditBinding; import com.kunfei.bookshelf.model.BookSourceManager; import com.kunfei.bookshelf.presenter.SourceEditPresenter; import com.kunfei.bookshelf.presenter.contract.SourceEditContract; @@ -52,7 +48,6 @@ import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.adapter.SourceEditAdapter; import com.kunfei.bookshelf.view.popupwindow.KeyboardToolPop; -import com.kunfei.bookshelf.widget.views.ATECheckBox; import org.jetbrains.annotations.NotNull; @@ -64,8 +59,6 @@ import java.util.List; import java.util.Objects; -import butterknife.BindView; -import butterknife.ButterKnife; import cn.bingoogolapple.qrcode.zxing.QRCodeEncoder; import io.reactivex.Observable; import io.reactivex.Single; @@ -82,21 +75,7 @@ public class SourceEditActivity extends MBaseActivity sourceEditList = new ArrayList<>(); private List findEditList = new ArrayList<>(); @@ -158,7 +137,8 @@ protected void onSaveInstanceState(@NonNull Bundle outState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_source_edit); + binding = ActivitySourceEditBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override @@ -180,14 +160,13 @@ protected void initData() { @Override protected void bindView() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); mSoftKeyboardTool = new KeyboardToolPop(this, Arrays.asList(keyHelp), this); getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new KeyboardOnGlobalChangeListener()); adapter = new SourceEditAdapter(this); - recyclerView.setLayoutManager(new LinearLayoutManager(this)); - recyclerView.setAdapter(adapter); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.setAdapter(adapter); adapter.reSetData(sourceEditList); setText(bookSourceBean); } @@ -195,23 +174,23 @@ protected void bindView() { @Override protected void bindEvent() { super.bindEvent(); - tvEditFind.setOnClickListener(v -> { - recyclerView.clearFocus(); + binding.tvEditFind.setOnClickListener(v -> { + binding.recyclerView.clearFocus(); if (showFind) { adapter.reSetData(sourceEditList); - tvEditFind.setText(R.string.edit_find); + binding.tvEditFind.setText(R.string.edit_find); } else { adapter.reSetData(findEditList); - tvEditFind.setText(R.string.back); + binding.tvEditFind.setText(R.string.back); } showFind = !showFind; - recyclerView.scrollToPosition(0); + binding.recyclerView.scrollToPosition(0); }); } private boolean canSaveBookSource() { - SoftInputUtil.hideIMM(recyclerView); - recyclerView.clearFocus(); + SoftInputUtil.hideIMM(binding.recyclerView); + binding.recyclerView.clearFocus(); BookSourceBean bookSourceBean = getBookSource(true); if (isEmpty(bookSourceBean.getBookSourceName()) || isEmpty(bookSourceBean.getBookSourceUrl())) { toast(R.string.non_null_source_name_url, ERROR); @@ -285,8 +264,8 @@ public void setText(BookSourceBean bookSourceBean) { } else { adapter.reSetData(sourceEditList); } - cbIsAudio.setChecked(Objects.equals(bookSourceBean.getBookSourceType(), BookType.AUDIO)); - cbIsEnable.setChecked(bookSourceBean.getEnable()); + binding.cbIsAudio.setChecked(Objects.equals(bookSourceBean.getBookSourceType(), BookType.AUDIO)); + binding.cbIsEnable.setChecked(bookSourceBean.getEnable()); } private void scanBookSource() { @@ -424,8 +403,8 @@ private BookSourceBean getBookSource(boolean hasFind) { } } bookSourceBeanN.setSerialNumber(serialNumber); - bookSourceBeanN.setEnable(cbIsEnable.isChecked()); - bookSourceBeanN.setBookSourceType(cbIsAudio.isChecked() ? BookType.AUDIO : null); + bookSourceBeanN.setEnable(binding.cbIsEnable.isChecked()); + bookSourceBeanN.setBookSourceType(binding.cbIsAudio.isChecked() ? BookType.AUDIO : null); return bookSourceBeanN; } @@ -678,7 +657,7 @@ private void showKeyboardTopPopupWindow() { return; } if (mSoftKeyboardTool != null & !this.isFinishing()) { - mSoftKeyboardTool.showAtLocation(llContent, Gravity.BOTTOM, 0, 0); + mSoftKeyboardTool.showAtLocation(binding.llContent, Gravity.BOTTOM, 0, 0); } } @@ -699,11 +678,11 @@ public void onGlobalLayout() { boolean preShowing = mIsSoftKeyBoardShowing; if (Math.abs(keyboardHeight) > screenHeight / 5) { mIsSoftKeyBoardShowing = true; // 超过屏幕五分之一则表示弹出了输入法 - recyclerView.setPadding(0, 0, 0, 100); + binding.recyclerView.setPadding(0, 0, 0, 100); showKeyboardTopPopupWindow(); } else { mIsSoftKeyBoardShowing = false; - recyclerView.setPadding(0, 0, 0, 0); + binding.recyclerView.setPadding(0, 0, 0, 0); if (preShowing) { closePopupWindow(); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceLoginActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceLoginActivity.java index 34a176e4a7..979bcf387b 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceLoginActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/SourceLoginActivity.java @@ -12,12 +12,9 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; -import android.widget.LinearLayout; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; -import com.google.android.material.appbar.AppBarLayout; import com.kunfei.basemvplib.BitIntentDataManager; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.DbHelper; @@ -25,21 +22,12 @@ import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.bean.CookieBean; +import com.kunfei.bookshelf.databinding.ActivitySourceLoginBinding; import com.kunfei.bookshelf.utils.theme.ThemeStore; -import butterknife.BindView; -import butterknife.ButterKnife; - public class SourceLoginActivity extends MBaseActivity { - @BindView(R.id.web_view) - WebView webView; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.action_bar) - AppBarLayout actionBar; - @BindView(R.id.ll_content) - LinearLayout llContent; + private ActivitySourceLoginBinding binding; private BookSourceBean bookSourceBean; private boolean checking = false; @@ -74,9 +62,9 @@ protected void onCreate(Bundle savedInstanceState) { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_source_login); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivitySourceLoginBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); } @@ -88,13 +76,13 @@ protected void onCreateActivity() { protected void initData() { String key = this.getIntent().getStringExtra("data_key"); bookSourceBean = (BookSourceBean) BitIntentDataManager.getInstance().getData(key); - WebSettings settings = webView.getSettings(); + WebSettings settings = binding.webView.getSettings(); settings.setSupportZoom(true); settings.setBuiltInZoomControls(true); settings.setDefaultTextEncodingName("UTF-8"); settings.setJavaScriptEnabled(true); CookieManager cookieManager = CookieManager.getInstance(); - webView.setWebViewClient(new WebViewClient() { + binding.webView.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { String cookie = cookieManager.getCookie(url); @@ -109,11 +97,11 @@ public void onPageFinished(WebView view, String url) { if (checking) finish(); else - showSnackBar(toolbar, getString(R.string.click_check_after_success)); + showSnackBar(binding.toolbar, getString(R.string.click_check_after_success)); super.onPageFinished(view, url); } }); - webView.loadUrl(bookSourceBean.getLoginUrl()); + binding.webView.loadUrl(bookSourceBean.getLoginUrl()); } //设置ToolBar @@ -140,8 +128,8 @@ public boolean onOptionsItemSelected(MenuItem item) { case R.id.action_check: if (checking) break; checking = true; - showSnackBar(toolbar, getString(R.string.check_host_cookie)); - webView.loadUrl(bookSourceBean.getBookSourceUrl()); + showSnackBar(binding.toolbar, getString(R.string.check_host_cookie)); + binding.webView.loadUrl(bookSourceBean.getBookSourceUrl()); break; case android.R.id.home: finish(); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/ThemeSettingActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/ThemeSettingActivity.java index 25b846e435..00f929e150 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/ThemeSettingActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/ThemeSettingActivity.java @@ -3,30 +3,24 @@ import android.content.Context; import android.content.Intent; import android.view.MenuItem; -import android.widget.LinearLayout; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; +import com.kunfei.bookshelf.databinding.ActivitySettingsBinding; import com.kunfei.bookshelf.utils.theme.ThemeStore; import com.kunfei.bookshelf.view.fragment.ThemeSettingsFragment; -import butterknife.BindView; -import butterknife.ButterKnife; - /** * Created by GKF on 2017/12/16. * 设置 */ public class ThemeSettingActivity extends MBaseActivity { - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_content) - LinearLayout llContent; + + private ActivitySettingsBinding binding; public static void startThis(Context context) { context.startActivity(new Intent(context, ThemeSettingActivity.class)); @@ -40,9 +34,9 @@ protected IPresenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_settings); - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + binding = ActivitySettingsBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + this.setSupportActionBar(binding.toolbar); setupActionBar(); ThemeSettingsFragment settingsFragment = new ThemeSettingsFragment(); getFragmentManager().beginTransaction() diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/TxtChapterRuleActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/TxtChapterRuleActivity.java index f21be2a479..9b6f898a5c 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/TxtChapterRuleActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/TxtChapterRuleActivity.java @@ -4,18 +4,16 @@ import android.content.Intent; import android.view.Menu; import android.view.MenuItem; -import android.widget.LinearLayout; import androidx.appcompat.app.ActionBar; -import androidx.appcompat.widget.Toolbar; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.google.android.material.snackbar.Snackbar; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; import com.kunfei.bookshelf.bean.TxtChapterRuleBean; +import com.kunfei.bookshelf.databinding.ActivityRecyclerVewBinding; import com.kunfei.bookshelf.help.ItemTouchCallback; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; @@ -28,20 +26,12 @@ import com.kunfei.bookshelf.widget.filepicker.picker.FilePicker; import com.kunfei.bookshelf.widget.modialog.TxtChapterRuleDialog; -import butterknife.BindView; -import butterknife.ButterKnife; import kotlin.Unit; public class TxtChapterRuleActivity extends MBaseActivity implements TxtChapterRuleContract.View { private final int requestImport = 102; - @BindView(R.id.toolbar) - Toolbar toolbar; - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - + private ActivityRecyclerVewBinding binding; private TxtChapterRuleAdapter adapter; private boolean selectAll = true; @@ -59,13 +49,13 @@ protected TxtChapterRuleContract.Presenter initInjector() { @Override protected void onCreateActivity() { getWindow().getDecorView().setBackgroundColor(ThemeStore.backgroundColor(this)); - setContentView(R.layout.activity_recycler_vew); + binding = ActivityRecyclerVewBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); } @Override protected void initData() { - ButterKnife.bind(this); - this.setSupportActionBar(toolbar); + this.setSupportActionBar(binding.toolbar); setupActionBar(); initRecyclerView(); refresh(); @@ -115,14 +105,14 @@ public boolean onOptionsItemSelected(MenuItem item) { } private void initRecyclerView() { - recyclerView.setLayoutManager(new LinearLayoutManager(this)); + binding.recyclerView.setLayoutManager(new LinearLayoutManager(this)); adapter = new TxtChapterRuleAdapter(this); - recyclerView.setAdapter(adapter); + binding.recyclerView.setAdapter(adapter); ItemTouchCallback itemTouchCallback = new ItemTouchCallback(); itemTouchCallback.setOnItemTouchCallbackListener(adapter.getItemTouchCallbackListener()); itemTouchCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); - itemTouchHelper.attachToRecyclerView(recyclerView); + itemTouchHelper.attachToRecyclerView(binding.recyclerView); } public void editChapterRule(TxtChapterRuleBean txtChapterRuleBean) { @@ -171,7 +161,7 @@ public void refresh() { @Override public Snackbar getSnackBar(String msg, int length) { - return Snackbar.make(llContent, msg, length); + return Snackbar.make(binding.llContent, msg, length); } private void selectReplaceRuleFile() { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/activity/WelcomeActivity.java b/app/src/main/java/com/kunfei/bookshelf/view/activity/WelcomeActivity.java index 3af9a8988d..5785d4fb59 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/activity/WelcomeActivity.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/activity/WelcomeActivity.java @@ -5,25 +5,18 @@ import android.animation.ValueAnimator; import android.content.Intent; import android.os.AsyncTask; -import android.widget.ImageView; -import android.widget.TextView; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.DbHelper; import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseActivity; +import com.kunfei.bookshelf.databinding.ActivityWelcomeBinding; import com.kunfei.bookshelf.presenter.ReadBookPresenter; import com.kunfei.bookshelf.utils.theme.ThemeStore; -import butterknife.BindView; -import butterknife.ButterKnife; - public class WelcomeActivity extends MBaseActivity { - @BindView(R.id.iv_bg) - ImageView ivBg; - @BindView(R.id.tv_gzh) - TextView tvGzh; + private ActivityWelcomeBinding binding; @Override protected IPresenter initInjector() { @@ -37,16 +30,16 @@ protected void onCreateActivity() { finish(); return; } - setContentView(R.layout.activity_welcome); + binding = ActivityWelcomeBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); AsyncTask.execute(DbHelper::getDaoSession); - ButterKnife.bind(this); - tvGzh.setTextColor(ThemeStore.accentColor(this)); - ivBg.setColorFilter(ThemeStore.accentColor(this)); + binding.tvGzh.setTextColor(ThemeStore.accentColor(this)); + binding.ivBg.setColorFilter(ThemeStore.accentColor(this)); ValueAnimator welAnimator = ValueAnimator.ofFloat(1f, 0f).setDuration(800); welAnimator.setStartDelay(500); welAnimator.addUpdateListener(animation -> { float alpha = (Float) animation.getAnimatedValue(); - ivBg.setAlpha(alpha); + binding.ivBg.setAlpha(alpha); }); welAnimator.addListener(new Animator.AnimatorListener() { @Override diff --git a/app/src/main/java/com/kunfei/bookshelf/view/adapter/ChapterListAdapter.java b/app/src/main/java/com/kunfei/bookshelf/view/adapter/ChapterListAdapter.java index 3f94ae23c9..4edbffd639 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/adapter/ChapterListAdapter.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/adapter/ChapterListAdapter.java @@ -129,7 +129,7 @@ public void onBindViewHolder(@NonNull ThisViewHolder holder, int position, @NonN @Override public int getItemCount() { - if (bookShelfBean == null) + if (bookShelfBean == null || allChapter == null) return 0; else { if (isSearch) { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookListFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookListFragment.java index 33f95df530..11cb5a8f36 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookListFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookListFragment.java @@ -4,11 +4,9 @@ import android.content.Intent; import android.content.SharedPreferences; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.View; -import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.RelativeLayout; -import android.widget.TextView; +import android.view.ViewGroup; import android.widget.Toast; import androidx.annotation.Nullable; @@ -17,7 +15,6 @@ import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import androidx.viewpager.widget.ViewPager; import com.kunfei.basemvplib.BitIntentDataManager; @@ -26,6 +23,7 @@ import com.kunfei.bookshelf.base.MBaseFragment; import com.kunfei.bookshelf.base.observer.MySingleObserver; import com.kunfei.bookshelf.bean.BookShelfBean; +import com.kunfei.bookshelf.databinding.FragmentBookListBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.help.ItemTouchCallback; import com.kunfei.bookshelf.presenter.BookDetailPresenter; @@ -45,35 +43,13 @@ import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; public class BookListFragment extends MBaseFragment implements BookListContract.View { - @BindView(R.id.refresh_layout) - SwipeRefreshLayout refreshLayout; - @BindView(R.id.local_book_rv_content) - RecyclerView rvBookshelf; - @BindView(R.id.tv_empty) - TextView tvEmpty; - @BindView(R.id.rl_empty_view) - RelativeLayout rlEmptyView; - @BindView(R.id.iv_back) - ImageView ivBack; - @BindView(R.id.action_bar) - LinearLayout actionBar; - @BindView(R.id.tv_select_count) - TextView tvSelectCount; - @BindView(R.id.iv_del) - ImageView ivDel; - @BindView(R.id.iv_select_all) - ImageView ivSelectAll; - private CallbackValue callbackValue; - private Unbinder unbinder; + private FragmentBookListBinding binding; private String bookPx; private boolean resumed = false; private boolean isRecreate; @@ -90,8 +66,9 @@ public void onCreate(@Nullable Bundle savedInstanceState) { } @Override - public int createLayoutId() { - return R.layout.fragment_book_list; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentBookListBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -109,55 +86,51 @@ protected void initData() { @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); int bookshelfLayout = preferences.getInt("bookshelfLayout", 0); if (bookshelfLayout == 0) { - rvBookshelf.setLayoutManager(new LinearLayoutManager(getContext())); + binding.rvBookshelf.setLayoutManager(new LinearLayoutManager(getContext())); bookShelfAdapter = new BookShelfListAdapter(getActivity()); } else { - rvBookshelf.setLayoutManager(new GridLayoutManager(getContext(), bookshelfLayout + 2)); + binding.rvBookshelf.setLayoutManager(new GridLayoutManager(getContext(), bookshelfLayout + 2)); bookShelfAdapter = new BookShelfGridAdapter(getActivity()); } - rvBookshelf.setAdapter((RecyclerView.Adapter) bookShelfAdapter); - refreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); + binding.rvBookshelf.setAdapter((RecyclerView.Adapter) bookShelfAdapter); + binding.refreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); } @Override protected void firstRequest() { group = preferences.getInt("bookshelfGroup", 0); - if (preferences.getBoolean(getString(R.string.pk_auto_refresh), false) - && !isRecreate && NetworkUtils.isNetWorkAvailable() && group != 2) { - mPresenter.queryBookShelf(true, group); - } else { - mPresenter.queryBookShelf(false, group); - } + boolean needRefresh = preferences.getBoolean(getString(R.string.pk_auto_refresh), false) + && !isRecreate && NetworkUtils.isNetWorkAvailable() && group != 2; + mPresenter.queryBookShelf(needRefresh, group); } @Override protected void bindEvent() { - refreshLayout.setOnRefreshListener(() -> { + binding.refreshLayout.setOnRefreshListener(() -> { mPresenter.queryBookShelf(NetworkUtils.isNetWorkAvailable(), group); if (!NetworkUtils.isNetWorkAvailable()) { Toast.makeText(getContext(), R.string.network_connection_unavailable, Toast.LENGTH_SHORT).show(); } - refreshLayout.setRefreshing(false); + binding.refreshLayout.setRefreshing(false); }); ItemTouchCallback itemTouchCallback = new ItemTouchCallback(); - itemTouchCallback.setSwipeRefreshLayout(refreshLayout); + itemTouchCallback.setSwipeRefreshLayout(binding.refreshLayout); itemTouchCallback.setViewPager(callbackValue.getViewPager()); if (bookPx.equals("2")) { itemTouchCallback.setDragEnable(true); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); - itemTouchHelper.attachToRecyclerView(rvBookshelf); + itemTouchHelper.attachToRecyclerView(binding.rvBookshelf); } else { itemTouchCallback.setDragEnable(false); ItemTouchHelper itemTouchHelper = new ItemTouchHelper(itemTouchCallback); - itemTouchHelper.attachToRecyclerView(rvBookshelf); + itemTouchHelper.attachToRecyclerView(binding.rvBookshelf); } bookShelfAdapter.setItemClickListener(getAdapterListener()); itemTouchCallback.setOnItemTouchCallbackListener(bookShelfAdapter.getItemTouchCallbackListener()); - ivBack.setOnClickListener(v -> setArrange(false)); - ivDel.setOnClickListener(v -> { + binding.ivBack.setOnClickListener(v -> setArrange(false)); + binding.ivDel.setOnClickListener(v -> { if (bookShelfAdapter.getSelected().size() == bookShelfAdapter.getBooks().size()) { AlertDialog alertDialog = new AlertDialog.Builder(requireContext()) .setTitle(R.string.delete) @@ -170,14 +143,14 @@ protected void bindEvent() { delSelect(); } }); - ivSelectAll.setOnClickListener(v -> bookShelfAdapter.selectAll()); + binding.ivSelectAll.setOnClickListener(v -> bookShelfAdapter.selectAll()); } private OnItemClickListenerTwo getAdapterListener() { return new OnItemClickListenerTwo() { @Override public void onClick(View view, int index) { - if (actionBar.getVisibility() == View.VISIBLE) { + if (binding.actionBar.getVisibility() == View.VISIBLE) { upSelectCount(); return; } @@ -234,12 +207,12 @@ private void stopBookShelfRefreshAnim() { @Override public void refreshBookShelf(List bookShelfBeanList) { bookShelfAdapter.replaceAll(bookShelfBeanList, bookPx); - if (rlEmptyView == null) return; + if (binding.viewEmpty.rlEmptyView == null) return; if (bookShelfBeanList.size() > 0) { - rlEmptyView.setVisibility(View.GONE); + binding.viewEmpty.rlEmptyView.setVisibility(View.GONE); } else { - tvEmpty.setText(R.string.bookshelf_empty); - rlEmptyView.setVisibility(View.VISIBLE); + binding.viewEmpty.tvEmpty.setText(R.string.bookshelf_empty); + binding.viewEmpty.rlEmptyView.setVisibility(View.VISIBLE); } } @@ -266,24 +239,24 @@ public SharedPreferences getPreferences() { @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); + binding = null; } public void setArrange(boolean isArrange) { if (bookShelfAdapter != null) { bookShelfAdapter.setArrange(isArrange); if (isArrange) { - actionBar.setVisibility(View.VISIBLE); + binding.actionBar.setVisibility(View.VISIBLE); upSelectCount(); } else { - actionBar.setVisibility(View.GONE); + binding.actionBar.setVisibility(View.GONE); } } } @SuppressLint("DefaultLocale") private void upSelectCount() { - tvSelectCount.setText(String.format("%d/%d", bookShelfAdapter.getSelected().size(), bookShelfAdapter.getBooks().size())); + binding.tvSelectCount.setText(String.format("%d/%d", bookShelfAdapter.getSelected().size(), bookShelfAdapter.getBooks().size())); } private void delSelect() { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookmarkFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookmarkFragment.java index d4deb23cf6..ed747ec490 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookmarkFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/BookmarkFragment.java @@ -1,6 +1,9 @@ package com.kunfei.bookshelf.view.fragment; import android.os.Bundle; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; @@ -8,40 +11,35 @@ import com.hwangjr.rxbus.RxBus; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.DbHelper; -import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseFragment; import com.kunfei.bookshelf.base.observer.MySingleObserver; import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.bean.BookmarkBean; import com.kunfei.bookshelf.bean.OpenChapterBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.FragmentBookmarkListBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.utils.RxUtils; import com.kunfei.bookshelf.view.activity.ChapterListActivity; import com.kunfei.bookshelf.view.adapter.BookmarkAdapter; import com.kunfei.bookshelf.widget.modialog.BookmarkDialog; -import com.kunfei.bookshelf.widget.recycler.scroller.FastScrollRecyclerView; import java.util.List; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; import io.reactivex.Single; import io.reactivex.SingleOnSubscribe; public class BookmarkFragment extends MBaseFragment { - @BindView(R.id.rv_list) - FastScrollRecyclerView rvList; - private Unbinder unbinder; + private FragmentBookmarkListBinding binding; private BookShelfBean bookShelf; private List bookmarkBeanList; private BookmarkAdapter adapter; @Override - public int createLayoutId() { - return R.layout.fragment_bookmark_list; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentBookmarkListBinding.inflate(inflater, container, false); + return binding.getRoot(); } /** @@ -75,7 +73,6 @@ protected void initData() { @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); adapter = new BookmarkAdapter(bookShelf, new BookmarkAdapter.OnItemClickListener() { @Override public void itemClick(int index, int page) { @@ -96,8 +93,8 @@ public void itemLongClick(BookmarkBean bookmarkBean) { showBookmark(bookmarkBean); } }); - rvList.setLayoutManager(new LinearLayoutManager(getActivity())); - rvList.setAdapter(adapter); + binding.rvList.setLayoutManager(new LinearLayoutManager(getActivity())); + binding.rvList.setAdapter(adapter); } @Override @@ -124,7 +121,7 @@ public void onSuccess(Boolean aBoolean) { @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); + binding = null; RxBus.get().unregister(this); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/ChapterListFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/ChapterListFragment.java index ba10c327eb..39d6f1b8ff 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/ChapterListFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/ChapterListFragment.java @@ -1,9 +1,9 @@ package com.kunfei.bookshelf.view.fragment; import android.os.Bundle; +import android.view.LayoutInflater; import android.view.View; -import android.widget.ImageView; -import android.widget.TextView; +import android.view.ViewGroup; import androidx.annotation.Nullable; import androidx.recyclerview.widget.LinearLayoutManager; @@ -14,39 +14,22 @@ import com.hwangjr.rxbus.annotation.Tag; import com.hwangjr.rxbus.thread.EventThread; import com.kunfei.basemvplib.impl.IPresenter; -import com.kunfei.bookshelf.R; import com.kunfei.bookshelf.base.MBaseFragment; import com.kunfei.bookshelf.bean.BookChapterBean; import com.kunfei.bookshelf.bean.BookContentBean; import com.kunfei.bookshelf.bean.BookShelfBean; import com.kunfei.bookshelf.bean.OpenChapterBean; import com.kunfei.bookshelf.constant.RxBusTag; +import com.kunfei.bookshelf.databinding.FragmentChapterListBinding; import com.kunfei.bookshelf.view.activity.ChapterListActivity; import com.kunfei.bookshelf.view.adapter.ChapterListAdapter; -import com.kunfei.bookshelf.widget.recycler.scroller.FastScrollRecyclerView; import java.util.List; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; - public class ChapterListFragment extends MBaseFragment { - @BindView(R.id.rv_list) - FastScrollRecyclerView rvList; - @BindView(R.id.tv_current_chapter_info) - TextView tvChapterInfo; - @BindView(R.id.iv_chapter_top) - ImageView ivChapterTop; - @BindView(R.id.iv_chapter_bottom) - ImageView ivChapterBottom; - @BindView(R.id.ll_chapter_base_info) - View llBaseInfo; - @BindView(R.id.v_shadow) - View vShadow; - - private Unbinder unbinder; + + private FragmentChapterListBinding binding; private ChapterListAdapter chapterListAdapter; @@ -57,8 +40,9 @@ public class ChapterListFragment extends MBaseFragment { private boolean isChapterReverse; @Override - public int createLayoutId() { - return R.layout.fragment_chapter_list; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentChapterListBinding.inflate(inflater, container, false); + return binding.getRoot(); } /** @@ -94,9 +78,8 @@ protected void initData() { @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); - rvList.setLayoutManager(layoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, isChapterReverse)); - rvList.setItemAnimator(null); + binding.rvList.setLayoutManager(layoutManager = new LinearLayoutManager(getContext(), RecyclerView.VERTICAL, isChapterReverse)); + binding.rvList.setItemAnimator(null); chapterListAdapter = new ChapterListAdapter(bookShelf, chapterBeanList, (index, page) -> { if (index != bookShelf.getDurChapter()) { RxBus.get().post(RxBusTag.SKIP_TO_CHAPTER, new OpenChapterBean(index, page)); @@ -107,7 +90,7 @@ protected void bindView() { } }); if (bookShelf != null) { - rvList.setAdapter(chapterListAdapter); + binding.rvList.setAdapter(chapterListAdapter); updateIndex(bookShelf.getDurChapter()); updateChapterInfo(); } @@ -119,11 +102,11 @@ protected void bindView() { @Override protected void bindEvent() { super.bindEvent(); - tvChapterInfo.setOnClickListener(view -> layoutManager.scrollToPositionWithOffset(bookShelf.getDurChapter(), 0)); - ivChapterTop.setOnClickListener(v -> rvList.scrollToPosition(0)); - ivChapterBottom.setOnClickListener(v -> { + binding.tvCurrentChapterInfo.setOnClickListener(view -> layoutManager.scrollToPositionWithOffset(bookShelf.getDurChapter(), 0)); + binding.ivChapterTop.setOnClickListener(v -> binding.rvList.scrollToPosition(0)); + binding.ivChapterBottom.setOnClickListener(v -> { if (chapterListAdapter.getItemCount() > 0) { - rvList.scrollToPosition(chapterListAdapter.getItemCount() - 1); + binding.rvList.scrollToPosition(chapterListAdapter.getItemCount() - 1); } }); } @@ -140,9 +123,9 @@ private void updateIndex(int durChapter) { private void updateChapterInfo() { if (bookShelf != null) { if (chapterListAdapter.getItemCount() == 0) { - tvChapterInfo.setText(bookShelf.getDurChapterName()); + binding.tvCurrentChapterInfo.setText(bookShelf.getDurChapterName()); } else { - tvChapterInfo.setText(String.format(Locale.getDefault(), "%s (%d/%d章)", bookShelf.getDurChapterName(), bookShelf.getDurChapter() + 1, bookShelf.getChapterListSize())); + binding.tvCurrentChapterInfo.setText(String.format(Locale.getDefault(), "%s (%d/%d章)", bookShelf.getDurChapterName(), bookShelf.getDurChapter() + 1, bookShelf.getChapterListSize())); } } } @@ -154,7 +137,7 @@ private ChapterListActivity getFatherActivity() { @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); + binding = null; RxBus.get().unregister(this); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/FileCategoryFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/FileCategoryFragment.java index c5ff54cf82..b733e55585 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/FileCategoryFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/FileCategoryFragment.java @@ -2,14 +2,17 @@ import android.graphics.PorterDuff; import android.os.Environment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; import android.widget.TextView; import androidx.appcompat.app.AlertDialog; import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.kunfei.basemvplib.impl.IPresenter; import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.FragmentFileCategoryBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.help.FileHelp; import com.kunfei.bookshelf.utils.FileStack; @@ -28,28 +31,17 @@ import java.util.Objects; import java.util.Set; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; - public class FileCategoryFragment extends BaseFileFragment { private static final String TAG = "FileCategoryFragment"; - @BindView(R.id.file_category_tv_path) - TextView mTvPath; - @BindView(R.id.file_category_tv_back_last) - TextView mTvBackLast; - @BindView(R.id.file_category_rv_content) - RecyclerView mRvContent; - @BindView(R.id.tv_sd) - TextView tvSd; - - private Unbinder unbinder; + + private FragmentFileCategoryBinding binding; private FileStack mFileStack; private String rootFilePath; @Override - public int createLayoutId() { - return R.layout.fragment_file_category; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentFileCategoryBinding.inflate(inflater, container, false); + return binding.getRoot(); } /** @@ -63,17 +55,16 @@ protected IPresenter initInjector() { @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); mFileStack = new FileStack(); setUpAdapter(); } private void setUpAdapter() { mAdapter = new FileSystemAdapter(); - mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); - mRvContent.addItemDecoration(new DividerItemDecoration(Objects.requireNonNull(getContext()))); - mRvContent.setAdapter(mAdapter); - setTextViewIconColor(mTvBackLast); + binding.fileCategoryRvContent.setLayoutManager(new LinearLayoutManager(getContext())); + binding.fileCategoryRvContent.addItemDecoration(new DividerItemDecoration(Objects.requireNonNull(getContext()))); + binding.fileCategoryRvContent.setAdapter(mAdapter); + setTextViewIconColor(binding.fileCategoryTvBackLast); } @Override @@ -85,9 +76,9 @@ protected void bindEvent() { if (file.isDirectory()) { //保存当前信息。 FileStack.FileSnapshot snapshot = new FileStack.FileSnapshot(); - snapshot.filePath = mTvPath.getText().toString(); + snapshot.filePath = binding.fileCategoryTvPath.getText().toString(); snapshot.files = new ArrayList<>(mAdapter.getItems()); - snapshot.scrollOffset = mRvContent.computeVerticalScrollOffset(); + snapshot.scrollOffset = binding.fileCategoryRvContent.computeVerticalScrollOffset(); mFileStack.push(snapshot); //切换下一个文件 toggleFileTree(file); @@ -108,21 +99,21 @@ protected void bindEvent() { } ); - mTvBackLast.setOnClickListener(v -> { - FileStack.FileSnapshot snapshot = mFileStack.pop(); - int oldScrollOffset = mRvContent.computeHorizontalScrollOffset(); - if (snapshot == null) return; - mTvPath.setText(snapshot.filePath); - mAdapter.refreshItems(snapshot.files); - mRvContent.scrollBy(0, snapshot.scrollOffset - oldScrollOffset); - //反馈 - if (mListener != null) { - mListener.onCategoryChanged(); - } + binding.fileCategoryTvBackLast.setOnClickListener(v -> { + FileStack.FileSnapshot snapshot = mFileStack.pop(); + int oldScrollOffset = binding.fileCategoryRvContent.computeHorizontalScrollOffset(); + if (snapshot == null) return; + binding.fileCategoryTvPath.setText(snapshot.filePath); + mAdapter.refreshItems(snapshot.files); + binding.fileCategoryRvContent.scrollBy(0, snapshot.scrollOffset - oldScrollOffset); + //反馈 + if (mListener != null) { + mListener.onCategoryChanged(); + } } ); - tvSd.setOnClickListener(v -> { + binding.tvSd.setOnClickListener(v -> { if (getContext() != null) { List list = FileUtils.getStorageData(getContext()); if (list != null) { @@ -161,7 +152,7 @@ private void setTextViewIconColor(TextView textView) { private void toggleFileTree(File file) { //路径名 - mTvPath.setText(file.getPath().replace(rootFilePath, "")); + binding.fileCategoryTvPath.setText(file.getPath().replace(rootFilePath, "")); //获取数据 File[] files = file.listFiles(new SimpleFileFilter()); //转换成List @@ -191,7 +182,7 @@ public int getFileCount() { @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); + binding = null; } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/FindBookFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/FindBookFragment.java index 7ba8d1fefd..01f7730d43 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/FindBookFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/FindBookFragment.java @@ -10,10 +10,7 @@ import android.view.Menu; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; import android.widget.PopupMenu; -import android.widget.RelativeLayout; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -21,7 +18,6 @@ import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearSmoothScroller; import androidx.recyclerview.widget.RecyclerView; -import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.kunfei.bookshelf.MApplication; import com.kunfei.bookshelf.R; @@ -30,6 +26,7 @@ import com.kunfei.bookshelf.bean.BookSourceBean; import com.kunfei.bookshelf.bean.FindKindBean; import com.kunfei.bookshelf.bean.FindKindGroupBean; +import com.kunfei.bookshelf.databinding.FragmentBookFindBinding; import com.kunfei.bookshelf.model.BookSourceManager; import com.kunfei.bookshelf.presenter.FindBookPresenter; import com.kunfei.bookshelf.presenter.contract.FindBookContract; @@ -49,31 +46,14 @@ import java.util.List; import java.util.Objects; -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; - import static android.app.Activity.RESULT_OK; public class FindBookFragment extends MBaseFragment implements FindBookContract.View, OnRecyclerViewListener.OnItemClickListener, OnRecyclerViewListener.OnItemLongClickListener { - @BindView(R.id.ll_content) - LinearLayout llContent; - @BindView(R.id.refresh_layout) - SwipeRefreshLayout refreshLayout; - @BindView(R.id.tv_empty) - TextView tvEmpty; - @BindView(R.id.rl_empty_view) - RelativeLayout rlEmptyView; - @BindView(R.id.rv_find_left) - RecyclerView rvFindLeft; - @BindView(R.id.rv_find_right) - RecyclerView rvFindRight; - @BindView(R.id.vw_divider) - View vwDivider; - - private Unbinder unbinder; + + + private FragmentBookFindBinding binding; private FindLeftAdapter findLeftAdapter; private FindRightAdapter findRightAdapter; private FindKindAdapter findKindAdapter; @@ -82,8 +62,9 @@ public class FindBookFragment extends MBaseFragment private List data = new ArrayList<>(); @Override - public int createLayoutId() { - return R.layout.fragment_book_find; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentBookFindBinding.inflate(inflater, container, false); + return binding.getRoot(); } @Override @@ -99,12 +80,11 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); - rvFindRight.addItemDecoration(new GridSpacingItemDecoration(10)); - refreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); - refreshLayout.setOnRefreshListener(() -> { + binding.rvFindRight.addItemDecoration(new GridSpacingItemDecoration(10)); + binding.refreshLayout.setColorSchemeColors(ThemeStore.accentColor(MApplication.getInstance())); + binding.refreshLayout.setOnRefreshListener(() -> { refreshData(); - refreshLayout.setRefreshing(false); + binding.refreshLayout.setRefreshing(false); }); leftLayoutManager = new LinearLayoutManager(getContext()); initRecyclerView(); @@ -133,7 +113,7 @@ public void upData(List group) { } public void upStyle() { - if (rlEmptyView == null) return; + if (binding.emptyView.rlEmptyView == null) return; initRecyclerView(); if (isFlexBox()) { findRightAdapter.setData(data); @@ -145,21 +125,21 @@ public void upStyle() { } public void upUI() { - if (rlEmptyView == null) return; + if (binding.emptyView.rlEmptyView == null) return; if (data.size() == 0) { - tvEmpty.setText(R.string.no_find); - rlEmptyView.setVisibility(View.VISIBLE); + binding.emptyView.tvEmpty.setText(R.string.no_find); + binding.emptyView.rlEmptyView.setVisibility(View.VISIBLE); } else { - rlEmptyView.setVisibility(View.GONE); + binding.emptyView.rlEmptyView.setVisibility(View.GONE); } if (isFlexBox()) { - rlEmptyView.setVisibility(View.GONE); + binding.emptyView.rlEmptyView.setVisibility(View.GONE); if (data.size() <= 1 | !showLeftView()) { - rvFindLeft.setVisibility(View.GONE); - vwDivider.setVisibility(View.GONE); + binding.rvFindLeft.setVisibility(View.GONE); + binding.vwDivider.setVisibility(View.GONE); } else { - rvFindLeft.setVisibility(View.VISIBLE); - vwDivider.setVisibility(View.VISIBLE); + binding.rvFindLeft.setVisibility(View.VISIBLE); + binding.vwDivider.setVisibility(View.VISIBLE); } } } @@ -173,7 +153,7 @@ private boolean showLeftView() { } private void initRecyclerView() { - if (rvFindRight == null) return; + if (binding.rvFindRight == null) return; if (isFlexBox()) { findKindAdapter = null; findLeftAdapter = new FindLeftAdapter(getActivity(), pos -> { @@ -184,31 +164,31 @@ private void initRecyclerView() { } ((ScrollLinearLayoutManger) rightLayoutManager).scrollToPositionWithOffset(counts + pos, 0); }); - rvFindLeft.setLayoutManager(leftLayoutManager); - rvFindLeft.setAdapter(findLeftAdapter); + binding.rvFindLeft.setLayoutManager(leftLayoutManager); + binding.rvFindLeft.setAdapter(findLeftAdapter); findRightAdapter = new FindRightAdapter(Objects.requireNonNull(getActivity()), this); //设置header rightLayoutManager = new ScrollLinearLayoutManger(getActivity(), 3); ((ScrollLinearLayoutManger) rightLayoutManager).setSpanSizeLookup(new SectionedSpanSizeLookup(findRightAdapter, (ScrollLinearLayoutManger) rightLayoutManager)); - rvFindRight.setLayoutManager(rightLayoutManager); - rvFindRight.setLayoutManager(rightLayoutManager); - rvFindRight.setItemViewCacheSize(10); - rvFindRight.setItemAnimator(null); - rvFindRight.setHasFixedSize(true); - rvFindRight.setAdapter(findRightAdapter); + binding.rvFindRight.setLayoutManager(rightLayoutManager); + binding.rvFindRight.setLayoutManager(rightLayoutManager); + binding.rvFindRight.setItemViewCacheSize(10); + binding.rvFindRight.setItemAnimator(null); + binding.rvFindRight.setHasFixedSize(true); + binding.rvFindRight.setAdapter(findRightAdapter); } else { rightLayoutManager = new LinearLayoutManager(getContext()); - rvFindLeft.setVisibility(View.GONE); - vwDivider.setVisibility(View.GONE); + binding.rvFindLeft.setVisibility(View.GONE); + binding.vwDivider.setVisibility(View.GONE); findLeftAdapter = null; findRightAdapter = null; findKindAdapter = new FindKindAdapter(getContext(), new ArrayList<>()); findKindAdapter.setOnItemClickListener(this); findKindAdapter.setOnItemLongClickListener(this); findKindAdapter.setCanExpandAll(false); - rvFindRight.setLayoutManager(rightLayoutManager); - rvFindRight.setAdapter(findKindAdapter); + binding.rvFindRight.setLayoutManager(rightLayoutManager); + binding.rvFindRight.setAdapter(findKindAdapter); } } @@ -282,7 +262,7 @@ public void onChildItemLongClick(int position, int groupPosition, int childPosit @Override public void onDestroyView() { super.onDestroyView(); - unbinder.unbind(); + binding = null; } @Override diff --git a/app/src/main/java/com/kunfei/bookshelf/view/fragment/LocalBookFragment.java b/app/src/main/java/com/kunfei/bookshelf/view/fragment/LocalBookFragment.java index fc739b35ff..06c5fb8268 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/fragment/LocalBookFragment.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/fragment/LocalBookFragment.java @@ -1,19 +1,17 @@ package com.kunfei.bookshelf.view.fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; + import androidx.recyclerview.widget.LinearLayoutManager; -import androidx.recyclerview.widget.RecyclerView; import com.kunfei.basemvplib.impl.IPresenter; -import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.FragmentLocalBookBinding; import com.kunfei.bookshelf.help.BookshelfHelp; import com.kunfei.bookshelf.help.media.MediaStoreHelper; import com.kunfei.bookshelf.view.adapter.FileSystemAdapter; import com.kunfei.bookshelf.widget.itemdecoration.DividerItemDecoration; -import com.kunfei.bookshelf.widget.recycler.refresh.RefreshLayout; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; /** * Created by newbiechen on 17-5-27. @@ -21,16 +19,13 @@ */ public class LocalBookFragment extends BaseFileFragment { - @BindView(R.id.refresh_layout) - RefreshLayout mRlRefresh; - @BindView(R.id.local_book_rv_content) - RecyclerView mRvContent; - private Unbinder unbinder; + private FragmentLocalBookBinding binding; @Override - public int createLayoutId() { - return R.layout.fragment_local_book; + protected View createView(LayoutInflater inflater, ViewGroup container) { + binding = FragmentLocalBookBinding.inflate(inflater, container, false); + return binding.getRoot(); } /** @@ -44,16 +39,15 @@ protected IPresenter initInjector() { @Override protected void bindView() { super.bindView(); - unbinder = ButterKnife.bind(this, view); setUpAdapter(); } private void setUpAdapter() { mAdapter = new FileSystemAdapter(); if (getContext() != null) { - mRvContent.setLayoutManager(new LinearLayoutManager(getContext())); - mRvContent.addItemDecoration(new DividerItemDecoration(getContext())); - mRvContent.setAdapter(mAdapter); + binding.localBookRvContent.setLayoutManager(new LinearLayoutManager(getContext())); + binding.localBookRvContent.addItemDecoration(new DividerItemDecoration(getContext())); + binding.localBookRvContent.setAdapter(mAdapter); } } @@ -86,10 +80,10 @@ protected void firstRequest() { MediaStoreHelper.getAllBookFile(getActivity(), (files) -> { if (files.isEmpty()) { - mRlRefresh.showEmpty(); + binding.refreshLayout.showEmpty(); } else { mAdapter.refreshItems(files); - mRlRefresh.showFinish(); + binding.refreshLayout.showFinish(); //反馈 if (mListener != null) { mListener.onCategoryChanged(); @@ -102,6 +96,6 @@ protected void firstRequest() { @Override public void onDestroy() { super.onDestroy(); - unbinder.unbind(); + binding = null; } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/KeyboardToolPop.kt b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/KeyboardToolPop.kt index 961a6fe1b7..0013913ad8 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/KeyboardToolPop.kt +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/KeyboardToolPop.kt @@ -1,17 +1,15 @@ package com.kunfei.bookshelf.view.popupwindow -import android.annotation.SuppressLint import android.content.Context import android.view.LayoutInflater import android.view.ViewGroup import android.widget.PopupWindow import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView -import com.kunfei.bookshelf.R import com.kunfei.bookshelf.base.adapter.ItemViewHolder -import com.kunfei.bookshelf.base.adapter.SimpleRecyclerAdapter -import kotlinx.android.synthetic.main.item_text.view.* -import kotlinx.android.synthetic.main.popup_keyboard_tool.view.* +import com.kunfei.bookshelf.base.adapter.RecyclerAdapter +import com.kunfei.bookshelf.databinding.ItemTextBinding +import com.kunfei.bookshelf.databinding.PopupKeyboardToolBinding import org.jetbrains.anko.sdk27.listeners.onClick @@ -21,33 +19,41 @@ class KeyboardToolPop( val callBack: CallBack? ) : PopupWindow(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) { - init { - @SuppressLint("InflateParams") - this.contentView = LayoutInflater.from(context).inflate(R.layout.popup_keyboard_tool, null) + private val binding = PopupKeyboardToolBinding.inflate(LayoutInflater.from(context)) + init { isTouchable = true isOutsideTouchable = false isFocusable = false inputMethodMode = INPUT_METHOD_NEEDED //解决遮盖输入法 + contentView = binding.root initRecyclerView() } private fun initRecyclerView() = with(contentView) { val adapter = Adapter(context) - recycler_view.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) - recycler_view.adapter = adapter + binding.recyclerView.layoutManager = LinearLayoutManager(context, RecyclerView.HORIZONTAL, false) + binding.recyclerView.adapter = adapter adapter.setItems(chars) } inner class Adapter(context: Context) : - SimpleRecyclerAdapter(context, R.layout.item_text) { + RecyclerAdapter(context) { + + override fun getViewBinding(parent: ViewGroup): ItemTextBinding { + return ItemTextBinding.bind(parent) + } - override fun convert(holder: ItemViewHolder, item: String, payloads: MutableList) { - with(holder.itemView) { - text_view.text = item - onClick { callBack?.sendText(item) } + override fun convert(holder: ItemViewHolder, binding: ItemTextBinding, item: String, payloads: MutableList) { + with(binding) { + textView.text = item + root.onClick { callBack?.sendText(item) } } } + + override fun registerListener(holder: ItemViewHolder, binding: ItemTextBinding) { + + } } interface CallBack { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MediaPlayerPop.java b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MediaPlayerPop.java index 3e5c8e6280..cba3864767 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MediaPlayerPop.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MediaPlayerPop.java @@ -8,11 +8,8 @@ import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; -import android.widget.ImageView; import android.widget.SeekBar; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -21,50 +18,24 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy; import com.bumptech.glide.load.resource.drawable.DrawableTransitionOptions; import com.bumptech.glide.request.RequestOptions; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.PopMediaPlayerBinding; import com.kunfei.bookshelf.help.BlurTransformation; import com.kunfei.bookshelf.help.ImageLoader; import com.kunfei.bookshelf.utils.ColorUtil; import com.kunfei.bookshelf.utils.TimeUtils; import com.kunfei.bookshelf.utils.theme.MaterialValueHelper; import com.kunfei.bookshelf.utils.theme.ThemeStore; -import com.kunfei.bookshelf.widget.views.ATESeekBar; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Locale; -import butterknife.BindView; -import butterknife.ButterKnife; - public class MediaPlayerPop extends FrameLayout { @SuppressLint("ConstantLocale") private final DateFormat timeFormat = new SimpleDateFormat("mm:ss", Locale.getDefault()); - @BindView(R.id.vw_bg) - View vwBg; - @BindView(R.id.iv_cover) - ImageView ivCover; - @BindView(R.id.tv_dur_time) - TextView tvDurTime; - @BindView(R.id.player_progress) - ATESeekBar seekBar; - @BindView(R.id.tv_all_time) - TextView tvAllTime; - @BindView(R.id.iv_skip_previous) - ImageView ivSkipPrevious; - @BindView(R.id.fab_play_stop) - FloatingActionButton fabPlayStop; - @BindView(R.id.iv_skip_next) - ImageView ivSkipNext; - @BindView(R.id.iv_timer) - ImageView ivTimer; - @BindView(R.id.iv_chapter) - ImageView ivChapter; - @BindView(R.id.iv_cover_bg) - ImageView ivCoverBg; - + private PopMediaPlayerBinding binding = PopMediaPlayerBinding.inflate(LayoutInflater.from(getContext()), this, true); private int primaryTextColor; private Callback callback; @@ -90,17 +61,15 @@ public MediaPlayerPop(@NonNull Context context, @Nullable AttributeSet attrs, in } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.pop_media_player, this); - ButterKnife.bind(this, view); - view.setBackgroundColor(ThemeStore.primaryColor(context)); - vwBg.setOnClickListener(null); + binding.getRoot().setBackgroundColor(ThemeStore.primaryColor(context)); + binding.vwBg.setOnClickListener(null); primaryTextColor = MaterialValueHelper.getPrimaryTextColor(context, ColorUtil.isColorLight(ThemeStore.primaryColor(context))); - setColor(ivSkipPrevious.getDrawable()); - setColor(ivSkipNext.getDrawable()); - setColor(ivChapter.getDrawable()); - setColor(ivTimer.getDrawable()); - seekBar.setEnabled(false); - seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + setColor(binding.ivSkipPrevious.getDrawable()); + setColor(binding.ivSkipNext.getDrawable()); + setColor(binding.ivChapter.getDrawable()); + setColor(binding.ivTimer.getDrawable()); + binding.seekBar.setEnabled(false); + binding.seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { @@ -130,58 +99,58 @@ public void setCallback(Callback callback) { } public void setSeekBarEnable(boolean enable) { - seekBar.setEnabled(enable); + binding.seekBar.setEnabled(enable); } public void upAudioSize(int audioSize) { - seekBar.setMax(audioSize); - tvAllTime.setText(TimeUtils.millis2String(audioSize, timeFormat)); + binding.seekBar.setMax(audioSize); + binding.tvAllTime.setText(TimeUtils.millis2String(audioSize, timeFormat)); } public void upAudioDur(int audioDur) { - seekBar.setProgress(audioDur); - tvDurTime.setText(TimeUtils.millis2String(audioDur, timeFormat)); + binding.seekBar.setProgress(audioDur); + binding.tvDurTime.setText(TimeUtils.millis2String(audioDur, timeFormat)); } public void setIvCoverBgClickListener(OnClickListener onClickListener) { - ivCoverBg.setOnClickListener(onClickListener); + binding.ivCoverBg.setOnClickListener(onClickListener); } public void setPlayClickListener(OnClickListener onClickListener) { - fabPlayStop.setOnClickListener(onClickListener); + binding.fabPlayStop.setOnClickListener(onClickListener); } public void setPrevClickListener(OnClickListener onClickListener) { - ivSkipPrevious.setOnClickListener(onClickListener); + binding.ivSkipPrevious.setOnClickListener(onClickListener); } public void setNextClickListener(OnClickListener onClickListener) { - ivSkipNext.setOnClickListener(onClickListener); + binding.ivSkipNext.setOnClickListener(onClickListener); } public void setIvTimerClickListener(OnClickListener onClickListener) { - ivTimer.setOnClickListener(onClickListener); + binding.ivTimer.setOnClickListener(onClickListener); } public void setIvChapterClickListener(OnClickListener onClickListener) { - ivChapter.setOnClickListener(onClickListener); + binding.ivChapter.setOnClickListener(onClickListener); } public void setFabReadAloudImage(int id) { - fabPlayStop.setImageResource(id); + binding.fabPlayStop.setImageResource(id); } public void setCover(String coverPath) { ImageLoader.INSTANCE.load(getContext(), coverPath) .apply(new RequestOptions().dontAnimate().diskCacheStrategy(DiskCacheStrategy.RESOURCE).centerCrop() .placeholder(R.drawable.image_cover_default)) - .into(ivCover); + .into(binding.ivCover); ImageLoader.INSTANCE.load(getContext(), coverPath) .transition(DrawableTransitionOptions.withCrossFade(1500)) .thumbnail(defaultCover()) .centerCrop() .apply(RequestOptions.bitmapTransform(new BlurTransformation(getContext(), 25))) - .into(ivCoverBg); + .into(binding.ivCoverBg); } private RequestBuilder defaultCover() { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MoreSettingPop.kt b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MoreSettingPop.kt index 42b2f2de2e..e78d79e6b1 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MoreSettingPop.kt +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/MoreSettingPop.kt @@ -12,16 +12,17 @@ import androidx.appcompat.app.AlertDialog import com.hwangjr.rxbus.RxBus import com.kunfei.bookshelf.R import com.kunfei.bookshelf.constant.RxBusTag +import com.kunfei.bookshelf.databinding.PopMoreSettingBinding import com.kunfei.bookshelf.help.ReadBookControl import com.kunfei.bookshelf.utils.theme.ATH import com.kunfei.bookshelf.widget.modialog.PageKeyDialog -import kotlinx.android.synthetic.main.pop_more_setting.view.* import org.jetbrains.anko.sdk27.listeners.onClick class MoreSettingPop : FrameLayout { private val readBookControl = ReadBookControl.getInstance() private var callback: Callback? = null + private val binding = PopMoreSettingBinding.inflate(LayoutInflater.from(context), this, true) constructor(context: Context) : super(context) { init(context) @@ -36,8 +37,7 @@ class MoreSettingPop : FrameLayout { } private fun init(context: Context) { - LayoutInflater.from(context).inflate(R.layout.pop_more_setting, this) - vw_bg.setOnClickListener(null) + binding.vwBg.setOnClickListener(null) } fun setListener(callback: Callback) { @@ -48,79 +48,79 @@ class MoreSettingPop : FrameLayout { private fun bindEvent() { setOnClickListener { this.visibility = View.GONE } - sbImmersionStatusBar.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> + binding.sbImmersionStatusBar.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> if (compoundButton.isPressed) { readBookControl.immersionStatusBar = b callback?.upBar() RxBus.get().post(RxBusTag.RECREATE, true) } } - sb_light_novel_paragraph.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbLightNovelParagraph.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.lightNovelParagraph = isChecked callback?.recreate() } } - sb_hideStatusBar.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbHideStatusBar.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.hideStatusBar = isChecked callback?.recreate() } } - sb_to_lh.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbToLh.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.toLh = isChecked callback?.recreate() } } - sb_hideNavigationBar.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbHideNavigationBar.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.hideNavigationBar = isChecked initData() callback?.recreate() } } - sw_volume_next_page.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> + binding.swVolumeNextPage.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> if (compoundButton.isPressed) { readBookControl.canKeyTurn = b upView() } } - sw_read_aloud_key.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> + binding.swReadAloudKey.setOnCheckedChangeListener { compoundButton: CompoundButton, b: Boolean -> if (compoundButton.isPressed) { readBookControl.aloudCanKeyTurn = b } } - sb_click.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbClick.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.canClickTurn = isChecked upView() } } - sb_click_all_next.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbClickAllNext.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.clickAllNext = isChecked } } - sb_show_title.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbShowTitle.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.showTitle = isChecked callback?.refreshPage() } } - sb_showTimeBattery.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbShowTimeBattery.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.showTimeBattery = isChecked callback?.refreshPage() } } - sb_showLine.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbShowLine.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.showLine = isChecked callback?.refreshPage() } } - llScreenTimeOut.setOnClickListener { + binding.llScreenTimeOut.setOnClickListener { val dialog = AlertDialog.Builder(context) .setTitle(context.getString(R.string.keep_light)) .setSingleChoiceItems( @@ -136,7 +136,7 @@ class MoreSettingPop : FrameLayout { dialog.show() ATH.setAlertDialogTint(dialog) } - llJFConvert.setOnClickListener { + binding.llJFConvert.setOnClickListener { val dialog = AlertDialog.Builder(context) .setTitle(context.getString(R.string.jf_convert)) .setSingleChoiceItems(context.resources.getStringArray(R.array.convert_s), readBookControl.textConvert) { dialogInterface: DialogInterface, i: Int -> @@ -149,7 +149,7 @@ class MoreSettingPop : FrameLayout { dialog.show() ATH.setAlertDialogTint(dialog) } - ll_screen_direction.setOnClickListener { + binding.llScreenDirection.setOnClickListener { val dialog = AlertDialog.Builder(context) .setTitle(context.getString(R.string.screen_direction)) .setSingleChoiceItems(context.resources.getStringArray(R.array.screen_direction_list_title), readBookControl.screenDirection) { dialogInterface: DialogInterface, i: Int -> @@ -162,7 +162,7 @@ class MoreSettingPop : FrameLayout { dialog.show() ATH.setAlertDialogTint(dialog) } - llNavigationBarColor!!.setOnClickListener { + binding.llNavigationBarColor.setOnClickListener { val dialog = AlertDialog.Builder(context) .setTitle(context.getString(R.string.re_navigation_bar_color)) .setSingleChoiceItems(context.resources.getStringArray(R.array.NavBarColors), readBookControl.navBarColor) { dialogInterface: DialogInterface, i: Int -> @@ -175,12 +175,12 @@ class MoreSettingPop : FrameLayout { dialog.show() ATH.setAlertDialogTint(dialog) } - sb_select_text.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> + binding.sbSelectText.setOnCheckedChangeListener { buttonView: CompoundButton, isChecked: Boolean -> if (buttonView.isPressed) { readBookControl.isCanSelectText = isChecked } } - ll_click_key_code.onClick { + binding.llClickKeyCode.onClick { PageKeyDialog(context).show() } } @@ -190,60 +190,60 @@ class MoreSettingPop : FrameLayout { upScreenTimeOut(readBookControl.screenTimeOut) upFConvert(readBookControl.textConvert) upNavBarColor(readBookControl.navBarColor) - sbImmersionStatusBar!!.isChecked = readBookControl.immersionStatusBar - sw_volume_next_page.isChecked = readBookControl.canKeyTurn - sw_read_aloud_key.isChecked = readBookControl.aloudCanKeyTurn - sb_light_novel_paragraph.isChecked = readBookControl.lightNovelParagraph; - sb_hideStatusBar.isChecked = readBookControl.hideStatusBar - sb_to_lh.isChecked = readBookControl.toLh - sb_hideNavigationBar.isChecked = readBookControl.hideNavigationBar - sb_click.isChecked = readBookControl.canClickTurn - sb_click_all_next.isChecked = readBookControl.clickAllNext - sb_show_title.isChecked = readBookControl.showTitle - sb_showTimeBattery.isChecked = readBookControl.showTimeBattery - sb_showLine.isChecked = readBookControl.showLine - sb_select_text.isChecked = readBookControl.isCanSelectText + binding.sbImmersionStatusBar.isChecked = readBookControl.immersionStatusBar + binding.swVolumeNextPage.isChecked = readBookControl.canKeyTurn + binding.swReadAloudKey.isChecked = readBookControl.aloudCanKeyTurn + binding.sbLightNovelParagraph.isChecked = readBookControl.lightNovelParagraph; + binding.sbHideStatusBar.isChecked = readBookControl.hideStatusBar + binding.sbToLh.isChecked = readBookControl.toLh + binding.sbHideNavigationBar.isChecked = readBookControl.hideNavigationBar + binding.sbClick.isChecked = readBookControl.canClickTurn + binding.sbClickAllNext.isChecked = readBookControl.clickAllNext + binding.sbShowTitle.isChecked = readBookControl.showTitle + binding.sbShowTimeBattery.isChecked = readBookControl.showTimeBattery + binding.sbShowLine.isChecked = readBookControl.showLine + binding.sbSelectText.isChecked = readBookControl.isCanSelectText upView() } private fun upView() { if (readBookControl.hideStatusBar) { - sb_showTimeBattery.isEnabled = true - sb_to_lh.isEnabled = true + binding.sbShowTimeBattery.isEnabled = true + binding.sbToLh.isEnabled = true } else { - sb_showTimeBattery.isEnabled = false - sb_to_lh.isEnabled = false + binding.sbShowTimeBattery.isEnabled = false + binding.sbToLh.isEnabled = false } - sw_read_aloud_key.isEnabled = readBookControl.canKeyTurn - sb_click_all_next.isEnabled = readBookControl.canClickTurn + binding.swReadAloudKey.isEnabled = readBookControl.canKeyTurn + binding.sbClickAllNext.isEnabled = readBookControl.canClickTurn if (readBookControl.hideNavigationBar) { - llNavigationBarColor.isEnabled = false - reNavBarColor_val.isEnabled = false + binding.llNavigationBarColor.isEnabled = false + binding.reNavBarColorVal.isEnabled = false } else { - llNavigationBarColor!!.isEnabled = true - reNavBarColor_val.isEnabled = true + binding.llNavigationBarColor.isEnabled = true + binding.reNavBarColorVal.isEnabled = true } } private fun upScreenTimeOut(screenTimeOut: Int) { - tv_screen_time_out.text = context.resources.getStringArray(R.array.screen_time_out)[screenTimeOut] + binding.tvScreenTimeOut.text = context.resources.getStringArray(R.array.screen_time_out)[screenTimeOut] } private fun upFConvert(fConvert: Int) { - tvJFConvert.text = context.resources.getStringArray(R.array.convert_s)[fConvert] + binding.tvJFConvert.text = context.resources.getStringArray(R.array.convert_s)[fConvert] } private fun upScreenDirection(screenDirection: Int) { val screenDirectionListTitle = context.resources.getStringArray(R.array.screen_direction_list_title) if (screenDirection >= screenDirectionListTitle.size) { - tv_screen_direction.text = screenDirectionListTitle[0] + binding.tvScreenDirection.text = screenDirectionListTitle[0] } else { - tv_screen_direction.text = screenDirectionListTitle[screenDirection] + binding.tvScreenDirection.text = screenDirectionListTitle[screenDirection] } } private fun upNavBarColor(nColor: Int) { - reNavBarColor_val.text = context.resources.getStringArray(R.array.NavBarColors)[nColor] + binding.reNavBarColorVal.text = context.resources.getStringArray(R.array.NavBarColors)[nColor] } interface Callback { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustMarginPop.kt b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustMarginPop.kt index ca89fbe0f3..e014ec3ee9 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustMarginPop.kt +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustMarginPop.kt @@ -4,39 +4,33 @@ package com.kunfei.bookshelf.view.popupwindow import android.app.Activity import android.content.Context import android.util.AttributeSet +import android.view.LayoutInflater import android.widget.FrameLayout import android.widget.SeekBar import android.widget.TextView -import com.kunfei.bookshelf.R +import com.kunfei.bookshelf.databinding.PopReadAdjustMarginBinding import com.kunfei.bookshelf.help.ReadBookControl -import kotlinx.android.synthetic.main.pop_read_adjust_margin.view.* import org.jetbrains.anko.sdk27.listeners.onClick class ReadAdjustMarginPop : FrameLayout { - private var context: Activity? = null + val binding = PopReadAdjustMarginBinding.inflate(LayoutInflater.from(context), this, true) + private var activity: Activity? = null private val readBookControl = ReadBookControl.getInstance() private var callback: Callback? = null - constructor(context: Context) : super(context) { - init(context) - } + constructor(context: Context) : super(context) - constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { - init(context) - } + constructor(context: Context, attrs: AttributeSet) : super(context, attrs) - constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) { - init(context) - } + constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) - private fun init(context: Context) { - inflate(context, R.layout.pop_read_adjust_margin, this) - vw_bg.setOnClickListener(null) + init { + binding.vwBg.setOnClickListener(null) } fun setListener(activity: Activity, callback: Callback) { - this.context = activity + this.activity = activity this.callback = callback initData(0) bindEvent() @@ -49,86 +43,86 @@ class ReadAdjustMarginPop : FrameLayout { private fun initData(flag: Int) { if (flag == 0) { // 字距 - setSeekBarView(hpb_mr_f, tv_hpb_mr_f, -0.5f, 0.5f, readBookControl.textLetterSpacing, 100) + setSeekBarView(binding.hpbMrF, binding.tvHpbMrF, -0.5f, 0.5f, readBookControl.textLetterSpacing, 100) // 行距 - setSeekBarView(hpb_mr_rm, tv_hpb_mr_rm, 0.5f, 3.0f, readBookControl.lineMultiplier, 10) + setSeekBarView(binding.hpbMrRm, binding.tvHpbMrRm, 0.5f, 3.0f, readBookControl.lineMultiplier, 10) // 段距 - setSeekBarView(hpb_mr_dm, tv_hpb_mr_dm, 1.0f, 5.0f, readBookControl.paragraphSize, 10) + setSeekBarView(binding.hpbMrDm, binding.tvHpbMrDm, 1.0f, 5.0f, readBookControl.paragraphSize, 10) } if (flag == 0 || flag == 1) { // 正文边距 - setSeekBarView(hpb_mr_z_t, tv_hpb_mr_z_t, 0, 100, readBookControl.paddingTop) - setSeekBarView(hpb_mr_z_l, tv_hpb_mr_z_l, 0, 100, readBookControl.paddingLeft) - setSeekBarView(hpb_mr_z_r, tv_hpb_mr_z_r, 0, 100, readBookControl.paddingRight) - setSeekBarView(hpb_mr_z_b, tv_hpb_mr_z_b, 0, 100, readBookControl.paddingBottom) + setSeekBarView(binding.hpbMrZT, binding.tvHpbMrZT, 0, 100, readBookControl.paddingTop) + setSeekBarView(binding.hpbMrZL, binding.tvHpbMrZL, 0, 100, readBookControl.paddingLeft) + setSeekBarView(binding.hpbMrZR, binding.tvHpbMrZR, 0, 100, readBookControl.paddingRight) + setSeekBarView(binding.hpbMrZB, binding.tvHpbMrZB, 0, 100, readBookControl.paddingBottom) } if (flag == 0 || flag == 2) { // Tip边距 - setSeekBarView(hpb_mr_t_t, tv_hpb_mr_t_t, 0, 100, readBookControl.tipPaddingTop) - setSeekBarView(hpb_mr_t_l, tv_hpb_mr_t_l, 0, 100, readBookControl.tipPaddingLeft) - setSeekBarView(hpb_mr_t_r, tv_hpb_mr_t_r, 0, 100, readBookControl.tipPaddingRight) - setSeekBarView(hpb_mr_t_b, tv_hpb_mr_t_b, 0, 100, readBookControl.tipPaddingBottom) + setSeekBarView(binding.hpbMrTT, binding.tvHpbMrTT, 0, 100, readBookControl.tipPaddingTop) + setSeekBarView(binding.hpbMrTL, binding.tvHpbMrTL, 0, 100, readBookControl.tipPaddingLeft) + setSeekBarView(binding.hpbMrTR, binding.tvHpbMrTR, 0, 100, readBookControl.tipPaddingRight) + setSeekBarView(binding.hpbMrTB, binding.tvHpbMrTB, 0, 100, readBookControl.tipPaddingBottom) } } - private fun bindEvent() { + private fun bindEvent() = with(binding) { //字距调节 - hpb_mr_f.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + hpbMrF.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { readBookControl.textLetterSpacing = i / 100.0f - 0.5f - tv_hpb_mr_f.text = String.format("%.2f", readBookControl.textLetterSpacing) + tvHpbMrF.text = String.format("%.2f", readBookControl.textLetterSpacing) callback?.upTextSize() } override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} }) - iv_mr_f_add.onClick { hpb_mr_f.progress = hpb_mr_f.progress + 1 } - iv_mr_f_remove.onClick { hpb_mr_f.progress = hpb_mr_f.progress - 1 } + ivMrFAdd.onClick { hpbMrF.progress = hpbMrF.progress + 1 } + ivMrFRemove.onClick { hpbMrF.progress = hpbMrF.progress - 1 } //行距调节 - hpb_mr_rm.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + hpbMrRm.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { readBookControl.lineMultiplier = i / 10.0f + 0.5f - tv_hpb_mr_rm.text = String.format("%.1f", readBookControl.lineMultiplier) + tvHpbMrRm.text = String.format("%.1f", readBookControl.lineMultiplier) callback?.upTextSize() } override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} }) - iv_mr_rm_add.onClick { hpb_mr_rm.progress = hpb_mr_rm.progress + 1 } - iv_mr_rm_remove.onClick { hpb_mr_rm.progress = hpb_mr_rm.progress - 1 } + ivMrRmAdd.onClick { hpbMrRm.progress = hpbMrRm.progress + 1 } + ivMrRmRemove.onClick { hpbMrRm.progress = hpbMrRm.progress - 1 } //段距调节 - hpb_mr_dm.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { + hpbMrDm.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { readBookControl.paragraphSize = i / 10.0f + 1.0f - tv_hpb_mr_dm.text = String.format("%.1f", readBookControl.paragraphSize) + tvHpbMrDm.text = String.format("%.1f", readBookControl.paragraphSize) callback?.upTextSize() } override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} }) - iv_mr_dm_add.onClick { hpb_mr_dm.progress = hpb_mr_dm.progress + 1 } - iv_mr_dm_remove.onClick { hpb_mr_dm.progress = hpb_mr_dm.progress - 1 } + ivMrDmAdd.onClick { hpbMrDm.progress = hpbMrDm.progress + 1 } + ivMrDmRemove.onClick { hpbMrDm.progress = hpbMrDm.progress - 1 } //段距调节 val pdChange = object : SeekBar.OnSeekBarChangeListener { override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) { var flag = 1 when { - seekBar === hpb_mr_z_t -> readBookControl.paddingTop = i - seekBar === hpb_mr_z_l -> readBookControl.paddingLeft = i - seekBar === hpb_mr_z_r -> readBookControl.paddingRight = i - seekBar === hpb_mr_z_b -> readBookControl.paddingBottom = i + seekBar === hpbMrZT -> readBookControl.paddingTop = i + seekBar === hpbMrZL -> readBookControl.paddingLeft = i + seekBar === hpbMrZR -> readBookControl.paddingRight = i + seekBar === hpbMrZB -> readBookControl.paddingBottom = i else -> { flag = 2 when { - seekBar === hpb_mr_t_t -> readBookControl.tipPaddingTop = i - seekBar === hpb_mr_t_l -> readBookControl.tipPaddingLeft = i - seekBar === hpb_mr_t_r -> readBookControl.tipPaddingRight = i + seekBar === hpbMrTT -> readBookControl.tipPaddingTop = i + seekBar === hpbMrTL -> readBookControl.tipPaddingLeft = i + seekBar === hpbMrTR -> readBookControl.tipPaddingRight = i else -> readBookControl.tipPaddingBottom = i } } @@ -140,30 +134,30 @@ class ReadAdjustMarginPop : FrameLayout { override fun onStartTrackingTouch(seekBar: SeekBar) {} override fun onStopTrackingTouch(seekBar: SeekBar) {} } - hpb_mr_z_t.setOnSeekBarChangeListener(pdChange) - hpb_mr_z_l.setOnSeekBarChangeListener(pdChange) - hpb_mr_z_r.setOnSeekBarChangeListener(pdChange) - hpb_mr_z_b.setOnSeekBarChangeListener(pdChange) - hpb_mr_t_t.setOnSeekBarChangeListener(pdChange) - hpb_mr_t_l.setOnSeekBarChangeListener(pdChange) - hpb_mr_t_r.setOnSeekBarChangeListener(pdChange) - hpb_mr_t_b.setOnSeekBarChangeListener(pdChange) - iv_mr_z_t_add.onClick { hpb_mr_z_t.progress = hpb_mr_z_t.progress + 1 } - iv_mr_z_t_remove.onClick { hpb_mr_z_t.progress = hpb_mr_z_t.progress - 1 } - iv_mr_z_l_add.onClick { hpb_mr_z_l.progress = hpb_mr_z_l.progress + 1 } - iv_mr_z_l_remove.onClick { hpb_mr_z_l.progress = hpb_mr_z_l.progress - 1 } - iv_mr_z_r_add.onClick { hpb_mr_z_r.progress = hpb_mr_z_r.progress + 1 } - iv_mr_z_r_remove.onClick { hpb_mr_z_r.progress = hpb_mr_z_r.progress - 1 } - iv_mr_z_b_add.onClick { hpb_mr_z_b.progress = hpb_mr_z_b.progress + 1 } - iv_mr_z_b_remove.onClick { hpb_mr_z_b.progress = hpb_mr_z_b.progress - 1 } - iv_mr_t_t_add.onClick { hpb_mr_t_t.progress = hpb_mr_t_t.progress + 1 } - iv_mr_t_t_remove.onClick { hpb_mr_t_t.progress = hpb_mr_t_t.progress - 1 } - iv_mr_t_l_add.onClick { hpb_mr_t_l.progress = hpb_mr_t_l.progress + 1 } - iv_mr_t_l_remove.onClick { hpb_mr_t_l.progress = hpb_mr_t_l.progress - 1 } - iv_mr_t_r_add.onClick { hpb_mr_t_r.progress = hpb_mr_t_r.progress + 1 } - iv_mr_t_r_remove.onClick { hpb_mr_t_r.progress = hpb_mr_t_r.progress - 1 } - iv_mr_t_b_add.onClick { hpb_mr_t_b.progress = hpb_mr_t_b.progress + 1 } - iv_mr_t_b_remove.onClick { hpb_mr_t_b.progress = hpb_mr_t_b.progress - 1 } + hpbMrZT.setOnSeekBarChangeListener(pdChange) + hpbMrZL.setOnSeekBarChangeListener(pdChange) + hpbMrZR.setOnSeekBarChangeListener(pdChange) + hpbMrZB.setOnSeekBarChangeListener(pdChange) + hpbMrTT.setOnSeekBarChangeListener(pdChange) + hpbMrTL.setOnSeekBarChangeListener(pdChange) + hpbMrTR.setOnSeekBarChangeListener(pdChange) + hpbMrTB.setOnSeekBarChangeListener(pdChange) + ivMrZTAdd.onClick { hpbMrZT.progress = hpbMrZT.progress + 1 } + ivMrZTRemove.onClick { hpbMrZT.progress = hpbMrZT.progress - 1 } + ivMrZLAdd.onClick { hpbMrZL.progress = hpbMrZL.progress + 1 } + ivMrZLRemove.onClick { hpbMrZL.progress = hpbMrZL.progress - 1 } + ivMrZRAdd.onClick { hpbMrZR.progress = hpbMrZR.progress + 1 } + ivMrZRRemove.onClick { hpbMrZR.progress = hpbMrZR.progress - 1 } + ivMrZBAdd.onClick { hpbMrZB.progress = hpbMrZB.progress + 1 } + ivMrZBRemove.onClick { hpbMrZB.progress = hpbMrZB.progress - 1 } + ivMrTTAdd.onClick { hpbMrTT.progress = hpbMrTT.progress + 1 } + ivMrTTRemove.onClick { hpbMrTT.progress = hpbMrTT.progress - 1 } + ivMrTLAdd.onClick { hpbMrTL.progress = hpbMrTL.progress + 1 } + ivMrTLRemove.onClick { hpbMrTL.progress = hpbMrTL.progress - 1 } + ivMrTRAdd.onClick { hpbMrTR.progress = hpbMrTR.progress + 1 } + ivMrTRRemove.onClick { hpbMrTR.progress = hpbMrTR.progress - 1 } + ivMrTBAdd.onClick { hpbMrTB.progress = hpbMrTB.progress + 1 } + ivMrTBRemove.onClick { hpbMrTB.progress = hpbMrTB.progress - 1 } } private fun setSeekBarView(hpb: SeekBar, tv: TextView?, min: Float, max: Float, value: Float, p: Int) { diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustPop.java b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustPop.java index 3b3d5c81a0..e152f6fe06 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustPop.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadAdjustPop.java @@ -5,43 +5,17 @@ import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.view.WindowManager; import android.widget.FrameLayout; -import android.widget.LinearLayout; import android.widget.SeekBar; -import android.widget.TextView; -import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.PopReadAdjustBinding; import com.kunfei.bookshelf.help.ReadBookControl; -import com.kunfei.bookshelf.widget.check_box.SmoothCheckBox; - -import butterknife.BindView; -import butterknife.ButterKnife; public class ReadAdjustPop extends FrameLayout { - @BindView(R.id.vw_bg) - View vwBg; - @BindView(R.id.hpb_light) - SeekBar hpbLight; - @BindView(R.id.scb_follow_sys) - SmoothCheckBox scbFollowSys; - @BindView(R.id.ll_follow_sys) - LinearLayout llFollowSys; - @BindView(R.id.ll_click) - LinearLayout llClick; - @BindView(R.id.hpb_click) - SeekBar hpbClick; - @BindView(R.id.ll_tts_SpeechRate) - LinearLayout llTtsSpeechRate; - @BindView(R.id.hpb_tts_SpeechRate) - SeekBar hpbTtsSpeechRate; - @BindView(R.id.scb_tts_follow_sys) - SmoothCheckBox scbTtsFollowSys; - @BindView(R.id.tv_auto_page) - TextView tvAutoPage; - - private Activity context; + + private PopReadAdjustBinding binding = PopReadAdjustBinding.inflate(LayoutInflater.from(getContext()), this, true); + private Activity activity; private ReadBookControl readBookControl = ReadBookControl.getInstance(); private Callback callback; @@ -61,13 +35,11 @@ public ReadAdjustPop(Context context, AttributeSet attrs, int defStyleAttr) { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.pop_read_adjust, this); - ButterKnife.bind(this, view); - vwBg.setOnClickListener(null); + binding.vwBg.setOnClickListener(null); } public void setListener(Activity activity, Callback callback) { - this.context = activity; + this.activity = activity; this.callback = callback; initData(); bindEvent(); @@ -79,41 +51,33 @@ public void show() { } private void initData() { - scbTtsFollowSys.setChecked(readBookControl.isSpeechRateFollowSys()); - if (readBookControl.isSpeechRateFollowSys()) { - hpbTtsSpeechRate.setEnabled(false); - } else { - hpbTtsSpeechRate.setEnabled(true); - } + binding.scbTtsFollowSys.setChecked(readBookControl.isSpeechRateFollowSys()); + binding.hpbTtsSpeechRate.setEnabled(!readBookControl.isSpeechRateFollowSys()); //CPM范围设置 每分钟阅读200字到2000字 默认500字/分钟 - hpbClick.setMax(readBookControl.maxCPM - readBookControl.minCPM); - hpbClick.setProgress(readBookControl.getCPM()); - tvAutoPage.setText(String.format("%sCPM", readBookControl.getCPM())); - hpbTtsSpeechRate.setProgress(readBookControl.getSpeechRate() - 5); + binding.hpbClick.setMax(readBookControl.maxCPM - readBookControl.minCPM); + binding.hpbClick.setProgress(readBookControl.getCPM()); + binding.tvAutoPage.setText(String.format("%sCPM", readBookControl.getCPM())); + binding.hpbTtsSpeechRate.setProgress(readBookControl.getSpeechRate() - 5); } private void bindEvent() { //亮度调节 - llFollowSys.setOnClickListener(v -> { - if (scbFollowSys.isChecked()) { - scbFollowSys.setChecked(false, true); - } else { - scbFollowSys.setChecked(true, true); - } + binding.llFollowSys.setOnClickListener(v -> { + binding.scbFollowSys.setChecked(!binding.scbFollowSys.isChecked(), true); }); - scbFollowSys.setOnCheckedChangeListener((checkBox, isChecked) -> { + binding.scbFollowSys.setOnCheckedChangeListener((checkBox, isChecked) -> { readBookControl.setLightFollowSys(isChecked); if (isChecked) { //跟随系统 - hpbLight.setEnabled(false); + binding.hpbLight.setEnabled(false); setScreenBrightness(); } else { //不跟随系统 - hpbLight.setEnabled(true); + binding.hpbLight.setEnabled(true); setScreenBrightness(readBookControl.getLight()); } }); - hpbLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.hpbLight.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (!readBookControl.getLightFollowSys()) { @@ -134,10 +98,10 @@ public void onStopTrackingTouch(SeekBar seekBar) { }); //自动翻页阅读速度(CPM) - hpbClick.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.hpbClick.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { - tvAutoPage.setText(String.format("%sCPM", i + readBookControl.minCPM)); + binding.tvAutoPage.setText(String.format("%sCPM", i + readBookControl.minCPM)); readBookControl.setCPM(i + readBookControl.minCPM); } @@ -153,31 +117,27 @@ public void onStopTrackingTouch(SeekBar seekBar) { }); //朗读语速调节 - llTtsSpeechRate.setOnClickListener(v -> { - if (scbTtsFollowSys.isChecked()) { - scbTtsFollowSys.setChecked(false, true); - } else { - scbTtsFollowSys.setChecked(true, true); - } + binding.llTtsSpeechRate.setOnClickListener(v -> { + binding.scbTtsFollowSys.setChecked(!binding.scbTtsFollowSys.isChecked(), true); }); - scbTtsFollowSys.setOnCheckedChangeListener((checkBox, isChecked) -> { + binding.scbTtsFollowSys.setOnCheckedChangeListener((checkBox, isChecked) -> { if (isChecked) { //跟随系统 - hpbTtsSpeechRate.setEnabled(false); + binding.hpbTtsSpeechRate.setEnabled(false); readBookControl.setSpeechRateFollowSys(true); if (callback != null) { callback.speechRateFollowSys(); } } else { //不跟随系统 - hpbTtsSpeechRate.setEnabled(true); + binding.hpbTtsSpeechRate.setEnabled(true); readBookControl.setSpeechRateFollowSys(false); if (callback != null) { callback.changeSpeechRate(readBookControl.getSpeechRate()); } } }); - hpbTtsSpeechRate.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.hpbTtsSpeechRate.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { @@ -199,21 +159,21 @@ public void onStopTrackingTouch(SeekBar seekBar) { } public void setScreenBrightness() { - WindowManager.LayoutParams params = (context).getWindow().getAttributes(); + WindowManager.LayoutParams params = activity.getWindow().getAttributes(); params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; - (context).getWindow().setAttributes(params); + activity.getWindow().setAttributes(params); } public void setScreenBrightness(int value) { if (value < 1) value = 1; - WindowManager.LayoutParams params = (context).getWindow().getAttributes(); + WindowManager.LayoutParams params = activity.getWindow().getAttributes(); params.screenBrightness = value * 1.0f / 255f; - (context).getWindow().setAttributes(params); + activity.getWindow().setAttributes(params); } public void initLight() { - hpbLight.setProgress(readBookControl.getLight()); - scbFollowSys.setChecked(readBookControl.getLightFollowSys()); + binding.hpbLight.setProgress(readBookControl.getLight()); + binding.scbFollowSys.setChecked(readBookControl.getLightFollowSys()); if (!readBookControl.getLightFollowSys()) { setScreenBrightness(readBookControl.getLight()); } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadBottomMenu.java b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadBottomMenu.java index 7e6e1d599c..5cb83f56be 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadBottomMenu.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadBottomMenu.java @@ -3,58 +3,16 @@ import android.content.Context; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; -import android.widget.LinearLayout; import android.widget.SeekBar; -import android.widget.TextView; -import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.PopReadMenuBinding; import com.kunfei.bookshelf.service.ReadAloudService; -import butterknife.BindView; -import butterknife.ButterKnife; - public class ReadBottomMenu extends FrameLayout { - @BindView(R.id.vw_bg) - View vwBg; - @BindView(R.id.fab_read_aloud_timer) - FloatingActionButton fabReadAloudTimer; - @BindView(R.id.tv_read_aloud_timer) - TextView tvReadAloudTimer; - @BindView(R.id.ll_read_aloud_timer) - LinearLayout llReadAloudTimer; - @BindView(R.id.fabReadAloud) - FloatingActionButton fabReadAloud; - @BindView(R.id.fabAutoPage) - FloatingActionButton fabAutoPage; - @BindView(R.id.fabReplaceRule) - FloatingActionButton fabReplaceRule; - @BindView(R.id.fabNightTheme) - FloatingActionButton fabNightTheme; - @BindView(R.id.tv_pre) - TextView tvPre; - @BindView(R.id.hpb_read_progress) - SeekBar hpbReadProgress; - @BindView(R.id.tv_next) - TextView tvNext; - @BindView(R.id.ll_catalog) - LinearLayout llCatalog; - @BindView(R.id.ll_adjust) - LinearLayout llAdjust; - @BindView(R.id.ll_font) - LinearLayout llFont; - @BindView(R.id.ll_setting) - LinearLayout llSetting; - @BindView(R.id.llNavigationBar) - LinearLayout llNavigationBar; - @BindView(R.id.ll_floating_button) - LinearLayout llFloatingButton; - @BindView(R.id.vwNavigationBar) - View vwNavigationBar; - + private PopReadMenuBinding binding = PopReadMenuBinding.inflate(LayoutInflater.from(getContext()), this, true); private Callback callback; public ReadBottomMenu(Context context) { @@ -73,14 +31,12 @@ public ReadBottomMenu(Context context, AttributeSet attrs, int defStyleAttr) { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.pop_read_menu, this); - ButterKnife.bind(this, view); - vwBg.setOnClickListener(null); - vwNavigationBar.setOnClickListener(null); + binding.vwBg.setOnClickListener(null); + binding.vwNavigationBar.setOnClickListener(null); } public void setNavigationBarHeight(int height) { - vwNavigationBar.getLayoutParams().height = height; + binding.vwNavigationBar.getLayoutParams().height = height; } public void setListener(Callback callback) { @@ -89,11 +45,11 @@ public void setListener(Callback callback) { } private void bindEvent() { - llReadAloudTimer.setOnClickListener(view -> callback.dismiss()); - llFloatingButton.setOnClickListener(view -> callback.dismiss()); + binding.llReadAloudTimer.setOnClickListener(view -> callback.dismiss()); + binding.llFloatingButton.setOnClickListener(view -> callback.dismiss()); //阅读进度 - hpbReadProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + binding.hpbReadProgress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { @@ -111,12 +67,12 @@ public void onStopTrackingTouch(SeekBar seekBar) { }); //朗读定时 - fabReadAloudTimer.setOnClickListener(view -> ReadAloudService.setTimer(getContext(), 10)); + binding.fabReadAloudTimer.setOnClickListener(view -> ReadAloudService.setTimer(getContext(), 10)); //朗读 - fabReadAloud.setOnClickListener(view -> callback.onMediaButton()); + binding.fabReadAloud.setOnClickListener(view -> callback.onMediaButton()); //长按停止朗读 - fabReadAloud.setOnLongClickListener(view -> { + binding.fabReadAloud.setOnLongClickListener(view -> { if (ReadAloudService.running) { callback.toast(R.string.aloud_stop); ReadAloudService.stop(getContext()); @@ -127,94 +83,94 @@ public void onStopTrackingTouch(SeekBar seekBar) { }); //自动翻页 - fabAutoPage.setOnClickListener(view -> callback.autoPage()); - fabAutoPage.setOnLongClickListener(view -> { + binding.fabAutoPage.setOnClickListener(view -> callback.autoPage()); + binding.fabAutoPage.setOnLongClickListener(view -> { callback.toast(R.string.auto_next_page); return true; }); //替换 - fabReplaceRule.setOnClickListener(view -> callback.openReplaceRule()); - fabReplaceRule.setOnLongClickListener(view -> { + binding.fabReplaceRule.setOnClickListener(view -> callback.openReplaceRule()); + binding.fabReplaceRule.setOnLongClickListener(view -> { callback.toast(R.string.replace_rule_title); return true; }); //夜间模式 - fabNightTheme.setOnClickListener(view -> callback.setNightTheme()); - fabNightTheme.setOnLongClickListener(view -> { + binding.fabNightTheme.setOnClickListener(view -> callback.setNightTheme()); + binding.fabNightTheme.setOnLongClickListener(view -> { callback.toast(R.string.night_theme); return true; }); //上一章 - tvPre.setOnClickListener(view -> callback.skipPreChapter()); + binding.tvPre.setOnClickListener(view -> callback.skipPreChapter()); //下一章 - tvNext.setOnClickListener(view -> callback.skipNextChapter()); + binding.tvNext.setOnClickListener(view -> callback.skipNextChapter()); //目录 - llCatalog.setOnClickListener(view -> callback.openChapterList()); + binding.llCatalog.setOnClickListener(view -> callback.openChapterList()); //调节 - llAdjust.setOnClickListener(view -> callback.openAdjust()); + binding.llAdjust.setOnClickListener(view -> callback.openAdjust()); //界面 - llFont.setOnClickListener(view -> callback.openReadInterface()); + binding.llFont.setOnClickListener(view -> callback.openReadInterface()); //设置 - llSetting.setOnClickListener(view -> callback.openMoreSetting()); + binding.llSetting.setOnClickListener(view -> callback.openMoreSetting()); - tvReadAloudTimer.setOnClickListener(null); + binding.tvReadAloudTimer.setOnClickListener(null); } public void setFabReadAloudImage(int id) { - fabReadAloud.setImageResource(id); + binding.fabReadAloud.setImageResource(id); } public void setReadAloudTimer(boolean visibility) { if (visibility) { - llReadAloudTimer.setVisibility(VISIBLE); + binding.llReadAloudTimer.setVisibility(VISIBLE); } else { - llReadAloudTimer.setVisibility(GONE); + binding.llReadAloudTimer.setVisibility(GONE); } } public void setReadAloudTimer(String text) { - tvReadAloudTimer.setText(text); + binding.tvReadAloudTimer.setText(text); } public void setFabReadAloudText(String text) { - fabReadAloud.setContentDescription(text); + binding.fabReadAloud.setContentDescription(text); } public SeekBar getReadProgress() { - return hpbReadProgress; + return binding.hpbReadProgress; } public void setTvPre(boolean enable) { - tvPre.setEnabled(enable); + binding.tvPre.setEnabled(enable); } public void setTvNext(boolean enable) { - tvNext.setEnabled(enable); + binding.tvNext.setEnabled(enable); } public void setAutoPage(boolean autoPage) { if (autoPage) { - fabAutoPage.setImageResource(R.drawable.ic_auto_page_stop); - fabAutoPage.setContentDescription(getContext().getString(R.string.auto_next_page_stop)); + binding.fabAutoPage.setImageResource(R.drawable.ic_auto_page_stop); + binding.fabAutoPage.setContentDescription(getContext().getString(R.string.auto_next_page_stop)); } else { - fabAutoPage.setImageResource(R.drawable.ic_auto_page); - fabAutoPage.setContentDescription(getContext().getString(R.string.auto_next_page)); + binding.fabAutoPage.setImageResource(R.drawable.ic_auto_page); + binding.fabAutoPage.setContentDescription(getContext().getString(R.string.auto_next_page)); } } public void setFabNightTheme(boolean isNightTheme) { if (isNightTheme) { - fabNightTheme.setImageResource(R.drawable.ic_daytime); + binding.fabNightTheme.setImageResource(R.drawable.ic_daytime); } else { - fabNightTheme.setImageResource(R.drawable.ic_brightness); + binding.fabNightTheme.setImageResource(R.drawable.ic_brightness); } } diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadInterfacePop.java b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadInterfacePop.java index 2fe60a5e57..1ee9a1eea7 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadInterfacePop.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadInterfacePop.java @@ -6,15 +6,13 @@ import android.graphics.Color; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; -import android.widget.ImageView; -import android.widget.TextView; import androidx.annotation.NonNull; import androidx.appcompat.app.AlertDialog; import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.PopReadInterfaceBinding; import com.kunfei.bookshelf.help.ReadBookControl; import com.kunfei.bookshelf.help.permission.Permissions; import com.kunfei.bookshelf.help.permission.PermissionsCompat; @@ -24,60 +22,11 @@ import com.kunfei.bookshelf.widget.font.FontSelector; import com.kunfei.bookshelf.widget.page.animation.PageAnimation; -import butterknife.BindView; -import butterknife.ButterKnife; -import de.hdodenhof.circleimageview.CircleImageView; import kotlin.Unit; public class ReadInterfacePop extends FrameLayout { - @BindView(R.id.vw_bg) - View vwBg; - @BindView(R.id.fl_text_Bold) - TextView flTextBold; - @BindView(R.id.fl_text_font) - TextView fl_text_font; - @BindView(R.id.civ_bg_white) - CircleImageView civBgWhite; - @BindView(R.id.civ_bg_yellow) - CircleImageView civBgYellow; - @BindView(R.id.civ_bg_green) - CircleImageView civBgGreen; - @BindView(R.id.civ_bg_black) - CircleImageView civBgBlack; - @BindView(R.id.civ_bg_blue) - CircleImageView civBgBlue; - @BindView(R.id.tv0) - TextView tv0; - @BindView(R.id.tv1) - TextView tv1; - @BindView(R.id.tv2) - TextView tv2; - @BindView(R.id.tv3) - TextView tv3; - @BindView(R.id.tv4) - TextView tv4; - - @BindView(R.id.nbTextSize) - TextView nbTextSize; - @BindView(R.id.nbTextSizeAdd) - TextView nbTextSizeAdd; - @BindView(R.id.nbTextSizeDec) - TextView nbTextSizeDec; - @BindView(R.id.fl_indent) - TextView tvIndent; - @BindView(R.id.tvPageMode) - TextView tvPageMode; - @BindView(R.id.tvRowDef0) - TextView tvRowDef0; - @BindView(R.id.tvRowDef1) - TextView tvRowDef1; - @BindView(R.id.tvRowDef2) - TextView tvRowDef2; - @BindView(R.id.tvRowDef) - TextView tvRowDef; - @BindView(R.id.tvOther) - ImageView tvOther; + private PopReadInterfaceBinding binding = PopReadInterfaceBinding.inflate(LayoutInflater.from(getContext()), this, true); private ReadBookActivity activity; private ReadBookControl readBookControl = ReadBookControl.getInstance(); private Callback callback; @@ -98,9 +47,7 @@ public ReadInterfacePop(Context context, AttributeSet attrs, int defStyleAttr) { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.pop_read_interface, this); - ButterKnife.bind(this, view); - vwBg.setOnClickListener(null); + binding.vwBg.setOnClickListener(null); } public void setListener(ReadBookActivity readBookActivity, @NonNull Callback callback) { @@ -116,30 +63,31 @@ private void initData() { updateBoldText(readBookControl.getTextBold()); updatePageMode(readBookControl.getPageMode()); - nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); } + binding.nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); + } /** * 控件事件 */ private void bindEvent() { //字号减 - nbTextSizeDec.setOnClickListener(v -> { + binding.nbTextSizeDec.setOnClickListener(v -> { int fontSize = readBookControl.getTextSize() - 1; if (fontSize < 10) fontSize = 10; readBookControl.setTextSize(fontSize); - nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); + binding.nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); callback.upTextSize(); }); //字号加 - nbTextSizeAdd.setOnClickListener(v -> { + binding.nbTextSizeAdd.setOnClickListener(v -> { int fontSize = readBookControl.getTextSize() + 1; if (fontSize > 40) fontSize = 40; readBookControl.setTextSize(fontSize); - nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); + binding.nbTextSize.setText(String.format("%d", readBookControl.getTextSize())); callback.upTextSize(); }); //缩进 - tvIndent.setOnClickListener(v -> { + binding.flIndent.setOnClickListener(v -> { AlertDialog dialog = new AlertDialog.Builder(activity, R.style.alertDialogTheme) .setTitle(activity.getString(R.string.indent)) .setSingleChoiceItems(activity.getResources().getStringArray(R.array.indent), @@ -154,7 +102,7 @@ private void bindEvent() { ATH.setAlertDialogTint(dialog); }); //翻页模式 - tvPageMode.setOnClickListener(view -> { + binding.tvPageMode.setOnClickListener(view -> { AlertDialog dialog = new AlertDialog.Builder(activity, R.style.alertDialogTheme) .setTitle(activity.getString(R.string.page_mode)) .setSingleChoiceItems(PageAnimation.Mode.getAllPageMode(), readBookControl.getPageMode(), (dialogInterface, i) -> { @@ -168,69 +116,69 @@ private void bindEvent() { ATH.setAlertDialogTint(dialog); }); //加粗切换 - flTextBold.setOnClickListener(view -> { + binding.flTextBold.setOnClickListener(view -> { readBookControl.setTextBold(!readBookControl.getTextBold()); updateBoldText(readBookControl.getTextBold()); callback.upTextSize(); }); //行距单倍 - tvRowDef0.setOnClickListener(v -> { + binding.tvRowDef0.setOnClickListener(v -> { readBookControl.setLineMultiplier(0.6f); readBookControl.setParagraphSize(1.5f); callback.upTextSize(); }); //行距双倍 - tvRowDef1.setOnClickListener(v -> { + binding.tvRowDef1.setOnClickListener(v -> { readBookControl.setLineMultiplier(1.2f); readBookControl.setParagraphSize(1.8f); callback.upTextSize(); }); //行距三倍 - tvRowDef2.setOnClickListener(v -> { + binding.tvRowDef2.setOnClickListener(v -> { readBookControl.setLineMultiplier(1.8f); readBookControl.setParagraphSize(2.0f); callback.upTextSize(); }); //行距默认 - tvRowDef.setOnClickListener(v -> { + binding.tvRowDef.setOnClickListener(v -> { readBookControl.setLineMultiplier(1.0f); readBookControl.setParagraphSize(1.8f); callback.upTextSize(); }); //自定义间距 - tvOther.setOnClickListener(v -> { + binding.tvOther.setOnClickListener(v -> { activity.readAdjustMarginIn(); }); //背景选择 - civBgWhite.setOnClickListener(v -> { + binding.civBgWhite.setOnClickListener(v -> { updateBg(0); callback.bgChange(); }); - civBgYellow.setOnClickListener(v -> { + binding.civBgYellow.setOnClickListener(v -> { updateBg(1); callback.bgChange(); }); - civBgGreen.setOnClickListener(v -> { + binding.civBgGreen.setOnClickListener(v -> { updateBg(2); callback.bgChange(); }); - civBgBlue.setOnClickListener(v -> { + binding.civBgBlue.setOnClickListener(v -> { updateBg(3); callback.bgChange(); }); - civBgBlack.setOnClickListener(v -> { + binding.civBgBlack.setOnClickListener(v -> { updateBg(4); callback.bgChange(); }); //自定义阅读样式 - civBgWhite.setOnLongClickListener(view -> customReadStyle(0)); - civBgYellow.setOnLongClickListener(view -> customReadStyle(1)); - civBgGreen.setOnLongClickListener(view -> customReadStyle(2)); - civBgBlue.setOnLongClickListener(view -> customReadStyle(3)); - civBgBlack.setOnLongClickListener(view -> customReadStyle(4)); + binding.civBgWhite.setOnLongClickListener(view -> customReadStyle(0)); + binding.civBgYellow.setOnLongClickListener(view -> customReadStyle(1)); + binding.civBgGreen.setOnLongClickListener(view -> customReadStyle(2)); + binding.civBgBlue.setOnLongClickListener(view -> customReadStyle(3)); + binding.civBgBlack.setOnLongClickListener(view -> customReadStyle(4)); //选择字体 - fl_text_font.setOnClickListener(view -> { + binding.flTextFont.setOnClickListener(view -> { new PermissionsCompat.Builder(activity) .addPermissions(Permissions.READ_EXTERNAL_STORAGE, Permissions.WRITE_EXTERNAL_STORAGE) .rationale(R.string.get_storage_per) @@ -255,7 +203,7 @@ public void setFontPath(String fontPath) { }); //长按清除字体 - fl_text_font.setOnLongClickListener(view -> { + binding.flTextFont.setOnLongClickListener(view -> { clearFontPath(); activity.toast(R.string.clear_font); return true; @@ -283,47 +231,47 @@ private void clearFontPath() { } private void updatePageMode(int pageMode) { - tvPageMode.setText(String.format("%s", PageAnimation.Mode.getPageMode(pageMode))); + binding.tvPageMode.setText(String.format("%s", PageAnimation.Mode.getPageMode(pageMode))); } private void updateBoldText(Boolean isBold) { - flTextBold.setSelected(isBold); + binding.flTextBold.setSelected(isBold); } public void setBg() { - tv0.setTextColor(readBookControl.getTextColor(0)); - tv1.setTextColor(readBookControl.getTextColor(1)); - tv2.setTextColor(readBookControl.getTextColor(2)); - tv3.setTextColor(readBookControl.getTextColor(3)); - tv4.setTextColor(readBookControl.getTextColor(4)); - civBgWhite.setImageDrawable(readBookControl.getBgDrawable(0, activity, 100, 180)); - civBgYellow.setImageDrawable(readBookControl.getBgDrawable(1, activity, 100, 180)); - civBgGreen.setImageDrawable(readBookControl.getBgDrawable(2, activity, 100, 180)); - civBgBlue.setImageDrawable(readBookControl.getBgDrawable(3, activity, 100, 180)); - civBgBlack.setImageDrawable(readBookControl.getBgDrawable(4, activity, 100, 180)); + binding.tv0.setTextColor(readBookControl.getTextColor(0)); + binding.tv1.setTextColor(readBookControl.getTextColor(1)); + binding.tv2.setTextColor(readBookControl.getTextColor(2)); + binding.tv3.setTextColor(readBookControl.getTextColor(3)); + binding.tv4.setTextColor(readBookControl.getTextColor(4)); + binding.civBgWhite.setImageDrawable(readBookControl.getBgDrawable(0, activity, 100, 180)); + binding.civBgYellow.setImageDrawable(readBookControl.getBgDrawable(1, activity, 100, 180)); + binding.civBgGreen.setImageDrawable(readBookControl.getBgDrawable(2, activity, 100, 180)); + binding.civBgBlue.setImageDrawable(readBookControl.getBgDrawable(3, activity, 100, 180)); + binding.civBgBlack.setImageDrawable(readBookControl.getBgDrawable(4, activity, 100, 180)); } private void updateBg(int index) { - civBgWhite.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); - civBgYellow.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); - civBgGreen.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); - civBgBlack.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); - civBgBlue.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); + binding.civBgWhite.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); + binding.civBgYellow.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); + binding.civBgGreen.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); + binding.civBgBlack.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); + binding.civBgBlue.setBorderColor(activity.getResources().getColor(R.color.tv_text_default)); switch (index) { case 0: - civBgWhite.setBorderColor(Color.parseColor("#F3B63F")); + binding.civBgWhite.setBorderColor(Color.parseColor("#F3B63F")); break; case 1: - civBgYellow.setBorderColor(Color.parseColor("#F3B63F")); + binding.civBgYellow.setBorderColor(Color.parseColor("#F3B63F")); break; case 2: - civBgGreen.setBorderColor(Color.parseColor("#F3B63F")); + binding.civBgGreen.setBorderColor(Color.parseColor("#F3B63F")); break; case 3: - civBgBlue.setBorderColor(Color.parseColor("#F3B63F")); + binding.civBgBlue.setBorderColor(Color.parseColor("#F3B63F")); break; case 4: - civBgBlack.setBorderColor(Color.parseColor("#F3B63F")); + binding.civBgBlack.setBorderColor(Color.parseColor("#F3B63F")); break; } readBookControl.setTextDrawableIndex(index); diff --git a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadLongPressPop.java b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadLongPressPop.java index e1a384c7d7..6acfc84a1c 100644 --- a/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadLongPressPop.java +++ b/app/src/main/java/com/kunfei/bookshelf/view/popupwindow/ReadLongPressPop.java @@ -8,30 +8,17 @@ import android.os.Build; import android.util.AttributeSet; import android.view.LayoutInflater; -import android.view.View; import android.widget.FrameLayout; import androidx.annotation.NonNull; -import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.PopReadLongPressBinding; import com.kunfei.bookshelf.help.ReadBookControl; import com.kunfei.bookshelf.utils.DensityUtil; -import butterknife.BindView; -import butterknife.ButterKnife; - public class ReadLongPressPop extends FrameLayout { - - //翻页相关 - @BindView(R.id.fl_replace) - FrameLayout flReplace; - @BindView(R.id.fl_cp) - FrameLayout flCp; - @BindView(R.id.fl_replace_ad) - FrameLayout flReplaceAd; - - + private PopReadLongPressBinding binding = PopReadLongPressBinding.inflate(LayoutInflater.from(getContext()), this, true); //private ReadBookActivity activity; private ReadBookControl readBookControl = ReadBookControl.getInstance(); private OnBtnClickListener clickListener; @@ -65,10 +52,7 @@ protected void dispatchDraw(Canvas canvas) { } private void init(Context context) { - View view = LayoutInflater.from(context).inflate(R.layout.pop_read_long_press, null); - addView(view); - ButterKnife.bind(this, view); - view.setOnClickListener(null); + binding.getRoot().setOnClickListener(null); } public void setListener(@NonNull OnBtnClickListener clickListener) { @@ -85,13 +69,13 @@ private void initData() { private void bindEvent() { //复制 - flCp.setOnClickListener(v -> clickListener.copySelect()); + binding.flCp.setOnClickListener(v -> clickListener.copySelect()); //替换 - flReplace.setOnClickListener(v -> clickListener.replaceSelect()); + binding.flReplace.setOnClickListener(v -> clickListener.replaceSelect()); //标记广告 - flReplaceAd.setOnClickListener(v -> clickListener.replaceSelectAd()); + binding.flReplaceAd.setOnClickListener(v -> clickListener.replaceSelectAd()); } public interface OnBtnClickListener { diff --git a/app/src/main/java/com/kunfei/bookshelf/widget/modialog/PageKeyDialog.kt b/app/src/main/java/com/kunfei/bookshelf/widget/modialog/PageKeyDialog.kt index ff4d89e10d..5ee4d126f6 100644 --- a/app/src/main/java/com/kunfei/bookshelf/widget/modialog/PageKeyDialog.kt +++ b/app/src/main/java/com/kunfei/bookshelf/widget/modialog/PageKeyDialog.kt @@ -2,25 +2,27 @@ package com.kunfei.bookshelf.widget.modialog import android.content.Context import android.view.KeyEvent +import android.view.LayoutInflater import com.kunfei.bookshelf.MApplication -import com.kunfei.bookshelf.R +import com.kunfei.bookshelf.databinding.DialogPageKeyBinding import com.kunfei.bookshelf.utils.SoftInputUtil -import kotlinx.android.synthetic.main.dialog_page_key.* import org.jetbrains.anko.sdk27.listeners.onClick class PageKeyDialog(context: Context) : BaseDialog(context) { + val binding = DialogPageKeyBinding.inflate(LayoutInflater.from(context)) + init { - setContentView(R.layout.dialog_page_key) - et_prev.setText(MApplication.getConfigPreferences().getInt("prevKeyCode", 0).toString()) - et_next.setText(MApplication.getConfigPreferences().getInt("nextKeyCode", 0).toString()) - tv_ok.onClick { + setContentView(binding.root) + binding.etPrev.setText(MApplication.getConfigPreferences().getInt("prevKeyCode", 0).toString()) + binding.etNext.setText(MApplication.getConfigPreferences().getInt("nextKeyCode", 0).toString()) + binding.tvOk.onClick { val edit = MApplication.getConfigPreferences().edit() - et_prev.text?.let { + binding.etPrev.text?.let { edit.putInt("prevKeyCode", it.toString().toInt()) } - et_next.text?.let { + binding.etNext.text?.let { edit.putInt("nextKeyCode", it.toString().toInt()) } edit.apply() @@ -30,10 +32,10 @@ class PageKeyDialog(context: Context) : BaseDialog(context) { override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean { if (keyCode != KeyEvent.KEYCODE_BACK) { - if (et_prev.hasFocus()) { - et_prev.setText(keyCode.toString()) - } else if (et_next.hasFocus()) { - et_next.setText(keyCode.toString()) + if (binding.etPrev.hasFocus()) { + binding.etPrev.setText(keyCode.toString()) + } else if (binding.etNext.hasFocus()) { + binding.etNext.setText(keyCode.toString()) } return true } diff --git a/app/src/main/java/com/kunfei/bookshelf/widget/recycler/refresh/RefreshRecyclerView.java b/app/src/main/java/com/kunfei/bookshelf/widget/recycler/refresh/RefreshRecyclerView.java index 512e8765e2..91edff5894 100644 --- a/app/src/main/java/com/kunfei/bookshelf/widget/recycler/refresh/RefreshRecyclerView.java +++ b/app/src/main/java/com/kunfei/bookshelf/widget/recycler/refresh/RefreshRecyclerView.java @@ -8,7 +8,6 @@ import android.view.MotionEvent; import android.view.View; import android.widget.FrameLayout; -import android.widget.LinearLayout; import androidx.annotation.NonNull; import androidx.recyclerview.widget.ItemTouchHelper; @@ -16,20 +15,13 @@ import androidx.recyclerview.widget.RecyclerView; import com.kunfei.bookshelf.R; +import com.kunfei.bookshelf.databinding.ViewRefreshRecyclerBinding; import java.util.Objects; -import butterknife.BindView; -import butterknife.ButterKnife; - public class RefreshRecyclerView extends FrameLayout { - @BindView(R.id.recycler_view) - RecyclerView recyclerView; - @BindView(R.id.rpb) - RefreshProgressBar rpb; - @BindView(R.id.ll_content) - LinearLayout llContent; + private ViewRefreshRecyclerBinding binding = ViewRefreshRecyclerBinding.inflate(LayoutInflater.from(getContext()), this, true); private View noDataView; private View refreshErrorView; private float durTouchX = -1000000; @@ -55,29 +47,31 @@ public boolean onTouch(View v, MotionEvent event) { float dY = event.getY() - durTouchY; //>0下拉 durTouchY = event.getY(); - if (baseRefreshListener != null && ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).getIsRequesting() == 0 && rpb.getSecondDurProgress() == rpb.getSecondFinalProgress()) { - if (rpb.getVisibility() != View.VISIBLE) { - rpb.setVisibility(View.VISIBLE); + if (baseRefreshListener != null + && ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).getIsRequesting() == 0 + && binding.rpb.getSecondDurProgress() == binding.rpb.getSecondFinalProgress()) { + if (binding.rpb.getVisibility() != View.VISIBLE) { + binding.rpb.setVisibility(View.VISIBLE); } - if (recyclerView.getAdapter().getItemCount() > 0) { - if (0 == ((LinearLayoutManager) Objects.requireNonNull(recyclerView.getLayoutManager())).findFirstCompletelyVisibleItemPosition()) { - rpb.setSecondDurProgress((int) (rpb.getSecondDurProgress() + dY)); + if (binding.recyclerView.getAdapter().getItemCount() > 0) { + if (0 == ((LinearLayoutManager) Objects.requireNonNull(binding.recyclerView.getLayoutManager())).findFirstCompletelyVisibleItemPosition()) { + binding.rpb.setSecondDurProgress((int) (binding.rpb.getSecondDurProgress() + dY)); } } else { - rpb.setSecondDurProgress((int) (rpb.getSecondDurProgress() + dY)); + binding.rpb.setSecondDurProgress((int) (binding.rpb.getSecondDurProgress() + dY)); } - return rpb.getSecondDurProgress() > 0; + return binding.rpb.getSecondDurProgress() > 0; } break; case MotionEvent.ACTION_UP: - if (baseRefreshListener != null && rpb.getSecondMaxProgress() > 0 && rpb.getSecondDurProgress() > 0) { - if (rpb.getSecondDurProgress() >= rpb.getSecondMaxProgress() && ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).getIsRequesting() == 0) { + if (baseRefreshListener != null && binding.rpb.getSecondMaxProgress() > 0 && binding.rpb.getSecondDurProgress() > 0) { + if (binding.rpb.getSecondDurProgress() >= binding.rpb.getSecondMaxProgress() && ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).getIsRequesting() == 0) { if (baseRefreshListener instanceof OnRefreshWithProgressListener) { //带有进度的 //执行刷新响应 - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsAll(false, false); - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsRequesting(1, true); - rpb.setMaxProgress(((OnRefreshWithProgressListener) baseRefreshListener).getMaxProgress()); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsAll(false, false); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsRequesting(1, true); + binding.rpb.setMaxProgress(((OnRefreshWithProgressListener) baseRefreshListener).getMaxProgress()); baseRefreshListener.startRefresh(); if (noDataView != null) { noDataView.setVisibility(GONE); @@ -87,8 +81,8 @@ public boolean onTouch(View v, MotionEvent event) { } } else { //不带进度的 - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsAll(false, false); - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsRequesting(1, true); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsAll(false, false); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsRequesting(1, true); baseRefreshListener.startRefresh(); if (noDataView != null) { noDataView.setVisibility(GONE); @@ -96,11 +90,11 @@ public boolean onTouch(View v, MotionEvent event) { if (refreshErrorView != null) { refreshErrorView.setVisibility(GONE); } - rpb.setIsAutoLoading(true); + binding.rpb.setIsAutoLoading(true); } } else { - if (((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).getIsRequesting() != 1) - rpb.setSecondDurProgressWithAnim(0); + if (((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).getIsRequesting() != 1) + binding.rpb.setSecondDurProgressWithAnim(0); } } durTouchX = -1000000; @@ -122,26 +116,21 @@ public RefreshRecyclerView(Context context, AttributeSet attrs) { public RefreshRecyclerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - View view = LayoutInflater.from(context).inflate(R.layout.view_refresh_recycler, this, false); - ButterKnife.bind(this, view); - @SuppressLint("CustomViewStyleable") TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RefreshProgressBar); - rpb.setSpeed(a.getDimensionPixelSize(R.styleable.RefreshProgressBar_speed, rpb.getSpeed())); - rpb.setMaxProgress(a.getInt(R.styleable.RefreshProgressBar_max_progress, rpb.getMaxProgress())); - rpb.setSecondMaxProgress(a.getDimensionPixelSize(R.styleable.RefreshProgressBar_second_max_progress, rpb.getSecondMaxProgress())); - rpb.setBgColor(a.getColor(R.styleable.RefreshProgressBar_bg_color, rpb.getBgColor())); - rpb.setSecondColor(a.getColor(R.styleable.RefreshProgressBar_second_color, rpb.getSecondColor())); - rpb.setFontColor(a.getColor(R.styleable.RefreshProgressBar_font_color, rpb.getFontColor())); + binding.rpb.setSpeed(a.getDimensionPixelSize(R.styleable.RefreshProgressBar_speed, binding.rpb.getSpeed())); + binding.rpb.setMaxProgress(a.getInt(R.styleable.RefreshProgressBar_max_progress, binding.rpb.getMaxProgress())); + binding.rpb.setSecondMaxProgress(a.getDimensionPixelSize(R.styleable.RefreshProgressBar_second_max_progress, binding.rpb.getSecondMaxProgress())); + binding.rpb.setBgColor(a.getColor(R.styleable.RefreshProgressBar_bg_color, binding.rpb.getBgColor())); + binding.rpb.setSecondColor(a.getColor(R.styleable.RefreshProgressBar_second_color, binding.rpb.getSecondColor())); + binding.rpb.setFontColor(a.getColor(R.styleable.RefreshProgressBar_font_color, binding.rpb.getFontColor())); a.recycle(); bindEvent(); - - addView(view); } public void addItemDecoration(@NonNull RecyclerView.ItemDecoration decor) { - recyclerView.addItemDecoration(decor); + binding.recyclerView.addItemDecoration(decor); } public void setBaseRefreshListener(BaseRefreshListener baseRefreshListener) { @@ -154,7 +143,7 @@ public void setLoadMoreListener(OnLoadMoreListener loadMoreListener) { @SuppressLint("ClickableViewAccessibility") private void bindEvent() { - recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { + binding.recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { @@ -170,21 +159,21 @@ public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) { } } }); - recyclerView.setOnTouchListener(refreshTouchListener); + binding.recyclerView.setOnTouchListener(refreshTouchListener); } public RefreshProgressBar getRpb() { - return rpb; + return binding.rpb; } public RecyclerView getRecyclerView() { - return recyclerView; + return binding.recyclerView; } public void refreshError() { - rpb.setIsAutoLoading(false); - rpb.clean(); - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(0, true); + binding.rpb.setIsAutoLoading(false); + binding.rpb.clean(); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(0, true); if (noDataView != null) { noDataView.setVisibility(GONE); } @@ -195,13 +184,13 @@ public void refreshError() { public void startRefresh() { if (baseRefreshListener instanceof OnRefreshWithProgressListener) { - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsAll(false, false); - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsRequesting(1, false); - rpb.setSecondDurProgress(rpb.getSecondMaxProgress()); - rpb.setMaxProgress(((OnRefreshWithProgressListener) baseRefreshListener).getMaxProgress()); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsAll(false, false); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsRequesting(1, false); + binding.rpb.setSecondDurProgress(binding.rpb.getSecondMaxProgress()); + binding.rpb.setMaxProgress(((OnRefreshWithProgressListener) baseRefreshListener).getMaxProgress()); } else { - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(1, true); - rpb.setIsAutoLoading(true); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(1, true); + binding.rpb.setIsAutoLoading(true); if (noDataView != null) { noDataView.setVisibility(GONE); } @@ -212,24 +201,24 @@ public void startRefresh() { } public void finishRefresh(Boolean needNotify) { - finishRefresh(((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).getICount() == 0, needNotify); + finishRefresh(((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).getICount() == 0, needNotify); } public void finishRefresh(Boolean isAll, Boolean needNotify) { - rpb.setDurProgress(0); + binding.rpb.setDurProgress(0); if (isAll) { - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(0, false); - rpb.setIsAutoLoading(false); - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsAll(true, needNotify); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(0, false); + binding.rpb.setIsAutoLoading(false); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsAll(true, needNotify); } else { - rpb.setIsAutoLoading(false); - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(0, needNotify); + binding.rpb.setIsAutoLoading(false); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(0, needNotify); } if (isAll) { if (noDataView != null) { - recyclerView.post(() -> { - if (((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).getICount() == 0) { + binding.recyclerView.post(() -> { + if (((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).getICount() == 0) { noDataView.setVisibility(VISIBLE); } else { noDataView.setVisibility(GONE); @@ -244,10 +233,10 @@ public void finishRefresh(Boolean isAll, Boolean needNotify) { public void finishLoadMore(Boolean isAll, Boolean needNoti) { if (isAll) { - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(0, false); - ((RefreshRecyclerViewAdapter) recyclerView.getAdapter()).setIsAll(true, needNoti); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(0, false); + ((RefreshRecyclerViewAdapter) binding.recyclerView.getAdapter()).setIsAll(true, needNoti); } else { - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setIsRequesting(0, needNoti); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setIsRequesting(0, needNoti); } if (noDataView != null) { @@ -263,8 +252,8 @@ public void setRefreshRecyclerViewAdapter(RefreshRecyclerViewAdapter refreshRecy if (loadMoreListener != null) loadMoreListener.loadMoreErrorTryAgain(); }); - recyclerView.setLayoutManager(layoutManager); - recyclerView.setAdapter(refreshRecyclerViewAdapter); + binding.recyclerView.setLayoutManager(layoutManager); + binding.recyclerView.setAdapter(refreshRecyclerViewAdapter); } public void setRefreshRecyclerViewAdapter(View headerView, RefreshRecyclerViewAdapter refreshRecyclerViewAdapter, RecyclerView.LayoutManager layoutManager) { @@ -272,20 +261,20 @@ public void setRefreshRecyclerViewAdapter(View headerView, RefreshRecyclerViewAd if (loadMoreListener != null) loadMoreListener.loadMoreErrorTryAgain(); }); - llContent.addView(headerView, 0); - recyclerView.setLayoutManager(layoutManager); - recyclerView.setAdapter(refreshRecyclerViewAdapter); + binding.llContent.addView(headerView, 0); + binding.recyclerView.setLayoutManager(layoutManager); + binding.recyclerView.setAdapter(refreshRecyclerViewAdapter); } public void setItemTouchHelperCallback(ItemTouchHelper.Callback callback) { ItemTouchHelper itemTouchHelper = new ItemTouchHelper(callback); - itemTouchHelper.attachToRecyclerView(recyclerView); + itemTouchHelper.attachToRecyclerView(binding.recyclerView); } public void loadMoreError() { - rpb.setIsAutoLoading(false); - rpb.clean(); - ((RefreshRecyclerViewAdapter) Objects.requireNonNull(recyclerView.getAdapter())).setLoadMoreError(true, true); + binding.rpb.setIsAutoLoading(false); + binding.rpb.clean(); + ((RefreshRecyclerViewAdapter) Objects.requireNonNull(binding.recyclerView.getAdapter())).setLoadMoreError(true, true); } public void setNoDataAndRefreshErrorView(View noData, View refreshError) { diff --git a/app/src/main/res/layout/activity_book_detail.xml b/app/src/main/res/layout/activity_book_detail.xml index dfc68b83f0..9972c6f42f 100644 --- a/app/src/main/res/layout/activity_book_detail.xml +++ b/app/src/main/res/layout/activity_book_detail.xml @@ -216,12 +216,17 @@ android:textColor="@color/tv_text_book_detail" android:textSize="13sp" /> - diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index f2790b7848..c109832808 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -13,7 +13,9 @@ android:layout_height="match_parent" android:orientation="vertical"> - + diff --git a/app/src/main/res/layout/fragment_book_find.xml b/app/src/main/res/layout/fragment_book_find.xml index 87b88a9890..fa928bab74 100644 --- a/app/src/main/res/layout/fragment_book_find.xml +++ b/app/src/main/res/layout/fragment_book_find.xml @@ -39,7 +39,9 @@ - + diff --git a/app/src/main/res/layout/fragment_book_list.xml b/app/src/main/res/layout/fragment_book_list.xml index 8950fa8d8c..a7dece976c 100644 --- a/app/src/main/res/layout/fragment_book_list.xml +++ b/app/src/main/res/layout/fragment_book_list.xml @@ -18,7 +18,7 @@ android:padding="6dp"> - + diff --git a/app/src/main/res/layout/pop_media_player.xml b/app/src/main/res/layout/pop_media_player.xml index 248d65c761..25ecf69790 100644 --- a/app/src/main/res/layout/pop_media_player.xml +++ b/app/src/main/res/layout/pop_media_player.xml @@ -57,7 +57,7 @@ tools:ignore="RtlSymmetry" />