mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Restore dynamic number of checkmarks
This commit is contained in:
@@ -20,6 +20,7 @@
|
|||||||
package org.isoron.uhabits.ui.habits.list;
|
package org.isoron.uhabits.ui.habits.list;
|
||||||
|
|
||||||
import android.content.*;
|
import android.content.*;
|
||||||
|
import android.content.res.*;
|
||||||
import android.support.annotation.*;
|
import android.support.annotation.*;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.view.*;
|
import android.view.*;
|
||||||
@@ -58,6 +59,9 @@ public class ListHabitsRootView extends BaseRootView
|
|||||||
@BindView(R.id.hintView)
|
@BindView(R.id.hintView)
|
||||||
HintView hintView;
|
HintView hintView;
|
||||||
|
|
||||||
|
@BindView(R.id.header)
|
||||||
|
HeaderView header;
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private final HabitCardListAdapter listAdapter;
|
private final HabitCardListAdapter listAdapter;
|
||||||
|
|
||||||
@@ -81,17 +85,6 @@ public class ListHabitsRootView extends BaseRootView
|
|||||||
hintView.setHints(hintList);
|
hintView.setHints(hintList);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getCheckmarkCount(View v)
|
|
||||||
{
|
|
||||||
// Resources res = v.getResources();
|
|
||||||
// float labelWidth = res.getDimension(R.dimen.habitNameWidth);
|
|
||||||
// float buttonWidth = res.getDimension(R.dimen.checkmarkWidth);
|
|
||||||
// return Math.min(MAX_CHECKMARK_COUNT, Math.max(0,
|
|
||||||
// (int) ((v.getMeasuredWidth() - labelWidth) / buttonWidth)));
|
|
||||||
|
|
||||||
return 5; // TODO: Fix this.
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public ProgressBar getProgressBar()
|
public ProgressBar getProgressBar()
|
||||||
@@ -138,10 +131,27 @@ public class ListHabitsRootView extends BaseRootView
|
|||||||
super.onDetachedFromWindow();
|
super.onDetachedFromWindow();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCheckmarkCount()
|
||||||
|
{
|
||||||
|
Resources res = getResources();
|
||||||
|
float labelWidth = res.getDimension(R.dimen.habitNameWidth);
|
||||||
|
float buttonWidth = res.getDimension(R.dimen.checkmarkWidth);
|
||||||
|
return Math.min(MAX_CHECKMARK_COUNT, Math.max(0,
|
||||||
|
(int) ((getMeasuredWidth() - labelWidth) / buttonWidth)));
|
||||||
|
}
|
||||||
|
|
||||||
private void updateEmptyView()
|
private void updateEmptyView()
|
||||||
{
|
{
|
||||||
llEmpty.setVisibility(
|
llEmpty.setVisibility(
|
||||||
listAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
|
listAdapter.getItemCount() > 0 ? View.GONE : View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onSizeChanged(int w, int h, int oldw, int oldh)
|
||||||
|
{
|
||||||
|
int count = getCheckmarkCount();
|
||||||
|
header.setButtonCount(count);
|
||||||
|
listView.setCheckmarkCount(count);
|
||||||
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,20 +54,6 @@ public class HabitCardListController implements HabitCardListView.Controller
|
|||||||
this.activeMode = new NormalMode();
|
this.activeMode = new NormalMode();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Called when the user is dragging a habit which was originally at position
|
|
||||||
* 'from' and is currently hovering over position 'to'. Note that the user
|
|
||||||
* has not yet finished the dragging operation.
|
|
||||||
*
|
|
||||||
* @param from the original position of the habit
|
|
||||||
* @param to the position where the habit is currently hovering
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void drag(int from, int to)
|
|
||||||
{
|
|
||||||
// ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the user drags a habit and drops it somewhere. Note that the
|
* Called when the user drags a habit and drops it somewhere. Note that the
|
||||||
* dragging operation is already complete.
|
* dragging operation is already complete.
|
||||||
|
|||||||
@@ -63,14 +63,6 @@ public class CheckmarkPanelView extends LinearLayout
|
|||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CheckmarkPanelView(Context context,
|
|
||||||
AttributeSet attrs,
|
|
||||||
int defStyleAttr)
|
|
||||||
{
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
init();
|
|
||||||
}
|
|
||||||
|
|
||||||
public CheckmarkButtonView getButton(int position)
|
public CheckmarkButtonView getButton(int position)
|
||||||
{
|
{
|
||||||
return (CheckmarkButtonView) getChildAt(position);
|
return (CheckmarkButtonView) getChildAt(position);
|
||||||
@@ -104,6 +96,24 @@ public class CheckmarkPanelView extends LinearLayout
|
|||||||
public void setHabit(@NonNull Habit habit)
|
public void setHabit(@NonNull Habit habit)
|
||||||
{
|
{
|
||||||
this.habit = habit;
|
this.habit = habit;
|
||||||
|
setupCheckmarkButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthSpec, int heightSpec)
|
||||||
|
{
|
||||||
|
float buttonWidth = getResources().getDimension(R.dimen.checkmarkWidth);
|
||||||
|
float buttonHeight =
|
||||||
|
getResources().getDimension(R.dimen.checkmarkHeight);
|
||||||
|
|
||||||
|
float width = buttonWidth * nButtons;
|
||||||
|
|
||||||
|
widthSpec =
|
||||||
|
MeasureSpec.makeMeasureSpec((int) width, MeasureSpec.EXACTLY);
|
||||||
|
heightSpec = MeasureSpec.makeMeasureSpec((int) buttonHeight,
|
||||||
|
MeasureSpec.EXACTLY);
|
||||||
|
|
||||||
|
super.onMeasure(widthSpec, heightSpec);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addCheckmarkButtons()
|
private void addCheckmarkButtons()
|
||||||
@@ -138,23 +148,6 @@ public class CheckmarkPanelView extends LinearLayout
|
|||||||
setWillNotDraw(false);
|
setWillNotDraw(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
|
||||||
{
|
|
||||||
float buttonWidth = getResources().getDimension(R.dimen.checkmarkWidth);
|
|
||||||
float buttonHeight =
|
|
||||||
getResources().getDimension(R.dimen.checkmarkHeight);
|
|
||||||
|
|
||||||
float width = buttonWidth * nButtons;
|
|
||||||
|
|
||||||
widthMeasureSpec =
|
|
||||||
MeasureSpec.makeMeasureSpec((int) width, MeasureSpec.EXACTLY);
|
|
||||||
heightMeasureSpec = MeasureSpec.makeMeasureSpec((int) buttonHeight,
|
|
||||||
MeasureSpec.EXACTLY);
|
|
||||||
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setupButtonControllers(long timestamp,
|
private void setupButtonControllers(long timestamp,
|
||||||
CheckmarkButtonView buttonView)
|
CheckmarkButtonView buttonView)
|
||||||
{
|
{
|
||||||
@@ -185,5 +178,6 @@ public class CheckmarkPanelView extends LinearLayout
|
|||||||
|
|
||||||
public interface Controller extends CheckmarkButtonController.Listener
|
public interface Controller extends CheckmarkButtonController.Listener
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,8 @@ import org.isoron.uhabits.models.*;
|
|||||||
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
import org.isoron.uhabits.ui.habits.list.controllers.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.model.*;
|
import org.isoron.uhabits.ui.habits.list.model.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
public class HabitCardListView extends RecyclerView
|
public class HabitCardListView extends RecyclerView
|
||||||
{
|
{
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -40,6 +42,8 @@ public class HabitCardListView extends RecyclerView
|
|||||||
|
|
||||||
private final ItemTouchHelper touchHelper;
|
private final ItemTouchHelper touchHelper;
|
||||||
|
|
||||||
|
private int checkmarkCount;
|
||||||
|
|
||||||
public HabitCardListView(Context context, AttributeSet attrs)
|
public HabitCardListView(Context context, AttributeSet attrs)
|
||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
@@ -73,10 +77,13 @@ public class HabitCardListView extends RecyclerView
|
|||||||
boolean selected,
|
boolean selected,
|
||||||
int position)
|
int position)
|
||||||
{
|
{
|
||||||
|
int visibleCheckmarks[] =
|
||||||
|
Arrays.copyOfRange(checkmarks, 0, checkmarkCount);
|
||||||
|
|
||||||
HabitCardView cardView = (HabitCardView) holder.itemView;
|
HabitCardView cardView = (HabitCardView) holder.itemView;
|
||||||
cardView.setHabit(habit);
|
cardView.setHabit(habit);
|
||||||
cardView.setSelected(selected);
|
cardView.setSelected(selected);
|
||||||
cardView.setCheckmarkValues(checkmarks);
|
cardView.setCheckmarkValues(visibleCheckmarks);
|
||||||
cardView.setScore(score);
|
cardView.setScore(score);
|
||||||
if (controller != null) setupCardViewController(holder, position);
|
if (controller != null) setupCardViewController(holder, position);
|
||||||
return cardView;
|
return cardView;
|
||||||
@@ -94,6 +101,11 @@ public class HabitCardListView extends RecyclerView
|
|||||||
super.setAdapter(adapter);
|
super.setAdapter(adapter);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCheckmarkCount(int checkmarkCount)
|
||||||
|
{
|
||||||
|
this.checkmarkCount = checkmarkCount;
|
||||||
|
}
|
||||||
|
|
||||||
public void setController(@Nullable Controller controller)
|
public void setController(@Nullable Controller controller)
|
||||||
{
|
{
|
||||||
this.controller = controller;
|
this.controller = controller;
|
||||||
@@ -134,8 +146,6 @@ public class HabitCardListView extends RecyclerView
|
|||||||
public interface Controller
|
public interface Controller
|
||||||
extends CheckmarkButtonController.Listener, HabitCardController.Listener
|
extends CheckmarkButtonController.Listener, HabitCardController.Listener
|
||||||
{
|
{
|
||||||
void drag(int from, int to);
|
|
||||||
|
|
||||||
void drop(int from, int to);
|
void drop(int from, int to);
|
||||||
|
|
||||||
void onItemClick(int pos);
|
void onItemClick(int pos);
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ import android.widget.*;
|
|||||||
import org.isoron.uhabits.*;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.models.*;
|
import org.isoron.uhabits.models.*;
|
||||||
import org.isoron.uhabits.ui.common.views.*;
|
import org.isoron.uhabits.ui.common.views.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.*;
|
|
||||||
import org.isoron.uhabits.utils.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@@ -77,9 +76,7 @@ public class HabitCardView extends FrameLayout
|
|||||||
|
|
||||||
public void setCheckmarkValues(int checkmarks[])
|
public void setCheckmarkValues(int checkmarks[])
|
||||||
{
|
{
|
||||||
int count = ListHabitsRootView.getCheckmarkCount(this);
|
checkmarkPanel.setCheckmarkValues(checkmarks);
|
||||||
int visibleCheckmarks[] = Arrays.copyOfRange(checkmarks, 0, count);
|
|
||||||
checkmarkPanel.setCheckmarkValues(visibleCheckmarks);
|
|
||||||
postInvalidate();
|
postInvalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,19 +19,16 @@
|
|||||||
|
|
||||||
package org.isoron.uhabits.ui.habits.list.views;
|
package org.isoron.uhabits.ui.habits.list.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.*;
|
||||||
import android.content.SharedPreferences;
|
import android.preference.*;
|
||||||
import android.preference.PreferenceManager;
|
import android.util.*;
|
||||||
import android.util.AttributeSet;
|
import android.view.*;
|
||||||
import android.view.View;
|
import android.widget.*;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.*;
|
||||||
import org.isoron.uhabits.ui.habits.list.*;
|
import org.isoron.uhabits.utils.*;
|
||||||
import org.isoron.uhabits.utils.DateUtils;
|
|
||||||
|
|
||||||
import java.util.GregorianCalendar;
|
import java.util.*;
|
||||||
|
|
||||||
public class HeaderView extends LinearLayout
|
public class HeaderView extends LinearLayout
|
||||||
{
|
{
|
||||||
@@ -41,19 +38,33 @@ public class HeaderView extends LinearLayout
|
|||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
|
private int buttonCount;
|
||||||
|
|
||||||
public HeaderView(Context context, AttributeSet attrs)
|
public HeaderView(Context context, AttributeSet attrs)
|
||||||
{
|
{
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setButtonCount(int buttonCount)
|
||||||
|
{
|
||||||
|
this.buttonCount = buttonCount;
|
||||||
|
createButtons();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
||||||
|
{
|
||||||
|
createButtons();
|
||||||
|
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
||||||
|
}
|
||||||
|
|
||||||
private void createButtons()
|
private void createButtons()
|
||||||
{
|
{
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
GregorianCalendar day = DateUtils.getStartOfTodayCalendar();
|
||||||
double count = ListHabitsRootView.getCheckmarkCount(this);
|
|
||||||
|
|
||||||
for (int i = 0; i < count; i++)
|
for (int i = 0; i < buttonCount; i++)
|
||||||
{
|
{
|
||||||
int position = 0;
|
int position = 0;
|
||||||
|
|
||||||
@@ -78,11 +89,4 @@ public class HeaderView extends LinearLayout
|
|||||||
prefs.getBoolean("pref_checkmark_reverse_order", false);
|
prefs.getBoolean("pref_checkmark_reverse_order", false);
|
||||||
return reverse ? CHECKMARK_RIGHT_TO_LEFT : CHECKMARK_LEFT_TO_RIGHT;
|
return reverse ? CHECKMARK_RIGHT_TO_LEFT : CHECKMARK_LEFT_TO_RIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
|
|
||||||
{
|
|
||||||
createButtons();
|
|
||||||
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user