Merge pull request 'enhancement/too-many-calls' (#68) from enhancement/too-many-calls into master
Reviewed-on: https://gitea.amine-louveau.fr/Louvorg/ReaderForSelfoss-multiplatform/pulls/68
This commit is contained in:
commit
d81fb79b4f
@ -143,13 +143,13 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener, DIAwar
|
|||||||
|
|
||||||
handleSwipeRefreshLayout()
|
handleSwipeRefreshLayout()
|
||||||
|
|
||||||
getElementsAccordingToTab()
|
|
||||||
|
|
||||||
|
|
||||||
|
if (appSettingsService.isItemCachingEnabled()) {
|
||||||
CoroutineScope(Dispatchers.Main).launch {
|
CoroutineScope(Dispatchers.Main).launch {
|
||||||
repository.tryToCacheItemsAndGetNewOnes()
|
repository.tryToCacheItemsAndGetNewOnes()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun handleSwipeRefreshLayout() {
|
private fun handleSwipeRefreshLayout() {
|
||||||
binding.swipeRefreshLayout.setColorSchemeResources(
|
binding.swipeRefreshLayout.setColorSchemeResources(
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:theme="@style/ToolBarStyle"
|
android:theme="@style/ToolBarStyle"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme" />
|
app:popupTheme="?attr/toolbarPopupTheme" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
android:id="@+id/toolBar"
|
android:id="@+id/toolBar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:theme="@style/ToolBarStyle"
|
android:theme="@style/ToolBarStyle"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme" />
|
app:popupTheme="?attr/toolbarPopupTheme" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme"
|
app:popupTheme="?attr/toolbarPopupTheme"
|
||||||
app:theme="@style/ToolBarStyle" />
|
android:theme="@style/ToolBarStyle" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:theme="@style/ToolBarStyle"
|
android:theme="@style/ToolBarStyle"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme" />
|
app:popupTheme="?attr/toolbarPopupTheme" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme"
|
app:popupTheme="?attr/toolbarPopupTheme"
|
||||||
app:theme="@style/ToolBarStyle" />
|
android:theme="@style/ToolBarStyle" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
android:id="@+id/toolbar"
|
android:id="@+id/toolbar"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="?attr/actionBarSize"
|
android:layout_height="?attr/actionBarSize"
|
||||||
app:theme="@style/ToolBarStyle"
|
android:theme="@style/ToolBarStyle"
|
||||||
app:popupTheme="?attr/toolbarPopupTheme" />
|
app:popupTheme="?attr/toolbarPopupTheme" />
|
||||||
|
|
||||||
</com.google.android.material.appbar.AppBarLayout>
|
</com.google.android.material.appbar.AppBarLayout>
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="200"
|
android:defaultValue="20"
|
||||||
android:inputType="number"
|
android:inputType="number"
|
||||||
android:key="prefer_api_items_number"
|
android:key="prefer_api_items_number"
|
||||||
android:selectAllOnFocus="true"
|
android:selectAllOnFocus="true"
|
||||||
|
@ -28,12 +28,12 @@ kotlin {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
val commonMain by getting {
|
val commonMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.ktor:ktor-client-core:2.0.1")
|
implementation("io.ktor:ktor-client-core:2.1.1")
|
||||||
implementation("io.ktor:ktor-client-content-negotiation:2.0.1")
|
implementation("io.ktor:ktor-client-content-negotiation:2.1.1")
|
||||||
implementation("io.ktor:ktor-serialization-kotlinx-json:2.0.1")
|
implementation("io.ktor:ktor-serialization-kotlinx-json:2.1.1")
|
||||||
implementation("io.ktor:ktor-client-logging:2.0.1")
|
implementation("io.ktor:ktor-client-logging:2.1.1")
|
||||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0")
|
||||||
implementation("io.ktor:ktor-client-auth:2.0.1")
|
implementation("io.ktor:ktor-client-auth:2.1.1")
|
||||||
implementation("org.jsoup:jsoup:1.14.3")
|
implementation("org.jsoup:jsoup:1.14.3")
|
||||||
|
|
||||||
//Dependency Injection
|
//Dependency Injection
|
||||||
@ -60,7 +60,7 @@ kotlin {
|
|||||||
}
|
}
|
||||||
val androidMain by getting {
|
val androidMain by getting {
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.ktor:ktor-client-android:2.0.1")
|
implementation("io.ktor:ktor-client-okhttp:2.1.1")
|
||||||
|
|
||||||
// Sql
|
// Sql
|
||||||
implementation(SqlDelight.android)
|
implementation(SqlDelight.android)
|
||||||
@ -94,7 +94,7 @@ kotlin {
|
|||||||
iosX64Test.dependsOn(this)
|
iosX64Test.dependsOn(this)
|
||||||
iosArm64Test.dependsOn(this)
|
iosArm64Test.dependsOn(this)
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("io.ktor:ktor-client-ios:2.0.1")
|
implementation("io.ktor:ktor-client-ios:2.1.1")
|
||||||
}
|
}
|
||||||
//iosSimulatorArm64Test.dependsOn(this)
|
//iosSimulatorArm64Test.dependsOn(this)
|
||||||
}
|
}
|
||||||
|
@ -48,6 +48,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
suspend fun getNewerItems(): ArrayList<SelfossModel.Item> {
|
||||||
// TODO: Use the updatedSince parameter
|
// TODO: Use the updatedSince parameter
|
||||||
var fetchedItems: SelfossModel.StatusAndData<List<SelfossModel.Item>> = SelfossModel.StatusAndData.error()
|
var fetchedItems: SelfossModel.StatusAndData<List<SelfossModel.Item>> = SelfossModel.StatusAndData.error()
|
||||||
|
var fromDB = false
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
fetchedItems = api.getItems(
|
fetchedItems = api.getItems(
|
||||||
displayedItems.type,
|
displayedItems.type,
|
||||||
@ -59,6 +60,7 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
if (appSettingsService.isItemCachingEnabled()) {
|
if (appSettingsService.isItemCachingEnabled()) {
|
||||||
|
fromDB = true
|
||||||
fetchedItems = SelfossModel.StatusAndData.succes(
|
fetchedItems = SelfossModel.StatusAndData.succes(
|
||||||
getDBItems().filter {
|
getDBItems().filter {
|
||||||
displayedItems == ItemType.ALL ||
|
displayedItems == ItemType.ALL ||
|
||||||
@ -71,7 +73,9 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
if (fetchedItems.success && fetchedItems.data != null) {
|
if (fetchedItems.success && fetchedItems.data != null) {
|
||||||
items = ArrayList(fetchedItems.data!!)
|
items = ArrayList(fetchedItems.data!!)
|
||||||
sortItems()
|
if (fromDB) {
|
||||||
|
items.sortByDescending { dateUtils.parseDate(it.datetime) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
@ -92,7 +96,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
|
|
||||||
if (fetchedItems.success && fetchedItems.data != null) {
|
if (fetchedItems.success && fetchedItems.data != null) {
|
||||||
items.addAll(fetchedItems.data!!)
|
items.addAll(fetchedItems.data!!)
|
||||||
sortItems()
|
|
||||||
}
|
}
|
||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
@ -118,10 +121,6 @@ class Repository(private val api: SelfossApi, private val appSettingsService: Ap
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sortItems() {
|
|
||||||
items.sortByDescending { dateUtils.parseDate(it.datetime) }
|
|
||||||
}
|
|
||||||
|
|
||||||
suspend fun reloadBadges(): Boolean {
|
suspend fun reloadBadges(): Boolean {
|
||||||
var success = false
|
var success = false
|
||||||
if (isNetworkAvailable()) {
|
if (isNetworkAvailable()) {
|
||||||
|
@ -88,7 +88,7 @@ class AppSettingsService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun refreshItemsNumber() {
|
fun refreshItemsNumber() {
|
||||||
_itemsNumber = settings.getString("prefer_api_items_number", "200").toInt()
|
_itemsNumber = settings.getString("prefer_api_items_number", "20").toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getApiTimeout(): Long {
|
fun getApiTimeout(): Long {
|
||||||
|
Loading…
Reference in New Issue
Block a user