mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Used SimpleTextListener
This commit is contained in:
parent
e37c0dd0cd
commit
e4a5f2eab3
@ -47,6 +47,7 @@ import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_FILE
|
|||||||
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_TITLE
|
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_TITLE
|
||||||
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_URL
|
import org.kiwix.kiwixmobile.core.utils.EXTRA_CHOSE_X_URL
|
||||||
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
import org.kiwix.kiwixmobile.core.utils.KiwixDialog
|
||||||
|
import org.kiwix.kiwixmobile.core.utils.SimpleTextListener
|
||||||
import java.util.ArrayList
|
import java.util.ArrayList
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
@ -66,28 +67,19 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
@Inject
|
@Inject
|
||||||
lateinit var dialogShower: DialogShower
|
lateinit var dialogShower: DialogShower
|
||||||
private var refreshAdapter = true
|
private var refreshAdapter = true
|
||||||
private var bookmarksAdapter: BookmarksAdapter? = null
|
private lateinit var bookmarksAdapter: BookmarksAdapter
|
||||||
private var actionMode: ActionMode? = null
|
private var actionMode: ActionMode? = null
|
||||||
private val actionModeCallback: ActionMode.Callback =
|
private val actionModeCallback: ActionMode.Callback =
|
||||||
object : ActionMode.Callback {
|
object : ActionMode.Callback {
|
||||||
override fun onCreateActionMode(
|
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||||
mode: ActionMode,
|
|
||||||
menu: Menu
|
|
||||||
): Boolean {
|
|
||||||
mode.menuInflater.inflate(R.menu.menu_context_delete, menu)
|
mode.menuInflater.inflate(R.menu.menu_context_delete, menu)
|
||||||
bookmarks_switch.isEnabled = false
|
bookmarks_switch.isEnabled = false
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPrepareActionMode(
|
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean = false
|
||||||
mode: ActionMode,
|
|
||||||
menu: Menu
|
|
||||||
): Boolean = false
|
|
||||||
|
|
||||||
override fun onActionItemClicked(
|
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||||
mode: ActionMode,
|
|
||||||
item: MenuItem
|
|
||||||
): Boolean {
|
|
||||||
refreshAdapter = false
|
refreshAdapter = false
|
||||||
if (item.itemId == R.id.menu_context_delete) {
|
if (item.itemId == R.id.menu_context_delete) {
|
||||||
dialogShower.show(KiwixDialog.DeleteBookmarks, {
|
dialogShower.show(KiwixDialog.DeleteBookmarks, {
|
||||||
@ -95,8 +87,8 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
for (bookmark in deleteList) {
|
for (bookmark in deleteList) {
|
||||||
val position = bookmarksList.indexOf(bookmark)
|
val position = bookmarksList.indexOf(bookmark)
|
||||||
bookmarksList.remove(bookmark)
|
bookmarksList.remove(bookmark)
|
||||||
bookmarksAdapter!!.notifyItemRemoved(position)
|
bookmarksAdapter.notifyItemRemoved(position)
|
||||||
bookmarksAdapter!!.notifyItemRangeChanged(position, bookmarksAdapter!!.itemCount)
|
bookmarksAdapter.notifyItemRangeChanged(position, bookmarksAdapter.itemCount)
|
||||||
}
|
}
|
||||||
presenter.deleteBookmarks(ArrayList(deleteList))
|
presenter.deleteBookmarks(ArrayList(deleteList))
|
||||||
mode.finish()
|
mode.finish()
|
||||||
@ -112,7 +104,7 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
actionMode = null
|
actionMode = null
|
||||||
if (refreshAdapter) {
|
if (refreshAdapter) {
|
||||||
bookmarksAdapter!!.notifyDataSetChanged()
|
bookmarksAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
bookmarks_switch!!.isEnabled = true
|
bookmarks_switch!!.isEnabled = true
|
||||||
}
|
}
|
||||||
@ -143,7 +135,7 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
|
|
||||||
private fun setupBookmarksAdapter() {
|
private fun setupBookmarksAdapter() {
|
||||||
bookmarksAdapter = BookmarksAdapter(bookmarksList, deleteList, this)
|
bookmarksAdapter = BookmarksAdapter(bookmarksList, deleteList, this)
|
||||||
bookmarksAdapter!!.registerAdapterDataObserver(object : AdapterDataObserver() {
|
bookmarksAdapter.registerAdapterDataObserver(object : AdapterDataObserver() {
|
||||||
override fun onChanged() {
|
override fun onChanged() {
|
||||||
super.onChanged()
|
super.onChanged()
|
||||||
no_bookmarks.visibility = if (bookmarksList.size == 0) View.VISIBLE else View.GONE
|
no_bookmarks.visibility = if (bookmarksList.size == 0) View.VISIBLE else View.GONE
|
||||||
@ -161,20 +153,13 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
val search = menu.findItem(R.id.menu_bookmarks_search)
|
val search = menu.findItem(R.id.menu_bookmarks_search)
|
||||||
.actionView as SearchView
|
.actionView as SearchView
|
||||||
search.queryHint = getString(R.string.search_bookmarks)
|
search.queryHint = getString(R.string.search_bookmarks)
|
||||||
search.setOnQueryTextListener(object :
|
search.setOnQueryTextListener(SimpleTextListener {
|
||||||
SearchView.OnQueryTextListener {
|
bookmarksList.clear()
|
||||||
override fun onQueryTextSubmit(query: String): Boolean = false
|
bookmarksList.addAll(allBookmarks)
|
||||||
|
if ("" == it) {
|
||||||
override fun onQueryTextChange(newText: String): Boolean {
|
bookmarksAdapter.notifyDataSetChanged()
|
||||||
bookmarksList.clear()
|
|
||||||
bookmarksList.addAll(allBookmarks)
|
|
||||||
if ("" == newText) {
|
|
||||||
bookmarksAdapter!!.notifyDataSetChanged()
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
presenter.filterBookmarks(bookmarksList, newText)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
presenter.filterBookmarks(bookmarksList, it)
|
||||||
})
|
})
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -189,7 +174,7 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
presenter.deleteBookmarks(ArrayList(allBookmarks))
|
presenter.deleteBookmarks(ArrayList(allBookmarks))
|
||||||
allBookmarks.clear()
|
allBookmarks.clear()
|
||||||
bookmarksList.clear()
|
bookmarksList.clear()
|
||||||
bookmarksAdapter!!.notifyDataSetChanged()
|
bookmarksAdapter.notifyDataSetChanged()
|
||||||
no_bookmarks.snack(R.string.all_bookmarks_cleared)
|
no_bookmarks.snack(R.string.all_bookmarks_cleared)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -212,13 +197,10 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
override fun notifyBookmarksListFiltered(bookmarksList: List<BookmarkItem>) {
|
override fun notifyBookmarksListFiltered(bookmarksList: List<BookmarkItem>) {
|
||||||
this.bookmarksList.clear()
|
this.bookmarksList.clear()
|
||||||
this.bookmarksList.addAll(bookmarksList)
|
this.bookmarksList.addAll(bookmarksList)
|
||||||
bookmarksAdapter!!.notifyDataSetChanged()
|
bookmarksAdapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemClick(
|
override fun onItemClick(favicon: ImageView, bookmark: BookmarkItem) {
|
||||||
favicon: ImageView,
|
|
||||||
bookmark: BookmarkItem
|
|
||||||
) {
|
|
||||||
if (actionMode == null) {
|
if (actionMode == null) {
|
||||||
val intent = internal(
|
val intent = internal(
|
||||||
CoreMainActivity::class.java
|
CoreMainActivity::class.java
|
||||||
@ -240,10 +222,7 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onItemLongClick(
|
override fun onItemLongClick(favicon: ImageView, bookmark: BookmarkItem): Boolean {
|
||||||
favicon: ImageView,
|
|
||||||
bookmark: BookmarkItem
|
|
||||||
): Boolean {
|
|
||||||
if (actionMode != null) {
|
if (actionMode != null) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
@ -253,10 +232,7 @@ class BookmarksActivity : BaseActivity(),
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun toggleSelection(
|
private fun toggleSelection(favicon: ImageView, bookmark: BookmarkItem) {
|
||||||
favicon: ImageView,
|
|
||||||
bookmark: BookmarkItem
|
|
||||||
) {
|
|
||||||
if (deleteList.remove(bookmark)) {
|
if (deleteList.remove(bookmark)) {
|
||||||
favicon.setBitmap(Base64String(bookmark.favicon))
|
favicon.setBitmap(Base64String(bookmark.favicon))
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,8 +21,8 @@ import org.kiwix.kiwixmobile.core.base.BaseContract
|
|||||||
|
|
||||||
interface BookmarksContract {
|
interface BookmarksContract {
|
||||||
interface View : BaseContract.View<Presenter> {
|
interface View : BaseContract.View<Presenter> {
|
||||||
fun updateBookmarksList(bookmarksList: List<BookmarkItem>)
|
fun updateBookmarksList(bookmarks: List<BookmarkItem>)
|
||||||
fun notifyBookmarksListFiltered(bookmarksList: List<BookmarkItem>)
|
fun notifyBookmarksListFiltered(bookmarks: List<BookmarkItem>)
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Presenter : BaseContract.Presenter<View> {
|
interface Presenter : BaseContract.Presenter<View> {
|
||||||
|
@ -60,8 +60,8 @@ class BookmarksPresenter extends BasePresenter<BookmarksContract.View>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(List<BookmarkItem> bookmarksList) {
|
public void onSuccess(List<BookmarkItem> bookmarks) {
|
||||||
view.updateBookmarksList(bookmarksList);
|
view.updateBookmarksList(bookmarks);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user