Skip to content

iOS/watchOS版ウィジェットと同じ体裁のホーム画面ウィジェットをAndroidに追加 - #6569

Merged
TinyKitten merged 2 commits into
devfrom
claude/android-widget-implementation-jc2yaf
Aug 6, 2026
Merged

TinyKitten merged 2 commits into
devfrom
claude/android-widget-implementation-jc2yaf

Conversation

@TinyKitten

@TinyKitten TinyKitten commented Aug 6, 2026 •

Copy link
Copy Markdown
Member

概要

iOS のロック画面ウィジェット(LockScreenWidget)と watchOS のコンプリケーション(WatchWidget)に相当するホーム画面ウィジェットを Android に追加しました。表示内容・レイアウトは iOS/watchOS 版を踏襲し、ウィジェットのサイズに応じて iOS の 3 つの accessory family 相当のレイアウトを出し分けます。

レイアウト iOS/watchOS 相当 表示内容
widget_ride_circular accessoryCircular 路線色でストロークした円 + 路線記号
widget_ride_inline accessoryInline 路線色バー + 「○○線に乗車中」
widget_ride_rectangular accessoryRectangular 角丸の路線色バー + 路線名(太字) + 方面

未乗車時のプレースホルダー(路線が未設定です / 方面が未設定です / 記号 ? / 色 #277BC0)と、路線記号を持たない路線で路線名の先頭 1 文字を代替表示する挙動も iOS 版に合わせています。

データ経路は iOS と異なります。iOS は LiveActivityModule がライブアクティビティ更新のついでに App Group の UserDefaults へ書き込んでいますが、Android のライブアップデート(LiveUpdateModule)は Android 16 (API 36) 以降専用のため、それより前の OS でもウィジェットが動くよう更新経路を独立させています。

変更の種類

  • バグ修正
  • 新機能
  • リファクタリング
  • ドキュメント
  • CI/CD
  • その他

変更内容

  • RideWidgetProvider: AppWidgetProvider 実装。onUpdate / onAppWidgetOptionsChanged でウィジェットの実サイズ(OPTION_APPWIDGET_MIN_WIDTH / MIN_HEIGHT)を見て円形・1 行・横長のレイアウトを選択し、タップでアプリを起動する PendingIntent と contentDescription を設定
  • WidgetStateStore: 表示内容を SharedPreferences へ保存。アプリのプロセスが落ちていても AppWidgetProvider から読めるようにするため。差分がある場合のみ保存+再描画を行い、無変化の更新でブロードキャストを投げない(iOS 版の lastWidgetState と同じ考え方)
  • WidgetModule: JS から表示内容を更新する React Native ブリッジ。TrainLCDPackage へ登録
  • レイアウト 3 種・drawable 4 種を追加。背景と文字色は values / values-night でライト/ダーク両対応、角丸は Android 12 以降でランチャー既定値(system_app_widget_background_radius)へ追従
  • AndroidManifest.xml に RideWidgetProvider の receiver と @xml/ride_widget_info を追加
  • 文言(widget_description / widget_line_not_set / widget_destination_not_set / widget_riding_on)を日本語(values)・英語(values-en)で追加。iOS の Localizable.strings と同一文言
  • src/utils/native/android/widgetModule.ts: ネイティブモジュールのラッパー(Android 以外では no-op)と、その単体テストを追加
  • useUpdateLiveActivities: 乗車開始時・更新時に updateWidget、降車時に clearWidget を呼ぶよう追加

テスト

npm run lint / npm test / npm run typecheck をローカルで実行し、いずれも成功しています(npm test: 208 suites / 2195 tests passed)。

加えて、Android SDK 36 + JDK 17 を用意して ./gradlew :app:compileDevDebugKotlin を実行し BUILD SUCCESSFUL を確認しました。processDevDebugResources を通過しているため、追加したレイアウト・drawable・manifest の receiver 定義もリソース処理レベルで検証済みです。

  • npm run lint が通ること
  • npm test が通ること
  • npm run typecheck が通ること

関連Issue

スクリーンショット(任意)

作業環境にエミュレータ/実機がないため未取得です。マージ前に実機(例: Pixel 8)で 1x1・2x1・4x1 の各サイズとライト/ダークテーマの見た目確認をお願いします。


Generated by Claude Code

Summary by CodeRabbit

  • 新機能

    • Androidのホーム画面に、乗車中の路線・路線記号・行き先を表示するウィジェットを追加しました。
    • ウィジェットのサイズに応じて表示レイアウトを自動調整します。
    • ライブ表示の開始・更新・終了に合わせて、ウィジェットの内容を自動更新・消去します。
    • ウィジェットからアプリを起動できます。
    • ライトテーマとダークテーマ、アクセシビリティに対応しました。
  • テスト

    • Androidでのウィジェット更新・消去、およびAndroid以外での動作を検証するテストを追加しました。

@coderabbitai

coderabbitai Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 36 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 649767c4-99db-4ca7-8f30-ec0ea9146718

📥 Commits

Reviewing files that changed from the base of the PR and between d8b149e and 1c0245b.

📒 Files selected for processing (1)
  • android/app/src/main/res/values-en/strings.xml
📝 Walkthrough

Walkthrough

Androidホーム画面ウィジェットを追加しました。乗車状態を保存し、サイズ別に表示します。React Nativeのライブアクティビティ開始・更新・終了に合わせて、ウィジェットを更新または消去します。

Changes

Android乗車ウィジェット

Layer / File(s) Summary
乗車状態の保存と読み込み
android/app/src/main/java/me/tinykitten/trainlcd/WidgetStateStore.kt
乗車状態、路線名、路線色、路線記号、降車駅名をSharedPreferencesへ保存します。状態の変更判定、消去、読み込み、路線色の解析を追加します。
React Nativeネイティブモジュール
android/app/src/main/java/me/tinykitten/trainlcd/WidgetModule.kt, android/app/src/main/java/me/tinykitten/trainlcd/TrainLCDPackage.kt
React Nativeからウィジェット状態の更新と消去を呼び出せるネイティブモジュールを追加し、モジュール一覧へ登録します。
ウィジェット表示とAndroid設定
android/app/src/main/AndroidManifest.xml, android/app/src/main/java/me/tinykitten/trainlcd/RideWidgetProvider.kt, android/app/src/main/res/drawable/*, android/app/src/main/res/layout/*, android/app/src/main/res/values*/*, android/app/src/main/res/xml/ride_widget_info.xml
非公開のRideWidgetProviderを登録します。円形、1行、横長のレイアウトをサイズに応じて選択します。未設定表示、路線色、アクセシビリティ説明、アプリ起動処理を設定します。
ライブアクティビティ同期と検証
src/utils/native/android/widgetModule.ts, src/utils/native/android/widgetModule.test.ts, src/hooks/useUpdateLiveActivities.ts
AndroidでのみネイティブAPIを呼び出すTypeScriptモジュールを追加します。ライブアクティビティの開始・更新時に状態を渡し、終了時にウィジェットを消去します。Android以外の動作をテストします。

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

  • TrainLCD/MobileApp#6135: 同じuseUpdateLiveActivities.tsを変更していますが、本PRはAndroidウィジェット同期を追加します。

Poem

ぴょんとホームに、列車が表示
路線の色も、駅名もくっきり
乗れば更新、降りれば消える
React Nativeと仲良く連携
うさぎも便利で耳ぴくぴく】【。

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed タイトルは、iOS/watchOS版に相当するAndroidホーム画面ウィジェットの追加という主な変更を明確に示しています。
Description check ✅ Passed 概要、変更内容、テスト結果、変更種別、任意項目を含み、PRの変更目的と検証状況を十分に説明しています。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch claude/android-widget-implementation-jc2yaf

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@android/app/src/main/res/values-en/strings.xml`:
- Line 8: Update the English text for the widget_description string to use
natural wording that describes the line and destination information shown while
riding, rather than implying the destination itself is being ridden.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 89ba0149-4e18-40de-b142-82f0caabb95c

📥 Commits

Reviewing files that changed from the base of the PR and between e96e5c6 and d8b149e.

📒 Files selected for processing (22)
  • android/app/src/main/AndroidManifest.xml
  • android/app/src/main/java/me/tinykitten/trainlcd/RideWidgetProvider.kt
  • android/app/src/main/java/me/tinykitten/trainlcd/TrainLCDPackage.kt
  • android/app/src/main/java/me/tinykitten/trainlcd/WidgetModule.kt
  • android/app/src/main/java/me/tinykitten/trainlcd/WidgetStateStore.kt
  • android/app/src/main/res/drawable/widget_background.xml
  • android/app/src/main/res/drawable/widget_background_circle.xml
  • android/app/src/main/res/drawable/widget_line_bar.xml
  • android/app/src/main/res/drawable/widget_numbering_circle.xml
  • android/app/src/main/res/layout/widget_ride_circular.xml
  • android/app/src/main/res/layout/widget_ride_inline.xml
  • android/app/src/main/res/layout/widget_ride_rectangular.xml
  • android/app/src/main/res/values-en/strings.xml
  • android/app/src/main/res/values-night/colors.xml
  • android/app/src/main/res/values-v31/dimens.xml
  • android/app/src/main/res/values/colors.xml
  • android/app/src/main/res/values/dimens.xml
  • android/app/src/main/res/values/strings.xml
  • android/app/src/main/res/xml/ride_widget_info.xml
  • src/hooks/useUpdateLiveActivities.ts
  • src/utils/native/android/widgetModule.test.ts
  • src/utils/native/android/widgetModule.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants