-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bath remove favourite songs, improvements
- Loading branch information
1 parent
7a7f837
commit 56c1f50
Showing
22 changed files
with
304 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
app/src/main/java/org/indywidualni/centrumfm/rest/adapter/SelectableAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package org.indywidualni.centrumfm.rest.adapter; | ||
|
||
import android.support.v7.widget.RecyclerView; | ||
import android.util.SparseBooleanArray; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
@SuppressWarnings("unused") | ||
public abstract class SelectableAdapter<VH extends RecyclerView.ViewHolder> | ||
extends RecyclerView.Adapter<VH> { | ||
|
||
private static final String TAG = SelectableAdapter.class.getSimpleName(); | ||
|
||
private SparseBooleanArray selectedItems; | ||
|
||
public SelectableAdapter() { | ||
selectedItems = new SparseBooleanArray(); | ||
} | ||
|
||
/** | ||
* Indicates if the item at position position is selected | ||
* @param position Position of the item to check | ||
* @return true if the item is selected, false otherwise | ||
*/ | ||
public boolean isSelected(int position) { | ||
return getSelectedItems().contains(position); | ||
} | ||
|
||
/** | ||
* Toggle the selection status of the item at a given position | ||
* @param position Position of the item to toggle the selection status for | ||
*/ | ||
public void toggleSelection(int position) { | ||
if (selectedItems.get(position, false)) { | ||
selectedItems.delete(position); | ||
} else { | ||
selectedItems.put(position, true); | ||
} | ||
notifyItemChanged(position); | ||
} | ||
|
||
/** | ||
* Clear the selection status for all items | ||
*/ | ||
public void clearSelection() { | ||
List<Integer> selection = getSelectedItems(); | ||
selectedItems.clear(); | ||
for (Integer i : selection) { | ||
notifyItemChanged(i); | ||
} | ||
} | ||
|
||
/** | ||
* Count the selected items | ||
* @return Selected items count | ||
*/ | ||
public int getSelectedItemCount() { | ||
return selectedItems.size(); | ||
} | ||
|
||
/** | ||
* Indicates the list of selected items | ||
* @return List of selected items ids | ||
*/ | ||
public List<Integer> getSelectedItems() { | ||
List<Integer> items = new ArrayList<>(selectedItems.size()); | ||
for (int i = 0; i < selectedItems.size(); ++i) { | ||
items.add(selectedItems.keyAt(i)); | ||
} | ||
return items; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.