mirror of
				https://github.com/yggdrasil-network/yggdrasil-android.git
				synced 2025-11-04 03:05:08 +03:00 
			
		
		
		
	Implemented an option to reset keys (and IP).
This commit is contained in:
		
							parent
							
								
									a07412d02d
								
							
						
					
					
						commit
						305b2ab7c2
					
				
					 5 changed files with 28 additions and 2 deletions
				
			
		| 
						 | 
					@ -29,6 +29,14 @@ object ConfigurationProxy {
 | 
				
			||||||
        fix()
 | 
					        fix()
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun resetKeys() {
 | 
				
			||||||
 | 
					        val newJson = JSONObject(String(Mobile.generateConfigJSON()))
 | 
				
			||||||
 | 
					        updateJSON { json ->
 | 
				
			||||||
 | 
					            json.put("PrivateKey", newJson.getString("PrivateKey"))
 | 
				
			||||||
 | 
					            json.put("PublicKey", newJson.getString("PublicKey"))
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun updateJSON(fn: (JSONObject) -> Unit) {
 | 
					    fun updateJSON(fn: (JSONObject) -> Unit) {
 | 
				
			||||||
        json = JSONObject(file.readText(Charsets.UTF_8))
 | 
					        json = JSONObject(file.readText(Charsets.UTF_8))
 | 
				
			||||||
        fn(json)
 | 
					        fn(json)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -7,6 +7,7 @@ import androidx.appcompat.app.AppCompatActivity
 | 
				
			||||||
import android.os.Bundle
 | 
					import android.os.Bundle
 | 
				
			||||||
import android.view.ContextThemeWrapper
 | 
					import android.view.ContextThemeWrapper
 | 
				
			||||||
import android.view.LayoutInflater
 | 
					import android.view.LayoutInflater
 | 
				
			||||||
 | 
					import android.view.View
 | 
				
			||||||
import android.widget.*
 | 
					import android.widget.*
 | 
				
			||||||
import androidx.core.widget.doOnTextChanged
 | 
					import androidx.core.widget.doOnTextChanged
 | 
				
			||||||
import org.json.JSONObject
 | 
					import org.json.JSONObject
 | 
				
			||||||
| 
						 | 
					@ -32,8 +33,8 @@ class SettingsActivity : AppCompatActivity() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        deviceNameEntry.doOnTextChanged { text, _, _, _ ->
 | 
					        deviceNameEntry.doOnTextChanged { text, _, _, _ ->
 | 
				
			||||||
            config.updateJSON { cfg ->
 | 
					            config.updateJSON { cfg ->
 | 
				
			||||||
                val nodeinfo = cfg.optJSONObject("NodeInfo")
 | 
					                val nodeInfo = cfg.optJSONObject("NodeInfo")
 | 
				
			||||||
                if (nodeinfo == null) {
 | 
					                if (nodeInfo == null) {
 | 
				
			||||||
                    cfg.put("NodeInfo", JSONObject("{}"))
 | 
					                    cfg.put("NodeInfo", JSONObject("{}"))
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                cfg.getJSONObject("NodeInfo").put("name", text)
 | 
					                cfg.getJSONObject("NodeInfo").put("name", text)
 | 
				
			||||||
| 
						 | 
					@ -56,6 +57,11 @@ class SettingsActivity : AppCompatActivity() {
 | 
				
			||||||
            builder.show()
 | 
					            builder.show()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        findViewById<View>(R.id.resetKeysRow).setOnClickListener {
 | 
				
			||||||
 | 
					            config.resetKeys()
 | 
				
			||||||
 | 
					            updateView()
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        publicKeyLabel.setOnLongClickListener {
 | 
					        publicKeyLabel.setOnLongClickListener {
 | 
				
			||||||
            val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
 | 
					            val clipboard: ClipboardManager = getSystemService(CLIPBOARD_SERVICE) as ClipboardManager
 | 
				
			||||||
            val clip = ClipData.newPlainText("public key", publicKeyLabel.text)
 | 
					            val clip = ClipData.newPlainText("public key", publicKeyLabel.text)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -234,6 +234,16 @@
 | 
				
			||||||
                        android:paddingBottom="2pt"
 | 
					                        android:paddingBottom="2pt"
 | 
				
			||||||
                        android:showDividers="middle">
 | 
					                        android:showDividers="middle">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        <TableRow
 | 
				
			||||||
 | 
					                            android:id="@+id/resetKeysRow"
 | 
				
			||||||
 | 
					                            style="@style/SelectableItemStyle">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                            <TextView
 | 
				
			||||||
 | 
					                                android:layout_width="wrap_content"
 | 
				
			||||||
 | 
					                                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                                android:text="@string/reset_keys" />
 | 
				
			||||||
 | 
					                        </TableRow>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        <TableRow
 | 
					                        <TableRow
 | 
				
			||||||
                            android:id="@+id/resetConfigurationRow"
 | 
					                            android:id="@+id/resetConfigurationRow"
 | 
				
			||||||
                            style="@style/SelectableItemStyle">
 | 
					                            style="@style/SelectableItemStyle">
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,6 +64,7 @@
 | 
				
			||||||
    <string name="node_info_hint">Эта информация публична и может появиться на картах сети.</string>
 | 
					    <string name="node_info_hint">Эта информация публична и может появиться на картах сети.</string>
 | 
				
			||||||
    <string name="public_key">Публичный ключ</string>
 | 
					    <string name="public_key">Публичный ключ</string>
 | 
				
			||||||
    <string name="public_key_hint">Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно.</string>
 | 
					    <string name="public_key_hint">Ваш публичный ключ идентифицирует вас в сети. Его распространение безопасно.</string>
 | 
				
			||||||
 | 
					    <string name="reset_keys">Сбросить ключи (и адрес IP)</string>
 | 
				
			||||||
    <string name="reset_configuration">Сбросить настройки</string>
 | 
					    <string name="reset_configuration">Сбросить настройки</string>
 | 
				
			||||||
    <string name="reset_configuration_hint">Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP.</string>
 | 
					    <string name="reset_configuration_hint">Сброс создаст полностью новые настройки. Это изменит ваш публичный ключ и адрес IP.</string>
 | 
				
			||||||
    <string name="tile_disabled">Выключено</string>
 | 
					    <string name="tile_disabled">Выключено</string>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -64,6 +64,7 @@
 | 
				
			||||||
    <string name="node_info_hint">Information entered here is public and may be shown on network maps.</string>
 | 
					    <string name="node_info_hint">Information entered here is public and may be shown on network maps.</string>
 | 
				
			||||||
    <string name="public_key">Public Key</string>
 | 
					    <string name="public_key">Public Key</string>
 | 
				
			||||||
    <string name="public_key_hint">Your public key forms your identity on the network. It is safe to be shared.</string>
 | 
					    <string name="public_key_hint">Your public key forms your identity on the network. It is safe to be shared.</string>
 | 
				
			||||||
 | 
					    <string name="reset_keys">Reset keys (and IP-address)</string>
 | 
				
			||||||
    <string name="reset_configuration">Reset configuration</string>
 | 
					    <string name="reset_configuration">Reset configuration</string>
 | 
				
			||||||
    <string name="reset_configuration_hint">Resetting will overwrite with newly generated configuration. Your public keys and IP address on the network will change.</string>
 | 
					    <string name="reset_configuration_hint">Resetting will overwrite with newly generated configuration. Your public keys and IP address on the network will change.</string>
 | 
				
			||||||
    <string name="tile_disabled">Disabled</string>
 | 
					    <string name="tile_disabled">Disabled</string>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue