mirror of https://github.com/iSoron/uhabits.git
parent
efd0d1e051
commit
6ba6d7c8c1
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides views that are used across the app, such as RingView.
|
||||
*/
|
||||
package org.isoron.uhabits.ui.common.views;
|
@ -1,104 +0,0 @@
|
||||
/*
|
||||
* 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.ui.habits.show;
|
||||
|
||||
import android.os.*;
|
||||
import android.support.v4.app.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.cards.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
public class ShowHabitFragment extends Fragment
|
||||
{
|
||||
Habit habit;
|
||||
|
||||
protected ShowHabitActivity activity;
|
||||
|
||||
@BindView(R.id.frequencyCard)
|
||||
FrequencyCard frequencyCard;
|
||||
|
||||
@BindView(R.id.streakCard)
|
||||
StreakCard streakCard;
|
||||
|
||||
@BindView(R.id.subtitleCard)
|
||||
SubtitleCard subtitleCard;
|
||||
|
||||
@BindView(R.id.overviewCard)
|
||||
OverviewCard overviewCard;
|
||||
|
||||
@BindView(R.id.strengthCard)
|
||||
ScoreCard scoreCard;
|
||||
|
||||
@BindView(R.id.historyCard)
|
||||
HistoryCard historyCard;
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
// inflater.inflate(R.menu.show_habit_fragment, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater,
|
||||
ViewGroup container,
|
||||
Bundle savedInstanceState)
|
||||
{
|
||||
View view = inflater.inflate(R.layout.show_habit, container, false);
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
activity = (ShowHabitActivity) getActivity();
|
||||
habit = activity.getHabit();
|
||||
|
||||
subtitleCard.setHabit(habit);
|
||||
overviewCard.setHabit(habit);
|
||||
scoreCard.setHabit(habit);
|
||||
historyCard.setHabit(habit);
|
||||
streakCard.setHabit(habit);
|
||||
frequencyCard.setHabit(habit);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.action_edit_habit)
|
||||
return showEditHabitDialog();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private boolean showEditHabitDialog()
|
||||
{
|
||||
if (habit == null) return false;
|
||||
|
||||
BaseDialogFragment frag =
|
||||
EditHabitDialogFragment.newInstance(habit.getId());
|
||||
frag.show(getFragmentManager(), "editHabit");
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.ui.habits.show;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
|
||||
import static org.isoron.uhabits.utils.InterfaceUtils.*;
|
||||
|
||||
public class ShowHabitRootView extends BaseRootView implements ModelObservable.Listener
|
||||
{
|
||||
@NonNull
|
||||
private Habit habit;
|
||||
|
||||
@BindView(R.id.frequencyCard)
|
||||
FrequencyCard frequencyCard;
|
||||
|
||||
@BindView(R.id.streakCard)
|
||||
StreakCard streakCard;
|
||||
|
||||
@BindView(R.id.subtitleCard)
|
||||
SubtitleCard subtitleCard;
|
||||
|
||||
@BindView(R.id.overviewCard)
|
||||
OverviewCard overviewCard;
|
||||
|
||||
@BindView(R.id.strengthCard)
|
||||
ScoreCard scoreCard;
|
||||
|
||||
@BindView(R.id.historyCard)
|
||||
HistoryCard historyCard;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
private final ShowHabitScreen screen;
|
||||
|
||||
public ShowHabitRootView(@NonNull Context context,
|
||||
@NonNull Habit habit,
|
||||
@NonNull ShowHabitScreen screen)
|
||||
{
|
||||
super(context);
|
||||
this.habit = habit;
|
||||
this.screen = screen;
|
||||
|
||||
addView(inflate(getContext(), R.layout.show_habit, null));
|
||||
ButterKnife.bind(this);
|
||||
|
||||
initCards();
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelChange()
|
||||
{
|
||||
post(() -> screen.invalidateToolbar());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow()
|
||||
{
|
||||
super.onAttachedToWindow();
|
||||
habit.getObservable().addListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow()
|
||||
{
|
||||
habit.getObservable().removeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getDisplayHomeAsUp()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Toolbar getToolbar()
|
||||
{
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolbarColor()
|
||||
{
|
||||
if (!getStyledBoolean(getContext(), R.attr.useHabitColorAsPrimary))
|
||||
return super.getToolbarColor();
|
||||
|
||||
return ColorUtils.getColor(getContext(), habit.getColor());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initToolbar()
|
||||
{
|
||||
super.initToolbar();
|
||||
toolbar.setTitle(habit.getName());
|
||||
}
|
||||
|
||||
private void initCards()
|
||||
{
|
||||
subtitleCard.setHabit(habit);
|
||||
overviewCard.setHabit(habit);
|
||||
scoreCard.setHabit(habit);
|
||||
historyCard.setHabit(habit);
|
||||
streakCard.setHabit(habit);
|
||||
frequencyCard.setHabit(habit);
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
/*
|
||||
* 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.ui.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
import android.support.v4.app.*;
|
||||
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
|
||||
public class ShowHabitScreen extends BaseScreen
|
||||
{
|
||||
@NonNull
|
||||
private final Habit habit;
|
||||
|
||||
public ShowHabitScreen(@NonNull BaseActivity activity, @NonNull Habit habit)
|
||||
{
|
||||
super(activity);
|
||||
this.habit = habit;
|
||||
|
||||
ShowHabitRootView view = new ShowHabitRootView(activity, habit, this);
|
||||
ShowHabitsMenu menu = new ShowHabitsMenu(activity, this);
|
||||
|
||||
setRootView(view);
|
||||
setMenu(menu);
|
||||
}
|
||||
|
||||
public void showEditHabitDialog()
|
||||
{
|
||||
FragmentManager manager = activity.getSupportFragmentManager();
|
||||
EditHabitDialogFragment
|
||||
.newInstance(habit.getId())
|
||||
.show(manager, "editHabit");
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* 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.ui.habits.show;
|
||||
|
||||
import android.support.annotation.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
|
||||
public class ShowHabitsMenu extends BaseMenu
|
||||
{
|
||||
@NonNull
|
||||
private final ShowHabitScreen screen;
|
||||
|
||||
public ShowHabitsMenu(@NonNull BaseActivity activity,
|
||||
@NonNull ShowHabitScreen screen)
|
||||
{
|
||||
super(activity);
|
||||
this.screen = screen;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onItemSelected(@NonNull MenuItem item)
|
||||
{
|
||||
switch (item.getItemId())
|
||||
{
|
||||
case R.id.action_edit_habit:
|
||||
screen.showEditHabitDialog();
|
||||
return true;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getMenuResourceId()
|
||||
{
|
||||
return R.menu.show_habit;
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/container"
|
||||
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"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.habits.show.ShowHabitActivity"
|
||||
tools:ignore="MergeRootFrame"
|
||||
tools:menu="show_habit_activity_menu,show_habit_fragment_menu">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/Toolbar"
|
||||
app:popupTheme="?toolbarPopupTheme"/>
|
||||
|
||||
<fragment
|
||||
android:id="@+id/fragment2"
|
||||
android:name="org.isoron.uhabits.ui.habits.show.ShowHabitFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_below="@id/toolbar"
|
||||
android:layout_gravity="center"
|
||||
tools:layout="@layout/show_habit"/>
|
||||
|
||||
<View
|
||||
android:id="@+id/toolbarShadow"
|
||||
style="@style/ToolbarShadow"/>
|
||||
|
||||
</RelativeLayout>
|
@ -0,0 +1,68 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ 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/>.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?windowBackgroundColor"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true"
|
||||
tools:showIn="@layout/show_habit">
|
||||
|
||||
<LinearLayout
|
||||
style="@style/CardList"
|
||||
android:clipToPadding="false">
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.SubtitleCard
|
||||
android:id="@+id/subtitleCard"
|
||||
style="@style/ShowHabit.Subtitle"/>
|
||||
|
||||
<!--<View-->
|
||||
<!--android:id="@+id/headerShadow"-->
|
||||
<!--style="@style/ToolbarShadow"/>-->
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.OverviewCard
|
||||
android:id="@+id/overviewCard"
|
||||
style="@style/Card"
|
||||
android:paddingTop="12dp"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.ScoreCard
|
||||
android:id="@+id/strengthCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.HistoryCard
|
||||
android:id="@+id/historyCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center"
|
||||
android:paddingBottom="0dp"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.StreakCard
|
||||
android:id="@+id/streakCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.FrequencyCard
|
||||
android:id="@+id/frequencyCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
Loading…
Reference in new issue