Visual feedback on disabled buttons
This commit is contained in:
parent
e1d7b9918f
commit
b81c899ea3
@ -5,6 +5,7 @@ import android.os.Bundle
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import android.widget.NumberPicker
|
import android.widget.NumberPicker
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
@ -37,6 +38,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
lateinit var logbook: Logbook
|
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 recyclerView: RecyclerView
|
lateinit var recyclerView: RecyclerView
|
||||||
lateinit var handler: Handler
|
lateinit var handler: Handler
|
||||||
var savingEvent = false
|
var savingEvent = false
|
||||||
@ -56,6 +58,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.activity_main)
|
setContentView(R.layout.activity_main)
|
||||||
|
|
||||||
progressIndicator = findViewById<LinearProgressIndicator>(R.id.progress_indicator)
|
progressIndicator = findViewById<LinearProgressIndicator>(R.id.progress_indicator)
|
||||||
|
buttonsContainer = findViewById<ViewGroup>(R.id.buttons_container)
|
||||||
recyclerView = findViewById<RecyclerView>(R.id.list_events)
|
recyclerView = findViewById<RecyclerView>(R.id.list_events)
|
||||||
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
recyclerView.setLayoutManager(LinearLayoutManager(applicationContext))
|
||||||
recyclerView.adapter = adapter
|
recyclerView.adapter = adapter
|
||||||
@ -194,11 +197,11 @@ class MainActivity : AppCompatActivity() {
|
|||||||
return
|
return
|
||||||
|
|
||||||
// Load data
|
// Load data
|
||||||
progressIndicator.visibility = View.VISIBLE
|
setLoading(true)
|
||||||
logbookRepo?.loadLogbook(this, object: LogbookLoadedListener{
|
logbookRepo?.loadLogbook(this, object: LogbookLoadedListener{
|
||||||
override fun onLogbookLoaded(lb: Logbook) {
|
override fun onLogbookLoaded(lb: Logbook) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
findViewById<View>(R.id.no_connection_screen).visibility = View.GONE
|
findViewById<View>(R.id.no_connection_screen).visibility = View.GONE
|
||||||
logbook = lb
|
logbook = lb
|
||||||
showLogbook()
|
showLogbook()
|
||||||
@ -207,14 +210,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onIOError(error: IOException) {
|
override fun onIOError(error: IOException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWebDAVError(error: SardineException) {
|
override fun onWebDAVError(error: SardineException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
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)
|
||||||
@ -227,14 +230,14 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onJSONError(error: JSONException) {
|
override fun onJSONError(error: JSONException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onError(error: Exception) {
|
override fun onError(error: Exception) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -244,34 +247,34 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
fun onRepoError(message: String){
|
fun onRepoError(message: String){
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
findViewById<View>(R.id.no_connection_screen).visibility = View.VISIBLE
|
findViewById<View>(R.id.no_connection_screen).visibility = View.VISIBLE
|
||||||
findViewById<TextView>(R.id.no_connection_screen_message).text = message
|
findViewById<TextView>(R.id.no_connection_screen_message).text = message
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
fun logEvent(event: LunaEvent) {
|
fun logEvent(event: LunaEvent) {
|
||||||
savingEvent = true
|
savingEvent(true)
|
||||||
adapter.items.add(0, event)
|
adapter.items.add(0, event)
|
||||||
adapter.notifyItemInserted(0)
|
adapter.notifyItemInserted(0)
|
||||||
recyclerView.smoothScrollToPosition(0)
|
recyclerView.smoothScrollToPosition(0)
|
||||||
|
|
||||||
progressIndicator.visibility = View.VISIBLE
|
setLoading(true)
|
||||||
logbook.logs.add(0, event)
|
logbook.logs.add(0, event)
|
||||||
logbookRepo?.saveLogbook(this, logbook, object: LogbookSavedListener{
|
logbookRepo?.saveLogbook(this, logbook, object: LogbookSavedListener{
|
||||||
override fun onLogbookSaved() {
|
override fun onLogbookSaved() {
|
||||||
Log.d(TAG, "Logbook saved")
|
Log.d(TAG, "Logbook saved")
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
|
|
||||||
Toast.makeText(this@MainActivity, R.string.toast_event_added, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@MainActivity, R.string.toast_event_added, Toast.LENGTH_SHORT).show()
|
||||||
savingEvent = false
|
savingEvent(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onIOError(error: IOException) {
|
override fun onIOError(error: IOException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
onRepoError(getString(R.string.settings_network_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
@ -279,7 +282,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onWebDAVError(error: SardineException) {
|
override fun onWebDAVError(error: SardineException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
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)
|
||||||
@ -293,7 +296,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onJSONError(error: JSONException) {
|
override fun onJSONError(error: JSONException) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
onRepoError(getString(R.string.settings_json_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
@ -301,7 +304,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onError(error: Exception) {
|
override fun onError(error: Exception) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
onRepoError(getString(R.string.settings_generic_error) + error.toString())
|
||||||
onAddError(event, error.toString())
|
onAddError(event, error.toString())
|
||||||
})
|
})
|
||||||
@ -312,13 +315,31 @@ class MainActivity : AppCompatActivity() {
|
|||||||
private fun onAddError(event: LunaEvent, error: String) {
|
private fun onAddError(event: LunaEvent, error: String) {
|
||||||
Log.e(TAG, "Logbook was NOT saved! $error")
|
Log.e(TAG, "Logbook was NOT saved! $error")
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
progressIndicator.visibility = View.INVISIBLE
|
setLoading(false)
|
||||||
|
|
||||||
Toast.makeText(this@MainActivity, R.string.toast_event_add_error, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this@MainActivity, R.string.toast_event_add_error, Toast.LENGTH_SHORT).show()
|
||||||
adapter.items.remove(event)
|
adapter.items.remove(event)
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
savingEvent = false
|
savingEvent(false)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun setLoading(loading: Boolean) {
|
||||||
|
if (loading) {
|
||||||
|
progressIndicator.visibility = View.VISIBLE
|
||||||
|
} else {
|
||||||
|
progressIndicator.visibility = View.INVISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun savingEvent(saving: Boolean) {
|
||||||
|
if (saving) {
|
||||||
|
savingEvent = true
|
||||||
|
buttonsContainer.alpha = 0.2f
|
||||||
|
} else {
|
||||||
|
savingEvent = false
|
||||||
|
buttonsContainer.alpha = 1f
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,12 @@
|
|||||||
android:text="@string/log_an_event"
|
android:text="@string/log_an_event"
|
||||||
android:gravity="center_horizontal"/>
|
android:gravity="center_horizontal"/>
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:id="@+id/buttons_container"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
@ -121,6 +127,8 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<com.google.android.material.progressindicator.LinearProgressIndicator
|
<com.google.android.material.progressindicator.LinearProgressIndicator
|
||||||
android:id="@+id/progress_indicator"
|
android:id="@+id/progress_indicator"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
Loading…
Reference in New Issue
Block a user