Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recycler view for Episodes Fragment #1336

Merged
merged 11 commits into from
Nov 5, 2015

Conversation

TomHennen
Copy link
Contributor

This swaps our use of DSLV for recycler view in the Episodes Fragment.

We SHOULD NOT merge this in for 1.4. Instead this will be targeted for the next version where we can build on in for RecyclerView in the Queue.

I've integrated the use of SnackBar as demonstrated by @mfietz. Ideally we'd do something more like this: https://github.com/hudomju/android-swipe-to-dismiss-undo, but we'd need it to be compatible with api 10.

@TomHennen TomHennen added this to the FUTURE milestone Nov 4, 2015

private final Context context;
private final ItemAccess itemAccess;
private final ActionButtonCallback actionButtonCallback;
private final ActionButtonUtils actionButtonUtils;
private final boolean showOnlyNewEpisodes;
private final MainActivity mainActivity;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not really cause an activity leak (as long as we set the adapter in the activity to null), but I could sleep better if this was a WeakReference

@mfietz
Copy link
Contributor

mfietz commented Nov 4, 2015

Just had an idea to get rid of the stupid AllEpisodesFragment constructor warning. We simply change the attributes to methods.
AllEpisodesFragment:

private boolean showOnlyNewEpisodes() { return false; }
private String getPrefName() { return DEFAULT_PREF_NAME; }

NewEpisodesFragment:

@Override
private boolean showOnlyNewEpisodes() { return true; }
@Override
private String getPrefName() { return PREF_NAME; }

progLoading = (ProgressBar) root.findViewById(R.id.progLoading);
listView = (RecyclerView) root.findViewById(android.R.id.list);
layoutManager = new LinearLayoutManager(getActivity());
listView.setLayoutManager(layoutManager);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

listView.setHasFixedSize(true);

listView → recyclerView?

Also, you can take https://github.com/mfietz/AntennaPod/blob/recyclerview/app/src/main/java/de/danoeh/antennapod/view/DividerItemDecoration.java and

RecyclerView.ItemDecoration itemDecoration = new DividerItemDecoration(getActivity(), null);
        listView.addItemDecoration(itemDecoration);

@mfietz
Copy link
Contributor

mfietz commented Nov 4, 2015

Fresh develop installation, one feed subscribed, short playing around in episodes, upgrade to this PR:

java.lang.ClassCastException: java.lang.Integer cannot be cast to java.lang.Float
    at android.app.SharedPreferencesImpl.getFloat(SharedPreferencesImpl.java:254)
    at de.danoeh.antennapod.fragment.AllEpisodesFragment.restoreScrollPosition(AllEpisodesFragment.java:184)
    at de.danoeh.antennapod.fragment.AllEpisodesFragment.onFragmentLoaded(AllEpisodesFragment.java:326)
    at de.danoeh.antennapod.fragment.AllEpisodesFragment.lambda$loadItems$41(AllEpisodesFragment.java:414)
    at de.danoeh.antennapod.fragment.AllEpisodesFragment.access$lambda$1(AllEpisodesFragment.java)
    at de.danoeh.antennapod.fragment.AllEpisodesFragment$$Lambda$2.call(Unknown Source)
    at rx.Observable$31.onNext(Observable.java:7593)
    at rx.observers.SafeSubscriber.onNext(SafeSubscriber.java:130)
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber.pollQueue(OperatorObserveOn.java:208)
    at rx.internal.operators.OperatorObserveOn$ObserveOnSubscriber$2.call(OperatorObserveOn.java:170)
    at rx.internal.schedulers.ScheduledAction.run(ScheduledAction.java:55)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5001)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
    at dalvik.system.NativeStart.main(Native Method)

editor.putInt(PREF_KEY_LIST_SELECTION, 0);
editor.putInt(PREF_KEY_LIST_TOP, 0);
editor.putInt(PREF_SCROLL_POSITION, 0);
editor.putInt(PREF_SCROLL_OFFSET, 0);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

editor.putFloat(PREF_SCROLL_OFFSET, 0.0f);

Snackbar snackbar = Snackbar.make(root, getString(R.string.removed_item),
Snackbar.LENGTH_LONG);
snackbar.setAction(getString(R.string.undo), v -> {
DBWriter.addFavoriteItem(item);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this doesn't put it back in the same position it was in before, that may be confusing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably the solution, however we'd have to update our supportlib use to 23 to get it: http://stackoverflow.com/a/32190462/6839

(though someone else suggests a hack/workaround to use in the meantime). That could be promising. It would also get rid of the runnable business we have to do for NewEpisodesFragment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, couldn't we just create an Pair<FeedItem,Integer> that also holds the position and submit that to snackbar for undo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not really tracking position in favorites at this point. It mostly reflects the order you added things. Not sure I want to worry about order just to resolve this issue.

Another solution, which might make more sense anyways, is to sort the items in Favorites. We could use the date the item was published or just sort alphabetically by title.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to get started on this (and you think it's minimally acceptable) you could merge now while we work on this solution in another issue/PR.

@TomHennen TomHennen modified the milestones: 1.4, FUTURE Nov 5, 2015
@TomHennen
Copy link
Contributor Author

After discussion with @mfietz we're going to get this in to 1.4 since DSLV is causing crashes for people.

TomHennen added a commit that referenced this pull request Nov 5, 2015
Recycler view for Episodes Fragment
@TomHennen TomHennen merged commit 3b003c6 into AntennaPod:develop Nov 5, 2015
@TomHennen TomHennen deleted the recycler_view branch November 22, 2015 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants