add setting to disable breastfeeding buttons
Some women do not breastfeed. Hide the buttons in order to have more space for log messages.
This commit is contained in:
		@@ -168,6 +168,12 @@ class MainActivity : AppCompatActivity() {
 | 
				
			|||||||
            logbookRepo = FileLogbookRepository()
 | 
					            logbookRepo = FileLogbookRepository()
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        val noBreastfeeding = settingsRepository.loadNoBreastfeeding()
 | 
				
			||||||
 | 
					        findViewById<View>(R.id.layout_nipples).visibility = when (noBreastfeeding) {
 | 
				
			||||||
 | 
					            true -> View.GONE
 | 
				
			||||||
 | 
					            false -> View.VISIBLE
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Update list dates
 | 
					        // Update list dates
 | 
				
			||||||
        recyclerView.adapter?.notifyDataSetChanged()
 | 
					        recyclerView.adapter?.notifyDataSetChanged()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,6 +7,7 @@ import android.widget.TextView
 | 
				
			|||||||
import android.widget.Toast
 | 
					import android.widget.Toast
 | 
				
			||||||
import androidx.appcompat.app.AppCompatActivity
 | 
					import androidx.appcompat.app.AppCompatActivity
 | 
				
			||||||
import com.google.android.material.progressindicator.LinearProgressIndicator
 | 
					import com.google.android.material.progressindicator.LinearProgressIndicator
 | 
				
			||||||
 | 
					import com.google.android.material.switchmaterial.SwitchMaterial
 | 
				
			||||||
import com.thegrizzlylabs.sardineandroid.impl.SardineException
 | 
					import com.thegrizzlylabs.sardineandroid.impl.SardineException
 | 
				
			||||||
import it.danieleverducci.lunatracker.repository.FileLogbookRepository
 | 
					import it.danieleverducci.lunatracker.repository.FileLogbookRepository
 | 
				
			||||||
import it.danieleverducci.lunatracker.repository.LocalSettingsRepository
 | 
					import it.danieleverducci.lunatracker.repository.LocalSettingsRepository
 | 
				
			||||||
@@ -24,6 +25,7 @@ open class SettingsActivity : AppCompatActivity() {
 | 
				
			|||||||
    protected lateinit var textViewWebDAVUser: TextView
 | 
					    protected lateinit var textViewWebDAVUser: TextView
 | 
				
			||||||
    protected lateinit var textViewWebDAVPass: TextView
 | 
					    protected lateinit var textViewWebDAVPass: TextView
 | 
				
			||||||
    protected lateinit var progressIndicator: LinearProgressIndicator
 | 
					    protected lateinit var progressIndicator: LinearProgressIndicator
 | 
				
			||||||
 | 
					    protected lateinit var switchNoBreastfeeding: SwitchMaterial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
					    override fun onCreate(savedInstanceState: Bundle?) {
 | 
				
			||||||
        super.onCreate(savedInstanceState)
 | 
					        super.onCreate(savedInstanceState)
 | 
				
			||||||
@@ -35,6 +37,8 @@ open class SettingsActivity : AppCompatActivity() {
 | 
				
			|||||||
        textViewWebDAVUser = findViewById(R.id.settings_data_webdav_user)
 | 
					        textViewWebDAVUser = findViewById(R.id.settings_data_webdav_user)
 | 
				
			||||||
        textViewWebDAVPass = findViewById(R.id.settings_data_webdav_pass)
 | 
					        textViewWebDAVPass = findViewById(R.id.settings_data_webdav_pass)
 | 
				
			||||||
        progressIndicator = findViewById(R.id.progress_indicator)
 | 
					        progressIndicator = findViewById(R.id.progress_indicator)
 | 
				
			||||||
 | 
					        switchNoBreastfeeding = findViewById(R.id.switch_no_breastfeeding)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        findViewById<View>(R.id.settings_save).setOnClickListener({
 | 
					        findViewById<View>(R.id.settings_save).setOnClickListener({
 | 
				
			||||||
            validateAndSave()
 | 
					            validateAndSave()
 | 
				
			||||||
        })
 | 
					        })
 | 
				
			||||||
@@ -49,11 +53,15 @@ open class SettingsActivity : AppCompatActivity() {
 | 
				
			|||||||
    fun loadSettings() {
 | 
					    fun loadSettings() {
 | 
				
			||||||
        val dataRepo = settingsRepository.loadDataRepository()
 | 
					        val dataRepo = settingsRepository.loadDataRepository()
 | 
				
			||||||
        val webDavCredentials = settingsRepository.loadWebdavCredentials()
 | 
					        val webDavCredentials = settingsRepository.loadWebdavCredentials()
 | 
				
			||||||
 | 
					        val noBreastfeeding = settingsRepository.loadNoBreastfeeding()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        when (dataRepo) {
 | 
					        when (dataRepo) {
 | 
				
			||||||
            LocalSettingsRepository.DATA_REPO.LOCAL_FILE -> radioDataLocal.isChecked = true
 | 
					            LocalSettingsRepository.DATA_REPO.LOCAL_FILE -> radioDataLocal.isChecked = true
 | 
				
			||||||
            LocalSettingsRepository.DATA_REPO.WEBDAV -> radioDataWebDAV.isChecked = true
 | 
					            LocalSettingsRepository.DATA_REPO.WEBDAV -> radioDataWebDAV.isChecked = true
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        switchNoBreastfeeding.isChecked = noBreastfeeding
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (webDavCredentials != null) {
 | 
					        if (webDavCredentials != null) {
 | 
				
			||||||
            textViewWebDAVUrl.setText(webDavCredentials[0])
 | 
					            textViewWebDAVUrl.setText(webDavCredentials[0])
 | 
				
			||||||
            textViewWebDAVUser.setText(webDavCredentials[1])
 | 
					            textViewWebDAVUser.setText(webDavCredentials[1])
 | 
				
			||||||
@@ -149,6 +157,7 @@ open class SettingsActivity : AppCompatActivity() {
 | 
				
			|||||||
            if (radioDataWebDAV.isChecked) LocalSettingsRepository.DATA_REPO.WEBDAV
 | 
					            if (radioDataWebDAV.isChecked) LocalSettingsRepository.DATA_REPO.WEBDAV
 | 
				
			||||||
            else LocalSettingsRepository.DATA_REPO.LOCAL_FILE
 | 
					            else LocalSettingsRepository.DATA_REPO.LOCAL_FILE
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
 | 
					        settingsRepository.saveNoBreastfeeding(switchNoBreastfeeding.isChecked)
 | 
				
			||||||
        settingsRepository.saveWebdavCredentials(
 | 
					        settingsRepository.saveWebdavCredentials(
 | 
				
			||||||
            textViewWebDAVUrl.text.toString(),
 | 
					            textViewWebDAVUrl.text.toString(),
 | 
				
			||||||
            textViewWebDAVUser.text.toString(),
 | 
					            textViewWebDAVUser.text.toString(),
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -3,6 +3,7 @@ package it.danieleverducci.lunatracker.repository
 | 
				
			|||||||
import android.content.Context
 | 
					import android.content.Context
 | 
				
			||||||
import android.content.Context.MODE_PRIVATE
 | 
					import android.content.Context.MODE_PRIVATE
 | 
				
			||||||
import android.content.SharedPreferences
 | 
					import android.content.SharedPreferences
 | 
				
			||||||
 | 
					import androidx.core.content.edit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class LocalSettingsRepository(val context: Context) {
 | 
					class LocalSettingsRepository(val context: Context) {
 | 
				
			||||||
    companion object {
 | 
					    companion object {
 | 
				
			||||||
@@ -12,6 +13,7 @@ class LocalSettingsRepository(val context: Context) {
 | 
				
			|||||||
        val SHARED_PREFS_DAV_URL = "webdav_url"
 | 
					        val SHARED_PREFS_DAV_URL = "webdav_url"
 | 
				
			||||||
        val SHARED_PREFS_DAV_USER = "webdav_user"
 | 
					        val SHARED_PREFS_DAV_USER = "webdav_user"
 | 
				
			||||||
        val SHARED_PREFS_DAV_PASS = "webdav_password"
 | 
					        val SHARED_PREFS_DAV_PASS = "webdav_password"
 | 
				
			||||||
 | 
					        val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    enum class DATA_REPO {LOCAL_FILE, WEBDAV}
 | 
					    enum class DATA_REPO {LOCAL_FILE, WEBDAV}
 | 
				
			||||||
    val sharedPreferences: SharedPreferences
 | 
					    val sharedPreferences: SharedPreferences
 | 
				
			||||||
@@ -28,6 +30,14 @@ class LocalSettingsRepository(val context: Context) {
 | 
				
			|||||||
        return sharedPreferences.getInt(SHARED_PREFS_BB_CONTENT, 1)
 | 
					        return sharedPreferences.getInt(SHARED_PREFS_BB_CONTENT, 1)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun saveNoBreastfeeding(content: Boolean) {
 | 
				
			||||||
 | 
					        sharedPreferences.edit().putBoolean(SHARED_PREFS_NO_BREASTFEEDING, content).apply()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fun loadNoBreastfeeding(): Boolean {
 | 
				
			||||||
 | 
					        return sharedPreferences.getBoolean(SHARED_PREFS_NO_BREASTFEEDING, false)
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    fun saveDataRepository(repo: DATA_REPO) {
 | 
					    fun saveDataRepository(repo: DATA_REPO) {
 | 
				
			||||||
        val spe = sharedPreferences.edit()
 | 
					        val spe = sharedPreferences.edit()
 | 
				
			||||||
        spe.putString(
 | 
					        spe.putString(
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -122,7 +122,8 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
            <LinearLayout
 | 
					            <LinearLayout
 | 
				
			||||||
                android:layout_width="match_parent"
 | 
					                android:layout_width="match_parent"
 | 
				
			||||||
                android:layout_height="wrap_content">
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                android:id="@+id/layout_nipples">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                <TextView
 | 
					                <TextView
 | 
				
			||||||
                    android:id="@+id/button_nipple_left"
 | 
					                    android:id="@+id/button_nipple_left"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -115,36 +115,58 @@
 | 
				
			|||||||
                android:layout_height="wrap_content"
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
                android:indeterminate="true"
 | 
					                android:indeterminate="true"
 | 
				
			||||||
                app:indicatorColor="@color/accent"
 | 
					                app:indicatorColor="@color/accent"
 | 
				
			||||||
                android:layout_margin="20dp"
 | 
					                android:layout_marginTop="20dp"
 | 
				
			||||||
                android:visibility="invisible"/>
 | 
					                android:visibility="invisible"/>
 | 
				
			||||||
 | 
					 | 
				
			||||||
            <LinearLayout
 | 
					 | 
				
			||||||
                android:layout_width="match_parent"
 | 
					 | 
				
			||||||
                android:layout_height="wrap_content"
 | 
					 | 
				
			||||||
                android:orientation="horizontal">
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                <Button
 | 
					 | 
				
			||||||
                    android:id="@+id/settings_cancel"
 | 
					 | 
				
			||||||
                    android:layout_width="0dp"
 | 
					 | 
				
			||||||
                    android:layout_height="wrap_content"
 | 
					 | 
				
			||||||
                    android:layout_weight="1"
 | 
					 | 
				
			||||||
                    android:layout_marginRight="20dp"
 | 
					 | 
				
			||||||
                    android:background="@drawable/button_background"
 | 
					 | 
				
			||||||
                    android:textColor="@color/accent"
 | 
					 | 
				
			||||||
                    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:background="@drawable/button_background"
 | 
					 | 
				
			||||||
                    android:text="@android:string/ok"/>
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
            </LinearLayout>
 | 
					 | 
				
			||||||
        </RadioGroup>
 | 
					        </RadioGroup>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <LinearLayout
 | 
				
			||||||
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:orientation="horizontal"
 | 
				
			||||||
 | 
					            android:layout_marginEnd="30dp">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <TextView
 | 
				
			||||||
 | 
					                android:layout_width="0dp"
 | 
				
			||||||
 | 
					                android:layout_weight="1"
 | 
				
			||||||
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                android:textStyle="bold"
 | 
				
			||||||
 | 
					                android:text="@string/no_breastfeeding" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <com.google.android.material.switchmaterial.SwitchMaterial
 | 
				
			||||||
 | 
					                android:id="@+id/switch_no_breastfeeding"
 | 
				
			||||||
 | 
					                android:layout_width="0dp"
 | 
				
			||||||
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                android:layout_weight="1" />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        </LinearLayout>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        <LinearLayout
 | 
				
			||||||
 | 
					            android:layout_width="match_parent"
 | 
				
			||||||
 | 
					            android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					            android:layout_marginTop="20dp"
 | 
				
			||||||
 | 
					            android:orientation="horizontal">
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            <Button
 | 
				
			||||||
 | 
					                android:id="@+id/settings_cancel"
 | 
				
			||||||
 | 
					                android:layout_width="0dp"
 | 
				
			||||||
 | 
					                android:layout_height="wrap_content"
 | 
				
			||||||
 | 
					                android:layout_weight="1"
 | 
				
			||||||
 | 
					                android:layout_marginEnd="20dp"
 | 
				
			||||||
 | 
					                android:background="@drawable/button_background"
 | 
				
			||||||
 | 
					                android:textColor="@color/accent"
 | 
				
			||||||
 | 
					                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:background="@drawable/button_background"
 | 
				
			||||||
 | 
					                android:text="@android:string/ok"/>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        </LinearLayout>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    </LinearLayout>
 | 
					    </LinearLayout>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
</ScrollView>
 | 
					</ScrollView>
 | 
				
			||||||
@@ -51,6 +51,8 @@
 | 
				
			|||||||
    <string name="no_connection_go_to_settings">Einstellungen</string>
 | 
					    <string name="no_connection_go_to_settings">Einstellungen</string>
 | 
				
			||||||
    <string name="no_connection_retry">Erneut versuchen</string>
 | 
					    <string name="no_connection_retry">Erneut versuchen</string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <string name="no_breastfeeding">Kein Stillen</string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <string name="settings_title">Einstellungen</string>
 | 
					    <string name="settings_title">Einstellungen</string>
 | 
				
			||||||
    <string name="settings_storage">Speicherort für Daten auswählen</string>
 | 
					    <string name="settings_storage">Speicherort für Daten auswählen</string>
 | 
				
			||||||
    <string name="settings_storage_local">Auf dem Gerät</string>
 | 
					    <string name="settings_storage_local">Auf dem Gerät</string>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -66,6 +66,8 @@
 | 
				
			|||||||
    <string name="no_connection_go_to_settings">Settings</string>
 | 
					    <string name="no_connection_go_to_settings">Settings</string>
 | 
				
			||||||
    <string name="no_connection_retry">Retry</string>
 | 
					    <string name="no_connection_retry">Retry</string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    <string name="no_breastfeeding">No Breastfeeding</string>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    <string name="settings_title">Settings</string>
 | 
					    <string name="settings_title">Settings</string>
 | 
				
			||||||
    <string name="settings_storage">Choose where to save data</string>
 | 
					    <string name="settings_storage">Choose where to save data</string>
 | 
				
			||||||
    <string name="settings_storage_local">On device</string>
 | 
					    <string name="settings_storage_local">On device</string>
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user