some changes

This commit is contained in:
Tucan444 2021-04-14 14:49:43 +02:00
parent c41a2c81e9
commit 2045cb4425
8 changed files with 32 additions and 10 deletions

@ -265,7 +265,7 @@ class MainActivity : AppCompatActivity() {
place.img = bitmap 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) PlaceSupplier.appendPlace(place)
} else { } else {
@ -275,7 +275,7 @@ class MainActivity : AppCompatActivity() {
containingPlace?.img = bitmap 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 // checking if location wasn't changed

@ -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) } } catch (e: Throwable) { println(e) }

@ -65,13 +65,17 @@ class infoFragment : Fragment(R.layout.fragment_info) {
val json = JsonManager(requireContext(), data) val json = JsonManager(requireContext(), data)
json.findJsonObjectByAttribute("ID", serverId) json.findJsonObjectByAttribute("ID", serverId)
mainImage?.let {
mainTitle.post { mainTitle.post {
mainTitle.text = json.getAttributeContentByPath("description/title") mainTitle.text = json.getAttributeContentByPath("description/title")
} }
}
mainDescription?.let {
mainDescription.post { mainDescription.post {
this.mainDescription.text = json.getAttributeContentByPath("description/description_s") this.mainDescription.text = json.getAttributeContentByPath("description/description_s")
} }
}
val imageReceiver1: (Bitmap) -> Unit = { bitmap: Bitmap -> val imageReceiver1: (Bitmap) -> Unit = { bitmap: Bitmap ->
mainImage.post { mainImage.post {
@ -84,7 +88,8 @@ class infoFragment : Fragment(R.layout.fragment_info) {
val coordinates = json.getAttributeContent("location").split(",") val coordinates = json.getAttributeContent("location").split(",")
location = LatLng(coordinates[0].toDouble(), coordinates[1].toDouble()) 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 // getting files
@ -196,7 +201,8 @@ class infoFragment : Fragment(R.layout.fragment_info) {
} }
fun goMapFragment() { 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)
} }
} }

@ -26,6 +26,7 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
val args: mapFragmentArgs by navArgs() val args: mapFragmentArgs by navArgs()
private var loadFromMapManager = true private var loadFromMapManager = true
private var loadLastCoordinates = false
var location: LatLng? = null var location: LatLng? = null
var lastClickedMarkerTitle = "" var lastClickedMarkerTitle = ""
@ -46,11 +47,14 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
try { try {
location = args.location location = args.location
loadLastCoordinates = args.loadLastCoordinates
loadFromMapManager = false loadFromMapManager = false
} catch (e: Throwable) { println("[debug] Exception in Map Fragment while getting args: $e") } } catch (e: Throwable) { println("[debug] Exception in Map Fragment while getting args: $e") }
if (loadFromMapManager) { if (loadFromMapManager) {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.connectedServerPosition, 15.0F)) googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.connectedServerPosition, 15.0F))
} else if (loadLastCoordinates){
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(MapManagement.lastCoordinates, 15F))
} else { } else {
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 15.0F)) googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(location, 15.0F))
} }
@ -80,6 +84,7 @@ class mapFragment : Fragment(), GoogleMap.OnMarkerClickListener {
for (n in PlaceSupplier.places.indices) { for (n in PlaceSupplier.places.indices) {
if (marker.title == PlaceSupplier.places[n]!!.title) { if (marker.title == PlaceSupplier.places[n]!!.title) {
CustomBackstackVariables.infoFragmentBackDestination = "mapFragment" CustomBackstackVariables.infoFragmentBackDestination = "mapFragment"
MapManagement.lastCoordinates = marker.position
ServerManagement.selectedServerId = PlaceSupplier.places[n]!!.id!! ServerManagement.selectedServerId = PlaceSupplier.places[n]!!.id!!
val action = mapFragmentDirections.mapFragmentToInfoFragment() val action = mapFragmentDirections.mapFragmentToInfoFragment()
Navigation.findNavController(navControllerView).navigate(action) Navigation.findNavController(navControllerView).navigate(action)

@ -118,6 +118,7 @@ class ServerManager {
val bitmap = BitmapFactory.decodeStream(inputStream) val bitmap = BitmapFactory.decodeStream(inputStream)
imageReceiver(bitmap) imageReceiver(bitmap)
break
} catch (e: Throwable) { println(e) } } catch (e: Throwable) { println(e) }
ServerManagement.totalNumberOfRequestsSent += 1 ServerManagement.totalNumberOfRequestsSent += 1

@ -10,6 +10,8 @@ import com.example.wikispot.modelClasses.JsonManagerLite
import com.example.wikispot.saveString import com.example.wikispot.saveString
import com.google.android.gms.maps.model.LatLng import com.google.android.gms.maps.model.LatLng
import org.json.JSONArray 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) { 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) { fun saveToCache(context: Context) {
val save = JSONArray() val save = JSONArray()
var i = 0
for (n in places.indices) { for (n in places.indices) {
val place = places[n] val place = places[n]
if (getSavePermission(place)) { 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++
} }
} }

@ -34,6 +34,7 @@ object ServerManagement {
object MapManagement { object MapManagement {
var connectedServerPosition: LatLng? = LatLng(0.toDouble(), 0.toDouble()) var connectedServerPosition: LatLng? = LatLng(0.toDouble(), 0.toDouble())
var lastCoordinates = LatLng(0.toDouble(), 0.toDouble())
} }

@ -52,6 +52,10 @@
android:name="loadAutomatically" android:name="loadAutomatically"
android:defaultValue="true" /> android:defaultValue="true" />
</action> </action>
<argument
android:name="loadLastCoordinates"
app:argType="boolean"
android:defaultValue="false" />
</fragment> </fragment>
<fragment <fragment
android:id="@+id/settingsFragment" android:id="@+id/settingsFragment"