mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Refactor ShowHabit screen; remove fragment
This commit is contained in:
@@ -24,7 +24,7 @@ import android.os.*;
|
||||
import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.ColorUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.util.Log;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.test.suitebuilder.annotation.SmallTest;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -33,9 +33,10 @@ import javax.annotation.*;
|
||||
*/
|
||||
public abstract class BaseMenu
|
||||
{
|
||||
@NonNull
|
||||
private final BaseActivity activity;
|
||||
|
||||
public BaseMenu(BaseActivity activity)
|
||||
public BaseMenu(@NonNull BaseActivity activity)
|
||||
{
|
||||
this.activity = activity;
|
||||
}
|
||||
@@ -85,7 +86,7 @@ public abstract class BaseMenu
|
||||
*/
|
||||
public boolean onItemSelected(@NonNull MenuItem item)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,20 +19,15 @@
|
||||
|
||||
package org.isoron.uhabits.ui;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.content.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.utils.InterfaceUtils;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
public abstract class BaseRootView extends FrameLayout
|
||||
{
|
||||
@@ -44,28 +39,6 @@ public abstract class BaseRootView extends FrameLayout
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public BaseRootView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public BaseRootView(Context context, AttributeSet attrs, int defStyleAttr)
|
||||
{
|
||||
super(context, attrs, defStyleAttr);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
public BaseRootView(Context context,
|
||||
AttributeSet attrs,
|
||||
int defStyleAttr,
|
||||
int defStyleRes)
|
||||
{
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public boolean getDisplayHomeAsUp()
|
||||
{
|
||||
return false;
|
||||
@@ -82,29 +55,22 @@ public abstract class BaseRootView extends FrameLayout
|
||||
|
||||
public int getToolbarColor()
|
||||
{
|
||||
// if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP)
|
||||
// {
|
||||
// if (InterfaceUtils.isNightMode()) return;
|
||||
// int color = activity.getResources().getColor(R.color.grey_900);
|
||||
// }
|
||||
// if (!InterfaceUtils.getStyledBoolean(activity, R.attr.useHabitColorAsPrimary)) return;
|
||||
return Color.BLACK;
|
||||
if ((Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) &&
|
||||
!InterfaceUtils.isNightMode())
|
||||
{
|
||||
return getContext().getResources().getColor(R.color.grey_900);
|
||||
}
|
||||
|
||||
private void hideFakeToolbarShadow()
|
||||
{
|
||||
View view = findViewById(R.id.toolbarShadow);
|
||||
if (view != null) view.setVisibility(View.GONE);
|
||||
|
||||
// view = findViewById(R.id.headerShadow);
|
||||
// if (view != null) view.setVisibility(View.GONE);
|
||||
return InterfaceUtils.getStyledColor(getContext(), R.attr.colorPrimary);
|
||||
}
|
||||
|
||||
protected void initToolbar()
|
||||
{
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
|
||||
{
|
||||
getToolbar().setElevation(InterfaceUtils.dpToPixels(context, 2));
|
||||
|
||||
hideFakeToolbarShadow();
|
||||
View view = findViewById(R.id.toolbarShadow);
|
||||
if (view != null) view.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,13 +56,13 @@ public abstract class BaseScreen
|
||||
@Nullable
|
||||
private BaseSelectionMenu selectionMenu;
|
||||
|
||||
public BaseScreen(BaseActivity activity)
|
||||
public BaseScreen(@NonNull BaseActivity activity)
|
||||
{
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void setupActionBarColor(AppCompatActivity activity,
|
||||
public static void setupActionBarColor(@NonNull AppCompatActivity activity,
|
||||
int color)
|
||||
{
|
||||
|
||||
@@ -166,7 +166,7 @@ public abstract class BaseScreen
|
||||
activity.setContentView(rootView);
|
||||
if (rootView == null) return;
|
||||
|
||||
initToolbar();
|
||||
invalidateToolbar();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -230,7 +230,7 @@ public abstract class BaseScreen
|
||||
dialog.show(activity.getSupportFragmentManager(), tag);
|
||||
}
|
||||
|
||||
private void initToolbar()
|
||||
public void invalidateToolbar()
|
||||
{
|
||||
if (rootView == null) return;
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.animation.*;
|
||||
import android.content.*;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.charts;
|
||||
package org.isoron.uhabits.ui.common.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.graphics.*;
|
||||
@@ -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;
|
||||
@@ -33,7 +33,7 @@ import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.HabitList;
|
||||
import org.isoron.uhabits.tasks.BaseTask;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.HistoryChart;
|
||||
import org.isoron.uhabits.ui.common.views.HistoryChart;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
||||
@@ -97,12 +97,6 @@ public class ListHabitsRootView extends BaseRootView
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolbarColor()
|
||||
{
|
||||
return InterfaceUtils.getStyledColor(getContext(), R.attr.colorPrimary);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModelChange()
|
||||
{
|
||||
|
||||
@@ -19,35 +19,26 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Handler;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.content.*;
|
||||
import android.net.*;
|
||||
import android.os.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.app.*;
|
||||
|
||||
import com.android.colorpicker.ColorPickerDialog;
|
||||
import com.android.colorpicker.*;
|
||||
|
||||
import org.isoron.uhabits.HabitsApplication;
|
||||
import org.isoron.uhabits.MainActivity;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.BaseActivity;
|
||||
import org.isoron.uhabits.ui.BaseScreen;
|
||||
import org.isoron.uhabits.ui.about.AboutActivity;
|
||||
import org.isoron.uhabits.ui.habits.edit.BaseDialogFragment;
|
||||
import org.isoron.uhabits.ui.habits.edit.CreateHabitDialogFragment;
|
||||
import org.isoron.uhabits.ui.habits.edit.EditHabitDialogFragment;
|
||||
import org.isoron.uhabits.ui.habits.list.model.HabitCardListAdapter;
|
||||
import org.isoron.uhabits.ui.habits.show.ShowHabitActivity;
|
||||
import org.isoron.uhabits.ui.intro.IntroActivity;
|
||||
import org.isoron.uhabits.ui.settings.FilePickerDialog;
|
||||
import org.isoron.uhabits.ui.settings.SettingsActivity;
|
||||
import org.isoron.uhabits.utils.ColorUtils;
|
||||
import org.isoron.uhabits.utils.FileUtils;
|
||||
import org.isoron.uhabits.utils.InterfaceUtils;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.ui.about.*;
|
||||
import org.isoron.uhabits.ui.habits.edit.*;
|
||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||
import org.isoron.uhabits.ui.habits.show.*;
|
||||
import org.isoron.uhabits.ui.intro.*;
|
||||
import org.isoron.uhabits.ui.settings.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.*;
|
||||
|
||||
public class ListHabitsScreen extends BaseScreen
|
||||
{
|
||||
@@ -72,12 +63,18 @@ public class ListHabitsScreen extends BaseScreen
|
||||
setMenu(menu);
|
||||
setSelectionMenu(selectionMenu);
|
||||
|
||||
HabitCardListAdapter adapter = new HabitCardListAdapter(
|
||||
ListHabitsRootView.MAX_CHECKMARK_COUNT);
|
||||
HabitCardListAdapter adapter =
|
||||
new HabitCardListAdapter(ListHabitsRootView.MAX_CHECKMARK_COUNT);
|
||||
rootView.setListAdapter(adapter);
|
||||
selectionMenu.setListAdapter(adapter);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ListHabitsRootView getRootView()
|
||||
{
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
@@ -229,10 +226,4 @@ public class ListHabitsScreen extends BaseScreen
|
||||
{
|
||||
void onColorSelected(int color);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ListHabitsRootView getRootView()
|
||||
{
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,8 +29,8 @@ import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -22,12 +22,11 @@ package org.isoron.uhabits.ui.habits.show;
|
||||
import android.content.*;
|
||||
import android.net.*;
|
||||
import android.os.*;
|
||||
import android.support.v7.app.*;
|
||||
import android.support.annotation.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import javax.inject.*;
|
||||
|
||||
@@ -38,39 +37,26 @@ import javax.inject.*;
|
||||
*/
|
||||
public class ShowHabitActivity extends BaseActivity
|
||||
{
|
||||
private Habit habit;
|
||||
|
||||
@Inject
|
||||
HabitList habitList;
|
||||
|
||||
public Habit getHabit()
|
||||
{
|
||||
return habit;
|
||||
}
|
||||
|
||||
public void setupHabitActionBar()
|
||||
{
|
||||
if (habit == null) return;
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if (actionBar == null) return;
|
||||
|
||||
actionBar.setTitle(habit.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
HabitsApplication.getComponent().inject(this);
|
||||
|
||||
Habit habit = getHabitFromIntent();
|
||||
ShowHabitScreen screen = new ShowHabitScreen(this, habit);
|
||||
setScreen(screen);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private Habit getHabitFromIntent()
|
||||
{
|
||||
Uri data = getIntent().getData();
|
||||
habit = habitList.getById(ContentUris.parseId(data));
|
||||
|
||||
setContentView(R.layout.show_habit_activity);
|
||||
BaseScreen.setupActionBarColor(this,
|
||||
ColorUtils.getColor(this, habit.getColor()));
|
||||
|
||||
setupHabitActionBar();
|
||||
Habit habit = habitList.getById(ContentUris.parseId(data));
|
||||
if (habit == null) throw new RuntimeException("habit not found");
|
||||
return habit;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,7 @@
|
||||
*/
|
||||
|
||||
/**
|
||||
* Provides activity that display detailed habit information and related
|
||||
* Provides activity that displays detailed habit information and related
|
||||
* classes.
|
||||
*/
|
||||
package org.isoron.uhabits.ui.habits.show;
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.util.*;
|
||||
@@ -26,7 +26,7 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -53,12 +53,18 @@ public class FrequencyCard extends HabitCard
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
new RefreshTask().execute();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
inflate(getContext(), R.layout.show_habit_frequency, this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
if(isInEditMode()) initEditMode();
|
||||
if (isInEditMode()) initEditMode();
|
||||
}
|
||||
|
||||
private void initEditMode()
|
||||
@@ -69,24 +75,24 @@ public class FrequencyCard extends HabitCard
|
||||
chart.populateWithRandomData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
|
||||
new BaseTask()
|
||||
private class RefreshTask extends BaseTask
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
RepetitionList reps = habit.getRepetitions();
|
||||
RepetitionList reps = getHabit().getRepetitions();
|
||||
HashMap<Long, Integer[]> frequency = reps.getWeekdayFrequency();
|
||||
chart.setFrequency(frequency);
|
||||
}
|
||||
}.execute();
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
super.onPreExecute();
|
||||
int color =
|
||||
ColorUtils.getColor(getContext(), getHabit().getColor());
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
@@ -61,7 +61,7 @@ public abstract class HabitCard extends LinearLayout
|
||||
@Override
|
||||
public void onModelChange()
|
||||
{
|
||||
refreshData();
|
||||
post(() -> refreshData());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.util.*;
|
||||
@@ -26,7 +26,7 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
@@ -61,6 +61,31 @@ public class HistoryCard extends HabitCard
|
||||
// frag.show(getContext().getFragmentManager(), "historyEditor");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
int checkmarks[] = habit.getCheckmarks().getAllValues();
|
||||
chart.setCheckmarks(checkmarks);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
super.onPreExecute();
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
inflate(getContext(), R.layout.show_habit_history, this);
|
||||
@@ -76,24 +101,4 @@ public class HistoryCard extends HabitCard
|
||||
chart.setColor(color);
|
||||
chart.populateWithRandomData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
|
||||
title.setTextColor(color);
|
||||
chart.setColor(color);
|
||||
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
int checkmarks[] = habit.getCheckmarks().getAllValues();
|
||||
chart.setCheckmarks(checkmarks);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
@@ -27,7 +27,7 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import butterknife.*;
|
||||
@@ -69,33 +69,7 @@ public class OverviewCard extends HabitCard
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
refreshColors();
|
||||
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
ScoreList scores = habit.getScores();
|
||||
|
||||
long today = DateUtils.getStartOfToday();
|
||||
long lastMonth = today - 30 * DateUtils.millisecondsInOneDay;
|
||||
long lastYear = today - 365 * DateUtils.millisecondsInOneDay;
|
||||
|
||||
cache.todayScore = (float) scores.getTodayValue();
|
||||
cache.lastMonthScore = (float) scores.getValue(lastMonth);
|
||||
cache.lastYearScore = (float) scores.getValue(lastYear);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
refreshScore();
|
||||
super.onPostExecute(aVoid);
|
||||
}
|
||||
}.execute();
|
||||
new RefreshTask().execute();
|
||||
}
|
||||
|
||||
private String formatPercentageDiff(float percentageDiff)
|
||||
@@ -161,4 +135,36 @@ public class OverviewCard extends HabitCard
|
||||
|
||||
public float lastYearScore;
|
||||
}
|
||||
|
||||
private class RefreshTask extends BaseTask
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
ScoreList scores = getHabit().getScores();
|
||||
|
||||
long today = DateUtils.getStartOfToday();
|
||||
long lastMonth = today - 30 * DateUtils.millisecondsInOneDay;
|
||||
long lastYear = today - 365 * DateUtils.millisecondsInOneDay;
|
||||
|
||||
cache.todayScore = (float) scores.getTodayValue();
|
||||
cache.lastMonthScore = (float) scores.getValue(lastMonth);
|
||||
cache.lastYearScore = (float) scores.getValue(lastYear);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid)
|
||||
{
|
||||
refreshScore();
|
||||
super.onPostExecute(aVoid);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
super.onPreExecute();
|
||||
color = ColorUtils.getColor(getContext(), getHabit().getColor());
|
||||
refreshColors();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.support.annotation.*;
|
||||
@@ -27,7 +27,7 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -71,26 +71,7 @@ public class ScoreCard extends HabitCard
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
|
||||
title.setTextColor(color);
|
||||
chart.setPrimaryColor(color);
|
||||
|
||||
new BaseTask()
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
List<Score> scores;
|
||||
|
||||
if (bucketSize == 1) scores = habit.getScores().getAll();
|
||||
else scores = habit.getScores().groupBy(getTruncateField());
|
||||
|
||||
chart.setScores(scores);
|
||||
chart.setBucketSize(bucketSize);
|
||||
}
|
||||
}.execute();
|
||||
new RefreshTask().execute();
|
||||
}
|
||||
|
||||
private int getDefaultSpinnerPosition()
|
||||
@@ -138,4 +119,29 @@ public class ScoreCard extends HabitCard
|
||||
InterfaceUtils.setDefaultScoreSpinnerPosition(getContext(), position);
|
||||
bucketSize = BUCKET_SIZES[position];
|
||||
}
|
||||
|
||||
private class RefreshTask extends BaseTask
|
||||
{
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
List<Score> scores;
|
||||
|
||||
if (bucketSize == 1) scores = getHabit().getScores().getAll();
|
||||
else scores = getHabit().getScores().groupBy(getTruncateField());
|
||||
|
||||
chart.setScores(scores);
|
||||
chart.setBucketSize(bucketSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
super.onPreExecute();
|
||||
int color =
|
||||
ColorUtils.getColor(getContext(), getHabit().getColor());
|
||||
title.setTextColor(color);
|
||||
chart.setPrimaryColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.content.*;
|
||||
import android.util.*;
|
||||
@@ -26,7 +26,7 @@ import android.widget.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.tasks.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -35,6 +35,8 @@ import butterknife.*;
|
||||
|
||||
public class StreakCard extends HabitCard
|
||||
{
|
||||
public static final int NUM_STREAKS = 10;
|
||||
|
||||
@BindView(R.id.title)
|
||||
TextView title;
|
||||
|
||||
@@ -53,12 +55,18 @@ public class StreakCard extends HabitCard
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
new MyBaseTask().execute();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
inflate(getContext(), R.layout.show_habit_streak, this);
|
||||
ButterKnife.bind(this);
|
||||
setOrientation(VERTICAL);
|
||||
if(isInEditMode()) initEditMode();
|
||||
if (isInEditMode()) initEditMode();
|
||||
}
|
||||
|
||||
private void initEditMode()
|
||||
@@ -69,23 +77,14 @@ public class StreakCard extends HabitCard
|
||||
streakChart.populateWithRandomData();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
Habit habit = getHabit();
|
||||
int color = ColorUtils.getColor(getContext(), habit.getColor());
|
||||
|
||||
title.setTextColor(color);
|
||||
streakChart.setColor(color);
|
||||
|
||||
new BaseTask()
|
||||
private class MyBaseTask extends BaseTask
|
||||
{
|
||||
public List<Streak> streaks;
|
||||
|
||||
@Override
|
||||
protected void doInBackground()
|
||||
{
|
||||
streaks = habit.getStreaks().getBest(10);
|
||||
streaks = getHabit().getStreaks().getBest(NUM_STREAKS);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -94,6 +93,15 @@ public class StreakCard extends HabitCard
|
||||
streakChart.setStreaks(streaks);
|
||||
super.onPostExecute(aVoid);
|
||||
}
|
||||
}.execute();
|
||||
|
||||
@Override
|
||||
protected void onPreExecute()
|
||||
{
|
||||
super.onPreExecute();
|
||||
int color =
|
||||
ColorUtils.getColor(getContext(), getHabit().getColor());
|
||||
title.setTextColor(color);
|
||||
streakChart.setColor(color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,13 +17,12 @@
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.isoron.uhabits.ui.habits.show.views.cards;
|
||||
package org.isoron.uhabits.ui.habits.show.views;
|
||||
|
||||
import android.annotation.*;
|
||||
import android.content.*;
|
||||
import android.content.res.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
@@ -55,23 +54,6 @@ public class SubtitleCard extends HabitCard
|
||||
init();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
Context context = getContext();
|
||||
inflate(context, R.layout.show_habit_subtitle, this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
if (isInEditMode()) initEditMode();
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void initEditMode()
|
||||
{
|
||||
questionLabel.setTextColor(ColorUtils.getAndroidTestColor(1));
|
||||
questionLabel.setText("Have you meditated today?");
|
||||
reminderLabel.setText("08:00");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void refreshData()
|
||||
{
|
||||
@@ -87,10 +69,26 @@ public class SubtitleCard extends HabitCard
|
||||
|
||||
if (habit.hasReminder()) updateReminderText(habit.getReminder());
|
||||
|
||||
if (habit.getDescription().isEmpty())
|
||||
questionLabel.setVisibility(View.GONE);
|
||||
if (habit.getDescription().isEmpty()) questionLabel.setVisibility(GONE);
|
||||
|
||||
postInvalidate();
|
||||
invalidate();
|
||||
}
|
||||
|
||||
private void init()
|
||||
{
|
||||
Context context = getContext();
|
||||
inflate(context, R.layout.show_habit_subtitle, this);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
if (isInEditMode()) initEditMode();
|
||||
}
|
||||
|
||||
@SuppressLint("SetTextI18n")
|
||||
private void initEditMode()
|
||||
{
|
||||
questionLabel.setTextColor(ColorUtils.getAndroidTestColor(1));
|
||||
questionLabel.setText("Have you meditated today?");
|
||||
reminderLabel.setText("08:00");
|
||||
}
|
||||
|
||||
private String toText(Frequency freq)
|
||||
@@ -24,7 +24,7 @@ import android.view.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.widgets.views.*;
|
||||
|
||||
public class CheckmarkWidgetProvider extends BaseWidgetProvider
|
||||
|
||||
@@ -26,7 +26,7 @@ import android.view.*;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
|
||||
public class FrequencyWidgetProvider extends BaseWidgetProvider
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.view.*;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
|
||||
public class HistoryWidgetProvider extends BaseWidgetProvider
|
||||
{
|
||||
|
||||
@@ -25,8 +25,8 @@ import android.view.*;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.cards.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
public class ScoreWidgetProvider extends BaseWidgetProvider
|
||||
|
||||
@@ -25,7 +25,7 @@ import android.view.*;
|
||||
import org.apache.commons.lang3.*;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
|
||||
public class StreakWidgetProvider extends BaseWidgetProvider
|
||||
{
|
||||
|
||||
@@ -30,8 +30,8 @@ import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Checkmark;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.models.Score;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.HabitChart;
|
||||
import org.isoron.uhabits.ui.habits.show.views.RingView;
|
||||
import org.isoron.uhabits.ui.common.views.HabitChart;
|
||||
import org.isoron.uhabits.ui.common.views.RingView;
|
||||
import org.isoron.uhabits.utils.ColorUtils;
|
||||
import org.isoron.uhabits.utils.InterfaceUtils;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import android.widget.TextView;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.HabitChart;
|
||||
import org.isoron.uhabits.ui.common.views.HabitChart;
|
||||
|
||||
public class GraphWidgetView extends HabitWidgetView implements HabitChart
|
||||
{
|
||||
|
||||
@@ -30,7 +30,7 @@ import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.models.*;
|
||||
import org.isoron.uhabits.ui.habits.show.views.charts.*;
|
||||
import org.isoron.uhabits.ui.common.views.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
style="@style/ListHabits.HabitCard"
|
||||
android:layout_width="match_parent">
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.RingView
|
||||
<org.isoron.uhabits.ui.common.views.RingView
|
||||
android:id="@+id/scoreRing"
|
||||
android:layout_width="15dp"
|
||||
android:layout_height="15dp"
|
||||
|
||||
@@ -17,50 +17,23 @@
|
||||
~ with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<ScrollView
|
||||
<LinearLayout
|
||||
android:id="@+id/container"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?windowBackgroundColor"
|
||||
android:clipToPadding="false"
|
||||
android:fillViewport="true">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/Toolbar"
|
||||
app:popupTheme="?toolbarPopupTheme"/>
|
||||
|
||||
<LinearLayout
|
||||
style="@style/CardList"
|
||||
android:clipToPadding="false">
|
||||
<View
|
||||
android:id="@+id/toolbarShadow"
|
||||
style="@style/ToolbarShadow"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.SubtitleCard
|
||||
style="@style/ShowHabit.Subtitle"
|
||||
android:id="@+id/subtitleCard"/>
|
||||
|
||||
<!--<View-->
|
||||
<!--android:id="@+id/headerShadow"-->
|
||||
<!--style="@style/ToolbarShadow"/>-->
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.OverviewCard
|
||||
android:id="@+id/overviewCard"
|
||||
android:paddingTop="12dp"
|
||||
style="@style/Card" />
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.ScoreCard
|
||||
android:id="@+id/strengthCard"
|
||||
style="@style/Card"
|
||||
android:gravity="center" />
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.HistoryCard
|
||||
android:id="@+id/historyCard"
|
||||
style="@style/Card"
|
||||
android:paddingBottom="0dp"
|
||||
android:gravity="center" />
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.StreakCard
|
||||
android:id="@+id/streakCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.cards.FrequencyCard
|
||||
android:id="@+id/frequencyCard"
|
||||
style="@style/Card"/>
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
<!-- Separate file so that we can use the layout editor to preview it -->
|
||||
<include layout="@layout/show_habit_inner"/>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -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>
|
||||
@@ -24,7 +24,7 @@
|
||||
style="@style/CardHeader"
|
||||
android:text="@string/frequency"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.charts.FrequencyChart
|
||||
<org.isoron.uhabits.ui.common.views.FrequencyChart
|
||||
android:id="@+id/frequencyChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"/>
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
style="@style/CardHeader"
|
||||
android:text="@string/history"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.charts.HistoryChart
|
||||
<org.isoron.uhabits.ui.common.views.HistoryChart
|
||||
android:id="@+id/historyChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="160dp"/>
|
||||
|
||||
68
app/src/main/res/layout/show_habit_inner.xml
Normal file
68
app/src/main/res/layout/show_habit_inner.xml
Normal file
@@ -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>
|
||||
@@ -38,7 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="5">
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.RingView
|
||||
<org.isoron.uhabits.ui.common.views.RingView
|
||||
android:id="@+id/scoreRing"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="30dp"
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
android:layout_alignParentTop="true"
|
||||
android:text="@string/habit_strength"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.charts.ScoreChart
|
||||
<org.isoron.uhabits.ui.common.views.ScoreChart
|
||||
android:id="@+id/scoreView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="220dp"
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
style="@style/CardHeader"
|
||||
android:text="@string/best_streaks"/>
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.charts.StreakChart
|
||||
<org.isoron.uhabits.ui.common.views.StreakChart
|
||||
android:id="@+id/streakChart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="200dp"/>
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<org.isoron.uhabits.ui.habits.show.views.RingView
|
||||
<org.isoron.uhabits.ui.common.views.RingView
|
||||
android:id="@+id/scoreRing"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
|
||||
Reference in New Issue
Block a user