Skip to content

Commit

Permalink
Increment version to v0.2.0, various fixes
Browse files Browse the repository at this point in the history
Implement ServiceNotConnectedView and rename to LoadingSplashView
Add backhandler to SongFeedPage and SearchPage which removes the selected filter
Localise download notification strings
Implement library search and sort buttons for playlist page
Hide library search and sort buttons when in the profile page
Fix artists of song feed items not loading correctly
  • Loading branch information
toasterofbread committed Sep 11, 2023
1 parent 163ca28 commit 0daa7c4
Show file tree
Hide file tree
Showing 38 changed files with 369 additions and 199 deletions.
2 changes: 1 addition & 1 deletion androidApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ android {
}

defaultConfig {
versionCode = 5
versionCode = 6
versionName = getString("version_string")

applicationId = "com.toasterofbread.spmp"
Expand Down
4 changes: 2 additions & 2 deletions shared/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ fun GenerateBuildConfig.buildConfig(debug: Boolean) {
}

val buildConfigDebug = tasks.register("buildConfigDebug", GenerateBuildConfig::class.java) {
buildConfig(debug = true)
buildConfig(debug = false)
}
val buildConfigRelease = tasks.register("buildConfigRelease", GenerateBuildConfig::class.java) {
buildConfig(debug = true)
buildConfig(debug = false)
}

tasks.all {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import com.toasterofbread.spmp.platform.PlatformServiceImpl
import com.toasterofbread.spmp.platform.PlayerDownloadManager
import com.toasterofbread.spmp.platform.PlayerDownloadManager.DownloadStatus
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.resources.getStringTODO
import kotlinx.coroutines.delay
import kotlinx.coroutines.runBlocking
import java.io.File
Expand Down Expand Up @@ -556,28 +555,27 @@ class PlayerDownloadService: PlatformServiceImpl() {
else {
builder.setProgress(100, (total_progress * 100).toInt(), false)

val title = if (downloads.size == 1) {
val song_title = context.database.mediaItemQueries.titleById(downloads.first().id).executeAsOne().title
var title: String? = null
if (downloads.size == 1) {
val song = SongRef(downloads.first().id)
val song_title = song.getActiveTitle(context.database)
if (song_title != null) {
getStringTODO("Downloading $song_title")
}
else {
getStringTODO("Downloading 1 song")
title = getString("downloading_song_\$title").replace("\$title", song_title)
}
}
else {
getStringTODO("Downloading ${downloads.size} songs")

if (title == null) {
title = getString("downloading_\$x_songs").replace("\$x", downloads.size.toString())
}

builder.setContentTitle(if (paused) "$title (paused)" else title)
builder.setContentText(getNotificationText())

val elapsed_minutes = ((System.currentTimeMillis() - start_time) / 60000f).toInt()
builder.setSubText(when(elapsed_minutes) {
0 -> getStringTODO("Just started")
1 -> getStringTODO("Started 1 min ago")
else -> getStringTODO("Started $elapsed_minutes mins ago")
})
builder.setSubText(
if (elapsed_minutes == 0) getString("download_just_started")
else getString("download_started_\$x_minutes_ago").replace("\$x", elapsed_minutes.toString())
)
}

if (ActivityCompat.checkSelfPermission(this, "android.permission.POST_NOTIFICATIONS") == PackageManager.PERMISSION_GRANTED) {
Expand Down
8 changes: 4 additions & 4 deletions shared/src/commonMain/kotlin/SpMp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.animation.expandVertically
import androidx.compose.animation.fadeIn
import androidx.compose.animation.fadeOut
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
Expand Down Expand Up @@ -44,7 +46,7 @@ import com.toasterofbread.spmp.resources.uilocalisation.localised.UILanguages
import com.toasterofbread.spmp.ui.layout.mainpage.PlayerState
import com.toasterofbread.spmp.ui.layout.mainpage.PlayerStateImpl
import com.toasterofbread.spmp.ui.layout.mainpage.RootView
import com.toasterofbread.spmp.ui.layout.mainpage.ServiceNotConnectedView
import com.toasterofbread.spmp.ui.layout.mainpage.LoadingSplashView
import com.toasterofbread.spmp.ui.theme.ApplicationTheme
import com.toasterofbread.spmp.ui.theme.Theme
import com.toasterofbread.spmp.youtubeapi.fromJson
Expand Down Expand Up @@ -140,9 +142,7 @@ object SpMp {
if (player_state.service_connected) {
RootView(player_state)
}
else {
ServiceNotConnectedView()
}
LoadingSplashView(player_state.service_connected, Modifier.fillMaxSize())
}
error_manager.Indicator(Theme.accent_provider)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import androidx.compose.ui.graphics.Color
import com.toasterofbread.Database
import com.toasterofbread.spmp.model.mediaitem.artist.Artist
import com.toasterofbread.spmp.model.mediaitem.artist.ArtistData
import com.toasterofbread.spmp.model.mediaitem.artist.ArtistRef
import com.toasterofbread.spmp.model.mediaitem.enums.MediaItemType
import com.toasterofbread.spmp.model.mediaitem.enums.PlaylistType
import com.toasterofbread.spmp.model.mediaitem.playlist.RemotePlaylistData
Expand Down Expand Up @@ -79,7 +80,7 @@ abstract class MediaItemData: MediaItem {
}

if (!artist_found && this is MediaItem.DataWithArtist) {
artist = ArtistData.createForItem(this).also {
artist = ArtistData(com.toasterofbread.spmp.model.mediaitem.artist.Artist.getForItemId(this)).also {
it.title = runs.getOrNull(1)?.text
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ enum class MediaItemSortType {
fun getReadable(native_string_key: String? = null): String =
getString(when(this) {
NATIVE -> native_string_key!!
ALPHABET -> "sort_option_alphabet"
DURATION -> "sort_option_duration"
PLAY_COUNT -> "sort_option_playcount"
ALPHABET -> "sort_type_alphabet"
DURATION -> "sort_type_duration"
PLAY_COUNT -> "sort_type_playcount"
})

fun <T: MediaItem> sortItems(items: List<T>, db: Database, reversed: Boolean = false): List<T> {
Expand All @@ -38,6 +38,15 @@ enum class MediaItemSortType {
return items.sortedWith(if (reverse) compareByDescending(selector) else compareBy(selector))
}

fun <T: MediaItem> sortAndFilterItems(items: List<T>, filter: String?, db: Database, reversed: Boolean): List<T> {
val sorted = sortItems(items, db, reversed)
if (filter == null) {
return sorted
}

return sorted.filter { it.getActiveTitle(db)?.contains(filter, true) == true }
}

companion object {
@Composable
fun SelectionMenu(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,6 @@ sealed interface Artist: MediaItem {
get() = property_rememberer.rememberSingleQueryProperty(
"SubscriberCount", { artistQueries.subscriberCountById(id) }, { subscriber_count?.toInt() }, { artistQueries.updateSubscriberCountById(it?.toLong(), id) }
)
val IsForItem: Property<Boolean>
get() = property_rememberer.rememberSingleQueryProperty(
"IsForItem",
{ artistQueries.isForItemById(id) },
{ is_for_item.fromSQLBoolean() },
{ artistQueries.updateIsForItemById(it.toSQLBoolean(), id) },
{ false }
)

val Subscribed: Property<Boolean?>
get() = property_rememberer.rememberSingleQueryProperty(
Expand All @@ -88,9 +80,18 @@ sealed interface Artist: MediaItem {
}
}
data.subscriber_count = SubscriberCount.get(db)
data.is_for_item = IsForItem.get(db)
}
override suspend fun loadData(context: PlatformContext, populate_data: Boolean, force: Boolean): Result<ArtistData> {
return super.loadData(context, populate_data, force) as Result<ArtistData>
}

fun isForItem(): Boolean =
id.startsWith("FORITEM")

companion object {
fun getForItemId(item: MediaItem): String {
RuntimeException().printStackTrace()
return "FORITEM${item.id}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ class ArtistData(
var subscribe_channel_id: String? = null,
var layouts: MutableList<ArtistLayoutData>? = null,
var subscriber_count: Int? = null,
var is_for_item: Boolean = false,

var subscribed: Boolean? = null
): MediaItemData(), Artist {
override fun getDataValues(): Map<String, Any?> =
super.getDataValues() + mapOf(
"subscribe_channel_id" to subscribe_channel_id,
"layouts" to layouts,
"subscriber_count" to subscriber_count,
"is_for_item" to is_for_item
"subscriber_count" to subscriber_count
)

override fun toString(): String = "ArtistData($id)"
Expand All @@ -43,12 +41,6 @@ class ArtistData(

SubscribeChannelId.setNotNull(subscribe_channel_id, db, uncertain)
SubscriberCount.setNotNull(subscriber_count, db, uncertain)
IsForItem.setNotNull(is_for_item, db, uncertain)
}}
}

companion object {
fun createForItem(item: MediaItem): ArtistData =
ArtistData("", is_for_item = true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import com.toasterofbread.spmp.platform.getDefaultHorizontalPadding
import com.toasterofbread.spmp.resources.getString
import com.toasterofbread.spmp.ui.component.ErrorInfoDisplay
import com.toasterofbread.spmp.model.mediaitem.layout.MediaItemLayout
import com.toasterofbread.spmp.platform.BackHandler
import com.toasterofbread.spmp.ui.component.multiselect.MediaItemMultiSelectContext
import com.toasterofbread.spmp.ui.layout.mainpage.MainPage
import com.toasterofbread.spmp.ui.layout.mainpage.MainPageState
Expand Down Expand Up @@ -144,6 +145,10 @@ class SearchPage(state: MainPageState, val context: PlatformContext): MainPage(s
return
}

BackHandler({ current_filter != null }) {
setFilter(null)
}

val player = LocalPlayerState.current
val focus_manager = LocalFocusManager.current
val keyboard_controller = LocalSoftwareKeyboardController.current
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fun ArtistPage(
val db = player.context.database

lazyAssert {
!artist.IsForItem.get(db)
!artist.isForItem()
}

var load_error: Throwable? by remember { mutableStateOf(null) }
Expand Down
Loading

0 comments on commit 0daa7c4

Please sign in to comment.