Make actions selectable
This commit is contained in:
parent
b5457efedd
commit
527ff45229
@ -34,6 +34,14 @@ public class EpisodesApplyActionFragment extends Fragment {
|
||||
|
||||
public String TAG = "EpisodeActionFragment";
|
||||
|
||||
public static final int ACTION_QUEUE = 0;
|
||||
public static final int ACTION_MARK_PLAYED = 1;
|
||||
public static final int ACTION_MARK_UNPLAYED = 2;
|
||||
public static final int ACTION_DOWNLOAD = 4;
|
||||
public static final int ACTION_REMOVE = 8;
|
||||
public static final int ACTION_ALL = ACTION_QUEUE | ACTION_MARK_PLAYED | ACTION_MARK_UNPLAYED
|
||||
| ACTION_DOWNLOAD | ACTION_REMOVE;
|
||||
|
||||
private ListView mListView;
|
||||
private ArrayAdapter<String> mAdapter;
|
||||
|
||||
@ -43,27 +51,26 @@ public class EpisodesApplyActionFragment extends Fragment {
|
||||
private Button btnDownload;
|
||||
private Button btnDelete;
|
||||
|
||||
private final Map<Long,FeedItem> idMap;
|
||||
private final List<FeedItem> episodes;
|
||||
private final Map<Long,FeedItem> idMap = new ArrayMap<>();
|
||||
private final List<FeedItem> episodes = new ArrayList<>();
|
||||
private int actions;
|
||||
private final List<String> titles = new ArrayList();
|
||||
private final LongList checkedIds = new LongList();
|
||||
|
||||
private MenuItem mSelectToggle;
|
||||
|
||||
private int textColor;
|
||||
|
||||
public EpisodesApplyActionFragment() {
|
||||
this.episodes = new ArrayList<>();
|
||||
this.idMap = new ArrayMap<>();
|
||||
public static EpisodesApplyActionFragment newInstance(List<FeedItem> items) {
|
||||
return newInstance(items, ACTION_ALL);
|
||||
}
|
||||
|
||||
public void setEpisodes(List<FeedItem> episodes) {
|
||||
this.episodes.clear();
|
||||
this.episodes.addAll(episodes);
|
||||
this.idMap.clear();
|
||||
for(FeedItem episode : episodes) {
|
||||
this.idMap.put(episode.getId(), episode);
|
||||
public static EpisodesApplyActionFragment newInstance(List<FeedItem> items, int actions) {
|
||||
EpisodesApplyActionFragment f = new EpisodesApplyActionFragment();
|
||||
f.episodes.addAll(items);
|
||||
for(FeedItem episode : items) {
|
||||
f.idMap.put(episode.getId(), episode);
|
||||
}
|
||||
f.actions = actions;
|
||||
return f;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -98,16 +105,48 @@ public class EpisodesApplyActionFragment extends Fragment {
|
||||
mListView.setAdapter(mAdapter);
|
||||
checkAll();
|
||||
|
||||
int lastVisibleDiv = 0;
|
||||
btnAddToQueue = (Button) view.findViewById(R.id.btnAddToQueue);
|
||||
btnAddToQueue.setOnClickListener(v -> queueChecked());
|
||||
if((actions & ACTION_QUEUE) != 0) {
|
||||
btnAddToQueue.setOnClickListener(v -> queueChecked());
|
||||
lastVisibleDiv = R.id.divider1;
|
||||
} else {
|
||||
btnAddToQueue.setVisibility(View.GONE);
|
||||
view.findViewById(R.id.divider1).setVisibility(View.GONE);
|
||||
}
|
||||
btnMarkAsPlayed = (Button) view.findViewById(R.id.btnMarkAsPlayed);
|
||||
btnMarkAsPlayed.setOnClickListener(v -> markedCheckedPlayed());
|
||||
if((actions & ACTION_MARK_PLAYED) != 0) {
|
||||
btnMarkAsPlayed.setOnClickListener(v -> markedCheckedPlayed());
|
||||
lastVisibleDiv = R.id.divider2;
|
||||
} else {
|
||||
btnMarkAsPlayed.setVisibility(View.GONE);
|
||||
view.findViewById(R.id.divider2).setVisibility(View.GONE);
|
||||
}
|
||||
btnMarkAsUnplayed = (Button) view.findViewById(R.id.btnMarkAsUnplayed);
|
||||
btnMarkAsUnplayed.setOnClickListener(v -> markedCheckedUnplayed());
|
||||
if((actions & ACTION_MARK_UNPLAYED) != 0) {
|
||||
btnMarkAsUnplayed.setOnClickListener(v -> markedCheckedUnplayed());
|
||||
lastVisibleDiv = R.id.divider3;
|
||||
} else {
|
||||
btnMarkAsUnplayed.setVisibility(View.GONE);
|
||||
view.findViewById(R.id.divider3).setVisibility(View.GONE);
|
||||
}
|
||||
btnDownload = (Button) view.findViewById(R.id.btnDownload);
|
||||
btnDownload.setOnClickListener(v -> downloadChecked());
|
||||
if((actions & ACTION_DOWNLOAD) != 0) {
|
||||
btnDownload.setOnClickListener(v -> downloadChecked());
|
||||
lastVisibleDiv = R.id.divider4;
|
||||
} else {
|
||||
btnDownload.setVisibility(View.GONE);
|
||||
view.findViewById(R.id.divider4).setVisibility(View.GONE);
|
||||
}
|
||||
btnDelete = (Button) view.findViewById(R.id.btnDelete);
|
||||
btnDelete.setOnClickListener(v -> deleteChecked());
|
||||
if((actions & ACTION_REMOVE) != 0) {
|
||||
btnDelete.setOnClickListener(v -> deleteChecked());
|
||||
} else {
|
||||
btnDelete.setVisibility(View.GONE);
|
||||
if(lastVisibleDiv > 0) {
|
||||
view.findViewById(lastVisibleDiv).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
@ -252,8 +252,8 @@ public class ItemlistFragment extends ListFragment {
|
||||
if (!FeedMenuHandler.onOptionsItemClicked(getActivity(), item, feed)) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.episode_actions:
|
||||
EpisodesApplyActionFragment fragment = new EpisodesApplyActionFragment();
|
||||
fragment.setEpisodes(feed.getItems());
|
||||
EpisodesApplyActionFragment fragment = EpisodesApplyActionFragment
|
||||
.newInstance(feed.getItems());
|
||||
((MainActivity)getActivity()).loadChildFragment(fragment);
|
||||
return true;
|
||||
case R.id.remove_item:
|
||||
|
@ -1,16 +1,16 @@
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bottomBar"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="68dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal"
|
||||
android:padding="4dp">
|
||||
|
||||
<Button
|
||||
@ -18,103 +18,98 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"
|
||||
android:drawableTop="?attr/content_new"
|
||||
android:text="@string/add_to_queue_label"
|
||||
android:textSize="10sp"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
<View
|
||||
android:id="@+id/divider1"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnMarkAsPlayed"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"
|
||||
android:drawableTop="?attr/navigation_accept"
|
||||
android:text="@string/mark_read_label"
|
||||
android:textSize="10sp"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
<View
|
||||
android:id="@+id/divider2"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnMarkAsUnplayed"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"
|
||||
android:drawableTop="?attr/navigation_cancel"
|
||||
android:text="@string/mark_unread_label"
|
||||
android:textSize="10sp"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
<View
|
||||
android:id="@+id/divider3"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDownload"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"
|
||||
android:drawableTop="?attr/av_download"
|
||||
android:text="@string/download_label"
|
||||
android:textSize="10sp"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
<View xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
<View
|
||||
android:id="@+id/divider4"
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="4dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnDelete"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:background="@android:color/transparent"
|
||||
android:drawableTop="?attr/content_discard"
|
||||
android:text="@string/remove_episode_lable"
|
||||
android:textSize="10sp"
|
||||
android:background="@android:color/transparent"/>
|
||||
android:textSize="10sp" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
android:paddingBottom="4dp"
|
||||
android:layout_above="@id/bottomBar"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_above="@id/bottomBar"
|
||||
android:background="?android:attr/listDivider"
|
||||
android:paddingBottom="4dp"
|
||||
tools:background="@android:color/holo_red_dark" />
|
||||
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_above="@id/divider">
|
||||
|
||||
</ListView>
|
||||
|
||||
android:layout_above="@id/divider"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user