-
Notifications
You must be signed in to change notification settings - Fork 0
アーキテクチャを適用 #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
アーキテクチャを適用 #25
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
07ee020
ref: ディレクトリ構成をfeature ファーストに変更
harutiro b13dd79
ref: ファイル名の変更
harutiro 0d52702
ref: ざっくりUsecaseとRepositoryを分けた
harutiro 63c9ca5
add: hiltの導入
harutiro 8286155
add: hiltの導入して依存性の注入を行った
harutiro 4d6da5b
ref:リンターのフォーマット
harutiro a25aefd
update: readmeのkotlinのバージョンを修正
harutiro 1a8355c
fix: エラーの表示の仕方を細かくした
harutiro 3078e68
fix: ネットワークチェックロジックの移動を行った
harutiro ef83d5f
fix: いらないcontextの排除
harutiro 71552bf
ref: リンターのフォーマットを通した
harutiro 7aa12af
fix: エラーの表示方法をstringのIDを渡すように変更
harutiro 9a7f330
ref: 使わなくなったviewModelの呼び出し方を削除
harutiro 0291ed4
ref: リンターの修正
harutiro 77249d4
ref: いらないcontextを削除した。
harutiro 46db2fc
ref: いらないcontextを削除した。
harutiro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
app/src/main/kotlin/jp/co/yumemi/android/code_check/CodeCheckApplication.kt
This file contains hidden or 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,7 @@ | ||
| package jp.co.yumemi.android.code_check | ||
|
|
||
| import android.app.Application | ||
| import dagger.hilt.android.HiltAndroidApp | ||
|
|
||
| @HiltAndroidApp | ||
| class CodeCheckApplication : Application() |
38 changes: 38 additions & 0 deletions
38
app/src/main/kotlin/jp/co/yumemi/android/code_check/CodeCheckModule.kt
This file contains hidden or 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,38 @@ | ||
| package jp.co.yumemi.android.code_check | ||
|
|
||
| import dagger.Binds | ||
| import dagger.Module | ||
| import dagger.Provides | ||
| import dagger.hilt.InstallIn | ||
| import dagger.hilt.components.SingletonComponent | ||
| import jp.co.yumemi.android.code_check.features.github.api.GitHubServiceApi | ||
| import jp.co.yumemi.android.code_check.features.github.api.GitHubServiceApiImpl | ||
| import jp.co.yumemi.android.code_check.features.github.reposiotory.GitHubServiceRepository | ||
| import jp.co.yumemi.android.code_check.features.github.reposiotory.GitHubServiceRepositoryImpl | ||
| import jp.co.yumemi.android.code_check.features.github.usecase.GitHubServiceUsecase | ||
| import jp.co.yumemi.android.code_check.features.github.usecase.GitHubServiceUsecaseImpl | ||
| import javax.inject.Singleton | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class GitHubUsecaseModule { | ||
| @Singleton | ||
| @Binds | ||
| abstract fun provideGitHubServiceUsecase(impl: GitHubServiceUsecaseImpl): GitHubServiceUsecase | ||
| } | ||
|
|
||
| @Module | ||
| @InstallIn(SingletonComponent::class) | ||
| abstract class GitHubRepositoryModule { | ||
| @Singleton | ||
| @Binds | ||
| abstract fun provideGitHubServiceRepository(impl: GitHubServiceRepositoryImpl): GitHubServiceRepository | ||
|
|
||
| companion object { | ||
| @Provides | ||
| @Singleton | ||
| fun provideGitHubServiceApi(): GitHubServiceApi { | ||
| return GitHubServiceApiImpl() | ||
| } | ||
| } | ||
| } |
52 changes: 0 additions & 52 deletions
52
app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
22 changes: 22 additions & 0 deletions
22
app/src/main/kotlin/jp/co/yumemi/android/code_check/core/api/NetworkConnectivityService.kt
This file contains hidden or 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,22 @@ | ||
| package jp.co.yumemi.android.code_check.core.api | ||
|
|
||
| import android.content.Context | ||
| import android.net.ConnectivityManager | ||
| import android.net.NetworkCapabilities | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class NetworkConnectivityService | ||
| @Inject | ||
| constructor( | ||
| @ApplicationContext private val context: Context, | ||
| ) { | ||
| fun isNetworkAvailable(): Boolean { | ||
| val connectivityManager = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager | ||
| val network = connectivityManager.activeNetwork ?: return false | ||
| val capabilities = connectivityManager.getNetworkCapabilities(network) ?: return false | ||
| return capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...memi/android/code_check/RepositoryItem.kt → .../code_check/core/entity/RepositoryItem.kt
This file contains hidden or 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
6 changes: 5 additions & 1 deletion
6
...id/code_check/RepositoryDetailFragment.kt → ...senter/detail/RepositoryDetailFragment.kt
This file contains hidden or 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 hidden or 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 hidden or 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
79 changes: 79 additions & 0 deletions
79
...kotlin/jp/co/yumemi/android/code_check/core/presenter/search/RepositorySearchViewModel.kt
This file contains hidden or 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,79 @@ | ||
| package jp.co.yumemi.android.code_check.core.presenter.search | ||
|
|
||
| import android.content.Context | ||
| import android.util.Log | ||
| import androidx.lifecycle.LiveData | ||
| import androidx.lifecycle.MutableLiveData | ||
| import androidx.lifecycle.ViewModel | ||
| import androidx.lifecycle.viewModelScope | ||
| import dagger.hilt.android.lifecycle.HiltViewModel | ||
| import jp.co.yumemi.android.code_check.R | ||
| import jp.co.yumemi.android.code_check.core.entity.RepositoryItem | ||
| import jp.co.yumemi.android.code_check.features.github.reposiotory.NetworkException | ||
| import jp.co.yumemi.android.code_check.features.github.usecase.GitHubServiceUsecase | ||
| import jp.co.yumemi.android.code_check.features.github.utils.GitHubError | ||
| import jp.co.yumemi.android.code_check.features.github.utils.NetworkResult | ||
| import kotlinx.coroutines.launch | ||
| import javax.inject.Inject | ||
|
|
||
| /** | ||
| * RepositorySearchFragmentで利用するリポジトリ検索用のViewModel | ||
| */ | ||
| @HiltViewModel | ||
| class RepositorySearchViewModel | ||
| @Inject | ||
| constructor( | ||
| private val networkRepository: GitHubServiceUsecase, | ||
| ) : ViewModel() { | ||
| private val _errorMessage = MutableLiveData<Int?>() | ||
| val errorMessage: LiveData<Int?> get() = _errorMessage | ||
|
|
||
| private val _searchResults = MutableLiveData<List<RepositoryItem>>() | ||
| val searchResults: LiveData<List<RepositoryItem>> get() = _searchResults | ||
|
|
||
| /** | ||
| * GitHubのレポジトリ検索を行う | ||
| * @param query 検索キーワード | ||
| * @param context コンテキスト | ||
| */ | ||
| fun searchRepositories( | ||
| query: String, | ||
| context: Context, | ||
| ) { | ||
harutiro marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if (query.isBlank()) { | ||
| _errorMessage.postValue(R.string.form_is_empty) | ||
| return | ||
| } | ||
| viewModelScope.launch { | ||
| try { | ||
| val results = networkRepository.fetchSearchResults(query) | ||
| if (results is NetworkResult.Error) { | ||
| handleError(results.exception) | ||
| return@launch | ||
| } | ||
| if (results is NetworkResult.Success) { | ||
| _searchResults.postValue(results.data) | ||
| } | ||
| } catch (e: NetworkException) { | ||
| Log.e("NetworkException", e.message, e) | ||
| handleError(GitHubError.NetworkError(e)) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * エラーが発生した時に、Viewに問題を表示するためのもの | ||
| * @param GitHubError エラー情報 | ||
| * @param context コンテキスト | ||
| */ | ||
| private fun handleError(error: GitHubError) { | ||
| _errorMessage.value = | ||
| when (error) { | ||
| is GitHubError.NetworkError -> R.string.network_error | ||
| is GitHubError.ApiError -> R.string.api_error | ||
| is GitHubError.ParseError -> R.string.parse_error | ||
| is GitHubError.RateLimitError -> R.string.rate_limit_error | ||
| is GitHubError.AuthenticationError -> R.string.auth_error | ||
| } | ||
| } | ||
| } | ||
2 changes: 1 addition & 1 deletion
2
...yumemi/android/code_check/DialogHelper.kt → ...oid/code_check/core/utils/DialogHelper.kt
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.