Skip to content

Commit c511001

Browse files
committed
update ... logic and add text size configuration
1 parent e339b2e commit c511001

4 files changed

Lines changed: 158 additions & 141 deletions

File tree

app/src/main/java/com/mixtapeo/lyrisync/LyricAdapter.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.mixtapeo.lyrisync
22

33
import android.content.Context
44
import android.util.Log
5+
import android.util.TypedValue
56
import android.view.LayoutInflater
67
import android.view.View
78
import android.view.ViewGroup
@@ -18,6 +19,9 @@ class LyricAdapter(
1819
) : RecyclerView.Adapter<LyricAdapter.LyricViewHolder>() {
1920

2021
var activeIndex: Int = -1
22+
var textSize: Float = 22f
23+
var furiganaSize: Float = 12f
24+
var translationSize: Float = 16f
2125

2226
fun updateData(
2327
newLyrics: List<LyricLine>?, // Make these nullable for safety
@@ -55,12 +59,32 @@ class LyricAdapter(
5559
override fun onBindViewHolder(holder: LyricViewHolder, position: Int) {
5660
val lyricText = lyrics[position].text
5761
val hasJapanese = lyricText.contains(jpCharacterRegex)
62+
val isGap = lyricText == "..."
5863
holder.jp.text = lyricText
5964
holder.en.text = translations.getOrNull(position) ?: ""
6065

6166
val furiganaContent = furiganaList.getOrNull(position) ?: ""
6267
holder.furigana?.text = furiganaContent
6368

69+
// Apply text sizes in SP
70+
holder.jp.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize)
71+
holder.furigana?.setTextSize(TypedValue.COMPLEX_UNIT_SP, furiganaSize)
72+
holder.en.setTextSize(TypedValue.COMPLEX_UNIT_SP, translationSize)
73+
74+
75+
if (isGap) {
76+
holder.en.text = ""
77+
holder.en.visibility = View.GONE
78+
holder.furigana?.visibility = View.GONE
79+
holder.jp.alpha = 0.3f // Optional: dim the dots
80+
} else {
81+
// 3. Normal translation logic
82+
val translation = translations.getOrNull(position) ?: ""
83+
holder.en.text = translation
84+
85+
// Ensure visibility follows your existing SubtitleMode logic below
86+
holder.jp.alpha = if (position == activeIndex) 1.0f else 0.5f
87+
}
6488

6589
if (position == activeIndex) {
6690
// Active State: Spotify Green, fully opaque

app/src/main/java/com/mixtapeo/lyrisync/MainActivity.kt

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ private val translationService: TranslationService by lazy {
156156
}
157157
private val queryCache = mutableMapOf<String, JishoEntry?>()
158158
private val jpCharacterRegex = Regex("[\\u3040-\\u30ff\\u4e00-\\u9faf]")
159-
private val singleKanaRegex = Regex("[\\u3040-\\u30ff]")
160159

161160
class MainActivity : AppCompatActivity() {
162161
private var translatedLyrics = listOf<String>()
@@ -269,7 +268,25 @@ class MainActivity : AppCompatActivity() {
269268
jishoRv.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this)
270269

271270
// setup text size buttons
272-
// val textSizeSlider = findViewById<com.google.android.material.slider.Slider>(R.id.slider)
271+
val textSizeSlider = findViewById<com.google.android.material.slider.Slider>(R.id.textSizeSlider)
272+
273+
// Load saved text sizes
274+
val savedTextSize = sharedPrefs.getFloat("TEXT_SIZE", 22f)
275+
276+
// Initialize Sliders
277+
textSizeSlider.value = savedTextSize
278+
279+
// Initialize Adapter
280+
lyricAdapter?.textSize = savedTextSize
281+
282+
// Listeners for sliders
283+
val previewLyric = findViewById<TextView>(R.id.previewLyric)
284+
285+
textSizeSlider.addOnChangeListener { _, value, _ ->
286+
// Map 1-7 to something like 12sp - 32sp
287+
val newSize = 12f + (value * 3f)
288+
previewLyric.textSize = newSize
289+
}
273290

274291
// --- SETUP DEFINITION LIMIT SLIDER ---
275292
val defSlider = findViewById<com.google.android.material.slider.Slider>(R.id.slider)
@@ -780,6 +797,9 @@ class MainActivity : AppCompatActivity() {
780797
}
781798

782799
@SuppressLint("NotifyDataSetChanged")
800+
/*
801+
* Uses lexicological analyzer (kuromoji) to segement words -> underlines and coloring, furigana and translation fetch, and issue UI update
802+
* */
783803
private fun prefetchSongDictionary(lyrics: List<LyricLine>) {
784804
val startTime = System.currentTimeMillis()
785805
Log.d("Lyrisync", "Prefetch started for ${lyrics.size} lines")
@@ -817,7 +837,8 @@ class MainActivity : AppCompatActivity() {
817837
val lineStart = System.currentTimeMillis()
818838
val lineText = line.text
819839

820-
if (lineText.isBlank()) {
840+
// exceptions to skip processing
841+
if (lineText == "..." || lineText.isBlank()) {
821842
highlightsList.add(emptyList())
822843
furiganaLyrics.add("")
823844
continue
@@ -1059,7 +1080,7 @@ class MainActivity : AppCompatActivity() {
10591080
if (sortedLyrics.isNotEmpty()) {
10601081
val firstLyricTime = sortedLyrics[0].timeMs
10611082
if (firstLyricTime > 2500) { // If intro is longer than 2.5s
1062-
finalLyrics.add(LyricLine(1, "..."))
1083+
finalLyrics.add(LyricLine(1, " "))
10631084
}
10641085
}
10651086

@@ -1074,9 +1095,10 @@ class MainActivity : AppCompatActivity() {
10741095
val gap = nextStart - currentStart
10751096

10761097
// If gap is > 5 seconds
1077-
if (gap > 5000) {
1078-
finalLyrics.add(LyricLine(nextStart-5000, "..."))
1098+
if (gap > 10000) {
1099+
finalLyrics.add(LyricLine(nextStart, " "))
10791100
}
1101+
Log.d("Lyrisync", "Gap between lines: $gap at $currentLyric")
10801102
}
10811103
}
10821104
Log.d("Lyrisync", "Parsed Lyrics: $finalLyrics")

app/src/main/res/layout/activity_main.xml

Lines changed: 66 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,69 @@
292292
app:thumbColor="@color/brand_primary"
293293
app:trackColorInactive="#33FFFFFF" />
294294

295+
<com.google.android.material.card.MaterialCardView
296+
android:layout_width="match_parent"
297+
android:layout_height="wrap_content"
298+
android:layout_marginTop="16dp"
299+
app:cardBackgroundColor="#1AFFFFFF"
300+
app:cardCornerRadius="12dp"
301+
app:strokeWidth="0dp">
302+
303+
<LinearLayout
304+
android:layout_width="match_parent"
305+
android:layout_height="wrap_content"
306+
android:orientation="vertical"
307+
android:padding="16dp"
308+
android:gravity="center">
309+
310+
<TextView
311+
android:id="@+id/previewFurigana"
312+
android:layout_width="wrap_content"
313+
android:layout_height="wrap_content"
314+
android:text="かんじ"
315+
android:textColor="@color/gray"
316+
android:textSize="12sp" />
317+
318+
<TextView
319+
android:id="@+id/previewLyric"
320+
android:layout_width="wrap_content"
321+
android:layout_height="wrap_content"
322+
android:text="漢字"
323+
android:textColor="@android:color/white"
324+
android:textSize="24sp"
325+
android:textStyle="bold" />
326+
327+
<TextView
328+
android:id="@+id/previewTranslation"
329+
android:layout_width="wrap_content"
330+
android:layout_height="wrap_content"
331+
android:layout_marginTop="4dp"
332+
android:text="Text Preview"
333+
android:textColor="@color/gray"
334+
android:textSize="14sp" />
335+
</LinearLayout>
336+
</com.google.android.material.card.MaterialCardView>
337+
338+
<TextView
339+
android:layout_width="wrap_content"
340+
android:layout_height="wrap_content"
341+
android:layout_marginTop="16dp"
342+
android:text="Text size (Lyric)"
343+
android:textColor="@color/gray"
344+
android:textSize="16sp" />
345+
346+
<com.google.android.material.slider.Slider
347+
android:id="@+id/textSizeSlider"
348+
android:layout_width="match_parent"
349+
android:layout_height="wrap_content"
350+
android:stepSize="4"
351+
android:value="4"
352+
android:valueFrom="4"
353+
android:valueTo="48"
354+
app:thumbColor="@color/brand_primary"
355+
app:trackColorInactive="#33FFFFFF" />
356+
357+
295358
<com.google.android.material.button.MaterialButton
296359
android:id="@+id/wipeHistoryButton"
297360
style="@style/Widget.Material3.Button.TonalButton"
@@ -332,7 +395,7 @@
332395
app:icon="@drawable/ic_github"
333396
app:iconPadding="8dp"
334397
app:iconTint="#E0E0E0" />
335-
<!-- version -->
398+
<!-- version -->
336399
<TextView
337400
android:id="@+id/version"
338401
android:layout_width="match_parent"
@@ -484,6 +547,7 @@
484547
android:textColor="@color/brand_secondary" />
485548
</LinearLayout>
486549
</FrameLayout>
550+
487551
<FrameLayout
488552
android:id="@+id/SpotifyAuthRequest"
489553
android:layout_width="match_parent"
@@ -555,10 +619,10 @@
555619
android:layout_width="wrap_content"
556620
android:layout_height="wrap_content"
557621
android:layout_marginTop="24dp"
558-
android:textSize="8dp"
559622
android:paddingTop="24dp"
560623
android:text='If you repeatedly get this error and have spotify installed, try unrestricting battery for spotify. Else please raise an issue on github.com/mixtapeo/LyriSyncAndroid'
561624
android:textColor="@color/gray"
625+
android:textSize="8dp"
562626
android:textStyle="italic" />
563627
</LinearLayout>
564628
</FrameLayout>

0 commit comments

Comments
 (0)