Skip to content

Commit 0d97a45

Browse files
committed
add navbar toggle, update ver to v.4
1 parent 0b5c9fb commit 0d97a45

File tree

4 files changed

+56
-24
lines changed

4 files changed

+56
-24
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ For this reason, db is pushed to RAM to allow fast querying
1616
- Single page UI (activity_main.xml)
1717

1818
## Planned features / bugs lol:
19+
- add an alert when lost connection w spotify (10 min timeout from spot)
1920
- start playing on searched song
2021
- play pause button (+ settings toggle for this)
2122
- add a intro page + settings entry to re show intro page

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ android {
1212
applicationId = "com.mixtapeo.lyrisync"
1313
minSdk = 24
1414
targetSdk = 36
15-
versionCode = 6
16-
versionName = "v0.39"
15+
versionCode = 7
16+
versionName = "v0.4"
1717

1818
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
1919
}

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

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import androidx.room.Room
3939
import androidx.room.RoomDatabase
4040
import coil.load
4141
import com.atilika.kuromoji.ipadic.Tokenizer
42+
import com.google.android.material.materialswitch.MaterialSwitch
4243
import com.spotify.android.appremote.api.ConnectionParams
4344
import com.spotify.android.appremote.api.Connector
4445
import com.spotify.android.appremote.api.SpotifyAppRemote
@@ -182,36 +183,45 @@ class MainActivity : AppCompatActivity() {
182183
override fun onCreate(savedInstanceState: Bundle?) {
183184
super.onCreate(savedInstanceState)
184185
setContentView(R.layout.activity_main)
185-
// remove status and navbar of android (fullscreen app)
186+
187+
// 1. DECLARE ONCE AT THE TOP
188+
val sharedPrefs = getSharedPreferences("LyriSyncPrefs", MODE_PRIVATE)
189+
val controller = WindowCompat.getInsetsController(window, window.decorView)
190+
191+
// 2. SYSTEM NAVIGATION LOGIC
186192
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
187-
// Make app draw edge-to-edge
188-
// WindowCompat.setDecorFitsSystemWindows(window, false)
193+
val systemNavSwitch = findViewById<MaterialSwitch>(R.id.switchSystemNav)
189194

190-
// Get controller
191-
val controller = WindowCompat.getInsetsController(window, window.decorView)
195+
// Load saved state
196+
val isNavHidden = sharedPrefs.getBoolean("HIDE_SYSTEM_NAV", true)
197+
systemNavSwitch.isChecked = isNavHidden
192198

193-
// Optional: allow swipe to temporarily show bars
194-
controller.systemBarsBehavior =
195-
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
199+
if (isNavHidden) {
200+
controller.hide(WindowInsetsCompat.Type.systemBars())
201+
controller.systemBarsBehavior =
202+
WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
203+
}
196204

197-
// Hide status + navigation bars (fullscreen)
198-
controller.hide(WindowInsetsCompat.Type.statusBars())
199-
controller.hide(WindowInsetsCompat.Type.navigationBars())
205+
systemNavSwitch.setOnCheckedChangeListener { _, isChecked ->
206+
sharedPrefs.edit { putBoolean("HIDE_SYSTEM_NAV", isChecked) }
207+
if (isChecked) {
208+
controller.hide(WindowInsetsCompat.Type.systemBars())
209+
} else {
210+
controller.show(WindowInsetsCompat.Type.systemBars())
211+
}
212+
}
200213
} else {
201214
@Suppress("DEPRECATION")
202-
window.decorView.systemUiVisibility =
203-
View.SYSTEM_UI_FLAG_FULLSCREEN
215+
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_FULLSCREEN
204216
}
205217

206-
findViewById<TextView>(R.id.songTitleText)?.text = "Waiting for Spotify..."
207-
Log.d("Lyrisync", "onCreate finished")
208-
209-
// setup settings views
218+
// 3. SETTINGS & OTHER UI (Remove the 'val' from the sharedPrefs lines below)
219+
// Just use 'sharedPrefs' directly now.
210220
val radioGroupSubtitle = findViewById<RadioGroup>(R.id.spinnerSubtitleMode)
211-
val btnClearHistory = findViewById<Button>(R.id.wipeHistoryButton)
212-
val sharedPrefs = getSharedPreferences("LyriSyncPrefs", MODE_PRIVATE)
213221
val version = packageManager.getPackageInfo(packageName, 0).versionName
214222
findViewById<TextView>(R.id.version).text = version
223+
val btnClearHistory = findViewById<Button>(R.id.wipeHistoryButton)
224+
findViewById<TextView>(R.id.version).text = version
215225

216226
// --- Setup Subtitle Radio Logic ---
217227
val idToIndex = mapOf(
@@ -268,7 +278,8 @@ class MainActivity : AppCompatActivity() {
268278
jishoRv.layoutManager = androidx.recyclerview.widget.LinearLayoutManager(this)
269279

270280
// setup text size buttons
271-
val textSizeSlider = findViewById<com.google.android.material.slider.Slider>(R.id.textSizeSlider)
281+
val textSizeSlider =
282+
findViewById<com.google.android.material.slider.Slider>(R.id.textSizeSlider)
272283

273284
// Load saved text sizes
274285
val savedTextSize = sharedPrefs.getFloat("TEXT_SIZE", 22f)

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,9 @@
303303
<LinearLayout
304304
android:layout_width="match_parent"
305305
android:layout_height="wrap_content"
306+
android:gravity="center"
306307
android:orientation="vertical"
307-
android:padding="16dp"
308-
android:gravity="center">
308+
android:padding="16dp">
309309

310310
<TextView
311311
android:id="@+id/previewFurigana"
@@ -354,6 +354,26 @@
354354
app:thumbColor="@color/brand_primary"
355355
app:trackColorInactive="#33FFFFFF" />
356356

357+
<LinearLayout
358+
android:layout_width="match_parent"
359+
android:layout_height="wrap_content"
360+
android:orientation="horizontal"
361+
android:gravity="center_vertical"
362+
android:paddingVertical="12dp">
363+
<TextView
364+
android:layout_width="0dp"
365+
android:layout_height="wrap_content"
366+
android:layout_weight="1"
367+
android:text="Hide system nav bar"
368+
android:textColor="#FFFFFF"
369+
android:textSize="16sp" />
370+
371+
<com.google.android.material.materialswitch.MaterialSwitch
372+
android:id="@+id/switchSystemNav"
373+
android:layout_width="wrap_content"
374+
android:layout_height="wrap_content"
375+
android:checked="false" />
376+
</LinearLayout>
357377

358378
<com.google.android.material.button.MaterialButton
359379
android:id="@+id/wipeHistoryButton"

0 commit comments

Comments
 (0)