From 2045cb4425566ada017d12acf7e651fecabaa23a Mon Sep 17 00:00:00 2001
From: Tucan444 <66880425+Tucan444@users.noreply.github.com>
Date: Wed, 14 Apr 2021 14:49:43 +0200
Subject: [PATCH] some changes
---
.../wikispot/activities/MainActivity.kt | 4 ++--
.../example/wikispot/fragments/homeFragment.kt | 3 ++-
.../example/wikispot/fragments/infoFragment.kt | 18 ++++++++++++------
.../example/wikispot/fragments/mapFragment.kt | 5 +++++
.../wikispot/modelClasses/ServerManager.kt | 1 +
.../modelsForAdapters/ExploreListModel.kt | 6 +++++-
.../example/wikispot/projectScopeVariables.kt | 1 +
.../navigation/main_activity_navigation.xml | 4 ++++
8 files changed, 32 insertions(+), 10 deletions(-)
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt
index e80b76f..1062422 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/activities/MainActivity.kt
@@ -265,7 +265,7 @@ class MainActivity : AppCompatActivity() {
place.img = bitmap
}
- ServerManagement.serverManager.getImage(imageReceiver, id, "test.png", 3)
+ ServerManagement.serverManager.getImage(imageReceiver, id, json.getAttributeContentByPath("description/photo_s"), 3)
PlaceSupplier.appendPlace(place)
} else {
@@ -275,7 +275,7 @@ class MainActivity : AppCompatActivity() {
containingPlace?.img = bitmap
}
- ServerManagement.serverManager.getImage(imageReceiver, id, "test.png", 3)
+ ServerManagement.serverManager.getImage(imageReceiver, id, json.getAttributeContentByPath("description/photo_s"), 3)
}
// checking if location wasn't changed
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/homeFragment.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/homeFragment.kt
index 695c825..46627cc 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/homeFragment.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/homeFragment.kt
@@ -49,7 +49,8 @@ class homeFragment : Fragment(R.layout.fragment_home) {
}
}
- ServerManagement.serverManager.getImage(imageReceiver, json.getAttributeContent("ID").toInt(), "test0.jpg", 3)
+ ServerManagement.serverManager.getImage(imageReceiver, json.getAttributeContent("ID").toInt(),
+ json.getAttributeContentByPath("description/photo_b"), 3)
}
} catch (e: Throwable) { println(e) }
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/infoFragment.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/infoFragment.kt
index 574c6ae..3385ad7 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/infoFragment.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/infoFragment.kt
@@ -65,12 +65,16 @@ class infoFragment : Fragment(R.layout.fragment_info) {
val json = JsonManager(requireContext(), data)
json.findJsonObjectByAttribute("ID", serverId)
- mainTitle.post {
- mainTitle.text = json.getAttributeContentByPath("description/title")
+ mainImage?.let {
+ mainTitle.post {
+ mainTitle.text = json.getAttributeContentByPath("description/title")
+ }
}
- mainDescription.post {
- this.mainDescription.text = json.getAttributeContentByPath("description/description_s")
+ mainDescription?.let {
+ mainDescription.post {
+ this.mainDescription.text = json.getAttributeContentByPath("description/description_s")
+ }
}
val imageReceiver1: (Bitmap) -> Unit = { bitmap: Bitmap ->
@@ -84,7 +88,8 @@ class infoFragment : Fragment(R.layout.fragment_info) {
val coordinates = json.getAttributeContent("location").split(",")
location = LatLng(coordinates[0].toDouble(), coordinates[1].toDouble())
- ServerManagement.serverManager.getImage(imageReceiver1, json.getAttributeContent("ID").toInt(), "test0.jpg", 2)
+ ServerManagement.serverManager.getImage(imageReceiver1, json.getAttributeContent("ID").toInt(),
+ json.getAttributeContentByPath("description/photo_b"), 2)
// getting files
@@ -196,7 +201,8 @@ class infoFragment : Fragment(R.layout.fragment_info) {
}
fun goMapFragment() {
- Navigation.findNavController(mainTitle).navigate(R.id.infoFragment_to_mapFragment)
+ val action = infoFragmentDirections.infoFragmentToMapFragment(LatLng(0.toDouble(), 0.toDouble()), true)
+ Navigation.findNavController(mainTitle).navigate(action)
}
}
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/mapFragment.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/mapFragment.kt
index 9e6c5b4..618e998 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/mapFragment.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/fragments/mapFragment.kt
@@ -26,6 +26,7 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
val args: mapFragmentArgs by navArgs()
private var loadFromMapManager = true
+ private var loadLastCoordinates = false
var location: LatLng? = null
var lastClickedMarkerTitle = ""
@@ -46,11 +47,14 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
try {
location = args.location
+ loadLastCoordinates = args.loadLastCoordinates
loadFromMapManager = false
} catch (e: Throwable) { println("[debug] Exception in Map Fragment while getting args: $e") }
if (loadFromMapManager) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.connectedServerPosition, 15.0F))
+ } else if (loadLastCoordinates){
+ googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.lastCoordinates, 15F))
} else {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 15.0F))
}
@@ -80,6 +84,7 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
for (n in PlaceSupplier.places.indices) {
if (marker.title == PlaceSupplier.places[n]!!.title) {
CustomBackstackVariables.infoFragmentBackDestination = "mapFragment"
+ MapManagement.lastCoordinates = marker.position
ServerManagement.selectedServerId = PlaceSupplier.places[n]!!.id!!
val action = mapFragmentDirections.mapFragmentToInfoFragment()
Navigation.findNavController(navControllerView).navigate(action)
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt
index 362bfcb..7b2ed5b 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelClasses/ServerManager.kt
@@ -118,6 +118,7 @@ class ServerManager {
val bitmap = BitmapFactory.decodeStream(inputStream)
imageReceiver(bitmap)
+ break
} catch (e: Throwable) { println(e) }
ServerManagement.totalNumberOfRequestsSent += 1
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelsForAdapters/ExploreListModel.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelsForAdapters/ExploreListModel.kt
index a571ce9..28f7994 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/modelsForAdapters/ExploreListModel.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/modelsForAdapters/ExploreListModel.kt
@@ -10,6 +10,8 @@ import com.example.wikispot.modelClasses.JsonManagerLite
import com.example.wikispot.saveString
import com.google.android.gms.maps.model.LatLng
import org.json.JSONArray
+import java.lang.IndexOutOfBoundsException
+import java.lang.NullPointerException
data class PlacePreview(var title: String, var description: String, var location: String? = null, var img: Bitmap? = null, val id: Int?=null) {
@@ -96,10 +98,12 @@ object PlaceSupplier {
fun saveToCache(context: Context) {
val save = JSONArray()
+ var i = 0
for (n in places.indices) {
val place = places[n]
if (getSavePermission(place)) {
- save.put(n, "${place!!.title}|||||${place.description}|||||${place.location}|||||${place.id}")
+ save.put(i, "${place!!.title}|||||${place.description}|||||${place.location}|||||${place.id}")
+ i++
}
}
diff --git a/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt b/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt
index 4666e55..a861fda 100644
--- a/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt
+++ b/app/WikiSpot/app/src/main/java/com/example/wikispot/projectScopeVariables.kt
@@ -34,6 +34,7 @@ object ServerManagement {
object MapManagement {
var connectedServerPosition: LatLng? = LatLng(0.toDouble(), 0.toDouble())
+ var lastCoordinates = LatLng(0.toDouble(), 0.toDouble())
}
diff --git a/app/WikiSpot/app/src/main/res/navigation/main_activity_navigation.xml b/app/WikiSpot/app/src/main/res/navigation/main_activity_navigation.xml
index 1a3a002..d6baa81 100644
--- a/app/WikiSpot/app/src/main/res/navigation/main_activity_navigation.xml
+++ b/app/WikiSpot/app/src/main/res/navigation/main_activity_navigation.xml
@@ -52,6 +52,10 @@
android:name="loadAutomatically"
android:defaultValue="true" />
+