Fix IndexOutOfBoundsException in HabitCardListAdapter

pull/316/head
Alinson S. Xavier 8 years ago
parent 91996924d9
commit de3b97dfdf

@ -105,11 +105,10 @@ public class HabitCardListAdapter
* Returns the item that occupies a certain position on the list
*
* @param position position of the item
* @return the item at given position
* @throws IndexOutOfBoundsException if position is not valid
* @return the item at given position or null if position is invalid
*/
@Deprecated
@NonNull
@Nullable
public Habit getItem(int position)
{
return cache.getHabitByPosition(position);
@ -314,6 +313,8 @@ public class HabitCardListAdapter
public void toggleSelection(int position)
{
Habit h = getItem(position);
if (h == null) return;
int k = selected.indexOf(h);
if (k < 0) selected.add(h);
else selected.remove(h);

@ -93,12 +93,12 @@ public class HabitCardListCache implements CommandRunner.Listener
* Returns the habits that occupies a certain position on the list.
*
* @param position the position of the habit
* @return the habit at given position
* @throws IndexOutOfBoundsException if position is not valid
* @return the habit at given position or null if position is invalid
*/
@NonNull
public Habit getHabitByPosition(int position)
@Nullable
public synchronized Habit getHabitByPosition(int position)
{
if(position < 0 || position >= data.habits.size()) return null;
return data.habits.get(position);
}

Loading…
Cancel
Save