-
Notifications
You must be signed in to change notification settings - Fork 960
Add Recently Played tab to Android Auto #3567
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
Open
hazemelraffiee
wants to merge
3
commits into
quran:main
Choose a base branch
from
hazemelraffiee:auto_recently_played
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+355
−9
Open
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
7 changes: 7 additions & 0 deletions
7
feature/autoquran/src/main/java/com/quran/labs/feature/autoquran/common/RecentQari.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 com.quran.labs.feature.autoquran.common | ||
|
|
||
| data class RecentQari( | ||
| val qariId: Int, | ||
| val lastSura: Int, | ||
| val timestamp: Long | ||
| ) |
60 changes: 60 additions & 0 deletions
60
feature/autoquran/src/main/java/com/quran/labs/feature/autoquran/common/RecentQariManager.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,60 @@ | ||
| package com.quran.labs.feature.autoquran.common | ||
|
|
||
| import android.content.Context | ||
| import android.content.SharedPreferences | ||
| import com.quran.mobile.di.qualifier.ApplicationContext | ||
| import dev.zacsweers.metro.Inject | ||
| import org.json.JSONArray | ||
| import org.json.JSONObject | ||
| import timber.log.Timber | ||
|
|
||
| class RecentQariManager @Inject constructor( | ||
| @ApplicationContext appContext: Context, | ||
| ) { | ||
|
|
||
| private val prefs: SharedPreferences = | ||
| appContext.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) | ||
|
|
||
| fun getRecentQaris(): List<RecentQari> { | ||
| val json = prefs.getString(KEY_RECENT_QARIS, null) ?: return emptyList() | ||
| return try { | ||
| val array = JSONArray(json) | ||
| (0 until array.length()).map { i -> | ||
| val obj = array.getJSONObject(i) | ||
| RecentQari( | ||
| qariId = obj.getInt(FIELD_QARI_ID), | ||
| lastSura = obj.getInt(FIELD_LAST_SURA), | ||
| timestamp = obj.getLong(FIELD_TIMESTAMP) | ||
| ) | ||
| } | ||
| } catch (e: Exception) { | ||
| Timber.e(e, "Failed to parse recent qaris") | ||
| emptyList() | ||
| } | ||
| } | ||
|
|
||
| fun recordQari(qariId: Int, sura: Int) { | ||
| val current = getRecentQaris().toMutableList() | ||
| current.removeAll { it.qariId == qariId && it.lastSura == sura } | ||
| current.add(0, RecentQari(qariId, sura, System.currentTimeMillis())) | ||
| val trimmed = current.take(MAX_RECENT) | ||
| val array = JSONArray() | ||
| for (entry in trimmed) { | ||
| val obj = JSONObject() | ||
| obj.put(FIELD_QARI_ID, entry.qariId) | ||
| obj.put(FIELD_LAST_SURA, entry.lastSura) | ||
| obj.put(FIELD_TIMESTAMP, entry.timestamp) | ||
| array.put(obj) | ||
| } | ||
| prefs.edit().putString(KEY_RECENT_QARIS, array.toString()).apply() | ||
| } | ||
|
|
||
| companion object { | ||
| private const val PREFS_NAME = "autoquran_recent" | ||
| private const val KEY_RECENT_QARIS = "recent_qaris" | ||
| private const val FIELD_QARI_ID = "qari_id" | ||
| private const val FIELD_LAST_SURA = "last_sura" | ||
| private const val FIELD_TIMESTAMP = "timestamp" | ||
| private const val MAX_RECENT = 5 | ||
| } | ||
| } |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a new recent item is recorded, this notifies
ROOT_IDwithrecentCount + 1, but the root node only ever exposes one child (Qaris) or two children (Recently Played+Qaris). After the second recent entry, browsers are told there are 3+ root children that do not exist, which can lead Android Auto clients to request non-existent items and show inconsistent/empty UI. The root notification count should be fixed to the actual root size (typically2when recents exist, otherwise1, orITEM_COUNT_UNKNOWN).Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed