2024-04-27 14:02:15 -04:00
package com.nin0dev.vendroid
2024-04-30 07:38:48 -04:00
import android.annotation.SuppressLint
2024-04-27 14:02:15 -04:00
import android.content.Context
import android.graphics.Color
2024-04-30 07:38:48 -04:00
import android.opengl.Visibility
2024-04-27 14:02:15 -04:00
import android.os.Bundle
2024-04-30 07:38:48 -04:00
import android.service.voice.VoiceInteractionSession.VisibleActivityCallback
2024-04-27 14:02:15 -04:00
import android.view.View
import android.view.WindowManager
import android.widget.CheckBox
import android.widget.EditText
import android.widget.RadioButton
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.google.android.material.floatingactionbutton.ExtendedFloatingActionButton
import com.google.android.material.materialswitch.MaterialSwitch
2024-04-30 07:38:48 -04:00
import com.google.android.material.radiobutton.MaterialRadioButton
import com.google.android.material.textfield.TextInputEditText
2024-04-27 14:02:15 -04:00
class SettingsActivity : AppCompatActivity ( ) {
2024-04-30 07:38:48 -04:00
@SuppressLint ( " CutPasteId " )
2024-04-27 14:02:15 -04:00
override fun onCreate ( savedInstanceState : Bundle ? ) {
super . onCreate ( savedInstanceState )
2024-04-30 07:38:48 -04:00
val sPrefs = getSharedPreferences ( " settings " , Context . MODE _PRIVATE )
2024-04-27 14:02:15 -04:00
window . clearFlags ( WindowManager . LayoutParams . FLAG _TRANSLUCENT _STATUS )
window . statusBarColor = Color . TRANSPARENT
window . clearFlags ( WindowManager . LayoutParams . FLAG _TRANSLUCENT _NAVIGATION )
window . navigationBarColor = Color . TRANSPARENT
setContentView ( R . layout . activity _settings )
2024-04-30 07:38:48 -04:00
findViewById < MaterialSwitch > ( R . id . check _vendroid _updates ) . isChecked = sPrefs . getBoolean ( " checkVendroidUpdates " , false )
when ( sPrefs . getString ( " discordBranch " , " stable " ) ) {
" stable " -> findViewById < MaterialRadioButton > ( R . id . stable ) . isChecked = true
" ptb " -> findViewById < MaterialRadioButton > ( R . id . ptb ) . isChecked = true
" canary " -> findViewById < MaterialRadioButton > ( R . id . canary ) . isChecked = true
}
if ( sPrefs . getString ( " vencordLocation " , " " ) ?. isNotBlank ( ) == true ) {
findViewById < CheckBox > ( R . id . allow _custom _location ) . isChecked = true
val devbuildField = findViewById < TextInputEditText > ( R . id . custom _location )
devbuildField . visibility = View . VISIBLE
devbuildField . setText ( sPrefs . getString ( " vencordLocation " , " " ) )
}
2024-04-27 14:02:15 -04:00
val devbuildCheckbox = findViewById < CheckBox > ( R . id . allow _custom _location )
devbuildCheckbox . setOnClickListener {
if ( devbuildCheckbox . isChecked ) {
MaterialAlertDialogBuilder ( this )
. setTitle ( " Warning " )
. setMessage ( " If you set a custom location, you will be loading and injecting Vencord from a different location. This feature is meant for developers ONLY. Never edit this setting if someone else asked you to, or if you don't know what you're doing! If you do set a custom location, you will not be able to ask for support in the Vencord support channel or in this project's issues. Are you sure you want to continue? " )
. setNegativeButton ( resources . getString ( R . string . no ) ) { _ , _ ->
devbuildCheckbox . isChecked = false
}
. setPositiveButton ( resources . getString ( R . string . yes ) ) { _ , _ ->
findViewById < EditText > ( R . id . custom _location ) . visibility = View . VISIBLE
}
. show ( )
}
else {
findViewById < EditText > ( R . id . custom _location ) . visibility = View . GONE
2024-04-30 07:38:48 -04:00
findViewById < EditText > ( R . id . custom _location ) . setText ( " " )
2024-04-27 14:02:15 -04:00
}
}
findViewById < ExtendedFloatingActionButton > ( R . id . save _settings ) . setOnClickListener {
val editor = sPrefs . edit ( )
editor . putBoolean ( " checkVendroidUpdates " , findViewById < MaterialSwitch > ( R . id . check _vendroid _updates ) . isChecked )
if ( findViewById < RadioButton > ( R . id . stable ) . isChecked ) editor . putString ( " discordBranch " , " stable " )
if ( findViewById < RadioButton > ( R . id . ptb ) . isChecked ) editor . putString ( " discordBranch " , " ptb " )
if ( findViewById < RadioButton > ( R . id . canary ) . isChecked ) editor . putString ( " discordBranch " , " canary " )
if ( findViewById < CheckBox > ( R . id . allow _custom _location ) . isChecked && findViewById < EditText > ( R . id . custom _location ) . text . isNotBlank ( ) ) editor . putString ( " vencordLocation " , findViewById < EditText > ( R . id . custom _location ) . text . toString ( ) )
editor . apply ( )
Toast . makeText ( this , " Settings saved, restart Vendroid to apply them. " , Toast . LENGTH _LONG ) . show ( )
finish ( )
}
}
}