cleaning up map fragment and cache download

pull/489/head
PWRxPSYCHO 2022-10-02 21:50:01 -04:00
rodzic a537335f8c
commit 93664a9bb9
2 zmienionych plików z 44 dodań i 70 usunięć

Wyświetl plik

@ -7,7 +7,6 @@ import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.graphics.Rect
import android.opengl.Visibility
import android.os.Bundle
import android.text.Editable
import android.text.TextWatcher
@ -65,7 +64,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
private lateinit var cacheSouth: EditText
private lateinit var cacheEast: EditText
private lateinit var cacheWest: EditText
private lateinit var cacheOutput: EditText
private lateinit var cacheEstimate: TextView
@ -230,7 +228,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
cacheSouth.setText(boundingBox.latSouth.toString() + "")
cacheWest = view.findViewById(R.id.cache_west)
cacheWest.setText(boundingBox.lonWest.toString() + "")
cacheOutput = view.findViewById(R.id.cache_output)
cacheEstimate = view.findViewById(R.id.cache_estimate)
//change listeners for both validation and to trigger the download estimation
@ -248,7 +245,6 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
cacheWest.text = null
zoomMin.progress = 0
zoomMax.progress = 0
cacheOutput.text = null;
}
builder.setView(view)
builder.setCancelable(true)
@ -262,7 +258,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
*/
private fun updateEstimate(startJob: Boolean) {
try {
if (cacheWest.text != null && cacheNorth.text != null && cacheSouth.text != null && cacheOutput.text != null && ::zoomMax.isInitialized && ::zoomMin.isInitialized) {
if (cacheWest.text != null && cacheNorth.text != null && cacheSouth.text != null && ::zoomMax.isInitialized && ::zoomMin.isInitialized) {
val n: Double = cacheNorth.text.toString().toDouble()
val s: Double = cacheSouth.text.toString().toDouble()
val e: Double = cacheEast.text.toString().toDouble()
@ -305,44 +301,7 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
return
}
//this triggers the download
cacheManager.downloadAreaAsync(
activity,
bb,
zoommin,
zoommax,
object : CacheManagerCallback {
override fun onTaskComplete() {
Toast.makeText(activity, "Download complete!", Toast.LENGTH_LONG)
.show()
writer.onDetach()
}
override fun onTaskFailed(errors: Int) {
Toast.makeText(
activity,
"Download complete with $errors errors",
Toast.LENGTH_LONG
).show()
writer.onDetach()
}
override fun updateProgress(
progress: Int,
currentZoomLevel: Int,
zoomMin: Int,
zoomMax: Int
) {
//NOOP since we are using the build in UI
}
override fun downloadStarted() {
//NOOP since we are using the build in UI
}
override fun setPossibleTilesInArea(total: Int) {
//NOOP since we are using the build in UI
}
})
downloadRegion(bb, zoommin, zoommax)
}
}
} catch (ex: Exception) {
@ -350,6 +309,47 @@ class MapFragment : ScreenFragment("Map"), Logging, View.OnClickListener, OnSeek
}
}
private fun downloadRegion(bb: BoundingBox, zoommin: Int, zoommax: Int) {
cacheManager.downloadAreaAsync(
activity,
bb,
zoommin,
zoommax,
object : CacheManagerCallback {
override fun onTaskComplete() {
Toast.makeText(activity, "Download complete!", Toast.LENGTH_LONG)
.show()
writer.onDetach()
}
override fun onTaskFailed(errors: Int) {
Toast.makeText(
activity,
"Download complete with $errors errors",
Toast.LENGTH_LONG
).show()
writer.onDetach()
}
override fun updateProgress(
progress: Int,
currentZoomLevel: Int,
zoomMin: Int,
zoomMax: Int
) {
//NOOP since we are using the build in UI
}
override fun downloadStarted() {
//NOOP since we are using the build in UI
}
override fun setPossibleTilesInArea(total: Int) {
//NOOP since we are using the build in UI
}
})
}
private fun chooseMapStyle() {
/// Prepare dialog and its items
val builder = MaterialAlertDialogBuilder(context!!)

Wyświetl plik

@ -104,38 +104,12 @@
android:layout_height="wrap_content"
/>
<LinearLayout
android:id="@+id/cache_archival_section"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Archive File name:"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="@+id/cache_output"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="archive.sqlite"
android:lines="1"
android:text="archive.sqlite"
/>
</LinearLayout>
<Button
android:id="@+id/executeJob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start Download" />
/>
</LinearLayout>
</ScrollView>