Skip to content

Commit 26a1d87

Browse files
author
Edd
committed
finalized dagger 🗡️
establishing forecast fixed 🩹 some bugs 🦟 increased my chance of finishing at time
1 parent cea48df commit 26a1d87

File tree

96 files changed

+1235
-59
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+1235
-59
lines changed

.idea/vcs.xml

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

app/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ dependencies {
4646
implementation Deps.constraint
4747
implementation Deps.coordinator
4848
implementation Deps.recyclerView
49+
implementation Deps.swipeRefreshLayout
4950
implementation Deps.design
5051
implementation Deps.cardview
5152
implementation Deps.core
5253
implementation Deps.coroutines
54+
55+
//lifecycle
5356
implementation Deps.viewmodel
57+
implementation Deps.lifecycle
5458

5559
// Network
5660
implementation Deps.retrofit
@@ -60,11 +64,13 @@ dependencies {
6064
implementation Deps.okhttpLoggingInterceptor
6165

6266
// Dependency injection
67+
implementation Deps.dagger
6368
implementation Deps.daggerAndroidSupport
6469
kapt Deps.daggerCompiler
6570
kapt Deps.daggerAndroidProcessor
6671

6772
testImplementation Deps.mockk
73+
testImplementation Deps.mockito
6874
testImplementation Deps.junit
6975

7076

app/src/main/AndroidManifest.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="com.github.amazingweather">
33

4+
<uses-permission android:name="android.permission.INTERNET" />
5+
46
<application
57
android:name="App"
68
android:allowBackup="true"
@@ -10,7 +12,14 @@
1012
android:supportsRtl="true"
1113
android:theme="@style/AppTheme">
1214

13-
<activity android:name=".presentation.ContainerActivity" />
15+
<activity android:name=".presentation.FragmentContainerActivity">
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
<category android:name="android.intent.category.DEFAULT" />
21+
</intent-filter>
22+
</activity>
1423

1524
</application>
1625
</manifest>
Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
package com.github.amazingweather
22

3-
import android.app.Application
3+
import com.github.amazingweather.di.DaggerAppComponent
4+
import dagger.android.AndroidInjector
5+
import dagger.android.DaggerApplication
6+
7+
class App : DaggerApplication() {
8+
9+
override fun onCreate() {
10+
super.onCreate()
11+
12+
}
13+
14+
override fun applicationInjector(): AndroidInjector<out DaggerApplication> {
15+
return DaggerAppComponent.builder().application(this).build()
16+
}
417

5-
class App : Application() {
618
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.github.amazingweather.core
2+
3+
import androidx.core.os.bundleOf
4+
import androidx.fragment.app.Fragment
5+
import androidx.lifecycle.LiveData
6+
import androidx.lifecycle.Observer
7+
import androidx.lifecycle.ViewModelProvider.Factory
8+
import androidx.lifecycle.ViewModel
9+
import androidx.lifecycle.ViewModelProvider
10+
import com.github.amazingweather.presentation.ViewModelFactory
11+
12+
fun <T : Any, L : LiveData<T>> Fragment.observe(liveData: L, body: (T) -> Unit) {
13+
liveData.observe(viewLifecycleOwner, Observer(body))
14+
}
15+
16+
inline fun <reified T : Fragment> newFragment(vararg params: Pair<String, Any>): T {
17+
return T::class.java.newInstance().apply {
18+
arguments = bundleOf(*params)
19+
}
20+
}
21+
22+
inline fun <reified T> Fragment.args(key: String, default: T) = lazy {
23+
(arguments?.get(key) ?: default) as T
24+
}

app/src/main/java/com/github/amazingweather/domain/DataLoaderUseCase.kt renamed to app/src/main/java/com/github/amazingweather/core/UseCase.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
package com.github.amazingweather.domain
1+
package com.github.amazingweather.core
22

33
import android.util.Log
4-
import com.github.amazingweather.core.EitherErrorOr
5-
import com.github.amazingweather.core.Result
64
import kotlinx.coroutines.*
75

86
/**
@@ -12,7 +10,7 @@ Built using Kotlin Coroutines for easy context switching.
1210
Main purpose to communicate with data layer however it can also be use as a switch between bg and ui threads
1311
*/
1412

15-
abstract class DataLoaderUseCase<ParamsType, ResultType> {
13+
abstract class UseCase<ParamsType, ResultType> {
1614

1715
private var parent: Job = SupervisorJob()
1816
private lateinit var scope: CoroutineScope
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package com.github.amazingweather.data
2+
3+
object DataHolder {
4+
val citiesId = mutableListOf<Int>(524901, 703448, 2643743)
5+
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.amazingweather.data
2+
3+
object Keys {
4+
const val EXTRA_ID = "EXTRA_ID"
5+
6+
fun getImageUrl(icon: String) = "https://openweathermap.org/img/wn/${icon}@2x.png"
7+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.github.amazingweather.di
2+
3+
import android.app.Application
4+
import com.github.amazingweather.di.module.ActivityBindingModule
5+
import com.github.amazingweather.di.module.AppModule
6+
import com.github.amazingweather.di.module.NetworkModule
7+
import com.github.amazingweather.di.module.ViewModelModule
8+
import com.github.amazingweather.di.scope.AppScoped
9+
import dagger.BindsInstance
10+
import dagger.Component
11+
import dagger.android.AndroidInjector
12+
import dagger.android.DaggerApplication
13+
import dagger.android.support.AndroidSupportInjectionModule
14+
15+
@AppScoped
16+
@Component(
17+
modules = [
18+
AppModule::class,
19+
ActivityBindingModule::class,
20+
AndroidSupportInjectionModule::class,
21+
ViewModelModule::class,
22+
NetworkModule::class
23+
]
24+
)
25+
interface AppComponent : AndroidInjector<DaggerApplication> {
26+
27+
@Component.Builder
28+
interface Builder {
29+
30+
@BindsInstance
31+
fun application(application: Application): Builder
32+
33+
fun build(): AppComponent
34+
}
35+
36+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.github.amazingweather.di
2+
3+
import androidx.lifecycle.ViewModel
4+
import dagger.MapKey
5+
import kotlin.reflect.KClass
6+
7+
@kotlin.annotation.Target(AnnotationTarget.FUNCTION)
8+
@Retention(AnnotationRetention.RUNTIME)
9+
@MapKey
10+
internal annotation class ViewModelKey(val value: KClass<out ViewModel>)

0 commit comments

Comments
 (0)