Skip to content

Commit 6d30a7f

Browse files
authored
update (#3)
1 parent 0942a30 commit 6d30a7f

File tree

10 files changed

+43
-37
lines changed

10 files changed

+43
-37
lines changed

.idea/codeStyles/Project.xml

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ android {
3131
jvmTarget = "1.8"
3232
}
3333

34-
viewBinding {
35-
enabled = true
34+
buildFeatures {
35+
viewBinding = true
3636
}
3737
}
3838

3939
dependencies {
4040
implementation fileTree(dir: 'libs', include: ['*.jar'])
4141
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
4242

43-
implementation 'androidx.appcompat:appcompat:1.2.0-beta01'
44-
implementation 'androidx.core:core-ktx:1.3.0-rc01'
43+
implementation 'androidx.appcompat:appcompat:1.3.0-alpha01'
44+
implementation 'androidx.core:core-ktx:1.4.0-alpha01'
4545
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
4646
implementation 'androidx.recyclerview:recyclerview:1.2.0-alpha03'
4747
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0-rc01'
48-
implementation 'com.google.android.material:material:1.2.0-alpha06'
48+
implementation 'com.google.android.material:material:1.3.0-alpha01'
4949

5050
// viewModelScope
51-
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha02'
51+
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.0-alpha03'
5252

5353
// lifecycleScope
54-
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha02'
54+
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0-alpha03'
5555

5656
// retrofit2
5757
implementation 'com.squareup.retrofit2:retrofit:2.8.1'

app/src/main/AndroidManifest.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
</intent-filter>
2222
</activity>
2323

24-
<activity android:name=".ui.add.AddActivity" />
24+
<activity
25+
android:name=".ui.add.AddActivity"
26+
android:label="Add user" />
2527

2628
<meta-data
2729
android:name="preloaded_fonts"

app/src/main/java/com/hoc/flowmvi/data/UserRepositoryImpl.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
1212
import kotlinx.coroutines.FlowPreview
1313
import kotlinx.coroutines.channels.BroadcastChannel
1414
import kotlinx.coroutines.channels.Channel
15+
import kotlinx.coroutines.delay
1516
import kotlinx.coroutines.flow.*
1617
import kotlinx.coroutines.withContext
1718

@@ -73,6 +74,7 @@ class UserRepositoryImpl(
7374
val body = domainToBody(user).copy(avatar = avatarUrls.random())
7475
val response = userApiService.add(body)
7576
changesChannel.send(Change.Added(responseToDomain(response)))
77+
delay(400)
7678
}
7779
}
7880

app/src/main/java/com/hoc/flowmvi/ui/add/AddActivity.kt

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import android.view.MenuItem
66
import androidx.appcompat.app.AppCompatActivity
77
import androidx.core.view.isInvisible
88
import androidx.lifecycle.lifecycleScope
9+
import androidx.transition.AutoTransition
10+
import androidx.transition.TransitionManager
911
import com.hoc.flowmvi.clicks
1012
import com.hoc.flowmvi.databinding.ActivityAddBinding
1113
import com.hoc.flowmvi.textChanges
@@ -28,7 +30,7 @@ class AddActivity : AppCompatActivity(), View {
2830
supportActionBar?.setDisplayHomeAsUpEnabled(true)
2931

3032
setupViews()
31-
bindVM()
33+
bindVM(addVM)
3234
}
3335

3436
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@@ -38,7 +40,7 @@ class AddActivity : AppCompatActivity(), View {
3840
}
3941
}
4042

41-
private fun bindVM() {
43+
private fun bindVM(addVM: AddVM) {
4244
// observe view model
4345
lifecycleScope.launchWhenStarted {
4446
addVM.viewState
@@ -101,13 +103,18 @@ class AddActivity : AppCompatActivity(), View {
101103
addBinding.lastNameEditText.error = lastNameErrorMessage
102104
}
103105

106+
TransitionManager.beginDelayedTransition(
107+
addBinding.root,
108+
AutoTransition()
109+
.addTarget(addBinding.progressBar)
110+
.addTarget(addBinding.addButton)
111+
.setDuration(200)
112+
)
104113
addBinding.progressBar.isInvisible = !viewState.isLoading
114+
addBinding.addButton.isInvisible = viewState.isLoading
105115
}
106116

107-
private fun setupViews() {
108-
109-
}
110-
117+
private fun setupViews() = Unit
111118

112119
override fun intents(): Flow<ViewIntent> {
113120
return merge(

app/src/main/java/com/hoc/flowmvi/ui/main/MainActivity.kt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import com.hoc.flowmvi.ui.add.AddActivity
1818
import com.hoc.flowmvi.ui.main.MainContract.*
1919
import kotlinx.coroutines.ExperimentalCoroutinesApi
2020
import kotlinx.coroutines.FlowPreview
21+
import kotlinx.coroutines.channels.BroadcastChannel
2122
import kotlinx.coroutines.channels.Channel
2223
import kotlinx.coroutines.flow.*
2324
import org.koin.androidx.viewmodel.ext.android.viewModel
@@ -31,14 +32,14 @@ class MainActivity : AppCompatActivity(), View {
3132
private val userAdapter = UserAdapter()
3233
private val mainBinding by lazy(NONE) { ActivityMainBinding.inflate(layoutInflater) }
3334

34-
private val removeChannel = Channel<UserItem>(Channel.UNLIMITED)
35+
private val removeChannel = BroadcastChannel<UserItem>(Channel.BUFFERED)
3536

3637
override fun onCreate(savedInstanceState: Bundle?) {
3738
super.onCreate(savedInstanceState)
3839
setContentView(mainBinding.root)
3940

4041
setupViews()
41-
bindVM()
42+
bindVM(mainVM)
4243
}
4344

4445
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@@ -72,7 +73,7 @@ class MainActivity : AppCompatActivity(), View {
7273
}
7374
}
7475

75-
private fun bindVM() {
76+
private fun bindVM(mainVM: MainVM) {
7677
// observe view model
7778
lifecycleScope.launchWhenStarted {
7879
mainVM.viewState
@@ -97,7 +98,7 @@ class MainActivity : AppCompatActivity(), View {
9798
flowOf(ViewIntent.Initial),
9899
mainBinding.swipeRefreshLayout.refreshes().map { ViewIntent.Refresh },
99100
mainBinding.retryButton.clicks().map { ViewIntent.Retry },
100-
removeChannel.consumeAsFlow().map { ViewIntent.RemoveUser(it) }
101+
removeChannel.asFlow().map { ViewIntent.RemoveUser(it) }
101102
)
102103

103104
private fun handleSingleEvent(event: SingleEvent) {

app/src/main/java/com/hoc/flowmvi/ui/main/MainVM.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class MainVM(
2323
private val removeUser: RemoveUserUseCase,
2424
) : ViewModel() {
2525
private val _eventChannel = BroadcastChannel<SingleEvent>(capacity = Channel.BUFFERED)
26-
private val _intentChannel = BroadcastChannel<ViewIntent>(capacity = Channel.CONFLATED)
26+
private val _intentChannel = BroadcastChannel<ViewIntent>(capacity = Channel.BUFFERED)
2727

2828
val viewState: StateFlow<ViewState>
2929

app/src/main/res/layout/activity_add.xml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
android:layout_width="0dp"
4141
android:layout_height="wrap_content"
4242
android:layout_marginStart="16dp"
43-
android:layout_marginTop="8dp"
43+
android:layout_marginTop="4dp"
4444
android:layout_marginEnd="16dp"
4545
android:hint="First name"
4646
app:errorEnabled="true"
@@ -70,13 +70,13 @@
7070
android:layout_width="0dp"
7171
android:layout_height="wrap_content"
7272
android:layout_marginStart="16dp"
73-
android:layout_marginTop="8dp"
73+
android:layout_marginTop="4dp"
7474
android:layout_marginEnd="16dp"
7575
android:hint="Last name"
7676
app:errorEnabled="true"
7777
app:hintAnimationEnabled="true"
7878
app:hintEnabled="true"
79-
app:layout_constraintBottom_toTopOf="@+id/progressBar"
79+
app:layout_constraintBottom_toTopOf="@+id/addButton"
8080
app:layout_constraintEnd_toEndOf="parent"
8181
app:layout_constraintHorizontal_bias="0.5"
8282
app:layout_constraintStart_toStartOf="parent"
@@ -90,6 +90,7 @@
9090
android:layout_marginTop="8dp"
9191
android:layout_marginEnd="16dp"
9292
android:fontFamily="@font/noto_sans"
93+
android:imeOptions="actionDone"
9394
android:inputType="textPersonName"
9495
android:singleLine="true"
9596
android:textSize="16sp" />
@@ -104,9 +105,9 @@
104105
android:elevation="12dp"
105106
android:fontFamily="@font/noto_sans"
106107
android:paddingStart="32dp"
107-
android:paddingTop="16dp"
108+
android:paddingTop="12dp"
108109
android:paddingEnd="32dp"
109-
android:paddingBottom="16dp"
110+
android:paddingBottom="12dp"
110111
android:text="Add"
111112
android:textColor="@android:color/white"
112113
android:textSize="16sp"
@@ -115,17 +116,15 @@
115116
app:layout_constraintEnd_toEndOf="parent"
116117
app:layout_constraintHorizontal_bias="0.5"
117118
app:layout_constraintStart_toStartOf="parent"
118-
app:layout_constraintTop_toBottomOf="@+id/progressBar" />
119+
app:layout_constraintTop_toBottomOf="@+id/lastNameEditText" />
119120

120121
<ProgressBar
121122
android:id="@+id/progressBar"
122123
style="?android:attr/progressBarStyle"
123124
android:layout_width="wrap_content"
124125
android:layout_height="wrap_content"
125-
android:layout_marginTop="8dp"
126-
app:layout_constraintBottom_toTopOf="@+id/addButton"
126+
app:layout_constraintBottom_toBottomOf="@+id/addButton"
127127
app:layout_constraintEnd_toEndOf="parent"
128-
app:layout_constraintHorizontal_bias="0.5"
129128
app:layout_constraintStart_toStartOf="parent"
130-
app:layout_constraintTop_toBottomOf="@+id/lastNameEditText" />
129+
app:layout_constraintTop_toTopOf="@id/addButton" />
131130
</androidx.constraintlayout.widget.ConstraintLayout>

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ buildscript {
88
maven { url 'https://dl.bintray.com/kotlin/kotlin-eap' }
99
}
1010
dependencies {
11-
classpath 'com.android.tools.build:gradle:3.6.3'
11+
classpath 'com.android.tools.build:gradle:4.0.0'
1212
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1313

1414
// NOTE: Do not place your application dependencies here; they belong
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#Sat Feb 08 09:17:34 ICT 2020
1+
#Sat Jun 13 00:43:17 ICT 2020
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1-milestone-2-all.zip
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip

0 commit comments

Comments
 (0)