Skip to content

Commit fcdfbfb

Browse files
author
Vera Sokolova
committed
added new lines in files, move factory to file
1 parent 5e529fc commit fcdfbfb

16 files changed

+32
-25
lines changed

app/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,4 @@ dependencies {
4848
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1'
4949
implementation 'androidx.activity:activity-ktx:1.7.2'
5050
testImplementation 'junit:junit:4.13.2'
51-
}
51+
}

app/src/main/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@
2020
</activity>
2121
</application>
2222

23-
</manifest>
23+
</manifest>

app/src/main/java/otus/homework/coroutines/CatViewModel.kt

-8
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ class CatViewModel(
1919
) : ViewModel() {
2020
val catModel = MutableLiveData<Result>()
2121

22-
class CatsViewModelFactory(private val factService: CatsFactService,
23-
private val imageService: CatsImageService) : ViewModelProvider.Factory {
24-
@Suppress("UNCHECKED_CAST")
25-
override fun <T : ViewModel> create(modelClass: Class<T>): T {
26-
return CatViewModel(factService, imageService) as T
27-
}
28-
}
29-
3022
fun onInitComplete() {
3123
loadData()
3224
}

app/src/main/java/otus/homework/coroutines/CatsFactService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ interface CatsFactService {
88

99
@GET("fact")
1010
suspend fun getCatFact() : Response<Fact>
11-
}
11+
}

app/src/main/java/otus/homework/coroutines/CatsImageService.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ interface CatsImageService {
1212
companion object {
1313
const val BASE_URL = "https://cataas.com/"
1414
}
15-
}
15+
}

app/src/main/java/otus/homework/coroutines/CatsPresenter.kt

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package otus.homework.coroutines
22

3-
import android.util.Log
43
import kotlinx.coroutines.CancellationException
54
import kotlinx.coroutines.Dispatchers
65
import kotlinx.coroutines.async
76
import kotlinx.coroutines.cancel
87
import kotlinx.coroutines.launch
98
import kotlinx.coroutines.runBlocking
109
import otus.homework.coroutines.model.CatModel
11-
import java.lang.Exception
1210
import java.net.SocketTimeoutException
1311

1412
class CatsPresenter(
@@ -60,4 +58,4 @@ class CatsPresenter(
6058
fun onStop(){
6159
catsScope.cancel()
6260
}
63-
}
61+
}

app/src/main/java/otus/homework/coroutines/CatsView.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@ interface ICatsView {
4242

4343
fun populate(catModel: CatModel)
4444
fun showToast(message: String)
45-
}
45+
}

app/src/main/java/otus/homework/coroutines/CrashMonitor.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ object CrashMonitor {
1313
crashesList.add(message)
1414
Log.e("crash_mirror", message)
1515
}
16-
}
16+
}

app/src/main/java/otus/homework/coroutines/DiContainer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ class DiContainer {
4545
.addConverterFactory(GsonConverterFactory.create(gson))
4646
.build()
4747
}
48-
}
48+
}

app/src/main/java/otus/homework/coroutines/MainActivity.kt

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.os.Bundle
44
import androidx.appcompat.app.AppCompatActivity
55
import androidx.lifecycle.Observer
66
import androidx.lifecycle.ViewModelProvider
7+
import otus.homework.coroutines.model.CatsViewModelFactory
78

89

910
class MainActivity : AppCompatActivity() {
@@ -25,7 +26,7 @@ class MainActivity : AppCompatActivity() {
2526

2627
catViewModel = ViewModelProvider(
2728
this,
28-
CatViewModel.CatsViewModelFactory(diContainer.serviceFact, diContainer.serviceImage)
29+
CatsViewModelFactory(diContainer.serviceFact, diContainer.serviceImage)
2930
)[CatViewModel::class.java]
3031

3132
view.viewModel = catViewModel
@@ -50,4 +51,4 @@ class MainActivity : AppCompatActivity() {
5051
// catsPresenter.onStop()
5152
super.onStop()
5253
}
53-
}
54+
}

app/src/main/java/otus/homework/coroutines/PresenterScope.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ class PresenterScope : CoroutineScope {
1010

1111
override val coroutineContext: CoroutineContext
1212
get() = Job() + Dispatchers.Main + CoroutineName("CatsCoroutine")
13-
}
13+
}

app/src/main/java/otus/homework/coroutines/Result.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ import otus.homework.coroutines.model.CatModel
55
sealed class Result {
66
data class Success(val catData: CatModel) : Result()
77
data class Error(val throwable: Throwable) : Result()
8-
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package otus.homework.coroutines.model
2+
3+
import androidx.lifecycle.ViewModel
4+
import androidx.lifecycle.ViewModelProvider
5+
import otus.homework.coroutines.CatViewModel
6+
import otus.homework.coroutines.CatsFactService
7+
import otus.homework.coroutines.CatsImageService
8+
9+
class CatsViewModelFactory(private val factService: CatsFactService,
10+
private val imageService: CatsImageService
11+
) : ViewModelProvider.Factory {
12+
@Suppress("UNCHECKED_CAST")
13+
override fun <T : ViewModel> create(modelClass: Class<T>): T {
14+
return CatViewModel(factService, imageService) as T
15+
}
16+
}

app/src/main/java/otus/homework/coroutines/model/Fact.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ data class Fact(
77
val fact: String,
88
@field:SerializedName("length")
99
val length: Int
10-
)
10+
)

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
app:layout_constraintEnd_toEndOf="parent"
3535
app:layout_constraintStart_toStartOf="parent"
3636
app:layout_constraintTop_toBottomOf="@+id/fact_textView" />
37-
</otus.homework.coroutines.CatsView>
37+
</otus.homework.coroutines.CatsView>

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ allprojects {
2323

2424
task clean(type: Delete) {
2525
delete rootProject.buildDir
26-
}
26+
}

0 commit comments

Comments
 (0)