(1) Fix refresh indicator (2) On download event, only refresh items that are affected

This commit is contained in:
Martin Fietz 2015-12-13 11:08:57 +01:00
parent 3bb8d9304a
commit a4dea4ba24
4 changed files with 31 additions and 19 deletions

View File

@ -303,6 +303,7 @@ public class AllEpisodesFragment extends Fragment {
View root = inflater.inflate(fragmentResource, container, false);
recyclerView = (RecyclerView) root.findViewById(android.R.id.list);
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.setHasFixedSize(true);
@ -397,14 +398,15 @@ public class AllEpisodesFragment extends Fragment {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
downloaderList = update.downloaders;
if(update.feedIds.length > 0) {
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
if (isUpdatingFeeds != update.feedIds.length > 0) {
getActivity().supportInvalidateOptionsMenu();
}
if(listAdapter != null && update.mediaIds.length > 0) {
for(long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(episodes, mediaId);
if(pos >= 0) {
listAdapter.notifyItemChanged(pos);
}
if(update.mediaIds.length > 0) {
if(listAdapter != null) {
listAdapter.notifyDataSetChanged();
}
}
}

View File

@ -9,7 +9,6 @@ import android.graphics.Color;
import android.graphics.LightingColorFilter;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.ListFragment;
import android.support.v4.util.Pair;
import android.support.v4.view.MenuItemCompat;
@ -417,15 +416,13 @@ public class ItemlistFragment extends ListFragment {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
downloaderList = update.downloaders;
if(update.feedIds.length > 0) {
if (isUpdatingFeed != event.update.feedIds.length > 0) {
updateProgressBarVisibility();
}
if(update.mediaIds.length > 0) {
if (adapter != null) {
if(adapter != null && update.mediaIds.length > 0) {
adapter.notifyDataSetChanged();
}
}
}
private EventDistributor.EventListener contentUpdate = new EventDistributor.EventListener() {

View File

@ -179,13 +179,15 @@ public class QueueFragment extends Fragment {
Log.d(TAG, "onEventMainThread() called with: " + "event = [" + event + "]");
DownloaderUpdate update = event.update;
downloaderList = update.downloaders;
if (update.feedIds.length > 0) {
if (isUpdatingFeeds != updateRefreshMenuItemChecker.isRefreshing()) {
if (isUpdatingFeeds != update.feedIds.length > 0) {
getActivity().supportInvalidateOptionsMenu();
}
} else if (update.mediaIds.length > 0) {
if (recyclerAdapter != null) {
recyclerAdapter.notifyDataSetChanged();
if (recyclerAdapter != null && update.mediaIds.length > 0) {
for (long mediaId : update.mediaIds) {
int pos = FeedItemUtil.indexOfItemWithMediaId(queue, mediaId);
if (pos >= 0) {
recyclerAdapter.notifyItemChanged(pos);
}
}
}
}
@ -363,6 +365,7 @@ public class QueueFragment extends Fragment {
View root = inflater.inflate(R.layout.queue_fragment, container, false);
infoBar = (TextView) root.findViewById(R.id.info_bar);
recyclerView = (RecyclerView) root.findViewById(R.id.recyclerView);
recyclerView.getItemAnimator().setSupportsChangeAnimations(false);
layoutManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(new HorizontalDividerItemDecoration.Builder(getActivity()).build());

View File

@ -29,6 +29,16 @@ public class FeedItemUtil {
return -1;
}
public static int indexOfItemWithMediaId(List<FeedItem> items, long mediaId) {
for(int i=0; i < items.size(); i++) {
FeedItem item = items.get(i);
if(item != null && item.getMedia() != null && item.getMedia().getId() == mediaId) {
return i;
}
}
return -1;
}
public static long[] getIds(FeedItem... items) {
if(items == null || items.length == 0) {
return new long[0];