Skip to content

Commit

Permalink
Merge pull request #7 from prime-zs/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
iZakirSheikh authored Dec 10, 2022
2 parents d60fadb + 6a726f7 commit 0bfabae
Show file tree
Hide file tree
Showing 21 changed files with 1,146 additions and 523 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ android {
applicationId "com.prime.player"
minSdk 21
targetSdk 33
versionCode 12
versionName "1.0.0"
versionCode 14
versionName "1.0.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables {
Expand Down Expand Up @@ -147,7 +147,7 @@ dependencies {
implementation 'com.flaviofaria:kenburnsview:1.0.7'

//Preferences and other widgets
def support_version = '1.0.0-alpha12'
def support_version = '1.0.0-alpha17'
implementation "com.github.prime-zs:support:$support_version"

//work manager
Expand Down
111 changes: 73 additions & 38 deletions app/src/main/java/com/prime/player/Audiofy.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Build
import android.provider.MediaStore
import androidx.compose.ui.unit.dp
import androidx.hilt.work.HiltWorkerFactory
import androidx.work.Configuration
import com.google.firebase.FirebaseApp
import com.google.firebase.analytics.FirebaseAnalytics
import com.prime.player.common.FontFamily
import com.prime.player.common.NightMode
import com.prime.player.core.LocalDb
Expand All @@ -24,6 +24,7 @@ import dagger.hilt.InstallIn
import dagger.hilt.android.HiltAndroidApp
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import java.util.concurrent.TimeUnit
import javax.inject.Inject
import javax.inject.Singleton

Expand All @@ -37,51 +38,91 @@ class Audiofy : Application(), Configuration.Provider {
* Retrieves/Sets The [NightMode] Strategy
*/
val NIGHT_MODE =
stringPreferenceKey("${TAG}_night_mode", NightMode.YES, object : StringSaver<NightMode> {
override fun save(value: NightMode): String = value.name
stringPreferenceKey("${TAG}_night_mode",
NightMode.YES,
object : StringSaver<NightMode> {
override fun save(value: NightMode): String = value.name
override fun restore(value: String): NightMode = NightMode.valueOf(value)
})

val FONT_FAMILY =
stringPreferenceKey(TAG + "_font_family",
FontFamily.PROVIDED,
object : StringSaver<FontFamily> {
override fun save(value: FontFamily): String = value.name
override fun restore(value: String): FontFamily = FontFamily.valueOf(value)
})


val FORCE_COLORIZE =
booleanPreferenceKey(
TAG + "_force_colorize", false
)

override fun restore(value: String): NightMode = NightMode.valueOf(value)
})
val COLOR_STATUS_BAR =
booleanPreferenceKey(
TAG + "_color_status_bar", false
)

val FONT_FAMILY = stringPreferenceKey(
TAG + "_font_family",
FontFamily.PROVIDED,
object : StringSaver<FontFamily> {
override fun save(value: FontFamily): String = value.name
val HIDE_STATUS_BAR =
booleanPreferenceKey(
TAG + "_hide_status_bar", false
)

override fun restore(value: String): FontFamily = FontFamily.valueOf(value)
})

val FONT_SCALE =
floatPreferenceKey(
TAG + "_font_scale", defaultValue = 1.0f
)

val FORCE_COLORIZE = booleanPreferenceKey(
TAG + "_force_colorize", false
)
/**
* The counter counts the number of times this app was launched.
*/
val KEY_LAUNCH_COUNTER =
intPreferenceKey(TAG + "_launch_counter")

val COLOR_STATUS_BAR = booleanPreferenceKey(
TAG + "_color_status_bar", false
)
val SHOW_MINI_PROGRESS_BAR =
booleanPreferenceKey(
TAG + "_show_mini_progress_bar", false
)

val HIDE_STATUS_BAR = booleanPreferenceKey(
TAG + "_hide_status_bar", false
)

private val defaultMinTrackLimit = TimeUnit.MINUTES.toMillis(1)

val FONT_SCALE = floatPreferenceKey(
TAG + "_font_scale", defaultValue = 1.0f
)
/**
* The length/duration of the track in mills considered above which to include
*/
val EXCLUDE_TRACK_DURATION =
longPreferenceKey(
TAG + "_min_duration_limit_of_track", defaultMinTrackLimit
)


val MAX_RECENT_PLAYLIST_SIZE =
intPreferenceKey(
TAG + "_max_recent_size", defaultValue = 20
)

/**
* The counter counts the number of times this app was launched.
* A prefix char for private playlists.
*/
val KEY_LAUNCH_COUNTER = intPreferenceKey(TAG + "_launch_counter")
const val PRIVATE_PLAYLIST_PREFIX = '_'

/**
* The name of the playlist contains the favourites.
*/
val PLAYLIST_FAVOURITES = PRIVATE_PLAYLIST_PREFIX + "favourites"

/**
* peek Height of [BottomSheetScaffold], also height of [MiniPlayer]
*/
val MINI_PLAYER_HEIGHT = 68.dp

const val PLAYBACK_CHANNEL_ID = "audio_playback_channel"
const val UPDATES_CHANNEL_ID = "content_updates"
const val PLAYBACK_NOTIFICATION_ID = 1
lateinit var DEFAULT_ALBUM_ART: Bitmap

const val DEBUG = false

/**
* The link to PlayStore Market.
*/
Expand Down Expand Up @@ -110,8 +151,7 @@ class Audiofy : Application(), Configuration.Provider {
* This Composes the [MediaStore.Audio.Media.EXTERNAL_CONTENT_URI] from the provided Album [id]
*/
@JvmStatic
fun toAlbumArtUri(id: Long): Uri =
ContentUris.withAppendedId(Uri.parse(ALBUM_ART_URI), id)
fun toAlbumArtUri(id: Long): Uri = ContentUris.withAppendedId(Uri.parse(ALBUM_ART_URI), id)

/**
* This Composes the [MediaStore.Audio.Media.EXTERNAL_CONTENT_URI] with the provided [Audio] [id]
Expand All @@ -126,18 +166,14 @@ class Audiofy : Application(), Configuration.Provider {
lateinit var workerFactory: HiltWorkerFactory

override fun getWorkManagerConfiguration(): Configuration =
Configuration.Builder()
.setWorkerFactory(workerFactory)
.build()
Configuration.Builder().setWorkerFactory(workerFactory).build()

override fun onCreate() {
super.onCreate()
DEFAULT_ALBUM_ART = BitmapFactory.decodeResource(resources, R.drawable.default_art)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel(
PLAYBACK_CHANNEL_ID,
"Playing Music Channel",
NotificationManager.IMPORTANCE_DEFAULT
PLAYBACK_CHANNEL_ID, "Playing Music Channel", NotificationManager.IMPORTANCE_DEFAULT
)
channel.setShowBadge(false)
channel.setSound(null, null)
Expand Down Expand Up @@ -176,6 +212,5 @@ object Singleton {
@Provides
fun localDb(
@ApplicationContext context: Context
) =
LocalDb.get(context)
) = LocalDb.get(context)
}
159 changes: 58 additions & 101 deletions app/src/main/java/com/prime/player/Home.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.prime.player
import androidx.activity.compose.BackHandler
import androidx.compose.animation.*
import androidx.compose.animation.core.tween
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
Expand All @@ -17,7 +18,6 @@ import androidx.navigation.NavGraphBuilder
import com.google.accompanist.navigation.animation.AnimatedNavHost
import com.google.accompanist.navigation.animation.composable
import com.google.accompanist.navigation.animation.rememberAnimatedNavController
import com.prime.player.audio.Player
import com.prime.player.audio.buckets.Buckets
import com.prime.player.audio.buckets.BucketsViewModel
import com.prime.player.audio.console.Console
Expand All @@ -26,10 +26,7 @@ import com.prime.player.audio.library.Library
import com.prime.player.audio.library.LibraryViewModel
import com.prime.player.audio.tracks.Tracks
import com.prime.player.audio.tracks.TracksViewModel
import com.prime.player.common.compose.LocalNavController
import com.prime.player.common.compose.LocalSnackDataChannel
import com.prime.player.common.compose.LocalWindowPadding
import com.prime.player.common.compose.stringResource
import com.prime.player.common.compose.*
import com.prime.player.settings.MainGraphRoutes
import com.prime.player.settings.Settings
import com.prime.player.settings.SettingsViewModel
Expand All @@ -47,102 +44,6 @@ private val EnterTransition = scaleIn(

private val ExitTransition = fadeOut(tween(700))

@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
@Composable
fun Home() {
// Currently; supports only 1 Part
// add others in future
// including support for more tools, like direction, prime factorization etc.
// also support for navGraph.
val controller = rememberAnimatedNavController()
val scope = rememberCoroutineScope()
val consoleViewModel = hiltViewModel<ConsoleViewModel>()

//FixMe - Needs to be corrected.
val connected by consoleViewModel.connected
LaunchedEffect(key1 = connected) {
//delay(1000)
consoleViewModel.connect()
}
val show = consoleViewModel.current.value != null

// The state of the Snackbar
val snackbar = remember(::SnackbarHostState)
//Handle messages etc.
val state =
rememberBottomSheetScaffoldState(snackbarHostState = snackbar)

// observe the channel
// emit the updates
val channel = LocalSnackDataChannel.current
val resource = LocalContext.current.resources
LaunchedEffect(key1 = channel) {
channel.receiveAsFlow().collect { (label, message, duration, action) ->
// dismantle the given snack and use the corresponding components
val result = snackbar.showSnackbar(
message = resource.stringResource(message).text,
actionLabel = resource.stringResource(label)?.text
?: resource.getString(R.string.dismiss),
duration = duration
)
// action based on
when (result) {
SnackbarResult.ActionPerformed -> action?.invoke()
SnackbarResult.Dismissed -> { /*do nothing*/
}
}
}
}

BackHandler(state.bottomSheetState.isExpanded) {
if (state.bottomSheetState.isExpanded)
scope.launch {
state.bottomSheetState.snapTo(targetValue = BottomSheetValue.Collapsed)
}
}

var windowPadding by rememberState(initial = PaddingValues(0.dp))
CompositionLocalProvider(
LocalWindowPadding provides windowPadding,
LocalNavController provides controller,
) {
//Bottom sheet
BottomSheetScaffold(
backgroundColor = Material.colors.background,
scaffoldState = state,
sheetElevation = 0.dp,
sheetGesturesEnabled = false,
sheetBackgroundColor = androidx.compose.ui.graphics.Color.Transparent,
sheetPeekHeight = if (show) Player.MINI_PLAYER_HEIGHT else 0.dp,

sheetContent = {
Console(
viewModel = consoleViewModel,
expanded = state.bottomSheetState.isExpanded
) {
scope.launch {
if (state.bottomSheetState.isExpanded) {
state.bottomSheetState.snapTo(targetValue = BottomSheetValue.Collapsed)
} else {
state.bottomSheetState.snapTo(targetValue = BottomSheetValue.Expanded)
}
}
}
},

content = { inner ->
// update window padding when ever it changes.
windowPadding = inner
Box(
Modifier.fillMaxSize(),
content = { NavGraph() }
)
},
)
}
}


@OptIn(ExperimentalAnimationApi::class)
@Composable
private fun NavGraph() {
Expand Down Expand Up @@ -206,3 +107,59 @@ private fun NavGraphBuilder.composable(
}
}

@OptIn(ExperimentalMaterialApi::class, ExperimentalAnimationApi::class)
@Composable
fun Home() {
// Currently; supports only 1 Part
// add others in future
// including support for more tools, like direction, prime factorization etc.
// also support for navGraph.
val controller = rememberAnimatedNavController()
val scope = rememberCoroutineScope()
val consoleViewModel = hiltViewModel<ConsoleViewModel>()

//FixMe - Needs to be corrected.
val connected by consoleViewModel.connected
LaunchedEffect(key1 = connected) {
//delay(1000)
consoleViewModel.connect()
}
val show = consoleViewModel.current.value != null
//Handle messages etc.
val state =
rememberPlayerState(initial = PlayerValue.COLLAPSED)

BackHandler(state.isExpanded) {
scope.launch { state.snapTo(PlayerValue.COLLAPSED) }
}

val peekHeight = if (show) Audiofy.MINI_PLAYER_HEIGHT else 0.dp
val windowPadding by rememberUpdatedState(PaddingValues(bottom = peekHeight))
CompositionLocalProvider(
LocalWindowPadding provides windowPadding,
LocalNavController provides controller,
) {
Player(
sheet = {
Console(consoleViewModel, state.isExpanded, { scope.launch { state.toggle() } })
},
state = state,
sheetPeekHeight = peekHeight,
toast = LocalContext.toastHostState,
progress = LocalContext.inAppUpdateProgress.value,
content = {
Surface(modifier = Modifier.fillMaxSize(), color = Material.colors.background) {
NavGraph()
}
}
)
}
}

private suspend inline fun PlayerState.toggle() {
if (isExpanded) {
snapTo(targetValue = PlayerValue.COLLAPSED)
} else {
snapTo(targetValue = PlayerValue.EXPANDED)
}
}
Loading

0 comments on commit 0bfabae

Please sign in to comment.