diff options
author | Martin Fietz <marf@hadiko-99-4.hadiko.uni-karlsruhe.de> | 2015-05-08 17:07:32 +0200 |
---|---|---|
committer | Martin Fietz <Martin.Fietz@gmail.com> | 2015-05-19 11:58:37 +0200 |
commit | 518e8207da568d04c3e780b407f29bc51e2d1995 (patch) | |
tree | 84f2c1c9024ae89fe792a3e1c9bb365e8b9b65b8 /app | |
parent | 6f5d23c55743bd98800148c943880ce00d04441a (diff) | |
download | AntennaPod-518e8207da568d04c3e780b407f29bc51e2d1995.zip |
Reset dialog in progress
Diffstat (limited to 'app')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java | 127 | ||||
-rw-r--r-- | app/src/main/res/menu/queue_context.xml | 4 |
2 files changed, 116 insertions, 15 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java index a17194dee..46fe02ab9 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/QueueFragment.java @@ -1,6 +1,7 @@ package de.danoeh.antennapod.fragment; import android.app.Activity; +import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.content.SharedPreferences; @@ -24,6 +25,7 @@ import android.widget.TextView; import com.mobeta.android.dslv.DragSortListView; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.atomic.AtomicReference; @@ -311,9 +313,23 @@ public class QueueFragment extends Fragment { menu.findItem(R.id.move_to_bottom_item).setEnabled(!queue.isEmpty() && queue.get(queue.size() - 1) != item); if(item.isRead()) { menu.findItem(R.id.mark_read_item).setVisible(false); - } else { - menu.findItem(R.id.mark_unread_item).setVisible(false); + } else if(!isResettable(item)){ + menu.findItem(R.id.reset_attributes).setVisible(false); + } + } + + private static boolean isResettable(FeedItem item) { + // TODO add auto_download + if(item.isRead()) { + return true; } + if(item.getMedia() != null) { + FeedMedia media = item.getMedia(); + if(media.getPosition() > 0 || media.getPlayedDuration() > 0) { + return true; + } + } + return false; } @Override @@ -345,17 +361,8 @@ public class QueueFragment extends Fragment { GpodnetPreferences.enqueueEpisodeAction(actionPlay); } return true; - case R.id.mark_unread_item: - DBWriter.markItemRead(getActivity(), selectedItem, false, false); - selectedItem.setRead(false); - if(GpodnetPreferences.loggedIn()) { - GpodnetEpisodeAction actionNew = new GpodnetEpisodeAction.Builder(selectedItem, GpodnetEpisodeAction.Action.NEW) - .currentDeviceId() - .currentTimestamp() - .build(); - GpodnetPreferences.enqueueEpisodeAction(actionNew); - } - startItemLoader(); + case R.id.reset_attributes: + showResetAttributesDialog(selectedItem); return true; case R.id.move_to_bottom_item: DBWriter.moveQueueItemToBottom(getActivity(), selectedItem.getId(), true); @@ -368,6 +375,100 @@ public class QueueFragment extends Fragment { } } + private void showResetAttributesDialog(final FeedItem item) { + final String resetReadValue = "RESET_READ"; + final String resetPositionValue = "RESET_POSITION"; + final String activateAutoDownloadValue = "ACTIVATE_AUTO_DOWNLOAD"; + final String unflattrValue = "UNFLATTR"; + + AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); + builder.setTitle(R.string.reset_attributes_title); + final List<String> resettableItems = new ArrayList<String>(); + final List<String> resettableValues = new ArrayList<String>(); + if(item.isRead()) { + resettableItems.add(getString(R.string.mark_unread_label)); + resettableValues.add(resetReadValue); + } + // TODO + /* + if(false == item.getAutoDownload) { + resettableItems.add(getString(R.string.mark_unread_label)); + resettableValues.add("ACTIVATE_AUTO_DOWNLOAD"); + } + + if(item.getFlattrStatus().getUnflattred() == false) { + resettableItems.add(getString(R.string.reset)); + resettableValues.add("ACTIVATE_AUTO_DOWNLOAD"); + } + */ + if(item.getMedia() != null) { + FeedMedia media = item.getMedia(); + if(media.getPosition() > 0) { + resettableItems.add(getString(R.string.reset_attribute_position)); + resettableValues.add(resetPositionValue); + } + } + + String[] items = resettableItems.toArray(new String[resettableItems.size()]); + final boolean[] checked = new boolean[items.length]; + builder.setMultiChoiceItems(items, checked, new DialogInterface.OnMultiChoiceClickListener() { + @Override + public void onClick(DialogInterface dialog, int which, boolean isChecked) { + checked[which] = isChecked; + if(resettableValues.get(which).equals(resetPositionValue) && isChecked) { + AlertDialog alertDialog = (AlertDialog) dialog; + int position = resettableValues.indexOf(resetReadValue); + alertDialog.getListView().setItemChecked(position, true); + } + } + }); + builder.setPositiveButton(R.string.confirm_label, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + boolean markAsUnplayed = false; + boolean resetPosition = false; + boolean unflattr = false; + boolean activateAutoDownload = false; + for(int i=0; i < checked.length; i++) { + if(checked[i]) { + switch(resettableValues.get(i)) { + case resetReadValue: + markAsUnplayed = true; + break; + case resetPositionValue: + resetPosition = true; + break; + case unflattrValue: + unflattr = true; + break; + case activateAutoDownloadValue: + activateAutoDownload = true; + } + } + } + if(markAsUnplayed) { + DBWriter.markItemRead(getActivity(), item, false, resetPosition); + if(GpodnetPreferences.loggedIn()) { + GpodnetEpisodeAction actionNew = new GpodnetEpisodeAction.Builder(item, + GpodnetEpisodeAction.Action.NEW) + .currentDeviceId() + .currentTimestamp() + .build(); + GpodnetPreferences.enqueueEpisodeAction(actionNew); + } + } + if(unflattr) { + // TODO + } + if(activateAutoDownload) { + // TODO + } + } + }); + builder.setNegativeButton(R.string.cancel_label, null); + builder.create().show(); + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); diff --git a/app/src/main/res/menu/queue_context.xml b/app/src/main/res/menu/queue_context.xml index d20e57cc9..b1589af3b 100644 --- a/app/src/main/res/menu/queue_context.xml +++ b/app/src/main/res/menu/queue_context.xml @@ -13,9 +13,9 @@ android:title="@string/mark_read_label" /> <item - android:id="@+id/mark_unread_item" + android:id="@+id/reset_attributes" android:menuCategory="container" - android:title="@string/mark_unread_label" /> + android:title="@string/reset_attributes" /> <item android:id="@+id/remove_from_queue_item" |