Skip to content

Commit

Permalink
Bump to BETA-1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
lighttigerXIV committed Sep 28, 2023
1 parent 02f3e6b commit 59a2de1
Show file tree
Hide file tree
Showing 28 changed files with 1,768 additions and 308 deletions.
4 changes: 2 additions & 2 deletions .idea/deploymentTargetDropDown.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ android {
applicationId "com.lighttigerxiv.simple.mp"
minSdk 26
targetSdk 33
versionCode 21
versionName "BETA-1.7.1"

versionCode 22
versionName "BETA-1.8.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
useSupportLibrary true
Expand Down Expand Up @@ -102,4 +101,8 @@ dependencies {

//Catppuccin Colors
implementation 'com.github.lighttigerxiv:catppuccin-kt:1.0.0'

//Android Auto
implementation 'androidx.car.app:app:1.2.0'

}
Binary file not shown.
4 changes: 2 additions & 2 deletions app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 21,
"versionName": "BETA-1.7.1",
"versionCode": 22,
"versionName": "BETA-1.8.0",
"outputFile": "app-release.apk"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.lighttigerxiv.simple.mp.compose

import android.annotation.SuppressLint
import android.content.AsyncQueryHandler
import android.content.BroadcastReceiver
import android.content.ContentResolver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.database.Cursor
import android.net.Uri
import androidx.core.content.ContextCompat


class AndroidAutoDetector(val context: Context) {

var onDisconnect: () -> Unit = {}

companion object {
const val TAG = "AutoConnectionDetector"

// columnName for provider to query on connection status
const val CAR_CONNECTION_STATE = "CarConnectionState"

// auto app on your phone will send broadcast with this action when connection state changes
const val ACTION_CAR_CONNECTION_UPDATED = "androidx.car.app.connection.action.CAR_CONNECTION_UPDATED"

// phone is not connected to car
const val CONNECTION_TYPE_NOT_CONNECTED = 0

// phone is connected to Automotive OS
const val CONNECTION_TYPE_NATIVE = 1

// phone is connected to Android Auto
const val CONNECTION_TYPE_PROJECTION = 2

private const val QUERY_TOKEN = 42

private const val CAR_CONNECTION_AUTHORITY = "androidx.car.app.connection"

private val PROJECTION_HOST_URI = Uri.Builder().scheme("content").authority(CAR_CONNECTION_AUTHORITY).build()
}

private val carConnectionReceiver = CarConnectionBroadcastReceiver()
private val carConnectionQueryHandler = CarConnectionQueryHandler(context.contentResolver)


fun registerCarConnectionReceiver() {

ContextCompat.registerReceiver(context, carConnectionReceiver, IntentFilter(ACTION_CAR_CONNECTION_UPDATED), ContextCompat.RECEIVER_NOT_EXPORTED)
queryForState()
}

fun unRegisterCarConnectionReceiver() {
context.unregisterReceiver(carConnectionReceiver)
}

private fun queryForState() {
carConnectionQueryHandler.startQuery(
QUERY_TOKEN,
null,
PROJECTION_HOST_URI,
arrayOf(CAR_CONNECTION_STATE),
null,
null,
null
)
}

inner class CarConnectionBroadcastReceiver : BroadcastReceiver() {
// query for connection state every time the receiver receives the broadcast
override fun onReceive(context: Context?, intent: Intent?) {
queryForState()
}
}

internal class CarConnectionQueryHandler(resolver: ContentResolver?) : AsyncQueryHandler(resolver) {
// notify new queryed connection status when query complete
override fun onQueryComplete(token: Int, cookie: Any?, response: Cursor?) {
if (response == null) {

return
}
val carConnectionTypeColumn = response.getColumnIndex(CAR_CONNECTION_STATE)
if (carConnectionTypeColumn < 0) {

return
}
if (!response.moveToNext()) {

return
}
val connectionState = response.getInt(carConnectionTypeColumn)
if (connectionState == CONNECTION_TYPE_NOT_CONNECTED) {

} else {

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import android.provider.MediaStore
import android.widget.Toast
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.car.app.connection.CarConnection
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
Expand Down Expand Up @@ -55,6 +56,7 @@ import com.lighttigerxiv.simple.mp.compose.screens.main.floating_album.FloatingA
import com.lighttigerxiv.simple.mp.compose.screens.main.floating_artist.FloatingArtistScreen
import com.lighttigerxiv.simple.mp.compose.screens.main.floating_artist.FloatingArtistScreenVM
import com.lighttigerxiv.simple.mp.compose.screens.main.main.MainScreen
import com.lighttigerxiv.simple.mp.compose.screens.main.player.PlayerScreenVM
import com.lighttigerxiv.simple.mp.compose.screens.main.playlists.PlaylistsScreenVM
import com.lighttigerxiv.simple.mp.compose.screens.main.playlists.playlist.PlaylistScreenVM
import com.lighttigerxiv.simple.mp.compose.screens.main.playlists.playlist.add_songs.AddSongsScreen
Expand Down Expand Up @@ -82,8 +84,6 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)



if (!getSharedPreferences(packageName, MODE_PRIVATE).getBoolean("setupCompleted", false)) {

startActivity(
Expand All @@ -93,12 +93,39 @@ class MainActivity : ComponentActivity() {
finish()
}


createNotificationChannels()


val vm = ViewModelProvider(this)[MainVM::class.java]
val settingsVM = ViewModelProvider(this)[SettingsVM::class.java]

fun onAndroidAutoStateUpdate(connectionState: Int){

val carPlayerEnabled = settingsVM.carPlayerSetting.value
val showCarPlayer = vm.showCarPlayer.value

when(connectionState){
CarConnection.CONNECTION_TYPE_NOT_CONNECTED -> {

if(carPlayerEnabled && !showCarPlayer){
vm.updateShowCarPlayer(false)
}
}
CarConnection.CONNECTION_TYPE_NATIVE ->{
if(carPlayerEnabled && !showCarPlayer){
vm.updateShowCarPlayer(true)
}
}
CarConnection.CONNECTION_TYPE_PROJECTION ->{
if(carPlayerEnabled && !showCarPlayer){
vm.updateShowCarPlayer(true)
}
}
}
}

CarConnection(application).type.observe(this, ::onAndroidAutoStateUpdate)


setContent {
Expand Down Expand Up @@ -200,6 +227,7 @@ class MainActivity : ComponentActivity() {

MainScreen(
mainVM = vm,
settingsVM = settingsVM,
activityContext = activityContext,
rootNavController = rootNavController,
onGetPlaylistImage = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import android.os.IBinder
import android.provider.MediaStore
import android.util.Log
import android.util.Size
import androidx.car.app.connection.CarConnection
import androidx.compose.material.BottomSheetState
import androidx.compose.material.BottomSheetValue
import androidx.compose.material.ExperimentalMaterialApi
Expand Down Expand Up @@ -64,6 +65,12 @@ class MainVM(application: Application) : AndroidViewModel(application) {
private val _loadingSongs = MutableStateFlow(true)
val loadingSongs = _loadingSongs.asStateFlow()

private val _showCarPlayer = MutableStateFlow(false)
val showCarPlayer = _showCarPlayer.asStateFlow()
fun updateShowCarPlayer(newValue: Boolean){
_showCarPlayer.update { newValue }
}

private val cachedQueries = CacheQueries(getMongoRealm())


Expand Down Expand Up @@ -756,6 +763,7 @@ class MainVM(application: Application) : AndroidViewModel(application) {
val workManager = WorkManager.getInstance(application)
workManager.enqueueUniquePeriodicWork("SyncSongsRequest", ExistingPeriodicWorkPolicy.CANCEL_AND_REENQUEUE, syncSongsRequest)


val serviceIntent = Intent(context, SimpleMPService::class.java)
context.bindService(serviceIntent, simpleMPConnection, Context.BIND_AUTO_CREATE)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ object Settings{
const val HOME_SORT = "HomeSort"
const val ARTISTS_SORT = "ArtistsSort"
const val ALBUMS_SORT = "AlbumsSort"
const val CAR_PLAYER = "CarPlayer"
const val KEEP_SCREEN_ON_IN_CAR_MODE = "KeepScreenOnInCarMode"

object Values{
object ColorScheme{
Expand Down Expand Up @@ -143,6 +145,8 @@ object Settings{
const val OLDEST = "oldest"
const val ASCENDENT = "ascendent"
const val DESCENDENT = "descendent"
const val ARTIST_ASCENDENT = "artistAscendent"
const val ARTIST_DESCENDENT = "artistDescendent"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,18 @@ import kotlinx.coroutines.withContext
import java.io.File

class SyncSongsWorker(appContext: Context, params: WorkerParameters) : CoroutineWorker(appContext, params) {


@SuppressLint("Range")
override suspend fun doWork(): Result {
return withContext(Dispatchers.IO) {

val preferences = applicationContext.getSharedPreferences(applicationContext.packageName, Context.MODE_PRIVATE)
val indexingSongs = preferences.getBoolean("indexingSongs", false)

return withContext(Dispatchers.IO){
if (indexingSongs) return@withContext Result.success()

preferences.edit().putBoolean("indexingSongs", true).apply()

val notificationManager = applicationContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val notificationBuilder = NotificationCompat.Builder(applicationContext, "Sync")
Expand Down Expand Up @@ -145,6 +153,8 @@ class SyncSongsWorker(appContext: Context, params: WorkerParameters) : Coroutine

notificationManager.cancel(3)

preferences.edit().putBoolean("indexingSongs", false).apply()

return@withContext Result.success()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,11 @@ fun AboutScreen(
.background(MaterialTheme.colorScheme.surfaceVariant)
.padding(MEDIUM_SPACING),
color = MaterialTheme.colorScheme.onSurface,
text = "- Added a smooth animation when opening and closing player \n\n" +
"- Added Latte theme \n\n" +
"- Added Light theme and Dark Theme options \n\n" +
"- Fixed Oled theme on home screen\n\n" +
"- Fixed empty albums and artists showing up due to filter\n\n" +
"- Fixed crash on Android 9 devices\n\n" +
"- Fixed notification on Android 9\n\n" +
"- Fixed songs that don't have artist id or album id showing up" +
"- App now syncs songs in background when opening\n\n" +
"- Added swipe to resync songs on home screen \n\n" +
"- Other small UI Updates "
text = "- Added Experimental Car Player Mode - (It should open when connecting to android auto)\n\n" +
"- Added sort by artist option in Albums\n\n" +
"- Added German Translation (@Integraluminium)\n\n" +
"- Fixed local artist image not showing\n\n" +
"- Fixed other small bugs"
)

MediumVerticalSpacer()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ fun AlbumsScreen(
val oldestAlbums = vm.oldestAlbums.collectAsState().value
val ascendentAlbums = vm.ascendentAlbums.collectAsState().value
val descendentAlbums = vm.descendentAlbums.collectAsState().value
val artistAscendentAlbums = vm.artistAscendentAlbums.collectAsState().value
val artistDescendentAlbums = vm.artistDescendentAlbums.collectAsState().value

val gridCellsCount = when (LocalConfiguration.current.orientation) {
Configuration.ORIENTATION_PORTRAIT -> 2
else -> 4
Expand Down Expand Up @@ -159,6 +162,36 @@ fun AlbumsScreen(
)
}
)

DropdownMenuItem(
text = {
Text(text = stringResource(id = R.string.SortByArtist))
},
onClick = {

val currentSort = context.getSharedPreferences(context.packageName, Context.MODE_PRIVATE).getString(Settings.ALBUMS_SORT, Settings.Values.Sort.RECENT)
val filterAlgorithm = if (currentSort == Settings.Values.Sort.ARTIST_ASCENDENT) Settings.Values.Sort.ARTIST_DESCENDENT else Settings.Values.Sort.ARTIST_ASCENDENT
val filterAlbums = if(currentSort == Settings.Values.Sort.ARTIST_ASCENDENT) artistDescendentAlbums else artistAscendentAlbums

vm.updateSortType(filterAlgorithm)
vm.updateCurrentAlbums(filterAlbums)
scope.launch {
vm.updateMenuExpanded(false)
delay(200)
listState.scrollToItem(index = 0)
}
},
leadingIcon = {
Icon(
modifier = Modifier
.height(20.dp)
.width(20.dp),
painter = painterResource(id = R.drawable.person),
contentDescription = null,
tint = MaterialTheme.colorScheme.onSurface
)
}
)
}
}

Expand Down

0 comments on commit 59a2de1

Please sign in to comment.