Skip to content

Commit

Permalink
Add option to align lyrics left/center/right (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
z-huang committed Oct 23, 2022
1 parent f6f0b74 commit adf8a6f
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import com.zionhuang.music.playback.MediaSessionConnection
import com.zionhuang.music.ui.activities.MainActivity
import com.zionhuang.music.utils.NavigationEndpointHandler
import com.zionhuang.music.utils.makeTimeString
import com.zionhuang.music.utils.preference.PreferenceLiveData
import com.zionhuang.music.viewmodels.PlaybackViewModel
import dev.chrisbanes.insetter.applyInsetter
import kotlinx.coroutines.flow.collectLatest
Expand Down Expand Up @@ -88,6 +89,10 @@ class BottomControlsFragment : Fragment() {
viewModel.mediaController?.transportControls?.seekTo(time)
true
}
PreferenceLiveData(requireContext(), R.string.pref_lyrics_text_position, "1").observe(viewLifecycleOwner) {
binding.lyricsView.setTextGravity(it.toIntOrNull() ?: 1)
binding.lyricsView.invalidate()
}
lifecycleScope.launch {
viewModel.playbackState.collect { playbackState ->
if (playbackState.state != PlaybackStateCompat.STATE_NONE && playbackState.state != PlaybackStateCompat.STATE_STOPPED) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ class LyricsView @JvmOverloads constructor(

fun setTextGravity(gravity: Int) {
textGravity = gravity
initEntryList()
postInvalidate()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ data class LyricsEntry(
override fun compareTo(other: LyricsEntry): Int = (time - other.time).toInt()

companion object {
const val GRAVITY_CENTER = 0
const val GRAVITY_LEFT = 1
const val GRAVITY_LEFT = 0
const val GRAVITY_CENTER = 1
const val GRAVITY_RIGHT = 2
}
}
6 changes: 5 additions & 1 deletion app/src/main/res/values-es-rUS/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Modo oscuro</string>
<string name="dark_theme_on">Encendido</string>
<string name="dark_theme_off">Apagado</string>
<string name="dark_theme_follow_system">Predeterminado del sistema</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Predeterminado del sistema</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Contenido</string>
<string name="pref_content_language_title">Idioma por defecto del contenido</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Tema oscuro</string>
<string name="dark_theme_on">Encendido</string>
<string name="dark_theme_off">Apagado</string>
<string name="dark_theme_follow_system">Seguir el sistema</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Seguir el sistema</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Contenido</string>
<string name="pref_content_language_title">Idioma de contenido predeterminado</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-fa-rIR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">تم تاریک</string>
<string name="dark_theme_on">روشن</string>
<string name="dark_theme_off">خاموش</string>
<string name="dark_theme_follow_system">پیروی از سیستم</string>
<string name="pref_default_open_tab_title">زبانه باز پیش‌فرض</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">پیروی از سیستم</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">محتوا</string>
<string name="pref_content_language_title">زبان پیش‌فرض محتوا</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-fi-rFI/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Tumma teema</string>
<string name="dark_theme_on">Käytössä</string>
<string name="dark_theme_off">Pois käytöstä</string>
<string name="dark_theme_follow_system">Järjestelmän teeman mukainen</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Järjestelmän teeman mukainen</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Sisältö</string>
<string name="pref_content_language_title">Sisällön oletuskieli</string>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-fr-rFR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Dark theme</string>
<string name="dark_theme_on">On</string>
<string name="dark_theme_off">Off</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Follow system</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Content</string>
<string name="pref_content_language_title">Langue du contenu par défaut</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Sötét téma</string>
<string name="dark_theme_on">Be</string>
<string name="dark_theme_off">Ki</string>
<string name="dark_theme_follow_system">Rendszer szerint</string>
<string name="pref_default_open_tab_title">Alapért. nyitott lap</string>
<string name="pref_customize_navigation_tabs">A navigációs lapok testreszabása</string>
<string name="dark_theme_follow_system">Rendszer szerint</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Tartalom</string>
<string name="pref_content_language_title">A tartalom alapért. nyelve</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Tema scuro</string>
<string name="dark_theme_on">Attivato</string>
<string name="dark_theme_off">Disattivato</string>
<string name="dark_theme_follow_system">Segui sistema</string>
<string name="pref_default_open_tab_title">Scheda principale predefinita</string>
<string name="pref_customize_navigation_tabs">Personalizza schede di navigazione</string>
<string name="dark_theme_follow_system">Segui sistema</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Contenuti</string>
<string name="pref_content_language_title">Lingua predefinita dei contenuti</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-ja-rJP/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">ダークテーマ</string>
<string name="dark_theme_on">オン</string>
<string name="dark_theme_off">オフ</string>
<string name="dark_theme_follow_system">システムに従う</string>
<string name="pref_default_open_tab_title">起動時に開くタブ</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">システムに従う</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">コンテンツ</string>
<string name="pref_content_language_title">デフォルトのコンテンツの言語</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-ko-rKR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">다크 테마</string>
<string name="dark_theme_on">켬</string>
<string name="dark_theme_off">끔</string>
<string name="dark_theme_follow_system">시스템</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">시스템</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">콘텐츠</string>
<string name="pref_content_language_title">기본 콘텐츠 언어</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-ml-rIN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">ഡാർക്ക് തീം</string>
<string name="dark_theme_on">ഓൺ</string>
<string name="dark_theme_off">ഓഫ്</string>
<string name="dark_theme_follow_system">സിസ്റ്റം പിന്തുടരുക</string>
<string name="pref_default_open_tab_title">സ്ഥിര ഓപ്പൺ ടാബ്</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">സിസ്റ്റം പിന്തുടരുക</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">കന്റെന്റ്</string>
<string name="pref_content_language_title">സ്ഥിര കന്റെന്റ് ഭാഷ</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Tema escuro</string>
<string name="dark_theme_on">On</string>
<string name="dark_theme_off">Off</string>
<string name="dark_theme_follow_system">Seguir o sistema</string>
<string name="pref_default_open_tab_title">Aba padrão ao iniciar</string>
<string name="pref_customize_navigation_tabs">Costumar barra de navegação</string>
<string name="dark_theme_follow_system">Seguir o sistema</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Conteúdo</string>
<string name="pref_content_language_title">Idioma padrão do conteúdo</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-sv-rSE/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Mörkt tema</string>
<string name="dark_theme_on">På</string>
<string name="dark_theme_off">Av</string>
<string name="dark_theme_follow_system">Följ systemet</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Följ systemet</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Innehåll</string>
<string name="pref_content_language_title">Standard innehållsspråk</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">深色主题</string>
<string name="dark_theme_on">开</string>
<string name="dark_theme_off">关</string>
<string name="dark_theme_follow_system">跟随系统</string>
<string name="pref_default_open_tab_title">默认启动选项卡</string>
<string name="pref_customize_navigation_tabs">自定义导航选项卡</string>
<string name="dark_theme_follow_system">跟随系统</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">内容</string>
<string name="pref_content_language_title">默认内容语言</string>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">深色主題</string>
<string name="dark_theme_on">開</string>
<string name="dark_theme_off">關</string>
<string name="dark_theme_follow_system">跟隨系統</string>
<string name="pref_default_open_tab_title">預設啟動標籤</string>
<string name="pref_customize_navigation_tabs">自訂導覽列</string>
<string name="dark_theme_follow_system">跟隨系統</string>
<string name="pref_lyrics_text_position_title">歌詞文字位置</string>
<string name="align_left">靠左</string>
<string name="align_center">置中</string>
<string name="align_right">靠右</string>

<string name="pref_content_title">內容</string>
<string name="pref_content_language_title">預設內容語言</string>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/values/constants.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="pref_dark_theme" translatable="false">DARK_THEME</string>
<string name="pref_default_open_tab" translatable="false">DEFAULT_OPEN_TAB</string>
<string name="pref_nav_tab_config" translatable="false">NAV_TAB_CONFIG</string>
<string name="pref_lyrics_text_position" translatable="false">LRC_TEXT_POS</string>

<string name="pref_content_language" translatable="false">CONTENT_LANGUAGE</string>
<string name="pref_content_country" translatable="false">CONTENT_COUNTRY</string>
Expand Down Expand Up @@ -139,6 +140,18 @@
<item>4</item>
</string-array>

<string-array name="lyrics_position_texts" translatable="false">
<item>@string/align_left</item>
<item>@string/align_center</item>
<item>@string/align_right</item>
</string-array>

<string-array name="lyrics_position_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

<string-array name="proxy_types" translatable="false">
<item>HTTP</item>
<item>SOCKS</item>
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,13 @@
<string name="pref_dark_theme_title">Dark theme</string>
<string name="dark_theme_on">On</string>
<string name="dark_theme_off">Off</string>
<string name="dark_theme_follow_system">Follow system</string>
<string name="pref_default_open_tab_title">Default open tab</string>
<string name="pref_customize_navigation_tabs">Customize navigation tabs</string>
<string name="dark_theme_follow_system">Follow system</string>
<string name="pref_lyrics_text_position_title">Lyrics text position</string>
<string name="align_left">Left</string>
<string name="align_center">Center</string>
<string name="align_right">Right</string>

<string name="pref_content_title">Content</string>
<string name="pref_content_language_title">Default content language</string>
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/res/xml/pref_appearance.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,12 @@
android:icon="@drawable/ic_view_column"
android:key="@string/pref_nav_tab_config"
android:title="@string/pref_customize_navigation_tabs" />
<ListPreference
android:defaultValue="1"
android:entries="@array/lyrics_position_texts"
android:entryValues="@array/lyrics_position_values"
android:icon="@drawable/ic_lyrics"
android:key="@string/pref_lyrics_text_position"
android:summary="%s"
android:title="@string/pref_lyrics_text_position_title" />
</PreferenceScreen>

0 comments on commit adf8a6f

Please sign in to comment.