Bimba.git

commit e200ec2c2898c340acd1e8aca5452e0dd4acf877

Author: Adam <git@apiote.xyz>

refctoring

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt b/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt
index 9003b635331206b7d7214cd7d2b8146607f47e52..f29db966823fce52669d6fb63f08c1caaff82fe3 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/api/Api.kt
@@ -18,10 +18,19 @@ data class Error(val statusCode: Int, val stringResource: Int, val imageResource: Int)
 
 @Suppress("BlockingMethodInNonBlockingContext")
 suspend fun getFeeds(cm: ConnectivityManager, server: Server): Result {
-	return rawRequest(URL("${hostWithScheme(server.host)}/api/"), server, cm)  // todo(error-handling) if is not a valid URL
+	return rawRequest(
+		URL("${hostWithScheme(server.host)}/api/"),
+		server,
+		cm
+	)  // todo(error-handling) if is not a valid URL
 }
 
-suspend fun queryItems(cm: ConnectivityManager, server: Server, query: String, limit: Int? = null): Result {
+suspend fun queryItems(
+	cm: ConnectivityManager,
+	server: Server,
+	query: String,
+	limit: Int? = null
+): Result {
 	val params = mutableMapOf("q" to query)
 	if (limit != null) {
 		params["limit"] = limit.toString()
@@ -29,11 +38,16 @@ 	}
 	return request(server, "items", params, cm)
 }
 
-suspend fun locateItems(cm:ConnectivityManager, server: Server, plusCode: String): Result {
+suspend fun locateItems(cm: ConnectivityManager, server: Server, plusCode: String): Result {
 	return request(server, "items", mapOf("near" to plusCode), cm)
 }
 
-suspend fun getDepartures(cm: ConnectivityManager, server: Server, stop: String, line: String? = null): Result {
+suspend fun getDepartures(
+	cm: ConnectivityManager,
+	server: Server,
+	stop: String,
+	line: String? = null
+): Result {
 	val params = mutableMapOf("code" to stop)
 	if (line != null) {
 		params["line"] = line




diff --git a/app/src/main/java/ml/adamsprogs/bimba/departures/Departures.kt b/app/src/main/java/ml/adamsprogs/bimba/departures/Departures.kt
index 92f5ea673169e60962325585e9166b0555aaabc8..e58b4da46855d4bc1a66949f2679fab514847144 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/departures/Departures.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/departures/Departures.kt
@@ -92,7 +92,6 @@ 	override fun getItemCount(): Int = departures.size
 
 	fun update(items: List<Departure>) {
 		departures = items
-		Log.v("Departures", departures.toString())
 		notifyDataSetChanged()
 	}
 }




diff --git a/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt
index eb3ce1061c018ec3040fe7d9b95aaab3d109d4af..a87fb47ec4ee057778fd84eecb242155e1c769fd 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/departures/DeparturesActivity.kt
@@ -44,7 +44,7 @@
 		binding.departuresRecycler.layoutManager = LinearLayoutManager(this)
 		adapter = BimbaDeparturesAdapter(layoutInflater, this, listOf()) {
 			Log.v("Departure", "clicked: $it")
-			val modalBottomSheet = ModalBottomSheet(it).apply {
+			ModalBottomSheet(it).apply {
 				show(supportFragmentManager, ModalBottomSheet.TAG)
 			}
 		}




diff --git a/app/src/main/java/ml/adamsprogs/bimba/search/ResultsActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/search/ResultsActivity.kt
index 038e11559ff0acdd6eaa2158c1aa1cee2a818636..2027f08cab67cdd6eea79c994a65250c32aa4720 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/search/ResultsActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/search/ResultsActivity.kt
@@ -19,11 +19,11 @@ import androidx.core.view.WindowCompat
 import androidx.recyclerview.widget.LinearLayoutManager
 import com.google.openlocationcode.OpenLocationCode
 import kotlinx.coroutines.*
-import ml.adamsprogs.bimba.departures.DeparturesActivity
 import kotlinx.coroutines.Runnable
 import ml.adamsprogs.bimba.R
 import ml.adamsprogs.bimba.api.*
 import ml.adamsprogs.bimba.databinding.ActivityResultsBinding
+import ml.adamsprogs.bimba.departures.DeparturesActivity
 import java.io.InputStream
 
 class ResultsActivity : AppCompatActivity(), LocationListener {
@@ -88,10 +88,10 @@ 		}
 	}
 
 	@SuppressLint("MissingPermission")
-	private fun locate() {  // todo also on back to this activity (onRestart?)
+	private fun locate() {
 		val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
 		locationManager.requestLocationUpdates(
-			LocationManager.GPS_PROVIDER, 5000, 10f, this
+			LocationManager.GPS_PROVIDER, 1000 * 60 * 10, 100f, this
 		)
 		handler.removeCallbacks(runnable)
 		runnable = Runnable {
@@ -105,8 +105,6 @@
 	override fun onLocationChanged(location: Location) {
 		handler.removeCallbacks(runnable)
 		val code = OpenLocationCode.encode(location.latitude, location.longitude)
-		val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
-		locationManager.removeUpdates(this)
 		val host = preferences.getString("host", "bimba.apiote.xyz")!!
 		getItemsByLocation(
 			Server(
@@ -116,7 +114,7 @@ 			), code
 		)
 	}
 
-	override fun onDestroy() {  // todo also on hide this activity (onPause?)
+	override fun onDestroy() {
 		super.onDestroy()
 		val locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
 		locationManager.removeUpdates(this)