mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Create HabitTypeDialog
This commit is contained in:
@@ -70,6 +70,10 @@ android {
|
||||
sourceSets {
|
||||
main.assets.srcDirs += '../uhabits-core/src/main/resources/'
|
||||
}
|
||||
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -23,12 +23,11 @@ import android.content.res.*
|
||||
import android.graphics.*
|
||||
import android.os.*
|
||||
import androidx.appcompat.app.*
|
||||
import kotlinx.android.synthetic.main.activity_edit_habit.*
|
||||
import org.isoron.androidbase.utils.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.activities.*
|
||||
import org.isoron.uhabits.activities.common.dialogs.*
|
||||
import org.isoron.uhabits.core.preferences.*
|
||||
import org.isoron.uhabits.databinding.*
|
||||
import org.isoron.uhabits.preferences.*
|
||||
import org.isoron.uhabits.utils.*
|
||||
|
||||
@@ -36,6 +35,8 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
|
||||
private lateinit var themeSwitcher: AndroidThemeSwitcher
|
||||
|
||||
private lateinit var binding: ActivityEditHabitBinding
|
||||
|
||||
var paletteColor = 11
|
||||
var freqNum = 1
|
||||
var freqDen = 1
|
||||
@@ -46,16 +47,17 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
themeSwitcher = AndroidThemeSwitcher(this, prefs)
|
||||
themeSwitcher.apply()
|
||||
|
||||
setContentView(R.layout.activity_edit_habit)
|
||||
binding = ActivityEditHabitBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
updateColors()
|
||||
|
||||
setSupportActionBar(toolbar)
|
||||
setSupportActionBar(binding.toolbar)
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||
supportActionBar?.elevation = 10.0f
|
||||
|
||||
val colorPickerDialogFactory = ColorPickerDialogFactory(this)
|
||||
colorButton.setOnClickListener {
|
||||
binding.colorButton.setOnClickListener {
|
||||
val dialog = colorPickerDialogFactory.create(paletteColor)
|
||||
dialog.setListener { paletteColor ->
|
||||
this.paletteColor = paletteColor
|
||||
@@ -65,7 +67,7 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
populateFrequency()
|
||||
frequencyPicker.setOnClickListener {
|
||||
binding.frequencyPicker.setOnClickListener {
|
||||
val dialog = FrequencyPickerDialog(freqNum, freqDen)
|
||||
dialog.onFrequencyPicked = {num, den ->
|
||||
freqNum = num
|
||||
@@ -74,6 +76,10 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
}
|
||||
dialog.show(supportFragmentManager, "frequencyPicker")
|
||||
}
|
||||
|
||||
binding.buttonSave.setOnClickListener {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
private fun populateFrequency() {
|
||||
@@ -85,16 +91,16 @@ class EditHabitActivity : AppCompatActivity() {
|
||||
freqDen == 31 -> "$freqNum times per month"
|
||||
else -> "Unknown"
|
||||
}
|
||||
frequencyPicker.text = label
|
||||
binding.frequencyPicker.text = label
|
||||
}
|
||||
|
||||
private fun updateColors() {
|
||||
val androidColor = PaletteUtils.getColor(this, paletteColor)
|
||||
colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
|
||||
binding.colorButton.backgroundTintList = ColorStateList.valueOf(androidColor)
|
||||
if(!themeSwitcher.isNightMode) {
|
||||
val darkerAndroidColor = ColorUtils.mixColors(Color.BLACK, androidColor, 0.15f)
|
||||
window.statusBarColor = darkerAndroidColor
|
||||
toolbar.setBackgroundColor(androidColor)
|
||||
binding.toolbar.setBackgroundColor(androidColor)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
*
|
||||
* This file is part of Loop Habit Tracker.
|
||||
*
|
||||
* Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
* more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.activities.habits.edit
|
||||
|
||||
import android.os.*
|
||||
import android.view.*
|
||||
import androidx.appcompat.app.*
|
||||
import org.isoron.uhabits.*
|
||||
import org.isoron.uhabits.databinding.*
|
||||
import org.isoron.uhabits.intents.*
|
||||
|
||||
class HabitTypeDialog : AppCompatDialogFragment() {
|
||||
override fun getTheme() = R.style.Translucent
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?): View? {
|
||||
val binding = SelectHabitTypeBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.buttonYesNo.setOnClickListener {
|
||||
val intent = IntentFactory().startEditActivity(activity!!)
|
||||
startActivity(intent)
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.buttonMeasurable.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.buttonSubjective.setOnClickListener{
|
||||
dismiss()
|
||||
}
|
||||
|
||||
binding.background.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
return binding.root
|
||||
}
|
||||
}
|
||||
@@ -39,9 +39,7 @@ class ListHabitsMenu @Inject constructor(
|
||||
val nightModeItem = menu.findItem(R.id.actionToggleNightMode)
|
||||
val hideArchivedItem = menu.findItem(R.id.actionHideArchived)
|
||||
val hideCompletedItem = menu.findItem(R.id.actionHideCompleted)
|
||||
val addNumericalHabit = menu.findItem(R.id.actionCreateNumeralHabit)
|
||||
|
||||
addNumericalHabit.isVisible = preferences.isDeveloper
|
||||
nightModeItem.isChecked = themeSwitcher.isNightMode
|
||||
hideArchivedItem.isChecked = !preferences.showArchived
|
||||
hideCompletedItem.isChecked = !preferences.showCompleted
|
||||
@@ -54,13 +52,8 @@ class ListHabitsMenu @Inject constructor(
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionCreateBooleanHabit -> {
|
||||
behavior.onCreateBooleanHabit()
|
||||
return true
|
||||
}
|
||||
|
||||
R.id.actionCreateNumeralHabit -> {
|
||||
behavior.onCreateNumericalHabit()
|
||||
R.id.actionCreateHabit -> {
|
||||
behavior.onCreateHabit()
|
||||
return true
|
||||
}
|
||||
|
||||
|
||||
@@ -137,14 +137,9 @@ class ListHabitsScreen
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun showCreateBooleanHabitScreen() {
|
||||
val intent = intentFactory.startEditActivity(activity)
|
||||
activity.startActivity(intent)
|
||||
}
|
||||
|
||||
override fun showCreateNumericalHabitScreen() {
|
||||
val dialog = editHabitDialogFactory.createNumerical()
|
||||
activity.showDialog(dialog, "editHabit")
|
||||
override fun showSelectHabitTypeDialog() {
|
||||
val dialog = HabitTypeDialog()
|
||||
activity.showDialog(dialog, "habitType")
|
||||
}
|
||||
|
||||
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ripple
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:color="?colorAccent">
|
||||
<item android:gravity="center">
|
||||
<shape android:shape="rectangle">
|
||||
<solid android:color="?cardBgColor"/>
|
||||
<corners android:radius="5dp" />
|
||||
</shape>
|
||||
</item>
|
||||
</ripple>
|
||||
@@ -26,7 +26,7 @@
|
||||
app:titleTextColor="@color/white">
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/material_text_button"
|
||||
android:id="@+id/buttonSave"
|
||||
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2016-2020 Álinson Santos Xavier <isoron@gmail.com>
|
||||
~
|
||||
~ This file is part of Loop Habit Tracker.
|
||||
~
|
||||
~ Loop Habit Tracker is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by the
|
||||
~ Free Software Foundation, either version 3 of the License, or (at your
|
||||
~ option) any later version.
|
||||
~
|
||||
~ Loop Habit Tracker is distributed in the hope that it will be useful, but
|
||||
~ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
~ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
~ more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License along
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center"
|
||||
android:background="#a0000000"
|
||||
android:clickable="true"
|
||||
android:id="@+id/background"
|
||||
>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttonYesNo"
|
||||
style="@style/SelectHabitTypeButton">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonTitle"
|
||||
android:text="@string/yes_or_no" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonBody"
|
||||
android:text="@string/yes_or_no_example" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttonMeasurable"
|
||||
style="@style/SelectHabitTypeButton">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonTitle"
|
||||
android:text="@string/measurable" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonBody"
|
||||
android:text="@string/measurable_example" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/buttonSubjective"
|
||||
style="@style/SelectHabitTypeButton">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonTitle"
|
||||
android:text="@string/subjective" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/SelectHabitTypeButtonBody"
|
||||
android:text="@string/subjective_example" />
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
@@ -23,7 +23,7 @@
|
||||
tools:context=".MainActivity">
|
||||
|
||||
<item
|
||||
android:id="@+id/actionCreateBooleanHabit"
|
||||
android:id="@+id/actionCreateHabit"
|
||||
android:enabled="true"
|
||||
android:icon="?iconAdd"
|
||||
android:title="@string/add_habit"
|
||||
@@ -96,11 +96,4 @@
|
||||
android:title="@string/about"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/actionCreateNumeralHabit"
|
||||
android:enabled="true"
|
||||
android:title="Add Numerical Habit"
|
||||
android:orderInCategory="200"
|
||||
app:showAsAction="never" />
|
||||
|
||||
</menu>
|
||||
|
||||
@@ -247,4 +247,10 @@
|
||||
<string name="notes">Notes</string>
|
||||
<string name="example_notes">You can put whatever you want here!</string>
|
||||
|
||||
<string name="yes_or_no_example">e.g. Did you wake up early today? Did you exercise? Did you play chess?</string>
|
||||
<string name="measurable">Measurable</string>
|
||||
<string name="measurable_example">e.g. How many miles did you run today? How many pages did you read? How many calories did you eat?</string>
|
||||
<string name="subjective">Subjective</string>
|
||||
<string name="subjective_example">e.g. Are you felling happy today? Definitely, somewhat, not at all? How frequently did you snack? Very often, sometimes, never?</string>
|
||||
|
||||
</resources>
|
||||
@@ -22,6 +22,7 @@
|
||||
<item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
|
||||
<item name="android:dialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
||||
<item name="android:alertDialogTheme">@style/Theme.AppCompat.Light.Dialog</item>
|
||||
<item name="android:navigationBarColor">?attr/colorPrimary</item>
|
||||
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
<item name="actionModeBackground">@color/blue_grey_700</item>
|
||||
@@ -256,4 +257,39 @@
|
||||
<style name="ScrollableRecyclerViewStyle" parent="android:Widget">
|
||||
<item name="android:scrollbars">vertical</item>
|
||||
</style>
|
||||
|
||||
<style name="SelectHabitTypeButton">
|
||||
<item name="android:orientation">vertical</item>
|
||||
<item name="android:paddingTop">14dp</item>
|
||||
<item name="android:paddingBottom">16dp</item>
|
||||
<item name="android:paddingLeft">16dp</item>
|
||||
<item name="android:paddingRight">16dp</item>
|
||||
<item name="android:layout_marginLeft">16dp</item>
|
||||
<item name="android:layout_marginRight">16dp</item>
|
||||
<item name="android:layout_marginBottom">8dp</item>
|
||||
<item name="android:layout_marginTop">8dp</item>
|
||||
<item name="android:elevation">6dp</item>
|
||||
<item name="android:background">@drawable/round_ripple</item>
|
||||
<item name="android:clickable">true</item>
|
||||
<item name="android:selectable">true</item>
|
||||
</style>
|
||||
|
||||
<style name="SelectHabitTypeButtonTitle">
|
||||
<item name="android:textSize">20sp</item>
|
||||
<item name="android:textStyle">bold</item>
|
||||
<item name="android:layout_marginBottom">8dp</item>
|
||||
</style>
|
||||
|
||||
<style name="SelectHabitTypeButtonBody">
|
||||
<item name="android:textSize">@dimen/smallTextSize</item>
|
||||
<item name="android:lineSpacingMultiplier">1.25</item>
|
||||
</style>
|
||||
|
||||
<style name="Translucent">
|
||||
<item name="android:windowNoTitle">true</item>
|
||||
<item name="android:windowBackground">@android:color/transparent</item>
|
||||
<item name="android:colorBackgroundCacheHint">@null</item>
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
@@ -61,14 +61,9 @@ public class ListHabitsMenuBehavior
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
public void onCreateBooleanHabit()
|
||||
public void onCreateHabit()
|
||||
{
|
||||
screen.showCreateBooleanHabitScreen();
|
||||
}
|
||||
|
||||
public void onCreateNumericalHabit()
|
||||
{
|
||||
screen.showCreateNumericalHabitScreen();
|
||||
screen.showSelectHabitTypeDialog();
|
||||
}
|
||||
|
||||
public void onViewFAQ()
|
||||
@@ -150,12 +145,10 @@ public class ListHabitsMenuBehavior
|
||||
|
||||
void showAboutScreen();
|
||||
|
||||
void showCreateBooleanHabitScreen();
|
||||
|
||||
void showCreateNumericalHabitScreen();
|
||||
|
||||
void showFAQScreen();
|
||||
|
||||
void showSettingsScreen();
|
||||
|
||||
void showSelectHabitTypeDialog();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user