Skip to content

Conversation

@harutiro
Copy link
Owner

@harutiro harutiro commented Jan 19, 2025

概要

HTTPクライアントがかなり使いずらいのでRetrofitに変更する
現状はJsonのパース関係もかなりやりずらいので適応をする

関連Issue

このセクションでは、このPRが関連するIssueやタスクをリンクしてください。以下のように記述します。

変更点

このセクションでは、具体的な変更点や修正箇所を箇条書きでリストアップしてください。

  • kotlinのバージョンを1.9に上げる
  • Retrofitの導入

テスト

このセクションでは、このPRに関連するテストケースやテスト方法を記載してください。

  • 検索をする
  • オフラインで検索をする
  • 空欄で検索をする
  • 詳細を見る

Summary by CodeRabbit

  • 新機能

    • Retrofit と Moshi を使用したネットワーク通信機能の追加
    • GitHub リポジトリ検索 API の実装
    • ネットワーク接続情報へのアクセス権限を追加
    • 新しいインターフェースとデータクラスの導入
    • ネットワーク結果を管理するための新しいクラスとエラー処理の追加
  • 依存関係の更新

    • Retrofit、Moshi、OkHttp のライブラリバージョンを更新
    • Kotlin Gradle プラグインを 1.6.21 から 1.9.0 にアップグレード
  • リファクタリング

    • ネットワーク通信の実装方法を刷新
    • エラーハンドリングの改善
    • 不要なクラスの削除

@coderabbitai
Copy link

coderabbitai bot commented Jan 19, 2025

"""

Walkthrough

このプルリクエストは、Android アプリケーションのネットワーク層を Retrofit と Moshi を使用して再設計します。新しい NetworkRepository クラスが導入され、GitHub API からリポジトリを検索するためのインターフェースとエンティティが追加されました。また、ビルド設定の更新や依存関係の追加が行われ、アプリケーションのネットワーク機能が強化されています。

Changes

ファイル 変更の概要
app/build.gradle buildConfig true を追加し、Retrofit、Moshi、OkHttp のライブラリ依存関係を追加
build.gradle Kotlin Gradle プラグインのバージョンを 1.6.21 から 1.9.0 に更新
app/src/main/kotlin/jp/co/yumemi/android/code_check/NetworkRepository.kt 新しいネットワークリポジトリの実装、Retrofit を使用した API 呼び出し
app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt searchRepositories メソッドに appContext パラメータを追加し、エラーハンドリングを強化
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApi.kt GitHub リポジトリ検索のためのインターフェース追加
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiBuilderInterface.kt GitHub API へのネットワーク呼び出しのためのインターフェース追加
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt GitHubRepositoryApi インターフェースの実装を追加
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/entity/GitHubRepositoryEntity.kt リポジトリデータのエンティティクラスを追加
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt 新しいネットワークリポジトリの実装、API 呼び出しとエラーハンドリングの追加
app/src/main/AndroidManifest.xml ネットワーク状態にアクセスするためのパーミッションを追加

Possibly related PRs

Poem

🐰 コードの旅路、新たな道
Retrofit と Moshi が導く光
古き HTTP、さようなら
型安全の世界へと飛躍
うさぎジャンプ、コードは進む! 🚀
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 934e1c0 and e9e81e1.

📒 Files selected for processing (1)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 6

🧹 Nitpick comments (7)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApi.kt (1)

5-7: 戻り値の型についての提案

Response<RepositoryList> を戻り値として使用することで、HTTPステータスコードやヘッダー情報にアクセスできるようになり、より詳細なエラーハンドリングが可能になります。

interface GitHubRepositoryApi {
-    suspend fun getRepository(searchWord: String): RepositoryList
+    suspend fun getRepository(searchWord: String): Response<RepositoryList>
}
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiBuilderInterface.kt (1)

8-13: GitHub APIのレート制限への対応

GitHub APIにはレート制限があるため、以下の対応を推奨します:

  • レスポンスヘッダーから制限情報を取得
  • 制限に近づいた際のハンドリング
  • キャッシュの実装
interface RateLimitHandler {
    fun handleRateLimit(response: Response<*>)
    fun getRemainingRequests(): Int
    fun isRateLimited(): Boolean
}
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/entity/GitHubRepositoryEntity.kt (1)

5-17: KDocドキュメントの追加を推奨

データクラスの各プロパティの意味や制約を明確にするため、KDocドキュメントの追加を推奨します。特に:

  • 各フィールドの説明
  • nullableな値の意味
  • 数値フィールドの範囲や制約
/**
 * GitHubリポジトリの検索結果を表現するデータクラス
 * @property items 検索結果のリポジトリリスト
 */
data class RepositoryList(
    val items: List<RepositoryItem>,
)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1)

34-34: 例外クラスの改善

より詳細なエラーハンドリングのため、具体的なエラー型の定義を推奨します。

sealed class NetworkException(message: String, cause: Throwable? = null) : Exception(message, cause) {
    class JsonParsingException(cause: Throwable? = null) : 
        NetworkException("JSON解析エラー", cause)
    class NetworkConnectionException(cause: Throwable? = null) : 
        NetworkException("ネットワークエラー", cause)
    class RateLimitException : 
        NetworkException("APIレート制限に達しました")
}
app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (2)

18-18: NetworkRepositoryの初期化設定を検討する必要があります

デフォルト設定でNetworkRepositoryを初期化していますが、タイムアウトやリトライなどの設定オプションを提供することを検討してください。

-    private val networkRepository = NetworkRepository()
+    private val networkRepository = NetworkRepository(
+        connectTimeout = 30L,
+        readTimeout = 30L,
+        retryCount = 3
+    )

40-41: エラーメッセージの国際化対応が必要です

エラーメッセージがハードコードされています。strings.xmlを使用して多言語対応することを推奨します。

-                Log.e("NetworkException", e.message, e)
-                _errorMessage.postValue(e.message)
+                Log.e(TAG, "Network error occurred", e)
+                _errorMessage.postValue(context.getString(R.string.network_error_message))
app/build.gradle (1)

67-70: 依存関係のバージョン管理の改善が必要です

  1. バージョン番号をバージョンカタログまたは変数として定義することを推奨します
  2. 依存関係の更新を容易にするため、バージョン制約をより柔軟にすることを検討してください
+    ext {
+        retrofit_version = "2.11.0"
+        moshi_version = "1.14.0"
+        okhttp_version = "4.12.0"
+    }
+
-    implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
-    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
-    implementation("com.squareup.retrofit2:retrofit:2.11.0")
-    implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
+    implementation("com.squareup.retrofit2:converter-moshi:$retrofit_version")
+    implementation("com.squareup.okhttp3:logging-interceptor:$okhttp_version")
+    implementation("com.squareup.retrofit2:retrofit:$retrofit_version")
+    implementation("com.squareup.moshi:moshi-kotlin:$moshi_version")
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9c0dc1d and e7f1f91.

📒 Files selected for processing (9)
  • app/build.gradle (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/NetworkRepository.kt (0 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (2 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApi.kt (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiBuilderInterface.kt (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/entity/GitHubRepositoryEntity.kt (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1 hunks)
  • build.gradle (1 hunks)
💤 Files with no reviewable changes (1)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/NetworkRepository.kt
🧰 Additional context used
📓 Learnings (1)
app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (4)
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt:34-48
Timestamp: 2025-01-08T13:51:57.413Z
Learning: The error handling implementation in RepositorySearchViewModel is planned to be addressed in a separate PR to maintain focused changes and better code review process.
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#17
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchFragment.kt:70-70
Timestamp: 2025-01-19T18:29:34.699Z
Learning: In Android MVVM architecture, input validation like empty search query checks should be handled in the ViewModel (e.g., RepositorySearchViewModel.searchRepositories) rather than in the Fragment, following proper separation of concerns. The ViewModel can communicate validation errors back to the Fragment through LiveData.
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt:31-33
Timestamp: 2025-01-08T14:03:34.415Z
Learning: In Android/Kotlin ViewModels, HttpClient instances should be managed as ViewModel properties and properly closed in onCleared() rather than creating new instances for each request, to improve resource utilization and performance.
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchFragment.kt:35-35
Timestamp: 2025-01-08T13:52:10.282Z
Learning: ViewModelの初期化方法の改善など、アーキテクチャに関する変更は、コードの可読性向上とは別のPRで対応することが望ましい。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (5)
app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (1)

19-19: 依存性注入の導入を推奨します

NetworkRepositoryのインスタンス化を直接行うのではなく、依存性注入を使用することでテスト容易性が向上します。

-    private val networkRepository = NetworkRepository()
+    private val networkRepository: NetworkRepository
+
+    constructor(
+        application: Application,
+        networkRepository: NetworkRepository = NetworkRepository()
+    ) : super(application) {
+        this.networkRepository = networkRepository
+    }
app/build.gradle (1)

67-71: 依存関係のバージョン管理の改善を推奨します

Retrofitと関連ライブラリのバージョンを変数として定義し、一元管理することを推奨します。

+    ext {
+        retrofit_version = "2.11.0"
+        moshi_version = "1.14.0"
+        okhttp_version = "4.12.0"
+    }
+
     // Retrofit
-    implementation("com.squareup.retrofit2:converter-moshi:2.9.0")
-    implementation("com.squareup.okhttp3:logging-interceptor:4.12.0")
-    implementation("com.squareup.retrofit2:retrofit:2.11.0")
-    implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
+    implementation("com.squareup.retrofit2:converter-moshi:$retrofit_version")
+    implementation("com.squareup.okhttp3:logging-interceptor:$okhttp_version")
+    implementation("com.squareup.retrofit2:retrofit:$retrofit_version")
+    implementation("com.squareup.moshi:moshi-kotlin:$moshi_version")
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt (1)

14-41: シングルトンパターンの実装を推奨します

companion objectのプロパティをprivateにし、適切なシングルトンパターンを実装することを推奨します。

     companion object {
-        val client =
+        private val client =
-        val moshi =
+        private val moshi =
-        val weatherService =
+        private val githubService =
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (2)

17-19: 依存性注入の実装をさらに改善できます

デフォルト値を提供する代わりに、依存性を必須とすることで、より明示的な依存関係を作成できます。

-class NetworkRepository(
-    private val gitHubRepositoryApi: GitHubRepositoryApi = GitHubRepositoryApiImpl(),
-) {
+class NetworkRepository(private val gitHubRepositoryApi: GitHubRepositoryApi) {

35-35: nullの扱いを改善できます

言語がnullの場合に"none"を使用していますが、より明示的な値を使用することを推奨します。

-                        language = item.language ?: "none",
+                        language = item.language ?: "Not specified",
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e7f1f91 and 9f7ee97.

📒 Files selected for processing (5)
  • app/build.gradle (2 hunks)
  • app/src/main/AndroidManifest.xml (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (2 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt (1 hunks)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1 hunks)
🧰 Additional context used
📓 Learnings (3)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt (1)
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#20
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt:13-14
Timestamp: 2025-01-19T20:47:28.451Z
Learning: In Android applications using HttpLoggingInterceptor (OkHttp/Retrofit), the log level should be configured based on the build type using BuildConfig.DEBUG to prevent sensitive information leakage in production:
```kotlin
logging.level = if (BuildConfig.DEBUG) {
    HttpLoggingInterceptor.Level.BODY
} else {
    HttpLoggingInterceptor.Level.NONE
}

</details>
<details>
<summary>app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (4)</summary>

Learnt from: harutiro
PR: #12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt:34-48
Timestamp: 2025-01-08T13:51:57.413Z
Learning: The error handling implementation in RepositorySearchViewModel is planned to be addressed in a separate PR to maintain focused changes and better code review process.


Learnt from: harutiro
PR: #17
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchFragment.kt:70-70
Timestamp: 2025-01-19T18:29:34.699Z
Learning: In Android MVVM architecture, input validation like empty search query checks should be handled in the ViewModel (e.g., RepositorySearchViewModel.searchRepositories) rather than in the Fragment, following proper separation of concerns. The ViewModel can communicate validation errors back to the Fragment through LiveData.


Learnt from: harutiro
PR: #12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt:31-33
Timestamp: 2025-01-08T14:03:34.415Z
Learning: In Android/Kotlin ViewModels, HttpClient instances should be managed as ViewModel properties and properly closed in onCleared() rather than creating new instances for each request, to improve resource utilization and performance.


Learnt from: harutiro
PR: #12
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchFragment.kt:35-35
Timestamp: 2025-01-08T13:52:10.282Z
Learning: ViewModelの初期化方法の改善など、アーキテクチャに関する変更は、コードの可読性向上とは別のPRで対応することが望ましい。


</details>
<details>
<summary>app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (3)</summary>

Learnt from: harutiro
PR: #20
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt:11-31
Timestamp: 2025-01-19T20:33:29.369Z
Learning: In Android applications, network connectivity can be checked using ConnectivityManager. For Android M (API 23) and above, use NetworkCapabilities API, and for older versions, use NetworkInfo API. The ACCESS_NETWORK_STATE permission is required in AndroidManifest.xml.


Learnt from: harutiro
PR: #20
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt:8-10
Timestamp: 2025-01-19T20:47:21.710Z
Learning: In the Android application, dependency injection is preferred over direct instantiation to improve testability and flexibility. This applies particularly to service/repository classes like NetworkRepository that depend on other services or APIs.


Learnt from: harutiro
PR: #18
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/NetworkRepository.kt:0-0
Timestamp: 2025-01-19T19:23:10.771Z
Learning: In the Android app for jp.co.yumemi.android.code_check, when throwing custom exceptions like NetworkException, preserve the original exception cause by passing it as a parameter to maintain the error chain for better debugging and logging.


</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (4)</summary><blockquote>

<details>
<summary>app/src/main/AndroidManifest.xml (1)</summary>

`4-4`: **適切なパーミッションが追加されています!**

`ACCESS_NETWORK_STATE`パーミッションの追加は、ネットワーク接続状態の確認に必要で適切です。

</details>
<details>
<summary>app/src/main/kotlin/jp/co/yumemi/android/code_check/RepositorySearchViewModel.kt (1)</summary>

Line range hint `33-45`: **エラーハンドリングの実装が適切です!**

空の入力チェックとネットワークエラーの処理が適切に実装されています。

</details>
<details>
<summary>app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/api/GitHubRepositoryApiImpl.kt (1)</summary>

`43-54`: **エラーハンドリングの実装が適切です!**

HTTPステータスコードに応じた適切なエラーメッセージの提供が実装されています。

</details>
<details>
<summary>app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1)</summary>

`11-15`: **NetworkResultの実装が適切です!**

シールドクラスを使用した結果のラッピングは、型安全な方法でネットワーク操作の結果を処理できます。

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (2)

11-15: NetworkResultにLoadingステートの追加を推奨

非同期処理の状態をより適切に表現するため、Loadingステートの追加を検討してください。これにより、ユーザーインターフェースでローディング状態を適切に表示できます。

sealed class NetworkResult<out T> {
    data class Success<T>(val data: T) : NetworkResult<T>()
    data class Error(val exception: NetworkException) : NetworkResult<Nothing>()
+   object Loading : NetworkResult<Nothing>()
}

20-44: エラーメッセージのリソース化を推奨

エラーメッセージをstrings.xmlリソースとして外部化することで、多言語対応と保守性が向上します。

- return NetworkResult.Error(NetworkException("オフライン状態です"))
+ return NetworkResult.Error(NetworkException(context.getString(R.string.error_offline)))

- NetworkResult.Error(NetworkException("JSONパースエラー", e))
+ NetworkResult.Error(NetworkException(context.getString(R.string.error_json_parse), e))

- NetworkResult.Error(NetworkException("ネットワークエラー", e))
+ NetworkResult.Error(NetworkException(context.getString(R.string.error_network), e))

strings.xmlに追加するリソース:

<resources>
    <string name="error_offline">オフライン状態です</string>
    <string name="error_json_parse">JSONパースエラー</string>
    <string name="error_network">ネットワークエラー</string>
</resources>
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fad1c21 and 934e1c0.

📒 Files selected for processing (1)
  • app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (1 hunks)
🧰 Additional context used
📓 Learnings (1)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (3)
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#20
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt:11-31
Timestamp: 2025-01-19T20:33:29.369Z
Learning: In Android applications, network connectivity can be checked using ConnectivityManager. For Android M (API 23) and above, use NetworkCapabilities API, and for older versions, use NetworkInfo API. The ACCESS_NETWORK_STATE permission is required in AndroidManifest.xml.
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#20
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt:8-10
Timestamp: 2025-01-19T20:47:21.710Z
Learning: In the Android application, dependency injection is preferred over direct instantiation to improve testability and flexibility. This applies particularly to service/repository classes like NetworkRepository that depend on other services or APIs.
Learnt from: harutiro
PR: harutiro/android-engineer-codecheck#18
File: app/src/main/kotlin/jp/co/yumemi/android/code_check/NetworkRepository.kt:0-0
Timestamp: 2025-01-19T19:23:10.771Z
Learning: In the Android app for jp.co.yumemi.android.code_check, when throwing custom exceptions like NetworkException, preserve the original exception cause by passing it as a parameter to maintain the error chain for better debugging and logging.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: gradle
🔇 Additional comments (3)
app/src/main/kotlin/jp/co/yumemi/android/code_check/features/github/reposiotory/NetworkRepository.kt (3)

17-19: 依存性注入のベストプラクティスに従う

コンストラクタでのデフォルト実装は、テスト容易性と柔軟性を低下させます。依存性注入のベストプラクティスに従い、デフォルト実装を削除することを推奨します。

class NetworkRepository(
-   private val gitHubRepositoryApi: GitHubRepositoryApi = GitHubRepositoryApiImpl(),
+   private val gitHubRepositoryApi: GitHubRepositoryApi,
)

46-52: ネットワーク接続チェックの実装が適切です

ConnectivityManagerを使用したネットワーク接続チェックの実装が、Androidのベストプラクティスに従っており、適切に実装されています。


55-55: 例外チェーンの保持が適切です

NetworkExceptionクラスがcauseパラメータを適切に保持しており、デバッグとロギングのための例外チェーンが維持されています。

@harutiro harutiro merged commit 52aea43 into develop Jan 19, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants