Skip to content

Commit

Permalink
Add home widget
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Feb 15, 2024
1 parent 861dac5 commit d5ea876
Show file tree
Hide file tree
Showing 29 changed files with 743 additions and 63 deletions.
3 changes: 3 additions & 0 deletions .idea/deploymentTargetDropDown.xml

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

2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ android {
targetSdk = 34
versionCode = 16
versionName = "0.2.0"
vectorDrawables.useSupportLibrary = true

ksp {
arg("room.schemaLocation", "$projectDir/schemas")
Expand Down Expand Up @@ -51,6 +52,7 @@ android {
}
debug {
applicationIdSuffix = ".dev"
versionNameSuffix = "-dev"
}
}
compileOptions {
Expand Down
115 changes: 66 additions & 49 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,35 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO"/>
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK" />

<uses-feature
android:name="android.hardware.type.automotive"
android:required="false" />
<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.landscape"
android:required="false" />

<queries>
<intent>
<action android:name="android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL" />
</intent>
</queries>
<queries>
<package android:name="com.maxrave.simpmusic" />
</queries>
<queries>
<intent>
<action android:name="androidx.media3.session.MediaSessionService" />
</intent>
</queries>

<application
android:name=".SimpMusicApplication"
android:usesCleartextTraffic="true"
android:allowBackup="true"
android:appCategory="audio"
android:dataExtractionRules="@xml/data_extraction_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:appCategory="audio"
android:supportsRtl="true"
android:localeConfig="@xml/locale_config"
android:networkSecurityConfig="@xml/network_security_config"
android:supportsRtl="true"
android:theme="@style/Theme.SimpMusic"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules">
android:usesCleartextTraffic="true">
<receiver
android:name=".ui.widget.BasicWidget"
android:exported="false">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>

<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/new_app_widget_info" />
</receiver>

<activity
android:name=".ui.MainActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:exported="true"
android:launchMode="singleTask"
android:configChanges="keyboardHidden|orientation|screenSize">
android:launchMode="singleTask">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
Expand Down Expand Up @@ -66,7 +106,6 @@
<!-- playlist prefix -->
<data android:pathPrefix="/playlist" />
</intent-filter>

<intent-filter>
<action android:name="android.intent.action.VIEW" />
<action android:name="android.media.action.MEDIA_PLAY_FROM_SEARCH" />
Expand Down Expand Up @@ -101,21 +140,24 @@
<data android:mimeType="text/plain" />
</intent-filter>

<meta-data android:name="android.app.shortcuts"
<meta-data
android:name="android.app.shortcuts"
android:resource="@xml/shortcuts" />
</activity>
<receiver android:name="androidx.media3.session.MediaButtonReceiver"

<receiver
android:name="androidx.media3.session.MediaButtonReceiver"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
</receiver>

<provider
android:name="androidx.startup.InitializationProvider"
android:authorities="${applicationId}.androidx-startup"
android:exported="false"
tools:node="merge">
</provider>
tools:node="merge"></provider>
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.FileProvider"
Expand All @@ -135,21 +177,23 @@

<service
android:name=".service.SimpleMediaService"
android:foregroundServiceType="mediaPlayback"
android:stopWithTask="false"
android:enabled="true"
android:exported="true">
android:exported="true"
android:foregroundServiceType="mediaPlayback"
android:stopWithTask="false">
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService" />
<action android:name="androidx.media3.session.MediaLibraryService" />
<action android:name="android.media.browse.MediaBrowserService" />
</intent-filter>
</service>
<service android:name=".service.test.download.MusicDownloadService"
<service
android:name=".service.test.download.MusicDownloadService"
android:exported="false"
android:foregroundServiceType="dataSync">
<intent-filter>
<action android:name="androidx.media3.exoplayer.downloadService.action.RESTART" />

<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</service>
Expand All @@ -167,31 +211,4 @@
android:resource="@xml/automotive_app_desc" />
</application>

<uses-feature
android:name="android.hardware.type.automotive"
android:required="false" />

<uses-feature
android:name="android.hardware.wifi"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.portrait"
android:required="false" />
<uses-feature
android:name="android.hardware.screen.landscape"
android:required="false" />

<queries>
<intent>
<action android:name="android.media.action.DISPLAY_AUDIO_EFFECT_CONTROL_PANEL" />
</intent>
</queries>
<queries>
<package android:name="com.maxrave.simpmusic" />
</queries>
<queries>
<intent>
<action android:name="androidx.media3.session.MediaSessionService"/>
</intent>
</queries>
</manifest>
7 changes: 7 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/extension/AllExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.ActivityManager
import android.app.Service
import android.content.Context
import android.graphics.Color
import android.graphics.Point
import android.os.Bundle
import android.text.Html
import android.view.View
Expand Down Expand Up @@ -511,6 +512,12 @@ fun setEnabledAll(v: View, enabled: Boolean) {
}
}

fun getScreenSize(context: Context): Point {
val x: Int = context.resources.displayMetrics.widthPixels
val y: Int = context.resources.displayMetrics.heightPixels
return Point(x, y)
}

fun ArrayList<String>.removeConflicts(): ArrayList<String> {
val nonConflictingSet = HashSet<String>()
val nonConflictingList = ArrayList<String>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import com.maxrave.simpmusic.di.DownloadCache
import com.maxrave.simpmusic.di.PlayerCache
import com.maxrave.simpmusic.service.test.CoilBitmapLoader
import com.maxrave.simpmusic.ui.MainActivity
import com.maxrave.simpmusic.ui.widget.BasicWidget
import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.cancellable
Expand Down Expand Up @@ -111,6 +112,21 @@ class SimpleMediaService : MediaLibraryService() {

@UnstableApi
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
if (intent != null && intent.action != null) {
when (intent.action) {
BasicWidget.ACTION_TOGGLE_PAUSE -> {
if (player.isPlaying) player.pause() else player.play()
}

BasicWidget.ACTION_SKIP -> {
player.seekToNext()
}

BasicWidget.ACTION_REWIND -> {
player.seekToPrevious()
}
}
}
return super.onStartCommand(intent, flags, startId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import kotlinx.coroutines.flow.cancellable
import kotlinx.coroutines.flow.first

@UnstableApi
class SimpleMediaServiceHandler constructor(
class SimpleMediaServiceHandler(
val player: ExoPlayer,
private val mediaSession: MediaSession,
mediaSessionCallback: SimpleMediaSessionCallback,
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/com/maxrave/simpmusic/ui/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.maxrave.simpmusic.ui

import android.Manifest
import android.appwidget.AppWidgetManager
import android.content.BroadcastReceiver
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.ServiceConnection
import android.content.res.Configuration
import android.graphics.Bitmap
Expand All @@ -21,6 +25,7 @@ import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.ContextCompat
import androidx.core.graphics.ColorUtils
import androidx.core.net.toUri
import androidx.core.os.LocaleListCompat
Expand Down Expand Up @@ -61,6 +66,9 @@ import com.maxrave.simpmusic.extension.navigateSafe
import com.maxrave.simpmusic.extension.setTextAnimation
import com.maxrave.simpmusic.service.SimpleMediaService
import com.maxrave.simpmusic.service.SimpleMediaServiceHandler
import com.maxrave.simpmusic.ui.widget.BaseAppWidget.Companion.APP_WIDGET_UPDATE
import com.maxrave.simpmusic.ui.widget.BaseAppWidget.Companion.EXTRA_APP_WIDGET_NAME
import com.maxrave.simpmusic.ui.widget.BasicWidget
import com.maxrave.simpmusic.viewModel.SharedViewModel
import com.maxrave.simpmusic.viewModel.UIEvent
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -503,7 +511,6 @@ class MainActivity : AppCompatActivity() {
viewModel.onUIEvent(UIEvent.PlayPause)
}
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.CREATED) {
val job1 = launch {
viewModel.intent.collectLatest { intent ->
if (intent != null){
Expand Down Expand Up @@ -587,7 +594,6 @@ class MainActivity : AppCompatActivity() {
}
}
job1.join()
}
}
lifecycleScope.launch {
val job1 = launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.graphics.Color
import android.graphics.Insets
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.TransitionDrawable
Expand All @@ -17,7 +16,6 @@ import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowInsets
import android.view.animation.AnimationUtils
import android.widget.Toast
import androidx.core.graphics.ColorUtils
Expand Down Expand Up @@ -164,8 +162,6 @@ class NowPlayingFragment : Fragment() {
fun getScreenHeight(activity: Activity): Int {
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val windowMetrics = activity.windowManager.currentWindowMetrics
val insets: Insets = windowMetrics.windowInsets
.getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
(windowMetrics.bounds.height())
} else {
val displayMetrics = DisplayMetrics()
Expand Down
Loading

0 comments on commit d5ea876

Please sign in to comment.