more changes

This commit is contained in:
Tucan444 2021-03-17 20:02:05 +01:00
parent 4e75a3f2a2
commit 14b356bd6c
24 changed files with 499 additions and 26 deletions

@ -0,0 +1,7 @@
<component name="ProjectDictionaryState">
<dictionary name="ben44">
<words>
<w>initing</w>
</words>
</dictionary>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyInterpreterInspection" enabled="false" level="WARNING" enabled_by_default="false" />
</profile>
</component>

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>

@ -2,6 +2,7 @@ plugins {
id 'com.android.application'
id 'kotlin-android'
id 'com.chaquo.python'
id 'kotlin-android-extensions'
}
android {
@ -15,6 +16,8 @@ android {
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
sourceSets {
@ -25,8 +28,9 @@ android {
}
}
python {
buildPython "/urs/local/bin/python3"
buildPython "python3"
pip {
install "requests"
}
}
ndk {
@ -54,7 +58,6 @@ android {
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'

@ -2,6 +2,9 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wikispot">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"

@ -1,3 +0,0 @@
package com.example.wikispot
object Constants {}

@ -1,12 +1,19 @@
package com.example.wikispot.activities
import androidx.appcompat.app.AppCompatActivity
import android.os.Build
import android.os.Bundle
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import com.chaquo.python.Python
import com.chaquo.python.android.AndroidPlatform
import com.example.wikispot.R
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.android.synthetic.main.activity_main.*
import org.json.JSONArray
import org.json.JSONObject
import java.util.*
class MainActivity : AppCompatActivity() {
@ -14,8 +21,8 @@ class MainActivity : AppCompatActivity() {
val builder = AlertDialog.Builder(this)
builder.setTitle("Confirm")
builder.setMessage("Do you want to quit the application?")
builder.setPositiveButton("Yes") {_, _ -> finish()}
builder.setNegativeButton("No") {_, _ -> }
builder.setPositiveButton("Yes") { _, _ -> finish()}
builder.setNegativeButton("No") { _, _ -> }
builder.show()
}
@ -24,8 +31,8 @@ class MainActivity : AppCompatActivity() {
setContentView(R.layout.activity_main)
val navController = findNavController(R.id.mainFragmentHost)
val bottomNavView = findViewById<BottomNavigationView>(R.id.mainBottomNavigationView)
bottomNavView.setupWithNavController(navController)
mainBottomNavigationView.setupWithNavController(navController)
}
}

@ -3,12 +3,37 @@ package com.example.wikispot
import android.content.Context
import android.view.View
import android.widget.Toast
import com.chaquo.python.Python
import com.chaquo.python.android.AndroidPlatform
import com.google.android.material.snackbar.Snackbar
import org.json.JSONObject
fun Context.showToast(message: String, length: Int=Toast.LENGTH_SHORT) {
Toast.makeText(this, message, length).show()
}
fun Context.showSnack(message: String, view: View, length: Int=Snackbar.LENGTH_LONG) {
fun Context.showSnack(message: String, view: View, length: Int = Snackbar.LENGTH_LONG) {
Snackbar.make(this, view, message, length).show()
}
fun Context.getDataFromServer(): MutableList<JSONObject> {
// initing
if (!Python.isStarted()) {
Python.start(AndroidPlatform(this))
}
// getting file
val python = Python.getInstance()
val pythonFile = python.getModule("server_manager")
// getting the data
pythonFile.callAttr("init")
val size = pythonFile.callAttr("get_length").toInt()
val jsonList = mutableListOf<JSONObject>()
for (n in 0 until size) {
jsonList.add(n, JSONObject(pythonFile.callAttr("get_json", n).toString()))
}
return jsonList
}

@ -0,0 +1,40 @@
package com.example.wikispot.fragments
import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.example.wikispot.R
import com.example.wikispot.getDataFromServer
import com.example.wikispot.showSnack
import kotlinx.android.synthetic.main.fragment_debug.*
import org.json.JSONObject
class debugFragment : Fragment(R.layout.fragment_debug) {
private var jsonList: MutableList<JSONObject> = mutableListOf<JSONObject>()
@SuppressLint("SetTextI18n")
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
getDataBtn.setOnClickListener {
context?.let {
jsonList = requireContext().getDataFromServer()
sizeView.text = "Amount of json's: ${jsonList.size}"
}
}
displayJsonFileBtn.setOnClickListener {
val id = idInput.text.toString().toInt()
if (id >= jsonList.size) {
context?.let {
requireContext().showSnack("Id out of range.", displayJsonFileBtn)
}
} else {
jsonFileOutputView.text = jsonList[id].toString()
}
}
}
}

@ -1,8 +1,33 @@
package com.example.wikispot.fragments
import android.os.Bundle
import android.view.View
import androidx.activity.addCallback
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wikispot.R
import com.example.wikispot.models_and_adapters.PlacePreviewsAdapter
import com.example.wikispot.models_and_adapters.PlaceSupplier
import kotlinx.android.synthetic.main.fragment_explore.*
class exploreFragment : Fragment(R.layout.fragment_explore) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupRecyclerView()
}
private fun setupRecyclerView() {
val layoutManager = LinearLayoutManager(context)
layoutManager.orientation = LinearLayoutManager.VERTICAL
explore_recycler_view.layoutManager = layoutManager
val adapter = context?.let { PlacePreviewsAdapter(it, PlaceSupplier.places) }
explore_recycler_view.adapter = adapter
}
}

@ -5,8 +5,19 @@ import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.navigation.Navigation
import com.example.wikispot.R
import kotlinx.android.synthetic.main.fragment_settings.*
class settingsFragment : Fragment(R.layout.fragment_settings) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
debugBtn.setOnClickListener {
Navigation.findNavController(it).navigate(R.id.navigateToDebugFragment)
}
}
}

@ -0,0 +1,39 @@
package com.example.wikispot.models_and_adapters
import android.media.Image
data class PlacePreview(var title: String, var description: String, var img: Image? = null) {
init {
val words = description.split(" ")
description = ""
var lastLine = ""
for (word in words) {
if (lastLine.length + word.length < 40) {
lastLine += " $word"
description += " $word"
} else {
description += "\n $word"
lastLine = " $word"
}
}
}
}
object PlaceSupplier {
val places = arrayOf(
PlacePreview("Castle", "Its ruins had been repaired to stable state."),
PlacePreview("Library", "You can find books here."),
PlacePreview("Bakery", "You can buy bread here."),
PlacePreview("School", "You can learn stuff here."),
PlacePreview("Castle", "Its ruins had been repaired to stable state."),
PlacePreview("Library", "You can find books here."),
PlacePreview("Bakery", "You can buy bread here."),
PlacePreview("School", "You can learn stuff here."),
PlacePreview("Library", "You can find books here."),
PlacePreview("Bakery", "You can buy bread here.")
)
}

@ -0,0 +1,49 @@
package com.example.wikispot.models_and_adapters
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.example.wikispot.R
import kotlinx.android.synthetic.main.explore_list_item.view.*
class PlacePreviewsAdapter(private val context: Context, private val placePreviews: Array<PlacePreview>) : RecyclerView.Adapter<PlacePreviewsAdapter.MyViewHolder>() {
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
var currentPlacePreview: PlacePreview? = null
var pos: Int = 0
init {
}
fun setData(placePreview: PlacePreview?, pos: Int) {
placePreview?.let {
itemView.item_title.text = placePreview.title
itemView.item_description.text = placePreview.description
placePreview.img?.let {
// TODO set image somehow
}
}
this.currentPlacePreview = placePreview
this.pos = pos
}
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val placePreview = placePreviews[position]
holder.setData(placePreview, position)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.explore_list_item, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
return placePreviews.size
}
}

@ -0,0 +1,15 @@
import requests
json_list = []
def init():
global json_list
json_list = eval(requests.get("http://192.168.1.120:8000/devices_list").text)
def get_length():
return len(json_list)
def get_json(i):
return json_list[i]

Binary file not shown.

After

Width:  |  Height:  |  Size: 304 B

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M20,8h-2.81c-0.45,-0.78 -1.07,-1.45 -1.82,-1.96L17,4.41 15.59,3l-2.17,2.17C12.96,5.06 12.49,5 12,5c-0.49,0 -0.96,0.06 -1.41,0.17L8.41,3 7,4.41l1.62,1.63C7.88,6.55 7.26,7.22 6.81,8L4,8v2h2.09c-0.05,0.33 -0.09,0.66 -0.09,1v1L4,12v2h2v1c0,0.34 0.04,0.67 0.09,1L4,16v2h2.81c1.04,1.79 2.97,3 5.19,3s4.15,-1.21 5.19,-3L20,18v-2h-2.09c0.05,-0.33 0.09,-0.66 0.09,-1v-1h2v-2h-2v-1c0,-0.34 -0.04,-0.67 -0.09,-1L20,10L20,8zM14,16h-4v-2h4v2zM14,12h-4v-2h4v2z"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
</vector>

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M12,2C8.13,2 5,5.13 5,9c0,5.25 7,13 7,13s7,-7.75 7,-13c0,-3.87 -3.13,-7 -7,-7zM12,11.5c-1.38,0 -2.5,-1.12 -2.5,-2.5s1.12,-2.5 2.5,-2.5 2.5,1.12 2.5,2.5 -1.12,2.5 -2.5,2.5z"/>
</vector>

@ -10,6 +10,7 @@
android:id="@+id/mainBottomNavigationView"
android:layout_width="match_parent"
android:layout_height="70dp"
app:itemRippleColor="#43E8E8E8"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
card_view:cardCornerRadius="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp">
<ImageView
android:id="@+id/item_img"
android:layout_width="80dp"
android:layout_height="80dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:srcCompat="@drawable/ic_baseline_image_24" />
<TextView
android:id="@+id/item_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginLeft="32dp"
android:layout_marginTop="8dp"
android:textSize="20sp"
android:textStyle="bold"
card_view:layout_constraintStart_toEndOf="@+id/item_img"
card_view:layout_constraintTop_toTopOf="parent"
tools:text="Title" />
<TextView
android:id="@+id/item_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Description"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toStartOf="@+id/item_location_img"
card_view:layout_constraintHorizontal_bias="0.15"
card_view:layout_constraintStart_toEndOf="@+id/item_img"
card_view:layout_constraintTop_toBottomOf="@+id/item_title" />
<ImageView
android:id="@+id/item_location_img"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:srcCompat="@drawable/loacation_vector_asset"
card_view:tint="#F1E79F" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

@ -0,0 +1,93 @@
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EF5350"
tools:context=".fragments.debugFragment">
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="Debug Fragment"
android:textColor="@android:color/white"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/getDataBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Get Data"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.2"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<EditText
android:id="@+id/idInput"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint=" id"
android:inputType="number"
app:layout_constraintStart_toStartOf="@+id/getDataBtn"
app:layout_constraintTop_toBottomOf="@+id/getDataBtn" />
<Button
android:id="@+id/displayJsonFileBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display Json File"
app:layout_constraintStart_toStartOf="@+id/idInput"
app:layout_constraintTop_toBottomOf="@+id/idInput" />
<ScrollView
android:id="@+id/scrollView3"
android:layout_width="380dp"
android:layout_height="100dp"
android:layout_marginTop="16dp"
android:background="#FF6C6C"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/displayJsonFileBtn">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/jsonFileOutputView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="json output"
android:textAlignment="center"
tools:layout_editor_absoluteX="254dp"
tools:layout_editor_absoluteY="95dp" />
</LinearLayout>
</ScrollView>
<TextView
android:id="@+id/sizeView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginLeft="24dp"
android:text="Amount of json's: 0"
android:textSize="24sp"
app:layout_constraintBottom_toTopOf="@+id/displayJsonFileBtn"
app:layout_constraintStart_toEndOf="@+id/idInput"
app:layout_constraintTop_toBottomOf="@+id/getDataBtn" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -4,20 +4,60 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C200897B"
android:background="#2EBFB2"
tools:context=".fragments.exploreFragment">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explore Fragment"
android:textStyle="bold"
android:textColor="#FFFFFF"
android:textSize="24sp"
android:textColor="@android:color/white"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="260dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="1.0">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/explore_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="32dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</ScrollView>
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:scaleX="10"
android:scaleY="0.1"
android:src="@drawable/blank"
android:translationY="10dp"
app:layout_constraintBottom_toTopOf="@+id/scrollView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -20,4 +20,12 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/debugBtn"
android:layout_width="30dp"
android:layout_height="30dp"
app:srcCompat="@drawable/debug_vector_asset"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -16,14 +16,21 @@
android:label="fragment_explore"
tools:layout="@layout/fragment_explore">
<action
android:id="@+id/action_exploreFragment_to_mapFragment"
android:id="@+id/navigateToHomeFragment"
app:destination="@id/mapFragment" />
<action
android:id="@+id/action_exploreFragment_to_homeFragment"
app:destination="@id/homeFragment" />
</fragment>
<fragment
android:id="@+id/homeFragment"
android:name="com.example.wikispot.fragments.homeFragment"
android:label="fragment_home"
tools:layout="@layout/fragment_home" />
tools:layout="@layout/fragment_home" >
<action
android:id="@+id/action_homeFragment_to_chatFragment"
app:destination="@id/chatFragment" />
</fragment>
<fragment
android:id="@+id/mapFragment"
android:name="com.example.wikispot.fragments.mapFragment"
@ -37,5 +44,14 @@
android:id="@+id/settingsFragment"
android:name="com.example.wikispot.fragments.settingsFragment"
android:label="fragment_settings"
tools:layout="@layout/fragment_settings" />
tools:layout="@layout/fragment_settings" >
<action
android:id="@+id/navigateToDebugFragment"
app:destination="@id/debugFragment" />
</fragment>
<fragment
android:id="@+id/debugFragment"
android:name="com.example.wikispot.fragments.debugFragment"
android:label="fragment_debug"
tools:layout="@layout/fragment_debug" />
</navigation>