Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement data store #387

Open
wants to merge 12 commits into
base: dev
Choose a base branch
from
4 changes: 3 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ Got **something interesting** you'd like to **ask or share**? Start a discussion

## Roadmap

Proposed future plans for the app are discussed [here](https://docs.google.com/document/d/1hY5oloIiANeXg1R9oSBIr2ZUHSlm7LU8qy6tW1VJMQg/edit?usp=sharing).
- Proposed future plans for the app are discussed [here](https://docs.google.com/document/d/1hY5oloIiANeXg1R9oSBIr2ZUHSlm7LU8qy6tW1VJMQg/edit?usp=sharing).
- Official Release Plan is [here](https://docs.google.com/document/d/1LSDXWciL4LMS_LJJ0Y47BZtU6jEI-8hiliWbzEOYKsA/edit?usp=sharing)
- Future features are discussed [here](https://docs.google.com/document/d/1fmsgFVvxAN39nUyaMsEdyePBaDyDwxelJXeLhaDylhs/edit?usp=sharing)

## Issues

Expand Down
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ dependencies {
implementation 'androidx.paging:paging-runtime-ktx:3.2.1'
implementation "androidx.paging:paging-compose:3.2.1"

// Typesafe-datastore
implementation "com.github.07jasjeet.typesafe-datastore:typesafe-datastore:$typesafe_datastore_version"
implementation "com.github.07jasjeet.typesafe-datastore:typesafe-datastore-gson:$typesafe_datastore_version"
testImplementation "com.github.07jasjeet.typesafe-datastore:typesafe-datastore-test:$typesafe_datastore_version"

//Image downloading and Caching library
implementation 'com.github.bumptech.glide:glide:4.16.0'
Expand Down Expand Up @@ -217,6 +221,7 @@ dependencies {
// Mockito framework
testImplementation 'org.mockito:mockito-core:5.10.0'
testImplementation 'org.mockito.kotlin:mockito-kotlin:5.2.1'
androidTestImplementation "org.mockito:mockito-android:5.2.1"

debugImplementation "androidx.test:monitor:1.6.1" // Solves "class PlatformTestStorageRegistery not found" error for ui tests.
debugImplementation 'androidx.compose.ui:ui-test-manifest:1.6.1'
Expand Down
27 changes: 27 additions & 0 deletions app/src/androidTest/java/org/listenbrainz/android/Extensions.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.listenbrainz.android

import androidx.activity.ComponentActivity
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.test.junit4.AndroidComposeTestRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import org.listenbrainz.android.model.UiMode
import org.listenbrainz.android.ui.theme.ListenBrainzTheme
import org.listenbrainz.android.ui.theme.isUiModeIsDark

fun AndroidComposeTestRule<ActivityScenarioRule<ComponentActivity>, ComponentActivity>.setExplicitContent(
uiMode: UiMode = UiMode.DARK,
content: @Composable () -> Unit
) {
isUiModeIsDark = when(uiMode) {
UiMode.LIGHT -> mutableStateOf(false)
UiMode.DARK -> mutableStateOf(true)
UiMode.FOLLOW_SYSTEM -> mutableStateOf(null)
}

this.setContent {
ListenBrainzTheme {
content()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@ package org.listenbrainz.android

import androidx.activity.ComponentActivity
import androidx.annotation.StringRes
import androidx.compose.ui.test.*
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.performScrollTo
import androidx.compose.ui.test.performTouchInput
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.listenbrainz.android.repository.preferences.AppPreferences
import org.listenbrainz.android.ui.screens.yim.navigation.YimNavigation
import org.listenbrainz.android.util.connectivityobserver.ConnectivityObserver
import org.listenbrainz.android.viewmodel.YimViewModel
import org.listenbrainz.sharedtest.mocks.MockAppPreferences
import org.listenbrainz.sharedtest.mocks.MockNetworkConnectivityViewModel
import org.listenbrainz.sharedtest.mocks.MockYimRepository
import org.mockito.Mock
import org.mockito.junit.MockitoJUnitRunner

@RunWith(AndroidJUnit4::class)
@RunWith(MockitoJUnitRunner::class)
//@LargeTest
@HiltAndroidTest
class YearInMusicActivityTest {
Expand All @@ -29,14 +34,16 @@ class YearInMusicActivityTest {
@get:Rule(order = 1)
val rule = createAndroidComposeRule<ComponentActivity>()

@Mock
private lateinit var mockAppPreferences: AppPreferences

private lateinit var activity : ComponentActivity

@Before
fun setup(){
activity = rule.activity
val yimViewModel = YimViewModel(
MockYimRepository(),
MockAppPreferences()
MockYimRepository(), mockAppPreferences
)
val networkViewModel = MockNetworkConnectivityViewModel(ConnectivityObserver.NetworkStatus.AVAILABLE)

Expand Down Expand Up @@ -86,4 +93,8 @@ class YearInMusicActivityTest {
performClick()
}
}

private fun initMocks() {

}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.listenbrainz.android.di

import android.content.Context

import android.util.Log
import androidx.work.Configuration
import androidx.work.WorkManager
Expand All @@ -14,7 +13,6 @@ import dagger.hilt.components.SingletonComponent
import dagger.hilt.testing.TestInstallIn
import org.listenbrainz.android.repository.preferences.AppPreferences
import org.listenbrainz.android.service.BrainzPlayerServiceConnection
import org.listenbrainz.sharedtest.mocks.MockAppPreferences
import javax.inject.Singleton

@Module
Expand Down Expand Up @@ -47,8 +45,8 @@ class TestAppModule {
@Provides
fun providesContext(@ApplicationContext context: Context): Context = context

@Singleton
/*@Singleton
@Provides
fun providesAppPreferences() : AppPreferences = MockAppPreferences()
fun providesAppPreferences() : AppPreferences = MockAppPreferences()*/

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package org.listenbrainz.android.feed

import androidx.activity.ComponentActivity
import androidx.compose.ui.test.junit4.createAndroidComposeRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.LargeTest
import dagger.hilt.android.testing.HiltAndroidTest
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.listenbrainz.android.model.feed.FeedEvent
import org.listenbrainz.android.model.feed.FeedEventType
import org.listenbrainz.android.model.feed.ReviewEntityType
import org.listenbrainz.android.setExplicitContent
import org.listenbrainz.android.ui.screens.feed.FeedScreen
import org.listenbrainz.android.ui.screens.feed.FeedUiState

@RunWith(AndroidJUnit4::class)
@LargeTest
@HiltAndroidTest
class FeedFlowTest {

@get:Rule(order = 0)
val rule = createAndroidComposeRule<ComponentActivity>()

@Before
fun setup(){

rule.setExplicitContent {

FeedScreen(
uiState = FeedUiState(),
scrollToTopState = false,
onScrollToTop = {},
onDeleteOrHide = { feedEvent: FeedEvent, feedEventType: FeedEventType, s: String -> },
onErrorShown = {},
recommendTrack = {},
personallyRecommendTrack = { feedEvent: FeedEvent, strings: List<String>, s: String -> },
review = { feedEvent: FeedEvent, reviewEntityType: ReviewEntityType, s: String, i: Int?, s1: String -> },
pin = { feedEvent: FeedEvent, s: String? -> },
searchFollower = {},
isCritiqueBrainzLinked = { true },
onPlay = {}
)
}
}

@Test
fun feedScreenTest() = runTest {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import dagger.hilt.android.scopes.ServiceScoped
import org.listenbrainz.android.repository.brainzplayer.AlbumRepository
import org.listenbrainz.android.repository.brainzplayer.PlaylistRepository
import org.listenbrainz.android.repository.brainzplayer.SongRepository
import org.listenbrainz.android.util.LocalMusicSource
import org.listenbrainz.android.util.MusicSource
import org.listenbrainz.android.util.brainzplayer.LocalMusicSource
import org.listenbrainz.android.util.brainzplayer.MusicSource

@Module
@InstallIn(ServiceComponent::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import kotlinx.coroutines.withContext
import org.listenbrainz.android.model.Album
import org.listenbrainz.android.model.Song
import org.listenbrainz.android.model.dao.AlbumDao
import org.listenbrainz.android.util.AlbumsData
import org.listenbrainz.android.util.SongsData
import org.listenbrainz.android.util.brainzplayer.AlbumsData
import org.listenbrainz.android.util.brainzplayer.SongsData
import org.listenbrainz.android.util.Transformer.toAlbum
import org.listenbrainz.android.util.Transformer.toAlbumEntity

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import org.listenbrainz.android.model.Album
import org.listenbrainz.android.model.Artist
import org.listenbrainz.android.model.Song
import org.listenbrainz.android.model.dao.ArtistDao
import org.listenbrainz.android.util.AlbumsData
import org.listenbrainz.android.util.SongsData
import org.listenbrainz.android.util.brainzplayer.AlbumsData
import org.listenbrainz.android.util.brainzplayer.SongsData
import org.listenbrainz.android.util.Transformer.toAlbumEntity
import org.listenbrainz.android.util.Transformer.toArtist
import org.listenbrainz.android.util.Transformer.toArtistEntity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import org.listenbrainz.android.model.Song
import org.listenbrainz.android.model.dao.SongDao
import org.listenbrainz.android.util.SongsData
import org.listenbrainz.android.util.brainzplayer.SongsData
import org.listenbrainz.android.util.Transformer.toSong
import org.listenbrainz.android.util.Transformer.toSongEntity
import javax.inject.Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ class ListenServiceManagerImpl @Inject constructor(
/** Used to avoid repetitive submissions.*/
private var lastNotificationPostTs = System.currentTimeMillis()
private lateinit var whitelist: List<String>

private var isListeningAllowed: Boolean = true


init {
with(scope) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package org.listenbrainz.android.repository.preferences

import com.jasjeet.typesafe_datastore.preferences.ComplexPreference
import com.jasjeet.typesafe_datastore.preferences.PrimitivePreference
import kotlinx.coroutines.flow.Flow
import org.listenbrainz.android.model.Playable
import org.listenbrainz.android.model.UiMode
import org.listenbrainz.android.util.LinkedService

interface AppPreferences {

val themePreference: DataStorePreference<UiMode>
val themePreference: ComplexPreference<UiMode>

/**
*
Expand All @@ -21,10 +23,10 @@ interface AppPreferences {
var permissionsPreference: String?

/** Whitelist for ListenSubmissionService.*/
val listeningWhitelist: DataStorePreference<List<String>>
val listeningWhitelist: ComplexPreference<List<String>>

/** Music Apps in users device registered by listenService.*/
val listeningApps: DataStorePreference<List<String>>
val listeningApps: ComplexPreference<List<String>>

var onboardingCompleted: Boolean

Expand All @@ -40,19 +42,19 @@ interface AppPreferences {
suspend fun isUserLoggedIn() : Boolean

/****ListenBrainz User Token:** User has to manually fill this token.*/
val lbAccessToken: DataStorePreference<String>
val lbAccessToken: PrimitivePreference<String>

val username: DataStorePreference<String>
val username: PrimitivePreference<String>

val refreshToken: String?

var linkedServices: List<LinkedService>

/** Default is true. */
val isListeningAllowed: DataStorePreference<Boolean>
val isListeningAllowed: PrimitivePreference<Boolean>

/** Default is true. */
val shouldListenNewPlayers: DataStorePreference<Boolean>
val shouldListenNewPlayers: PrimitivePreference<Boolean>

val isNotificationServiceAllowed: Boolean

Expand Down
Loading
Loading