forked from penguin86/luna-tracker
		
	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()
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        val noBreastfeeding = settingsRepository.loadNoBreastfeeding()
 | 
			
		||||
        findViewById<View>(R.id.layout_nipples).visibility = when (noBreastfeeding) {
 | 
			
		||||
            true -> View.GONE
 | 
			
		||||
            false -> View.VISIBLE
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Update list dates
 | 
			
		||||
        recyclerView.adapter?.notifyDataSetChanged()
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -7,6 +7,7 @@ import android.widget.TextView
 | 
			
		||||
import android.widget.Toast
 | 
			
		||||
import androidx.appcompat.app.AppCompatActivity
 | 
			
		||||
import com.google.android.material.progressindicator.LinearProgressIndicator
 | 
			
		||||
import com.google.android.material.switchmaterial.SwitchMaterial
 | 
			
		||||
import com.thegrizzlylabs.sardineandroid.impl.SardineException
 | 
			
		||||
import it.danieleverducci.lunatracker.repository.FileLogbookRepository
 | 
			
		||||
import it.danieleverducci.lunatracker.repository.LocalSettingsRepository
 | 
			
		||||
@@ -24,6 +25,7 @@ open class SettingsActivity : AppCompatActivity() {
 | 
			
		||||
    protected lateinit var textViewWebDAVUser: TextView
 | 
			
		||||
    protected lateinit var textViewWebDAVPass: TextView
 | 
			
		||||
    protected lateinit var progressIndicator: LinearProgressIndicator
 | 
			
		||||
    protected lateinit var switchNoBreastfeeding: SwitchMaterial
 | 
			
		||||
 | 
			
		||||
    override fun onCreate(savedInstanceState: Bundle?) {
 | 
			
		||||
        super.onCreate(savedInstanceState)
 | 
			
		||||
@@ -35,6 +37,8 @@ open class SettingsActivity : AppCompatActivity() {
 | 
			
		||||
        textViewWebDAVUser = findViewById(R.id.settings_data_webdav_user)
 | 
			
		||||
        textViewWebDAVPass = findViewById(R.id.settings_data_webdav_pass)
 | 
			
		||||
        progressIndicator = findViewById(R.id.progress_indicator)
 | 
			
		||||
        switchNoBreastfeeding = findViewById(R.id.switch_no_breastfeeding)
 | 
			
		||||
 | 
			
		||||
        findViewById<View>(R.id.settings_save).setOnClickListener({
 | 
			
		||||
            validateAndSave()
 | 
			
		||||
        })
 | 
			
		||||
@@ -49,11 +53,15 @@ open class SettingsActivity : AppCompatActivity() {
 | 
			
		||||
    fun loadSettings() {
 | 
			
		||||
        val dataRepo = settingsRepository.loadDataRepository()
 | 
			
		||||
        val webDavCredentials = settingsRepository.loadWebdavCredentials()
 | 
			
		||||
        val noBreastfeeding = settingsRepository.loadNoBreastfeeding()
 | 
			
		||||
 | 
			
		||||
        when (dataRepo) {
 | 
			
		||||
            LocalSettingsRepository.DATA_REPO.LOCAL_FILE -> radioDataLocal.isChecked = true
 | 
			
		||||
            LocalSettingsRepository.DATA_REPO.WEBDAV -> radioDataWebDAV.isChecked = true
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        switchNoBreastfeeding.isChecked = noBreastfeeding
 | 
			
		||||
 | 
			
		||||
        if (webDavCredentials != null) {
 | 
			
		||||
            textViewWebDAVUrl.setText(webDavCredentials[0])
 | 
			
		||||
            textViewWebDAVUser.setText(webDavCredentials[1])
 | 
			
		||||
@@ -149,6 +157,7 @@ open class SettingsActivity : AppCompatActivity() {
 | 
			
		||||
            if (radioDataWebDAV.isChecked) LocalSettingsRepository.DATA_REPO.WEBDAV
 | 
			
		||||
            else LocalSettingsRepository.DATA_REPO.LOCAL_FILE
 | 
			
		||||
        )
 | 
			
		||||
        settingsRepository.saveNoBreastfeeding(switchNoBreastfeeding.isChecked)
 | 
			
		||||
        settingsRepository.saveWebdavCredentials(
 | 
			
		||||
            textViewWebDAVUrl.text.toString(),
 | 
			
		||||
            textViewWebDAVUser.text.toString(),
 | 
			
		||||
 
 | 
			
		||||
@@ -3,6 +3,7 @@ package it.danieleverducci.lunatracker.repository
 | 
			
		||||
import android.content.Context
 | 
			
		||||
import android.content.Context.MODE_PRIVATE
 | 
			
		||||
import android.content.SharedPreferences
 | 
			
		||||
import androidx.core.content.edit
 | 
			
		||||
 | 
			
		||||
class LocalSettingsRepository(val context: Context) {
 | 
			
		||||
    companion object {
 | 
			
		||||
@@ -12,6 +13,7 @@ class LocalSettingsRepository(val context: Context) {
 | 
			
		||||
        val SHARED_PREFS_DAV_URL = "webdav_url"
 | 
			
		||||
        val SHARED_PREFS_DAV_USER = "webdav_user"
 | 
			
		||||
        val SHARED_PREFS_DAV_PASS = "webdav_password"
 | 
			
		||||
        val SHARED_PREFS_NO_BREASTFEEDING = "no_breastfeeding"
 | 
			
		||||
    }
 | 
			
		||||
    enum class DATA_REPO {LOCAL_FILE, WEBDAV}
 | 
			
		||||
    val sharedPreferences: SharedPreferences
 | 
			
		||||
@@ -28,6 +30,14 @@ class LocalSettingsRepository(val context: Context) {
 | 
			
		||||
        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) {
 | 
			
		||||
        val spe = sharedPreferences.edit()
 | 
			
		||||
        spe.putString(
 | 
			
		||||
 
 | 
			
		||||
@@ -122,7 +122,8 @@
 | 
			
		||||
 | 
			
		||||
            <LinearLayout
 | 
			
		||||
                android:layout_width="match_parent"
 | 
			
		||||
                android:layout_height="wrap_content">
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:id="@+id/layout_nipples">
 | 
			
		||||
 | 
			
		||||
                <TextView
 | 
			
		||||
                    android:id="@+id/button_nipple_left"
 | 
			
		||||
 
 | 
			
		||||
@@ -45,7 +45,7 @@
 | 
			
		||||
            <RadioButton android:id="@+id/settings_data_webdav"
 | 
			
		||||
                android:layout_width="wrap_content"
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:layout_marginTop="30dp"
 | 
			
		||||
                android:layout_marginTop="20dp"
 | 
			
		||||
                android:text="@string/settings_storage_dav"/>
 | 
			
		||||
 | 
			
		||||
            <TextView
 | 
			
		||||
@@ -115,36 +115,59 @@
 | 
			
		||||
                android:layout_height="wrap_content"
 | 
			
		||||
                android:indeterminate="true"
 | 
			
		||||
                app:indicatorColor="@color/accent"
 | 
			
		||||
                android:layout_margin="20dp"
 | 
			
		||||
                android:layout_marginTop="20dp"
 | 
			
		||||
                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>
 | 
			
		||||
 | 
			
		||||
        <LinearLayout
 | 
			
		||||
            android:layout_width="match_parent"
 | 
			
		||||
            android:layout_height="wrap_content"
 | 
			
		||||
            android:orientation="horizontal"
 | 
			
		||||
            android:layout_marginTop="5dp"
 | 
			
		||||
            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>
 | 
			
		||||
 | 
			
		||||
</ScrollView>
 | 
			
		||||
@@ -51,6 +51,8 @@
 | 
			
		||||
    <string name="no_connection_go_to_settings">Einstellungen</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_storage">Speicherort für Daten auswählen</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_retry">Retry</string>
 | 
			
		||||
 | 
			
		||||
    <string name="no_breastfeeding">No Breastfeeding</string>
 | 
			
		||||
 | 
			
		||||
    <string name="settings_title">Settings</string>
 | 
			
		||||
    <string name="settings_storage">Choose where to save data</string>
 | 
			
		||||
    <string name="settings_storage_local">On device</string>
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user