Reimplemented logbook selector as spinner
This commit is contained in:
parent
0494a11538
commit
e3aceaf133
1
.gitignore
vendored
1
.gitignore
vendored
@ -106,3 +106,4 @@ app/release/output-metadata.json
|
|||||||
|
|
||||||
# Other
|
# Other
|
||||||
app/src/main/java/it/danieleverducci/lunatracker/TemporaryHardcodedCredentials.kt
|
app/src/main/java/it/danieleverducci/lunatracker/TemporaryHardcodedCredentials.kt
|
||||||
|
.kotlin/sessions/*
|
||||||
|
@ -7,9 +7,12 @@ import android.util.Log
|
|||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
import android.widget.EditText
|
import android.widget.EditText
|
||||||
import android.widget.NumberPicker
|
import android.widget.NumberPicker
|
||||||
import android.widget.PopupWindow
|
import android.widget.PopupWindow
|
||||||
|
import android.widget.Spinner
|
||||||
import android.widget.TextView
|
import android.widget.TextView
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
@ -324,41 +327,28 @@ class MainActivity : AppCompatActivity() {
|
|||||||
logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener {
|
logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener {
|
||||||
override fun onLogbookListObtained(logbooksNames: ArrayList<String>) {
|
override fun onLogbookListObtained(logbooksNames: ArrayList<String>) {
|
||||||
runOnUiThread({
|
runOnUiThread({
|
||||||
// Show logbooks buttons
|
// Show logbooks dropdown
|
||||||
val logbooksButtonsContainer =
|
val spinner = findViewById<Spinner>(R.id.logbooks_spinner)
|
||||||
findViewById<ViewGroup>(R.id.logbooks_buttons_container)
|
val sAdapter = ArrayAdapter<String>(this@MainActivity, android.R.layout.simple_spinner_item)
|
||||||
logbooksButtonsContainer.removeAllViews()
|
sAdapter.addAll(logbooksNames)
|
||||||
for (lbn in logbooksNames) {
|
spinner.adapter = sAdapter
|
||||||
val lbnButton = layoutInflater.inflate(
|
spinner.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
|
||||||
R.layout.logbook_button,
|
override fun onItemSelected(
|
||||||
logbooksButtonsContainer,
|
parent: AdapterView<*>?,
|
||||||
false
|
view: View?,
|
||||||
) as TextView
|
position: Int,
|
||||||
lbnButton.setText(
|
id: Long
|
||||||
if (lbn.isEmpty()) getString(R.string.default_logbook_name) else lbn
|
) {
|
||||||
)
|
|
||||||
lbnButton.setTag(lbn)
|
|
||||||
lbnButton.setOnClickListener({
|
|
||||||
// Changed logbook: empty list
|
// Changed logbook: empty list
|
||||||
adapter.items.clear()
|
adapter.items.clear()
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
// Load logbook
|
// Load logbook
|
||||||
loadLogbook(lbn)
|
loadLogbook(logbooksNames.get(position))
|
||||||
})
|
}
|
||||||
logbooksButtonsContainer.addView(lbnButton)
|
|
||||||
}
|
|
||||||
// Show "Add logbook" button
|
|
||||||
val addLogbookButton = layoutInflater.inflate(
|
|
||||||
R.layout.logbook_button,
|
|
||||||
logbooksButtonsContainer,
|
|
||||||
false
|
|
||||||
) as TextView
|
|
||||||
addLogbookButton.setText("+")
|
|
||||||
addLogbookButton.setOnClickListener({showAddLogbookDialog()})
|
|
||||||
logbooksButtonsContainer.addView(addLogbookButton)
|
|
||||||
|
|
||||||
// Load logbook
|
override fun onNothingSelected(parent: AdapterView<*>?) {}
|
||||||
loadLogbook()
|
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,7 +389,6 @@ class MainActivity : AppCompatActivity() {
|
|||||||
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()
|
||||||
selectLogbookButton(name)
|
|
||||||
|
|
||||||
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
|
||||||
for (e in logbook.logs) {
|
for (e in logbook.logs) {
|
||||||
@ -610,20 +599,4 @@ class MainActivity : AppCompatActivity() {
|
|||||||
showingOverflowPopupWindow = true
|
showingOverflowPopupWindow = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun selectLogbookButton(logbookName: String) {
|
|
||||||
val logbooksButtonsContainer =
|
|
||||||
findViewById<ViewGroup>(R.id.logbooks_buttons_container)
|
|
||||||
for (lb in logbooksButtonsContainer.children) {
|
|
||||||
if (lb.tag != null && lb.tag.toString().equals(logbookName)) {
|
|
||||||
// Selected
|
|
||||||
lb.setBackgroundColor(ContextCompat.getColor(this, R.color.accent))
|
|
||||||
(lb as TextView).setTextColor(ContextCompat.getColor(this, R.color.black))
|
|
||||||
} else {
|
|
||||||
// Not selected
|
|
||||||
lb.setBackgroundColor(ContextCompat.getColor(this, R.color.transparent))
|
|
||||||
(lb as TextView).setTextColor(ContextCompat.getColor(this, R.color.accent))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -43,22 +43,41 @@
|
|||||||
app:tint="@color/grey"/>
|
app:tint="@color/grey"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<HorizontalScrollView
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="38dp"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_margin="10dp"
|
||||||
android:layout_marginBottom="10dp">
|
android:orientation="horizontal"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
|
||||||
<LinearLayout
|
<FrameLayout
|
||||||
android:id="@+id/logbooks_buttons_container"
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="match_parent"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:background="@drawable/button_background">
|
||||||
|
|
||||||
|
<Spinner
|
||||||
|
android:id="@+id/logbooks_spinner"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent"/>
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/logbooks_add"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="match_parent"
|
||||||
android:orientation="horizontal">
|
android:layout_marginLeft="10dp"
|
||||||
|
android:paddingLeft="16dp"
|
||||||
|
android:paddingRight="16dp"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:textColor="@color/accent"
|
||||||
|
android:textSize="20dp"
|
||||||
|
android:text="+"
|
||||||
|
android:background="@drawable/button_background"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
</HorizontalScrollView>
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:layout_marginRight="5dp"
|
|
||||||
android:paddingTop="10dp"
|
|
||||||
android:paddingBottom="10dp"
|
|
||||||
android:paddingLeft="20dp"
|
|
||||||
android:paddingRight="20dp"
|
|
||||||
android:background="@drawable/button_background"
|
|
||||||
android:textStyle="bold"
|
|
||||||
android:textColor="@color/accent"/>
|
|
Loading…
x
Reference in New Issue
Block a user