-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7750a64
commit 8122c28
Showing
12 changed files
with
140 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,5 +16,6 @@ class DogsApplication: Application() { | |
|
||
override fun onCreate() { | ||
super.onCreate() | ||
appComponent.inject(this) | ||
} | ||
} |
11 changes: 10 additions & 1 deletion
11
app/src/main/java/com/example/android/dogsapp/common/di/activity/ActivityComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,13 @@ | ||
package com.example.android.dogsapp.common.di.activity | ||
|
||
class ActivityComponent { | ||
import com.example.android.dogsapp.common.di.application.ApplicationComponent | ||
import com.example.android.dogsapp.ui.MainActivity | ||
import com.example.android.dogsapp.ui.main.MainFragment | ||
import dagger.Component | ||
|
||
@ActivityScope | ||
@Component(dependencies = [ApplicationComponent::class], modules = [ActivityModule::class]) | ||
interface ActivityComponent { | ||
fun inject(mainActivity: MainActivity) | ||
fun inject(mainFragment: MainFragment) | ||
} |
14 changes: 13 additions & 1 deletion
14
app/src/main/java/com/example/android/dogsapp/common/di/activity/ActivityModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,16 @@ | ||
package com.example.android.dogsapp.common.di.activity | ||
|
||
class ActivityModule { | ||
import com.example.android.dogsapp.ui.utils.RefreshManager | ||
import com.example.android.dogsapp.ui.utils.SwipeToRefreshManagerImpl | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
object ActivityModule { | ||
|
||
@Provides | ||
@ActivityScope | ||
fun provideRefreshManager(swipeToRefreshManagerImpl: SwipeToRefreshManagerImpl): RefreshManager { | ||
return swipeToRefreshManagerImpl | ||
} | ||
} |
6 changes: 5 additions & 1 deletion
6
app/src/main/java/com/example/android/dogsapp/common/di/application/ApplicationComponent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package com.example.android.dogsapp.common.di.application | ||
|
||
import com.example.android.dogsapp.DogsApplication | ||
import com.example.android.dogsapp.data.repository.DogsRepository | ||
import com.example.android.dogsapp.ui.MainActivity | ||
import com.example.android.dogsapp.ui.main.MainFragment | ||
import dagger.Component | ||
|
||
@ApplicationScope | ||
@Component(modules = [ApplicationModule::class]) | ||
interface ApplicationComponent { | ||
fun inject(mainFragment: MainFragment) | ||
fun inject(application: DogsApplication) | ||
|
||
fun inject(mainActivity: MainActivity) | ||
|
||
fun dogsRepository(): DogsRepository | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/example/android/dogsapp/ui/utils/RefreshManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.example.android.dogsapp.ui.utils | ||
|
||
interface RefreshManager { | ||
fun isRefreshing(): Boolean | ||
fun setRefreshing(refreshing: Boolean) | ||
fun setOnRefreshListener(listener: () -> Unit) | ||
fun onRefreshTriggered() | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/example/android/dogsapp/ui/utils/SwipeToRefreshManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.example.android.dogsapp.ui.utils | ||
|
||
import javax.inject.Inject | ||
|
||
class SwipeToRefreshManagerImpl @Inject constructor() : RefreshManager { | ||
|
||
private var isRefreshing = false | ||
private var refreshListener: (() -> Unit)? = null | ||
|
||
override fun isRefreshing() = isRefreshing | ||
|
||
override fun setRefreshing(refreshing: Boolean) { | ||
isRefreshing = refreshing | ||
} | ||
|
||
override fun setOnRefreshListener(listener: () -> Unit) { | ||
refreshListener = listener | ||
} | ||
|
||
override fun onRefreshTriggered() { | ||
if (!isRefreshing) { | ||
isRefreshing = true | ||
refreshListener?.invoke() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters