Fix for indicator, changes in context menus

This commit is contained in:
Martin Fietz 2015-05-11 19:58:06 +02:00
parent 4561f16f11
commit 298b02b0aa
13 changed files with 171 additions and 17 deletions

View File

@ -277,7 +277,7 @@ public class NavListAdapter extends BaseAdapter
holder.count.setText(String.valueOf(feedUnreadItems));
holder.count.setTypeface(holder.title.getTypeface());
} else {
holder.count.setVisibility(View.GONE);
holder.count.setVisibility(View.INVISIBLE);
}
return convertView;
}

View File

@ -10,6 +10,8 @@ import android.os.Handler;
import android.support.v4.app.Fragment;
import android.support.v4.view.MenuItemCompat;
import android.support.v7.widget.SearchView;
import android.util.Log;
import android.view.ContextMenu;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -41,8 +43,10 @@ import de.danoeh.antennapod.core.service.download.Downloader;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequestException;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
/**
@ -67,6 +71,7 @@ public class AllEpisodesFragment extends Fragment {
private AllEpisodesListAdapter listAdapter;
private TextView txtvEmpty;
private ProgressBar progLoading;
private ContextMenu contextMenu;
private List<FeedItem> episodes;
private LongList queuedItemsIds;
@ -293,6 +298,8 @@ public class AllEpisodesFragment extends Fragment {
}
});
registerForContextMenu(listView);
if (!itemsLoaded) {
progLoading.setVisibility(View.VISIBLE);
txtvEmpty.setVisibility(View.GONE);
@ -307,6 +314,55 @@ public class AllEpisodesFragment extends Fragment {
return root;
}
private final FeedItemMenuHandler.MenuInterface contextMenuInterface = new FeedItemMenuHandler.MenuInterface() {
@Override
public void setItemVisibility(int id, boolean visible) {
if(contextMenu == null) {
return;
}
MenuItem item = contextMenu.findItem(id);
if (item != null) {
item.setVisible(visible);
}
}
};
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
AdapterView.AdapterContextMenuInfo adapterInfo = (AdapterView.AdapterContextMenuInfo) menuInfo;
FeedItem item = itemAccess.getItem(adapterInfo.position);
MenuInflater inflater = getActivity().getMenuInflater();
inflater.inflate(R.menu.allepisodes_context, menu);
if (item != null) {
menu.setHeaderTitle(item.getTitle());
}
contextMenu = menu;
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
FeedItem selectedItem = itemAccess.getItem(menuInfo.position);
if (selectedItem == null) {
Log.i(TAG, "Selected item at position " + menuInfo.position + " was null, ignoring selection");
return super.onContextItemSelected(item);
}
try {
return FeedItemMenuHandler.onMenuItemClicked(getActivity(), item.getItemId(), selectedItem);
} catch (DownloadRequestException e) {
e.printStackTrace();
Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show();
return true;
}
}
private void onFragmentLoaded() {
if (listAdapter == null) {
listAdapter = new AllEpisodesListAdapter(activity.get(), itemAccess,

View File

@ -26,6 +26,7 @@ import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.joanzapata.android.iconify.Iconify;
@ -301,7 +302,7 @@ public class ItemlistFragment extends ListFragment {
}
contextMenu = menu;
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, false, queuedItemsIds);
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queuedItemsIds);
}
@Override
@ -428,6 +429,10 @@ public class ItemlistFragment extends ListFragment {
if(feed.getItemFilter() != null) {
FeedItemFilter filter = feed.getItemFilter();
if(filter.getValues().length > 0) {
if(feed.hasLastUpdateFailed()) {
RelativeLayout.LayoutParams p = (RelativeLayout.LayoutParams) txtvInformation.getLayoutParams();
p.addRule(RelativeLayout.BELOW, R.id.txtvFailure);
}
txtvInformation.setText("{fa-info-circle} " + this.getString(R.string.filtered_label));
Iconify.addIcons(txtvInformation);
txtvInformation.setVisibility(View.VISIBLE);

View File

@ -329,7 +329,7 @@ public class QueueFragment extends Fragment {
for(FeedItem queueItem : queue) {
queueIds.add(queueItem.getId());
}
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, false, queueIds);
FeedItemMenuHandler.onPrepareMenu(contextMenuInterface, item, true, queueIds);
}
@Override
@ -352,7 +352,6 @@ public class QueueFragment extends Fragment {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreateView(inflater, container, savedInstanceState);
@ -435,7 +434,6 @@ public class QueueFragment extends Fragment {
});
registerForContextMenu(listView);
if (!itemsLoaded) {

View File

@ -0,0 +1,56 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@id/skip_episode_item"
android:menuCategory="container"
android:title="@string/skip_episode_label" />
<item
android:id="@+id/mark_read_item"
android:menuCategory="container"
android:title="@string/mark_read_label" />
<item
android:id="@+id/mark_unread_item"
android:menuCategory="container"
android:title="@string/mark_unread_label" />
<item
android:id="@+id/add_to_queue_item"
android:menuCategory="container"
android:title="@string/add_to_queue_label" />
<item
android:id="@+id/remove_from_queue_item"
android:menuCategory="container"
android:title="@string/remove_from_queue_label" />
<item
android:id="@+id/reset_position"
android:menuCategory="container"
android:title="@string/reset_position" />
<item
android:id="@+id/activate_auto_download"
android:menuCategory="container"
android:title="@string/activate_auto_download" />
<item
android:id="@+id/deactivate_auto_download"
android:menuCategory="container"
android:title="@string/deactivate_auto_download" />
<item
android:id="@+id/share_link_item"
android:menuCategory="container"
android:title="@string/share_link_label" />
<item
android:id="@+id/visit_website_item"
android:menuCategory="container"
android:title="@string/visit_website_label" />
<item
android:id="@+id/support_item"
android:menuCategory="container"
android:title="@string/support_label" />
</menu>

View File

@ -30,6 +30,23 @@
android:title="@string/remove_from_queue_label">
</item>
<item
android:id="@+id/reset_position"
custom:showAsAction="collapseActionView"
android:title="@string/reset_position">
</item>
<item
android:id="@+id/activate_auto_download"
custom:showAsAction="collapseActionView"
android:title="@string/activate_auto_download">
</item>
<item
android:id="@+id/deactivate_auto_download"
custom:showAsAction="collapseActionView"
android:title="@string/deactivate_auto_download">
</item>
<item
android:id="@+id/share_link_item"
custom:showAsAction="collapseActionView"

View File

@ -2,6 +2,11 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@id/skip_episode_item"
android:menuCategory="container"
android:title="@string/skip_episode_label" />
<item
android:id="@+id/mark_read_item"
android:menuCategory="container"

View File

@ -7,13 +7,18 @@
android:menuCategory="container"
android:title="@string/move_to_top_label" />
<item
android:id="@+id/move_to_bottom_item"
android:menuCategory="container"
android:title="@string/move_to_bottom_label" />
<item
android:id="@+id/mark_read_item"
android:menuCategory="container"
android:title="@string/mark_read_label" />
<item
android:id="@+id/mark_unread_item_item"
android:id="@+id/mark_unread_item"
android:menuCategory="container"
android:title="@string/mark_unread_label" />
@ -38,8 +43,18 @@
android:title="@string/deactivate_auto_download" />
<item
android:id="@+id/move_to_bottom_item"
android:id="@+id/share_link_item"
android:menuCategory="container"
android:title="@string/move_to_bottom_label" />
android:title="@string/share_link_label" />
<item
android:id="@+id/visit_website_item"
android:menuCategory="container"
android:title="@string/visit_website_label" />
<item
android:id="@+id/support_item"
android:menuCategory="container"
android:title="@string/support_label" />
</menu>

View File

@ -1060,9 +1060,11 @@ public class DownloadService extends Service {
@Override
public void run() {
if (request.isDeleteOnFailure()) {
if(request.getFeedfileType() == Feed.FEEDFILETYPE_FEED) {
DBWriter.setFeedLastUpdateFailed(DownloadService.this, request.getFeedfileId(), true);
} else if (request.isDeleteOnFailure()) {
Log.d(TAG, "Ignoring failed download, deleteOnFailure=true");
} else {
} else {
File dest = new File(request.getDestination());
if (dest.exists() && request.getFeedfileType() == FeedMedia.FEEDFILETYPE_FEEDMEDIA) {
Log.d(TAG, "File has been partially downloaded. Writing file url");

View File

@ -193,7 +193,7 @@ public class PlaybackServiceMediaPlayer {
if(oldMedia.hasAlmostEnded()) {
Log.d(TAG, "smart mark as read");
FeedItem item = oldMedia.getItem();
// DBWriter.markItemRead(context, item, true, false);
DBWriter.markItemRead(context, item, true, false);
DBWriter.removeQueueItem(context, item, false);
DBWriter.addItemToPlaybackHistory(context, oldMedia);
if (UserPreferences.isAutoDelete()) {

View File

@ -319,7 +319,7 @@ public final class DBReader {
cursor.getInt(PodDBAdapter.IDX_FEED_SEL_STD_IS_PAGED) > 0,
cursor.getString(PodDBAdapter.IDX_FEED_SEL_STD_NEXT_PAGE_LINK),
cursor.getString(cursor.getColumnIndex(PodDBAdapter.KEY_HIDE)),
cursor.getInt(PodDBAdapter.IDX_FEED_SEL_STD_LAST_UPDATE_FAILED) > 0
cursor.getInt(cursor.getColumnIndex(PodDBAdapter.KEY_LAST_UPDATE_FAILED)) > 0
);
if (image != null) {

View File

@ -302,6 +302,7 @@ public final class DBTasks {
*/
public static void refreshFeed(Context context, Feed feed)
throws DownloadRequestException {
Log.d(TAG, "id " + feed.getId());
refreshFeed(context, feed, false);
}

View File

@ -302,8 +302,6 @@ public class PodDBAdapter {
public static final int IDX_FEED_SEL_STD_NEXT_PAGE_LINK = 17;
public static final int IDX_FEED_SEL_PREFERENCES_USERNAME = 18;
public static final int IDX_FEED_SEL_PREFERENCES_PASSWORD = 19;
public static final int IDX_FEED_SEL_STD_LAST_UPDATE_FAILED = 20;
/**
* Select all columns from the feeditems-table except description and
@ -810,9 +808,10 @@ public class PodDBAdapter {
}
public void setFeedLastUpdateFailed(long feedId, boolean failed) {
ContentValues values = new ContentValues();
values.put(KEY_LAST_UPDATE_FAILED, failed ? 1 : 0);
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(feedId)});
final String sql = "UPDATE " + TABLE_NAME_FEEDS
+ " SET " + KEY_LAST_UPDATE_FAILED+ "=" + (failed ? "1" : "0")
+ " WHERE " + KEY_ID + "="+ feedId;
db.execSQL(sql);
}
/**