improved media timeline load more

This commit is contained in:
Mariotaku Lee 2016-04-28 12:51:10 +08:00
parent 9f601c86d0
commit a227529e8f
6 changed files with 21 additions and 49 deletions

View File

@ -152,6 +152,7 @@ dependencies {
compile 'com.github.mariotaku.ObjectCursor:core:0.9.9'
compile 'com.github.mariotaku:MultiValueSwitch:0.9.4'
compile 'com.github.mariotaku:AbstractTask:0.9.1'
compile 'com.github.mariotaku.CommonsLibrary:parcel:0.9.2-SNAPSHOT'
}
task svgToDrawable(type: SvgDrawableTask) {

View File

@ -221,14 +221,16 @@ public abstract class ParcelableStatusesAdapter extends LoadMoreSupportAdapter<R
@Override
public boolean setData(List<ParcelableStatus> data) {
mData = data;
boolean changed = true;
if (data instanceof ObjectCursor || data == null || data.isEmpty()) {
mLastItemFiltered = false;
} else {
mLastItemFiltered = data.get(data.size() - 1).is_filtered;
changed = !data.equals(mData);
}
mData = data;
notifyDataSetChanged();
return true;
return changed;
}
public List<ParcelableStatus> getData() {

View File

@ -33,6 +33,7 @@ import android.view.KeyEvent;
import com.squareup.otto.Subscribe;
import org.mariotaku.commons.parcel.ParcelUtils;
import org.mariotaku.twidere.adapter.ParcelableUsersAdapter;
import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition;
import org.mariotaku.twidere.adapter.iface.IUsersAdapter;
@ -45,7 +46,6 @@ import org.mariotaku.twidere.util.AsyncTwitterWrapper;
import org.mariotaku.twidere.util.IntentUtils;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler;
import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback;
import org.mariotaku.twidere.util.ParcelUtils;
import org.mariotaku.twidere.util.RecyclerViewNavigationHelper;
import org.mariotaku.twidere.view.holder.UserViewHolder;
@ -227,7 +227,7 @@ public abstract class ParcelableUsersFragment extends AbsContentListRecyclerView
final ParcelableUsersAdapter adapter = getAdapter();
final int position = findPosition(adapter, event.getAccountKey(), event.getUserKey());
final List<ParcelableUser> data = adapter.getData();
if (position < 0 || position >= data.size()) return;
if (data == null || position < 0 || position >= data.size()) return;
if (shouldRemoveUser(position, event)) {
data.remove(position);
adapter.notifyItemRemoved(position);

View File

@ -8,6 +8,7 @@ import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.Loader;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -114,21 +115,23 @@ public class UserMediaTimelineFragment extends AbsContentRecyclerViewFragment<St
@Override
public void onLoadFinished(Loader<List<ParcelableStatus>> loader, List<ParcelableStatus> data) {
final StaggeredGridParcelableStatusesAdapter adapter = getAdapter();
adapter.setData(data);
if (!(loader instanceof IExtendedLoader) || ((IExtendedLoader) loader).isFromUser()) {
adapter.setLoadMoreSupportedPosition(hasMoreData(data) ? IndicatorPosition.END : IndicatorPosition.NONE);
}
if (loader instanceof IExtendedLoader) {
((IExtendedLoader) loader).setFromUser(false);
boolean changed = adapter.setData(data);
if (((IExtendedLoader) loader).isFromUser() && loader instanceof MediaTimelineLoader) {
String maxId = ((MediaTimelineLoader) loader).getMaxId();
String sinceId = ((MediaTimelineLoader) loader).getSinceId();
if (TextUtils.isEmpty(sinceId) && !TextUtils.isEmpty(maxId)) {
if (data != null && !data.isEmpty()) {
adapter.setLoadMoreSupportedPosition(changed ? IndicatorPosition.END : IndicatorPosition.NONE);
}
} else {
adapter.setLoadMoreSupportedPosition(IndicatorPosition.END);
}
}
((IExtendedLoader) loader).setFromUser(false);
showContent();
setLoadMoreIndicatorPosition(IndicatorPosition.NONE);
}
private boolean hasMoreData(List<ParcelableStatus> data) {
return true;
}
@Override
public void onLoaderReset(Loader<List<ParcelableStatus>> loader) {
getAdapter().setData(null);

View File

@ -25,6 +25,7 @@ import android.support.annotation.NonNull;
import android.support.annotation.WorkerThread;
import android.text.TextUtils;
import org.mariotaku.commons.parcel.ParcelUtils;
import org.mariotaku.twidere.api.twitter.Twitter;
import org.mariotaku.twidere.api.twitter.TwitterException;
import org.mariotaku.twidere.api.twitter.model.Paging;
@ -37,7 +38,6 @@ import org.mariotaku.twidere.model.util.ParcelableAccountUtils;
import org.mariotaku.twidere.model.util.ParcelableStatusUtils;
import org.mariotaku.twidere.util.InternalTwitterContentUtils;
import org.mariotaku.twidere.util.Nullables;
import org.mariotaku.twidere.util.ParcelUtils;
import org.mariotaku.twidere.util.TwitterAPIFactory;
import org.mariotaku.twidere.util.Utils;

View File

@ -1,34 +0,0 @@
package org.mariotaku.twidere.util;
import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.NonNull;
import java.lang.reflect.Field;
/**
* Created by mariotaku on 16/1/3.
*/
public class ParcelUtils {
private ParcelUtils() {
}
public static <T extends Parcelable> T clone(@NonNull T object) {
final Parcel parcel = Parcel.obtain();
try {
object.writeToParcel(parcel, 0);
parcel.setDataPosition(0);
final Field creatorField = object.getClass().getDeclaredField("CREATOR");
//noinspection unchecked
final Parcelable.Creator<T> creator = (Parcelable.Creator<T>) creatorField.get(null);
return creator.createFromParcel(parcel);
} catch (NoSuchFieldException e) {
throw new NoSuchFieldError("Missing CREATOR field");
} catch (IllegalAccessException e) {
throw new IllegalAccessError("Can't access CREATOR field");
} finally {
parcel.recycle();
}
}
}