more changes

This commit is contained in:
Tucan444 2021-04-14 14:04:01 +02:00
parent f3d90ae42a
commit c41a2c81e9
30 changed files with 755 additions and 159 deletions

@ -2,6 +2,7 @@
<dictionary name="ben44">
<words>
<w>backstack</w>
<w>datatype</w>
<w>filetype</w>
<w>initing</w>
</words>

@ -1,27 +1,29 @@
package com.example.wikispot.activities
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.util.DisplayMetrics
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
import androidx.fragment.app.Fragment
import androidx.navigation.findNavController
import androidx.navigation.ui.setupWithNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wikispot.*
import com.example.wikispot.adapters.FileViewsAdapter
import com.example.wikispot.adapters.LabeledValuesAdapter
import com.example.wikispot.adapters.PlacePreviewsAdapter
import com.example.wikispot.fragments.*
import com.example.wikispot.modelClasses.JsonManager
import com.example.wikispot.modelClasses.JsonManagerLite
import com.example.wikispot.modelClasses.SettingsSaveManager
import com.example.wikispot.modelsForAdapters.LabeledValue
import com.example.wikispot.modelsForAdapters.LabeledValuesSupplier
import com.example.wikispot.modelsForAdapters.PlacePreview
import com.example.wikispot.modelsForAdapters.PlaceSupplier
import com.example.wikispot.modelsForAdapters.*
import com.google.android.gms.maps.model.LatLng
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_explore.*
import kotlinx.android.synthetic.main.fragment_home.*
import kotlinx.android.synthetic.main.fragment_info.*
import kotlinx.android.synthetic.main.fragment_info.view.*
class MainActivity : AppCompatActivity() {
@ -46,11 +48,15 @@ class MainActivity : AppCompatActivity() {
askToQuit()
}
is infoFragment -> {
currentlyShownFragment.goExploreFragment()
println(CustomBackstackVariables.infoFragmentBackDestination)
when (CustomBackstackVariables.infoFragmentBackDestination) {
"exploreFragment" -> { currentlyShownFragment.goExploreFragment() }
"mapFragment" -> {currentlyShownFragment.goMapFragment()}
}
}
}
} catch (e: Throwable) { println(e) }
}
override fun onCreate(savedInstanceState: Bundle?) {
@ -82,16 +88,10 @@ class MainActivity : AppCompatActivity() {
val dataReceiver1: (String) -> Unit = { data1: String ->
val json = JsonManager(this, data1, "JSONObject")
val names = json.currentJsonObject!!.names()
println("[debug] $data1")
try {
mainFragmentHost.childFragmentManager.fragments[0]?.let {
when (it) {
is chatFragment -> {
}
is exploreFragment -> {
}
is homeFragment -> {
if (it is homeFragment) {
LabeledValuesSupplier.wipeData()
for (n in 0 until names!!.length()) {
@ -110,19 +110,10 @@ class MainActivity : AppCompatActivity() {
it.labeled_values_recycler_view.adapter = adapter
}
}
is mapFragment -> {
}
is settingsFragment -> {
}
is infoFragment -> {
}
else -> println("[debug] unknown fragment in sensorsConnection")
}
}
} catch (e: Throwable) { println(e) }
} catch (e: Throwable) { println("[debug] Exception in main activity, sensors connection : $e") }
}
println(data0)
if (!ServerManagement.serverManager.checkIfConnectionAlreadyExists("sensorsConnection")){
ServerManagement.serverManager.addReceiverConnection(dataReceiver1, this, "sensorsConnection", data0.toInt(), ServerManagement.sensors_keyword)
@ -133,13 +124,82 @@ class MainActivity : AppCompatActivity() {
var json = JsonManager(this, data1)
json = JsonManager(this, json.findJsonObjectByAttribute("ID", data0.toInt()), "JSONObject")
val positionsList = json.getAttributeContent("location").split(",")
MapManagement.connectedServerTitle = json.getAttributeContentByPath("description/title")
MapManagement.connectedServerPosition = LatLng(positionsList[0].toDouble(), positionsList[1].toDouble())
}
if (!ServerManagement.serverManager.checkIfConnectionAlreadyExists("mapConnection")){
ServerManagement.serverManager.addReceiverConnection(dataReceiver2, this, "mapConnection", data0.toInt(), "", "GET_WHOLE_ARRAY")
}
val dataReceiver3: (String) -> Unit = { data1: String ->
val json = JsonManager(this, data1)
json.findJsonObjectByAttribute("ID", data0.toInt())
fun updateFileViewsRecyclerView(fragment: Fragment) {
try {
fragment.homeFragmentInnerFragment?.let {
it.file_views_recycler_view.post {
val layoutManager = LinearLayoutManager(fragment.requireContext())
layoutManager.orientation = LinearLayoutManager.VERTICAL
it.file_views_recycler_view.layoutManager = layoutManager
val adapter = FileViewsAdapter(fragment.requireContext(), FileViewsSupplier.fileViews)
it.file_views_recycler_view.adapter = adapter
}
}
} catch (e: Throwable) { println("[debug] e1 that i couldnt fix so try catch Exception: $e") }
}
try {
mainFragmentHost.childFragmentManager.fragments[0]?.let {
when (it) {
is homeFragment -> {
json.getAttributeContent("files")
for (n in 0 until json.currentJsonAttribute1!!.length()) {
val fileInfo = JsonManagerLite(json.getAttributeContentByPath("files/$n"), "JSONObject")
val filetype = fileInfo.getAttributeContentByPath("format").split(".")[1]
val filename = fileInfo.getAttributeContentByPath("name")
// handling text
if ("txt json".contains(filetype)) {
val fileView = FileView(filetype, filename, "$data0|||||$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView(it)
}
}
// handling images
if ("jpg png".contains(filetype)) {
val fileView = FileView(filetype, filename, null, "$data0|||||$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView(it)
}
}
// handling pdf files
if ("pdf".contains(filetype)) {
val fileView = FileView(filetype, filename, null, null, "${ServerManagement.baseUrl}files/$data0/$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView(it)
}
}
}
}
}
}
} catch (e: Throwable) { println("[debug] Exception in main activity, files data request : $e") }
}
ServerManagement.serverManager.addReceiverConnection(dataReceiver3, this, "fileViewsConnection", data0.toInt(), "", "GET_WHOLE_ARRAY")
}
ServerManagement.serverManager.getData(dataReceiver0, this, 0, "", "connected_id", 3)
@ -150,6 +210,7 @@ class MainActivity : AppCompatActivity() {
PlaceSupplier.saveToCache(this)
ServerManagement.serverManager.deleteConnection("sensorsConnection")
ServerManagement.serverManager.deleteConnection("mapConnection")
ServerManagement.serverManager.deleteConnection("fileViewsConnection")
ServerManagement.serverManager.deleteConnection("exploreListConnection")
super.onPause()
}
@ -186,9 +247,7 @@ class MainActivity : AppCompatActivity() {
val dataReceiver: (String) -> Unit = { data: String ->
val json = JsonManager(this, data)
if (PlaceSupplier.controlJson == null) {
PlaceSupplier.controlJson = JsonManagerLite(data)
}
for (i in 1 until json.getLengthOfJsonArray()) {
@ -218,6 +277,26 @@ class MainActivity : AppCompatActivity() {
ServerManagement.serverManager.getImage(imageReceiver, id, "test.png", 3)
}
// checking if location wasn't changed
if ((containingPlace != null) and (containingPlace?.location != location)) {
containingPlace?.location = location
try {
mainFragmentHost.childFragmentManager.fragments[0]?.let {
if (it is exploreFragment) {
it.explore_recycler_view.post {
val layoutManager = LinearLayoutManager(it.requireContext())
layoutManager.orientation = LinearLayoutManager.VERTICAL
it.explore_recycler_view.layoutManager = layoutManager
val adapter = PlacePreviewsAdapter(it.requireContext(), PlaceSupplier.places)
it.explore_recycler_view.adapter = adapter
}
}
}
} catch (e: Throwable) { println("[debug] e4 that i couldnt fix si try catch Exception: $e") }
}
}
json.clearSelectedAttribute()
@ -227,34 +306,4 @@ class MainActivity : AppCompatActivity() {
ServerManagement.serverManager.addReceiverConnection(dataReceiver, this, "exploreListConnection", 0, "", "GET_WHOLE_ARRAY", 10000)
}
private fun restartAppPartially() { // todo remove if not used
val intent = Intent(applicationContext, MainActivity::class.java)
var currentNavHostFragmentName = "homeFragment"
try {
when (mainFragmentHost.childFragmentManager.fragments[0]) {
is chatFragment -> {
currentNavHostFragmentName = "chatFragment"
}
is exploreFragment -> {
currentNavHostFragmentName = "exploreFragment"
}
is homeFragment -> {
currentNavHostFragmentName = "homeFragment"
}
is mapFragment -> {
currentNavHostFragmentName = "mapFragment"
}
is settingsFragment -> {
currentNavHostFragmentName = "settingsFragment"
}
}
} catch (e: Throwable) { println(e) }
intent.putExtra(IntentsKeys.startFragment, currentNavHostFragmentName)
startActivity(intent)
finish()
}
}

@ -0,0 +1,44 @@
package com.example.wikispot.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 com.example.wikispot.modelsForAdapters.Message
import kotlinx.android.synthetic.main.message.view.*
class ChatMessagesAdapter(private val context: Context, private val messages: Array<Message?>) : RecyclerView.Adapter<ChatMessagesAdapter.MyViewHolder>() {
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
var message: Message? = null
var pos: Int = 0
fun setData(message: Message?, pos: Int) {
message?.let {
itemView.message_author_text.text = message.author
itemView.message_content_text.text = message.content
}
this.message = message
this.pos = pos
}
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val message = messages[position]
holder.setData(message, position)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.message, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
return messages.size
}
}

@ -0,0 +1,110 @@
package com.example.wikispot.adapters
import android.content.Context
import android.graphics.Bitmap
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import androidx.recyclerview.widget.RecyclerView
import com.example.wikispot.R
import com.example.wikispot.ServerManagement
import com.example.wikispot.modelsForAdapters.FileView
import kotlinx.android.synthetic.main.file_view.view.*
class FileViewsAdapter(private val context: Context, private val fileViews: Array<FileView?>) : RecyclerView.Adapter<FileViewsAdapter.MyViewHolder>() {
private val rotateOpen: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.open_rotation_anim) }
private val rotateClose: Animation by lazy { AnimationUtils.loadAnimation(context, R.anim.close_rotation_anim) }
inner class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView){
var fileView: FileView? = null
var pos: Int = 0
var textInfo: String? = null
var imgInfo: String? = null
var pdfUrl: String? = null
var opened = false
init {
itemView.setOnClickListener {
if (!opened) {
itemView.showFileBtn.startAnimation(rotateOpen)
fileView?.let {
textInfo?.let {
itemView.textContent.textSize = 18F
val dataReceiver: (String) -> Unit = { data: String ->
itemView.textContent.post {
itemView.textContent.text = data
}
}
val textInformation = textInfo!!.split("|||||")
ServerManagement.serverManager.getData(dataReceiver, itemView.context, textInformation[0].toInt(), textInformation[1])
}
imgInfo?.let {
itemView.imageContent.visibility = View.VISIBLE
val imageReceiver2: (Bitmap) -> Unit = { bitmap: Bitmap ->
itemView.imageContent.post {
itemView.imageContent.setImageBitmap(bitmap)
}
}
val imgInformation = imgInfo!!.split("|||||")
ServerManagement.serverManager.getImage(imageReceiver2, imgInformation[0].toInt(), imgInformation[1])
}
pdfUrl?.let {
itemView.pdfContent.visibility = View.VISIBLE
ServerManagement.serverManager.loadPdfView(itemView.pdfContent, pdfUrl!!)
}
}
} else {
itemView.showFileBtn.startAnimation(rotateClose)
itemView.textContent.textSize = 0F
itemView.imageContent.visibility = View.GONE
itemView.pdfContent.visibility = View.GONE
}
opened = !opened
}
}
fun setData(fileView: FileView?, pos: Int) {
fileView?.let {
fileView.textInfo?.let {
textInfo = it
}
fileView.imgInfo?.let {
imgInfo = it
}
fileView.pdfUrl?.let {
pdfUrl = it
}
itemView.filename_text.text = fileView.filename
}
this.fileView = fileView
this.pos = pos
}
}
override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
val fileView = fileViews[position]
holder.setData(fileView, position)
}
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
val view = LayoutInflater.from(context).inflate(R.layout.file_view, parent, false)
return MyViewHolder(view)
}
override fun getItemCount(): Int {
return fileViews.size
}
}

@ -4,8 +4,10 @@ import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import androidx.recyclerview.widget.RecyclerView
import com.example.wikispot.CustomBackstackVariables
import com.example.wikispot.R
import com.example.wikispot.ServerManagement
import com.example.wikispot.fragments.exploreFragmentDirections
@ -25,6 +27,7 @@ class PlacePreviewsAdapter(private val context: Context, private val placePrevie
init {
itemView.setOnClickListener {
CustomBackstackVariables.infoFragmentBackDestination = "exploreFragment"
ServerManagement.selectedServerId = currentPlacePreview?.id!!
val action = exploreFragmentDirections.navigateToInfoFragment(true)
Navigation.findNavController(it).navigate(action)
@ -32,7 +35,7 @@ class PlacePreviewsAdapter(private val context: Context, private val placePrevie
itemView.item_location_img.setOnClickListener {
if (location != null) {
val action = exploreFragmentDirections.navigateToMapFragment(location!!, currentPlacePreview!!.title)
val action = exploreFragmentDirections.navigateToMapFragment(location!!)
Navigation.findNavController(it).navigate(action)
}
}

@ -2,11 +2,35 @@ package com.example.wikispot.fragments
import android.os.Bundle
import androidx.fragment.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wikispot.R
import com.example.wikispot.adapters.ChatMessagesAdapter
import com.example.wikispot.adapters.FileViewsAdapter
import com.example.wikispot.modelsForAdapters.MessagesSupplier
import kotlinx.android.synthetic.main.fragment_chat.*
import kotlinx.android.synthetic.main.fragment_info.*
class chatFragment : Fragment(R.layout.fragment_chat) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateRecyclerView()
}
private fun updateRecyclerView() {
chat_messages_recycler_view.post {
val layoutManager = LinearLayoutManager(context)
layoutManager.orientation = LinearLayoutManager.VERTICAL
chat_messages_recycler_view.layoutManager = layoutManager
val adapter = context?.let { ChatMessagesAdapter(it, MessagesSupplier.messages) }
chat_messages_recycler_view.adapter = adapter
}
}
}

@ -1,9 +1,6 @@
package com.example.wikispot.fragments
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.Uri
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
@ -41,19 +38,16 @@ class debugFragment : Fragment(R.layout.fragment_debug) {
override fun run() {
val inputStream = java.net.URL("${ServerManagement.baseUrl}files/1/sample.pdf").openStream()
val uri = Uri.parse("${ServerManagement.baseUrl}files/1/sample.pdf")
Thread.sleep(500)
pdfView.post {
println("asdfsdfsdfs")
//pdfView.fromUri(uri).load()
pdfView.fromStream(inputStream).pages(0).load()
pdfView.zoomTo(pdfView.width / 490.0F)
println("[debug] zoom is ${pdfView.width / 490.0F}")
println(pdfView.width)
pdfContent.post {
pdfContent.fromStream(inputStream).load()
pdfContent.zoomTo(pdfContent.width / 490.0F)
println("[debug] zoom is ${pdfContent.width / 490.0F}")
println(pdfContent.width)
Thread.sleep(1000)
println(pdfView.currentPage)
println(pdfContent.currentPage)
}
ServerManagement.totalNumberOfRequestsSent += 1

@ -35,17 +35,19 @@ class homeFragment : Fragment(R.layout.fragment_home) {
infoFragmentLoadedIn = true
homeFragmentInnerFragment.post {
homeFragmentInnerFragment.let { fragment ->
homeFragmentInnerFragment?.let { fragment ->
fragment.mainTitle.text = json.getAttributeContentByPath("description/title")
fragment.mainDescription.text = json.getAttributeContentByPath("description/description_l")
}
}
val imageReceiver: (Bitmap) -> Unit = { bitmap: Bitmap ->
homeFragmentInnerFragment?.let {
homeFragmentInnerFragment.post {
homeFragmentInnerFragment.mainImage.setImageBitmap(bitmap)
}
}
}
ServerManagement.serverManager.getImage(imageReceiver, json.getAttributeContent("ID").toInt(), "test0.jpg", 3)

@ -9,15 +9,20 @@ import androidx.navigation.fragment.navArgs
import androidx.recyclerview.widget.LinearLayoutManager
import com.example.wikispot.R
import com.example.wikispot.ServerManagement
import com.example.wikispot.adapters.FileViewsAdapter
import com.example.wikispot.adapters.LabeledValuesAdapter
import com.example.wikispot.modelClasses.JsonManager
import com.example.wikispot.modelClasses.JsonManagerLite
import com.example.wikispot.modelsForAdapters.FileView
import com.example.wikispot.modelsForAdapters.FileViewsSupplier
import com.example.wikispot.modelsForAdapters.LabeledValue
import com.example.wikispot.modelsForAdapters.LabeledValuesSupplier
import com.google.android.gms.maps.model.LatLng
import kotlinx.android.synthetic.main.fragment_info.*
import java.io.File
class infoFragment() : Fragment(R.layout.fragment_info) {
class infoFragment : Fragment(R.layout.fragment_info) {
private val args: infoFragmentArgs by navArgs()
var location: LatLng? = null
@ -26,7 +31,10 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
updateRecyclerView()
LabeledValuesSupplier.wipeData()
FileViewsSupplier.wipeData()
updateSensorsRecyclerView()
updateFileViewsRecyclerView()
try {
loadAutomatically = args.loadAutomatically
@ -39,7 +47,7 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
locationBtn.setOnClickListener {
if (loadAutomatically) {
if (location != null) {
val action = infoFragmentDirections.infoFragmentToMapFragment(location!!, mainTitle.text.toString())
val action = infoFragmentDirections.infoFragmentToMapFragment(location!!)
Navigation.findNavController(it).navigate(action)
}
} else {
@ -52,19 +60,20 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
val serverId = ServerManagement.selectedServerId
val dataReceiver: (String) -> Unit = { data: String ->
try {
context?.let {
try {
val json = JsonManager(requireContext(), data)
json.findJsonObjectByAttribute("ID", serverId)
mainTitle.post {
mainTitle.text = json.getAttributeContentByPath("description/title")
}
mainDescription.post {
this.mainDescription.text = json.getAttributeContentByPath("description/description_s")
}
val imageReceiver: (Bitmap) -> Unit = { bitmap: Bitmap ->
val imageReceiver1: (Bitmap) -> Unit = { bitmap: Bitmap ->
mainImage.post {
mainImage?.let {
mainImage.setImageBitmap(bitmap)
@ -75,30 +84,69 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
val coordinates = json.getAttributeContent("location").split(",")
location = LatLng(coordinates[0].toDouble(), coordinates[1].toDouble())
ServerManagement.serverManager.getImage(imageReceiver, json.getAttributeContent("ID").toInt(), "test0.jpg", 2)
ServerManagement.serverManager.getImage(imageReceiver1, json.getAttributeContent("ID").toInt(), "test0.jpg", 2)
// getting files
json.getAttributeContent("files")
for (n in 0 until json.currentJsonAttribute1!!.length()) {
val fileInfo = JsonManagerLite(json.getAttributeContentByPath("files/$n"), "JSONObject")
val filetype = fileInfo.getAttributeContentByPath("format").split(".")[1]
val filename = fileInfo.getAttributeContentByPath("name")
// handling text
if ("txt json".contains(filetype)) {
val fileView = FileView(filetype, filename, "$serverId|||||$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView()
}
}
// handling images
if ("jpg png".contains(filetype)) {
val fileView = FileView(filetype, filename, null, "$serverId|||||$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView()
}
}
// handling pdf files
if ("pdf".contains(filetype)) {
val fileView = FileView(filetype, filename, null, null, "${ServerManagement.baseUrl}files/$serverId/$filename.$filetype")
if (!FileViewsSupplier.checkIfContains(fileView)) {
FileViewsSupplier.appendFileView(fileView)
updateFileViewsRecyclerView()
}
}
}
} catch (e: Throwable) { println("[debug] exception in infoFragment load data request Exception: $e") }
}
} catch (e: Throwable) { println(e) }
}
val sensorsDataReceiver: (String) -> Unit = {data: String ->
try {
context?.let {
println("[debug][info fragment] $data")
val json = JsonManager(requireContext(), data, "JSONObject")
val names = json.currentJsonObject!!.names()
LabeledValuesSupplier.wipeData()
for (n in 0 until names!!.length()) {
if (names != null) {
for (n in 0 until names.length()) {
val labeledValue = LabeledValue(names[n].toString(), json.getAttributeContent(names[n].toString()))
if (!LabeledValuesSupplier.checkIfContains(labeledValue)) {
LabeledValuesSupplier.appendLabeledValue(labeledValue)
}
}
updateRecyclerView()
}
} catch (e: Throwable) { println(e) }
updateSensorsRecyclerView()
}
} catch (e: Throwable) { println("[debug] Exception in info fragment, load, sensorsDataReceiver : $e") }
}
context?.let {
@ -106,7 +154,6 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
ServerManagement.serverManager.addReceiverConnection(sensorsDataReceiver, requireContext(), "infoFragmentSensorsConnection",
serverId, ServerManagement.sensors_keyword)
}
}
override fun onPause() {
@ -114,8 +161,9 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
super.onPause()
}
private fun updateRecyclerView() {
private fun updateSensorsRecyclerView() {
try {
labeled_values_recycler_view.post {
val layoutManager = LinearLayoutManager(context)
layoutManager.orientation = LinearLayoutManager.VERTICAL
@ -124,6 +172,22 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
val adapter = context?.let { LabeledValuesAdapter(it, LabeledValuesSupplier.labeledValues) }
labeled_values_recycler_view.adapter = adapter
}
} catch (e: Throwable) { println("[debug] e3 that i couldnt fix so try catch Exception: $e") }
}
private fun updateFileViewsRecyclerView() {
try {
file_views_recycler_view.post {
val layoutManager = LinearLayoutManager(context)
layoutManager.orientation = LinearLayoutManager.VERTICAL
file_views_recycler_view.layoutManager = layoutManager
val adapter = context?.let { FileViewsAdapter(it, FileViewsSupplier.fileViews) }
file_views_recycler_view.adapter = adapter
}
} catch (e: Throwable) { println("[debug] e2 that i couldnt fix so try catch Exception: $e") }
}
@ -131,4 +195,8 @@ class infoFragment() : Fragment(R.layout.fragment_info) {
Navigation.findNavController(mainTitle).navigate(R.id.navigateBackToExploreFragment)
}
fun goMapFragment() {
Navigation.findNavController(mainTitle).navigate(R.id.infoFragment_to_mapFragment)
}
}

@ -5,21 +5,29 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.Navigation
import androidx.navigation.fragment.navArgs
import com.example.wikispot.CustomBackstackVariables
import com.example.wikispot.MapManagement
import com.example.wikispot.R
import com.example.wikispot.ServerManagement
import com.example.wikispot.modelsForAdapters.PlaceSupplier
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.OnMapReadyCallback
import com.google.android.gms.maps.SupportMapFragment
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import kotlinx.android.synthetic.main.fragment_map.*
import java.time.Clock
class mapFragment : Fragment() {
class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
val args: mapFragmentArgs by navArgs()
private var loadFromMapManager = true
var location: LatLng? = null
var markerTitle: String? = null
var lastClickedMarkerTitle = ""
private val callback = OnMapReadyCallback { googleMap ->
/**
@ -38,17 +46,22 @@ class mapFragment : Fragment() {
try {
location = args.location
markerTitle = args.markerTitle
loadFromMapManager = false
} catch (e: Throwable) { println("[debug] Exception in Map Fragment while getting args: $e") }
if (loadFromMapManager) {
googleMap.addMarker(MarkerOptions().position(MapManagement.connectedServerPosition!!).title(MapManagement.connectedServerTitle))
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.connectedServerPosition, 16.0F))
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.connectedServerPosition, 15.0F))
} else {
googleMap.addMarker(MarkerOptions().position(location!!).title(markerTitle))
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 16.0F))
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 15.0F))
}
// loading other markers
for (n in PlaceSupplier.places.indices) {
val coordinates = PlaceSupplier.places[n]?.location!!.split(",")
googleMap.addMarker(MarkerOptions().position(LatLng(coordinates[0].toDouble(), coordinates[1].toDouble())).title(PlaceSupplier.places[n]?.title))
}
googleMap.setOnMarkerClickListener(this)
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
@ -60,4 +73,23 @@ class mapFragment : Fragment() {
val mapFragment = childFragmentManager.findFragmentById(R.id.map) as SupportMapFragment?
mapFragment?.getMapAsync(callback)
}
override fun onMarkerClick(marker: Marker?): Boolean {
marker?.let {
if (marker.title == lastClickedMarkerTitle) {
for (n in PlaceSupplier.places.indices) {
if (marker.title == PlaceSupplier.places[n]!!.title) {
CustomBackstackVariables.infoFragmentBackDestination = "mapFragment"
ServerManagement.selectedServerId = PlaceSupplier.places[n]!!.id!!
val action = mapFragmentDirections.mapFragmentToInfoFragment()
Navigation.findNavController(navControllerView).navigate(action)
}
}
}
lastClickedMarkerTitle = marker.title
println("[debug] marker title ${marker.title}")
println(System.currentTimeMillis())
}
return false
}
}

@ -11,8 +11,8 @@ data class JsonManager(private val context: Context, val data: String, val input
var jsonArray: JSONArray? = null
var currentJsonObject: JSONObject? = null
private var currentJsonAttribute0: JSONObject? = null
private var currentJsonAttribute1: JSONArray? = null
var currentJsonAttribute0: JSONObject? = null
var currentJsonAttribute1: JSONArray? = null
init {
if (inputType == "JSONArray") {

@ -1,9 +1,5 @@
package com.example.wikispot.modelClasses
import android.content.Context
import com.example.wikispot.getStringFromSharedPreferences
import com.example.wikispot.saveString
import com.example.wikispot.showToast
import org.json.JSONArray
import org.json.JSONObject
@ -94,7 +90,7 @@ data class JsonManagerLite(val data: String, val inputType: String = "JSONArray"
val currentJsonAttributesBackup = listOf(currentJsonAttribute0, currentJsonAttribute1) // backing up selected jsonAttributes
// getting the attribute
clearSelectedAttribute()
clearSelectedAttributes()
var result: Any? = null
for (step in steps) {
try {
@ -115,7 +111,7 @@ data class JsonManagerLite(val data: String, val inputType: String = "JSONArray"
return result.toString()
}
fun clearSelectedAttribute() {
fun clearSelectedAttributes() {
currentJsonAttribute0 = null
currentJsonAttribute1 = null
}

@ -5,6 +5,8 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.widget.TextView
import com.example.wikispot.ServerManagement
import com.github.barteksc.pdfviewer.PDFView
import kotlinx.android.synthetic.main.file_view.view.*
import okhttp3.*
import org.json.JSONArray
import org.json.JSONObject
@ -101,7 +103,7 @@ class ServerManager {
}
}
fun getImage(imageReceiver: (Bitmap) -> Unit, serverId: Int, path: String, numberOfAttempts: Int) {
fun getImage(imageReceiver: (Bitmap) -> Unit, serverId: Int, path: String, numberOfAttempts: Int = 2) {
val imageRequestThread = Thread(ImageRequest(imageReceiver, serverId, path, numberOfAttempts))
imageRequestThread.start()
}
@ -125,6 +127,22 @@ class ServerManager {
}
}
fun loadPdfView(view: PDFView, url: String) {
val pdfLoadingRequestThread = Thread(PdfLoadingRequest(view, url))
pdfLoadingRequestThread.start()
}
inner class PdfLoadingRequest(val view: PDFView, val url: String): Runnable {
override fun run() {
val inputStream = java.net.URL(url).openStream()
view.post {
view.fromStream(inputStream).load()
view.zoomTo(view.width / 490.0F)
}
}
}
// connections
fun clearConnections() {

@ -11,7 +11,7 @@ import com.example.wikispot.saveString
import com.google.android.gms.maps.model.LatLng
import org.json.JSONArray
data class PlacePreview(var title: String, var description: String, val location: String? = null, var img: Bitmap? = null, val id: Int?=null) {
data class PlacePreview(var title: String, var description: String, var location: String? = null, var img: Bitmap? = null, val id: Int?=null) {
init {
val words = description.split(" ")
@ -38,7 +38,11 @@ object PlaceSupplier {
var controlJson: JsonManagerLite? = null
var places = arrayOf<PlacePreview?>()
var places = arrayOf<PlacePreview?>(
PlacePreview("River", "", "39.94071648123733,-85.9346308193051"),
PlacePreview("Velky Manin", "", "49.12590793522579,18.49571849264312"),
PlacePreview("Klapy", "", "49.161527643132175,18.41231657316252")
)
fun appendPlace(place: PlacePreview) {
val array = places.copyOf(places.size + 1)
@ -123,7 +127,6 @@ object PlaceSupplier {
}
}
}
return false
}

@ -0,0 +1,34 @@
package com.example.wikispot.modelsForAdapters
import android.graphics.Bitmap
data class FileView(val filetype: String, val filename: String, var textInfo: String? = null, var imgInfo: String? = null, var pdfUrl: String? = null)
object FileViewsSupplier {
var fileViews = arrayOf<FileView?>()
fun appendFileView(fileView: FileView) {
val array = fileViews.copyOf(fileViews.size + 1)
array[fileViews.size] = fileView
fileViews = array
}
fun checkIfContains(fileView: FileView): Boolean{
for (n in fileViews.indices) {
if (fileViews[n]!!.filename == fileView.filename) {
if (fileViews[n]!!.filetype == fileView.filetype) {
return true
}
}
}
return false
}
fun wipeData() {
fileViews = arrayOf()
}
}

@ -0,0 +1,20 @@
package com.example.wikispot.modelsForAdapters
data class Message(val author: String, val content: String)
object MessagesSupplier {
var messages = arrayOf<Message?>()
fun appendMessage(message: Message) {
val array = messages.copyOf(messages.size + 1)
array[messages.size] = message
messages = array
}
fun wipeData() {
messages = arrayOf()
}
}

@ -23,7 +23,7 @@ object LabeledValuesSupplier {
}
fun wipeData() {
labeledValues = arrayOf<LabeledValue?>()
labeledValues = arrayOf()
}
}

@ -24,7 +24,7 @@ object ServerManagement {
const val viewConnectionOnCheckWait: Long = 5000
const val dataRequestOnAttemptWait: Long = 2000
const val imageRequestOnAttemptWait: Long = 2000
const val baseUrl = "http://192.168.1.230:8000/"
const val baseUrl = "http://192.168.1.156:8000/"
var selectedServerId = 0
const val sensors_keyword = "_[{(S,e,n,s,o,r,s)}]_"
@ -33,8 +33,7 @@ object ServerManagement {
}
object MapManagement {
var connectedServerPosition: LatLng? = null
var connectedServerTitle: String? = null
var connectedServerPosition: LatLng? = LatLng(0.toDouble(), 0.toDouble())
}
@ -44,6 +43,11 @@ object ScreenParameters {
}
object CustomBackstackVariables {
var infoFragmentBackDestination = "exploreFragment"
}
object ThemeOptions {
var darkTheme = false

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<rotate
android:fromDegrees="-180"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"/>
</set>

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true">
<rotate
android:fromDegrees="0"
android:toDegrees="-180"
android:pivotX="50%"
android:pivotY="50%"
android:duration="600"/>
</set>

@ -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="M7,14l5,-5 5,5H7z"/>
</vector>

@ -0,0 +1,76 @@
<?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">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="4dp">
<TextView
android:id="@+id/filename_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="36dp"
tools:text="Filename"
android:textSize="24sp"
android:textStyle="bold"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/showFileBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="36dp"
android:layout_marginEnd="32dp"
android:scaleX="4"
android:scaleY="4"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
card_view:srcCompat="@drawable/ic_sharp_arrow_drop_up_24" />
<TextView
android:id="@+id/textContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:textSize="0sp"
card_view:layout_constraintBottom_toTopOf="@+id/imageContent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.497"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="@+id/filename_text"
tools:ignore="SmallSp" />
<ImageView
android:id="@+id/imageContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
card_view:layout_constraintBottom_toTopOf="@+id/pdfContent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.5"
card_view:layout_constraintStart_toEndOf="@+id/filename_text"
card_view:layout_constraintStart_toStartOf="parent"
card_view:srcCompat="@drawable/blank" />
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfContent"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_margin="5dp"
android:visibility="gone"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.5"
card_view:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

@ -8,18 +8,15 @@
tools:background="@drawable/chat_fragment_gradient_background"
tools:context=".fragments.chatFragment">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chat Fragment"
android:textStyle="bold"
android:textSize="24sp"
android:textColor="@android:color/white"
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/chat_messages_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="12dp"
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"
tools:text="Chat Fragment" />
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

@ -55,7 +55,7 @@
</ScrollView>
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:id="@+id/pdfContent"
android:layout_width="200dp"
android:layout_height="300dp"
app:layout_constraintBottom_toBottomOf="parent"

@ -14,7 +14,7 @@
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView4"
android:id="@+id/home_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="60dp"

@ -63,6 +63,34 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:background="@drawable/text_background_gradient"
android:padding="4dp"
android:text="@string/files"
android:textAlignment="center"
android:textColor="#FFFFFF"
android:textSize="24sp"
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" />
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/file_views_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

@ -1,8 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
<LinearLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal">
<fragment xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragments.mapFragment" />
<TextView
android:id="@+id/navControllerView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:visibility="gone" />
</LinearLayout>

@ -0,0 +1,44 @@
<?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="2dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp"
android:textAlignment="textStart">
<TextView
android:id="@+id/message_author_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:textSize="20sp"
android:textStyle="bold"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.5"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toTopOf="parent"
tools:text="Author" />
<TextView
android:id="@+id/message_content_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:textAlignment="textStart"
card_view:layout_constraintBottom_toBottomOf="parent"
card_view:layout_constraintEnd_toEndOf="parent"
card_view:layout_constraintHorizontal_bias="0.5"
card_view:layout_constraintStart_toStartOf="parent"
card_view:layout_constraintTop_toBottomOf="@+id/message_author_text"
tools:text="message content" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>

@ -45,9 +45,13 @@
<argument
android:name="location"
app:argType="com.google.android.gms.maps.model.LatLng" />
<action
android:id="@+id/mapFragment_to_infoFragment"
app:destination="@id/infoFragment" >
<argument
android:name="markerTitle"
app:argType="string" />
android:name="loadAutomatically"
android:defaultValue="true" />
</action>
</fragment>
<fragment
android:id="@+id/settingsFragment"

@ -21,4 +21,5 @@
<string name="attachment_summary_on">Automatically download attachments for incoming emails
</string>
<string name="attachment_summary_off">Only download attachments when manually requested</string>
<string name="files">Files</string>
</resources>