added explore and search
This commit is contained in:
4
.idea/misc.xml
generated
4
.idea/misc.xml
generated
@@ -3,7 +3,11 @@
|
||||
<component name="DesignSurface">
|
||||
<option name="filePathToZoomLevelMap">
|
||||
<map>
|
||||
<entry key="app/src/main/res/drawable-v24/ic_launcher_foreground.xml" value="0.37864583333333335" />
|
||||
<entry key="app/src/main/res/drawable/ic_launcher_background.xml" value="0.37864583333333335" />
|
||||
<entry key="app/src/main/res/drawable/peernet_logo_black.xml" value="0.37864583333333335" />
|
||||
<entry key="app/src/main/res/layout/activity_main.xml" value="0.296195652173913" />
|
||||
<entry key="app/src/main/res/layout/activity_search.xml" value="0.3625" />
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
|
||||
@@ -44,4 +44,5 @@ dependencies {
|
||||
implementation (name:'mobile', ext:'aar')
|
||||
implementation 'com.vmadalin:easypermissions-ktx:1.0.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.8.1'
|
||||
//compile 'io.github.rybalkinsd:kohttp:0.10.0'
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
@@ -1,6 +1,15 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.peernet.test" xmlns:tools="http://schemas.android.com/tools">
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.peernet.test">
|
||||
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission
|
||||
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
|
||||
/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -8,8 +17,12 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:usesCleartextTraffic="true"
|
||||
android:theme="@style/Theme.Test">
|
||||
android:theme="@style/Theme.Test"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<activity
|
||||
android:name=".Search"
|
||||
android:exported="true" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
@@ -20,11 +33,5 @@
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace"/>
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
@@ -38,9 +38,6 @@ class MainActivity : AppCompatActivity() {
|
||||
//private val client = OkHttpClient()
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -53,7 +50,7 @@ class MainActivity : AppCompatActivity() {
|
||||
Timer().schedule(4000){
|
||||
// do something after 1 second
|
||||
GlobalScope.launch {
|
||||
val url = "http://127.0.0.1:5125/account/info"
|
||||
val url = "http://127.0.0.1:8881/account/info"
|
||||
|
||||
|
||||
|
||||
@@ -78,7 +75,7 @@ class MainActivity : AppCompatActivity() {
|
||||
// Add the request to the RequestQueue.
|
||||
queue.add(stringRequest)
|
||||
|
||||
val url1 = "http://127.0.0.1:5125/status"
|
||||
val url1 = "http://127.0.0.1:8881/status"
|
||||
|
||||
val stringRequest1 = StringRequest(
|
||||
Request.Method.GET, url1,
|
||||
@@ -99,7 +96,7 @@ class MainActivity : AppCompatActivity() {
|
||||
|
||||
queue.add(stringRequest1)
|
||||
|
||||
val url2 = "http://127.0.0.1:5125/blockchain/file/list"
|
||||
val url2 = "http://127.0.0.1:8881/blockchain/file/list"
|
||||
|
||||
val stringRequest2 = StringRequest(
|
||||
Request.Method.GET, url2,
|
||||
@@ -132,6 +129,15 @@ class MainActivity : AppCompatActivity() {
|
||||
startActivityForResult(Intent.createChooser(intent, "Select a file"), 777)
|
||||
}
|
||||
|
||||
// Go to the search page
|
||||
val SearchHomeButton = findViewById<Button>(R.id.SearchHomeButton)
|
||||
|
||||
SearchHomeButton.setOnClickListener {
|
||||
val intent = Intent(this, Search::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
192
app/src/main/java/com/peernet/test/Search.kt
Normal file
192
app/src/main/java/com/peernet/test/Search.kt
Normal file
@@ -0,0 +1,192 @@
|
||||
package com.peernet.test
|
||||
|
||||
import android.content.Intent
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.*
|
||||
import com.android.volley.Request
|
||||
import com.android.volley.Response
|
||||
import com.android.volley.toolbox.StringRequest
|
||||
import com.android.volley.toolbox.Volley
|
||||
import com.android.volley.DefaultRetryPolicy
|
||||
import com.android.volley.toolbox.JsonObjectRequest
|
||||
import mobile.Mobile
|
||||
import org.json.JSONObject
|
||||
import org.json.JSONTokener
|
||||
|
||||
|
||||
class Search : AppCompatActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_search)
|
||||
|
||||
// Go to the home page
|
||||
val Back = findViewById<Button>(R.id.Back)
|
||||
|
||||
// redirect back to the home page
|
||||
Back.setOnClickListener {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
val queue = Volley.newRequestQueue(this)
|
||||
|
||||
// Explore from golang
|
||||
// Mobile.searchResults()
|
||||
|
||||
// Default display explore
|
||||
val url = "http://127.0.0.1:8881/explore"
|
||||
|
||||
|
||||
|
||||
// Request a string response from the provided URL.
|
||||
val stringRequest = StringRequest(
|
||||
Request.Method.GET, url,
|
||||
Response.Listener<String> { response ->
|
||||
//val connectionLabel = findViewById<View>(R.id.PeernetInfo) as TextView
|
||||
// Display the first 500 characters of the response string.
|
||||
// textView.text = "Response is: ${response.substring(0, 500)}"
|
||||
//connectionLabel.text= "Response is: ${response.substring(0, 500)}"
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = response.toString()
|
||||
Log.d("myTag1", "Response is: ${response}");
|
||||
|
||||
val ResponseObject = JSONTokener(response.toString()).nextValue() as JSONObject
|
||||
|
||||
val searchResult = findViewById<ListView>(R.id.SearchResult)
|
||||
|
||||
val listItems = arrayOfNulls<String>(ResponseObject.getJSONArray("files").length())
|
||||
|
||||
for (i in 0 until ResponseObject.getJSONArray("files").length()) {
|
||||
val searchResultElement = ResponseObject.getJSONArray("files")[i]
|
||||
|
||||
val ResponseObjectInLoop = JSONTokener(ResponseObject.getJSONArray("files")[i].toString()).nextValue() as JSONObject
|
||||
|
||||
listItems[i] = ResponseObjectInLoop.get("name").toString()
|
||||
}
|
||||
|
||||
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)
|
||||
|
||||
searchResult.adapter = adapter
|
||||
|
||||
|
||||
|
||||
},
|
||||
Response.ErrorListener { errorresponse ->
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = errorresponse.toString()
|
||||
Log.d("myTag", errorresponse.toString());
|
||||
})
|
||||
|
||||
queue.add(stringRequest)
|
||||
|
||||
// Search Button
|
||||
val SearchButton = findViewById<Button>(R.id.Search)
|
||||
val SearchField = findViewById<EditText>(R.id.SearchField)
|
||||
|
||||
// Search onclick action
|
||||
SearchButton.setOnClickListener {
|
||||
// get text from search field
|
||||
val search = SearchField.text.toString()
|
||||
|
||||
|
||||
// Get search job UUID
|
||||
val url = "http://127.0.0.1:8881/search"
|
||||
|
||||
// val params = HashMap<String,String>()
|
||||
// params["term"] = search
|
||||
// val jsonObject = JSONObject(params)
|
||||
|
||||
// "timeout": 10,
|
||||
// "maxresults": 1000,
|
||||
// "sort": 0,
|
||||
// "filetype": -1,
|
||||
// "fileformat": -1,
|
||||
// "sizemin": -1,
|
||||
// "sizemax": -1
|
||||
|
||||
val jsonobj = JSONObject()
|
||||
jsonobj.put("term", search)
|
||||
jsonobj.put("timeout", 10)
|
||||
jsonobj.put("maxresults", 1000)
|
||||
jsonobj.put("filetype", -1)
|
||||
jsonobj.put("fileformat", -1)
|
||||
jsonobj.put("sizemin", -1)
|
||||
jsonobj.put("sizemax", -1)
|
||||
|
||||
|
||||
// Request a string response from the provided URL.
|
||||
|
||||
val stringRequest = JsonObjectRequest(
|
||||
Request.Method.POST,url,jsonobj,
|
||||
Response.Listener { response ->
|
||||
//val connectionLabel = findViewById<View>(R.id.PeernetInfo) as TextView
|
||||
// Display the first 500 characters of the response string.
|
||||
// textView.text = "Response is: ${response.substring(0, 500)}"
|
||||
//connectionLabel.text= "Response is: ${response.substring(0, 500)}"
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = response.toString()
|
||||
Log.d("myTag1", "Response is: ${response}");
|
||||
|
||||
val ResponseObject = JSONTokener(response.toString()).nextValue() as JSONObject
|
||||
|
||||
// request to get Job response
|
||||
val url1 = "http://127.0.0.1:8881/search/result?id=" + ResponseObject.get("id")
|
||||
|
||||
Log.d("myTag", url1);
|
||||
|
||||
val stringRequest1 = StringRequest(
|
||||
Request.Method.GET,url1,
|
||||
Response.Listener { response ->
|
||||
//val connectionLabel = findViewById<View>(R.id.PeernetInfo) as TextView
|
||||
// Display the first 500 characters of the response string.
|
||||
// textView.text = "Response is: ${response.substring(0, 500)}"
|
||||
//connectionLabel.text= "Response is: ${response.substring(0, 500)}"
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = response.toString()
|
||||
Log.d("myTag1", "Response is: ${response}");
|
||||
|
||||
val ResponseObject = JSONTokener(response.toString()).nextValue() as JSONObject
|
||||
|
||||
val searchResult = findViewById<ListView>(R.id.SearchResult)
|
||||
|
||||
val listItems = arrayOfNulls<String>(ResponseObject.getJSONArray("files").length())
|
||||
|
||||
for (i in 0 until ResponseObject.getJSONArray("files").length()) {
|
||||
val searchResultElement = ResponseObject.getJSONArray("files")[i]
|
||||
|
||||
val ResponseObjectInLoop = JSONTokener(ResponseObject.getJSONArray("files")[i].toString()).nextValue() as JSONObject
|
||||
|
||||
listItems[i] = ResponseObjectInLoop.get("name").toString()
|
||||
}
|
||||
|
||||
val adapter = ArrayAdapter(this, android.R.layout.simple_list_item_1, listItems)
|
||||
|
||||
searchResult.adapter = adapter
|
||||
|
||||
},
|
||||
Response.ErrorListener { errorresponse ->
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = errorresponse.toString()
|
||||
Log.d("myTag", errorresponse.toString());
|
||||
})
|
||||
|
||||
queue.add(stringRequest1)
|
||||
|
||||
},
|
||||
Response.ErrorListener { errorresponse ->
|
||||
// val connectionLabel1 = findViewById<View>(R.id.PeernetInfo1) as TextView
|
||||
// connectionLabel1.text = errorresponse.toString()
|
||||
Log.d("myTag", errorresponse.toString());
|
||||
})
|
||||
|
||||
queue.add(stringRequest)
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
9
app/src/main/res/drawable/peernet_logo_black.xml
Normal file
9
app/src/main/res/drawable/peernet_logo_black.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="1200dp"
|
||||
android:height="1200dp"
|
||||
android:viewportWidth="1200"
|
||||
android:viewportHeight="1200">
|
||||
<path
|
||||
android:pathData="M628.67,293C669.73,293 705.27,299.86 735.29,313.57C765.76,327.28 789.16,346.74 805.5,371.95C821.83,397.17 830,427.02 830,461.52C830,495.58 821.83,525.44 805.5,551.09C789.16,576.3 765.76,595.77 735.29,609.48C705.27,622.75 669.73,629.38 628.67,629.38H535.29V757.43L428,907V293H628.67ZM622.71,541.8C654.94,541.8 679.44,534.95 696.22,521.23C713,507.08 721.39,487.18 721.39,461.52C721.39,435.43 713,415.52 696.22,401.81C679.44,387.65 654.94,380.58 622.71,380.58H535.29V541.8H622.71Z"
|
||||
android:fillColor="#22242C"/>
|
||||
</vector>
|
||||
@@ -10,6 +10,7 @@
|
||||
android:id="@+id/PeernetInfo"
|
||||
android:layout_width="192dp"
|
||||
android:layout_height="244dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/PeernetInfo1"
|
||||
@@ -17,7 +18,7 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.01" />
|
||||
app:layout_constraintVertical_bias="0.324" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/PeernetInfo1"
|
||||
@@ -29,7 +30,7 @@
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.0" />
|
||||
app:layout_constraintVertical_bias="0.325" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/PeernetInfo2"
|
||||
@@ -37,20 +38,41 @@
|
||||
android:layout_height="245dp"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.453"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.534" />
|
||||
app:layout_constraintVertical_bias="0.845" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/AddFIle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="104dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:text="Add file "
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="385dp"
|
||||
android:layout_height="138dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.026"
|
||||
app:srcCompat="@drawable/peernet_logo_black"
|
||||
tools:layout_editor_absoluteX="13dp" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/SearchHomeButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Search"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.11"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="0.976" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
52
app/src/main/res/layout/activity_search.xml
Normal file
52
app/src/main/res/layout/activity_search.xml
Normal file
@@ -0,0 +1,52 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/SearchPeerNet"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".Search">
|
||||
|
||||
<EditText
|
||||
android:id="@+id/SearchField"
|
||||
android:layout_width="333dp"
|
||||
android:layout_height="49dp"
|
||||
android:layout_marginTop="84dp"
|
||||
android:ems="10"
|
||||
android:inputType="textPersonName"
|
||||
android:text="Search"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/Search"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="Search"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/SearchField" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/Back"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="4dp"
|
||||
android:text="Back"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintHorizontal_bias="0.0"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<ListView
|
||||
android:id="@+id/SearchResult"
|
||||
android:layout_width="409dp"
|
||||
android:layout_height="527dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintVertical_bias="1.0" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
Reference in New Issue
Block a user