Skip to content

Commit

Permalink
Release 0.5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Sep 3, 2023
2 parents e73b961 + a4e2df6 commit 2dd6d84
Show file tree
Hide file tree
Showing 80 changed files with 2,291 additions and 1,740 deletions.
7 changes: 3 additions & 4 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,18 @@ android {
applicationId = "com.zionhuang.music"
minSdk = 24
targetSdk = 33
versionCode = 18
versionName = "0.5.2"
versionCode = 19
versionName = "0.5.3"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = true
isShrinkResources = true
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"), "proguard-rules.pro")
resValue("string", "app_name", "InnerTune")
}
debug {
applicationIdSuffix = ".debug"
resValue("string", "app_name", "InnerTune Debug")
}
}
flavorDimensions += "version"
Expand Down Expand Up @@ -107,6 +105,7 @@ dependencies {
implementation(libs.compose.ui.tooling)
implementation(libs.compose.animation)
implementation(libs.compose.animation.graphics)
implementation(libs.compose.reorderable)

implementation(libs.viewmodel)
implementation(libs.viewmodel.compose)
Expand Down
4 changes: 4 additions & 0 deletions app/src/debug/res/values/app_name.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">InnerTune Debug</string>
</resources>
1 change: 0 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@

<service
android:name=".playback.MusicService"
android:enabled="true"
android:exported="true"
android:foregroundServiceType="mediaPlayback"
tools:ignore="ExportedService">
Expand Down
21 changes: 2 additions & 19 deletions app/src/main/java/com/zionhuang/music/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ import androidx.core.view.WindowCompat
import androidx.lifecycle.lifecycleScope
import androidx.media3.common.MediaItem
import androidx.media3.common.Player
import androidx.media3.session.MediaController
import androidx.media3.session.SessionToken
import androidx.navigation.NavDestination.Companion.hierarchy
import androidx.navigation.NavType
import androidx.navigation.compose.NavHost
Expand All @@ -63,7 +61,6 @@ import androidx.navigation.compose.rememberNavController
import androidx.navigation.navArgument
import coil.imageLoader
import coil.request.ImageRequest
import com.google.common.util.concurrent.MoreExecutors
import com.valentinilk.shimmer.LocalShimmerTheme
import com.zionhuang.innertube.YouTube
import com.zionhuang.innertube.models.SongItem
Expand Down Expand Up @@ -121,7 +118,6 @@ class MainActivity : ComponentActivity() {
lateinit var downloadUtil: DownloadUtil

private var playerConnection by mutableStateOf<PlayerConnection?>(null)
private var mediaController: MediaController? = null
private val serviceConnection = object : ServiceConnection {
override fun onServiceConnected(name: ComponentName?, service: IBinder?) {
if (service is MusicBinder) {
Expand All @@ -138,17 +134,13 @@ class MainActivity : ComponentActivity() {

override fun onStart() {
super.onStart()
startService(Intent(this, MusicService::class.java))
bindService(Intent(this, MusicService::class.java), serviceConnection, Context.BIND_AUTO_CREATE)
}

override fun onStop() {
super.onStop()
unbindService(serviceConnection)
}

override fun onDestroy() {
super.onDestroy()
mediaController?.release()
super.onStop()
}

@SuppressLint("UnusedMaterial3ScaffoldPaddingParameter")
Expand All @@ -157,14 +149,6 @@ class MainActivity : ComponentActivity() {
super.onCreate(savedInstanceState)
WindowCompat.setDecorFitsSystemWindows(window, false)

// Connect to service so that notification and background playing will work
val sessionToken = SessionToken(this, ComponentName(this, MusicService::class.java))
val controllerFuture = MediaController.Builder(this, sessionToken).buildAsync()
controllerFuture.addListener(
{ mediaController = controllerFuture.get() },
MoreExecutors.directExecutor()
)

setupRemoteConfig()

setContent {
Expand Down Expand Up @@ -794,7 +778,6 @@ class MainActivity : ComponentActivity() {
YouTubeSongMenu(
song = song,
navController = navController,
playerConnection = playerConnection,
onDismiss = { sharedSong = null }
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ val AlbumThumbnailSize = 144.dp

val ThumbnailCornerRadius = 6.dp

val PlayerHorizontalPadding = 32.dp

val NavigationBarAnimationSpec = spring<Dp>(stiffness = Spring.StiffnessMediumLow)
13 changes: 13 additions & 0 deletions app/src/main/java/com/zionhuang/music/constants/PreferenceKeys.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,22 @@ val ArtistSongSortDescendingKey = booleanPreferencesKey("artistSongSortDescendin

val SongFilterKey = stringPreferencesKey("songFilter")
val ArtistFilterKey = stringPreferencesKey("artistFilter")
val ArtistViewTypeKey = stringPreferencesKey("artistViewType")
val AlbumFilterKey = stringPreferencesKey("albumFilter")
val AlbumViewTypeKey = stringPreferencesKey("albumViewType")
val PlaylistViewTypeKey = stringPreferencesKey("playlistViewType")

val PlaylistEditLockKey = booleanPreferencesKey("playlistEditLock")

enum class LibraryViewType {
LIST, GRID;

fun toggle() = when (this) {
LIST -> GRID
GRID -> LIST
}
}

enum class SongSortType {
CREATE_DATE, NAME, ARTIST, PLAY_TIME
}
Expand Down Expand Up @@ -106,6 +118,7 @@ val VisitorDataKey = stringPreferencesKey("visitorData")
val InnerTubeCookieKey = stringPreferencesKey("innerTubeCookie")
val AccountNameKey = stringPreferencesKey("accountName")
val AccountEmailKey = stringPreferencesKey("accountEmail")
val AccountChannelHandleKey = stringPreferencesKey("accountChannelHandle")

val LanguageCodeToName = mapOf(
"af" to "Afrikaans",
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/zionhuang/music/db/DatabaseDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -310,8 +310,8 @@ interface DatabaseDao {
.reversed(descending)
}

@Query("SELECT * FROM artist WHERE id = :id")
fun artist(id: String): Flow<ArtistEntity?>
@Query("SELECT *, (SELECT COUNT(1) FROM song_artist_map JOIN song ON song_artist_map.songId = song.id WHERE artistId = artist.id AND song.inLibrary IS NOT NULL) AS songCount FROM artist WHERE id = :id")
fun artist(id: String): Flow<Artist?>

@Transaction
@Query("SELECT * FROM album WHERE EXISTS(SELECT * FROM song WHERE song.albumId = album.id AND song.inLibrary IS NOT NULL) ORDER BY rowId")
Expand Down
32 changes: 21 additions & 11 deletions app/src/main/java/com/zionhuang/music/di/AppModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,29 @@ object AppModule {
@Singleton
@Provides
@PlayerCache
fun providePlayerCache(@ApplicationContext context: Context, databaseProvider: DatabaseProvider): SimpleCache =
SimpleCache(
context.filesDir.resolve("exoplayer"),
when (val cacheSize = context.dataStore[MaxSongCacheSizeKey] ?: 1024) {
-1 -> NoOpCacheEvictor()
else -> LeastRecentlyUsedCacheEvictor(cacheSize * 1024 * 1024L)
},
databaseProvider
)
fun providePlayerCache(@ApplicationContext context: Context, databaseProvider: DatabaseProvider): SimpleCache {
val constructor = {
SimpleCache(
context.filesDir.resolve("exoplayer"),
when (val cacheSize = context.dataStore[MaxSongCacheSizeKey] ?: 1024) {
-1 -> NoOpCacheEvictor()
else -> LeastRecentlyUsedCacheEvictor(cacheSize * 1024 * 1024L)
},
databaseProvider
)
}
constructor().release()
return constructor()
}

@Singleton
@Provides
@DownloadCache
fun provideDownloadCache(@ApplicationContext context: Context, databaseProvider: DatabaseProvider): SimpleCache =
SimpleCache(context.filesDir.resolve("download"), NoOpCacheEvictor(), databaseProvider)
fun provideDownloadCache(@ApplicationContext context: Context, databaseProvider: DatabaseProvider): SimpleCache {
val constructor = {
SimpleCache(context.filesDir.resolve("download"), NoOpCacheEvictor(), databaseProvider)
}
constructor().release()
return constructor()
}
}
3 changes: 1 addition & 2 deletions app/src/main/java/com/zionhuang/music/extensions/ListExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package com.zionhuang.music.extensions
fun <T> List<T>.reversed(reversed: Boolean) = if (reversed) asReversed() else this

fun <T> MutableList<T>.move(fromIndex: Int, toIndex: Int): MutableList<T> {
val item = removeAt(fromIndex)
add(toIndex, item)
add(toIndex, removeAt(fromIndex))
return this
}
3 changes: 3 additions & 0 deletions app/src/main/java/com/zionhuang/music/extensions/PlayerExt.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ import com.zionhuang.music.models.MediaMetadata
import java.util.ArrayDeque

fun Player.togglePlayPause() {
if (!playWhenReady && playbackState == Player.STATE_IDLE) {
prepare()
}
playWhenReady = !playWhenReady
}

Expand Down
Loading

0 comments on commit 2dd6d84

Please sign in to comment.