diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml
index 585483f3..425bd77a 100644
--- a/.idea/codeStyles/Project.xml
+++ b/.idea/codeStyles/Project.xml
@@ -18,6 +18,7 @@
+
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index 4574b689..f5782a6e 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -81,5 +81,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/app/build.gradle b/app/build.gradle
index 1486e20d..24cff645 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -134,9 +134,9 @@ dependencies {
implementation "ru.noties.markwon:core:3.1.0"
- implementation "xyz.quaver:libpupil:1.9.7-SNAPSHOT"
+ implementation "xyz.quaver:libpupil:1.9.7"
implementation "xyz.quaver:documentfilex:0.4-alpha02"
- implementation "xyz.quaver:floatingsearchview:1.1.1"
+ implementation "xyz.quaver:floatingsearchview:1.1.3-SNAPSHOT"
implementation "com.orhanobut:logger:2.2.0"
diff --git a/app/src/main/java/xyz/quaver/pupil/adapters/MirrorAdapter.kt b/app/src/main/java/xyz/quaver/pupil/adapters/MirrorAdapter.kt
index 93d72678..06dee2c4 100644
--- a/app/src/main/java/xyz/quaver/pupil/adapters/MirrorAdapter.kt
+++ b/app/src/main/java/xyz/quaver/pupil/adapters/MirrorAdapter.kt
@@ -55,7 +55,7 @@ class MirrorAdapter(context: Context) : RecyclerView.Adapter("mirrors")
.split(">")
- .reversed()
+ .asReversed()
.forEach {
if (this.contains(it)) {
this.remove(it)
diff --git a/app/src/main/java/xyz/quaver/pupil/sources/History.kt b/app/src/main/java/xyz/quaver/pupil/sources/History.kt
index c4004df6..e74bcdc8 100644
--- a/app/src/main/java/xyz/quaver/pupil/sources/History.kt
+++ b/app/src/main/java/xyz/quaver/pupil/sources/History.kt
@@ -18,15 +18,12 @@
package xyz.quaver.pupil.sources
-import android.util.Log
-import com.orhanobut.logger.Logger
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.launch
import org.kodein.di.DI
import org.kodein.di.DIAware
-import org.kodein.di.android.di
import org.kodein.di.instance
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.pupil.util.SavedSourceSet
@@ -47,9 +44,11 @@ class History(override val di: DI, source: String) : Source()
CoroutineScope(Dispatchers.IO).launch {
- histories.map[source.name]?.forEach {
+ histories[source.name]?.asReversed()?.forEach {
channel.send(source.info(it))
}
+
+ channel.close()
}
return Pair(channel, histories.map.size)
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
index 87896078..9986643b 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/MainActivity.kt
@@ -148,6 +148,7 @@ class MainActivity :
} else {
binding.contents.progressbar.hide()
if (it.isEmpty()) {
+ binding.contents.recyclerview.adapter?.notifyDataSetChanged()
binding.contents.noresult.show()
} else {
binding.contents.recyclerview.adapter?.notifyItemInserted(it.size-1)
@@ -396,7 +397,7 @@ class MainActivity :
onActionMenuItemSelected(it)
}
- onQueryChangeListener = lambda@{ _, query ->
+ onQueryChangeListener = { _, query ->
model.query.value = query
model.suggestion()
@@ -404,9 +405,7 @@ class MainActivity :
swapSuggestions(listOf(LoadingSuggestion(getText(R.string.reader_loading).toString())))
}
- onSuggestionBinding = { binding, item ->
- model.source.value!!.onSuggestionBind(binding, item)
- }
+ onSuggestionBinding = model.source.value!!::onSuggestionBind
onFocusChangeListener = object: FloatingSearchView.OnFocusChangeListener {
override fun onFocus() {
@@ -450,24 +449,13 @@ class MainActivity :
binding.drawer.closeDrawers()
when(item.itemId) {
- R.id.main_drawer_history -> {
- //model.setSourceAndReset(direct.instance(arg = source.name))
- }
- R.id.main_drawer_help -> {
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help))))
- }
- R.id.main_drawer_github -> {
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github))))
- }
- R.id.main_drawer_homepage -> {
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.home_page))))
- }
- R.id.main_drawer_email -> {
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.email))))
- }
- R.id.main_drawer_kakaotalk -> {
- startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.discord))))
- }
+ R.id.main_drawer_home -> model.setModeAndReset(MainViewModel.MainMode.SEARCH)
+ R.id.main_drawer_history -> model.setModeAndReset(MainViewModel.MainMode.HISTORY)
+ R.id.main_drawer_help -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.help))))
+ R.id.main_drawer_github -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.github))))
+ R.id.main_drawer_homepage -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.home_page))))
+ R.id.main_drawer_email -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.email))))
+ R.id.main_drawer_kakaotalk -> startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.discord))))
}
}
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt b/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt
index c4d5256a..4bd2bfc5 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/ReaderActivity.kt
@@ -141,7 +141,7 @@ class ReaderActivity : BaseActivity(), DIAware {
menu?.forEach {
when (it.itemId) {
R.id.reader_menu_favorite -> {
- if (favorites.map[source]?.contains(itemID) == true)
+ if (favorites[source]?.contains(itemID) == true)
(it.icon as Animatable).start()
}
R.id.source -> {
@@ -160,7 +160,7 @@ class ReaderActivity : BaseActivity(), DIAware {
val id = itemID
val favorite = menu?.findItem(R.id.reader_menu_favorite) ?: return true
- if (favorites.map[source]?.contains(id) == true) {
+ if (favorites[source]?.contains(id) == true) {
favorites.remove(source, id)
favorite.icon = AnimatedVectorDrawableCompat.create(this, R.drawable.avd_star)
} else {
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/view/TagChip.kt b/app/src/main/java/xyz/quaver/pupil/ui/view/TagChip.kt
index 42fcb609..d9058f14 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/view/TagChip.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/view/TagChip.kt
@@ -75,7 +75,7 @@ class TagChip(context: Context, private val source: String, _tag: Tag) : Chip(co
)
setOnCloseIconClickListener {
- if (favoriteTags.map[source]?.contains(tag.toString()) == true) {
+ if (favoriteTags[source]?.contains(tag.toString()) == true) {
favoriteTags.remove(source, tag.toString())
closeIcon = ContextCompat.getDrawable(context, R.drawable.ic_star_empty)
diff --git a/app/src/main/java/xyz/quaver/pupil/ui/viewmodel/MainViewModel.kt b/app/src/main/java/xyz/quaver/pupil/ui/viewmodel/MainViewModel.kt
index 958facfc..da4dffa9 100644
--- a/app/src/main/java/xyz/quaver/pupil/ui/viewmodel/MainViewModel.kt
+++ b/app/src/main/java/xyz/quaver/pupil/ui/viewmodel/MainViewModel.kt
@@ -25,8 +25,10 @@ import kotlinx.coroutines.*
import org.kodein.di.DIAware
import org.kodein.di.android.x.di
import org.kodein.di.direct
+import org.kodein.di.instance
import xyz.quaver.floatingsearchview.suggestions.model.SearchSuggestion
import xyz.quaver.pupil.sources.AnySource
+import xyz.quaver.pupil.sources.History
import xyz.quaver.pupil.sources.ItemInfo
import xyz.quaver.pupil.util.Preferences
import xyz.quaver.pupil.util.notify
@@ -37,7 +39,6 @@ import kotlin.random.Random
@Suppress("UNCHECKED_CAST")
class MainViewModel(app: Application) : AndroidViewModel(app), DIAware {
-
override val di by di()
private val _searchResults = MutableLiveData>()
@@ -51,6 +52,10 @@ class MainViewModel(app: Application) : AndroidViewModel(app), DIAware {
val query = MutableLiveData()
private val queryStack = mutableListOf()
+ private val defaultSourceFactory: (String) -> AnySource = {
+ direct.source(it)
+ }
+ private var sourceFactory: (String) -> AnySource = defaultSourceFactory
private val _source = MutableLiveData()
val source: LiveData = _source
@@ -82,7 +87,7 @@ class MainViewModel(app: Application) : AndroidViewModel(app), DIAware {
}
fun setSourceAndReset(sourceName: String) {
- _source.value = direct.source(sourceName).also {
+ _source.value = sourceFactory(sourceName).also {
sortMode.value = it.availableSortMode.first()
}
@@ -97,6 +102,16 @@ class MainViewModel(app: Application) : AndroidViewModel(app), DIAware {
query()
}
+ fun setModeAndReset(mode: MainMode) {
+ sourceFactory = when (mode) {
+ MainMode.SEARCH -> defaultSourceFactory
+ MainMode.HISTORY -> { { direct.instance(arg = it) } }
+ else -> return
+ }
+
+ setSourceAndReset(source.value!!.name)
+ }
+
fun query() {
val perPage = Preferences["per_page", "25"].toInt()
val source = _source.value ?: error("Source is null")
@@ -181,4 +196,11 @@ class MainViewModel(app: Application) : AndroidViewModel(app), DIAware {
return true
}
+ enum class MainMode {
+ SEARCH,
+ HISTORY,
+ DOWNLOADS,
+ FAVORITES
+ }
+
}
\ No newline at end of file
diff --git a/app/src/main/java/xyz/quaver/pupil/util/SavedCollections.kt b/app/src/main/java/xyz/quaver/pupil/util/SavedCollections.kt
index 37131e4a..50bd9c6d 100644
--- a/app/src/main/java/xyz/quaver/pupil/util/SavedCollections.kt
+++ b/app/src/main/java/xyz/quaver/pupil/util/SavedCollections.kt
@@ -21,81 +21,14 @@ package xyz.quaver.pupil.util
import androidx.annotation.RequiresApi
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
+import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.builtins.MapSerializer
-import kotlinx.serialization.builtins.SetSerializer
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.Json.Default.decodeFromString
import kotlinx.serialization.serializer
import java.io.File
-class SavedSet (private val file: File, any: T, private val set: MutableSet = mutableSetOf()) : MutableSet by set {
-
- @Suppress("UNCHECKED_CAST")
- @OptIn(ExperimentalSerializationApi::class)
- val serializer: KSerializer> = SetSerializer(serializer(any::class.java) as KSerializer)
-
- init {
- if (!file.exists()) {
- save()
- }
- load()
- }
-
- @Synchronized
- fun load() {
- set.clear()
- kotlin.runCatching {
- decodeFromString(serializer, file.readText())
- }.onSuccess {
- set.addAll(it)
- }
- }
-
- @Synchronized
- fun save() {
- file.parentFile?.mkdirs()
- if (!file.exists())
- file.createNewFile()
-
- file.writeText(Json.encodeToString(serializer, set))
- }
-
- @Synchronized
- override fun add(element: T): Boolean {
- set.remove(element)
-
- return set.add(element).also {
- save()
- }
- }
-
- @Synchronized
- override fun addAll(elements: Collection): Boolean {
- set.removeAll(elements)
-
- return set.addAll(elements).also {
- save()
- }
- }
-
- @Synchronized
- override fun remove(element: T): Boolean {
- load()
-
- return set.remove(element).also {
- save()
- }
- }
-
- @Synchronized
- override fun clear() {
- set.clear()
- save()
- }
-
-}
-
class SavedMap (private val file: File, anyKey: K, anyValue: V, private val map: MutableMap = mutableMapOf()) : MutableMap by map {
@Suppress("UNCHECKED_CAST")
@@ -172,11 +105,10 @@ class SavedMap (private val file: File, anyKey: K, anyValue: V,
}
class SavedSourceSet(private val file: File) {
+ private val _map = mutableMapOf>()
+ val map: Map> = _map
- private val _map = mutableMapOf>()
- val map: Map> = _map
-
- private val serializer = MapSerializer(String.serializer(), SetSerializer(String.serializer()))
+ private val serializer = MapSerializer(String.serializer(), ListSerializer(String.serializer()))
@Synchronized
fun load() {
@@ -185,7 +117,7 @@ class SavedSourceSet(private val file: File) {
decodeFromString(serializer, file.readText())
}.onSuccess {
it.forEach { (k, v) ->
- _map[k] = v.toMutableSet()
+ _map[k] = v.toMutableList()
}
}
}
@@ -199,6 +131,8 @@ class SavedSourceSet(private val file: File) {
file.writeText(Json.encodeToString(serializer, _map))
}
+ operator fun get(key: String) = _map[key]
+
@Synchronized
fun add(source: String, value: String) {
load()
@@ -206,7 +140,7 @@ class SavedSourceSet(private val file: File) {
_map[source]?.remove(value)
if (!_map.containsKey(source))
- _map[source] = mutableSetOf()
+ _map[source] = mutableListOf()
else
_map[source]!!.add(value)
@@ -222,7 +156,7 @@ class SavedSourceSet(private val file: File) {
_map[source]!!.removeAll(from[source]!!)
_map[source]!!.addAll(from[source]!!)
} else {
- _map[source] = from[source]!!.toMutableSet()
+ _map[source] = from[source]!!.toMutableList()
}
}
diff --git a/app/src/main/res/drawable/clock_end.xml b/app/src/main/res/drawable/clock_end.xml
index 8f636ac6..4d205a72 100644
--- a/app/src/main/res/drawable/clock_end.xml
+++ b/app/src/main/res/drawable/clock_end.xml
@@ -1,3 +1,21 @@
+
+
diff --git a/app/src/main/res/drawable/clock_start.xml b/app/src/main/res/drawable/clock_start.xml
index f131c300..c9d24b92 100644
--- a/app/src/main/res/drawable/clock_start.xml
+++ b/app/src/main/res/drawable/clock_start.xml
@@ -1,3 +1,21 @@
+
+
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 85bb0c21..1e2fd1df 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -19,24 +19,4 @@
- SOCKS
-
- - 0
- - 1
- - 2
- - 4
- - 8
- - 16
- - 32
-
-
-
- - @string/settings_cache_unlimited
- - 1G
- - 2G
- - 4G
- - 8G
- - 16G
- - 32G
-
-
\ No newline at end of file
diff --git a/build.gradle b/build.gradle
index a8a3c669..07ba2d73 100644
--- a/build.gradle
+++ b/build.gradle
@@ -13,7 +13,7 @@ buildscript {
classpath "com.google.gms:google-services:4.3.5"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
- classpath "com.google.firebase:firebase-crashlytics-gradle:2.4.1"
+ classpath "com.google.firebase:firebase-crashlytics-gradle:2.5.0"
classpath "com.google.firebase:perf-plugin:1.3.4"
classpath "com.google.android.gms:oss-licenses-plugin:0.10.2"
}