forked from Hukumister/Gemini
-
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.
Merge pull request Hukumister#63 from HaronCode/task/store-keeper
task/store keeper
- Loading branch information
Showing
26 changed files
with
210 additions
and
44 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
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
21 changes: 21 additions & 0 deletions
21
gemini-binder/src/androidMain/kotlin/com/haroncode/gemini/binder/BinderImpl.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,21 @@ | ||
package com.haroncode.gemini.binder | ||
|
||
import androidx.lifecycle.LifecycleOwner | ||
import com.haroncode.gemini.binder.coordinator.Coordinator | ||
import com.haroncode.gemini.binder.rule.BindingRulesFactory | ||
import com.haroncode.gemini.lifecycle.StoreLifecycleObserver | ||
import com.haroncode.gemini.lifecycle.strategy.LifecycleStrategy | ||
import kotlinx.coroutines.Dispatchers | ||
|
||
internal class BinderImpl<View : LifecycleOwner>( | ||
private val factory: BindingRulesFactory<View>, | ||
private val lifecycleStrategy: LifecycleStrategy | ||
) : Binder<View> { | ||
|
||
override fun bind(view: View) { | ||
val bindingRules = factory.create(view) | ||
val coordinator = Coordinator(Dispatchers.Main.immediate, bindingRules) | ||
val storeLifecycleObserver = StoreLifecycleObserver(lifecycleStrategy, coordinator) | ||
view.lifecycle.addObserver(storeLifecycleObserver) | ||
} | ||
} |
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
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
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,52 @@ | ||
plugins { | ||
id("com.android.library") | ||
kotlin("android") | ||
id("ktlint-plugin") | ||
id("publish-plugin") | ||
} | ||
|
||
android { | ||
compileSdkVersion(Versions.android.compileSdk) | ||
buildToolsVersion(Versions.android.buildTools) | ||
|
||
defaultConfig { | ||
minSdkVersion(Versions.android.minSdk) | ||
} | ||
|
||
libraryVariants.all { | ||
generateBuildConfigProvider.configure { enabled = false } | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(Deps.kotlinx.coroutines) | ||
implementation(Deps.androidx.viewModel) | ||
api(project(":gemini-core")) | ||
} | ||
|
||
val geminiGroup = findProperty("group") as String | ||
val geminiVersion = findProperty("version") as String | ||
|
||
version = geminiVersion | ||
group = geminiGroup | ||
|
||
val sourcesJar by tasks.creating(Jar::class) { | ||
archiveClassifier.set("sources") | ||
from(android.sourceSets.getByName("main").java.srcDirs) | ||
} | ||
|
||
afterEvaluate { | ||
publishing { | ||
publications { | ||
create<MavenPublication>("gemini-store-keeper") { | ||
groupId = geminiGroup | ||
artifactId = "gemini-store-keeper" | ||
version = geminiVersion | ||
|
||
from(components["release"]) | ||
|
||
artifact(sourcesJar) | ||
} | ||
} | ||
} | ||
} |
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,2 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest package="com.haroncode.gemini.keeper" /> |
41 changes: 41 additions & 0 deletions
41
gemini-store-keeper/src/main/java/com/haroncode/gemini/keeper/StoreKeeperViewModel.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,41 @@ | ||
package com.haroncode.gemini.keeper | ||
|
||
import androidx.lifecycle.ViewModel | ||
import androidx.lifecycle.ViewModelProvider | ||
import androidx.lifecycle.ViewModelStoreOwner | ||
import com.haroncode.gemini.element.Store | ||
import kotlinx.coroutines.cancel | ||
|
||
/** | ||
* @author kdk96 | ||
*/ | ||
|
||
inline fun <reified T, Action : Any, State : Any, Event : Any> ViewModelStoreOwner.getStore( | ||
noinline provider: () -> T | ||
) where T : Store<Action, State, Event> = | ||
getStore(T::class.java.canonicalName!!, provider) | ||
|
||
fun <T, Action : Any, State : Any, Event : Any> ViewModelStoreOwner.getStore( | ||
key: String, | ||
provider: () -> T | ||
) where T : Store<Action, State, Event> = | ||
ViewModelProvider(this) | ||
.get(StoreKeeperViewModel::class.java) | ||
.get(key, provider) | ||
|
||
internal class StoreKeeperViewModel : ViewModel() { | ||
|
||
private val stores = HashMap<String, Store<*, *, *>>() | ||
|
||
@Suppress("UNCHECKED_CAST") | ||
fun <T, Action : Any, State : Any, Event : Any> get( | ||
key: String, | ||
provider: () -> T | ||
) where T : Store<Action, State, Event> = | ||
stores.getOrPut(key, provider) as T | ||
|
||
override fun onCleared() { | ||
stores.values.forEach { store -> store.coroutineScope.cancel() } | ||
stores.clear() | ||
} | ||
} |
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
19 changes: 0 additions & 19 deletions
19
sample/src/main/java/com/haroncode/gemini/sample/presentation/routing/MainBindingFactory.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
Oops, something went wrong.