mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Fix ripple on ListHabitsFragment
This commit is contained in:
@@ -24,11 +24,9 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.BaseAdapter;
|
import android.widget.BaseAdapter;
|
||||||
import android.widget.LinearLayout;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import org.isoron.uhabits.helpers.DateHelper;
|
|
||||||
import org.isoron.uhabits.R;
|
import org.isoron.uhabits.R;
|
||||||
|
import org.isoron.uhabits.helpers.DateHelper;
|
||||||
import org.isoron.uhabits.helpers.ListHabitsHelper;
|
import org.isoron.uhabits.helpers.ListHabitsHelper;
|
||||||
import org.isoron.uhabits.loaders.HabitListLoader;
|
import org.isoron.uhabits.loaders.HabitListLoader;
|
||||||
import org.isoron.uhabits.models.Habit;
|
import org.isoron.uhabits.models.Habit;
|
||||||
@@ -74,28 +72,15 @@ class HabitListAdapter extends BaseAdapter
|
|||||||
public View getView(int position, View view, ViewGroup parent)
|
public View getView(int position, View view, ViewGroup parent)
|
||||||
{
|
{
|
||||||
final Habit habit = loader.habitsList.get(position);
|
final Habit habit = loader.habitsList.get(position);
|
||||||
|
boolean selected = selectedPositions.contains(position);
|
||||||
|
|
||||||
if (view == null || (Long) view.getTag(R.id.timestamp_key) != DateHelper.getStartOfToday())
|
if (view == null || (Long) view.getTag(R.id.timestamp_key) != DateHelper.getStartOfToday())
|
||||||
{
|
{
|
||||||
view = inflater.inflate(R.layout.list_habits_item, null);
|
view = helper.inflateHabitCard(inflater, onCheckmarkLongClickListener,
|
||||||
helper.initializeLabelAndIcon(view);
|
onCheckmarkClickListener);
|
||||||
helper.inflateCheckmarkButtons(view, onCheckmarkLongClickListener,
|
|
||||||
onCheckmarkClickListener, inflater);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView tvStar = ((TextView) view.findViewById(R.id.tvStar));
|
helper.updateHabitCard(view, habit, selected);
|
||||||
TextView tvName = (TextView) view.findViewById(R.id.label);
|
|
||||||
LinearLayout llInner = (LinearLayout) view.findViewById(R.id.llInner);
|
|
||||||
LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons);
|
|
||||||
|
|
||||||
llInner.setTag(R.string.habit_key, habit.getId());
|
|
||||||
|
|
||||||
helper.updateNameAndIcon(habit, tvStar, tvName);
|
|
||||||
helper.updateCheckmarkButtons(habit, llButtons);
|
|
||||||
|
|
||||||
boolean selected = selectedPositions.contains(position);
|
|
||||||
helper.updateHabitBackground(llInner, selected);
|
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.helpers;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
@@ -167,7 +168,34 @@ public class ListHabitsHelper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateHabitBackground(View view, boolean isSelected)
|
public View inflateHabitCard(LayoutInflater inflater,
|
||||||
|
View.OnLongClickListener onCheckmarkLongClickListener,
|
||||||
|
View.OnClickListener onCheckmarkClickListener)
|
||||||
|
{
|
||||||
|
View view = inflater.inflate(R.layout.list_habits_item, null);
|
||||||
|
initializeLabelAndIcon(view);
|
||||||
|
inflateCheckmarkButtons(view, onCheckmarkLongClickListener, onCheckmarkClickListener,
|
||||||
|
inflater);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void updateHabitCard(View view, Habit habit, boolean selected)
|
||||||
|
{
|
||||||
|
TextView tvStar = ((TextView) view.findViewById(R.id.tvStar));
|
||||||
|
TextView tvName = (TextView) view.findViewById(R.id.label);
|
||||||
|
LinearLayout llInner = (LinearLayout) view.findViewById(R.id.llInner);
|
||||||
|
LinearLayout llButtons = (LinearLayout) view.findViewById(R.id.llButtons);
|
||||||
|
|
||||||
|
llInner.setTag(R.string.habit_key, habit.getId());
|
||||||
|
llInner.setOnTouchListener(new HotspotTouchListener());
|
||||||
|
|
||||||
|
updateNameAndIcon(habit, tvStar, tvName);
|
||||||
|
updateCheckmarkButtons(habit, llButtons);
|
||||||
|
updateHabitCardBackground(llInner, selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void updateHabitCardBackground(View view, boolean isSelected)
|
||||||
{
|
{
|
||||||
if (isSelected)
|
if (isSelected)
|
||||||
view.setBackgroundResource(R.drawable.selected_box);
|
view.setBackgroundResource(R.drawable.selected_box);
|
||||||
@@ -228,4 +256,15 @@ public class ListHabitsHelper
|
|||||||
else
|
else
|
||||||
updateCheckmark(androidColor, (TextView) v, 2);
|
updateCheckmark(androidColor, (TextView) v, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class HotspotTouchListener implements View.OnTouchListener
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public boolean onTouch(View v, MotionEvent event)
|
||||||
|
{
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 21)
|
||||||
|
v.getBackground().setHotspot(event.getX(), event.getY());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
android:paddingTop="@dimen/checkmarkHeight"
|
android:paddingTop="@dimen/checkmarkHeight"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:divider="?windowBackgroundColor"
|
android:divider="?windowBackgroundColor"
|
||||||
|
android:listSelector="@android:color/transparent"
|
||||||
android:dividerHeight="1dp"/>
|
android:dividerHeight="1dp"/>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
Reference in New Issue
Block a user