Converted hardcoded strings to string resources

This commit is contained in:
Prathamesh More 2022-05-11 23:06:34 +05:30
parent 90e113e8ab
commit 9c07ca2763
11 changed files with 38 additions and 20 deletions

View file

@ -27,6 +27,7 @@ import androidx.core.net.toUri
import androidx.core.text.parseAsHtml
import androidx.core.view.isVisible
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.base.AbsMusicServiceActivity
import code.name.monkey.retromusic.databinding.ActivityPermissionBinding
import code.name.monkey.retromusic.extensions.*
@ -75,7 +76,8 @@ class PermissionActivity : AbsMusicServiceActivity() {
val color = accentColor()
val hexColor = String.format("#%06X", 0xFFFFFF and color)
val appName =
"Hello there! <br>Welcome to <b>Retro <span style='color:$hexColor';>Music</span></b>"
getString(R.string.message_welcome,
"<b>Retro <span style='color:$hexColor';>Music</span></b>")
.parseAsHtml()
binding.appNameText.text = appName
}

View file

@ -154,7 +154,7 @@ class AlbumTagEditorActivity : AbsTagEditorActivity<ActivityAlbumTagEditorBindin
override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable)
showToast("Load Failed", Toast.LENGTH_LONG)
showToast(R.string.error_load_failed, Toast.LENGTH_LONG)
}
override fun setResource(resource: BitmapPaletteWrapper?) {}

View file

@ -193,7 +193,7 @@ class SongTagEditorActivity : AbsTagEditorActivity<ActivitySongTagEditorBinding>
override fun onLoadFailed(errorDrawable: Drawable?) {
super.onLoadFailed(errorDrawable)
showToast("Load Failed", Toast.LENGTH_LONG)
showToast(R.string.error_load_failed, Toast.LENGTH_LONG)
}
override fun setResource(resource: BitmapPaletteWrapper?) {}

View file

@ -122,7 +122,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
try {
file.delete()
} catch (exception: SecurityException) {
showToast("Could not delete backup")
showToast(R.string.error_delete_backup)
}
backupViewModel.loadBackups()
return true
@ -147,7 +147,7 @@ class BackupFragment : Fragment(R.layout.fragment_backup), BackupAdapter.BackupC
file.renameTo(renamedFile)
backupViewModel.loadBackups()
} else {
showToast("File already exists")
showToast(R.string.file_already_exists)
}
}
positiveButton(android.R.string.ok)

View file

@ -141,8 +141,8 @@ class LyricsFragment : AbsMainActivityFragment(R.layout.fragment_lyrics) {
binding.lyricsPager.adapter = lyricsSectionsAdapter
TabLayoutMediator(binding.tabLyrics, binding.lyricsPager) { tab, position ->
tab.text = when (position) {
0 -> "Synced Lyrics"
1 -> "Normal Lyrics"
0 -> getString(R.string.synced_lyrics)
1 -> getString(R.string.normal_lyrics)
else -> ""
}
}.attach()
@ -383,7 +383,7 @@ class LyricsFragment : AbsMainActivityFragment(R.layout.fragment_lyrics) {
}
fun loadLRCLyrics() {
binding.lyricsView.setLabel("Empty")
binding.lyricsView.setLabel(getString(R.string.empty))
LyricUtil.getSyncedLyricsFile(MusicPlayerRemote.currentSong)?.let {
binding.lyricsView.loadLrc(it)
}

View file

@ -96,7 +96,7 @@ class UserInfoFragment : Fragment() {
binding.next.setOnClickListener {
val nameString = binding.name.text.toString().trim { it <= ' ' }
if (nameString.isEmpty()) {
showToast("Your name can't be empty!")
showToast(R.string.error_empty_name)
return@setOnClickListener
}
userName = nameString
@ -262,7 +262,7 @@ class UserInfoFragment : Fragment() {
}
if (successful) {
withContext(Dispatchers.Main) {
showToast("Updated")
showToast(R.string.message_updated)
}
}
}

View file

@ -24,6 +24,7 @@ import androidx.preference.Preference
import androidx.preference.PreferenceManager
import code.name.monkey.appthemehelper.common.prefs.supportv7.ATEPreferenceFragmentCompat
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.activities.OnThemeChangedListener
import code.name.monkey.retromusic.extensions.showToast
import code.name.monkey.retromusic.preferences.*
@ -37,7 +38,7 @@ import dev.chrisbanes.insetter.applyInsetter
abstract class AbsSettingsFragment : ATEPreferenceFragmentCompat() {
internal fun showProToastAndNavigate(message: String) {
showToast("$message is Pro version feature.")
showToast(getString(R.string.message_pro_feature, message))
NavigationUtil.goToProVersion(requireActivity())
}

View file

@ -3,6 +3,7 @@ package code.name.monkey.retromusic.helper
import android.content.Context
import android.os.Environment
import code.name.monkey.retromusic.BuildConfig
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.db.PlaylistEntity
import code.name.monkey.retromusic.db.toSongEntity
import code.name.monkey.retromusic.extensions.showToast
@ -57,11 +58,11 @@ object BackupHelper : KoinComponent {
}
}.onFailure {
withContext(Dispatchers.Main) {
context.showToast("Couldn't create backup")
context.showToast(R.string.error_create_backup)
}
}.onSuccess {
withContext(Dispatchers.Main) {
context.showToast("Backup created successfully")
context.showToast(R.string.message_backup_create_success)
}
}
}
@ -160,7 +161,7 @@ object BackupHelper : KoinComponent {
}
}
withContext(Dispatchers.Main) {
context.showToast("Restore Completed Successfully")
context.showToast(R.string.message_restore_success)
}
}
}

View file

@ -76,7 +76,7 @@ class LibraryPreferenceDialog : DialogFragment() {
private fun updateCategories(categories: List<CategoryInfo>) {
if (getSelected(categories) == 0) return
if (getSelected(categories) > 5) {
showToast("Not more than 5 items")
showToast(R.string.message_limit_tabs)
return
}
PreferenceUtil.libraryCategory = categories

View file

@ -22,6 +22,7 @@ import android.provider.MediaStore
import android.widget.Toast
import androidx.core.content.edit
import code.name.monkey.retromusic.App
import code.name.monkey.retromusic.R
import code.name.monkey.retromusic.extensions.showToast
import code.name.monkey.retromusic.glide.GlideApp
import code.name.monkey.retromusic.model.Artist
@ -56,7 +57,7 @@ class CustomArtistImageUtil private constructor(context: Context) {
saveImage(context, artist, it)
}
.onFailure {
context.showToast("Load Failed")
context.showToast(R.string.error_load_failed)
}
}
}

View file

@ -86,7 +86,9 @@
<string name="audio_settings_summary">Change the sound settings and adjust the equalizer controls</string>
<string name="auto">Auto</string>
<string name="backup_restore_settings_summary">Backup and restore your settings, playlists</string>
<string name="backup_restore_title"><![CDATA[Backup & Restore]]></string>
<string name="backup_restore_title">
<![CDATA[Backup & Restore]]>
</string>
<string name="backup_title">Backups</string>
<string name="biography">Biography</string>
<string name="black_theme_name">Just Black</string>
@ -171,9 +173,14 @@
<string name="edit_synced_lyrics">Edit Synced Lyrics</string>
<string name="empty">Empty</string>
<string name="equalizer">Equalizer</string>
<string name="error_create_backup">Couldn\u2019t create backup</string>
<string name="error_delete_backup">Couldn\u2019t delete backup</string>
<string name="error_empty_name">Your name can\'t be empty!</string>
<string name="error_load_failed">Load failed</string>
<string name="expanded">Expanded</string>
<string name="faq">FAQ</string>
<string name="favorites">Favorites</string>
<string name="file_already_exists">File already exists</string>
<string name="finish_last_song">Finish last song</string>
<string name="fit">Fit</string>
<string name="flat">Flat</string>
@ -237,9 +244,15 @@
<string name="lyrics">Lyrics</string>
<string name="made_with_love">Made with ❤️ in India</string>
<string name="material">Material</string>
<string name="md3" translatable="false">MD3</string>
<string name="md_error_label">Error</string>
<string name="md_storage_perm_error">Permission error</string>
<string name="md3" translatable="false">MD3</string>
<string name="message_backup_create_success">Backup created successfully.</string>
<string name="message_limit_tabs">Not more than 5 items</string>
<string name="message_pro_feature">%s is a Pro feature.</string>
<string name="message_restore_success">Restore completed successfully.</string>
<string name="message_updated">Updated</string>
<string name="message_welcome"><![CDATA[Hello there! <br>Welcome to %s]]></string>
<string name="my_name">Name</string>
<string name="my_top_tracks">Most played</string>
<string name="never">Never</string>
@ -342,6 +355,7 @@
<string name="pref_summary_ignore_media_store_artwork">Can increase the album cover quality, but causes slower image loading times. Only enable this if you have problems with low resolution artworks</string>
<string name="pref_summary_library_categories">Configure visibility and order of library categories.</string>
<string name="pref_summary_lock_screen">Use Retro Music\'s custom lockscreen controls</string>
<string name="pref_summary_manage_audio_focus">Always play audio in background regardless of anything else being played</string>
<string name="pref_summary_open_source_licences">License details for open source software</string>
<string name="pref_summary_pause_history">When enabled, newly played songs won\'t show in history</string>
<string name="pref_summary_remember_tab">Navigate to the last used tab on start</string>
@ -354,7 +368,6 @@
<string name="pref_summary_toggle_volume">If enough space is available, show volume controls in the now playing screen</string>
<string name="pref_summary_wallpaper_accent">Extract accent color from wallpaper</string>
<string name="pref_summary_whitelist">Only show music from /Music Folder</string>
<string name="pref_summary_manage_audio_focus">Always play audio in background regardless of anything else being played</string>
<string name="pref_title_album_art_on_lockscreen">Show album cover</string>
<string name="pref_title_album_artists_only">Navigate by Album Artist</string>
<string name="pref_title_album_cover_style">Album cover theme</string>
@ -387,6 +400,7 @@
<string name="pref_title_lock_screen">Fullscreen controls</string>
<string name="pref_title_lyrics_screen_on">Keep screen on when showing lyrics</string>
<string name="pref_title_lyrics_type">Lyrics type</string>
<string name="pref_title_manage_audio_focus">Always play</string>
<string name="pref_title_now_playing_screen_appearance">Now playing theme</string>
<string name="pref_title_open_source_licences">Open source licences</string>
<string name="pref_title_pause_history">Pause history</string>
@ -402,7 +416,6 @@
<string name="pref_title_toggle_volume">Volume controls</string>
<string name="pref_title_wallpaper_accent">Wallpaper accent color</string>
<string name="pref_title_whitelist">Whitelist music</string>
<string name="pref_title_manage_audio_focus">Always play</string>
<string name="pro">Pro</string>
<string name="pro_summary">Black theme, Now playing themes, Carousel effect and more..</string>
<string name="profile">Profile</string>