Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup #3118

Merged
merged 6 commits into from
Sep 26, 2023
Merged

cleanup #3118

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions app/src/main/res/values/strings_account.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<resources xmlns:tools="http://schemas.android.com/tools">
<string name="menu_profile">Activity</string>
<string name="account_joined">Joined %1$s</string>

Expand All @@ -14,27 +14,27 @@
<eat-comment />
<string name="profile_tab_activity">Activity</string>
<string name="account_activity_header">Your activity</string>
<plurals name="account_activity_tool_opens">
<plurals name="account_activity_tool_opens" tools:ignore="ImpliedQuantity">
<item quantity="one">Tool open</item>
<item quantity="other">Tool opens</item>
</plurals>
<plurals name="account_activity_lesson_completions">
<plurals name="account_activity_lesson_completions" tools:ignore="ImpliedQuantity">
<item quantity="one">Lesson completion</item>
<item quantity="other">Lesson completions</item>
</plurals>
<plurals name="account_activity_screen_shares">
<plurals name="account_activity_screen_shares" tools:ignore="ImpliedQuantity">
<item quantity="one">Screen share</item>
<item quantity="other">Screen shares</item>
</plurals>
<plurals name="account_activity_links_shared">
<plurals name="account_activity_links_shared" tools:ignore="ImpliedQuantity">
<item quantity="one">Link shared</item>
<item quantity="other">Links shared</item>
</plurals>
<plurals name="account_activity_languages_used">
<plurals name="account_activity_languages_used" tools:ignore="ImpliedQuantity">
<item quantity="one">Language used</item>
<item quantity="other">Languages used</item>
</plurals>
<plurals name="account_activity_sessions">
<plurals name="account_activity_sessions" tools:ignore="ImpliedQuantity">
<item quantity="one">Session</item>
<item quantity="other">Sessions</item>
</plurals>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ object ApiModule {
): Retrofit = Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(LocaleConverterFactory)
.addConverterFactory(JsonApiConverterFactory.create(jsonApiConverter))
.addConverterFactory(JsonApiConverterFactory(jsonApiConverter))
.callFactory(okhttp)
.build()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class TasksTest {
@Test
fun `initFavoriteTools()`() = runTest {
val tools = Array(5) { Tool("${it + 1}") }
val translations = listOf("1", "5").map { Translation(it) }
val translations = listOf("1", "5").map { Translation(toolCode = it) }
coEvery { toolsRepository.getTools() } returns tools.toList()
coEvery { translationsRepository.getTranslationsForLanguages(any()) } returns translations
every { jsonApiConverter.fromJson(any(), Tool::class.java) } returns JsonApiObject.of(*tools)
Expand All @@ -100,9 +100,4 @@ class TasksTest {
confirmVerified(toolsRepository)
}
// endregion initFavoriteTools()

private fun Tool(tool: String) = Tool().apply { code = tool }
private fun Translation(tool: String) = Translation().apply {
toolCode = tool
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ private const val SYNC_PARALLELISM = 8
@Singleton
class GodToolsSyncService @VisibleForTesting internal constructor(
workManager: Lazy<WorkManager>,
private val syncTasks: Map<Class<out BaseSyncTasks>, @JvmSuppressWildcards Provider<BaseSyncTasks>>,
private val syncTasks: Map<Class<out BaseSyncTasks>, Provider<BaseSyncTasks>>,
private val coroutineDispatcher: CoroutineDispatcher,
private val coroutineScope: CoroutineScope = CoroutineScope(coroutineDispatcher + SupervisorJob()),
) {
Expand All @@ -49,7 +49,6 @@ class GodToolsSyncService @VisibleForTesting internal constructor(

private val workManager by workManager

private inline fun <reified T : BaseSyncTasks> with(block: T.() -> Unit) = with<T, Unit>(block)
private inline fun <reified T : BaseSyncTasks, R : Any?> with(block: T.() -> R) =
requireNotNull(syncTasks[T::class.java]?.get() as? T) { "${T::class.simpleName} not injected" }.block()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
package org.cru.godtools.sync.task

import android.content.ContentResolver
import android.os.Bundle
import androidx.annotation.RestrictTo
import androidx.annotation.WorkerThread
import androidx.collection.LongSparseArray
import org.cru.godtools.model.Base

@WorkerThread
@RestrictTo(RestrictTo.Scope.LIBRARY)
abstract class BaseSyncTasks internal constructor() {
companion object {
fun isForced(extras: Bundle) = extras.getBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, false)

fun <E : Base> index(items: Collection<E>) = LongSparseArray<E>().apply {
for (item in items) put(item.id, item)
}
}
}
abstract class BaseSyncTasks internal constructor()