Skip to content

Commit

Permalink
Update date added podcast display sort order (#3192)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashiagr authored Nov 8, 2024
1 parent 24c493b commit 96292fd
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
([#3120](https://github.com/Automattic/pocket-casts-android/pull/3120))
* Improve connection when some podcasts failed to play or download
([#3180](https://github.com/Automattic/pocket-casts-android/pull/3180))
* Add new podcast subscriptions to the top instead of bottom for Data Added podcast sort order
([#3192](https://github.com/Automattic/pocket-casts-android/pull/3192))
* Bug Fixes
* Use red color for the notification icons
([#3154](https://github.com/Automattic/pocket-casts-android/pull/3154))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class ExternalDataDaoTest {
podcastDao.insert(Podcast(uuid = "id-4", title = "title-4", isSubscribed = true, addedDate = Date(1)))
podcastDao.insert(Podcast(uuid = "id-5", title = "title-5", isSubscribed = true, addedDate = null))

val podcastIds = externalDataDao.getSubscribedPodcasts(PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST, limit = 100).map { it.id }
val podcastIds = externalDataDao.getSubscribedPodcasts(PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST, limit = 100).map { it.id }

assertEquals(listOf("id-4", "id-3", "id-1", "id-2", "id-5"), podcastIds)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ object FakeFileGenerator {
color = 1,
addedDate = Date(),
sortPosition = 1,
podcastsSortType = PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST,
podcastsSortType = PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST,
deleted = false,
syncModified = 1L,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class PodcastFolderHelperTest {
color = 0,
addedDate = Date(),
sortPosition = 0,
podcastsSortType = PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST,
podcastsSortType = PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST,
deleted = false,
syncModified = 0,
)
Expand All @@ -31,7 +31,7 @@ class PodcastFolderHelperTest {
color = 0,
addedDate = Date(),
sortPosition = 0,
podcastsSortType = PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST,
podcastsSortType = PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST,
deleted = false,
syncModified = 0,
)
Expand Down Expand Up @@ -113,7 +113,7 @@ class PodcastFolderHelperTest {
}

PodcastFolderHelper.sortForSelectingPodcasts(
sortType = PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST,
sortType = PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST,
podcastsSortedByReleaseDate = list,
currentFolderUuid = null,
).let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class FolderEditViewModel
val podcasts = podcastsSortedByReleaseDate
return when (settings.podcastsSortType.value) {
PodcastsSortType.EPISODE_DATE_NEWEST_TO_OLDEST -> podcastsSortedByReleaseDate
PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST -> podcasts.sortedWith(compareBy { it.addedDate })
PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST -> podcasts.sortedWith(compareBy { it.addedDate })
PodcastsSortType.DRAG_DROP -> podcasts.sortedWith(compareBy { it.sortPosition })
PodcastsSortType.NAME_A_TO_Z -> podcasts.sortedWith(compareBy { PodcastsSortType.cleanStringForSort(it.title) })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object PodcastFolderHelper {
}
}
val podcastComparator: Comparator<PodcastFolder>? = when (sortType) {
PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST -> addDateComparator
PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST -> addDateComparator
PodcastsSortType.EPISODE_DATE_NEWEST_TO_OLDEST -> null
else -> aToZComparator
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ class PodcastsViewModel
fun trackFolderShown(folderUuid: String) {
launch {
val properties = HashMap<String, Any>()
properties[SORT_ORDER_KEY] = (folderManager.findByUuid(folderUuid)?.podcastsSortType ?: PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST).analyticsValue
properties[SORT_ORDER_KEY] = (folderManager.findByUuid(folderUuid)?.podcastsSortType ?: PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST).analyticsValue
properties[NUMBER_OF_PODCASTS_KEY] = folderManager.findFolderPodcastsSorted(folderUuid).size
analyticsTracker.track(AnalyticsEvent.FOLDER_SHOWN, properties)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,6 @@ enum class PodcastsSortType(
val folderComparator: Comparator<FolderItem>,
val analyticsValue: String,
) {
DATE_ADDED_OLDEST_TO_NEWEST(
clientId = 0,
serverId = 0,
labelId = R.string.podcasts_sort_by_date_added,
podcastComparator = compareBy { it.addedDate },
folderComparator = compareBy { it.addedDate },
analyticsValue = "date_added",
),
NAME_A_TO_Z(
clientId = 2,
serverId = 1,
Expand All @@ -47,6 +39,14 @@ enum class PodcastsSortType(
folderComparator = Comparator { _, _ -> 0 },
analyticsValue = "episode_release_date",
),
DATE_ADDED_NEWEST_TO_OLDEST(
clientId = 0,
serverId = 0,
labelId = R.string.podcasts_sort_by_date_added,
podcastComparator = compareByDescending { it.addedDate },
folderComparator = compareByDescending { it.addedDate },
analyticsValue = "date_added",
),
DRAG_DROP(
clientId = 6,
serverId = 3,
Expand All @@ -58,7 +58,7 @@ enum class PodcastsSortType(
;

companion object {
val default = DATE_ADDED_OLDEST_TO_NEWEST
val default = DATE_ADDED_NEWEST_TO_OLDEST

fun fromServerId(serverId: Int?): PodcastsSortType {
if (serverId == null) {
Expand Down Expand Up @@ -88,7 +88,7 @@ enum class PodcastsSortType(
}

fun isAsc(): Boolean {
return clientId == DATE_ADDED_OLDEST_TO_NEWEST.clientId || clientId == NAME_A_TO_Z.clientId
return clientId == NAME_A_TO_Z.clientId
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import au.com.shiftyjelly.pocketcasts.models.entity.Folder
import au.com.shiftyjelly.pocketcasts.models.entity.Podcast
import au.com.shiftyjelly.pocketcasts.models.to.FolderItem
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType.DRAG_DROP
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType.EPISODE_DATE_NEWEST_TO_OLDEST
import au.com.shiftyjelly.pocketcasts.models.type.PodcastsSortType.NAME_A_TO_Z
Expand Down Expand Up @@ -250,7 +250,7 @@ class FolderManagerImpl @Inject constructor(

val itemsSorted = when (podcastSortType) {
NAME_A_TO_Z -> items.sortedWith(compareBy { PodcastsSortType.cleanStringForSort(it.title) })
DATE_ADDED_OLDEST_TO_NEWEST -> items.sortedWith(compareBy { it.addedDate })
DATE_ADDED_NEWEST_TO_OLDEST -> items.sortedWith(compareBy { it.addedDate })
DRAG_DROP -> items.sortedWith(compareBy { it.sortPosition })
else -> items
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ class PodcastManagerImpl @Inject constructor(
override fun observePodcastsInFolderOrderByUserChoice(folder: Folder): Flowable<List<Podcast>> {
val sort = folder.podcastsSortType
return when (sort) {
PodcastsSortType.DATE_ADDED_OLDEST_TO_NEWEST -> podcastDao.observeFolderOrderByAddedDate(folder.uuid, sort.isAsc())
PodcastsSortType.DATE_ADDED_NEWEST_TO_OLDEST -> podcastDao.observeFolderOrderByAddedDate(folder.uuid, sort.isAsc())
PodcastsSortType.EPISODE_DATE_NEWEST_TO_OLDEST -> podcastDao.observeFolderOrderByLatestEpisode(folder.uuid, sort.isAsc())
PodcastsSortType.DRAG_DROP -> podcastDao.observeFolderOrderByUserSort(folder.uuid)
else -> podcastDao.observeFolderOrderByName(folder.uuid, sort.isAsc())
Expand Down

0 comments on commit 96292fd

Please sign in to comment.