From 1434db6f43534ec91c511818b2be9805cddecc84 Mon Sep 17 00:00:00 2001 From: vadym Date: Mon, 7 Dec 2020 08:33:49 +0200 Subject: [PATCH] 1. issue #36. Add peer url form --- .../chronosx88/yggdrasil/PeerListActivity.kt | 42 +++++++++++++++++- .../res/layout/edit_peer_list_url_dialog.xml | 44 +++++++++++++++++++ app/src/main/res/layout/menu_edit_url.xml | 13 ++++++ app/src/main/res/menu/save.xml | 4 ++ 4 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout/edit_peer_list_url_dialog.xml create mode 100644 app/src/main/res/layout/menu_edit_url.xml diff --git a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt index 7007679..3fdad18 100644 --- a/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt +++ b/app/src/main/java/io/github/chronosx88/yggdrasil/PeerListActivity.kt @@ -5,12 +5,14 @@ import android.content.Intent import android.os.Build import android.os.Bundle import android.view.* +import android.webkit.URLUtil import android.widget.Button import android.widget.ListView import android.widget.PopupWindow import android.widget.TextView import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity +import androidx.preference.PreferenceManager import com.google.android.material.floatingactionbutton.FloatingActionButton import com.google.gson.Gson import com.google.gson.reflect.TypeToken @@ -40,6 +42,7 @@ import java.nio.charset.Charset class PeerListActivity : AppCompatActivity() { companion object { + const val PEER_LIST = "PEER_LIST" const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json" const val CACHE_NAME = "PEER_LIST_CACHE" const val ONLINE_PEERINFO_LIST = "online_peer_info_list" @@ -59,6 +62,7 @@ class PeerListActivity : AppCompatActivity() { } } + private var peerListUrl = PEER_LIST_URL private var peerListPing = true var popup: PopupWindow? = null var adapter: DropDownAdapter? = null @@ -70,6 +74,13 @@ class PeerListActivity : AppCompatActivity() { findViewById(R.id.fab).setOnClickListener { _ -> addNewPeer() } + val preferences = + PreferenceManager.getDefaultSharedPreferences(this.baseContext) + var peerListUrl: String = + preferences.getString(PEER_LIST, "")!! + if(!peerListUrl.isNullOrBlank()){ + peerListUrl = this@PeerListActivity.peerListUrl + } var extras = intent.extras var peerList = findViewById(R.id.peerList) var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), mutableSetOf()) @@ -108,7 +119,7 @@ class PeerListActivity : AppCompatActivity() { } } } - var json = downloadJson(PEER_LIST_URL) + var json = downloadJson(peerListUrl) var countries = CCPCountry.getLibraryMasterCountriesEnglish() val mapType: Type = object : TypeToken>>() {}.type @@ -196,6 +207,27 @@ class PeerListActivity : AppCompatActivity() { } } + private fun editPeerListUrl() { + val view: View = LayoutInflater.from(this).inflate(R.layout.edit_peer_list_url_dialog, null) + val ab: AlertDialog.Builder = AlertDialog.Builder(this) + ab.setCancelable(true).setView(view) + var ad = ab.show() + var saveButton = view.findViewById