Compare commits
No commits in common. "master" and "multiple-children" have entirely different histories.
master
...
multiple-c
@ -12,8 +12,8 @@ android {
|
|||||||
applicationId = "it.danieleverducci.lunatracker"
|
applicationId = "it.danieleverducci.lunatracker"
|
||||||
minSdk = 21
|
minSdk = 21
|
||||||
targetSdk = 34
|
targetSdk = 34
|
||||||
versionCode = 3
|
versionCode = 2
|
||||||
versionName = "0.5"
|
versionName = "0.3"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package it.danieleverducci.lunatracker
|
package it.danieleverducci.lunatracker
|
||||||
|
|
||||||
import android.content.DialogInterface
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
@ -49,7 +48,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
|
val DEBUG_CHECK_LOGBOOK_CONSISTENCY = false
|
||||||
}
|
}
|
||||||
|
|
||||||
var logbook: Logbook? = null
|
lateinit var logbook: Logbook
|
||||||
lateinit var adapter: LunaEventRecyclerAdapter
|
lateinit var adapter: LunaEventRecyclerAdapter
|
||||||
lateinit var progressIndicator: LinearProgressIndicator
|
lateinit var progressIndicator: LinearProgressIndicator
|
||||||
lateinit var buttonsContainer: ViewGroup
|
lateinit var buttonsContainer: ViewGroup
|
||||||
@ -57,8 +56,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
lateinit var handler: Handler
|
lateinit var handler: Handler
|
||||||
var savingEvent = false
|
var savingEvent = false
|
||||||
val updateListRunnable: Runnable = Runnable {
|
val updateListRunnable: Runnable = Runnable {
|
||||||
if (logbook != null)
|
loadLogbook(logbook.name)
|
||||||
loadLogbook(logbook!!.name)
|
|
||||||
handler.postDelayed(updateListRunnable, 1000*60)
|
handler.postDelayed(updateListRunnable, 1000*60)
|
||||||
}
|
}
|
||||||
var logbookRepo: LogbookRepository? = null
|
var logbookRepo: LogbookRepository? = null
|
||||||
@ -124,11 +122,10 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showSettings()
|
showSettings()
|
||||||
})
|
})
|
||||||
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
|
findViewById<View>(R.id.button_no_connection_retry).setOnClickListener({
|
||||||
// This may happen at start, when logbook is still null: better ask the logbook list
|
loadLogbook(logbook.name)
|
||||||
loadLogbookList()
|
|
||||||
})
|
})
|
||||||
findViewById<View>(R.id.button_sync).setOnClickListener({
|
findViewById<View>(R.id.button_sync).setOnClickListener({
|
||||||
loadLogbookList()
|
loadLogbook(logbook.name)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,11 +136,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun showLogbook() {
|
fun showLogbook() {
|
||||||
// Show logbook
|
// Show logbook
|
||||||
if (logbook == null)
|
|
||||||
Log.w(TAG, "showLogbook(): logbook is null!")
|
|
||||||
|
|
||||||
adapter.items.clear()
|
adapter.items.clear()
|
||||||
adapter.items.addAll(logbook?.logs ?: listOf())
|
adapter.items.addAll(logbook.logs)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,13 +162,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
// Update list dates
|
// Update list dates
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
|
||||||
if (logbook != null) {
|
// Reload data
|
||||||
// Already running: reload data for currently selected logbook
|
loadLogbookList()
|
||||||
loadLogbook(logbook!!.name)
|
|
||||||
} else {
|
|
||||||
// First start: load logbook list
|
|
||||||
loadLogbookList()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
@ -294,7 +283,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
d.setPositiveButton(R.string.trim_logbook_dialog_button_ok) { dialogInterface, i ->
|
d.setPositiveButton(R.string.trim_logbook_dialog_button_ok) { dialogInterface, i ->
|
||||||
logbook?.trim()
|
logbook.trim()
|
||||||
saveLogbook()
|
saveLogbook()
|
||||||
}
|
}
|
||||||
d.setNegativeButton(R.string.trim_logbook_dialog_button_cancel) { dialogInterface, i ->
|
d.setNegativeButton(R.string.trim_logbook_dialog_button_cancel) { dialogInterface, i ->
|
||||||
@ -318,10 +307,8 @@ class MainActivity : AppCompatActivity() {
|
|||||||
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).setText(event.notes)
|
dialogView.findViewById<TextView>(R.id.dialog_event_detail_type_notes).setText(event.notes)
|
||||||
d.setView(dialogView)
|
d.setView(dialogView)
|
||||||
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> dialogInterface.dismiss() }
|
d.setPositiveButton(android.R.string.ok) { dialogInterface, i -> dialogInterface.dismiss() }
|
||||||
d.setNeutralButton(R.string.dialog_event_detail_delete_button) { dialogInterface, i -> deleteEvent(event) }
|
|
||||||
val alertDialog = d.create()
|
val alertDialog = d.create()
|
||||||
alertDialog.show()
|
alertDialog.show()
|
||||||
alertDialog.getButton(DialogInterface.BUTTON_NEUTRAL).setTextColor(ContextCompat.getColor(this, R.color.danger))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun showAddLogbookDialog(requestedByUser: Boolean) {
|
fun showAddLogbookDialog(requestedByUser: Boolean) {
|
||||||
@ -385,35 +372,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onIOError(error: IOException) {
|
override fun onIOError(error: IOException) {
|
||||||
Log.e(TAG, "Unable to load logbooks list (IOError): $error")
|
TODO("Not yet implemented")
|
||||||
runOnUiThread({
|
|
||||||
setLoading(false)
|
|
||||||
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWebDAVError(error: SardineException) {
|
override fun onWebDAVError(error: SardineException) {
|
||||||
Log.e(TAG, "Unable to load logbooks list (SardineException): $error")
|
TODO("Not yet implemented")
|
||||||
runOnUiThread({
|
|
||||||
setLoading(false)
|
|
||||||
onRepoError(
|
|
||||||
if(error.toString().contains("401")) {
|
|
||||||
getString(R.string.settings_webdav_error_denied)
|
|
||||||
} else if(error.toString().contains("503")) {
|
|
||||||
getString(R.string.settings_webdav_error_server_offline)
|
|
||||||
} else {
|
|
||||||
getString(R.string.settings_webdav_error_generic) + error.toString()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(error: Exception) {
|
override fun onError(error: Exception) {
|
||||||
Log.e(TAG, "Unable to load logbooks list: $error")
|
TODO("Not yet implemented")
|
||||||
runOnUiThread({
|
|
||||||
setLoading(false)
|
|
||||||
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -442,8 +409,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
onRepoError(
|
onRepoError(
|
||||||
if(error.toString().contains("401")) {
|
if(error.toString().contains("401")) {
|
||||||
getString(R.string.settings_webdav_error_denied)
|
getString(R.string.settings_webdav_error_denied)
|
||||||
} else if(error.toString().contains("503")) {
|
|
||||||
getString(R.string.settings_webdav_error_server_offline)
|
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.settings_webdav_error_generic) + error.toString()
|
getString(R.string.settings_webdav_error_generic) + error.toString()
|
||||||
}
|
}
|
||||||
@ -484,7 +449,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showLogbook()
|
showLogbook()
|
||||||
|
|
||||||
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
||||||
for (e in logbook?.logs ?: listOf()) {
|
for (e in logbook.logs) {
|
||||||
val em = e.getTypeEmoji(this@MainActivity)
|
val em = e.getTypeEmoji(this@MainActivity)
|
||||||
if (em == getString(R.string.event_unknown_type)) {
|
if (em == getString(R.string.event_unknown_type)) {
|
||||||
Log.e(TAG, "UNKNOWN: ${e.type}")
|
Log.e(TAG, "UNKNOWN: ${e.type}")
|
||||||
@ -507,8 +472,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
onRepoError(
|
onRepoError(
|
||||||
if(error.toString().contains("401")) {
|
if(error.toString().contains("401")) {
|
||||||
getString(R.string.settings_webdav_error_denied)
|
getString(R.string.settings_webdav_error_denied)
|
||||||
} else if(error.toString().contains("503")) {
|
|
||||||
getString(R.string.settings_webdav_error_server_offline)
|
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.settings_webdav_error_generic) + error.toString()
|
getString(R.string.settings_webdav_error_generic) + error.toString()
|
||||||
}
|
}
|
||||||
@ -548,37 +511,21 @@ class MainActivity : AppCompatActivity() {
|
|||||||
recyclerView.smoothScrollToPosition(0)
|
recyclerView.smoothScrollToPosition(0)
|
||||||
|
|
||||||
setLoading(true)
|
setLoading(true)
|
||||||
logbook?.logs?.add(0, event)
|
logbook.logs.add(0, event)
|
||||||
saveLogbook(event)
|
saveLogbook(event)
|
||||||
|
|
||||||
// Check logbook size to avoid OOM errors
|
// Check logbook size to avoid OOM errors
|
||||||
if (logbook?.isTooBig() == true) {
|
if (logbook.isTooBig()) {
|
||||||
askToTrimLogbook()
|
askToTrimLogbook()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun deleteEvent(event: LunaEvent) {
|
|
||||||
// Update view
|
|
||||||
savingEvent(true)
|
|
||||||
adapter.items.remove(event)
|
|
||||||
adapter.notifyDataSetChanged()
|
|
||||||
|
|
||||||
// Update data
|
|
||||||
setLoading(true)
|
|
||||||
logbook?.logs?.remove(event)
|
|
||||||
saveLogbook()
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the logbook. If saving while adding an event, please specify the event so in case
|
* Saves the logbook. If saving while adding an event, please specify the event so in case
|
||||||
* of error can be removed from the list.
|
* of error can be removed from the list.
|
||||||
*/
|
*/
|
||||||
fun saveLogbook(lastEventAdded: LunaEvent? = null) {
|
fun saveLogbook(lastEventAdded: LunaEvent? = null) {
|
||||||
if (logbook == null) {
|
logbookRepo?.saveLogbook(this, logbook, object: LogbookSavedListener{
|
||||||
Log.e(TAG, "Trying to save logbook, but logbook is null!")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
logbookRepo?.saveLogbook(this, logbook!!, object: LogbookSavedListener{
|
|
||||||
override fun onLogbookSaved() {
|
override fun onLogbookSaved() {
|
||||||
Log.d(TAG, "Logbook saved")
|
Log.d(TAG, "Logbook saved")
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
@ -611,8 +558,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
onRepoError(
|
onRepoError(
|
||||||
if(error.toString().contains("401")) {
|
if(error.toString().contains("401")) {
|
||||||
getString(R.string.settings_webdav_error_denied)
|
getString(R.string.settings_webdav_error_denied)
|
||||||
} else if(error.toString().contains("503")) {
|
|
||||||
getString(R.string.settings_webdav_error_server_offline)
|
|
||||||
} else {
|
} else {
|
||||||
getString(R.string.settings_webdav_error_generic) + error.toString()
|
getString(R.string.settings_webdav_error_generic) + error.toString()
|
||||||
}
|
}
|
||||||
|
@ -103,32 +103,19 @@ class WebDAVLogbookRepository(val webDavURL: String, val username: String, val p
|
|||||||
listener: LogbookListObtainedListener
|
listener: LogbookListObtainedListener
|
||||||
) {
|
) {
|
||||||
Thread(Runnable {
|
Thread(Runnable {
|
||||||
try {
|
val logbooksNames = arrayListOf<String>()
|
||||||
val logbooksNames = arrayListOf<String>()
|
for (dr: DavResource in sardine.list(webDavURL)){
|
||||||
for (dr: DavResource in sardine.list(webDavURL)){
|
if(!dr.name.startsWith(FILE_NAME_START))
|
||||||
if(!dr.name.startsWith(FILE_NAME_START))
|
continue
|
||||||
continue
|
if(!dr.name.endsWith(FILE_NAME_END))
|
||||||
if(!dr.name.endsWith(FILE_NAME_END))
|
continue
|
||||||
continue
|
logbooksNames.add(
|
||||||
logbooksNames.add(
|
dr.name.replace("${FILE_NAME_START}_", "")
|
||||||
dr.name.replace("${FILE_NAME_START}_", "")
|
.replace(FILE_NAME_START, "")
|
||||||
.replace(FILE_NAME_START, "")
|
.replace(FILE_NAME_END, "")
|
||||||
.replace(FILE_NAME_END, "")
|
)
|
||||||
)
|
|
||||||
}
|
|
||||||
listener.onLogbookListObtained(logbooksNames)
|
|
||||||
} catch (e: SardineException) {
|
|
||||||
Log.e(TAG, e.toString())
|
|
||||||
listener.onWebDAVError(e)
|
|
||||||
} catch (e: IOException) {
|
|
||||||
Log.e(TAG, e.toString())
|
|
||||||
listener.onIOError(e)
|
|
||||||
} catch (e: SocketTimeoutException) {
|
|
||||||
Log.e(TAG, e.toString())
|
|
||||||
listener.onIOError(e)
|
|
||||||
} catch (e: Exception) {
|
|
||||||
listener.onError(e)
|
|
||||||
}
|
}
|
||||||
|
listener.onLogbookListObtained(logbooksNames)
|
||||||
}).start()
|
}).start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,6 @@
|
|||||||
<string name="settings_storage_dav_pass">Password</string>
|
<string name="settings_storage_dav_pass">Password</string>
|
||||||
<string name="settings_network_error">Impossibile raggiungere il server: </string>
|
<string name="settings_network_error">Impossibile raggiungere il server: </string>
|
||||||
<string name="settings_webdav_error_denied">Nome utente o password WebDAV sbagliati</string>
|
<string name="settings_webdav_error_denied">Nome utente o password WebDAV sbagliati</string>
|
||||||
<string name="settings_webdav_error_server_offline">Il server WebDAV non è al momento disponibile</string>
|
|
||||||
<string name="settings_webdav_error_generic">Si è verificato un errore tentando di accedere al server WebDAV:</string>
|
<string name="settings_webdav_error_generic">Si è verificato un errore tentando di accedere al server WebDAV:</string>
|
||||||
<string name="settings_webdav_creation_error_generic">Impossibile creare un file di salvataggio sul server WebDAV:</string>
|
<string name="settings_webdav_creation_error_generic">Impossibile creare un file di salvataggio sul server WebDAV:</string>
|
||||||
<string name="settings_webdav_creation_ok">Connessione al server WebDAV avvenuta con successo</string>
|
<string name="settings_webdav_creation_ok">Connessione al server WebDAV avvenuta con successo</string>
|
||||||
@ -81,14 +80,11 @@
|
|||||||
<string name="log_notes_dialog_note_hint">Inserisci le note</string>
|
<string name="log_notes_dialog_note_hint">Inserisci le note</string>
|
||||||
|
|
||||||
<string name="dialog_event_detail_title">Dettaglio evento</string>
|
<string name="dialog_event_detail_title">Dettaglio evento</string>
|
||||||
<string name="dialog_event_detail_save_button">Salva</string>
|
|
||||||
<string name="dialog_event_detail_delete_button">Elimina</string>
|
|
||||||
|
|
||||||
<string name="dialog_add_logbook_title">Aggiungi diario</string>
|
<string name="dialog_add_logbook_title">Aggiungi diario</string>
|
||||||
<string name="dialog_add_logbook_logbookname">👶 Nome del diario</string>
|
<string name="dialog_add_logbook_logbookname">👶 Nome del diario</string>
|
||||||
<string name="dialog_add_logbook_message">Scrivi un nome per identificare questo diario. Comparirà in cima allo schermo, e se usi WebDAV sarà incluso anche nel nome del file di salvataggio.\nSe vuoi un\'icona, inserisci una emoji!</string>
|
<string name="dialog_add_logbook_message">Scrivi un nome per identificare questo diario. Comparirà in cima allo schermo, e se usi WebDAV sarà incluso anche nel nome del file di salvataggio.\nSe vuoi un\'icona, inserisci una emoji!</string>
|
||||||
|
|
||||||
<string name="dialog_add_logbook_message_intro">Benvenuto! Per usare quest\'app devi creare almeno un diario. Probabilmente vuoi chiamarlo col nome di tuo figlio.</string>
|
|
||||||
<string name="default_logbook_name">👶 Il mio primo diario</string>
|
<string name="default_logbook_name">👶 Il mio primo diario</string>
|
||||||
<string name="logbook_created">Creato nuovo diario: </string>
|
<string name="logbook_created">Creato nuovo diario: </string>
|
||||||
|
|
||||||
|
@ -75,7 +75,6 @@
|
|||||||
<string name="settings_storage_dav_pass">Password</string>
|
<string name="settings_storage_dav_pass">Password</string>
|
||||||
<string name="settings_network_error">Unable to reach server: </string>
|
<string name="settings_network_error">Unable to reach server: </string>
|
||||||
<string name="settings_webdav_error_denied">Wrong WebDAV user or password</string>
|
<string name="settings_webdav_error_denied">Wrong WebDAV user or password</string>
|
||||||
<string name="settings_webdav_error_server_offline">WebDAV server is currently unavailable</string>
|
|
||||||
<string name="settings_webdav_error_generic">Error while trying to access WebDAV:</string>
|
<string name="settings_webdav_error_generic">Error while trying to access WebDAV:</string>
|
||||||
<string name="settings_webdav_creation_error_generic">Unable to save a file on the WebDAV server:</string>
|
<string name="settings_webdav_creation_error_generic">Unable to save a file on the WebDAV server:</string>
|
||||||
<string name="settings_webdav_creation_ok">Successfully connected with WebDAV server</string>
|
<string name="settings_webdav_creation_ok">Successfully connected with WebDAV server</string>
|
||||||
@ -104,8 +103,6 @@
|
|||||||
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
<string name="measurement_unit_temperature_base_metric" translatable="false">°C</string>
|
||||||
|
|
||||||
<string name="dialog_event_detail_title">Event detail</string>
|
<string name="dialog_event_detail_title">Event detail</string>
|
||||||
<string name="dialog_event_detail_save_button">Save</string>
|
|
||||||
<string name="dialog_event_detail_delete_button">Delete</string>
|
|
||||||
|
|
||||||
<string name="dialog_add_logbook_title">Add logbook</string>
|
<string name="dialog_add_logbook_title">Add logbook</string>
|
||||||
<string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
|
<string name="dialog_add_logbook_logbookname">👶 Logbook name</string>
|
||||||
|
@ -1,3 +0,0 @@
|
|||||||
Multiple children support
|
|
||||||
Fixed interface in devices with big font size
|
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user