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