Skip to content
Snippets Groups Projects
Verified Commit 76bf32e9 authored by Ruben van Dijk's avatar Ruben van Dijk
Browse files

swimmer ID field.

parent ccaf26c1
Branches
No related tags found
No related merge requests found
Pipeline #2084 passed
......@@ -75,6 +75,13 @@ class MainActivity : Activity() {
apply()
}
}
binding.swimmer.setText(storage.getString("swimmer",""))
binding.saveSwimmer.setOnClickListener {
with (storage.edit()) {
putString("swimmer", binding.swimmer.text.toString())
apply()
}
}
}
}
\ No newline at end of file
......@@ -14,23 +14,27 @@ import java.util.*
abstract class DataProvider {
protected abstract fun getData(json: String): Map<String, Any>
protected abstract val url: String
fun getResponse(http: CustomHttp, storage: SharedPreferences): Map<String, Any> = try {
if(storage.getBoolean("offline", false)) throw Exception("forced offline!")
val response: MutableMap<String, Any> = mutableMapOf("Last downloaded: "+ DateFormat.getDateTimeInstance().format(Date()) to listOf<String>())
val httpResponse = http.get(url).only200().text()
println("httpResponse: $httpResponse")
val data = getData(httpResponse)
println("data: $data")
response.putAll(data)
with(storage.edit()) {
putString(url, Gson().toJson(response))
apply()
fun getResponse(http: CustomHttp, storage: SharedPreferences): Map<String, Any> {
val swimmer=storage.getString("swimmer","")
val swimmerUrl="$url/$swimmer"
return try {
if(storage.getBoolean("offline", false)) throw Exception("forced offline!")
val response: MutableMap<String, Any> = mutableMapOf("Last downloaded: "+ DateFormat.getDateTimeInstance().format(Date()) to listOf<String>())
val httpResponse = http.get(swimmerUrl).only200().text()
println("httpResponse: $httpResponse")
val data = getData(httpResponse)
println("data: $data")
response.putAll(data)
with(storage.edit()) {
putString(swimmerUrl, Gson().toJson(response))
apply()
}
response
} catch (exception: Exception) {
exception.printStackTrace()
println(exception)
val type: Type = object : TypeToken<Map<String, Any>>() {}.type
Gson().fromJson(storage.getString(swimmerUrl, "{\"no data!\": []}"), type)
}
response
} catch (exception: Exception) {
exception.printStackTrace()
println(exception)
val type: Type = object : TypeToken<Map<String, Any>>() {}.type
Gson().fromJson(storage.getString(url, "{\"no data!\": []}"), type)
}
}
\ No newline at end of file
......@@ -7,17 +7,46 @@
tools:context=".MainActivity">
<Switch
android:id="@+id/offline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offline" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="40dp"
android:layout_height="40dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:orientation="horizontal">
<Switch
android:id="@+id/offline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Offline" />
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="40dp"
android:layout_height="40dp"
android:visibility="gone" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Swimtimes ID:" />
<EditText
android:id="@+id/swimmer"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="testtest" />
<Button
android:id="@+id/saveSwimmer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Opslaan" />
</LinearLayout>
</LinearLayout>
<ListView
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment