merge from dev

pull/499/head
Thomas Saedt 6 years ago
commit 129d346f0a

@ -33,9 +33,7 @@ class ListHabitsMenu @Inject constructor(
private val preferences: Preferences, private val preferences: Preferences,
private val themeSwitcher: ThemeSwitcher, private val themeSwitcher: ThemeSwitcher,
private val behavior: ListHabitsMenuBehavior private val behavior: ListHabitsMenuBehavior
) : BaseMenu(activity), Preferences.Listener { ) : BaseMenu(activity){
private lateinit var topBarMenu: Menu
override fun onCreate(menu: Menu) { override fun onCreate(menu: Menu) {
val nightModeItem = menu.findItem(R.id.actionToggleNightMode) val nightModeItem = menu.findItem(R.id.actionToggleNightMode)
@ -45,19 +43,6 @@ class ListHabitsMenu @Inject constructor(
nightModeItem.isChecked = themeSwitcher.isNightMode nightModeItem.isChecked = themeSwitcher.isNightMode
hideArchivedItem.isChecked = !preferences.showArchived hideArchivedItem.isChecked = !preferences.showArchived
hideCompletedItem.isChecked = !preferences.showCompleted hideCompletedItem.isChecked = !preferences.showCompleted
topBarMenu = menu
//the habit creation menu should be disabled when numeric habits are also disabled
if (!preferences.isNumericalHabitsFeatureEnabled) {
setCreateHabitMenuEnabled(false, menu)
}
//let the class add itself as listener
preferences.addListener(this)
}
override fun onNumericalHabitsFeatureChanged() {
if(topBarMenu==null){return}
setCreateHabitMenuEnabled(preferences.isNumericalHabitsFeatureEnabled, topBarMenu)
} }
override fun onItemSelected(item: MenuItem): Boolean { override fun onItemSelected(item: MenuItem): Boolean {
@ -67,11 +52,6 @@ class ListHabitsMenu @Inject constructor(
return true return true
} }
R.id.actionAdd -> {
behavior.onCreateHabit()
return true
}
R.id.actionCreateBooleanHabit -> { R.id.actionCreateBooleanHabit -> {
behavior.onCreateBooleanHabit() behavior.onCreateBooleanHabit()
return true return true
@ -133,18 +113,5 @@ class ListHabitsMenu @Inject constructor(
} }
} }
/**
* @param enabled whether the create habit menu should be enabled or disabled
* @param menu a reference to the menu on which should be enabled or disabled
*/
fun setCreateHabitMenuEnabled(enabled: Boolean, menu: Menu) {
val habitCreationMenu = menu.findItem(R.id.actionAdd).subMenu
for (itemIndex: Int in 0 until habitCreationMenu.size()) {
val menuItem = habitCreationMenu.getItem(itemIndex)
menuItem.isEnabled = enabled
menuItem.isVisible = enabled
}
}
override fun getMenuResourceId() = R.menu.list_habits override fun getMenuResourceId() = R.menu.list_habits
} }

@ -147,23 +147,6 @@ class ListHabitsScreen
activity.showDialog(dialog, "editHabit") 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 showDeleteConfirmationScreen(callback: OnConfirmedCallback) { override fun showDeleteConfirmationScreen(callback: OnConfirmedCallback) {
activity.showDialog(confirmDeleteDialogFactory.create(callback)) activity.showDialog(confirmDeleteDialogFactory.create(callback))
} }

@ -89,8 +89,6 @@ class SharedPreferencesStorage
preferences.setNotificationsLed(getBoolean(key, false)) preferences.setNotificationsLed(getBoolean(key, false))
"pref_feature_sync" -> "pref_feature_sync" ->
preferences.isSyncEnabled = getBoolean(key, false) preferences.isSyncEnabled = getBoolean(key, false)
"pref_feature_numerical_habits" ->
preferences.isNumericalHabitsFeatureEnabled = getBoolean(key, false)
} }
sharedPreferences.registerOnSharedPreferenceChangeListener(this) sharedPreferences.registerOnSharedPreferenceChangeListener(this)
} }

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

@ -224,17 +224,6 @@ public class Preferences
storage.putBoolean("pref_first_run", isFirstRun); 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);
for (Listener l : listeners) l.onNumericalHabitsFeatureChanged();
}
public boolean isPureBlackEnabled() public boolean isPureBlackEnabled()
{ {
return storage.getBoolean("pref_pure_black", false); return storage.getBoolean("pref_pure_black", false);
@ -347,10 +336,6 @@ public class Preferences
default void onSyncFeatureChanged() default void onSyncFeatureChanged()
{ {
} }
default void onNumericalHabitsFeatureChanged()
{
}
} }
public interface Storage public interface Storage

@ -61,19 +61,6 @@ public class ListHabitsMenuBehavior
updateAdapterFilter(); updateAdapterFilter();
} }
/**
* This function is called when a new habit should be created. (A dialog will be created)
* When only a single type of habit type exists (e.g. the numeral habits feature is disabled) a menu is spawned directly.
* If this is not the case however, a dropdown menu is shown.
*/
public void onCreateHabit()
{
if(!preferences.isNumericalHabitsFeatureEnabled())
{
screen.showCreateHabitScreen();
}
}
public void onCreateBooleanHabit() public void onCreateBooleanHabit()
{ {
screen.showCreateBooleanHabitScreen(); screen.showCreateBooleanHabitScreen();
@ -163,8 +150,6 @@ public class ListHabitsMenuBehavior
void showAboutScreen(); void showAboutScreen();
void showCreateHabitScreen();
void showCreateBooleanHabitScreen(); void showCreateBooleanHabitScreen();
void showCreateNumericalHabitScreen(); void showCreateNumericalHabitScreen();

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

Loading…
Cancel
Save