-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
da84ca5
commit 839b4ec
Showing
46 changed files
with
1,446 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
The RIBs Workers Demo app showcases: | ||
|
||
1. Binding of [com.uber.rib.core.Worker] with different [CoroutineContext] | ||
2. Binding of [com.uber.rib.core.RibCoroutineWorker] | ||
3. Binding multiple [com.uber.rib.core.Worker] in specific [CoroutineContext] | ||
4. Convert existing [com.uber.rib.core.Worker] to [com.uber.rib.core.RibCoroutineWorker] and viceversa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
apply plugin: 'com.android.application' | ||
apply plugin: 'org.jetbrains.kotlin.android' | ||
apply plugin: "org.jetbrains.kotlin.kapt" | ||
|
||
android { | ||
namespace "com.uber.rib.workers" | ||
compileSdk deps.build.compileSdkVersion | ||
|
||
defaultConfig { | ||
minSdk deps.build.minSdkVersion | ||
targetSdk deps.build.targetSdkVersion | ||
applicationId "com.uber.rib.workers" | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildFeatures { | ||
compose true | ||
} | ||
composeOptions { | ||
kotlinCompilerExtensionVersion deps.versions.androidx.compose.compiler | ||
} | ||
compileOptions { | ||
sourceCompatibility deps.build.javaVersion | ||
targetCompatibility deps.build.javaVersion | ||
} | ||
|
||
lint { | ||
abortOnError false | ||
quiet true | ||
} | ||
} | ||
|
||
dependencies { | ||
kapt deps.uber.motifCompiler | ||
implementation project(":libraries:rib-android") | ||
implementation project(":libraries:rib-android-compose") | ||
implementation project(":libraries:rib-coroutines") | ||
implementation deps.androidx.activityCompose | ||
implementation deps.androidx.annotations | ||
implementation deps.androidx.appcompat | ||
implementation deps.androidx.composeAnimation | ||
implementation deps.androidx.composeFoundation | ||
implementation deps.androidx.composeMaterial | ||
implementation deps.androidx.composeNavigation | ||
implementation deps.androidx.composeRuntimeRxJava2 | ||
implementation deps.androidx.composeUi | ||
implementation deps.androidx.composeViewModel | ||
implementation deps.androidx.composeUiTooling | ||
implementation deps.androidx.savedState | ||
implementation deps.external.rxandroid2 | ||
implementation deps.kotlin.coroutines | ||
implementation deps.kotlin.coroutinesAndroid | ||
implementation deps.kotlin.coroutinesRx2 | ||
implementation deps.uber.autodisposeCoroutines | ||
implementation deps.uber.motif | ||
|
||
debugImplementation 'com.facebook.flipper:flipper:0.93.0' | ||
debugImplementation 'com.facebook.soloader:soloader:0.10.1' | ||
releaseImplementation 'com.facebook.flipper:flipper-noop:0.93.0' | ||
|
||
implementation project(":tooling:rib-flipper-plugin") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:name=".ComposeApplication" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.Android"> | ||
|
||
<activity | ||
android:name=".root.RootActivity" | ||
android:windowSoftInputMode="adjustResize" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN"/> | ||
<category android:name="android.intent.category.LAUNCHER"/> | ||
</intent-filter> | ||
</activity> | ||
|
||
</application> | ||
|
||
</manifest> |
40 changes: 40 additions & 0 deletions
40
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/ComposeApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers | ||
|
||
import android.app.Application | ||
import com.facebook.flipper.android.AndroidFlipperClient | ||
import com.facebook.flipper.android.utils.FlipperUtils | ||
import com.facebook.flipper.core.FlipperClient | ||
import com.facebook.flipper.plugins.inspector.DescriptorMapping | ||
import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin | ||
import com.facebook.soloader.SoLoader | ||
import com.uber.rib.flipper.RibTreePlugin | ||
|
||
class ComposeApplication : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
SoLoader.init(this, false) | ||
|
||
if (BuildConfig.DEBUG && FlipperUtils.shouldEnableFlipper(this)) { | ||
val client: FlipperClient = AndroidFlipperClient.getInstance(this) | ||
client.addPlugin(RibTreePlugin()) | ||
client.addPlugin(InspectorFlipperPlugin(this, DescriptorMapping.withDefaults())) | ||
client.start() | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root | ||
|
||
import android.app.Application | ||
import android.view.ViewGroup | ||
import com.uber.rib.core.RibActivity | ||
import com.uber.rib.core.ViewRouter | ||
import motif.Creatable | ||
import motif.Expose | ||
import motif.NoDependencies | ||
import motif.ScopeFactory | ||
|
||
class RootActivity : RibActivity() { | ||
|
||
override fun createRouter(parentViewGroup: ViewGroup): ViewRouter<*, *> { | ||
return ScopeFactory.create(Parent::class.java) | ||
.rootScope(application, this, findViewById(android.R.id.content)) | ||
.router() | ||
} | ||
|
||
@motif.Scope | ||
interface Parent : Creatable<NoDependencies> { | ||
fun rootScope( | ||
@Expose application: Application, | ||
@Expose activity: RibActivity, | ||
parentViewGroup: ViewGroup, | ||
): RootScope | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root | ||
|
||
import com.uber.rib.core.BasicInteractor | ||
import com.uber.rib.core.Bundle | ||
import com.uber.rib.core.EmptyPresenter | ||
import com.uber.rib.core.WorkerBinder | ||
import com.uber.rib.workers.root.main.workers.monitoring.RibWorkerMonitor | ||
|
||
class RootInteractor( | ||
presenter: EmptyPresenter, | ||
private val ribWorkerMonitor: RibWorkerMonitor, | ||
) : BasicInteractor<EmptyPresenter, RootRouter>(presenter) { | ||
|
||
override fun didBecomeActive(savedInstanceState: Bundle?) { | ||
super.didBecomeActive(savedInstanceState) | ||
|
||
// Setting up Worker Monitoring prior to any WorkerBinding | ||
WorkerBinder.initializeMonitoring(ribWorkerMonitor) | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root | ||
|
||
import com.uber.rib.core.BasicViewRouter | ||
import com.uber.rib.workers.root.main.MainRouter | ||
|
||
class RootRouter( | ||
view: RootView, | ||
interactor: RootInteractor, | ||
private val scope: RootScope, | ||
) : BasicViewRouter<RootView, RootInteractor>(view, interactor) { | ||
|
||
private var mainRouter: MainRouter? = null | ||
|
||
override fun willAttach() { | ||
attachMain() | ||
} | ||
|
||
override fun willDetach() { | ||
detachMain() | ||
} | ||
|
||
private fun attachMain() { | ||
if (mainRouter == null) { | ||
mainRouter = scope.mainScope(view).router().also { attachChild(it) } | ||
} | ||
} | ||
|
||
private fun detachMain() { | ||
mainRouter?.let { detachChild(it) } | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootScope.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root | ||
|
||
import android.view.ViewGroup | ||
import androidx.lifecycle.setViewTreeLifecycleOwner | ||
import androidx.savedstate.setViewTreeSavedStateRegistryOwner | ||
import com.uber.rib.core.EmptyPresenter | ||
import com.uber.rib.core.RibActivity | ||
import com.uber.rib.workers.root.main.MainScope | ||
import com.uber.rib.workers.root.main.workers.monitoring.BackendReporter | ||
import com.uber.rib.workers.root.main.workers.monitoring.RibWorkerMonitor | ||
|
||
@motif.Scope | ||
interface RootScope { | ||
fun router(): RootRouter | ||
|
||
fun mainScope(parentViewGroup: ViewGroup): MainScope | ||
|
||
@motif.Objects | ||
abstract class Objects { | ||
abstract fun router(): RootRouter | ||
|
||
abstract fun interactor(): RootInteractor | ||
|
||
abstract fun presenter(): EmptyPresenter | ||
|
||
fun view(parentViewGroup: ViewGroup, activity: RibActivity): RootView { | ||
return RootView(parentViewGroup.context).apply { | ||
setViewTreeLifecycleOwner(activity) | ||
setViewTreeSavedStateRegistryOwner(activity) | ||
} | ||
} | ||
|
||
fun backendReporter(): BackendReporter = BackendReporter {} | ||
|
||
fun ribWorkerMonitor(backendReporter: BackendReporter): RibWorkerMonitor { | ||
return RibWorkerMonitor(backendReporter) | ||
} | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/RootView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.widget.FrameLayout | ||
|
||
class RootView | ||
@JvmOverloads | ||
constructor( | ||
context: Context, | ||
attrs: AttributeSet? = null, | ||
defStyle: Int = 0, | ||
) : FrameLayout(context, attrs, defStyle) |
33 changes: 33 additions & 0 deletions
33
android/demos/rib-workers/src/main/kotlin/com/uber/rib/workers/root/main/MainInteractor.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright (C) 2023. Uber Technologies | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.uber.rib.workers.root.main | ||
|
||
import com.uber.rib.core.BasicInteractor | ||
import com.uber.rib.core.Bundle | ||
import com.uber.rib.core.ComposePresenter | ||
|
||
class MainInteractor( | ||
presenter: ComposePresenter, | ||
private val childContent: MainRouter.ChildContent, | ||
) : BasicInteractor<ComposePresenter, MainRouter>(presenter) { | ||
|
||
override fun didBecomeActive(savedInstanceState: Bundle?) { | ||
super.didBecomeActive(savedInstanceState) | ||
|
||
router.view.setContent { MainView(childContent = childContent) } | ||
router.attachRibWorkersSelection() | ||
} | ||
} |
Oops, something went wrong.