This commit is contained in:
Frans-Lukas 2020-05-26 09:57:55 +02:00
parent f9cfda759b
commit e304aabcab
5 changed files with 6 additions and 18 deletions

View File

@ -30,6 +30,7 @@ import org.kiwix.kiwixmobile.core.dao.NewLanguagesDao
import org.kiwix.kiwixmobile.core.dao.NewRecentSearchDao
import org.kiwix.kiwixmobile.core.di.qualifiers.IO
import org.kiwix.kiwixmobile.core.di.qualifiers.MainThread
import org.kiwix.kiwixmobile.core.extensions.HeaderizableList
import org.kiwix.kiwixmobile.core.extensions.foldOverAddingHeaders
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.DateItem
@ -67,7 +68,7 @@ class Repository @Inject internal constructor(
override fun booksOnDiskAsListItems(): Flowable<List<BooksOnDiskListItem>> = bookDao.books()
.map { it.sortedBy { bookOnDisk -> bookOnDisk.book.language + bookOnDisk.book.title } }
.map {
it.foldOverAddingHeaders(
(it as HeaderizableList).foldOverAddingHeaders(
{ bookOnDisk -> LanguageItem(bookOnDisk.locale) },
{ current, next -> current.locale.displayName != next.locale.displayName })
}
@ -93,7 +94,7 @@ class Repository @Inject internal constructor(
)
)
.map {
it.foldOverAddingHeaders(
(it as HeaderizableList).foldOverAddingHeaders(
{ historyItem -> DateItem(historyItem.dateString) },
{ current, next -> current.dateString != next.dateString })
}

View File

@ -1,6 +1,5 @@
package org.kiwix.kiwixmobile.core.extensions
typealias HeaderizableList<T> = List<T>
fun <SUPERTYPE, ITEM : SUPERTYPE, HEADER : SUPERTYPE> HeaderizableList<ITEM>.foldOverAddingHeaders(
@ -20,4 +19,3 @@ fun <SUPERTYPE, ITEM : SUPERTYPE, HEADER : SUPERTYPE> HeaderizableList<ITEM>.fol
}
acc
})

View File

@ -14,6 +14,7 @@ import io.reactivex.processors.BehaviorProcessor
import io.reactivex.processors.PublishProcessor
import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.HistoryDao
import org.kiwix.kiwixmobile.core.extensions.HeaderizableList
import org.kiwix.kiwixmobile.core.extensions.foldOverAddingHeaders
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.DateItem
@ -34,9 +35,6 @@ import org.kiwix.kiwixmobile.core.history.viewmodel.State.SelectionResults
import org.kiwix.kiwixmobile.core.history.viewmodel.effects.OpenDialogToRequestDeletionOfSelectedHistoryItems
import org.kiwix.kiwixmobile.core.reader.ZimReaderContainer
import org.kiwix.kiwixmobile.core.search.viewmodel.effects.Finish
import org.kiwix.kiwixmobile.core.utils.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory
import org.kiwix.kiwixmobile.core.utils.SharedPreferenceUtil
import javax.inject.Inject
@ -103,13 +101,13 @@ class HistoryViewModel @Inject constructor(
private fun searchResults(
searchString: String,
showAllToggle: Boolean,
historyList: List<HistoryListItem>
historyList: HeaderizableList<HistoryListItem>
): List<HistoryListItem> = (historyList
.filterIsInstance<HistoryItem>()
.filter { h ->
h.historyTitle.contains(searchString, true) &&
(h.zimName == zimReaderContainer.name || showAllToggle)
} as List<HistoryListItem>).foldOverAddingHeaders(
} as HeaderizableList<HistoryListItem>).foldOverAddingHeaders(
{ historyItem -> DateItem((historyItem as HistoryItem).dateString) },
{ current, next -> (current as HistoryItem).dateString != (next as HistoryItem).dateString }
)

View File

@ -17,17 +17,12 @@
*/
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import io.reactivex.processors.PublishProcessor
import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.HistoryDao
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.HistoryItem
import org.kiwix.kiwixmobile.core.history.viewmodel.Action
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.DeleteHistoryItems
import org.kiwix.kiwixmobile.core.history.viewmodel.State
import org.kiwix.kiwixmobile.core.utils.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteAllHistory
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory
data class OpenDialogToRequestDeletionOfAllHistoryItems(
private val dialogShower: DialogShower,

View File

@ -19,14 +19,10 @@ package org.kiwix.kiwixmobile.core.history.viewmodel.effects
*/
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.MutableLiveData
import io.reactivex.processors.PublishProcessor
import org.kiwix.kiwixmobile.core.base.SideEffect
import org.kiwix.kiwixmobile.core.dao.HistoryDao
import org.kiwix.kiwixmobile.core.history.adapter.HistoryListItem.HistoryItem
import org.kiwix.kiwixmobile.core.history.viewmodel.Action
import org.kiwix.kiwixmobile.core.history.viewmodel.Action.DeleteHistoryItems
import org.kiwix.kiwixmobile.core.history.viewmodel.State
import org.kiwix.kiwixmobile.core.utils.DialogShower
import org.kiwix.kiwixmobile.core.utils.KiwixDialog.DeleteSelectedHistory