Skip to content

Commit

Permalink
Better architecture. Hot fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
maxrave-dev committed Oct 11, 2023
1 parent 44cb21e commit c477d22
Show file tree
Hide file tree
Showing 35 changed files with 1,580 additions and 1,228 deletions.
2 changes: 1 addition & 1 deletion .idea/kotlinc.xml

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

6 changes: 3 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ dependencies {
implementation("androidx.core:core-ktx:1.12.0")
implementation("androidx.appcompat:appcompat:1.6.1")
//material design3
implementation("com.google.android.material:material:1.9.0")
implementation("com.google.android.material:material:1.10.0")
//runtime
implementation("androidx.startup:startup-runtime:1.1.1")
implementation(project(mapOf("path" to ":kotlinYtmusicScraper")))
Expand Down Expand Up @@ -93,8 +93,8 @@ dependencies {
//Coroutines
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.7.3")
//Navigation
implementation("androidx.navigation:navigation-fragment-ktx:2.7.3")
implementation("androidx.navigation:navigation-ui-ktx:2.7.3")
implementation("androidx.navigation:navigation-fragment-ktx:2.7.4")
implementation("androidx.navigation:navigation-ui-ktx:2.7.4")

implementation("com.google.code.gson:gson:2.10.1")

Expand Down
4 changes: 1 addition & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<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"/>

<application
android:name=".SimpMusicApplication"
Expand Down Expand Up @@ -133,9 +134,6 @@
<intent-filter>
<action android:name="androidx.media3.session.MediaSessionService"/>
</intent-filter>
</service>
<service android:name=".service.test.source.FetchQueue">

</service>
<service android:name=".service.test.download.MusicDownloadService"
android:exported="false">
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/java/com/maxrave/simpmusic/SimpMusicApplication.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.maxrave.simpmusic

import android.app.Application
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.media3.common.util.UnstableApi
import cat.ereza.customactivityoncrash.config.CaocConfig
Expand All @@ -26,4 +27,15 @@ class SimpMusicApplication: Application(){
.restartActivity(MainActivity::class.java) //default: null (your app's launch activity)
.apply()
}

override fun onLowMemory() {
super.onLowMemory()
Log.w("Low Memory", "Checking")
}

override fun onTerminate() {
super.onTerminate()

Log.w("Terminate", "Checking")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import com.maxrave.simpmusic.data.model.explore.mood.genre.ItemsPlaylist
import com.maxrave.simpmusic.databinding.ItemMoodMomentPlaylistBinding

class GenreItemAdapter(private var genreList: ArrayList<ItemsPlaylist>, val context: Context, val navController: NavController): RecyclerView.Adapter<GenreItemAdapter.ViewHolder>() {
inner class ViewHolder(val binding: ItemMoodMomentPlaylistBinding): RecyclerView.ViewHolder(binding.root) {
inner class ViewHolder(val binding: ItemMoodMomentPlaylistBinding): RecyclerView.ViewHolder(binding.root)

}
fun updateData(newList: ArrayList<ItemsPlaylist>){
genreList.clear()
genreList.addAll(newList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ import com.maxrave.simpmusic.data.model.explore.mood.moodmoments.Item
import com.maxrave.simpmusic.databinding.ItemMoodMomentPlaylistBinding

class MoodItemAdapter(private var itemList: ArrayList<Item>, val context: Context, val navController: NavController): RecyclerView.Adapter<MoodItemAdapter.ViewHolder>() {
inner class ViewHolder(val binding: ItemMoodMomentPlaylistBinding): RecyclerView.ViewHolder(binding.root) {
inner class ViewHolder(val binding: ItemMoodMomentPlaylistBinding): RecyclerView.ViewHolder(binding.root)

}
fun updateData(newList: ArrayList<Item>){
itemList.clear()
itemList.addAll(newList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ class PlaylistItemAdapter(private var playlistItemList: ArrayList<Any>): Recycle
}
}
fun updateList(newList: ArrayList<Any>){
Log.d("PlaylistItemAdapter", "updateList: ${newList.toString()}")
Log.d("PlaylistItemAdapter", "updateList: $newList")
playlistItemList.clear()
newList.forEach {
playlistItemList.add(it)
}
Log.d("PlaylistItemAdapter", "updateList: ${playlistItemList.toString()}")
Log.d("PlaylistItemAdapter", "updateList: $playlistItemList")
notifyDataSetChanged()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.maxrave.simpmusic.data.dataStore

import android.content.Context
import android.util.Log
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
Expand All @@ -10,7 +9,6 @@ import androidx.media3.common.Player
import com.maxrave.simpmusic.common.SELECTED_LANGUAGE
import com.maxrave.simpmusic.common.SPONSOR_BLOCK
import com.maxrave.simpmusic.common.SUPPORTED_LANGUAGE
import dagger.hilt.android.qualifiers.ApplicationContext
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first
Expand All @@ -19,7 +17,7 @@ import kotlinx.coroutines.withContext
import javax.inject.Inject
import com.maxrave.simpmusic.common.QUALITY as COMMON_QUALITY

class DataStoreManager @Inject constructor(@ApplicationContext appContext: Context, private val settingsDataStore: DataStore<Preferences>) {
class DataStoreManager @Inject constructor(private val settingsDataStore: DataStore<Preferences>) {

val location: Flow<String> = settingsDataStore.data.map { preferences ->
preferences[LOCATION] ?: "VN"
Expand Down Expand Up @@ -234,6 +232,7 @@ class DataStoreManager @Inject constructor(@ApplicationContext appContext: Conte
preferences[RECENT_SONG_POSITION_KEY] ?: "0"
}
suspend fun saveRecentSong (mediaId: String, position: Long) {
Log.w("saveRecentSong", "$mediaId $position")
withContext(Dispatchers.IO) {
settingsDataStore.edit { settings ->
settings[RECENT_SONG_MEDIA_ID_KEY] = mediaId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ data class HomeResponse(
val homeItem: Resource<ArrayList<HomeItem>>,
val exploreMood: Resource<Mood>,
val exploreChart: Resource<Chart>
) {
}
)
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ fun parseSongChart(contents: List<MusicCarouselShelfRenderer.Content>): ArrayLis
var view = ""
val artists: ArrayList<Artist> = arrayListOf()
val albums: ArrayList<Album> = arrayListOf()
if (runs != null) {
if (runs != null) {
for (i in runs.indices) {
if (i.rem(2) == 0) {
if (i == runs.size -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ fun parseMixedContent(data: List<SectionListRenderer.Content>?): List<HomeItem>
if (ytItem != null) {
listContent.add(
Content(
album = Album( id = musicTwoRowItemRenderer.navigationEndpoint.browseEndpoint?.browseId ?: "", name = title ?: ""),
album = Album( id = musicTwoRowItemRenderer.navigationEndpoint.browseEndpoint?.browseId ?: "", name = title),
artists = listOf(),
description = null,
isExplicit = false,
Expand Down Expand Up @@ -214,7 +214,7 @@ fun parseMixedContent(data: List<SectionListRenderer.Content>?): List<HomeItem>
if (ytItemAlbum != null) {
listContent.add(
Content(
album = Album( id = musicTwoRowItemRenderer.navigationEndpoint.browseEndpoint?.browseId ?: "", name = title ?: ""),
album = Album( id = musicTwoRowItemRenderer.navigationEndpoint.browseEndpoint?.browseId ?: "", name = title),
artists = listOf(),
description = null,
isExplicit = false,
Expand Down Expand Up @@ -264,8 +264,8 @@ fun parseMixedContent(data: List<SectionListRenderer.Content>?): List<HomeItem>
playlistId = null,
browseId = null,
thumbnails = result1.musicResponsiveListItemRenderer!!.thumbnail?.musicThumbnailRenderer?.thumbnail?.thumbnails?.toListThumbnail() ?: listOf(),
title = ytItem.title ?: "",
videoId = ytItem.id ?: "",
title = ytItem.title,
videoId = ytItem.id,
views = "",
radio = null
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,14 @@ fun parseMoodsMomentObject(data: BrowseResponse?): MoodsMomentObject? {
val contentTitle =
content.musicTwoRowItemRenderer?.title?.runs?.get(0)?.text
val playlistBrowseId = content.musicTwoRowItemRenderer?.navigationEndpoint?.browseEndpoint?.browseId
listContent.add(
Content(
playlistBrowseId = playlistBrowseId ?: "",
subtitle = subtitle,
thumbnails = thumbnails ?: listOf(),
title = contentTitle ?: ""
)
listContent.add(
Content(
playlistBrowseId = playlistBrowseId ?: "",
subtitle = subtitle,
thumbnails = thumbnails ?: listOf(),
title = contentTitle ?: ""
)
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ class MainRepository @Inject constructor(private val localDataSource: LocalDataS
withContext(Dispatchers.IO) { localDataSource.insertFormat(format) }

suspend fun getFormat(videoId: String): Flow<FormatEntity?> =
flow { emit(localDataSource.getFormat(videoId)) }.flowOn(Dispatchers.IO)
flow { emit(localDataSource.getFormat(videoId)) }.flowOn(Dispatchers.Main)


suspend fun recoverQueue(temp: List<Track>) {
Expand Down Expand Up @@ -1166,7 +1166,7 @@ class MainRepository @Inject constructor(private val localDataSource: LocalDataS

suspend fun removeYouTubePlaylistItem(youtubePlaylistId: String, videoId: String) = flow {
runCatching {
getSetVideoId(videoId).collect() { setVideoId ->
getSetVideoId(videoId).collect { setVideoId ->
if (setVideoId?.setVideoId != null) {
YouTube.removeItemYouTubePlaylist(youtubePlaylistId, videoId, setVideoId.setVideoId).onSuccess {
emit(it)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,7 @@ object LocalServiceModule {

@Provides
@Singleton
fun provideDatastoreManager(@ApplicationContext context: Context, settingsDataStore: DataStore<Preferences>): DataStoreManager = DataStoreManager(context, settingsDataStore)
fun provideDatastoreManager(settingsDataStore: DataStore<Preferences>): DataStoreManager = DataStoreManager(
settingsDataStore
)
}
Loading

0 comments on commit c477d22

Please sign in to comment.