David Liu

convenience saving of url/token to device

... ... @@ -45,7 +45,7 @@ ext {
]
versions = [
androidx_core : "1.2.0",
androidx_lifecycle: "2.3.0",
androidx_lifecycle: "2.3.1",
dagger : "2.27",
groupie : "2.9.0",
protobuf : "3.15.1",
... ...
... ... @@ -39,9 +39,10 @@ dependencies {
implementation 'com.google.android.material:material:1.3.0'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation "androidx.activity:activity-ktx:1.2.1"
implementation 'androidx.fragment:fragment-ktx:1.3.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.0'
implementation "androidx.activity:activity-ktx:1.2.2"
implementation 'androidx.fragment:fragment-ktx:1.3.2'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.preference:preference:1.1.1'
implementation "androidx.viewpager2:viewpager2:1.0.0"
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:${versions.androidx_lifecycle}"
implementation "androidx.lifecycle:lifecycle-common-java8:${versions.androidx_lifecycle}"
... ...
... ... @@ -9,17 +9,24 @@ import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import io.livekit.android.sample.databinding.MainActivityBinding
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = MainActivityBinding.inflate(layoutInflater)
val preferences = PreferenceManager.getDefaultSharedPreferences(this)
val urlString = preferences.getString(PREFERENCES_KEY_URL, URL)
val tokenString = preferences.getString(PREFERENCES_KEY_TOKEN, TOKEN)
binding.run {
url.editText?.text = URL
token.editText?.text = TOKEN
url.editText?.text = SpannableStringBuilder(urlString)
token.editText?.text = SpannableStringBuilder(tokenString)
connectButton.setOnClickListener {
val intent = Intent(this@MainActivity, CallActivity::class.java).apply {
putExtra(
... ... @@ -33,6 +40,33 @@ class MainActivity : AppCompatActivity() {
startActivity(intent)
}
saveButton.setOnClickListener {
preferences.edit {
putString(PREFERENCES_KEY_URL, url.editText?.text.toString())
putString(PREFERENCES_KEY_TOKEN, token.editText?.text.toString())
}
Toast.makeText(
this@MainActivity,
"Values saved.",
Toast.LENGTH_SHORT
).show()
}
resetButton.setOnClickListener {
preferences.edit {
clear()
}
url.editText?.text = SpannableStringBuilder(URL)
token.editText?.text = SpannableStringBuilder(TOKEN)
Toast.makeText(
this@MainActivity,
"Values reset.",
Toast.LENGTH_SHORT
).show()
}
}
setContentView(binding.root)
... ... @@ -71,8 +105,11 @@ class MainActivity : AppCompatActivity() {
}
companion object {
val URL = SpannableStringBuilder("ws://192.168.91.198:7880")
val TOKEN =
SpannableStringBuilder("eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTgyMDg0NTAsImlzcyI6IkFQSU1teGlMOHJxdUt6dFpFb1pKVjlGYiIsImp0aSI6ImZvcnRoIiwibmJmIjoxNjE1NjE2NDUwLCJ2aWRlbyI6eyJyb29tIjoibXlyb29tIiwicm9vbUpvaW4iOnRydWV9fQ.nu-fOZA-TPFvzleyXk2Zz9b5lFApCXV1npUAexttXQA")
const val PREFERENCES_KEY_URL = "url"
const val PREFERENCES_KEY_TOKEN = "token"
const val URL = "ws://192.168.11.5:7880"
const val TOKEN =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTk0NDkwNTMsImlzcyI6IkFQSXdMZWFoN2c0ZnVMWURZQUplYUtzU0UiLCJqdGkiOiJwaG9uZTIiLCJuYmYiOjE2MTY4NTcwNTMsInZpZGVvIjp7InJvb20iOiJteXJvb20iLCJyb29tSm9pbiI6dHJ1ZX19.OiemzgYXe5269q_VDXb912LG3QoqoKy-52-xEWcTr3A"
}
}
\ No newline at end of file
... ...
... ... @@ -32,6 +32,18 @@
android:id="@+id/connect_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/connect"/>
android:text="@string/connect" />
<Button
android:id="@+id/save_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/save_values" />
<Button
android:id="@+id/reset_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/reset_values" />
</LinearLayout>
\ No newline at end of file
... ...
... ... @@ -3,4 +3,6 @@
<string name="connect">Connect</string>
<string name="token">Token</string>
<string name="url">URL</string>
<string name="save_values">Save Values</string>
<string name="reset_values">Reset Values</string>
</resources>
... ...