Skip to content

Instantly share code, notes, and snippets.

View BenHenning's full-sized avatar

Ben Henning BenHenning

  • 16:43 (UTC -07:00)
View GitHub Profile
fun <A: Activity, R> ActivityScenario<T>.letInActivity(callback: (A) -> R): R {
data class NullWrapper<T>(val value: T)
lateinit var result: NullWrapper<R>
onActivity { activity -> result = NullWrapper(callback(activity)) }
return result.value
}
package org.oppia.domain.oppialogger.analytics
import android.content.Context
import androidx.lifecycle.LiveData
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.launch
import org.oppia.app.model.EventLog
import org.oppia.app.model.EventLog.EventAction
import org.oppia.app.model.EventLog.Priority
package org.oppia.app.testing
import android.content.Context
import android.content.res.Configuration
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.intent.Intents
// Based on structure in https://gist.github.com/BenHenning/0e3a3c4a798dbe4ffb884144e2b7e592.
private const val CACHE_NAME = "topic_progress_database"
private const val CHAPTER_PROGRESS_ID = "ChapterProgressDataProvider"
class StoryProgressController @Inject constructor(private val persistentCacheStoreFactory: PersistentCacheStore.Factory, private val dataProviders: DataProviders) {
private val cacheStoreMap = mutableMapOf<ProfileId, PersistentCacheStore<TopicProgressDatabase>>()
fun lookUpChapterProgress(val topicId, val storyId, val explorationId, profileId: ProfileId): DataProvider<ChapterPlayState> {
return dataProviders.transform(retrieveCacheStore(profileId), CHAPTER_PROGRESS_ID) { database ->
message TopicProgressDatabase {
// Map from topic ID to TopicProgress.
map<string, TopicProgress> topic_progress = 1;
}
message TopicProgress {
// Map from story ID to StoryProgress.
map<string, StoryProgress> story_progress = 1;
}
* What went wrong:
Execution failed for task ':app:checkDebugAndroidTestDuplicateClasses'.
> 1 exception was raised by workers:
java.lang.RuntimeException: java.lang.RuntimeException: Duplicate class org.apache.maven.artifact.Artifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.ArtifactStatus found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.ArtifactUtils found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1)
Duplicate class org.apache.maven.artifact.DefaultArtifact found in modules maven-ant-tasks-2.1.3.jar (org.apache.maven:maven-ant-tasks:2.1.3) and maven-artifact-2.2.1.jar (org.apache.maven:maven-artifact:2.2.1
var errorText: ObservableField("")
fun onSubmitClicked() {
val answerErrorStr = getPendingAnswerError()
if (answerErrorStr != null) {
errorText.set(answerErrorStr)
} else {
// No error--submit like normal.
}
}
fun <V> storeDataWithCustomChannelAsync(updateInMemoryCache: Boolean = true, update: (T) -> T, V): Deferred<V> {
return cache.updateIfPresentAsync { cachedPayload ->
// Although it's odd to notify before the change is made, the single threaded nature of the blocking cache ensures
// nothing can read from it until this update completes.
asyncDataSubscriptionManager.notifyChange(providerId)
val updatedPayload, channelValue = storeFileCache(cachedPayload, update)
if (updateInMemoryCache) (updatedPayload, channelValue) else (cachedPayload, channelValue)
}
}
interface ImageLoader {
fun load(imageUrl: String, target: CustomTarget<Bitmap>)
}
class GlideImageLoader @Inject constructor(...): ImageLoader {
override fun load(...) {
..
}
}
@Inject lateinit var seedProvider: SeedProvider
@Test
fun testSomething() {
// Set the random seed after injection, but before the seed is provided (may require changes in the underlying controller, see note below).
seedProvider.seed = 1234L
}
@Singleton
inner class SeedProvider @Inject constructor() {