mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-16 10:56:50 -04:00
#2154 generified adapter
This commit is contained in:
parent
453b6fe67e
commit
ecb780bb36
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.page.adapter
|
||||
|
||||
interface OnItemClickListener {
|
||||
|
||||
fun onItemClick(page: Page)
|
||||
|
||||
fun onItemLongClick(page: Page): Boolean
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.page
|
||||
package org.kiwix.kiwixmobile.core.page.adapter
|
||||
|
||||
interface Page {
|
||||
val zimFilePath: String?
|
@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Kiwix Android
|
||||
* Copyright (c) 2020 Kiwix <android.kiwix.org>
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.kiwix.kiwixmobile.core.page.adapter
|
||||
|
||||
class PageAdapter
|
@ -20,10 +20,11 @@ import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.coreActivityComponent
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkDelegate.BookmarkItemDelegate
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarksAdapter
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarksAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.viewmodel.BookmarkState
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.viewmodel.BookmarkViewModel
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.Action
|
||||
@ -112,7 +113,7 @@ class BookmarksActivity : OnItemClickListener, BaseActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
fun render(state: BookmarkState) {
|
||||
private fun render(state: BookmarkState) {
|
||||
val filteredBookmarks = state.filteredBookmarks
|
||||
filteredBookmarks.let { bookmarksAdapter.items = it }
|
||||
toggleNoBookmarksText(filteredBookmarks)
|
||||
@ -140,10 +141,10 @@ class BookmarksActivity : OnItemClickListener, BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onItemClick(bookmark: BookmarkItem) {
|
||||
override fun onItemClick(bookmark: Page) {
|
||||
bookmarkViewModel.actions.offer(OnItemClick(bookmark))
|
||||
}
|
||||
|
||||
override fun onItemLongClick(bookmark: BookmarkItem): Boolean =
|
||||
override fun onItemLongClick(bookmark: Page): Boolean =
|
||||
bookmarkViewModel.actions.offer(OnItemLongClick(bookmark))
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ package org.kiwix.kiwixmobile.core.page.bookmark.adapter
|
||||
import android.view.ViewGroup
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.base.adapter.AbsDelegateAdapter
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarksAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.inflate
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
|
||||
sealed class BookmarkDelegate :
|
||||
AbsDelegateAdapter<BookmarkItem, BookmarkItem, BookmarkViewHolder> {
|
||||
@ -16,6 +16,7 @@ sealed class BookmarkDelegate :
|
||||
|
||||
override fun createViewHolder(parent: ViewGroup) =
|
||||
BookmarkViewHolder(
|
||||
parent.inflate(R.layout.item_bookmark_history, false), itemClickListener)
|
||||
parent.inflate(R.layout.item_bookmark_history, false), itemClickListener
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,7 @@
|
||||
package org.kiwix.kiwixmobile.core.page.bookmark.adapter
|
||||
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.BookmarkEntity
|
||||
import org.kiwix.kiwixmobile.core.page.Page
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
|
||||
data class BookmarkItem(
|
||||
|
@ -5,10 +5,10 @@ import kotlinx.android.synthetic.main.item_bookmark_history.favicon
|
||||
import kotlinx.android.synthetic.main.item_bookmark_history.title
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.base.adapter.BaseViewHolder
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarksAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.Base64String
|
||||
import org.kiwix.kiwixmobile.core.extensions.setBitmap
|
||||
import org.kiwix.kiwixmobile.core.extensions.setImageDrawableCompat
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
|
||||
class BookmarkViewHolder(
|
||||
override val containerView: View,
|
||||
|
@ -7,8 +7,4 @@ class BookmarksAdapter(
|
||||
vararg delegates: AdapterDelegate<BookmarkItem>
|
||||
) : BaseDelegateAdapter<BookmarkItem>(*delegates) {
|
||||
override fun getIdFor(item: BookmarkItem): Long = item.databaseId
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(bookmark: BookmarkItem)
|
||||
fun onItemLongClick(bookmark: BookmarkItem): Boolean
|
||||
}
|
||||
}
|
||||
|
@ -5,7 +5,6 @@ import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View.GONE
|
||||
import android.view.View.VISIBLE
|
||||
import android.widget.ImageView
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.lifecycle.Observer
|
||||
@ -22,11 +21,11 @@ import org.kiwix.kiwixmobile.core.base.BaseActivity
|
||||
import org.kiwix.kiwixmobile.core.di.components.CoreComponent
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.coreActivityComponent
|
||||
import org.kiwix.kiwixmobile.core.extensions.ActivityExtensions.viewModel
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryAdapter
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryDelegate.HistoryDateDelegate
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryDelegate.HistoryItemDelegate
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.viewmodel.HistoryState
|
||||
import org.kiwix.kiwixmobile.core.page.history.viewmodel.HistoryViewModel
|
||||
import org.kiwix.kiwixmobile.core.page.viewmodel.Action
|
||||
@ -105,7 +104,7 @@ class HistoryActivity : OnItemClickListener, BaseActivity() {
|
||||
return true
|
||||
}
|
||||
|
||||
fun render(state: HistoryState) {
|
||||
private fun render(state: HistoryState) {
|
||||
historyAdapter.items = state.historyListItems
|
||||
history_switch.isEnabled = !state.isInSelectionState
|
||||
no_history.visibility = if (state.historyListItems.isEmpty()) VISIBLE else GONE
|
||||
@ -133,10 +132,10 @@ class HistoryActivity : OnItemClickListener, BaseActivity() {
|
||||
return super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
override fun onItemClick(favicon: ImageView, history: HistoryItem) {
|
||||
override fun onItemClick(history: Page) {
|
||||
historyViewModel.actions.offer(OnItemClick(history))
|
||||
}
|
||||
|
||||
override fun onItemLongClick(favicon: ImageView, history: HistoryItem): Boolean =
|
||||
override fun onItemLongClick(history: Page): Boolean =
|
||||
historyViewModel.actions.offer(OnItemLongClick(history))
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
package org.kiwix.kiwixmobile.core.page.history.adapter
|
||||
|
||||
import android.widget.ImageView
|
||||
import org.kiwix.kiwixmobile.core.base.adapter.AdapterDelegate
|
||||
import org.kiwix.kiwixmobile.core.base.adapter.BaseDelegateAdapter
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
|
||||
class HistoryAdapter(
|
||||
vararg delegates: AdapterDelegate<HistoryListItem>
|
||||
) : BaseDelegateAdapter<HistoryListItem>(*delegates) {
|
||||
override fun getIdFor(item: HistoryListItem): Long = item.id
|
||||
interface OnItemClickListener {
|
||||
fun onItemClick(favicon: ImageView, history: HistoryItem)
|
||||
|
||||
fun onItemLongClick(favicon: ImageView, history: HistoryItem): Boolean
|
||||
}
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import android.view.ViewGroup
|
||||
import org.kiwix.kiwixmobile.core.R
|
||||
import org.kiwix.kiwixmobile.core.base.adapter.AbsDelegateAdapter
|
||||
import org.kiwix.kiwixmobile.core.extensions.ViewGroupExtensions.inflate
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItemViewHolder.HistoryItemViewHolder
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.DateItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
|
@ -18,7 +18,7 @@
|
||||
package org.kiwix.kiwixmobile.core.page.history.adapter
|
||||
|
||||
import org.kiwix.kiwixmobile.core.dao.entities.HistoryEntity
|
||||
import org.kiwix.kiwixmobile.core.page.Page
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimFileReader
|
||||
|
||||
sealed class HistoryListItem {
|
||||
|
@ -9,7 +9,7 @@ import org.kiwix.kiwixmobile.core.base.adapter.BaseViewHolder
|
||||
import org.kiwix.kiwixmobile.core.downloader.model.Base64String
|
||||
import org.kiwix.kiwixmobile.core.extensions.setBitmap
|
||||
import org.kiwix.kiwixmobile.core.extensions.setImageDrawableCompat
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryAdapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.OnItemClickListener
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.DateItem
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem.HistoryItem
|
||||
import org.threeten.bp.LocalDate
|
||||
@ -30,8 +30,8 @@ sealed class HistoryListItemViewHolder<in T : HistoryListItem>(containerView: Vi
|
||||
} else {
|
||||
favicon.setBitmap(Base64String(item.favicon))
|
||||
}
|
||||
itemView.setOnClickListener { itemClickListener.onItemClick(favicon, item) }
|
||||
itemView.setOnLongClickListener { itemClickListener.onItemLongClick(favicon, item) }
|
||||
itemView.setOnClickListener { itemClickListener.onItemClick(item) }
|
||||
itemView.setOnLongClickListener { itemClickListener.onItemLongClick(item) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
package org.kiwix.kiwixmobile.core.page.viewmodel
|
||||
|
||||
import org.kiwix.kiwixmobile.core.page.Page
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
|
||||
sealed class Action {
|
||||
object Exit : Action()
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.page.viewmodel
|
||||
|
||||
import org.kiwix.kiwixmobile.core.page.Page
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
|
||||
interface PageState {
|
||||
val pageItems: List<Page>
|
||||
|
@ -22,7 +22,7 @@ import android.app.Activity
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import org.kiwix.kiwixmobile.core.base.SideEffect
|
||||
import org.kiwix.kiwixmobile.core.page.Page
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
|
||||
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_FILE
|
||||
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_URL
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
package org.kiwix.kiwixmobile.core.page
|
||||
|
||||
import org.kiwix.kiwixmobile.core.page.adapter.Page
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.adapter.BookmarkItem
|
||||
import org.kiwix.kiwixmobile.core.page.bookmark.viewmodel.BookmarkState
|
||||
import org.kiwix.kiwixmobile.core.page.history.adapter.HistoryListItem
|
||||
|
Loading…
x
Reference in New Issue
Block a user