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.ViewGroup;
|
||||
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.helpers.DateHelper;
|
||||
import org.isoron.uhabits.helpers.ListHabitsHelper;
|
||||
import org.isoron.uhabits.loaders.HabitListLoader;
|
||||
import org.isoron.uhabits.models.Habit;
|
||||
@@ -74,28 +72,15 @@ class HabitListAdapter extends BaseAdapter
|
||||
public View getView(int position, View view, ViewGroup parent)
|
||||
{
|
||||
final Habit habit = loader.habitsList.get(position);
|
||||
boolean selected = selectedPositions.contains(position);
|
||||
|
||||
if (view == null || (Long) view.getTag(R.id.timestamp_key) != DateHelper.getStartOfToday())
|
||||
{
|
||||
view = inflater.inflate(R.layout.list_habits_item, null);
|
||||
helper.initializeLabelAndIcon(view);
|
||||
helper.inflateCheckmarkButtons(view, onCheckmarkLongClickListener,
|
||||
onCheckmarkClickListener, inflater);
|
||||
view = helper.inflateHabitCard(inflater, onCheckmarkLongClickListener,
|
||||
onCheckmarkClickListener);
|
||||
}
|
||||
|
||||
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());
|
||||
|
||||
helper.updateNameAndIcon(habit, tvStar, tvName);
|
||||
helper.updateCheckmarkButtons(habit, llButtons);
|
||||
|
||||
boolean selected = selectedPositions.contains(position);
|
||||
helper.updateHabitBackground(llInner, selected);
|
||||
|
||||
helper.updateHabitCard(view, habit, selected);
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@ package org.isoron.uhabits.helpers;
|
||||
import android.content.Context;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
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)
|
||||
view.setBackgroundResource(R.drawable.selected_box);
|
||||
@@ -228,4 +256,15 @@ public class ListHabitsHelper
|
||||
else
|
||||
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:layout_height="match_parent"
|
||||
android:divider="?windowBackgroundColor"
|
||||
android:listSelector="@android:color/transparent"
|
||||
android:dividerHeight="1dp"/>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
Reference in New Issue
Block a user