-
Notifications
You must be signed in to change notification settings - Fork 13
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
Showing
53 changed files
with
816 additions
and
247 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
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
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
Binary file not shown.
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
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
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
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
5 changes: 0 additions & 5 deletions
5
sample/androidApp/src/main/kotlin/pro/respawn/flowmvi/sample/app/XmlActivity.kt
This file was deleted.
Oops, something went wrong.
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
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
7 changes: 7 additions & 0 deletions
7
sample/src/androidMain/kotlin/pro/respawn/flowmvi/sample/di/AppModule.android.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 |
---|---|---|
@@ -1,11 +1,18 @@ | ||
package pro.respawn.flowmvi.sample.di | ||
|
||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import org.koin.core.module.dsl.factoryOf | ||
import org.koin.core.module.dsl.singleOf | ||
import org.koin.core.qualifier.qualifier | ||
import org.koin.dsl.bind | ||
import org.koin.dsl.module | ||
import pro.respawn.flowmvi.android.StoreViewModel | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityContainer | ||
import pro.respawn.flowmvi.sample.platform.AndroidFileManager | ||
import pro.respawn.flowmvi.sample.platform.FileManager | ||
|
||
actual val platformAppModule = module { | ||
singleOf(::AndroidFileManager) bind FileManager::class | ||
factoryOf(::XmlActivityContainer) | ||
viewModel(qualifier<XmlActivityContainer>()) { StoreViewModel(get<XmlActivityContainer>()) } | ||
} |
5 changes: 3 additions & 2 deletions
5
...wmvi/sample/app/AndroidFeatureLauncher.kt → ...mple/navigation/AndroidFeatureLauncher.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
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
75 changes: 75 additions & 0 deletions
75
sample/src/androidMain/kotlin/pro/respawn/flowmvi/sample/ui/screens/XmlActivity.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,75 @@ | ||
package pro.respawn.flowmvi.sample.ui.screens | ||
|
||
import android.os.Bundle | ||
import androidx.activity.ComponentActivity | ||
import androidx.core.view.isVisible | ||
import com.google.android.material.snackbar.Snackbar | ||
import org.koin.androidx.viewmodel.ext.android.viewModel | ||
import org.koin.core.qualifier.qualifier | ||
import pro.respawn.flowmvi.android.StoreViewModel | ||
import pro.respawn.flowmvi.android.subscribe | ||
import pro.respawn.flowmvi.sample.R | ||
import pro.respawn.flowmvi.sample.databinding.ActivityXmlBinding | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityAction | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityAction.ShowIncrementedSnackbar | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityContainer | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityIntent | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityIntent.ClickedIncrementCounter | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityState | ||
import pro.respawn.flowmvi.sample.features.xmlactivity.XmlActivityState.DisplayingCounter | ||
import pro.respawn.kmmutils.common.fastLazy | ||
|
||
private typealias ViewModel = StoreViewModel<XmlActivityState, XmlActivityIntent, XmlActivityAction> | ||
|
||
internal class XmlActivity : ComponentActivity() { | ||
|
||
private val vm by viewModel<ViewModel>(qualifier<XmlActivityContainer>()) | ||
private val binding by fastLazy { ActivityXmlBinding.inflate(layoutInflater) } | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(binding.root) | ||
subscribe(vm.store, ::consume, ::render) | ||
with(binding) { | ||
btnIncrement.setOnClickListener { vm.store.intent(ClickedIncrementCounter) } | ||
} | ||
} | ||
|
||
private fun render(state: XmlActivityState) = with(binding) { | ||
when (state) { | ||
is DisplayingCounter -> { | ||
tvCounter.isVisible = true | ||
btnIncrement.isVisible = true | ||
tvCounter.text = getString(R.string.counter_template, state.counter) | ||
|
||
tvError.isVisible = false | ||
progress.isVisible = false | ||
} | ||
is XmlActivityState.Error -> { | ||
tvError.isVisible = true | ||
tvError.text = state.e?.message ?: getString(R.string.error_message) | ||
|
||
progress.isVisible = false | ||
tvCounter.isVisible = false | ||
btnIncrement.isVisible = false | ||
} | ||
is XmlActivityState.Loading -> { | ||
progress.isVisible = true | ||
|
||
tvError.isVisible = false | ||
tvCounter.isVisible = false | ||
btnIncrement.isVisible = false | ||
} | ||
} | ||
} | ||
|
||
private fun consume(action: XmlActivityAction) { | ||
when (action) { | ||
ShowIncrementedSnackbar -> Snackbar.make( | ||
binding.root, | ||
getString(R.string.incremented_counter_message), | ||
Snackbar.LENGTH_SHORT | ||
).show() | ||
} | ||
} | ||
} |
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,68 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".ui.screens.XmlActivity"> | ||
|
||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/tvCounter" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_margin="8dp" | ||
android:gravity="center" | ||
android:textSize="16sp" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toTopOf="@+id/btnIncrement" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
app:layout_constraintVertical_bias="0.5" | ||
app:layout_constraintVertical_chainStyle="packed" | ||
tools:text="Counter: 5" | ||
tools:visibility="visible" /> | ||
|
||
<com.google.android.material.button.MaterialButton | ||
android:id="@+id/btnIncrement" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:layout_margin="8dp" | ||
android:text="@string/increment_counter" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintHorizontal_bias="0.502" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toBottomOf="@+id/tvCounter" | ||
app:layout_constraintVertical_bias="0.5" | ||
tools:visibility="visible" /> | ||
|
||
<com.google.android.material.textview.MaterialTextView | ||
android:id="@+id/tvError" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_gravity="bottom|end" | ||
android:textColor="@color/design_default_color_error" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:text="Error" | ||
tools:visibility="visible" /> | ||
|
||
<com.google.android.material.progressindicator.CircularProgressIndicator | ||
android:id="@+id/progress" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:indeterminate="true" | ||
android:visibility="gone" | ||
app:layout_constraintBottom_toBottomOf="parent" | ||
app:layout_constraintEnd_toEndOf="parent" | ||
app:layout_constraintStart_toStartOf="parent" | ||
app:layout_constraintTop_toTopOf="parent" | ||
tools:visibility="visible" /> | ||
</androidx.constraintlayout.widget.ConstraintLayout> |
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,14 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<string name="increment_counter">Increment counter</string> | ||
<string name="incremented_counter_message">Incremented counter</string> | ||
<string name="counter_template"> | ||
This feature showcases how you can implement multiplatform business logic and hook it up to a native UI. | ||
In this case, this activity is implemented using XML, but the store is in the shared module. | ||
\n\nFlowMVI provides a way to wrap your stores in ViewModels and automatically start/stop them as needed, then inject them | ||
into your UI components. | ||
\n\nAs needed, you can even persist the state of a store into a platform-dependent container, i.e. SavedInstanceState | ||
\nCounter : %d | ||
</string> | ||
<string name="error_message">Unknown error</string> | ||
</resources> |
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
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
Oops, something went wrong.