mirror of
https://github.com/yggdrasil-network/yggdrasil-android.git
synced 2025-04-28 22:25:09 +03:00
Implemented an option to reset keys (and IP). (#40)
* Implemented an option to reset keys (and IP). * Implemented an option to set own keys (and IP). * Incremented app version.
This commit is contained in:
parent
a07412d02d
commit
05de180066
8 changed files with 113 additions and 7 deletions
|
@ -1,7 +1,6 @@
|
|||
package eu.neilalexander.yggdrasil
|
||||
|
||||
import android.content.Context
|
||||
import android.provider.Settings
|
||||
import mobile.Mobile
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
@ -29,6 +28,21 @@ object ConfigurationProxy {
|
|||
fix()
|
||||
}
|
||||
|
||||
fun resetKeys() {
|
||||
val newJson = JSONObject(String(Mobile.generateConfigJSON()))
|
||||
updateJSON { json ->
|
||||
json.put("PrivateKey", newJson.getString("PrivateKey"))
|
||||
json.put("PublicKey", newJson.getString("PublicKey"))
|
||||
}
|
||||
}
|
||||
|
||||
fun setKeys(privateKey: String, publicKey: String) {
|
||||
updateJSON { json ->
|
||||
json.put("PrivateKey", privateKey)
|
||||
json.put("PublicKey", publicKey)
|
||||
}
|
||||
}
|
||||
|
||||
fun updateJSON(fn: (JSONObject) -> Unit) {
|
||||
json = JSONObject(file.readText(Charsets.UTF_8))
|
||||
fn(json)
|
||||
|
|
|
@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
|
|||
import android.os.Bundle
|
||||
import android.view.ContextThemeWrapper
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import androidx.core.widget.doOnTextChanged
|
||||
import org.json.JSONObject
|
||||
|
@ -32,8 +33,8 @@ class SettingsActivity : AppCompatActivity() {
|
|||
|
||||
deviceNameEntry.doOnTextChanged { text, _, _, _ ->
|
||||
config.updateJSON { cfg ->
|
||||
val nodeinfo = cfg.optJSONObject("NodeInfo")
|
||||
if (nodeinfo == null) {
|
||||
val nodeInfo = cfg.optJSONObject("NodeInfo")
|
||||
if (nodeInfo == null) {
|
||||
cfg.put("NodeInfo", JSONObject("{}"))
|
||||
}
|
||||
cfg.getJSONObject("NodeInfo").put("name", text)
|
||||
|
@ -56,6 +57,29 @@ class SettingsActivity : AppCompatActivity() {
|
|||
builder.show()
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.resetKeysRow).setOnClickListener {
|
||||
config.resetKeys()
|
||||
updateView()
|
||||
}
|
||||
|
||||
findViewById<View>(R.id.setKeysRow).setOnClickListener {
|
||||
val view = inflater.inflate(R.layout.dialog_set_keys, null)
|
||||
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
|
||||
val privateKey = view.findViewById<EditText>(R.id.private_key)
|
||||
val publicKey = view.findViewById<EditText>(R.id.public_key)
|
||||
builder.setTitle(getString(R.string.set_keys))
|
||||
builder.setView(view)
|
||||
builder.setPositiveButton(getString(R.string.save)) { dialog, _ ->
|
||||
config.setKeys(privateKey.text.toString(), publicKey.text.toString())
|
||||
updateView()
|
||||
dialog.dismiss()
|
||||
}
|
||||
builder.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
|
||||
dialog.cancel()
|
||||
}
|
||||
builder.show()
|
||||
}
|
||||
|
||||
publicKeyLabel.setOnLongClickListener {
|
||||
val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
|
||||
val clip = ClipData.newPlainText("public key", publicKeyLabel.text)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue