Fix crash in case of WebDAV misconfigurazion or non reachability, WIP settings screen
This commit is contained in:
parent
238e43509e
commit
8d218fbefe
@ -25,6 +25,10 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:label="@string/settings_title"
|
||||
android:theme="@style/Theme.LunaTracker"/>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -1,5 +1,6 @@
|
||||
package it.danieleverducci.lunatracker
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
@ -85,6 +86,18 @@ class MainActivity : AppCompatActivity() {
|
||||
LunaEventType.DIAPERCHANGE_PEE
|
||||
)
|
||||
) }
|
||||
findViewById<View>(R.id.button_no_connection_settings).setOnClickListener({
|
||||
showSettings()
|
||||
})
|
||||
findViewById<View>(R.id.button_settings).setOnClickListener({
|
||||
showSettings()
|
||||
})
|
||||
}
|
||||
|
||||
fun showSettings() {
|
||||
val i = Intent(this, SettingsActivity::class.java)
|
||||
startActivity(i)
|
||||
|
||||
}
|
||||
|
||||
fun showLogbook() {
|
||||
@ -98,6 +111,9 @@ class MainActivity : AppCompatActivity() {
|
||||
super.onStart()
|
||||
|
||||
// Update list dates
|
||||
adapter.notifyDataSetChanged()
|
||||
|
||||
// Reload data
|
||||
loadLogbook()
|
||||
handler.postDelayed(updateListRunnable, 1000*30)
|
||||
}
|
||||
@ -165,7 +181,9 @@ class MainActivity : AppCompatActivity() {
|
||||
override fun onError(error: String) {
|
||||
runOnUiThread({
|
||||
progressIndicator.visibility = View.INVISIBLE
|
||||
Log.e(TAG, "Unable to load logbook. Create a new one.")
|
||||
findViewById<View>(R.id.no_connection_screen).visibility = View.VISIBLE
|
||||
|
||||
Log.e(TAG, "Unable to load logbook: $error . Created a new one.")
|
||||
logbook = Logbook()
|
||||
showLogbook()
|
||||
})
|
||||
@ -185,6 +203,8 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.d(TAG, "Logbook saved")
|
||||
runOnUiThread({
|
||||
progressIndicator.visibility = View.INVISIBLE
|
||||
|
||||
Toast.makeText(this@MainActivity, R.string.toast_event_added, Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
}
|
||||
|
||||
@ -192,12 +212,14 @@ class MainActivity : AppCompatActivity() {
|
||||
Log.e(TAG, "ERROR: Logbook was NOT saved!")
|
||||
runOnUiThread({
|
||||
progressIndicator.visibility = View.INVISIBLE
|
||||
|
||||
Toast.makeText(this@MainActivity, R.string.toast_event_add_error, Toast.LENGTH_SHORT).show()
|
||||
adapter.items.remove(event)
|
||||
adapter.notifyDataSetChanged()
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Toast.makeText(this, R.string.toast_event_added, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,12 +2,23 @@ package it.danieleverducci.lunatracker
|
||||
|
||||
import android.os.Bundle
|
||||
import android.os.PersistableBundle
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
||||
class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?, persistentState: PersistableBundle?) {
|
||||
super.onCreate(savedInstanceState, persistentState)
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
setContentView(R.layout.activity_settings)
|
||||
|
||||
findViewById<View>(R.id.settings_save).setOnClickListener({
|
||||
Toast.makeText(this, "TODO", Toast.LENGTH_SHORT).show()
|
||||
})
|
||||
findViewById<View>(R.id.settings_cancel).setOnClickListener({
|
||||
finish()
|
||||
})
|
||||
}
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ import it.danieleverducci.lunatracker.entities.LunaEvent
|
||||
import kotlinx.coroutines.Runnable
|
||||
import org.json.JSONArray
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import kotlin.io.bufferedReader
|
||||
|
||||
class WebDAVLogbookRepository(val webDavURL: String, val username: String, val password: String): LogbookRepository {
|
||||
@ -30,6 +31,7 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
|
||||
try {
|
||||
val inputStream = sardine.get("$webDavURL/$FILE_NAME")
|
||||
val json = inputStream.bufferedReader().use(BufferedReader::readText)
|
||||
inputStream.close()
|
||||
val ja = JSONArray(json)
|
||||
val logbook = Logbook()
|
||||
for (i in 0 until ja.length()) {
|
||||
@ -38,7 +40,7 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
|
||||
logbook.logs.add(evt)
|
||||
}
|
||||
listener.onLogbookLoaded(logbook)
|
||||
} catch (e: SardineException) {
|
||||
} catch (e: IOException) {
|
||||
listener.onError(e.toString())
|
||||
}
|
||||
}).start()
|
||||
|
5
app/src/main/res/drawable/ic_connection.xml
Normal file
5
app/src/main/res/drawable/ic_connection.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="960" android:viewportWidth="960" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M198,682Q141,625 110.5,552.5Q80,480 80,400Q80,320 110.5,247.5Q141,175 198,118L246,166Q199,213 173.5,273.5Q148,334 148,400Q148,466 173.5,526.5Q199,587 246,634L198,682ZM290,590Q252,552 232,503Q212,454 212,400Q212,346 232,297Q252,248 290,210L338,258Q309,287 294.5,323.5Q280,360 280,400Q280,440 294.5,476.5Q309,513 338,542L290,590ZM440,840L440,492Q413,480 396.5,455Q380,430 380,400Q380,358 409,329Q438,300 480,300Q522,300 551,329Q580,358 580,400Q580,430 563.5,455Q547,480 520,492L520,840L440,840ZM670,590L622,542Q651,513 665.5,476.5Q680,440 680,400Q680,360 665.5,323.5Q651,287 622,258L670,210Q708,248 728,297Q748,346 748,400Q748,454 728,503Q708,552 670,590ZM762,682L714,634Q761,587 786.5,526.5Q812,466 812,400Q812,334 786.5,273.5Q761,213 714,166L762,118Q819,175 849.5,247.5Q880,320 880,400Q880,480 849.5,552.5Q819,625 762,682Z"/>
|
||||
|
||||
</vector>
|
5
app/src/main/res/drawable/ic_settings.xml
Normal file
5
app/src/main/res/drawable/ic_settings.xml
Normal file
@ -0,0 +1,5 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
|
||||
|
||||
<path android:fillColor="@android:color/white" android:pathData="M19.14,12.94c0.04,-0.3 0.06,-0.61 0.06,-0.94c0,-0.32 -0.02,-0.64 -0.07,-0.94l2.03,-1.58c0.18,-0.14 0.23,-0.41 0.12,-0.61l-1.92,-3.32c-0.12,-0.22 -0.37,-0.29 -0.59,-0.22l-2.39,0.96c-0.5,-0.38 -1.03,-0.7 -1.62,-0.94L14.4,2.81c-0.04,-0.24 -0.24,-0.41 -0.48,-0.41h-3.84c-0.24,0 -0.43,0.17 -0.47,0.41L9.25,5.35C8.66,5.59 8.12,5.92 7.63,6.29L5.24,5.33c-0.22,-0.08 -0.47,0 -0.59,0.22L2.74,8.87C2.62,9.08 2.66,9.34 2.86,9.48l2.03,1.58C4.84,11.36 4.8,11.69 4.8,12s0.02,0.64 0.07,0.94l-2.03,1.58c-0.18,0.14 -0.23,0.41 -0.12,0.61l1.92,3.32c0.12,0.22 0.37,0.29 0.59,0.22l2.39,-0.96c0.5,0.38 1.03,0.7 1.62,0.94l0.36,2.54c0.05,0.24 0.24,0.41 0.48,0.41h3.84c0.24,0 0.44,-0.17 0.47,-0.41l0.36,-2.54c0.59,-0.24 1.13,-0.56 1.62,-0.94l2.39,0.96c0.22,0.08 0.47,0 0.59,-0.22l1.92,-3.32c0.12,-0.22 0.07,-0.47 -0.12,-0.61L19.14,12.94zM12,15.6c-1.98,0 -3.6,-1.62 -3.6,-3.6s1.62,-3.6 3.6,-3.6s3.6,1.62 3.6,3.6S13.98,15.6 12,15.6z"/>
|
||||
|
||||
</vector>
|
@ -1,4 +1,9 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
@ -139,4 +144,57 @@
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="10dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/button_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dp"
|
||||
android:layout_gravity="right"
|
||||
android:src="@drawable/ic_settings"
|
||||
app:tint="@color/grey"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/no_connection_screen"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:background="@color/translucent"
|
||||
android:clickable="true"
|
||||
android:focusableInTouchMode="true"
|
||||
android:focusable="true"
|
||||
android:visibility="gone">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="200dp"
|
||||
android:layout_height="200dp"
|
||||
android:src="@drawable/ic_connection"
|
||||
app:tint="@color/accent"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:textSize="30dp"
|
||||
android:textColor="@color/accent"
|
||||
android:text="@string/no_connection"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/no_connection_explain"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/button_no_connection_settings"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="@string/no_connection_go_to_settings"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</FrameLayout>
|
@ -13,7 +13,8 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/settings_title"
|
||||
android:textSize="28sp"/>
|
||||
android:textSize="28sp"
|
||||
android:textColor="@color/accent"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
@ -101,13 +102,6 @@
|
||||
android:layout_marginTop="20dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/settings_save"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/ok"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/settings_cancel"
|
||||
android:layout_width="0dp"
|
||||
@ -115,6 +109,14 @@
|
||||
android:layout_weight="1"
|
||||
android:text="@android:string/cancel"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/settings_save"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="@color/accent"
|
||||
android:text="@android:string/ok"/>
|
||||
|
||||
</LinearLayout>
|
||||
</RadioGroup>
|
||||
|
||||
|
@ -3,4 +3,6 @@
|
||||
<color name="accent">#FFE68F</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
<color name="translucent">#c000</color>
|
||||
<color name="grey">#ccc</color>
|
||||
</resources>
|
@ -28,7 +28,8 @@
|
||||
<string name="event_diaperchange_pee_desc">Cambio (con pipì)</string>
|
||||
<string name="event_unknown_desc"></string>
|
||||
|
||||
<string name="toast_event_added">Evento aggiunto!</string>
|
||||
<string name="toast_event_added">Evento aggiunto</string>
|
||||
<string name="toast_event_add_error">Impossibile aggiungere l\'evento</string>
|
||||
<string name="toast_integer_error">Valore non valido. Inserire un numero intero.</string>
|
||||
|
||||
<string name="now">adesso</string>
|
||||
@ -37,6 +38,10 @@
|
||||
<string name="minute_ago">min</string>
|
||||
<string name="minutes_ago">min</string>
|
||||
|
||||
<string name="no_connection">Nessuna connessione</string>
|
||||
<string name="no_connection_explain">Impossibile raggiungere il servizio WebDAV</string>
|
||||
<string name="no_connection_go_to_settings">Impostazioni</string>
|
||||
|
||||
<string name="settings_title">Impostazioni</string>
|
||||
<string name="settings_storage">Scegli dove l\'app salva i dati</string>
|
||||
<string name="settings_storage_local">Sul dispositivo</string>
|
||||
|
Loading…
Reference in New Issue
Block a user