Internationalization

This commit is contained in:
shabinder 2021-06-26 01:28:00 +05:30
parent 00b8c55e6e
commit 3d28343017
7 changed files with 60 additions and 35 deletions

View File

@ -62,6 +62,7 @@ import com.shabinder.common.models.methods
import com.shabinder.common.root.SpotiFlyerRoot import com.shabinder.common.root.SpotiFlyerRoot
import com.shabinder.common.root.SpotiFlyerRoot.Analytics import com.shabinder.common.root.SpotiFlyerRoot.Analytics
import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks import com.shabinder.common.root.callbacks.SpotiFlyerRootCallBacks
import com.shabinder.common.translations.Strings
import com.shabinder.common.uikit.* import com.shabinder.common.uikit.*
import com.shabinder.spotiflyer.service.ForegroundService import com.shabinder.spotiflyer.service.ForegroundService
import com.shabinder.spotiflyer.ui.AnalyticsDialog import com.shabinder.spotiflyer.ui.AnalyticsDialog
@ -286,7 +287,7 @@ class MainActivity : ComponentActivity() {
override fun shareApp() { override fun shareApp() {
val sendIntent: Intent = Intent().apply { val sendIntent: Intent = Intent().apply {
action = Intent.ACTION_SEND action = Intent.ACTION_SEND
putExtra(Intent.EXTRA_TEXT, "Hey, checkout this excellent Music Downloader http://github.com/Shabinder/SpotiFlyer") putExtra(Intent.EXTRA_TEXT, Strings.shareMessage())
type = "text/plain" type = "text/plain"
} }
@ -376,7 +377,7 @@ class MainActivity : ComponentActivity() {
.setTheme(StorageChooser.Theme(applicationContext).apply { .setTheme(StorageChooser.Theme(applicationContext).apply {
scheme = applicationContext.resources.getIntArray(R.array.default_dark) scheme = applicationContext.resources.getIntArray(R.array.default_dark)
}) })
.setDialogTitle("Set Download Directory") .setDialogTitle(Strings.setDownloadDirectory())
.allowCustomPath(true) .allowCustomPath(true)
.setType(StorageChooser.DIRECTORY_CHOOSER) .setType(StorageChooser.DIRECTORY_CHOOSER)
.build() .build()
@ -388,13 +389,9 @@ class MainActivity : ComponentActivity() {
if (f.canWrite()) { if (f.canWrite()) {
// hell yeah :) // hell yeah :)
preferenceManager.setDownloadDirectory(path) preferenceManager.setDownloadDirectory(path)
showPopUpMessage( showPopUpMessage(Strings.downloadDirectorySetTo("\n${dir.defaultDir()}"))
"Download Directory Set to:\n${dir.defaultDir()} "
)
}else{ }else{
showPopUpMessage( showPopUpMessage(Strings.noWriteAccess("\n$path "))
"NO WRITE ACCESS on \n$path ,\nReverting Back to Previous"
)
} }
} }

View File

@ -240,7 +240,7 @@ class ForegroundService : LifecycleService() {
messageList = messageList.getEmpty().apply { messageList = messageList.getEmpty().apply {
set(index = 0, Message(Strings.cleaningAndExiting(),DownloadStatus.NotDownloaded)) set(index = 0, Message(Strings.cleaningAndExiting(),DownloadStatus.NotDownloaded))
} }
downloadService.value.close() downloadService.getOrNull()?.close()
downloadService.reset() downloadService.reset()
updateNotification() updateNotification()
cleanFiles(File(dir.defaultDir())) cleanFiles(File(dir.defaultDir()))

View File

@ -3,7 +3,6 @@ package com.shabinder.spotiflyer.ui
import androidx.compose.animation.AnimatedVisibility import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.Row
@ -18,7 +17,6 @@ import androidx.compose.material.OutlinedButton
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Close
import androidx.compose.material.icons.rounded.Insights import androidx.compose.material.icons.rounded.Insights
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
@ -28,6 +26,7 @@ import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties import androidx.compose.ui.window.DialogProperties
import com.shabinder.common.translations.Strings
import com.shabinder.common.uikit.SpotiFlyerShapes import com.shabinder.common.uikit.SpotiFlyerShapes
import com.shabinder.common.uikit.SpotiFlyerTypography import com.shabinder.common.uikit.SpotiFlyerTypography
import com.shabinder.common.uikit.colorPrimary import com.shabinder.common.uikit.colorPrimary
@ -45,9 +44,9 @@ fun AnalyticsDialog(
onDismissRequest = dismissDialog, onDismissRequest = dismissDialog,
title = { title = {
Row(verticalAlignment = Alignment.CenterVertically,horizontalArrangement = Arrangement.SpaceEvenly) { Row(verticalAlignment = Alignment.CenterVertically,horizontalArrangement = Arrangement.SpaceEvenly) {
Icon(Icons.Rounded.Insights,"Analytics", Modifier.size(42.dp)) Icon(Icons.Rounded.Insights,Strings.analytics(), Modifier.size(42.dp))
Spacer(Modifier.padding(horizontal = 8.dp)) Spacer(Modifier.padding(horizontal = 8.dp))
Text("Grant Analytics",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center) Text(Strings.grantAnalytics(),style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center)
} }
}, },
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
@ -61,7 +60,7 @@ fun AnalyticsDialog(
shape = SpotiFlyerShapes.medium, shape = SpotiFlyerShapes.medium,
colors = ButtonDefaults.buttonColors(backgroundColor = Color(0xFF303030)) colors = ButtonDefaults.buttonColors(backgroundColor = Color(0xFF303030))
) { ) {
Text("Nope",color = colorPrimary,fontSize = 18.sp,textAlign = TextAlign.Center) Text(Strings.no(),color = colorPrimary,fontSize = 18.sp,textAlign = TextAlign.Center)
} }
Spacer(Modifier.padding(vertical = 4.dp)) Spacer(Modifier.padding(vertical = 4.dp))
TextButton( TextButton(
@ -74,12 +73,12 @@ fun AnalyticsDialog(
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
shape = SpotiFlyerShapes.medium shape = SpotiFlyerShapes.medium
) { ) {
Text("Sure",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center) Text(Strings.yes(),color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center)
} }
} }
}, },
text = { text = {
Text("Your Data is Anonymized and will never be shared with any 3rd party service",style = SpotiFlyerTypography.body2,textAlign = TextAlign.Center) Text(Strings.analyticsDescription(),style = SpotiFlyerTypography.body2,textAlign = TextAlign.Center)
}, },
properties = DialogProperties(dismissOnBackPress = false,dismissOnClickOutside = false) properties = DialogProperties(dismissOnBackPress = false,dismissOnClickOutside = false)
) )

View File

@ -16,20 +16,34 @@
package com.shabinder.spotiflyer.ui package com.shabinder.spotiflyer.ui
import androidx.compose.animation.* import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.ExperimentalAnimationApi
import androidx.compose.foundation.Image import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.* import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.AlertDialog import androidx.compose.material.AlertDialog
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.CloudOff import androidx.compose.material.icons.rounded.CloudOff
import androidx.compose.runtime.* import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.State
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.ColorFilter import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import com.shabinder.common.translations.Strings
import com.shabinder.common.uikit.SpotiFlyerShapes import com.shabinder.common.uikit.SpotiFlyerShapes
import com.shabinder.common.uikit.SpotiFlyerTypography import com.shabinder.common.uikit.SpotiFlyerTypography
import com.shabinder.common.uikit.colorOffWhite import com.shabinder.common.uikit.colorOffWhite
@ -62,7 +76,7 @@ fun NetworkDialog(
Icon(Icons.Rounded.SyncProblem,"Check Network Connection Again") Icon(Icons.Rounded.SyncProblem,"Check Network Connection Again")
} }
*/}, */},
title = { Text("No Internet Connection!", title = { Text(Strings.noInternetConnection(),
style = SpotiFlyerTypography.h5, style = SpotiFlyerTypography.h5,
textAlign = TextAlign.Center) }, textAlign = TextAlign.Center) },
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
@ -72,11 +86,12 @@ fun NetworkDialog(
Row(verticalAlignment = Alignment.CenterVertically, Row(verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp) modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp)
) { ) {
Image(Icons.Rounded.CloudOff,"No Internet.",Modifier.size(42.dp),colorFilter = ColorFilter.tint( Image(Icons.Rounded.CloudOff,
Strings.noInternetConnection(),Modifier.size(42.dp),colorFilter = ColorFilter.tint(
colorOffWhite)) colorOffWhite))
Spacer(modifier = Modifier.padding(start = 16.dp)) Spacer(modifier = Modifier.padding(start = 16.dp))
Text( Text(
text = "Please Check Your Network Connection.", text = Strings.checkInternetConnection(),
style = SpotiFlyerTypography.subtitle1 style = SpotiFlyerTypography.subtitle1
) )
} }

View File

@ -8,13 +8,11 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.AlertDialog import androidx.compose.material.AlertDialog
import androidx.compose.material.Icon import androidx.compose.material.Icon
import androidx.compose.material.Text import androidx.compose.material.Text
import androidx.compose.material.TextButton import androidx.compose.material.TextButton
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.Insights
import androidx.compose.material.icons.rounded.SdStorage import androidx.compose.material.icons.rounded.SdStorage
import androidx.compose.material.icons.rounded.SystemSecurityUpdate import androidx.compose.material.icons.rounded.SystemSecurityUpdate
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
@ -30,7 +28,7 @@ import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.text.style.TextAlign import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp import androidx.compose.ui.unit.sp
import androidx.compose.ui.window.DialogProperties import com.shabinder.common.translations.Strings
import com.shabinder.common.uikit.SpotiFlyerShapes import com.shabinder.common.uikit.SpotiFlyerShapes
import com.shabinder.common.uikit.SpotiFlyerTypography import com.shabinder.common.uikit.SpotiFlyerTypography
import com.shabinder.common.uikit.colorPrimary import com.shabinder.common.uikit.colorPrimary
@ -64,9 +62,9 @@ fun PermissionDialog(
.background(colorPrimary, shape = SpotiFlyerShapes.medium) .background(colorPrimary, shape = SpotiFlyerShapes.medium)
.padding(horizontal = 8.dp), .padding(horizontal = 8.dp),
){ ){
Text("Grant Permissions",color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center) Text(Strings.grantPermissions(),color = Color.Black,fontSize = 18.sp,textAlign = TextAlign.Center)
} }
},title = { Text("Required Permissions:",style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center) }, },title = { Text(Strings.requiredPermissions(),style = SpotiFlyerTypography.h5,textAlign = TextAlign.Center) },
backgroundColor = Color.DarkGray, backgroundColor = Color.DarkGray,
text = { text = {
Column{ Column{
@ -74,15 +72,15 @@ fun PermissionDialog(
Row(verticalAlignment = Alignment.CenterVertically, Row(verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp) modifier = Modifier.fillMaxWidth().padding(vertical = 6.dp)
) { ) {
Icon(Icons.Rounded.SdStorage,"Storage Permission.") Icon(Icons.Rounded.SdStorage,Strings.storagePermission())
Spacer(modifier = Modifier.padding(start = 16.dp)) Spacer(modifier = Modifier.padding(start = 16.dp))
Column { Column {
Text( Text(
text = "Storage Permission.", text = Strings.storagePermission(),
style = SpotiFlyerTypography.h6.copy(fontWeight = FontWeight.SemiBold) style = SpotiFlyerTypography.h6.copy(fontWeight = FontWeight.SemiBold)
) )
Text( Text(
text = "To download your favourite songs to this device.", text = Strings.storagePermissionReason(),
style = SpotiFlyerTypography.subtitle2, style = SpotiFlyerTypography.subtitle2,
) )
} }
@ -91,15 +89,15 @@ fun PermissionDialog(
modifier = Modifier.fillMaxWidth().padding(top = 6.dp), modifier = Modifier.fillMaxWidth().padding(top = 6.dp),
verticalAlignment = Alignment.CenterVertically verticalAlignment = Alignment.CenterVertically
) { ) {
Icon(Icons.Rounded.SystemSecurityUpdate,"Allow Background Running") Icon(Icons.Rounded.SystemSecurityUpdate,Strings.backgroundRunning())
Spacer(modifier = Modifier.padding(start = 16.dp)) Spacer(modifier = Modifier.padding(start = 16.dp))
Column { Column {
Text( Text(
text = "Background Running.", text = Strings.backgroundRunning(),
style = SpotiFlyerTypography.h6.copy(fontWeight = FontWeight.SemiBold) style = SpotiFlyerTypography.h6.copy(fontWeight = FontWeight.SemiBold)
) )
Text( Text(
text = "To download all songs in background without any System Interruptions", text = Strings.backgroundRunningReason(),
style = SpotiFlyerTypography.subtitle2, style = SpotiFlyerTypography.subtitle2,
) )
} }

View File

@ -30,6 +30,8 @@ class AutoClear<T : Any?>(
val value: T get() = _value.requireNotNull() val value: T get() = _value.requireNotNull()
fun getOrNull(): T? = _value
private val observer: LifecycleAutoInitializer<T?> by lazy { private val observer: LifecycleAutoInitializer<T?> by lazy {
when(trigger) { when(trigger) {
TRIGGER.ON_CREATE -> LifecycleCreateAndDestroyObserver(initializer) TRIGGER.ON_CREATE -> LifecycleCreateAndDestroyObserver(initializer)

View File

@ -27,6 +27,21 @@ exit = Exit
downloading = Downloading downloading = Downloading
processing = Processing processing = Processing
queued = Queued queued = Queued
setDownloadDirectory = Set Download Directory
downloadDirectorySetTo = Download Directory Set to: {0}
noWriteAccess = NO WRITE ACCESS on: {0} , Reverting Back to Previous
shareMessage = Hey, checkout this excellent Music Downloader http://github.com/Shabinder/SpotiFlyer
grantAnalytics = Grant Analytics
noInternetConnection = No Internet Connection!
checkInternetConnection = Please Check Your Network Connection.
grantPermissions = Grant Permissions
requiredPermissions = Required Permissions:
storagePermission = Storage Permission.
storagePermissionReason = To download your favourite songs to this device.
backgroundRunning = Background Running.
backgroundRunningReason = To download all songs in background without any System Interruptions.
no = Nope
yes = Sure
acraNotificationTitle = OOPS, SpotiFlyer Crashed acraNotificationTitle = OOPS, SpotiFlyer Crashed
acraNotificationText = Please Send Crash Report to App Developers, So this unfortunate event may not happen again. acraNotificationText = Please Send Crash Report to App Developers, So this unfortunate event may not happen again.
@ -55,7 +70,6 @@ unknownError = Unknown Error
noMatchFound = NO Match Found! noMatchFound = NO Match Found!
noLinkFound = No Downloadable link found noLinkFound = No Downloadable link found
linkNotValid = Entered Link is NOT Valid! linkNotValid = Entered Link is NOT Valid!
checkInternetConnection = Check Your Internet Connection
featureUnImplemented = Feature not yet implemented. featureUnImplemented = Feature not yet implemented.
minute = min minute = min