Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from Husseinhj/imp/use_depenency_injection
Use Koin Dependency Injection
- Loading branch information
Showing
27 changed files
with
310 additions
and
172 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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/github/husseinhj/githubuser/ApplicationClass.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.github.husseinhj.githubuser | ||
|
||
import android.app.Application | ||
import org.koin.core.context.startKoin | ||
import org.koin.android.ext.koin.androidLogger | ||
import org.koin.android.ext.koin.androidContext | ||
import com.github.husseinhj.githubuser.modules.* | ||
|
||
class ApplicationClass : Application() { | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
startKoin { | ||
androidLogger() | ||
androidContext(this@ApplicationClass) | ||
modules(listOf( | ||
applicationModule, | ||
repositoryModules, | ||
viewModelModules, | ||
webServiceModules, | ||
retrofitModule | ||
)) | ||
} | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
app/src/main/java/com/github/husseinhj/githubuser/adapters/UserSearchResultAdapter.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
26 changes: 26 additions & 0 deletions
26
app/src/main/java/com/github/husseinhj/githubuser/bases/BaseAppCompatActivity.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.github.husseinhj.githubuser.bases | ||
|
||
import android.view.Menu | ||
import com.github.husseinhj.githubuser.R | ||
import org.koin.android.ext.android.inject | ||
import org.koin.core.parameter.parametersOf | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.github.husseinhj.githubuser.utils.ToolbarAppearance | ||
|
||
open class BaseAppCompatActivity: AppCompatActivity() { | ||
private val toolbarAppearance: ToolbarAppearance by inject { | ||
parametersOf(this, R.menu.main_menu) | ||
} | ||
|
||
override fun onCreateOptionsMenu(menu: Menu): Boolean { | ||
toolbarAppearance.configureSearchBarByMenu(menu) | ||
|
||
return super.onCreateOptionsMenu(menu) | ||
} | ||
|
||
override fun onBackPressed() { | ||
if (!toolbarAppearance.collapseSearchBar()) { | ||
super.onBackPressed() | ||
} | ||
} | ||
} |
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
3 changes: 3 additions & 0 deletions
3
app/src/main/java/com/github/husseinhj/githubuser/consts/Const.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
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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/com/github/husseinhj/githubuser/modules/DIApplicationModule.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,17 @@ | ||
package com.github.husseinhj.githubuser.modules | ||
|
||
import org.koin.dsl.module | ||
import com.github.husseinhj.githubuser.utils.ToolbarAppearance | ||
import com.github.husseinhj.githubuser.utils.NavigationAppearance | ||
|
||
val applicationModule = module { | ||
// Toolbar | ||
single { | ||
ToolbarAppearance(get(), get()) | ||
} | ||
|
||
// Navigation | ||
factory { | ||
NavigationAppearance(get()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/github/husseinhj/githubuser/modules/RepositoryModules.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,15 @@ | ||
package com.github.husseinhj.githubuser.modules | ||
|
||
import org.koin.dsl.module | ||
import com.github.husseinhj.githubuser.services.repositories.UserRepository | ||
import com.github.husseinhj.githubuser.services.repositories.SearchRepository | ||
|
||
val repositoryModules = module { | ||
single { | ||
UserRepository(get()) | ||
} | ||
|
||
single { | ||
SearchRepository(get()) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/com/github/husseinhj/githubuser/modules/RetrofitModules.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,14 @@ | ||
package com.github.husseinhj.githubuser.modules | ||
|
||
import org.koin.dsl.module | ||
import com.google.gson.GsonBuilder | ||
import com.github.husseinhj.githubuser.services.providers.getRetrofit | ||
import com.github.husseinhj.githubuser.services.providers.retrofitHttpClient | ||
import com.github.husseinhj.githubuser.services.interceptors.AuthenticationInterceptor | ||
|
||
val retrofitModule = module { | ||
single { getRetrofit() } | ||
single { retrofitHttpClient() } | ||
single { GsonBuilder().create() } | ||
single { AuthenticationInterceptor() } | ||
} |
30 changes: 30 additions & 0 deletions
30
app/src/main/java/com/github/husseinhj/githubuser/modules/ViewModelModules.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,30 @@ | ||
package com.github.husseinhj.githubuser.modules | ||
|
||
import org.koin.dsl.module | ||
import org.koin.androidx.viewmodel.dsl.viewModel | ||
import com.github.husseinhj.githubuser.viewmodels.fragments.HomeViewModel | ||
import com.github.husseinhj.githubuser.viewmodels.fragments.SearchUserViewModel | ||
import com.github.husseinhj.githubuser.viewmodels.fragments.UserDetailViewModel | ||
import com.github.husseinhj.githubuser.viewmodels.activities.MainActivityViewModel | ||
|
||
val viewModelModules = module { | ||
// Main Activity ViewModel | ||
viewModel { | ||
MainActivityViewModel() | ||
} | ||
|
||
// On-Boarding ViewModel | ||
viewModel { | ||
HomeViewModel() | ||
} | ||
|
||
// Search User ViewModel | ||
viewModel { | ||
SearchUserViewModel(get(), get()) | ||
} | ||
|
||
// User Profile ViewModel | ||
viewModel { | ||
UserDetailViewModel(get(), get()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/com/github/husseinhj/githubuser/modules/WebServiceModules.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,15 @@ | ||
package com.github.husseinhj.githubuser.modules | ||
|
||
import com.github.husseinhj.githubuser.services.repositories.SearchRepository | ||
import com.github.husseinhj.githubuser.services.repositories.UserRepository | ||
import retrofit2.Retrofit | ||
import org.koin.dsl.module | ||
import com.github.husseinhj.githubuser.services.repositories.interfaces.IUserRepository | ||
import com.github.husseinhj.githubuser.services.repositories.interfaces.ISearchRepository | ||
|
||
val webServiceModules = module { | ||
single(createdAtStart = false) { get<Retrofit>().create(IUserRepository::class.java) } | ||
single(createdAtStart = false) { get<Retrofit>().create(ISearchRepository::class.java) } | ||
single { UserRepository(get()) } | ||
single { SearchRepository(get()) } | ||
} |
Oops, something went wrong.