mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2025-01-22 16:06:30 +00:00
1. issue #36. Add peer url form
This commit is contained in:
parent
172b7e0ece
commit
1434db6f43
@ -5,12 +5,14 @@ import android.content.Intent
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.*
|
import android.view.*
|
||||||
|
import android.webkit.URLUtil
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
import android.widget.PopupWindow
|
import android.widget.PopupWindow
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
|
import androidx.preference.PreferenceManager
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.google.gson.reflect.TypeToken
|
import com.google.gson.reflect.TypeToken
|
||||||
@ -40,6 +42,7 @@ import java.nio.charset.Charset
|
|||||||
class PeerListActivity : AppCompatActivity() {
|
class PeerListActivity : AppCompatActivity() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
const val PEER_LIST = "PEER_LIST"
|
||||||
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
|
const val PEER_LIST_URL = "https://publicpeers.neilalexander.dev/publicnodes.json"
|
||||||
const val CACHE_NAME = "PEER_LIST_CACHE"
|
const val CACHE_NAME = "PEER_LIST_CACHE"
|
||||||
const val ONLINE_PEERINFO_LIST = "online_peer_info_list"
|
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
|
private var peerListPing = true
|
||||||
var popup: PopupWindow? = null
|
var popup: PopupWindow? = null
|
||||||
var adapter: DropDownAdapter? = null
|
var adapter: DropDownAdapter? = null
|
||||||
@ -70,6 +74,13 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { _ ->
|
findViewById<FloatingActionButton>(R.id.fab).setOnClickListener { _ ->
|
||||||
addNewPeer()
|
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 extras = intent.extras
|
||||||
var peerList = findViewById<ListView>(R.id.peerList)
|
var peerList = findViewById<ListView>(R.id.peerList)
|
||||||
var adapter = SelectPeerInfoListAdapter(this, arrayListOf(), mutableSetOf())
|
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()
|
var countries = CCPCountry.getLibraryMasterCountriesEnglish()
|
||||||
val mapType: Type = object :
|
val mapType: Type = object :
|
||||||
TypeToken<Map<String?, Map<String, Status>>>() {}.type
|
TypeToken<Map<String?, Map<String, Status>>>() {}.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<Button>(R.id.save)
|
||||||
|
saveButton.setOnClickListener{
|
||||||
|
var urlInput = view.findViewById<TextView>(R.id.urlInput)
|
||||||
|
var url = urlInput.text.toString()
|
||||||
|
if(!URLUtil.isValidUrl(url)){
|
||||||
|
urlInput.error = "The URL is invalid!"
|
||||||
|
return@setOnClickListener;
|
||||||
|
}
|
||||||
|
peerListUrl = url
|
||||||
|
val preferences =
|
||||||
|
PreferenceManager.getDefaultSharedPreferences(this.baseContext)
|
||||||
|
preferences.edit().putString(PEER_LIST, peerListUrl).apply()
|
||||||
|
ad.dismiss()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun addNewPeer() {
|
private fun addNewPeer() {
|
||||||
val view: View = LayoutInflater.from(this).inflate(R.layout.new_peer_dialog, null)
|
val view: View = LayoutInflater.from(this).inflate(R.layout.new_peer_dialog, null)
|
||||||
val countryCode: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
val countryCode: String = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
@ -315,6 +347,14 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
setResult(Activity.RESULT_OK, result)
|
setResult(Activity.RESULT_OK, result)
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val editUrl = menu.findItem(R.id.editUrlItem) as MenuItem
|
||||||
|
item.setActionView(R.layout.menu_edit_url)
|
||||||
|
val editUrlButton = editUrl
|
||||||
|
.actionView.findViewById<Button>(R.id.editUrlButton)
|
||||||
|
editUrlButton.setOnClickListener {
|
||||||
|
editPeerListUrl()
|
||||||
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
44
app/src/main/res/layout/edit_peer_list_url_dialog.xml
Normal file
44
app/src/main/res/layout/edit_peer_list_url_dialog.xml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:background="@color/grey">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
|
android:id="@+id/url"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
|
android:layout_margin="10dp"
|
||||||
|
app:boxBackgroundMode="none"
|
||||||
|
android:background="@drawable/edit_text_rounded_corner"
|
||||||
|
android:textColorHint="@color/white"
|
||||||
|
style="@style/EditText.OutlinedBox">
|
||||||
|
|
||||||
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/urlInput"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="URL"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:inputType="number"
|
||||||
|
android:textCursorDrawable="@null"/>
|
||||||
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/save"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:layout_marginLeft="10dp"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
app:layout_constraintTop_toBottomOf="@+id/url"
|
||||||
|
android:background="@drawable/button_selector"
|
||||||
|
app:backgroundTint="@null"
|
||||||
|
android:text="SAVE"
|
||||||
|
android:textColor="@color/white"/>
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
13
app/src/main/res/layout/menu_edit_url.xml
Normal file
13
app/src/main/res/layout/menu_edit_url.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
<Button xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:id="@+id/editUrlButton"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:text="EDIT URL"
|
||||||
|
android:background="@android:color/transparent"/>
|
||||||
|
</RelativeLayout>
|
@ -1,6 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
<item android:id="@+id/editUrlItem"
|
||||||
|
android:title=""
|
||||||
|
app:actionLayout="@layout/menu_edit_url"
|
||||||
|
app:showAsAction="always"/>
|
||||||
<item android:id="@+id/saveItem"
|
<item android:id="@+id/saveItem"
|
||||||
android:title=""
|
android:title=""
|
||||||
app:actionLayout="@layout/menu_save"
|
app:actionLayout="@layout/menu_save"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user