Skip to content

Commit 33575a6

Browse files
committed
misc. cleanup + gradle
1 parent e097cc8 commit 33575a6

2 files changed

Lines changed: 19 additions & 34 deletions

File tree

app/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ android {
2020
applicationId = "com.mixtapeo.lyrisync"
2121
minSdk = 24
2222
targetSdk = 36
23-
versionCode = 9
23+
versionCode = 10
2424
versionName = "v0.45"
2525

2626
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

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

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import android.content.Context
55
import android.content.Intent
66
import android.content.res.ColorStateList
77
import android.graphics.Color
8-
import android.net.Uri
98
import android.os.Build
109
import android.os.Bundle
1110
import android.os.Handler
@@ -26,6 +25,7 @@ import androidx.activity.viewModels
2625
import androidx.appcompat.app.AppCompatActivity
2726
import androidx.core.content.edit
2827
import androidx.core.graphics.toColorInt
28+
import androidx.core.net.toUri
2929
import androidx.core.view.WindowCompat
3030
import androidx.core.view.WindowInsetsCompat
3131
import androidx.core.view.WindowInsetsControllerCompat
@@ -39,13 +39,11 @@ import androidx.room.PrimaryKey
3939
import androidx.room.Room
4040
import androidx.room.RoomDatabase
4141
import coil.load
42-
import com.mixtapeo.lyrisync.BuildConfig
4342
import com.atilika.kuromoji.ipadic.Tokenizer
4443
import com.google.android.material.materialswitch.MaterialSwitch
4544
import com.spotify.android.appremote.api.ConnectionParams
4645
import com.spotify.android.appremote.api.Connector
4746
import com.spotify.android.appremote.api.SpotifyAppRemote
48-
import com.spotify.android.appremote.api.error.SpotifyConnectionTerminatedException
4947
import com.spotify.protocol.client.error.RemoteClientException
5048
import kotlinx.coroutines.Dispatchers
5149
import kotlinx.coroutines.Job
@@ -219,7 +217,6 @@ class MainActivity : AppCompatActivity() {
219217
private val preparedLineSets = mutableMapOf<Int, JishoLineSet>()
220218
private val viewModel: LyriSyncViewModel by viewModels()
221219
private var reconnectTry = 0
222-
private val maxRetries = 3
223220
private var connectionMonitorJob: Job? = null
224221
private var isConnecting = false
225222
private var currentTrackUri: String? = null
@@ -232,7 +229,7 @@ class MainActivity : AppCompatActivity() {
232229
private var webApiProgressMs = -1L
233230
private var isWebPlaying = false
234231

235-
@SuppressLint("SetTextI18n", "NotifyDataSetChanged")
232+
@SuppressLint("SetTextI18n", "NotifyDataSetChanged", "CutPasteId")
236233
override fun onCreate(savedInstanceState: Bundle?) {
237234
super.onCreate(savedInstanceState)
238235
setContentView(R.layout.activity_main)
@@ -311,7 +308,7 @@ class MainActivity : AppCompatActivity() {
311308
}
312309

313310
findViewById<Button>(R.id.btnGithub).setOnClickListener {
314-
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/mixtapeo"))
311+
val intent = Intent(Intent.ACTION_VIEW, "https://github.com/mixtapeo".toUri())
315312
startActivity(intent)
316313
}
317314

@@ -391,7 +388,7 @@ class MainActivity : AppCompatActivity() {
391388
}
392389

393390
// 2. EXISTING LOGIC
394-
sharedPrefs.edit().putInt("DEF_LIMIT", newLimit).apply()
391+
sharedPrefs.edit { putInt("DEF_LIMIT", newLimit) }
395392
jishoAdapter.definitionLimit = newLimit
396393
jishoAdapter.notifyDataSetChanged()
397394
}
@@ -647,7 +644,7 @@ class MainActivity : AppCompatActivity() {
647644

648645
override fun onStart() {
649646
super.onStart()
650-
val sharedPrefs = getSharedPreferences("LyriSyncPrefs", Context.MODE_PRIVATE)
647+
val sharedPrefs = getSharedPreferences("LyriSyncPrefs", MODE_PRIVATE)
651648
val isFirstRun = sharedPrefs.getBoolean("IS_FIRST_RUN", true)
652649

653650
if (!isFirstRun) {
@@ -674,7 +671,7 @@ class MainActivity : AppCompatActivity() {
674671
if (wipeRequested) {
675672
jishoHistory.clear()
676673
jishoAdapter?.notifyDataSetChanged()
677-
sharedPrefs.edit().putBoolean("WIPE_REQUESTED", false).apply()
674+
sharedPrefs.edit { putBoolean("WIPE_REQUESTED", false) }
678675
}
679676

680677
val refreshLyricsRequested = sharedPrefs.getBoolean("REFRESH_LYRICS_REQUESTED", false)
@@ -729,6 +726,7 @@ class MainActivity : AppCompatActivity() {
729726

730727
private var syncAndMonitorJob: Job? = null
731728

729+
@SuppressLint("UseKtx")
732730
private fun startHybridSyncLoop() {
733731
syncAndMonitorJob?.cancel()
734732
syncAndMonitorJob = lifecycleScope.launch(Dispatchers.Main) {
@@ -782,7 +780,7 @@ class MainActivity : AppCompatActivity() {
782780
// ---------------------------------------------------------
783781
if (banner.visibility == View.GONE) {
784782
banner.text = "Cloud Sync Active (Local App Asleep/Missing)"
785-
banner.backgroundTintList = ColorStateList.valueOf(Color.parseColor("#E65100"))
783+
banner.backgroundTintList = ColorStateList.valueOf("#E65100".toColorInt())
786784
banner.visibility = View.VISIBLE
787785
}
788786

@@ -882,20 +880,6 @@ class MainActivity : AppCompatActivity() {
882880

883881
private var lastPlaybackPosition: Long = -1L
884882

885-
private fun wakeUpSpotify() {
886-
val spotifyPackage = "com.spotify.music"
887-
val launchIntent = packageManager.getLaunchIntentForPackage(spotifyPackage)
888-
889-
if (launchIntent != null) {
890-
Toast.makeText(this, "Waking Spotify to sync...", Toast.LENGTH_SHORT).show()
891-
// Brings Spotify to the foreground briefly to restore its network privileges
892-
launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
893-
startActivity(launchIntent)
894-
} else {
895-
Toast.makeText(this, "Spotify not installed.", Toast.LENGTH_SHORT).show()
896-
}
897-
}
898-
899883
// <------- support funcs ------->
900884
// Setup Coil ImageLoader with GIF support
901885
private fun showFirstStartDialog(prefs: android.content.SharedPreferences) {
@@ -910,7 +894,7 @@ class MainActivity : AppCompatActivity() {
910894
// 1. Create a specialized Loader for animations
911895
val animationLoader = coil.ImageLoader.Builder(this)
912896
.components {
913-
if (android.os.Build.VERSION.SDK_INT >= 28) {
897+
if (Build.VERSION.SDK_INT >= 28) {
914898
add(coil.decode.ImageDecoderDecoder.Factory())
915899
} else {
916900
add(coil.decode.GifDecoder.Factory())
@@ -928,7 +912,7 @@ class MainActivity : AppCompatActivity() {
928912
}
929913

930914
btnNever.setOnClickListener {
931-
prefs.edit().putBoolean("IS_FIRST_RUN", false).apply()
915+
prefs.edit { putBoolean("IS_FIRST_RUN", false) }
932916
overlay.visibility = View.GONE
933917
reconnectToSpotify()
934918
}
@@ -1442,7 +1426,7 @@ class JishoHistoryAdapter(private val history: List<JishoLineSet>) :
14421426

14431427
text = spannable
14441428
textSize = 15f
1445-
setTextColor(Color.parseColor("#E0E0E0"))
1429+
setTextColor("#E0E0E0".toColorInt())
14461430
setPadding(32, 24, 32, 24)
14471431

14481432
val marginParams = android.widget.LinearLayout.LayoutParams(
@@ -1464,7 +1448,7 @@ class JishoHistoryAdapter(private val history: List<JishoLineSet>) :
14641448
isClickable = true
14651449
isFocusable = true
14661450

1467-
val typedValue = android.util.TypedValue()
1451+
val typedValue = TypedValue()
14681452
context.theme.resolveAttribute(
14691453
android.R.attr.selectableItemBackground, typedValue, true
14701454
)
@@ -1476,13 +1460,13 @@ class JishoHistoryAdapter(private val history: List<JishoLineSet>) :
14761460
val flashcardText =
14771461
"${jishoWord.phrase} [${jishoWord.reading}]\n\n$limitedDefinitions"
14781462

1479-
val sendIntent = android.content.Intent().apply {
1480-
action = android.content.Intent.ACTION_SEND
1481-
putExtra(android.content.Intent.EXTRA_TEXT, flashcardText)
1463+
val sendIntent = Intent().apply {
1464+
action = Intent.ACTION_SEND
1465+
putExtra(Intent.EXTRA_TEXT, flashcardText)
14821466
type = "text/plain"
14831467
}
14841468
val shareIntent =
1485-
android.content.Intent.createChooser(sendIntent, "Send to Anki")
1469+
Intent.createChooser(sendIntent, "Send to Anki")
14861470
context.startActivity(shareIntent)
14871471
}
14881472
}
@@ -1498,6 +1482,7 @@ class SearchAdapter(
14981482
private val onItemClick: (LrcResponse) -> Unit // 1. Added a click listener function
14991483
) : RecyclerView.Adapter<SearchAdapter.ViewHolder>() {
15001484

1485+
@SuppressLint("NotifyDataSetChanged")
15011486
fun updateData(newResults: List<LrcResponse>) {
15021487
this.results = newResults
15031488
notifyDataSetChanged()
@@ -1521,7 +1506,7 @@ class SearchAdapter(
15211506
holder.title.textSize = 16f
15221507

15231508
holder.artist.text = "${item.artistName} • Has Synced Lyrics: ${item.syncedLyrics != null}"
1524-
holder.artist.setTextColor(Color.parseColor("#A0A0A0"))
1509+
holder.artist.setTextColor("#A0A0A0".toColorInt())
15251510

15261511
// 2. Trigger the listener when the user taps this row
15271512
holder.itemView.setOnClickListener {

0 commit comments

Comments
 (0)