Skip to content

Commit

Permalink
Add an experimental integration with Flows
Browse files Browse the repository at this point in the history
Currently the only Flow will emit the status of the load along with the current placeholder or resource, clearing the request when the Flow ends. In future versions we might consider making clearing the target optional so that resources could be used after the flow is over. We could also expose some additional helper functions to make it easier to work with the first run of a flow, or to exclude placeholders. For now this seems like a reasonable starting point.
  • Loading branch information
sjudd committed Aug 16, 2022
1 parent 24e4b0f commit 7d9e1a3
Show file tree
Hide file tree
Showing 11 changed files with 883 additions and 5 deletions.
7 changes: 5 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,16 @@ ANDROID_X_TEST_CORE_VERSION=1.4.0
ANDROID_X_TEST_JUNIT_VERSION=1.1.3
ANDROID_X_TEST_RULES_VERSION=1.4.0
ANDROID_X_TEST_RUNNER_VERSION=1.4.0
ANDROID_X_TEST_CORE_KTX_VERSION=1.4.0
ANDROID_X_TEST_JUNIT_KTX_VERSION=1.1.3
ANDROID_X_TRACING_VERSION=1.0.0
ANDROID_X_VECTOR_DRAWABLE_ANIMATED_VERSION=1.1.0
ANDROID_X_CORE_KTX_VERSION=1.8.0
ANDROID_X_LIFECYCLE_KTX_VERSION=2.4.1

# org.jetbrains versions
JETBRAINS_KOTLINX_COROUTINES_VERSION=1.6.3
JETBRAINS_KOTLINX_COROUTINES_VERSION=1.6.4
JETBRAINS_KOTLINX_COROUTINES_TEST_VERSION=1.6.4
JETBRAINS_KOTLIN_VERSION=1.7.0
JETBRAINS_KOTLIN_TEST_VERSION=1.7.0

Expand All @@ -86,6 +89,6 @@ MOCKWEBSERVER_VERSION=3.0.0-RC1
OK_HTTP_VERSION=3.10.0
PMD_VERSION=6.0.0
ROBOLECTRIC_VERSION=4.8.1
TRUTH_VERSION=0.45
TRUTH_VERSION=1.1.3
VIOLATIONS_PLUGIN_VERSION=1.8
VOLLEY_VERSION=1.2.0
54 changes: 54 additions & 0 deletions integration/ktx/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
plugins {
id 'com.android.library'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdk COMPILE_SDK_VERSION as int

defaultConfig {
minSdk MIN_SDK_VERSION as int
targetSdk TARGET_SDK_VERSION as int

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_7
targetCompatibility JavaVersion.VERSION_1_7
}
kotlinOptions {
jvmTarget = '1.8'
}
}

// Enable strict mode, but exclude tests.
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile) {
if (!it.name.contains("Test")) {
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict"
}
}

dependencies {
api project(":library")
implementation "androidx.core:core-ktx:$ANDROID_X_CORE_KTX_VERSION"
implementation "androidx.test:core-ktx:$ANDROID_X_TEST_CORE_KTX_VERSION"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$JETBRAINS_KOTLINX_COROUTINES_VERSION"
testImplementation "androidx.test.ext:junit-ktx:$ANDROID_X_TEST_JUNIT_KTX_VERSION"
testImplementation "androidx.test.ext:junit:$ANDROID_X_TEST_JUNIT_VERSION"
testImplementation "org.robolectric:robolectric:$ROBOLECTRIC_VERSION"
testImplementation "androidx.test:runner:$ANDROID_X_TEST_RUNNER_VERSION"
testImplementation "junit:junit:$JUNIT_VERSION"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$JETBRAINS_KOTLINX_COROUTINES_TEST_VERSION"
testImplementation "com.google.truth:truth:$TRUTH_VERSION"
androidTestImplementation "androidx.test.ext:junit:$ANDROID_X_TEST_JUNIT_VERSION"
}

apply from: "${rootProject.projectDir}/scripts/upload.gradle"
9 changes: 9 additions & 0 deletions integration/ktx/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
POM_NAME=Glide Kotlin Extensions
POM_ARTIFACT_ID=ktx
POM_PACKAGING=aar
POM_DESCRIPTION=An integration library to improve Kotlin interop with Glide

VERSION_MAJOR=1
VERSION_MINOR=0
VERSION_PATCH=0
VERSION_NAME=1.0.0-alpha.0-SNAPSHOT
2 changes: 2 additions & 0 deletions integration/ktx/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.bumptech.glide.integration.ktx" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* Functions that give us access to some of Glide's non-public internals to make the flows API a bit
* better.
*/
package com.bumptech.glide

import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target

internal fun RequestBuilder<*>.requestManager() = this.requestManager

internal fun <ResourceT, TargetAndRequestListenerT> RequestBuilder<ResourceT>.intoDirect(
targetAndRequestListener: TargetAndRequestListenerT,
) where TargetAndRequestListenerT : Target<ResourceT>,
TargetAndRequestListenerT : RequestListener<ResourceT> {
this.into(targetAndRequestListener, targetAndRequestListener) {
it.run()
}
}
Loading

0 comments on commit 7d9e1a3

Please sign in to comment.