LibreTube/app/src/main/java/com/github/libretube/SettingsActivity.kt

74 lines
2.5 KiB
Kotlin
Raw Normal View History

2022-05-11 01:35:15 +05:30
package com.github.libretube
2022-06-01 11:32:16 +05:30
import android.app.NotificationManager
2022-05-11 01:35:15 +05:30
import android.os.Build
import android.os.Bundle
2022-05-11 13:34:48 +05:30
import android.view.View
import android.widget.ImageButton
import android.widget.TextView
2022-05-11 01:35:15 +05:30
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
2022-06-07 16:12:59 +05:30
import com.github.libretube.preferences.MainSettings
2022-06-07 13:05:49 +05:30
import com.github.libretube.util.ThemeHelper
2022-05-20 20:03:29 +05:30
import com.google.android.material.color.DynamicColors
2022-05-24 00:04:18 +05:30
2022-06-07 12:22:11 +05:30
var isCurrentViewMainSettings = true
var requireMainActivityRestart = false
2022-05-22 15:28:27 +05:30
2022-06-07 12:22:11 +05:30
class SettingsActivity : AppCompatActivity() {
2022-06-07 16:12:59 +05:30
val TAG = "SettingsActivity"
2022-05-11 01:35:15 +05:30
override fun onCreate(savedInstanceState: Bundle?) {
2022-05-20 03:43:02 +05:30
DynamicColors.applyToActivityIfAvailable(this)
2022-06-07 13:05:49 +05:30
ThemeHelper().updateTheme(this)
2022-06-07 17:12:07 +05:30
// makes the preference dialogs use material dialogs
setTheme(R.style.MaterialAlertDialog)
2022-05-20 03:11:21 +05:30
2022-05-11 01:35:15 +05:30
super.onCreate(savedInstanceState)
2022-05-13 22:25:15 +05:30
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
overridePendingTransition(50, 50)
2022-05-13 22:25:15 +05:30
}
2022-05-11 13:34:48 +05:30
val view = this.findViewById<View>(android.R.id.content)
2022-05-20 03:39:47 +05:30
view.alpha = 0F
view.animate().alpha(1F).duration = 300
2022-05-11 01:35:15 +05:30
setContentView(R.layout.activity_settings)
2022-06-07 23:46:58 +05:30
val backButton = view.findViewById<ImageButton>(R.id.back_imageButton)
2022-06-07 23:46:58 +05:30
backButton.setOnClickListener {
onBackPressed()
}
2022-05-11 01:35:15 +05:30
if (savedInstanceState == null) {
supportFragmentManager
.beginTransaction()
2022-06-07 16:12:59 +05:30
.replace(R.id.settings, MainSettings())
2022-05-11 01:35:15 +05:30
.commit()
}
}
2022-05-11 13:34:48 +05:30
override fun onBackPressed() {
2022-05-22 15:28:27 +05:30
if (isCurrentViewMainSettings) {
2022-05-31 01:49:42 +05:30
if (requireMainActivityRestart) {
2022-05-31 11:12:55 +05:30
requireMainActivityRestart = false
2022-06-01 11:32:16 +05:30
// kill player notification
2022-06-07 12:22:11 +05:30
val nManager =
2022-06-07 13:05:49 +05:30
this.getSystemService(NOTIFICATION_SERVICE) as NotificationManager
2022-06-01 11:32:16 +05:30
nManager.cancelAll()
2022-06-07 13:05:49 +05:30
ThemeHelper().restartMainActivity(this)
2022-06-07 12:22:11 +05:30
ActivityCompat.finishAffinity(this)
2022-05-31 01:49:42 +05:30
} else {
super.onBackPressed()
}
finishAndRemoveTask()
2022-05-22 15:28:27 +05:30
} else {
isCurrentViewMainSettings = true
supportFragmentManager
.beginTransaction()
2022-06-07 16:12:59 +05:30
.replace(R.id.settings, MainSettings())
2022-05-22 15:28:27 +05:30
.commit()
val topBarTextView = findViewById<TextView>(R.id.topBar_textView)
topBarTextView?.text = getString(R.string.settings)
2022-05-22 15:28:27 +05:30
}
2022-05-11 01:35:15 +05:30
}
2022-05-20 03:23:55 +05:30
}