Skip to content

Commit

Permalink
Removed pin,review,recommend strings from constants
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavkonidena committed Feb 21, 2024
1 parent a87ae57 commit 73ad09b
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ package org.listenbrainz.android.model

data class SocialUiState(
val error: ResponseError? = null,
val successMsg : String? = null
val successMsgId : Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,47 +4,37 @@ import android.content.res.Configuration.UI_MODE_NIGHT_YES
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.expandVertically
import androidx.compose.animation.shrinkVertically
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.material.Text
import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.listenbrainz.android.model.ResponseError
import org.listenbrainz.android.ui.theme.ListenBrainzTheme

import org.listenbrainz.android.R

@Composable
fun SuccessBar(
message : String?,
resId : Int?,
onMessageShown: () -> Unit,
snackbarState : SnackbarHostState
) {
LaunchedEffect(message) {
if (message != null) {
val context = LocalContext.current;
LaunchedEffect(resId) {
if (resId != null) {
delay(4000)
onMessageShown()
}
}

AnimatedVisibility(
visible = message != null,
visible = resId != null,
enter = expandVertically(),
exit = shrinkVertically()
) {
LaunchedEffect(key1 = message){
if(message != null){
snackbarState.showSnackbar(message)
LaunchedEffect(key1 = resId){
if(resId != null){
snackbarState.showSnackbar(context.getString(resId))
}
}
}
Expand All @@ -55,6 +45,6 @@ fun SuccessBar(
@Composable
private fun SuccessBarPreview() {
ListenBrainzTheme {
ErrorBar(error = ResponseError.NETWORK_ERROR) {}
SuccessBar(resId = R.string.about_title , onMessageShown = {} , snackbarState = SnackbarHostState())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,13 @@ import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalUriHandler
import androidx.compose.ui.platform.UriHandler
import androidx.compose.ui.tooling.preview.Preview
import androidx.hilt.navigation.compose.hiltViewModel
import kotlinx.coroutines.launch
import org.listenbrainz.android.R
import org.listenbrainz.android.model.Listen
import org.listenbrainz.android.model.Metadata
import org.listenbrainz.android.model.SocialUiState
Expand All @@ -52,7 +54,6 @@ import org.listenbrainz.android.ui.screens.feed.SocialDropdown
import org.listenbrainz.android.ui.screens.profile.UserData
import org.listenbrainz.android.ui.screens.settings.PreferencesUiState
import org.listenbrainz.android.ui.theme.ListenBrainzTheme
import org.listenbrainz.android.util.Constants
import org.listenbrainz.android.util.Utils
import org.listenbrainz.android.viewmodel.FeedViewModel
import org.listenbrainz.android.viewmodel.ListensViewModel
Expand Down Expand Up @@ -171,6 +172,8 @@ fun ListensScreen(
val dialogsState = rememberDialogsState()

val scope = rememberCoroutineScope()

val context = LocalContext.current

// Scroll to the top when shouldScrollToTop becomes true
LaunchedEffect(scrollRequestState) {
Expand Down Expand Up @@ -266,7 +269,7 @@ fun ListensScreen(
}
catch(e : Error) {
scope.launch {
snackbarState.showSnackbar(Constants.Strings.ERROR_MESSAGE)
snackbarState.showSnackbar(context.getString(R.string.err_generic_toast))
}
}
dropdownItemIndex.value = null
Expand All @@ -285,7 +288,7 @@ fun ListensScreen(
}

ErrorBar(error = socialUiState.error, onErrorShown = onErrorShown )
SuccessBar(message = socialUiState.successMsg, onMessageShown = onMessageShown, snackbarState = snackbarState)
SuccessBar(resId = socialUiState.successMsgId, onMessageShown = onMessageShown, snackbarState = snackbarState)

Dialogs(
deactivateDialog = {
Expand Down Expand Up @@ -331,6 +334,7 @@ private fun Dialogs(
snackbarState: SnackbarHostState,
socialUiState: SocialUiState
) {
val context = LocalContext.current
when (currentDialog) {
Dialog.NONE -> Unit
Dialog.PIN -> {
Expand All @@ -340,7 +344,7 @@ private fun Dialogs(
})
LaunchedEffect(socialUiState.error){
if(socialUiState.error == null){
snackbarState.showSnackbar(Constants.Strings.PIN_GREETING)
snackbarState.showSnackbar(context.getString(R.string.pin_greeting))
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/org/listenbrainz/android/util/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ object Constants {
const val REFRESH_TOKEN = "refresh_token"
const val STATUS_LOGGED_IN = 1
const val STATUS_LOGGED_OUT = 0
const val RECOMMENDATION_GREETING = "Song recommended successfully!"
const val PERSONAL_RECOMMENDATION_GREETING = "Song recommendation sent successfully!"
const val REVIEW_GREETING = "Song review submitted successfully!"
const val PIN_GREETING = "Song pinned successfully!"
const val ERROR_MESSAGE = "Error occurred! Please try again later!"

const val CHANNEL_NOTI_SCROBBLING = "noti_scrobbling"
const val CHANNEL_NOTI_SCR_ERR = "noti_scrobble_errors"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.listenbrainz.android.model.ResponseError
abstract class BaseViewModel<UiState>: ViewModel() {

protected val errorFlow = MutableStateFlow<ResponseError?>(null)
protected val successMsgFlow = MutableStateFlow<String?>(null)
protected val successMsgFlow = MutableStateFlow<Int?>(null)
/** Visible Ui-State for UI to consume.*/
abstract val uiState: StateFlow<UiState>

Expand All @@ -23,9 +23,9 @@ abstract class BaseViewModel<UiState>: ViewModel() {
}
}

protected fun emitMsg(message : String?){
protected fun emitMsg(messageId : Int?){
viewModelScope.launch {
successMsgFlow.emit(message)
successMsgFlow.emit(messageId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import org.listenbrainz.android.model.feed.ReviewEntityType
import org.listenbrainz.android.repository.preferences.AppPreferences
import org.listenbrainz.android.repository.remoteplayer.RemotePlaybackHandler
import org.listenbrainz.android.repository.social.SocialRepository
import org.listenbrainz.android.util.Constants
import org.listenbrainz.android.util.Resource
import javax.inject.Inject
import org.listenbrainz.android.R

@HiltViewModel
class SocialViewModel @Inject constructor(
Expand Down Expand Up @@ -108,7 +108,7 @@ class SocialViewModel @Inject constructor(
emitError(result.error)
}
else if(result.status == Resource.Status.SUCCESS){
emitMsg(Constants.Strings.RECOMMENDATION_GREETING)
emitMsg(R.string.recommendation_greeting)
}
}
}
Expand All @@ -135,7 +135,7 @@ class SocialViewModel @Inject constructor(
emitError(result.error)
}
else if(result.status == Resource.Status.SUCCESS){
emitMsg(Constants.Strings.PERSONAL_RECOMMENDATION_GREETING)
emitMsg(R.string.personal_recommendation_greeting)
}
}

Expand All @@ -162,7 +162,7 @@ class SocialViewModel @Inject constructor(
emitError(result.error)
}
else if(result.status == Resource.Status.SUCCESS){
emitMsg(Constants.Strings.REVIEW_GREETING)
emitMsg(R.string.review_greeting)
}
}
}
Expand All @@ -180,7 +180,7 @@ class SocialViewModel @Inject constructor(
emitError(result.error)
}
else if(result.status == Resource.Status.SUCCESS){
emitMsg(Constants.Strings.PIN_GREETING)
emitMsg(R.string.pin_greeting)
}
}
}
Expand Down

0 comments on commit 73ad09b

Please sign in to comment.