mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Implement dummy history editor; add edit history button
This commit is contained in:
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* 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.dialogs;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
|
import android.app.Dialog;
|
||||||
|
import android.app.DialogFragment;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
import org.isoron.uhabits.views.HabitHistoryView;
|
||||||
|
|
||||||
|
public class HistoryEditorDialog extends DialogFragment
|
||||||
|
implements DialogInterface.OnClickListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public Dialog onCreateDialog(Bundle savedInstanceState)
|
||||||
|
{
|
||||||
|
Context context = getActivity();
|
||||||
|
|
||||||
|
int p = (int) getResources().getDimension(R.dimen.history_editor_padding);
|
||||||
|
|
||||||
|
HabitHistoryView historyView = new HabitHistoryView(context, null);
|
||||||
|
historyView.setHabit(Habit.get(4L));
|
||||||
|
historyView.setPadding(p, 0, p, 0);
|
||||||
|
|
||||||
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
|
builder.setTitle("History Editor")
|
||||||
|
.setView(historyView)
|
||||||
|
.setPositiveButton(android.R.string.ok, this);
|
||||||
|
|
||||||
|
return builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume()
|
||||||
|
{
|
||||||
|
super.onResume();
|
||||||
|
|
||||||
|
DisplayMetrics metrics = getResources().getDisplayMetrics();
|
||||||
|
int maxHeight = getResources().getDimensionPixelSize(R.dimen.history_editor_max_height);
|
||||||
|
int width = metrics.widthPixels;
|
||||||
|
int height = Math.min(metrics.heightPixels, maxHeight);
|
||||||
|
|
||||||
|
Log.d("HistoryEditorDialog", String.format("h=%d max_h=%d", height, maxHeight));
|
||||||
|
|
||||||
|
getDialog().getWindow().setLayout(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClick(DialogInterface dialog, int which)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -28,6 +28,7 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.isoron.helpers.ColorHelper;
|
import org.isoron.helpers.ColorHelper;
|
||||||
@@ -35,6 +36,7 @@ import org.isoron.helpers.Command;
|
|||||||
import org.isoron.helpers.DialogHelper;
|
import org.isoron.helpers.DialogHelper;
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.ShowHabitActivity;
|
import org.isoron.uhabits.ShowHabitActivity;
|
||||||
|
import org.isoron.uhabits.dialogs.HistoryEditorDialog;
|
||||||
import org.isoron.uhabits.helpers.ReminderHelper;
|
import org.isoron.uhabits.helpers.ReminderHelper;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
import org.isoron.uhabits.models.Score;
|
import org.isoron.uhabits.models.Score;
|
||||||
@@ -75,6 +77,7 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
|||||||
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
|
TextView tvStrength = (TextView) view.findViewById(R.id.tvStrength);
|
||||||
TextView tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
|
TextView tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
|
||||||
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
||||||
|
Button btEditHistory = (Button) view.findViewById(R.id.btEditHistory);
|
||||||
HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView);
|
HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView);
|
||||||
HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
||||||
HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
|
HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
|
||||||
@@ -90,6 +93,16 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
|||||||
scoreView.setHabit(habit);
|
scoreView.setHabit(habit);
|
||||||
historyView.setHabit(habit);
|
historyView.setHabit(habit);
|
||||||
|
|
||||||
|
btEditHistory.setOnClickListener(new View.OnClickListener()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void onClick(View v)
|
||||||
|
{
|
||||||
|
HistoryEditorDialog frag = new HistoryEditorDialog();
|
||||||
|
frag.show(getFragmentManager(), "dialog");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.util.AttributeSet;
|
|||||||
|
|
||||||
import org.isoron.helpers.ColorHelper;
|
import org.isoron.helpers.ColorHelper;
|
||||||
import org.isoron.helpers.DateHelper;
|
import org.isoron.helpers.DateHelper;
|
||||||
|
import org.isoron.uhabits.R;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
@@ -50,7 +51,6 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
private int columnWidth;
|
private int columnWidth;
|
||||||
private int columnHeight;
|
private int columnHeight;
|
||||||
private int nColumns;
|
private int nColumns;
|
||||||
private int baseSize;
|
|
||||||
|
|
||||||
private String wdays[];
|
private String wdays[];
|
||||||
private SimpleDateFormat dfMonth;
|
private SimpleDateFormat dfMonth;
|
||||||
@@ -70,6 +70,7 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.primaryColor = ColorHelper.palette[7];
|
this.primaryColor = ColorHelper.palette[7];
|
||||||
|
this.checkmarks = new int[0];
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,6 +84,7 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
|
fetchData();
|
||||||
createPaints();
|
createPaints();
|
||||||
createColors();
|
createColors();
|
||||||
|
|
||||||
@@ -117,23 +119,42 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
||||||
{
|
{
|
||||||
if(height < 8) height = 200;
|
if(height < 8) height = 200;
|
||||||
|
int baseSize = height / 8;
|
||||||
baseSize = height / 8;
|
|
||||||
setScrollerBucketSize(baseSize);
|
setScrollerBucketSize(baseSize);
|
||||||
|
|
||||||
columnWidth = baseSize;
|
|
||||||
columnHeight = 8 * baseSize;
|
|
||||||
nColumns = width / baseSize;
|
|
||||||
|
|
||||||
squareSpacing = (int) Math.floor(baseSize / 15.0);
|
squareSpacing = (int) Math.floor(baseSize / 15.0);
|
||||||
pSquareFg.setTextSize(baseSize * 0.5f);
|
int maxTextSize = getResources().getDimensionPixelSize(R.dimen.history_max_font_size);
|
||||||
pTextHeader.setTextSize(baseSize * 0.5f);
|
float textSize = Math.min(baseSize * 0.5f, maxTextSize);
|
||||||
|
|
||||||
|
pSquareFg.setTextSize(textSize);
|
||||||
|
pTextHeader.setTextSize(textSize);
|
||||||
squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
|
squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
|
||||||
headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
|
headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
|
||||||
|
|
||||||
|
int rightLabelWidth = getWeekdayLabelWidth();
|
||||||
|
int horizontalPadding = getPaddingRight() + getPaddingLeft();
|
||||||
|
|
||||||
|
columnWidth = baseSize;
|
||||||
|
columnHeight = 8 * baseSize;
|
||||||
|
nColumns = (width - rightLabelWidth - horizontalPadding) / baseSize + 1;
|
||||||
|
|
||||||
updateDate();
|
updateDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getWeekdayLabelWidth()
|
||||||
|
{
|
||||||
|
int width = 0;
|
||||||
|
Rect bounds = new Rect();
|
||||||
|
|
||||||
|
for(String w : wdays)
|
||||||
|
{
|
||||||
|
pSquareFg.getTextBounds(w, 0, w.length(), bounds);
|
||||||
|
width = Math.max(width, bounds.right);
|
||||||
|
}
|
||||||
|
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
private void createColors()
|
private void createColors()
|
||||||
{
|
{
|
||||||
if(habit != null)
|
if(habit != null)
|
||||||
@@ -185,12 +206,7 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
generateRandomData();
|
generateRandomData();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(habit == null)
|
if(habit == null) return;
|
||||||
{
|
|
||||||
checkmarks = new int[0];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkmarks = habit.checkmarks.getAllValues();
|
checkmarks = habit.checkmarks.getAllValues();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,6 +242,7 @@ public class HabitHistoryView extends ScrollableDataView
|
|||||||
super.onDraw(canvas);
|
super.onDraw(canvas);
|
||||||
|
|
||||||
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
||||||
|
baseLocation.offset(getPaddingLeft(), getPaddingTop());
|
||||||
|
|
||||||
previousMonth = "";
|
previousMonth = "";
|
||||||
previousYear = "";
|
previousYear = "";
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ public class HabitScoreView extends ScrollableDataView
|
|||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.primaryColor = ColorHelper.palette[7];
|
this.primaryColor = ColorHelper.palette[7];
|
||||||
|
this.scores = new int[0];
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +85,7 @@ public class HabitScoreView extends ScrollableDataView
|
|||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
|
fetchData();
|
||||||
createPaints();
|
createPaints();
|
||||||
createColors();
|
createColors();
|
||||||
|
|
||||||
@@ -168,12 +170,7 @@ public class HabitScoreView extends ScrollableDataView
|
|||||||
generateRandomData();
|
generateRandomData();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (habit == null)
|
if (habit == null) return;
|
||||||
{
|
|
||||||
scores = new int[0];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
|
scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,6 +65,7 @@ public class HabitStreakView extends ScrollableDataView
|
|||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.primaryColor = ColorHelper.palette[7];
|
this.primaryColor = ColorHelper.palette[7];
|
||||||
|
startTimes = endTimes = lengths = new long[0];
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +80,7 @@ public class HabitStreakView extends ScrollableDataView
|
|||||||
|
|
||||||
private void init()
|
private void init()
|
||||||
{
|
{
|
||||||
|
fetchData();
|
||||||
createPaints();
|
createPaints();
|
||||||
createColors();
|
createColors();
|
||||||
|
|
||||||
@@ -163,11 +165,7 @@ public class HabitStreakView extends ScrollableDataView
|
|||||||
generateRandomData();
|
generateRandomData();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if(habit == null)
|
if(habit == null) return;
|
||||||
{
|
|
||||||
startTimes = endTimes = lengths = new long[0];
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Streak> streaks = habit.streaks.getAll();
|
List<Streak> streaks = habit.streaks.getAll();
|
||||||
int size = streaks.size();
|
int size = streaks.size();
|
||||||
|
|||||||
@@ -18,8 +18,8 @@
|
|||||||
-->
|
-->
|
||||||
|
|
||||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
xmlns:app="http://isoron.org/android"
|
xmlns:app="http://isoron.org/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:background="@color/windowBackground"
|
android:background="@color/windowBackground"
|
||||||
@@ -60,24 +60,32 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout style="@style/cardStyle">
|
<LinearLayout
|
||||||
|
style="@style/cardStyle"
|
||||||
|
android:paddingBottom="0dp"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/tvHistory"
|
android:id="@+id/tvHistory"
|
||||||
style="@style/cardHeaderStyle"
|
style="@style/cardHeaderStyle"
|
||||||
android:text="@string/history"/>
|
android:text="@string/history"/>
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:id="@+id/llHistory"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="horizontal"/>
|
|
||||||
|
|
||||||
<org.isoron.uhabits.views.HabitHistoryView
|
<org.isoron.uhabits.views.HabitHistoryView
|
||||||
android:id="@+id/historyView"
|
android:id="@+id/historyView"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="160dp" />
|
android:layout_height="160dp" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
style="?android:borderlessButtonStyle"
|
||||||
|
android:id="@+id/btEditHistory"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/ic_action_edit_light"
|
||||||
|
android:textColor="@color/grey_400"
|
||||||
|
android:text="@string/edit"/>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout style="@style/cardStyle">
|
<LinearLayout style="@style/cardStyle">
|
||||||
|
|||||||
@@ -316,7 +316,7 @@
|
|||||||
<color name="grey_100">#F5F5F5</color>
|
<color name="grey_100">#F5F5F5</color>
|
||||||
<!--<color name="grey_200">#EEEEEE</color>-->
|
<!--<color name="grey_200">#EEEEEE</color>-->
|
||||||
<!--<color name="grey_300">#E0E0E0</color>-->
|
<!--<color name="grey_300">#E0E0E0</color>-->
|
||||||
<!--<color name="grey_400">#BDBDBD</color>-->
|
<color name="grey_400">#BDBDBD</color>
|
||||||
<color name="grey_500">#9E9E9E</color>
|
<color name="grey_500">#9E9E9E</color>
|
||||||
<!--<color name="grey_600">#757575</color>-->
|
<!--<color name="grey_600">#757575</color>-->
|
||||||
<!--<color name="grey_700">#616161</color>-->
|
<!--<color name="grey_700">#616161</color>-->
|
||||||
|
|||||||
@@ -20,6 +20,9 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<dimen name="small_square_size">20dp</dimen>
|
<dimen name="small_square_size">20dp</dimen>
|
||||||
<dimen name="check_square_size">42dp</dimen>
|
<dimen name="check_square_size">42dp</dimen>
|
||||||
|
<dimen name="history_editor_max_height">450dp</dimen>
|
||||||
|
<dimen name="history_editor_padding">8dp</dimen>
|
||||||
|
<dimen name="history_max_font_size">14sp</dimen>
|
||||||
|
|
||||||
<string-array name="snooze_interval_names">
|
<string-array name="snooze_interval_names">
|
||||||
<item>@string/interval_15_minutes</item>
|
<item>@string/interval_15_minutes</item>
|
||||||
|
|||||||
Reference in New Issue
Block a user