Repository navigation
Expand file tree
/
Copy pathSettingsActivity.kt
More file actions
70 lines (52 loc) · 2.38 KB
/
Copy pathSettingsActivity.kt
File metadata and controls
70 lines (52 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.example.testsmpp
import android.content.Context
import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import android.widget.ImageButton
class SettingsActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_settings)
supportActionBar?.hide()
val sharedPref = this.getSharedPreferences("gateway_config", MODE_PRIVATE)
val hostEditText = findViewById<EditText>(R.id.editTextHost)
hostEditText.setText(sharedPref.getString("host", ""))
val portEditText = findViewById<EditText>(R.id.editTextPort)
portEditText.setText(sharedPref.getInt("port", 0).toString())
val usernameEditText = findViewById<EditText>(R.id.editTextUsername)
usernameEditText.setText(sharedPref.getString("username", ""))
val passwordEditText = findViewById<EditText>(R.id.editTextPassword)
passwordEditText.setText(sharedPref.getString("password", ""))
val keyEditText = findViewById<EditText>(R.id.editKey)
keyEditText.setText(sharedPref.getString("key", ""))
val submitButton = findViewById<Button>(R.id.buttonSave)
submitButton.setOnClickListener {
val host = hostEditText.text.toString()
val port = portEditText.text.toString()
val username = usernameEditText.text.toString()
val password = passwordEditText.text.toString()
val key = keyEditText.text.toString()
saveConfig(host, port, username, password,key)
val intent = Intent(this, MainActivity::class.java)
startActivity(intent)
}
val backButton = findViewById<ImageButton>(R.id.back_button)
backButton.setOnClickListener {
finish()
}
}
private fun saveConfig(host: String, port: String, username: String, password: String,key:String) {
val sharedPref = this.getSharedPreferences("gateway_config", Context.MODE_PRIVATE)
with(sharedPref.edit()) {
putString("host", host)
putInt("port", port.toInt())
putString("username", username)
putString("password", password)
putString("key", key)
apply()
}
}
}