Skip to content

Commit

Permalink
#4: Added WelcomeScreen - BP & NM
Browse files Browse the repository at this point in the history
  • Loading branch information
puttabrahmam committed Jan 21, 2022
1 parent e5b36a2 commit 93d43f9
Show file tree
Hide file tree
Showing 10 changed files with 139 additions and 4 deletions.
7 changes: 7 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ android {
excludes += '/META-INF/{AL2.0,LGPL2.1}'
}
}
testOptions {
unitTests.returnDefaultValues = true
}
}

tasks.dokkaHtml.configure {
Expand Down Expand Up @@ -90,4 +93,8 @@ dependencies {
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-tooling:$compose_version"

//Koin DI
implementation "io.insert-koin:koin-android:$koin_version"// Koin main features for Android
implementation "io.insert-koin:koin-androidx-compose:$koin_version"// Jetpack Compose
}
3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Jetflow">
android:theme="@style/Theme.Jetflow"
android:name=".JetflowApplication">
<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
19 changes: 19 additions & 0 deletions app/src/main/java/com/wwt/jetflow/AppModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.wwt.jetflow

import com.wwt.jetflow.welcome.WelcomeViewModel
import org.koin.core.component.KoinComponent
import org.koin.core.context.loadKoinModules
import org.koin.dsl.module

object AppModule : KoinComponent {
fun init(){
val welcomeModules = module {
single{WelcomeViewModel()}
}

val moduleList = listOf(
welcomeModules
)
loadKoinModules(moduleList)
}
}
15 changes: 15 additions & 0 deletions app/src/main/java/com/wwt/jetflow/JetflowApp.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.wwt.jetflow

import androidx.compose.runtime.Composable
import com.wwt.jetflow.welcome.WelcomeScreen
import com.wwt.jetflow.welcome.WelcomeViewModel
import org.koin.androidx.compose.inject

@Composable
fun JetflowApp() {
val welcomeViewModel: WelcomeViewModel by inject()
WelcomeScreen(
state = welcomeViewModel.viewState.value,
effectFlow = welcomeViewModel.effect,
onEventSent = { event -> welcomeViewModel.setEvent(event) })
}
22 changes: 22 additions & 0 deletions app/src/main/java/com/wwt/jetflow/JetflowApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.wwt.jetflow

import android.app.Application
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.koin.core.context.stopKoin

class JetflowApplication : Application(){
override fun onCreate() {
super.onCreate()

startKoin {
androidContext(this@JetflowApplication)
}
AppModule.init()
}

override fun onTerminate() {
super.onTerminate()
stopKoin()
}
}
7 changes: 4 additions & 3 deletions app/src/main/java/com/wwt/jetflow/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
package com.wwt.jetflow

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.material.MaterialTheme
import androidx.compose.material.Surface
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.tooling.preview.Preview
import com.wwt.jetflow.base.BaseActivity
import com.wwt.jetflow.ui.theme.JetflowTheme

class MainActivity : ComponentActivity() {
class MainActivity : BaseActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
JetflowTheme {
// A surface container using the 'background' color from the theme
Surface(color = MaterialTheme.colors.background) {
Greeting("Android")
JetflowApp()
}
}
}
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/wwt/jetflow/welcome/WelcomeScreen.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.wwt.jetflow.welcome

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.material.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import kotlinx.coroutines.flow.Flow

@Composable
fun WelcomeScreen(
state: WelcomeScreenContract.State,
effectFlow: Flow<WelcomeScreenContract.Effect>?,
onEventSent: (event: WelcomeScreenContract.Event) -> Unit
){
Box(
contentAlignment = Alignment.Center,
modifier = Modifier.fillMaxSize()
) {
Text(text = state.welcomeText)
}
}
18 changes: 18 additions & 0 deletions app/src/main/java/com/wwt/jetflow/welcome/WelcomeScreenContract.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.wwt.jetflow.welcome

import com.wwt.jetflow.base.ViewEvent
import com.wwt.jetflow.base.ViewSideEffect
import com.wwt.jetflow.base.ViewState


class WelcomeScreenContract {
sealed class Event : ViewEvent {
}

data class State(
val welcomeText: String =""
) : ViewState

sealed class Effect : ViewSideEffect {
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/wwt/jetflow/welcome/WelcomeViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.wwt.jetflow.welcome

import androidx.lifecycle.viewModelScope
import com.wwt.jetflow.base.BaseViewModel
import kotlinx.coroutines.launch


class WelcomeViewModel :
BaseViewModel<WelcomeScreenContract.Event,
WelcomeScreenContract.State,
WelcomeScreenContract.Effect>() {


init {
viewModelScope.launch {
setState {
copy(welcomeText = "Welcome to Jetflow")
}
}
}

override fun setInitialState(): WelcomeScreenContract.State =
WelcomeScreenContract.State(welcomeText = "")

override fun handleEvents(event: WelcomeScreenContract.Event) {
TODO("Not yet implemented")
}
}
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
buildscript {
ext {
compose_version = '1.0.1'
koin_version = '3.1.3'
}
repositories {
google()
Expand Down

0 comments on commit 93d43f9

Please sign in to comment.