mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 01:08:50 -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.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
@@ -35,6 +36,7 @@ import org.isoron.helpers.Command;
|
||||
import org.isoron.helpers.DialogHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ShowHabitActivity;
|
||||
import org.isoron.uhabits.dialogs.HistoryEditorDialog;
|
||||
import org.isoron.uhabits.helpers.ReminderHelper;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
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 tvStreaks = (TextView) view.findViewById(R.id.tvStreaks);
|
||||
RingView scoreRing = (RingView) view.findViewById(R.id.scoreRing);
|
||||
Button btEditHistory = (Button) view.findViewById(R.id.btEditHistory);
|
||||
HabitStreakView streakView = (HabitStreakView) view.findViewById(R.id.streakView);
|
||||
HabitScoreView scoreView = (HabitScoreView) view.findViewById(R.id.scoreView);
|
||||
HabitHistoryView historyView = (HabitHistoryView) view.findViewById(R.id.historyView);
|
||||
@@ -90,6 +93,16 @@ public class ShowHabitFragment extends Fragment implements DialogHelper.OnSavedL
|
||||
scoreView.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);
|
||||
return view;
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ import android.util.AttributeSet;
|
||||
|
||||
import org.isoron.helpers.ColorHelper;
|
||||
import org.isoron.helpers.DateHelper;
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
@@ -50,7 +51,6 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
private int columnWidth;
|
||||
private int columnHeight;
|
||||
private int nColumns;
|
||||
private int baseSize;
|
||||
|
||||
private String wdays[];
|
||||
private SimpleDateFormat dfMonth;
|
||||
@@ -70,6 +70,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
{
|
||||
super(context, attrs);
|
||||
this.primaryColor = ColorHelper.palette[7];
|
||||
this.checkmarks = new int[0];
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -83,6 +84,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -117,23 +119,42 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
protected void onSizeChanged(int width, int height, int oldWidth, int oldHeight)
|
||||
{
|
||||
if(height < 8) height = 200;
|
||||
|
||||
baseSize = height / 8;
|
||||
int baseSize = height / 8;
|
||||
setScrollerBucketSize(baseSize);
|
||||
|
||||
columnWidth = baseSize;
|
||||
columnHeight = 8 * baseSize;
|
||||
nColumns = width / baseSize;
|
||||
|
||||
squareSpacing = (int) Math.floor(baseSize / 15.0);
|
||||
pSquareFg.setTextSize(baseSize * 0.5f);
|
||||
pTextHeader.setTextSize(baseSize * 0.5f);
|
||||
int maxTextSize = getResources().getDimensionPixelSize(R.dimen.history_max_font_size);
|
||||
float textSize = Math.min(baseSize * 0.5f, maxTextSize);
|
||||
|
||||
pSquareFg.setTextSize(textSize);
|
||||
pTextHeader.setTextSize(textSize);
|
||||
squareTextOffset = pSquareFg.getFontSpacing() * 0.4f;
|
||||
headerTextOffset = pTextHeader.getFontSpacing() * 0.3f;
|
||||
|
||||
int rightLabelWidth = getWeekdayLabelWidth();
|
||||
int horizontalPadding = getPaddingRight() + getPaddingLeft();
|
||||
|
||||
columnWidth = baseSize;
|
||||
columnHeight = 8 * baseSize;
|
||||
nColumns = (width - rightLabelWidth - horizontalPadding) / baseSize + 1;
|
||||
|
||||
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()
|
||||
{
|
||||
if(habit != null)
|
||||
@@ -185,12 +206,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
generateRandomData();
|
||||
else
|
||||
{
|
||||
if(habit == null)
|
||||
{
|
||||
checkmarks = new int[0];
|
||||
return;
|
||||
}
|
||||
|
||||
if(habit == null) return;
|
||||
checkmarks = habit.checkmarks.getAllValues();
|
||||
}
|
||||
|
||||
@@ -226,6 +242,7 @@ public class HabitHistoryView extends ScrollableDataView
|
||||
super.onDraw(canvas);
|
||||
|
||||
baseLocation.set(0, 0, columnWidth - squareSpacing, columnWidth - squareSpacing);
|
||||
baseLocation.offset(getPaddingLeft(), getPaddingTop());
|
||||
|
||||
previousMonth = "";
|
||||
previousYear = "";
|
||||
|
||||
@@ -71,6 +71,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
{
|
||||
super(context, attrs);
|
||||
this.primaryColor = ColorHelper.palette[7];
|
||||
this.scores = new int[0];
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -84,6 +85,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -168,12 +170,7 @@ public class HabitScoreView extends ScrollableDataView
|
||||
generateRandomData();
|
||||
else
|
||||
{
|
||||
if (habit == null)
|
||||
{
|
||||
scores = new int[0];
|
||||
return;
|
||||
}
|
||||
|
||||
if (habit == null) return;
|
||||
scores = habit.scores.getAllValues(BUCKET_SIZE * DateHelper.millisecondsInOneDay);
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,7 @@ public class HabitStreakView extends ScrollableDataView
|
||||
{
|
||||
super(context, attrs);
|
||||
this.primaryColor = ColorHelper.palette[7];
|
||||
startTimes = endTimes = lengths = new long[0];
|
||||
init();
|
||||
}
|
||||
|
||||
@@ -79,6 +80,7 @@ public class HabitStreakView extends ScrollableDataView
|
||||
|
||||
private void init()
|
||||
{
|
||||
fetchData();
|
||||
createPaints();
|
||||
createColors();
|
||||
|
||||
@@ -163,11 +165,7 @@ public class HabitStreakView extends ScrollableDataView
|
||||
generateRandomData();
|
||||
else
|
||||
{
|
||||
if(habit == null)
|
||||
{
|
||||
startTimes = endTimes = lengths = new long[0];
|
||||
return;
|
||||
}
|
||||
if(habit == null) return;
|
||||
|
||||
List<Streak> streaks = habit.streaks.getAll();
|
||||
int size = streaks.size();
|
||||
|
||||
@@ -18,8 +18,8 @@
|
||||
-->
|
||||
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://isoron.org/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/windowBackground"
|
||||
@@ -60,24 +60,32 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout style="@style/cardStyle">
|
||||
<LinearLayout
|
||||
style="@style/cardStyle"
|
||||
android:paddingBottom="0dp"
|
||||
android:clipToPadding="false"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvHistory"
|
||||
style="@style/cardHeaderStyle"
|
||||
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
|
||||
android:id="@+id/historyView"
|
||||
android:layout_width="match_parent"
|
||||
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 style="@style/cardStyle">
|
||||
|
||||
@@ -316,7 +316,7 @@
|
||||
<color name="grey_100">#F5F5F5</color>
|
||||
<!--<color name="grey_200">#EEEEEE</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_600">#757575</color>-->
|
||||
<!--<color name="grey_700">#616161</color>-->
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
<resources>
|
||||
<dimen name="small_square_size">20dp</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">
|
||||
<item>@string/interval_15_minutes</item>
|
||||
|
||||
Reference in New Issue
Block a user