mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -06:00
Simplify ShowHabitActivity
This commit is contained in:
@@ -118,4 +118,11 @@ abstract public class BaseActivity extends AppCompatActivity
|
||||
{
|
||||
return new BaseExceptionHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
super.onResume();
|
||||
if(screen != null) screen.reattachDialogs();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,6 +46,9 @@ public abstract class BaseRootView extends FrameLayout
|
||||
|
||||
protected boolean shouldDisplayHomeAsUp = false;
|
||||
|
||||
@Nullable
|
||||
private BaseScreen screen;
|
||||
|
||||
public BaseRootView(@NonNull Context context)
|
||||
{
|
||||
super(context);
|
||||
@@ -91,4 +94,15 @@ public abstract class BaseRootView extends FrameLayout
|
||||
if (view != null) view.setVisibility(GONE);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAttachedToScreen(BaseScreen screen)
|
||||
{
|
||||
this.screen = screen;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BaseScreen getScreen()
|
||||
{
|
||||
return screen;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +157,15 @@ public class BaseScreen
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called after activity has been recreated, and the dialogs should be
|
||||
* reattached to their controllers.
|
||||
*/
|
||||
public void reattachDialogs()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the menu to be shown by this screen.
|
||||
* <p>
|
||||
@@ -180,7 +189,7 @@ public class BaseScreen
|
||||
this.rootView = rootView;
|
||||
activity.setContentView(rootView);
|
||||
if (rootView == null) return;
|
||||
|
||||
rootView.onAttachedToScreen(this);
|
||||
invalidateToolbar();
|
||||
}
|
||||
|
||||
|
||||
@@ -34,7 +34,6 @@ import org.isoron.uhabits.core.utils.*;
|
||||
import org.isoron.uhabits.intents.*;
|
||||
import org.isoron.uhabits.io.*;
|
||||
import org.isoron.uhabits.models.sqlite.*;
|
||||
import org.isoron.uhabits.notifications.*;
|
||||
import org.isoron.uhabits.sync.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.widgets.*;
|
||||
@@ -80,8 +79,6 @@ public interface HabitsApplicationComponent
|
||||
|
||||
ReminderScheduler getReminderScheduler();
|
||||
|
||||
RingtoneManager getRingtoneManager();
|
||||
|
||||
SyncManager getSyncManager();
|
||||
|
||||
TaskRunner getTaskRunner();
|
||||
|
||||
@@ -21,6 +21,7 @@ package org.isoron.uhabits.activities;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.about.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.list.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
@@ -33,6 +34,7 @@ import dagger.*;
|
||||
@ActivityScope
|
||||
@Component(modules = {
|
||||
ActivityModule.class,
|
||||
AboutModule.class,
|
||||
HabitsActivityModule.class,
|
||||
ListHabitsModule.class,
|
||||
ShowHabitModule.class,
|
||||
@@ -40,6 +42,10 @@ import dagger.*;
|
||||
}, dependencies = { HabitsApplicationComponent.class })
|
||||
public interface HabitsActivityComponent
|
||||
{
|
||||
AboutRootView getAboutRootView();
|
||||
|
||||
AboutScreen getAboutScreen();
|
||||
|
||||
BaseActivity getActivity();
|
||||
|
||||
CheckmarkButtonControllerFactory getCheckmarkButtonControllerFactory();
|
||||
@@ -48,8 +54,6 @@ public interface HabitsActivityComponent
|
||||
|
||||
HabitCardListAdapter getHabitCardListAdapter();
|
||||
|
||||
HabitCardListController getHabitCardListController();
|
||||
|
||||
ListHabitsController getListHabitsController();
|
||||
|
||||
ListHabitsMenu getListHabitsMenu();
|
||||
@@ -62,12 +66,6 @@ public interface HabitsActivityComponent
|
||||
|
||||
NumberButtonControllerFactory getNumberButtonControllerFactory();
|
||||
|
||||
ShowHabitController getShowHabitController();
|
||||
|
||||
ShowHabitsMenu getShowHabitMenu();
|
||||
|
||||
ShowHabitRootView getShowHabitRootView();
|
||||
|
||||
ShowHabitScreen getShowHabitScreen();
|
||||
|
||||
ThemeSwitcher getThemeSwitcher();
|
||||
|
||||
@@ -21,9 +21,7 @@ package org.isoron.uhabits.activities.about;
|
||||
|
||||
import android.os.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.*;
|
||||
import org.isoron.uhabits.core.ui.screens.about.*;
|
||||
|
||||
/**
|
||||
* Activity that allows the user to see information about the app itself.
|
||||
@@ -35,11 +33,8 @@ public class AboutActivity extends HabitsActivity
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
HabitsApplicationComponent cmp = getAppComponent();
|
||||
AboutScreen screen = new AboutScreen(this, cmp.getIntentFactory());
|
||||
AboutBehavior behavior = new AboutBehavior(cmp.getPreferences(), screen);
|
||||
AboutRootView rootView = new AboutRootView(this, behavior);
|
||||
screen.setRootView(rootView);
|
||||
AboutScreen screen = getActivityComponent().getAboutScreen();
|
||||
screen.setRootView(getActivityComponent().getAboutRootView());
|
||||
setScreen(screen);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* 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.activities.about;
|
||||
|
||||
import org.isoron.uhabits.core.ui.screens.about.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@Module
|
||||
public abstract class AboutModule
|
||||
{
|
||||
@Binds
|
||||
abstract AboutBehavior.Screen getScreen(AboutScreen screen);
|
||||
}
|
||||
@@ -29,6 +29,8 @@ import org.isoron.uhabits.BuildConfig;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.core.ui.screens.about.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
public class AboutRootView extends BaseRootView
|
||||
@@ -39,7 +41,8 @@ public class AboutRootView extends BaseRootView
|
||||
@NonNull
|
||||
private final AboutBehavior behavior;
|
||||
|
||||
public AboutRootView(@NonNull Context context,
|
||||
@Inject
|
||||
public AboutRootView(@NonNull @ActivityContext Context context,
|
||||
@NonNull AboutBehavior behavior)
|
||||
{
|
||||
super(context);
|
||||
|
||||
@@ -64,7 +64,6 @@ public class ListHabitsActivity extends HabitsActivity
|
||||
|
||||
screen.setMenu(menu);
|
||||
screen.setController(controller);
|
||||
screen.setListController(component.getHabitCardListController());
|
||||
screen.setSelectionMenu(selectionMenu);
|
||||
rootView.setController(controller, selectionMenu);
|
||||
|
||||
|
||||
@@ -30,10 +30,9 @@ import android.widget.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.androidbase.utils.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.activities.habits.list.controllers.*;
|
||||
import org.isoron.uhabits.core.commands.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
@@ -48,8 +47,8 @@ import java.util.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import static android.content.DialogInterface.*;
|
||||
import static android.view.inputmethod.EditorInfo.*;
|
||||
import static android.content.DialogInterface.BUTTON_POSITIVE;
|
||||
import static android.view.inputmethod.EditorInfo.IME_ACTION_DONE;
|
||||
|
||||
@ActivityScope
|
||||
public class ListHabitsScreen extends BaseScreen
|
||||
@@ -95,11 +94,6 @@ public class ListHabitsScreen extends BaseScreen
|
||||
@NonNull
|
||||
private Preferences prefs;
|
||||
|
||||
@Nullable
|
||||
private HabitCardListController listController;
|
||||
|
||||
private final ListHabitsRootView rootView;
|
||||
|
||||
@Inject
|
||||
public ListHabitsScreen(@NonNull BaseActivity activity,
|
||||
@NonNull CommandRunner commandRunner,
|
||||
@@ -113,7 +107,6 @@ public class ListHabitsScreen extends BaseScreen
|
||||
{
|
||||
super(activity);
|
||||
setRootView(rootView);
|
||||
this.rootView = rootView;
|
||||
this.prefs = prefs;
|
||||
this.colorPickerFactory = colorPickerFactory;
|
||||
this.commandRunner = commandRunner;
|
||||
@@ -123,11 +116,6 @@ public class ListHabitsScreen extends BaseScreen
|
||||
this.themeSwitcher = themeSwitcher;
|
||||
}
|
||||
|
||||
public void setListController(HabitCardListController listController)
|
||||
{
|
||||
this.listController = listController;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
private Integer getExecuteString(@NonNull Command command)
|
||||
{
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
package org.isoron.uhabits.activities.habits.show;
|
||||
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.activities.*;
|
||||
|
||||
@@ -31,30 +30,10 @@ import org.isoron.uhabits.activities.*;
|
||||
*/
|
||||
public class ShowHabitActivity extends HabitsActivity
|
||||
{
|
||||
|
||||
@Nullable
|
||||
private ShowHabitScreen screen;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
HabitsActivityComponent component = getActivityComponent();
|
||||
screen = component.getShowHabitScreen();
|
||||
screen.setMenu(component.getShowHabitMenu());
|
||||
screen.setController(component.getShowHabitController());
|
||||
component
|
||||
.getShowHabitRootView()
|
||||
.setController(component.getShowHabitController());
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
if (screen == null) throw new IllegalStateException();
|
||||
super.onResume();
|
||||
screen.reattachDialogs();
|
||||
setScreen(getActivityComponent().getShowHabitScreen());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
/*
|
||||
* 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.activities.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.show.views.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class ShowHabitController
|
||||
implements HistoryCard.Controller, HistoryEditorDialog.Controller
|
||||
{
|
||||
private ShowHabitBehavior behavior;
|
||||
|
||||
private ShowHabitScreen screen;
|
||||
|
||||
@Inject
|
||||
public ShowHabitController(@NonNull ShowHabitBehavior behavior,
|
||||
@NonNull ShowHabitScreen screen)
|
||||
{
|
||||
this.behavior = behavior;
|
||||
this.screen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditHistoryButtonClick()
|
||||
{
|
||||
behavior.onEditHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToggleCheckmark(long timestamp)
|
||||
{
|
||||
behavior.onToggleCheckmark(timestamp);
|
||||
}
|
||||
|
||||
public void onToolbarChanged()
|
||||
{
|
||||
screen.invalidateToolbar();
|
||||
}
|
||||
}
|
||||
@@ -66,8 +66,8 @@ public class ShowHabitRootView extends BaseRootView
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
@Nullable
|
||||
private ShowHabitController controller;
|
||||
@NonNull
|
||||
private Controller controller;
|
||||
|
||||
@Inject
|
||||
public ShowHabitRootView(@NonNull @ActivityContext Context context,
|
||||
@@ -79,6 +79,7 @@ public class ShowHabitRootView extends BaseRootView
|
||||
addView(inflate(getContext(), R.layout.show_habit, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
controller = new Controller() {};
|
||||
setDisplayHomeAsUp(true);
|
||||
initCards();
|
||||
initToolbar();
|
||||
@@ -101,10 +102,10 @@ public class ShowHabitRootView extends BaseRootView
|
||||
toolbar.setTitle(habit.getName());
|
||||
});
|
||||
|
||||
if(controller != null) controller.onToolbarChanged();
|
||||
controller.onToolbarChanged();
|
||||
}
|
||||
|
||||
public void setController(@NonNull ShowHabitController controller)
|
||||
public void setController(@NonNull Controller controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
historyCard.setController(controller);
|
||||
@@ -145,4 +146,9 @@ public class ShowHabitRootView extends BaseRootView
|
||||
else
|
||||
barCard.setVisibility(GONE);
|
||||
}
|
||||
|
||||
public interface Controller extends HistoryCard.Controller
|
||||
{
|
||||
default void onToolbarChanged() {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ package org.isoron.uhabits.activities.habits.show;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.activities.common.dialogs.*;
|
||||
import org.isoron.uhabits.activities.habits.edit.*;
|
||||
import org.isoron.uhabits.core.models.*;
|
||||
@@ -30,45 +30,68 @@ import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@ActivityScope
|
||||
public class ShowHabitScreen extends BaseScreen
|
||||
implements ShowHabitMenuBehavior.Screen, ShowHabitBehavior.Screen
|
||||
implements ShowHabitMenuBehavior.Screen,
|
||||
ShowHabitBehavior.Screen,
|
||||
HistoryEditorDialog.Controller,
|
||||
ShowHabitRootView.Controller
|
||||
{
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
@Nullable
|
||||
private ShowHabitController controller;
|
||||
|
||||
@NonNull
|
||||
private final EditHabitDialogFactory editHabitDialogFactory;
|
||||
|
||||
private final Lazy<ShowHabitBehavior> behavior;
|
||||
|
||||
@Inject
|
||||
public ShowHabitScreen(@NonNull BaseActivity activity,
|
||||
@NonNull Habit habit,
|
||||
@NonNull ShowHabitRootView view,
|
||||
@NonNull EditHabitDialogFactory editHabitDialogFactory)
|
||||
@NonNull ShowHabitsMenu menu,
|
||||
@NonNull
|
||||
EditHabitDialogFactory editHabitDialogFactory,
|
||||
@NonNull Lazy<ShowHabitBehavior> behavior)
|
||||
{
|
||||
super(activity);
|
||||
setMenu(menu);
|
||||
setRootView(view);
|
||||
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||
|
||||
this.habit = habit;
|
||||
this.behavior = behavior;
|
||||
this.editHabitDialogFactory = editHabitDialogFactory;
|
||||
view.setController(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEditHistoryButtonClick()
|
||||
{
|
||||
behavior.get().onEditHistory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToggleCheckmark(long timestamp)
|
||||
{
|
||||
behavior.get().onToggleCheckmark(timestamp);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onToolbarChanged()
|
||||
{
|
||||
invalidateToolbar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reattachDialogs()
|
||||
{
|
||||
if (controller == null) throw new IllegalStateException();
|
||||
|
||||
super.reattachDialogs();
|
||||
HistoryEditorDialog historyEditor = (HistoryEditorDialog) activity
|
||||
.getSupportFragmentManager()
|
||||
.findFragmentByTag("historyEditor");
|
||||
|
||||
if (historyEditor != null) historyEditor.setController(controller);
|
||||
}
|
||||
|
||||
public void setController(@NonNull ShowHabitController controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
if (historyEditor != null) historyEditor.setController(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -80,11 +103,9 @@ public class ShowHabitScreen extends BaseScreen
|
||||
@Override
|
||||
public void showEditHistoryScreen()
|
||||
{
|
||||
if (controller == null) throw new IllegalStateException();
|
||||
|
||||
HistoryEditorDialog dialog = new HistoryEditorDialog();
|
||||
dialog.setHabit(habit);
|
||||
dialog.setController(controller);
|
||||
dialog.setController(this);
|
||||
dialog.show(activity.getSupportFragmentManager(), "historyEditor");
|
||||
}
|
||||
|
||||
|
||||
@@ -23,20 +23,22 @@ import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.androidbase.activities.*;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.core.ui.screens.habits.show.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
import dagger.*;
|
||||
|
||||
@ActivityScope
|
||||
public class ShowHabitsMenu extends BaseMenu
|
||||
{
|
||||
@NonNull
|
||||
ShowHabitMenuBehavior behavior;
|
||||
private Lazy<ShowHabitMenuBehavior> behavior;
|
||||
|
||||
@Inject
|
||||
public ShowHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull ShowHabitMenuBehavior behavior)
|
||||
@NonNull Lazy<ShowHabitMenuBehavior> behavior)
|
||||
{
|
||||
super(activity);
|
||||
this.behavior = behavior;
|
||||
@@ -48,11 +50,11 @@ public class ShowHabitsMenu extends BaseMenu
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_edit_habit:
|
||||
behavior.onEditHabit();
|
||||
behavior.get().onEditHabit();
|
||||
return true;
|
||||
|
||||
case R.id.export:
|
||||
behavior.onExportCSV();
|
||||
behavior.get().onExportCSV();
|
||||
return true;
|
||||
|
||||
default:
|
||||
|
||||
@@ -68,7 +68,6 @@ public class HistoryCard extends HabitCard
|
||||
public void setController(@NonNull Controller controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
chart.setController(controller);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -102,7 +101,7 @@ public class HistoryCard extends HabitCard
|
||||
chart.populateWithRandomData();
|
||||
}
|
||||
|
||||
public interface Controller extends HistoryChart.Controller
|
||||
public interface Controller
|
||||
{
|
||||
default void onEditHistoryButtonClick() {}
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.core.preferences.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
public class AboutBehavior
|
||||
{
|
||||
private int developerCountdown = 5;
|
||||
@@ -33,6 +35,7 @@ public class AboutBehavior
|
||||
@NonNull
|
||||
private Screen screen;
|
||||
|
||||
@Inject
|
||||
public AboutBehavior(@NonNull Preferences prefs, @NonNull Screen screen)
|
||||
{
|
||||
this.prefs = prefs;
|
||||
|
||||
Reference in New Issue
Block a user