mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-07 01:28:52 -06:00
Fix IndexOutOfBoundsException in HabitCardListAdapter
This commit is contained in:
@@ -105,11 +105,10 @@ public class HabitCardListAdapter
|
|||||||
* Returns the item that occupies a certain position on the list
|
* Returns the item that occupies a certain position on the list
|
||||||
*
|
*
|
||||||
* @param position position of the item
|
* @param position position of the item
|
||||||
* @return the item at given position
|
* @return the item at given position or null if position is invalid
|
||||||
* @throws IndexOutOfBoundsException if position is not valid
|
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
@NonNull
|
@Nullable
|
||||||
public Habit getItem(int position)
|
public Habit getItem(int position)
|
||||||
{
|
{
|
||||||
return cache.getHabitByPosition(position);
|
return cache.getHabitByPosition(position);
|
||||||
@@ -314,6 +313,8 @@ public class HabitCardListAdapter
|
|||||||
public void toggleSelection(int position)
|
public void toggleSelection(int position)
|
||||||
{
|
{
|
||||||
Habit h = getItem(position);
|
Habit h = getItem(position);
|
||||||
|
if (h == null) return;
|
||||||
|
|
||||||
int k = selected.indexOf(h);
|
int k = selected.indexOf(h);
|
||||||
if (k < 0) selected.add(h);
|
if (k < 0) selected.add(h);
|
||||||
else selected.remove(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.
|
* Returns the habits that occupies a certain position on the list.
|
||||||
*
|
*
|
||||||
* @param position the position of the habit
|
* @param position the position of the habit
|
||||||
* @return the habit at given position
|
* @return the habit at given position or null if position is invalid
|
||||||
* @throws IndexOutOfBoundsException if position is not valid
|
|
||||||
*/
|
*/
|
||||||
@NonNull
|
@Nullable
|
||||||
public Habit getHabitByPosition(int position)
|
public synchronized Habit getHabitByPosition(int position)
|
||||||
{
|
{
|
||||||
|
if(position < 0 || position >= data.habits.size()) return null;
|
||||||
return data.habits.get(position);
|
return data.habits.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user