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;
|
||||
|
||||
import android.content.*;
|
||||
import android.content.res.*;
|
||||
import android.support.annotation.*;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.*;
|
||||
@@ -58,6 +59,9 @@ public class ListHabitsRootView extends BaseRootView
|
||||
@BindView(R.id.hintView)
|
||||
HintView hintView;
|
||||
|
||||
@BindView(R.id.header)
|
||||
HeaderView header;
|
||||
|
||||
@NonNull
|
||||
private final HabitCardListAdapter listAdapter;
|
||||
|
||||
@@ -81,17 +85,6 @@ public class ListHabitsRootView extends BaseRootView
|
||||
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
|
||||
@NonNull
|
||||
public ProgressBar getProgressBar()
|
||||
@@ -138,10 +131,27 @@ public class ListHabitsRootView extends BaseRootView
|
||||
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()
|
||||
{
|
||||
llEmpty.setVisibility(
|
||||
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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
* dragging operation is already complete.
|
||||
|
||||
@@ -63,14 +63,6 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
init();
|
||||
}
|
||||
|
||||
public CheckmarkPanelView(Context context,
|
||||
AttributeSet attrs,
|
||||
int defStyleAttr)
|
||||
{
|
||||
super(context, attrs, defStyleAttr);
|
||||
init();
|
||||
}
|
||||
|
||||
public CheckmarkButtonView getButton(int position)
|
||||
{
|
||||
return (CheckmarkButtonView) getChildAt(position);
|
||||
@@ -104,6 +96,24 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
public void setHabit(@NonNull 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()
|
||||
@@ -138,23 +148,6 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
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,
|
||||
CheckmarkButtonView buttonView)
|
||||
{
|
||||
@@ -185,5 +178,6 @@ public class CheckmarkPanelView extends LinearLayout
|
||||
|
||||
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.model.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
public class HabitCardListView extends RecyclerView
|
||||
{
|
||||
@Nullable
|
||||
@@ -40,6 +42,8 @@ public class HabitCardListView extends RecyclerView
|
||||
|
||||
private final ItemTouchHelper touchHelper;
|
||||
|
||||
private int checkmarkCount;
|
||||
|
||||
public HabitCardListView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
@@ -73,10 +77,13 @@ public class HabitCardListView extends RecyclerView
|
||||
boolean selected,
|
||||
int position)
|
||||
{
|
||||
int visibleCheckmarks[] =
|
||||
Arrays.copyOfRange(checkmarks, 0, checkmarkCount);
|
||||
|
||||
HabitCardView cardView = (HabitCardView) holder.itemView;
|
||||
cardView.setHabit(habit);
|
||||
cardView.setSelected(selected);
|
||||
cardView.setCheckmarkValues(checkmarks);
|
||||
cardView.setCheckmarkValues(visibleCheckmarks);
|
||||
cardView.setScore(score);
|
||||
if (controller != null) setupCardViewController(holder, position);
|
||||
return cardView;
|
||||
@@ -94,6 +101,11 @@ public class HabitCardListView extends RecyclerView
|
||||
super.setAdapter(adapter);
|
||||
}
|
||||
|
||||
public void setCheckmarkCount(int checkmarkCount)
|
||||
{
|
||||
this.checkmarkCount = checkmarkCount;
|
||||
}
|
||||
|
||||
public void setController(@Nullable Controller controller)
|
||||
{
|
||||
this.controller = controller;
|
||||
@@ -134,8 +146,6 @@ public class HabitCardListView extends RecyclerView
|
||||
public interface Controller
|
||||
extends CheckmarkButtonController.Listener, HabitCardController.Listener
|
||||
{
|
||||
void drag(int from, int to);
|
||||
|
||||
void drop(int from, int to);
|
||||
|
||||
void onItemClick(int pos);
|
||||
|
||||
@@ -30,7 +30,6 @@ 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.utils.*;
|
||||
|
||||
import java.util.*;
|
||||
@@ -77,9 +76,7 @@ public class HabitCardView extends FrameLayout
|
||||
|
||||
public void setCheckmarkValues(int checkmarks[])
|
||||
{
|
||||
int count = ListHabitsRootView.getCheckmarkCount(this);
|
||||
int visibleCheckmarks[] = Arrays.copyOfRange(checkmarks, 0, count);
|
||||
checkmarkPanel.setCheckmarkValues(visibleCheckmarks);
|
||||
checkmarkPanel.setCheckmarkValues(checkmarks);
|
||||
postInvalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,19 +19,16 @@
|
||||
|
||||
package org.isoron.uhabits.ui.habits.list.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
import android.content.*;
|
||||
import android.preference.*;
|
||||
import android.util.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
|
||||
import org.isoron.uhabits.R;
|
||||
import org.isoron.uhabits.ui.habits.list.*;
|
||||
import org.isoron.uhabits.utils.DateUtils;
|
||||
import org.isoron.uhabits.*;
|
||||
import org.isoron.uhabits.utils.*;
|
||||
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.*;
|
||||
|
||||
public class HeaderView extends LinearLayout
|
||||
{
|
||||
@@ -41,19 +38,33 @@ public class HeaderView extends LinearLayout
|
||||
|
||||
private final Context context;
|
||||
|
||||
private int buttonCount;
|
||||
|
||||
public HeaderView(Context context, AttributeSet attrs)
|
||||
{
|
||||
super(context, attrs);
|
||||
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()
|
||||
{
|
||||
removeAllViews();
|
||||
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;
|
||||
|
||||
@@ -78,11 +89,4 @@ public class HeaderView extends LinearLayout
|
||||
prefs.getBoolean("pref_checkmark_reverse_order", false);
|
||||
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