forked from penguin86/luna-tracker
		
	Reimplemented logbook selector as spinner
This commit is contained in:
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -106,3 +106,4 @@ app/release/output-metadata.json
 | 
			
		||||
 | 
			
		||||
# Other
 | 
			
		||||
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.View
 | 
			
		||||
import android.view.ViewGroup
 | 
			
		||||
import android.widget.AdapterView
 | 
			
		||||
import android.widget.ArrayAdapter
 | 
			
		||||
import android.widget.EditText
 | 
			
		||||
import android.widget.NumberPicker
 | 
			
		||||
import android.widget.PopupWindow
 | 
			
		||||
import android.widget.Spinner
 | 
			
		||||
import android.widget.TextView
 | 
			
		||||
import android.widget.Toast
 | 
			
		||||
import androidx.appcompat.app.AlertDialog
 | 
			
		||||
@@ -324,41 +327,28 @@ class MainActivity : AppCompatActivity() {
 | 
			
		||||
        logbookRepo?.listLogbooks(this, object: LogbookListObtainedListener {
 | 
			
		||||
            override fun onLogbookListObtained(logbooksNames: ArrayList<String>) {
 | 
			
		||||
                runOnUiThread({
 | 
			
		||||
                    // Show logbooks buttons
 | 
			
		||||
                    val logbooksButtonsContainer =
 | 
			
		||||
                        findViewById<ViewGroup>(R.id.logbooks_buttons_container)
 | 
			
		||||
                    logbooksButtonsContainer.removeAllViews()
 | 
			
		||||
                    for (lbn in logbooksNames) {
 | 
			
		||||
                        val lbnButton = layoutInflater.inflate(
 | 
			
		||||
                            R.layout.logbook_button,
 | 
			
		||||
                            logbooksButtonsContainer,
 | 
			
		||||
                            false
 | 
			
		||||
                        ) as TextView
 | 
			
		||||
                        lbnButton.setText(
 | 
			
		||||
                            if (lbn.isEmpty()) getString(R.string.default_logbook_name) else lbn
 | 
			
		||||
                        )
 | 
			
		||||
                        lbnButton.setTag(lbn)
 | 
			
		||||
                        lbnButton.setOnClickListener({
 | 
			
		||||
                    // Show logbooks dropdown
 | 
			
		||||
                    val spinner = findViewById<Spinner>(R.id.logbooks_spinner)
 | 
			
		||||
                    val sAdapter = ArrayAdapter<String>(this@MainActivity, android.R.layout.simple_spinner_item)
 | 
			
		||||
                    sAdapter.addAll(logbooksNames)
 | 
			
		||||
                    spinner.adapter = sAdapter
 | 
			
		||||
                    spinner.onItemSelectedListener = object: AdapterView.OnItemSelectedListener {
 | 
			
		||||
                        override fun onItemSelected(
 | 
			
		||||
                            parent: AdapterView<*>?,
 | 
			
		||||
                            view: View?,
 | 
			
		||||
                            position: Int,
 | 
			
		||||
                            id: Long
 | 
			
		||||
                        ) {
 | 
			
		||||
                            // Changed logbook: empty list
 | 
			
		||||
                            adapter.items.clear()
 | 
			
		||||
                            adapter.notifyDataSetChanged()
 | 
			
		||||
                            // Load logbook
 | 
			
		||||
                            loadLogbook(lbn)
 | 
			
		||||
                        })
 | 
			
		||||
                        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)
 | 
			
		||||
                            loadLogbook(logbooksNames.get(position))
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                    // Load logbook
 | 
			
		||||
                    loadLogbook()
 | 
			
		||||
                        override fun onNothingSelected(parent: AdapterView<*>?) {}
 | 
			
		||||
 | 
			
		||||
                    }
 | 
			
		||||
                })
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
@@ -399,7 +389,6 @@ class MainActivity : AppCompatActivity() {
 | 
			
		||||
                    findViewById<View>(R.id.no_connection_screen).visibility = View.GONE
 | 
			
		||||
                    logbook = lb
 | 
			
		||||
                    showLogbook()
 | 
			
		||||
                    selectLogbookButton(name)
 | 
			
		||||
 | 
			
		||||
                    if (DEBUG_CHECK_LOGBOOK_CONSISTENCY) {
 | 
			
		||||
                        for (e in logbook.logs) {
 | 
			
		||||
@@ -610,20 +599,4 @@ class MainActivity : AppCompatActivity() {
 | 
			
		||||
            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"/>
 | 
			
		||||
 | 
			
		||||
        </LinearLayout>
 | 
			
		||||
        
 | 
			
		||||
        <HorizontalScrollView
 | 
			
		||||
 | 
			
		||||
        <LinearLayout
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:layout_marginTop="10dp"
 | 
			
		||||
            android:layout_marginBottom="10dp">
 | 
			
		||||
            android:layout_height="38dp"
 | 
			
		||||
            android:layout_margin="10dp"
 | 
			
		||||
            android:orientation="horizontal"
 | 
			
		||||
            android:gravity="center_vertical">
 | 
			
		||||
 | 
			
		||||
            <LinearLayout
 | 
			
		||||
                android:id="@+id/logbooks_buttons_container"
 | 
			
		||||
            <FrameLayout
 | 
			
		||||
                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_height="wrap_content"
 | 
			
		||||
                android:orientation="horizontal">
 | 
			
		||||
                android:layout_height="match_parent"
 | 
			
		||||
                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>
 | 
			
		||||
 | 
			
		||||
        </HorizontalScrollView>
 | 
			
		||||
        </LinearLayout>
 | 
			
		||||
 | 
			
		||||
        <TextView
 | 
			
		||||
            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"/>
 | 
			
		||||
		Reference in New Issue
	
	Block a user