Changed habit type selection to dropdown instead of popup message (#498)

pull/504/head
Tthecreator 6 years ago committed by Alinson Xavier
parent ec2fa16fab
commit 3e2cf48223

@ -33,12 +33,13 @@ class ListHabitsMenu @Inject constructor(
private val preferences: Preferences,
private val themeSwitcher: ThemeSwitcher,
private val behavior: ListHabitsMenuBehavior
) : BaseMenu(activity) {
) : BaseMenu(activity){
override fun onCreate(menu: Menu) {
val nightModeItem = menu.findItem(R.id.actionToggleNightMode)
val hideArchivedItem = menu.findItem(R.id.actionHideArchived)
val hideCompletedItem = menu.findItem(R.id.actionHideCompleted)
nightModeItem.isChecked = themeSwitcher.isNightMode
hideArchivedItem.isChecked = !preferences.showArchived
hideCompletedItem.isChecked = !preferences.showCompleted
@ -51,8 +52,13 @@ class ListHabitsMenu @Inject constructor(
return true
}
R.id.actionAdd -> {
behavior.onCreateHabit()
R.id.actionCreateBooleanHabit -> {
behavior.onCreateBooleanHabit()
return true
}
R.id.actionCreateNumeralHabit -> {
behavior.onCreateNumericalHabit()
return true
}

@ -137,26 +137,14 @@ class ListHabitsScreen
activity.startActivity(intent)
}
fun showCreateBooleanHabitScreen() {
override fun showCreateBooleanHabitScreen() {
val dialog = editHabitDialogFactory.createBoolean()
activity.showDialog(dialog, "editHabit")
}
override fun showCreateHabitScreen() {
if (!preferences.isNumericalHabitsFeatureEnabled) {
showCreateBooleanHabitScreen()
return
}
val dialog = AlertDialog.Builder(activity)
.setTitle("Type of habit")
.setItems(R.array.habitTypes) { _, which ->
if (which == 0) showCreateBooleanHabitScreen()
else showCreateNumericalHabitScreen()
}
.create()
dialog.show()
override fun showCreateNumericalHabitScreen() {
val dialog = editHabitDialogFactory.createNumerical()
activity.showDialog(dialog, "editHabit")
}
override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
@ -236,11 +224,6 @@ class ListHabitsScreen
}
}
private fun showCreateNumericalHabitScreen() {
val dialog = editHabitDialogFactory.createNumerical()
activity.showDialog(dialog, "editHabit")
}
private fun onImportData(file: File, onFinished: () -> Unit) {
taskRunner.execute(importTaskFactory.create(file) { result ->
if (result == ImportDataTask.SUCCESS) {

@ -18,15 +18,28 @@
-->
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity">
<item
android:id="@+id/actionAdd"
android:icon="?iconAdd"
android:title="@string/add_habit"
app:showAsAction="always"/>
app:showAsAction="always">
<menu android:id="@+id/createHabitMenu">
<item
android:id="@+id/actionCreateBooleanHabit"
android:enabled="true"
android:title="@string/yes_or_no"/>
<item
android:id="@+id/actionCreateNumeralHabit"
android:enabled="true"
android:title="@string/number"/>
</menu>
</item>
<item
android:id="@+id/action_filter"

@ -184,6 +184,10 @@
<string name="total">Total</string>
<!-- Different types of habits -->
<string name="yes_or_no">Yes or No</string>
<string name="number">Number</string>
<!-- Middle part of the sentence '1 time in xx days' -->
<string name="time_every">time in</string>

@ -153,11 +153,6 @@
android:key="pref_developer"
android:title="Enable developer mode"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_feature_numerical_habits"
android:title="Enable numerical habits"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_feature_sync"

@ -224,16 +224,6 @@ public class Preferences
storage.putBoolean("pref_first_run", isFirstRun);
}
public boolean isNumericalHabitsFeatureEnabled()
{
return storage.getBoolean("pref_feature_numerical_habits", false);
}
public void setNumericalHabitsFeatureEnabled(boolean enabled)
{
storage.putBoolean("pref_feature_numerical_habits", enabled);
}
public boolean isPureBlackEnabled()
{
return storage.getBoolean("pref_pure_black", false);

@ -61,9 +61,14 @@ public class ListHabitsMenuBehavior
updateAdapterFilter();
}
public void onCreateHabit()
public void onCreateBooleanHabit()
{
screen.showCreateHabitScreen();
screen.showCreateBooleanHabitScreen();
}
public void onCreateNumericalHabit()
{
screen.showCreateNumericalHabitScreen();
}
public void onViewFAQ()
@ -145,7 +150,9 @@ public class ListHabitsMenuBehavior
void showAboutScreen();
void showCreateHabitScreen();
void showCreateBooleanHabitScreen();
void showCreateNumericalHabitScreen();
void showFAQScreen();

@ -196,14 +196,6 @@ public class PreferencesTest extends BaseUnitTest
assertTrue(prefs.isShortToggleEnabled());
}
@Test
public void testNumericalHabits() throws Exception
{
assertFalse(prefs.isNumericalHabitsFeatureEnabled());
prefs.setNumericalHabitsFeatureEnabled(true);
assertTrue(prefs.isNumericalHabitsFeatureEnabled());
}
@Test
public void testDeveloper() throws Exception
{

Loading…
Cancel
Save