mirror of https://github.com/iSoron/uhabits.git
parent
94c70485b7
commit
70423ddb0a
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Copyright (C) 2016 Á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;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@ActivityScope
|
||||
public class AndroidThemeSwitcher extends ThemeSwitcher
|
||||
{
|
||||
@NonNull
|
||||
private final BaseActivity activity;
|
||||
|
||||
@Inject
|
||||
public AndroidThemeSwitcher(@NonNull BaseActivity activity,
|
||||
@NonNull Preferences preferences)
|
||||
{
|
||||
super(preferences);
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyDarkTheme()
|
||||
{
|
||||
activity.setTheme(R.style.AppBaseThemeDark);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyLightTheme()
|
||||
{
|
||||
activity.setTheme(R.style.AppBaseTheme);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyPureBlackTheme()
|
||||
{
|
||||
activity.setTheme(R.style.AppBaseThemeDark_PureBlack);
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.ui.callbacks;
|
||||
|
||||
public interface OnColorPickedCallback
|
||||
{
|
||||
void onColorPicked(int color);
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.ui.callbacks;
|
||||
|
||||
public interface OnConfirmedCallback
|
||||
{
|
||||
void onConfirmed();
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.ui.callbacks;
|
||||
|
||||
public interface OnFinishedCallback
|
||||
{
|
||||
void onFinish();
|
||||
}
|
@ -0,0 +1,168 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.ui.screens.habits.list;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.preferences.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ListHabitsMenuBehavior
|
||||
{
|
||||
@NonNull
|
||||
private final Screen screen;
|
||||
|
||||
@NonNull
|
||||
private final Adapter adapter;
|
||||
|
||||
@NonNull
|
||||
private final Preferences preferences;
|
||||
|
||||
@NonNull
|
||||
private final ThemeSwitcher themeSwitcher;
|
||||
|
||||
private boolean showCompleted;
|
||||
|
||||
private boolean showArchived;
|
||||
|
||||
@Inject
|
||||
public ListHabitsMenuBehavior(@NonNull Screen screen,
|
||||
@NonNull Adapter adapter,
|
||||
@NonNull Preferences preferences,
|
||||
@NonNull ThemeSwitcher themeSwitcher)
|
||||
{
|
||||
this.screen = screen;
|
||||
this.adapter = adapter;
|
||||
this.preferences = preferences;
|
||||
this.themeSwitcher = themeSwitcher;
|
||||
|
||||
showCompleted = preferences.getShowCompleted();
|
||||
showArchived = preferences.getShowArchived();
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
public void onCreateHabit()
|
||||
{
|
||||
screen.showCreateHabitScreen();
|
||||
}
|
||||
|
||||
public void onViewFAQ()
|
||||
{
|
||||
screen.showFAQScreen();
|
||||
}
|
||||
|
||||
public void onViewAbout()
|
||||
{
|
||||
screen.showAboutScreen();
|
||||
}
|
||||
|
||||
public void onViewSettings()
|
||||
{
|
||||
screen.showSettingsScreen();
|
||||
}
|
||||
|
||||
public void onToggleShowArchived()
|
||||
{
|
||||
showArchived = !showArchived;
|
||||
preferences.setShowArchived(showArchived);
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
public void onToggleShowCompleted()
|
||||
{
|
||||
showCompleted = !showCompleted;
|
||||
preferences.setShowCompleted(showCompleted);
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
public void onSortByColor()
|
||||
{
|
||||
adapter.setOrder(HabitList.Order.BY_COLOR);
|
||||
}
|
||||
|
||||
public void onSortByManually()
|
||||
{
|
||||
adapter.setOrder(HabitList.Order.BY_POSITION);
|
||||
}
|
||||
|
||||
public void onSortByScore()
|
||||
{
|
||||
adapter.setOrder(HabitList.Order.BY_SCORE);
|
||||
}
|
||||
|
||||
public void onSortByName()
|
||||
{
|
||||
adapter.setOrder(HabitList.Order.BY_NAME);
|
||||
}
|
||||
|
||||
public void onToggleNightMode()
|
||||
{
|
||||
themeSwitcher.toggleNightMode();
|
||||
screen.applyTheme();
|
||||
}
|
||||
|
||||
private void toggleShowArchived()
|
||||
{
|
||||
showArchived = !showArchived;
|
||||
preferences.setShowArchived(showArchived);
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
private void toggleShowCompleted()
|
||||
{
|
||||
showCompleted = !showCompleted;
|
||||
preferences.setShowCompleted(showCompleted);
|
||||
updateAdapterFilter();
|
||||
}
|
||||
|
||||
private void updateAdapterFilter()
|
||||
{
|
||||
adapter.setFilter(new HabitMatcherBuilder()
|
||||
.setArchivedAllowed(showArchived)
|
||||
.setCompletedAllowed(showCompleted)
|
||||
.build());
|
||||
adapter.refresh();
|
||||
}
|
||||
|
||||
public interface Adapter
|
||||
{
|
||||
void refresh();
|
||||
|
||||
void setFilter(HabitMatcher build);
|
||||
|
||||
void setOrder(HabitList.Order order);
|
||||
}
|
||||
|
||||
public interface Screen
|
||||
{
|
||||
void applyTheme();
|
||||
|
||||
void showAboutScreen();
|
||||
|
||||
void showCreateHabitScreen();
|
||||
|
||||
void showFAQScreen();
|
||||
|
||||
void showSettingsScreen();
|
||||
}
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
/*
|
||||
* Copyright (C) 2017 Á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.ui.screens.habits.list;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.commands.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.callbacks.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ListHabitsSelectionMenuBehavior
|
||||
{
|
||||
@NonNull
|
||||
private final Screen screen;
|
||||
|
||||
@NonNull
|
||||
CommandRunner commandRunner;
|
||||
|
||||
@NonNull
|
||||
private final Adapter adapter;
|
||||
|
||||
@NonNull
|
||||
private final HabitList habitList;
|
||||
|
||||
@Inject
|
||||
public ListHabitsSelectionMenuBehavior(@NonNull HabitList habitList,
|
||||
@NonNull Screen screen,
|
||||
@NonNull Adapter adapter,
|
||||
@NonNull CommandRunner commandRunner)
|
||||
{
|
||||
this.habitList = habitList;
|
||||
this.screen = screen;
|
||||
this.adapter = adapter;
|
||||
this.commandRunner = commandRunner;
|
||||
}
|
||||
|
||||
public boolean canArchive()
|
||||
{
|
||||
for (Habit h : adapter.getSelected())
|
||||
if (h.isArchived()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canEdit()
|
||||
{
|
||||
return (adapter.getSelected().size() == 1);
|
||||
}
|
||||
|
||||
public boolean canUnarchive()
|
||||
{
|
||||
for (Habit h : adapter.getSelected())
|
||||
if (!h.isArchived()) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onArchiveHabits()
|
||||
{
|
||||
commandRunner.execute(
|
||||
new ArchiveHabitsCommand(habitList, adapter.getSelected()), null);
|
||||
adapter.clearSelection();
|
||||
}
|
||||
|
||||
public void onChangeColor()
|
||||
{
|
||||
List<Habit> selected = adapter.getSelected();
|
||||
Habit first = selected.get(0);
|
||||
|
||||
screen.showColorPicker(first.getColor(), selectedColor ->
|
||||
{
|
||||
commandRunner.execute(
|
||||
new ChangeHabitColorCommand(habitList, selected, selectedColor),
|
||||
null);
|
||||
adapter.clearSelection();
|
||||
});
|
||||
}
|
||||
|
||||
public void onDeleteHabits()
|
||||
{
|
||||
List<Habit> selected = adapter.getSelected();
|
||||
screen.showDeleteConfirmationScreen(() ->
|
||||
{
|
||||
adapter.performRemove(selected);
|
||||
commandRunner.execute(new DeleteHabitsCommand(habitList, selected),
|
||||
null);
|
||||
adapter.clearSelection();
|
||||
});
|
||||
}
|
||||
|
||||
public void onEditHabits()
|
||||
{
|
||||
screen.showEditHabitsScreen(adapter.getSelected());
|
||||
}
|
||||
|
||||
public void onUnarchiveHabits()
|
||||
{
|
||||
commandRunner.execute(
|
||||
new UnarchiveHabitsCommand(habitList, adapter.getSelected()), null);
|
||||
adapter.clearSelection();
|
||||
}
|
||||
|
||||
public interface Adapter
|
||||
{
|
||||
void clearSelection();
|
||||
|
||||
List<Habit> getSelected();
|
||||
|
||||
void performRemove(List<Habit> selected);
|
||||
}
|
||||
|
||||
public interface Screen
|
||||
{
|
||||
void showColorPicker(int defaultColor,
|
||||
@NonNull OnColorPickedCallback callback);
|
||||
|
||||
void showDeleteConfirmationScreen(
|
||||
@NonNull OnConfirmedCallback callback);
|
||||
|
||||
void showEditHabitsScreen(@NonNull List<Habit> selected);
|
||||
}
|
||||
}
|
Loading…
Reference in new issue