Skip to content

Commit

Permalink
SABP-18 Update company's Android template
Browse files Browse the repository at this point in the history
  • Loading branch information
VladSumtsov committed Nov 30, 2022
1 parent 3f0bee3 commit a4b7b9f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 9 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/io/template/app/common/di/rootModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package io.template.app.common.di

import io.template.app.core.RootActivity
import io.template.app.core.RootViewModel
import io.template.domain.ActivityScopeExample
import org.koin.androidx.viewmodel.dsl.viewModel
import org.koin.dsl.module

val rootModule = module {
viewModel { RootViewModel(get(), get()) }
scope<RootActivity> {
viewModel { RootViewModel(get(), get()) }
scoped { ActivityScopeExample(get()) }
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/io/template/app/common/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.template.app.common.ui

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import org.koin.androidx.scope.ScopeActivity

/** Base Activity to inject logic in-the-middle, e.g.: loggers, debuggers, extra dev. view, etc. */
abstract class BaseActivity : AppCompatActivity() {
abstract class BaseActivity : ScopeActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/io/template/app/common/ui/BaseFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
import androidx.lifecycle.LifecycleOwner
import org.koin.androidx.scope.ScopeFragment
import kotlin.properties.ReadOnlyProperty
import kotlin.properties.ReadWriteProperty
import kotlin.reflect.KProperty

abstract class BaseFragment(@LayoutRes contentLayoutId: Int = 0) : Fragment(contentLayoutId) {
abstract class BaseFragment(@LayoutRes contentLayoutId: Int = 0) : ScopeFragment(contentLayoutId) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.template.app.feature.authorization

import io.template.app.common.di.APP_COROUTINE_SCOPE
import io.template.app.feature.authorization.login.LoginFragment
import io.template.app.feature.authorization.login.LoginViewModel
import io.template.domain.auth.AuthorizationService
import io.template.domain.auth.AuthorizationServiceImpl
Expand All @@ -9,6 +10,13 @@ import org.koin.core.qualifier.named
import org.koin.dsl.module

val authorisationModule = module {
single<AuthorizationService> { AuthorizationServiceImpl(get(named(APP_COROUTINE_SCOPE)), get()) }
viewModel { LoginViewModel(get(), get()) }
single<AuthorizationService> {
AuthorizationServiceImpl(
appScope = get(named(APP_COROUTINE_SCOPE)),
sessionService = get()
)
}
scope<LoginFragment> {
viewModel { LoginViewModel(get(), get(), get()) }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import androidx.lifecycle.SavedStateHandle
import androidx.lifecycle.ViewModel
import com.github.michaelbull.result.onFailure
import com.github.michaelbull.result.onSuccess
import io.template.domain.ActivityScopeExample
import io.template.domain.auth.AuthorizationService
import io.template.domain.auth.SigninCredentials
import kotlinx.parcelize.IgnoredOnParcel
Expand All @@ -19,7 +20,8 @@ import org.orbitmvi.orbit.viewmodel.container

class LoginViewModel(
savedStateHandle: SavedStateHandle,
private val authorizationService: AuthorizationService
private val authorizationService: AuthorizationService,
private val activityScopeExample: ActivityScopeExample,
) : ViewModel(),
ContainerHost<State, Effect> {

Expand All @@ -38,6 +40,8 @@ class LoginViewModel(
}

fun onLogin() = intent {
activityScopeExample.runExample()

reduce { state.copy(actionState = State.ActionState.Progress) }
val result = with(state.input) {
authorizationService.signin(SigninCredentials(username, password))
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/io/template/domain/ActivityScopeExample.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package io.template.domain

import android.app.Activity

class ActivityScopeExample(
private val activity: Activity
) {
fun runExample() {
activity.windowManager
}
}
3 changes: 1 addition & 2 deletions buildSrc/src/main/kotlin/Deps.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,11 @@ object Deps {
private const val version = "1.6.4"
const val CORE = "org.jetbrains.kotlinx:kotlinx-coroutines-core:$version"
const val ANDROID = "org.jetbrains.kotlinx:kotlinx-coroutines-android:$version"

}
}

object Di {
private const val koin_version = "3.2.0"
private const val koin_version = "3.2.2"
const val CORE = "io.insert-koin:koin-core:$koin_version"
const val CORE_TEST = "io.insert-koin:koin-test:$koin_version"
const val ANDROIDX = "io.insert-koin:koin-android:$koin_version"
Expand Down

0 comments on commit a4b7b9f

Please sign in to comment.