diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/AccountResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/AccountResources.java index 32184e6c8..99e7a6372 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/AccountResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/AccountResources.java @@ -23,6 +23,7 @@ import android.support.annotation.Nullable; import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.mastodon.model.Account; import org.mariotaku.microblog.library.mastodon.model.AccountUpdate; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.mastodon.model.Relationship; import org.mariotaku.microblog.library.mastodon.model.Status; import org.mariotaku.microblog.library.mastodon.model.TimelineOption; @@ -34,8 +35,6 @@ import org.mariotaku.restfu.annotation.param.Param; import org.mariotaku.restfu.annotation.param.Path; import org.mariotaku.restfu.annotation.param.Query; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ @@ -52,15 +51,15 @@ public interface AccountResources { Account updateCredentials(@Param AccountUpdate update) throws MicroBlogException; @GET("/v1/accounts/{id}/followers") - List getFollowers(@Path("id") String id, @Query Paging paging) + LinkHeaderList getFollowers(@Path("id") String id, @Query Paging paging) throws MicroBlogException; @GET("/v1/accounts/{id}/following") - List getFollowing(@Path("id") String id, @Query Paging paging) + LinkHeaderList getFollowing(@Path("id") String id, @Query Paging paging) throws MicroBlogException; @GET("/v1/accounts/{id}/statuses") - List getStatuses(@Path("id") String id, @Query Paging paging, + LinkHeaderList getStatuses(@Path("id") String id, @Query Paging paging, @Query TimelineOption option) throws MicroBlogException; @POST("/v1/accounts/{id}/follow") @@ -82,8 +81,8 @@ public interface AccountResources { Relationship unmuteUser(@Path("id") String id) throws MicroBlogException; @GET("/v1/accounts/relationships") - List getRelationships(@Path("id") String id) throws MicroBlogException; + LinkHeaderList getRelationships(@Path("id") String id) throws MicroBlogException; @GET("/v1/accounts/search") - List searchAccounts(@Query("q") String query, @Nullable @Query Paging paging) throws MicroBlogException; + LinkHeaderList searchAccounts(@Query("q") String query, @Nullable @Query Paging paging) throws MicroBlogException; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/BlockResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/BlockResources.java index 84523b07e..28ffb5fcc 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/BlockResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/BlockResources.java @@ -19,17 +19,16 @@ package org.mariotaku.microblog.library.mastodon.api; import org.mariotaku.microblog.library.mastodon.model.Account; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.twitter.model.Paging; import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.param.Query; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ public interface BlockResources { @GET("/v1/blocks") - List getBlocks(@Query Paging paging); + LinkHeaderList getBlocks(@Query Paging paging); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FavouriteResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FavouriteResources.java index 295511aef..bb172b8c9 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FavouriteResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FavouriteResources.java @@ -19,13 +19,12 @@ package org.mariotaku.microblog.library.mastodon.api; import org.mariotaku.microblog.library.MicroBlogException; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.mastodon.model.Status; import org.mariotaku.microblog.library.twitter.model.Paging; import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.param.Query; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ @@ -36,6 +35,6 @@ public interface FavouriteResources { * @return An array of {@link Status} favourited by the authenticated user. */ @GET("/v1/favourites") - List getFavourites(@Query Paging paging) throws MicroBlogException; + LinkHeaderList getFavourites(@Query Paging paging) throws MicroBlogException; } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FollowRequestResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FollowRequestResources.java index 7780a28e6..9b2336426 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FollowRequestResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/FollowRequestResources.java @@ -19,16 +19,15 @@ package org.mariotaku.microblog.library.mastodon.api; import org.mariotaku.microblog.library.mastodon.model.Account; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.twitter.model.Paging; import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.param.Query; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ public interface FollowRequestResources { @GET("/v1/follow_requests") - List getFollowRequests(@Query Paging paging); + LinkHeaderList getFollowRequests(@Query Paging paging); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/MuteResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/MuteResources.java index 0926eb6e0..545f85aab 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/MuteResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/MuteResources.java @@ -19,17 +19,16 @@ package org.mariotaku.microblog.library.mastodon.api; import org.mariotaku.microblog.library.mastodon.model.Account; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.twitter.model.Paging; import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.param.Query; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ public interface MuteResources { @GET("/v1/mutes") - List getMutes(@Query Paging paging); + LinkHeaderList getMutes(@Query Paging paging); } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/StatusResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/StatusResources.java index 89c458019..692abb3cf 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/StatusResources.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/api/StatusResources.java @@ -22,6 +22,7 @@ import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.microblog.library.mastodon.model.Account; import org.mariotaku.microblog.library.mastodon.model.Card; import org.mariotaku.microblog.library.mastodon.model.Context; +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList; import org.mariotaku.microblog.library.mastodon.model.Status; import org.mariotaku.microblog.library.mastodon.model.StatusUpdate; import org.mariotaku.restfu.annotation.method.GET; @@ -29,8 +30,6 @@ import org.mariotaku.restfu.annotation.method.POST; import org.mariotaku.restfu.annotation.param.Param; import org.mariotaku.restfu.annotation.param.Path; -import java.util.List; - /** * Created by mariotaku on 2017/4/17. */ @@ -46,10 +45,10 @@ public interface StatusResources { Card getStatusCard(@Path("id") String id) throws MicroBlogException; @GET("/v1/statuses/{id}/reblogged_by") - List getStatusRebloggedBy(@Path("id") String id) throws MicroBlogException; + LinkHeaderList getStatusRebloggedBy(@Path("id") String id) throws MicroBlogException; @GET("/v1/statuses/{id}/favourited_by") - List getStatusFavouritedBy(@Path("id") String id) throws MicroBlogException; + LinkHeaderList getStatusFavouritedBy(@Path("id") String id) throws MicroBlogException; @POST("/v1/statuses") Status postStatus(@Param StatusUpdate update) throws MicroBlogException; diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList$$JsonObjectMapper.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList$$JsonObjectMapper.java new file mode 100644 index 000000000..193e5379a --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList$$JsonObjectMapper.java @@ -0,0 +1,68 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2017 Mariotaku Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mariotaku.microblog.library.mastodon.model; + +import com.bluelinelabs.logansquare.JsonMapper; +import com.bluelinelabs.logansquare.LoganSquare; +import com.bluelinelabs.logansquare.ParameterizedType; +import com.bluelinelabs.logansquare.util.SimpleArrayMap; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; + +import org.mariotaku.microblog.library.annotation.NoObfuscate; + +import java.io.IOException; + +@SuppressWarnings("unused") +@NoObfuscate +public final class LinkHeaderList$$JsonObjectMapper extends JsonMapper> { + private final JsonMapper m69ClassJsonMapper; + + public LinkHeaderList$$JsonObjectMapper(ParameterizedType type, ParameterizedType TType, SimpleArrayMap partialMappers) { + partialMappers.put(type, this); + //noinspection unchecked + m69ClassJsonMapper = LoganSquare.mapperFor(TType, partialMappers); + } + + @Override + public LinkHeaderList parse(JsonParser jsonParser) throws IOException { + if (jsonParser.getCurrentToken() == null) { + jsonParser.nextToken(); + } + LinkHeaderList instance = new LinkHeaderList<>(); + final JsonToken currentToken = jsonParser.getCurrentToken(); + if (currentToken == JsonToken.START_ARRAY) { + instance.addAll(m69ClassJsonMapper.parseList(jsonParser)); + } else { + jsonParser.skipChildren(); + } + return instance; + } + + @Override + public void parseField(LinkHeaderList instance, String fieldName, JsonParser jsonParser) throws IOException { + + } + + @Override + public void serialize(LinkHeaderList object, JsonGenerator jsonGenerator, boolean writeStartAndEnd) throws IOException { + throw new UnsupportedOperationException(); + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList.java new file mode 100644 index 000000000..ae486d3cd --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/mastodon/model/LinkHeaderList.java @@ -0,0 +1,80 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2017 Mariotaku Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mariotaku.microblog.library.mastodon.model; + +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.text.TextUtils; + +import org.mariotaku.restfu.http.HttpResponse; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by mariotaku on 2017/4/21. + */ +public class LinkHeaderList extends ArrayList { + + @NonNull + private Map linkParts = new HashMap<>(); + + public LinkHeaderList(int initialCapacity) { + super(initialCapacity); + } + + public LinkHeaderList() { + } + + public LinkHeaderList(@NonNull Collection c) { + super(c); + } + + public final void processResponseHeader(HttpResponse resp) { + linkParts.clear(); + String linkHeader = resp.getHeader("Link"); + if (linkHeader == null) return; + for (String link : TextUtils.split(linkHeader, ",")) { + String[] segments = TextUtils.split(link, ";"); + if (segments.length < 2) continue; + String linkPart = segments[0].trim(); + if (!linkPart.startsWith("<") || !linkPart.endsWith(">")) + continue; + linkPart = linkPart.substring(1, linkPart.length() - 1); + for (int i = 1; i < segments.length; i++) { + String[] rel = TextUtils.split(segments[i].trim(), "="); + if (rel.length < 2 || !"rel".equals(rel[0])) + continue; + + String relValue = rel[1]; + if (relValue.startsWith("\"") && relValue.endsWith("\"")) + relValue = relValue.substring(1, relValue.length() - 1); + + linkParts.put(relValue, linkPart); + } + } + } + + @Nullable + public String getLinkPart(String key) { + return linkParts.get(key); + } +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/StatusNet.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/StatusNet.java index 65b5263b3..76d8ae2aa 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/StatusNet.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/StatusNet.java @@ -18,6 +18,7 @@ package org.mariotaku.microblog.library.statusnet; +import org.mariotaku.microblog.library.statusnet.api.TimelineResources; import org.mariotaku.restfu.annotation.method.GET; import org.mariotaku.restfu.annotation.param.Query; import org.mariotaku.microblog.library.statusnet.api.GroupResources; @@ -30,7 +31,8 @@ import org.mariotaku.microblog.library.twitter.model.User; /** * Created by mariotaku on 16/3/4. */ -public interface StatusNet extends StatusNetResources, GroupResources, SearchResources, UserResources { +public interface StatusNet extends StatusNetResources, GroupResources, SearchResources, + UserResources, TimelineResources { @GET("/externalprofile/show.json") User showExternalProfile(@Query("profileurl") String profileUrl) throws MicroBlogException; diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/api/TimelineResources.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/api/TimelineResources.java new file mode 100644 index 000000000..fd1d1849e --- /dev/null +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/statusnet/api/TimelineResources.java @@ -0,0 +1,36 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright 2012-2017 Mariotaku Lee + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.mariotaku.microblog.library.statusnet.api; + +import org.mariotaku.microblog.library.MicroBlogException; +import org.mariotaku.microblog.library.twitter.model.Paging; +import org.mariotaku.microblog.library.twitter.model.ResponseList; +import org.mariotaku.microblog.library.twitter.model.Status; +import org.mariotaku.restfu.annotation.method.GET; +import org.mariotaku.restfu.annotation.param.Query; + +/** + * Created by mariotaku on 2017/4/21. + */ + +public interface TimelineResources { + + @GET("/statuses/networkpublic_timeline.json") + ResponseList getNetworkPublicTimeline(@Query Paging paging) throws MicroBlogException; +} diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/IDs$$JsonObjectMapper.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/IDs$$JsonObjectMapper.java index f179c3450..d596ac301 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/IDs$$JsonObjectMapper.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/IDs$$JsonObjectMapper.java @@ -23,6 +23,8 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import org.mariotaku.microblog.library.annotation.NoObfuscate; + import java.io.IOException; import java.util.ArrayList; import java.util.List; @@ -32,6 +34,7 @@ import java.util.List; * Created by mariotaku on 15/10/21. */ @SuppressWarnings("unused") +@NoObfuscate public class IDs$$JsonObjectMapper extends JsonMapper { @SuppressWarnings("TryWithIdenticalCatches") diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/PageableResponseList$$JsonObjectMapper.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/PageableResponseList$$JsonObjectMapper.java index 424f97702..284da7d1b 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/PageableResponseList$$JsonObjectMapper.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/PageableResponseList$$JsonObjectMapper.java @@ -26,9 +26,12 @@ import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonToken; +import org.mariotaku.microblog.library.annotation.NoObfuscate; + import java.io.IOException; @SuppressWarnings("unused") +@NoObfuscate public final class PageableResponseList$$JsonObjectMapper extends JsonMapper> { private final JsonMapper m84ClassJsonMapper; diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Paging.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Paging.java index ad2c307bb..e379d9811 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Paging.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/Paging.java @@ -45,10 +45,6 @@ public class Paging extends SimpleValueMap { put("count", count); } - public void setPage(int page) { - put("page", page); - } - public void setCursor(long cursor) { put("cursor", cursor); } @@ -61,10 +57,6 @@ public class Paging extends SimpleValueMap { put("latest_results", latestResults); } - public void setRpp(int rpp) { - put("rpp", rpp); - } - public Paging sinceId(String sinceId) { setSinceId(sinceId); return this; @@ -96,7 +88,7 @@ public class Paging extends SimpleValueMap { } public Paging page(int page) { - setPage(page); + put("page", page); return this; } @@ -110,8 +102,13 @@ public class Paging extends SimpleValueMap { return this; } + public Paging limit(int limit) { + put("limit", limit); + return this; + } + public Paging rpp(int rpp) { - setRpp(rpp); + put("rpp", rpp); return this; } } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseCode.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseCode.java index 4356ba7bc..719f26666 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseCode.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseCode.java @@ -18,9 +18,11 @@ package org.mariotaku.microblog.library.twitter.model; +import android.support.annotation.NonNull; + +import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.restfu.RestConverter; import org.mariotaku.restfu.http.HttpResponse; -import org.mariotaku.microblog.library.MicroBlogException; /** * Created by mariotaku on 15/6/15. @@ -43,8 +45,9 @@ public class ResponseCode { public static class ResponseConverter implements RestConverter { + @NonNull @Override - public ResponseCode convert(HttpResponse response) { + public ResponseCode convert(@NonNull HttpResponse response) { return new ResponseCode(response); } } diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseList.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseList.java index 98c368291..060158987 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseList.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/model/ResponseList.java @@ -18,11 +18,10 @@ package org.mariotaku.microblog.library.twitter.model; -import org.mariotaku.restfu.http.HttpResponse; import org.mariotaku.microblog.library.annotation.NoObfuscate; import org.mariotaku.microblog.library.twitter.util.InternalParseUtil; +import org.mariotaku.restfu.http.HttpResponse; -import java.util.AbstractList; import java.util.ArrayList; import java.util.List; @@ -31,48 +30,16 @@ import java.util.List; * Created by mariotaku on 15/5/7. */ @NoObfuscate -public class ResponseList extends AbstractList implements TwitterResponse { +public class ResponseList extends ArrayList implements TwitterResponse { - private List list; private int accessLevel; private RateLimitStatus rateLimitStatus; public ResponseList(List list) { - this.list = list; - } - - @Override - public void add(int location, T object) { - list.add(location, object); - } - - @Override - public T set(int location, T object) { - return list.set(location, object); - } - - @Override - public T get(int location) { - return list.get(location); - } - - @Override - public T remove(int location) { - return list.remove(location); - } - - @Override - public void clear() { - list.clear(); - } - - @Override - public int size() { - return list.size(); + super(list); } public ResponseList() { - this(new ArrayList()); } @Override diff --git a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/util/OAuthTokenResponseConverter.java b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/util/OAuthTokenResponseConverter.java index e2f5414d7..644e30fe3 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/util/OAuthTokenResponseConverter.java +++ b/twidere.component.common/src/main/java/org/mariotaku/microblog/library/twitter/util/OAuthTokenResponseConverter.java @@ -18,6 +18,8 @@ package org.mariotaku.microblog.library.twitter.util; +import android.support.annotation.NonNull; + import org.mariotaku.microblog.library.MicroBlogException; import org.mariotaku.restfu.RestConverter; import org.mariotaku.restfu.RestFuUtils; @@ -35,8 +37,9 @@ import java.text.ParseException; * Created by mariotaku on 16/5/21. */ public class OAuthTokenResponseConverter implements RestConverter { + @NonNull @Override - public OAuthToken convert(HttpResponse response) throws IOException, ConvertException { + public OAuthToken convert(@NonNull HttpResponse response) throws IOException, ConvertException { final Body body = response.getBody(); try { final ContentType contentType = body.contentType(); diff --git a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java index 6e82f6e90..e96b6c331 100644 --- a/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java +++ b/twidere.component.common/src/main/java/org/mariotaku/twidere/constant/IntentConstants.java @@ -161,6 +161,9 @@ public interface IntentConstants { String EXTRA_URL = "url"; String EXTRA_PROFILE_URL = "profile_url"; String EXTRA_NEXT_PAGE = "next_page"; + String EXTRA_NEXT_PAGINATION = "next_pagination"; + String EXTRA_PREV_PAGINATION = "prev_pagination"; + String EXTRA_PAGINATION = "pagination"; String EXTRA_NEXT_CURSOR = "next_cursor"; String EXTRA_PREV_CURSOR = "prev_cursor"; String EXTRA_EXTRA_INTENT = "extra_intent"; diff --git a/twidere/src/main/java/org/mariotaku/microblog/library/twitter/model/IDsAccessor.java b/twidere/src/main/java/org/mariotaku/microblog/library/twitter/model/IDsAccessor.java index 5661a7c9d..c3f1c209c 100644 --- a/twidere/src/main/java/org/mariotaku/microblog/library/twitter/model/IDsAccessor.java +++ b/twidere/src/main/java/org/mariotaku/microblog/library/twitter/model/IDsAccessor.java @@ -28,8 +28,10 @@ import android.support.annotation.NonNull; public class IDsAccessor { - public static void setIds(@NonNull final IDs ids, @NonNull final String[] array) { + @NonNull + public static IDs setIds(@NonNull final IDs ids, @NonNull final String[] array) { ids.ids = array; + return ids; } } diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/CursorPagination.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/CursorPagination.java new file mode 100644 index 000000000..922e75dad --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/CursorPagination.java @@ -0,0 +1,79 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; + +import org.jetbrains.annotations.Nullable; +import org.mariotaku.microblog.library.twitter.model.Paging; + +/** + * Created by mariotaku on 2017/4/21. + */ +@ParcelablePlease +public class CursorPagination implements Pagination, Parcelable { + + String cursor; + + CursorPagination() { + } + + public String getCursor() { + return cursor; + } + + @Override + public void applyTo(Paging paging) { + paging.cursor(cursor); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + CursorPaginationParcelablePlease.writeToParcel(this, dest, flags); + } + + public static final Creator CREATOR = new Creator() { + public CursorPagination createFromParcel(Parcel source) { + CursorPagination target = new CursorPagination(); + CursorPaginationParcelablePlease.readFromParcel(target, source); + return target; + } + + public CursorPagination[] newArray(int size) { + return new CursorPagination[size]; + } + }; + + @Nullable + public static CursorPagination valueOf(long cursor) { + if (cursor == 0) return null; + final CursorPagination pagination = new CursorPagination(); + pagination.cursor = String.valueOf(cursor); + return pagination; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PagePagination.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PagePagination.java new file mode 100644 index 000000000..d71335a59 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PagePagination.java @@ -0,0 +1,80 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; + +import org.jetbrains.annotations.Nullable; +import org.mariotaku.microblog.library.twitter.model.Paging; + +/** + * Created by mariotaku on 2017/4/21. + */ +@ParcelablePlease +public class PagePagination implements Pagination, Parcelable { + + int page; + + public int getPage() { + return page; + } + + public void setPage(int page) { + this.page = page; + } + + @Override + public void applyTo(Paging paging) { + paging.page(page); + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + PagePaginationParcelablePlease.writeToParcel(this, dest, flags); + } + + public static final Creator CREATOR = new Creator() { + public PagePagination createFromParcel(Parcel source) { + PagePagination target = new PagePagination(); + PagePaginationParcelablePlease.readFromParcel(target, source); + return target; + } + + public PagePagination[] newArray(int size) { + return new PagePagination[size]; + } + }; + + @Nullable + public static PagePagination valueOf(int page) { + if (page <= 0) return null; + final PagePagination pagination = new PagePagination(); + pagination.page = page; + return pagination; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedArrayList.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedArrayList.java new file mode 100644 index 000000000..37841abba --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedArrayList.java @@ -0,0 +1,64 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import android.support.annotation.NonNull; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Created by mariotaku on 2017/4/21. + */ + +public class PaginatedArrayList extends ArrayList implements PaginatedList { + + private Pagination previousPage; + private Pagination nextPage; + + public PaginatedArrayList(int initialCapacity) { + super(initialCapacity); + } + + public PaginatedArrayList() { + } + + public PaginatedArrayList(@NonNull Collection c) { + super(c); + } + + @Override + public Pagination getPreviousPage() { + return previousPage; + } + + @Override + public Pagination getNextPage() { + return nextPage; + } + + public void setPreviousPage(Pagination previousPage) { + this.previousPage = previousPage; + } + + public void setNextPage(Pagination nextPage) { + this.nextPage = nextPage; + } +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedList.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedList.java new file mode 100644 index 000000000..a6a29a519 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/PaginatedList.java @@ -0,0 +1,34 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import java.util.List; + +/** + * Created by mariotaku on 2017/4/21. + */ + +public interface PaginatedList extends List { + + Pagination getPreviousPage(); + + Pagination getNextPage(); + +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/Pagination.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/Pagination.java new file mode 100644 index 000000000..9db019f6e --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/Pagination.java @@ -0,0 +1,34 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import android.os.Parcelable; + +import org.mariotaku.microblog.library.twitter.model.Paging; + +/** + * Created by mariotaku on 2017/4/21. + */ + +public interface Pagination extends Parcelable { + + void applyTo(Paging paging); + +} diff --git a/twidere/src/main/java/org/mariotaku/twidere/model/pagination/SinceMaxPagination.java b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/SinceMaxPagination.java new file mode 100644 index 000000000..51a4d70c5 --- /dev/null +++ b/twidere/src/main/java/org/mariotaku/twidere/model/pagination/SinceMaxPagination.java @@ -0,0 +1,86 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.model.pagination; + +import android.os.Parcel; +import android.os.Parcelable; + +import com.hannesdorfmann.parcelableplease.annotation.ParcelablePlease; + +import org.mariotaku.microblog.library.twitter.model.Paging; + +/** + * Created by mariotaku on 2017/4/21. + */ + +@ParcelablePlease +public class SinceMaxPagination implements Pagination, Parcelable { + + String sinceId; + String maxId; + + public String getSinceId() { + return sinceId; + } + + public void setSinceId(String sinceId) { + this.sinceId = sinceId; + } + + public String getMaxId() { + return maxId; + } + + public void setMaxId(String maxId) { + this.maxId = maxId; + } + + @Override + public void applyTo(Paging paging) { + if (sinceId != null) { + paging.sinceId(sinceId); + } + if (maxId != null) { + paging.maxId(maxId); + } + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + SinceMaxPaginationParcelablePlease.writeToParcel(this, dest, flags); + } + + public static final Creator CREATOR = new Creator() { + public SinceMaxPagination createFromParcel(Parcel source) { + SinceMaxPagination target = new SinceMaxPagination(); + SinceMaxPaginationParcelablePlease.readFromParcel(target, source); + return target; + } + + public SinceMaxPagination[] newArray(int size) { + return new SinceMaxPagination[size]; + } + }; +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt index 1de86f948..a113c404b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/LinkHandlerActivity.kt @@ -62,6 +62,7 @@ import org.mariotaku.twidere.fragment.message.MessageConversationInfoFragment import org.mariotaku.twidere.fragment.message.MessageNewConversationFragment import org.mariotaku.twidere.fragment.message.MessagesConversationFragment import org.mariotaku.twidere.fragment.message.MessagesEntriesFragment +import org.mariotaku.twidere.fragment.users.* import org.mariotaku.twidere.graphic.EmptyDrawable import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.analyzer.PurchaseFinished @@ -521,7 +522,7 @@ class LinkHandlerActivity : BaseActivity(), SystemWindowsInsetsCallback, IContro @Throws(Utils.NoAccountException::class) private fun createFragmentForIntent(context: Context, linkId: Int, intent: Intent): Fragment? { - intent.setExtrasClassLoader(context.classLoader) + intent.setExtrasClassLoader(classLoader) val extras = intent.extras val uri = intent.data val fragment: Fragment diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt index dfd4a2e20..08752df8f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserListSelectorActivity.kt @@ -39,11 +39,12 @@ import org.mariotaku.twidere.adapter.SimpleParcelableUserListsAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListOwnershipsLoader -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader +import org.mariotaku.twidere.loader.userlists.UserListOwnershipsLoader import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.util.ContentScrollHandler import org.mariotaku.twidere.util.ListViewScrollHandler @@ -53,13 +54,26 @@ class UserListSelectorActivity : BaseActivity(), override lateinit var adapter: SimpleParcelableUserListsAdapter + override var refreshing: Boolean + get() { + return supportLoaderManager.hasRunningLoadersSafe() + } + set(value) { + } + + override val reachingStart: Boolean + get() = listView.firstVisiblePosition <= 0 + + override val reachingEnd: Boolean + get() = listView.lastVisiblePosition >= listView.count - 1 + private val accountKey: UserKey? get() = intent.getParcelableExtra(EXTRA_ACCOUNT_KEY) private val showMyLists: Boolean get() = intent.getBooleanExtra(EXTRA_SHOW_MY_LISTS, false) private var userKey: UserKey? = null - private var nextCursor: Long = -1 + private var nextPagination: Pagination? = null private var loaderInitialized: Boolean = false @@ -135,7 +149,7 @@ class UserListSelectorActivity : BaseActivity(), val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val nextCursor = args.getLong(EXTRA_NEXT_CURSOR) - return UserListOwnershipsLoader(this, accountKey, userKey, null, nextCursor, adapter.all) + return UserListOwnershipsLoader(this, accountKey, userKey, null, adapter.all) } override fun onLoaderReset(loader: Loader>?) { @@ -152,8 +166,8 @@ class UserListSelectorActivity : BaseActivity(), } adapter.setData(data) refreshing = false - if (loader is ICursorSupportLoader) { - nextCursor = loader.nextCursor + if (loader is IPaginationLoader) { + nextPagination = loader.nextPagination } showList() } @@ -161,18 +175,6 @@ class UserListSelectorActivity : BaseActivity(), override fun setControlVisible(visible: Boolean) { } - override var refreshing: Boolean - get() { - return supportLoaderManager.hasRunningLoadersSafe() - } - set(value) { - } - - override val reachingStart: Boolean - get() = listView.firstVisiblePosition <= 0 - - override val reachingEnd: Boolean - get() = listView.lastVisiblePosition >= listView.count - 1 override fun onLoadMoreContents(@IndicatorPosition position: Long) { val accountKey = this.accountKey ?: return @@ -181,10 +183,10 @@ class UserListSelectorActivity : BaseActivity(), return } adapter.loadMoreIndicatorPosition = position - loadUserLists(accountKey, userKey, nextCursor) + loadUserLists(accountKey, userKey, nextPagination) } - private fun loadUserLists(accountKey: UserKey, userKey: UserKey, nextCursor: Long = -1) { + private fun loadUserLists(accountKey: UserKey, userKey: UserKey, pagination: Pagination? = null) { if (userKey != this.userKey) { adapter.clear() showProgress() @@ -193,7 +195,7 @@ class UserListSelectorActivity : BaseActivity(), val args = Bundle { this[EXTRA_ACCOUNT_KEY] = accountKey this[EXTRA_USER_KEY] = userKey - this[EXTRA_NEXT_CURSOR] = nextCursor + this[EXTRA_PAGINATION] = pagination } if (!loaderInitialized) { loaderInitialized = true diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserSelectorActivity.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserSelectorActivity.kt index 8655837de..4c84dc845 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserSelectorActivity.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/activity/UserSelectorActivity.kt @@ -37,6 +37,7 @@ import org.mariotaku.ktextension.isNotNullOrEmpty import org.mariotaku.ktextension.set import org.mariotaku.twidere.R import org.mariotaku.twidere.adapter.SimpleParcelableUsersAdapter +import org.mariotaku.twidere.app.TwidereApplication import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.loader.CacheUserSearchLoader import org.mariotaku.twidere.model.ParcelableUser @@ -100,7 +101,7 @@ class UserSelectorActivity : BaseActivity(), OnItemClickListener, LoaderManager. val list = view as ListView val user = adapter.getItem(position - list.headerViewsCount) ?: return val data = Intent() - data.setExtrasClassLoader(classLoader) + data.setExtrasClassLoader(TwidereApplication::class.java.classLoader) data.putExtra(EXTRA_USER, user) data.putExtra(EXTRA_EXTRAS, intent.getBundleExtra(EXTRA_EXTRAS)) setResult(Activity.RESULT_OK, data) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/exception/APINotSupportedException.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/exception/APINotSupportedException.kt new file mode 100644 index 000000000..2199e670c --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/exception/APINotSupportedException.kt @@ -0,0 +1,24 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.exception + +import org.mariotaku.microblog.library.MicroBlogException + +class APINotSupportedException(platform: String = "this platform") : MicroBlogException("API not supported for $platform") diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/api/MicroBlogExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/api/MicroBlogExtensions.kt index f36002699..75aa03800 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/api/MicroBlogExtensions.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/api/MicroBlogExtensions.kt @@ -21,17 +21,39 @@ package org.mariotaku.twidere.extension.api import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.twitter.model.IDs import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.annotation.AccountType - -/** - * Created by mariotaku on 2017/4/20. - */ - +import org.mariotaku.twidere.model.pagination.CursorPagination +import org.mariotaku.twidere.model.pagination.PaginatedArrayList +import org.mariotaku.twidere.model.pagination.PaginatedList @Throws(MicroBlogException::class) -fun MicroBlog.showUser(id: String?, screenName: String?, accountType: String?): User { +fun MicroBlog.tryShowUser(id: String?, screenName: String?, accountType: String?): User { + try { + return showUser(id, screenName, accountType) + } catch (e: MicroBlogException) { + // Twitter specific error for private API calling through proxy + if (e.statusCode == 200) { + return showUserAlternative(id, screenName) + } + throw e + } + +} + +@Throws(MicroBlogException::class) +inline fun MicroBlog.lookupUsersMapPaginated(ids: IDs, transform: (User) -> R): PaginatedList { + val response = lookupUsers(ids.iDs) + val result = response.mapTo(PaginatedArrayList(response.size), transform) + result.previousPage = CursorPagination.valueOf(ids.previousCursor) + result.nextPage = CursorPagination.valueOf(ids.nextCursor) + return result +} + +@Throws(MicroBlogException::class) +private fun MicroBlog.showUser(id: String?, screenName: String?, accountType: String?): User { if (id != null) { if (AccountType.FANFOU == accountType) { return showFanfouUser(id) @@ -47,7 +69,7 @@ fun MicroBlog.showUser(id: String?, screenName: String?, accountType: String?): } @Throws(MicroBlogException::class) -fun MicroBlog.showUserAlternative(id: String?, screenName: String?): User { +private fun MicroBlog.showUserAlternative(id: String?, screenName: String?): User { val searchScreenName: String = screenName ?: run { if (id == null) throw IllegalArgumentException() return@run showFriendship(id).targetUserScreenName @@ -68,17 +90,3 @@ fun MicroBlog.showUserAlternative(id: String?, screenName: String?): User { throw MicroBlogException("Can't find user") } -@Throws(MicroBlogException::class) -fun MicroBlog.tryShowUser(id: String?, screenName: String?, accountType: String?): User { - try { - return showUser(id, screenName, accountType) - } catch (e: MicroBlogException) { - // Twitter specific error for private API calling through proxy - if (e.statusCode == 200) { - return showUserAlternative(id, screenName) - } - throw e - } - -} - diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/LinkHeaderListExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/LinkHeaderListExtensions.kt new file mode 100644 index 000000000..68f7474ec --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/mastodon/LinkHeaderListExtensions.kt @@ -0,0 +1,51 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.extension.model.api.mastodon + +import android.net.Uri +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList +import org.mariotaku.twidere.model.pagination.PaginatedArrayList +import org.mariotaku.twidere.model.pagination.PaginatedList +import org.mariotaku.twidere.model.pagination.Pagination +import org.mariotaku.twidere.model.pagination.SinceMaxPagination + +/** + * Created by mariotaku on 2017/4/21. + */ + +inline fun LinkHeaderList.mapToPaginated(transform: (T) -> R): PaginatedList { + val result = mapTo(PaginatedArrayList(size), transform) + result.previousPage = getLinkPagination("prev") + result.nextPage = getLinkPagination("next") + return result +} + +fun LinkHeaderList<*>.getLinkPagination(key: String): Pagination? { + val uri = getLinkPart(key)?.let(Uri::parse) ?: return null + val maxId = uri.getQueryParameter("max_id") + val sinceId = uri.getQueryParameter("since_id") + if (maxId != null || sinceId != null) { + return SinceMaxPagination().apply { + this.maxId = maxId + this.sinceId = sinceId + } + } + return null +} \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ResponseListExtensions.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ResponseListExtensions.kt new file mode 100644 index 000000000..6b9413a9a --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/extension/model/api/microblog/ResponseListExtensions.kt @@ -0,0 +1,48 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.extension.model.api.microblog + +import org.mariotaku.microblog.library.twitter.model.PageableResponseList +import org.mariotaku.microblog.library.twitter.model.ResponseList +import org.mariotaku.twidere.model.pagination.* + +/** + * Created by mariotaku on 2017/4/21. + */ + +inline fun ResponseList.mapToPaginated(current: Pagination?, transform: (T) -> R): PaginatedList { + val result = mapTo(PaginatedArrayList(size), transform) + if (current == null) { + // Assume we are on page 1 + result.previousPage = null + result.nextPage = PagePagination.valueOf(2) + } else if (current is PagePagination) { + result.previousPage = PagePagination.valueOf(current.page - 1) + result.nextPage = PagePagination.valueOf(current.page + 1) + } + return result +} + +inline fun PageableResponseList.mapToPaginated(transform: (T) -> R): PaginatedList { + val result = mapTo(PaginatedArrayList(size), transform) + result.previousPage = CursorPagination.valueOf(previousCursor) + result.nextPage = CursorPagination.valueOf(nextCursor) + return result +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt index cfc68ee6b..d33718f4a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsActivitiesFragment.kt @@ -517,7 +517,7 @@ abstract class AbsActivitiesFragment protected constructor() : } - override fun createItemDecoration(context: Context, recyclerView: RecyclerView, + override fun onCreateItemDecoration(context: Context, recyclerView: RecyclerView, layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { val itemDecoration = object : ExtendedDividerItemDecoration(context, (recyclerView.layoutManager as LinearLayoutManager).orientation) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListRecyclerViewFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListRecyclerViewFragment.kt index 9310191df..d825ab512 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListRecyclerViewFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentListRecyclerViewFragment.kt @@ -37,7 +37,7 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosi abstract class AbsContentListRecyclerViewFragment> : AbsContentRecyclerViewFragment() { - override fun createItemDecoration(context: Context, recyclerView: RecyclerView, + override fun onCreateItemDecoration(context: Context, recyclerView: RecyclerView, layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { return ExtendedDividerItemDecoration(context, layoutManager.orientation) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt index e8c73b6d1..c1f39784d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/AbsContentRecyclerViewFragment.kt @@ -219,7 +219,7 @@ abstract class AbsContentRecyclerViewFragment - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.fragment - -import android.content.Context -import android.os.Bundle -import android.support.v4.content.Loader -import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter -import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition -import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.model.ParcelableUser - -abstract class CursorUsersListFragment : ParcelableUsersFragment() { - - protected var nextCursor: Long = -1 - private set - protected var prevCursor: Long = -1 - private set - protected var nextPage = 1 - private set - - override fun onActivityCreated(savedInstanceState: Bundle?) { - if (savedInstanceState != null) { - nextCursor = savedInstanceState.getLong(EXTRA_NEXT_CURSOR, -1) - prevCursor = savedInstanceState.getLong(EXTRA_PREV_CURSOR, -1) - nextPage = savedInstanceState.getInt(EXTRA_NEXT_PAGE, -1) - } - super.onActivityCreated(savedInstanceState) - } - - override fun onLoaderReset(loader: Loader?>) { - super.onLoaderReset(loader) - } - - override fun onLoadFinished(loader: Loader?>, data: List?) { - super.onLoadFinished(loader, data) - val cursorLoader = loader as CursorSupportUsersLoader - nextCursor = cursorLoader.nextCursor - prevCursor = cursorLoader.prevCursor - nextPage = cursorLoader.nextPage - } - - override fun onLoadMoreContents(@IndicatorPosition position: Long) { - // Only supports load from end, skip START flag - if (position and ILoadMoreSupportAdapter.START != 0L) return - super.onLoadMoreContents(position) - if (position == 0L) return - val loaderArgs = Bundle(arguments) - loaderArgs.putBoolean(EXTRA_FROM_USER, true) - loaderArgs.putLong(EXTRA_NEXT_CURSOR, nextCursor) - loaderArgs.putInt(EXTRA_PAGE, nextPage) - loaderManager.restartLoader(0, loaderArgs, this) - } - - override fun onSaveInstanceState(outState: Bundle) { - super.onSaveInstanceState(outState) - outState.putLong(EXTRA_NEXT_CURSOR, nextCursor) - outState.putLong(EXTRA_PREV_CURSOR, prevCursor) - outState.putInt(EXTRA_NEXT_PAGE, nextPage) - } - - abstract override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader - -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt index 1e3cae9cb..7fb492641 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupFragment.kt @@ -13,6 +13,7 @@ import org.mariotaku.microblog.library.statusnet.model.Group import org.mariotaku.twidere.Constants.* import org.mariotaku.twidere.R import org.mariotaku.twidere.adapter.SupportTabsAdapter +import org.mariotaku.twidere.fragment.users.GroupMembersFragment import org.mariotaku.twidere.model.ParcelableGroup import org.mariotaku.twidere.model.SingleResponse import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupTimelineFragment.kt index 649f925e2..2d43ed567 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/GroupTimelineFragment.kt @@ -29,7 +29,7 @@ import android.view.MenuItem import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.activity.ComposeActivity -import org.mariotaku.twidere.loader.GroupTimelineLoader +import org.mariotaku.twidere.loader.statuses.GroupTimelineLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.util.Utils import java.util.* diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MediaStatusesSearchFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MediaStatusesSearchFragment.kt index 516f1d318..5404978d7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MediaStatusesSearchFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MediaStatusesSearchFragment.kt @@ -23,7 +23,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.loader.MediaStatusesSearchLoader +import org.mariotaku.twidere.loader.statuses.MediaStatusesSearchLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.util.Utils diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt index bde238bf3..4d88b7781 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableGroupsFragment.kt @@ -34,8 +34,10 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.loader.iface.IExtendedLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader import org.mariotaku.twidere.model.ParcelableGroup import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.util.IntentUtils import org.mariotaku.twidere.util.KeyboardShortcutsHandler import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback @@ -46,8 +48,12 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment?>, GroupAdapterListener, KeyboardShortcutCallback { private lateinit var navigationHelper: RecyclerViewNavigationHelper - val nextCursor: Long = 0 - val prevCursor: Long = 0 + + protected var nextPagination: Pagination? = null + protected var prevPagination: Pagination? = null + + protected val data: List? + get() = adapter.getData() override var refreshing: Boolean get() { @@ -82,6 +88,10 @@ abstract class ParcelableGroupsFragment : AbsContentListRecyclerViewFragment? - get() = adapter.getData() - override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { return navigationHelper.handleKeyboardShortcutSingle(handler, keyCode, event, metaState) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt index 2952374f6..1b8acd283 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableStatusesFragment.kt @@ -31,7 +31,7 @@ import org.mariotaku.twidere.adapter.ListParcelableStatusesAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.extension.getErrorMessage -import org.mariotaku.twidere.loader.AbsRequestStatusesLoader +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.model.BaseRefreshTaskParam import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.RefreshTaskParam diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt index 8891519c5..03df12bd7 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUserListsFragment.kt @@ -34,10 +34,11 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition import org.mariotaku.twidere.adapter.iface.IUserListsAdapter.UserListClickListener import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader import org.mariotaku.twidere.loader.iface.IExtendedLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.util.IntentUtils import org.mariotaku.twidere.util.KeyboardShortcutsHandler import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback @@ -47,11 +48,18 @@ import org.mariotaku.twidere.view.holder.UserListViewHolder abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment(), LoaderCallbacks>, UserListClickListener, KeyboardShortcutCallback { private lateinit var navigationHelper: RecyclerViewNavigationHelper - var nextCursor: Long = 0 + + var nextPagination: Pagination? = null private set - var prevCursor: Long = 0 + var prevPagination: Pagination? = null private set + protected val accountKey: UserKey? + get() = arguments.getParcelable(EXTRA_ACCOUNT_KEY) + + val data: List? + get() = adapter.getData() + override var refreshing: Boolean get() { if (context == null || isDetached) return false @@ -69,9 +77,6 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment< super.setupRecyclerView(context, recyclerView) } - protected val accountKey: UserKey? - get() = arguments.getParcelable(EXTRA_ACCOUNT_KEY) - protected fun hasMoreData(data: List?): Boolean { return data == null || !data.isEmpty() } @@ -85,9 +90,9 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment< if (loader is IExtendedLoader) { loader.fromUser = false } - if (loader is ICursorSupportLoader) { - nextCursor = loader.nextCursor - prevCursor = loader.nextCursor + if (loader is IPaginationLoader) { + nextPagination = loader.nextPagination + prevPagination = loader.nextPagination } showContent() refreshEnabled = true @@ -102,17 +107,10 @@ abstract class ParcelableUserListsFragment : AbsContentListRecyclerViewFragment< if (position == 0L) return val loaderArgs = Bundle(arguments) loaderArgs.putBoolean(EXTRA_FROM_USER, true) - loaderArgs.putLong(EXTRA_NEXT_CURSOR, nextCursor) + loaderArgs.putParcelable(EXTRA_PAGINATION, nextPagination) loaderManager.restartLoader(0, loaderArgs, this) } - protected fun removeUsers(vararg ids: Long) { - //TODO remove from adapter - } - - val data: List? - get() = adapter.getData() - override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { return navigationHelper.handleKeyboardShortcutSingle(handler, keyCode, event, metaState) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt index 26f45f03b..c8096e4e0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/ParcelableUsersFragment.kt @@ -39,13 +39,15 @@ import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter.UserClickListener import org.mariotaku.twidere.annotation.Referral -import org.mariotaku.twidere.constant.IntentConstants -import org.mariotaku.twidere.constant.IntentConstants.EXTRA_SIMPLE_LAYOUT +import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.loader.iface.IExtendedLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.util.IntentUtils import org.mariotaku.twidere.util.KeyboardShortcutsHandler import org.mariotaku.twidere.util.KeyboardShortcutsHandler.KeyboardShortcutCallback @@ -56,8 +58,32 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?>, UserClickListener, KeyboardShortcutCallback, IUsersAdapter.FriendshipClickListener { - private lateinit var navigationHelper: RecyclerViewNavigationHelper + override var refreshing: Boolean + get() { + if (context == null || isDetached) return false + return loaderManager.hasRunningLoadersSafe() + } + set(value) { + super.refreshing = value + } + protected open val userReferral: String? + @Referral + get() = null + + protected open val simpleLayout: Boolean + get() = arguments.getBoolean(EXTRA_SIMPLE_LAYOUT) + + protected open val showFollow: Boolean + get() = true + + protected var nextPagination: Pagination? = null + private set + + protected var prevPagination: Pagination? = null + private set + + private lateinit var navigationHelper: RecyclerViewNavigationHelper private val usersBusCallback: Any init { @@ -66,12 +92,16 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?> { + val fromUser = args.getBoolean(EXTRA_FROM_USER) + args.remove(EXTRA_FROM_USER) + return onCreateUsersLoader(activity, args, fromUser).apply { + if (this is AbsRequestUsersLoader) { + pagination = args.getParcelable(EXTRA_PAGINATION) + } + } } override fun onLoadFinished(loader: Loader?>, data: List?) { @@ -111,12 +140,41 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?>) { + if (loader is IExtendedLoader) { + loader.fromUser = false + } + } + + override fun onLoadMoreContents(@ILoadMoreSupportAdapter.IndicatorPosition position: Long) { + // Only supports load from end, skip START flag + if (position and ILoadMoreSupportAdapter.START != 0L) return + super.onLoadMoreContents(position) + if (position == 0L) return + val loaderArgs = Bundle(arguments) + loaderArgs.putBoolean(EXTRA_FROM_USER, true) + loaderArgs.putParcelable(EXTRA_PAGINATION, nextPagination) + loaderManager.restartLoader(0, loaderArgs, this) + } + + override fun onCreateAdapter(context: Context): ParcelableUsersAdapter { + val adapter = ParcelableUsersAdapter(context, Glide.with(this)) + adapter.simpleLayout = simpleLayout + adapter.showFollow = showFollow + adapter.friendshipClickListener = this + return adapter + } + override fun handleKeyboardShortcutSingle(handler: KeyboardShortcutsHandler, keyCode: Int, event: KeyEvent, metaState: Int): Boolean { return navigationHelper.handleKeyboardShortcutSingle(handler, keyCode, event, metaState) @@ -127,23 +185,12 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?> { - val fromUser = args.getBoolean(IntentConstants.EXTRA_FROM_USER) - args.remove(IntentConstants.EXTRA_FROM_USER) - return onCreateUsersLoader(activity, args, fromUser) - } - - override fun onLoaderReset(loader: Loader?>) { - if (loader is IExtendedLoader) { - loader.fromUser = false - } - } - override fun onUserClick(holder: UserViewHolder, position: Int) { val user = adapter.getUser(position) ?: return IntentUtils.openUserProfile(activity, user, preferences[newDocumentApiKey], userReferral) @@ -171,25 +218,12 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?> - - override fun createItemDecoration(context: Context, recyclerView: RecyclerView, + override fun onCreateItemDecoration(context: Context, recyclerView: RecyclerView, layoutManager: LinearLayoutManager): RecyclerView.ItemDecoration? { val itemDecoration = ExtendedDividerItemDecoration(context, (recyclerView.layoutManager as LinearLayoutManager).orientation) @@ -214,9 +248,8 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment?> protected open fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { return false @@ -230,6 +263,10 @@ abstract class ParcelableUsersFragment : AbsContentListRecyclerViewFragment - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.fragment - -import android.content.Context -import android.os.Bundle -import android.support.v4.content.Loader -import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter -import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition -import org.mariotaku.twidere.annotation.Referral -import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserSearchLoader -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey - -class SearchUsersFragment : ParcelableUsersFragment() { - - private var page = 1 - - override fun onActivityCreated(savedInstanceState: Bundle?) { - if (savedInstanceState != null) { - page = savedInstanceState.getInt(EXTRA_PAGE, 1) - } - super.onActivityCreated(savedInstanceState) - } - - override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): Loader?> { - val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val query = args.getString(EXTRA_QUERY) - val page = args.getInt(EXTRA_PAGE, 1) - return UserSearchLoader(context, accountKey, query, page, adapter.getData(), fromUser) - } - - override fun onLoadFinished(loader: Loader?>, data: List?) { - super.onLoadFinished(loader, data) - if (loader is UserSearchLoader) { - page = loader.page - } - } - - override fun onLoadMoreContents(@IndicatorPosition position: Long) { - // Only supports load from end, skip START flag - if (position and ILoadMoreSupportAdapter.START != 0L) return - super.onLoadMoreContents(position) - if (position == 0L) return - val loaderArgs = Bundle(arguments) - loaderArgs.putBoolean(EXTRA_FROM_USER, true) - loaderArgs.putInt(EXTRA_PAGE, page + 1) - loaderManager.restartLoader>(0, loaderArgs, this) - } - - override fun onSaveInstanceState(outState: Bundle) { - outState.putInt(EXTRA_PAGE, page) - super.onSaveInstanceState(outState) - } - - override fun onDestroyView() { - page = 1 - super.onDestroyView() - } - - override val userReferral: String? = Referral.SEARCH_RESULT -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt index a4b093e98..a45528b08 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFragment.kt @@ -95,7 +95,7 @@ import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.view.calculateSpaceItemHeight import org.mariotaku.twidere.fragment.AbsStatusesFragment.Companion.handleActionClick -import org.mariotaku.twidere.loader.ConversationLoader +import org.mariotaku.twidere.loader.statuses.ConversationLoader import org.mariotaku.twidere.loader.ParcelableStatusLoader import org.mariotaku.twidere.menu.FavoriteItemProvider import org.mariotaku.twidere.model.* diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusesSearchFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusesSearchFragment.kt index 04627e2a8..b1252c3f1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusesSearchFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusesSearchFragment.kt @@ -24,7 +24,7 @@ import android.graphics.Rect import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.loader.TweetSearchLoader +import org.mariotaku.twidere.loader.statuses.TweetSearchLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.util.Utils import java.io.UnsupportedEncodingException diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFavoritesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFavoritesFragment.kt index 7fdf9517d..2e18dc30b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFavoritesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFavoritesFragment.kt @@ -23,7 +23,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.loader.UserFavoritesLoader +import org.mariotaku.twidere.loader.statuses.UserFavoritesLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FavoriteTaskEvent diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserGroupsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserGroupsFragment.kt index 6520a5a2e..d8d95c5be 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserGroupsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserGroupsFragment.kt @@ -4,7 +4,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserGroupsLoader +import org.mariotaku.twidere.loader.group.UserGroupsLoader import org.mariotaku.twidere.model.ParcelableGroup import org.mariotaku.twidere.model.UserKey @@ -16,7 +16,7 @@ class UserGroupsFragment : ParcelableGroupsFragment() { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - return UserGroupsLoader(context, accountKey, userKey, screenName, data) + return UserGroupsLoader(context, accountKey, userKey, screenName, adapter.getData()) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt index cff89bd2b..fb8ffb6be 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListFragment.kt @@ -53,10 +53,13 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.AccountSelectorActivity import org.mariotaku.twidere.activity.UserSelectorActivity import org.mariotaku.twidere.adapter.SupportTabsAdapter +import org.mariotaku.twidere.app.TwidereApplication import org.mariotaku.twidere.constant.newDocumentApiKey import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.fragment.iface.IBaseFragment.SystemWindowsInsetsCallback import org.mariotaku.twidere.fragment.iface.SupportFragmentCallback +import org.mariotaku.twidere.fragment.users.UserListMembersFragment +import org.mariotaku.twidere.fragment.users.UserListSubscribersFragment import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.SingleResponse @@ -201,7 +204,7 @@ class UserListFragment : AbsToolbarTabPagesFragment(), OnClickListener, followItem.setTitle(R.string.action_subscribe) } val extensionsIntent = Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST) - extensionsIntent.setExtrasClassLoader(activity.classLoader) + extensionsIntent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) extensionsIntent.putExtra(EXTRA_USER_LIST, userList) MenuUtils.addIntentToMenu(activity, menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION) } else { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt index 26c6916bd..f3832761c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembershipsFragment.kt @@ -23,7 +23,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListMembershipsLoader +import org.mariotaku.twidere.loader.userlists.UserListMembershipsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey @@ -34,8 +34,9 @@ class UserListMembershipsFragment : ParcelableUserListsFragment() { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - val cursor = args.getLong(EXTRA_NEXT_CURSOR, -1) - return UserListMembershipsLoader(activity, accountKey, userKey, screenName, cursor, data) + return UserListMembershipsLoader(activity, accountKey, userKey, screenName, data).apply { + pagination = args.getParcelable(EXTRA_PAGINATION) + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt index 058086635..755e2c8bb 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscriptionsFragment.kt @@ -23,7 +23,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListSubscriptionsLoader +import org.mariotaku.twidere.loader.userlists.UserListSubscriptionsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey @@ -33,8 +33,9 @@ class UserListSubscriptionsFragment : ParcelableUserListsFragment() { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - val cursor = args.getLong(EXTRA_NEXT_CURSOR, -1) - return UserListSubscriptionsLoader(activity, accountKey, userKey, screenName, cursor, data) + return UserListSubscriptionsLoader(activity, accountKey, userKey, screenName, data).apply { + pagination = args.getParcelable(EXTRA_PAGINATION) + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListTimelineFragment.kt index 300769bd2..a3f3a0224 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListTimelineFragment.kt @@ -24,7 +24,7 @@ import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListTimelineLoader +import org.mariotaku.twidere.loader.statuses.UserListTimelineLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.util.Utils diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt index 6bd8c64ce..d663251d9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListsOwnershipsFragment.kt @@ -29,7 +29,7 @@ import com.squareup.otto.Subscribe import org.mariotaku.ktextension.setItemAvailability import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.UserListOwnershipsLoader +import org.mariotaku.twidere.loader.userlists.UserListOwnershipsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.UserListDestroyedEvent @@ -47,7 +47,9 @@ class UserListsOwnershipsFragment : ParcelableUserListsFragment() { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - return UserListOwnershipsLoader(activity, accountKey, userKey, screenName, nextCursor, data) + return UserListOwnershipsLoader(activity, accountKey, userKey, screenName, data).apply { + pagination = args.getParcelable(EXTRA_PAGINATION) + } } override fun onActivityCreated(savedInstanceState: Bundle?) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt index 2bf66cf8b..54882ec54 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMediaTimelineFragment.kt @@ -4,7 +4,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.MediaTimelineLoader +import org.mariotaku.twidere.loader.statuses.MediaTimelineLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMentionsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMentionsFragment.kt index 543b3e512..fcc129eb8 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMentionsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserMentionsFragment.kt @@ -23,7 +23,7 @@ import android.content.Context import android.os.Bundle import android.support.v4.content.Loader import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.loader.UserMentionsLoader +import org.mariotaku.twidere.loader.statuses.UserMentionsLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.util.Utils diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserTimelineFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserTimelineFragment.kt index 9230b6197..812847dcc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserTimelineFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserTimelineFragment.kt @@ -30,7 +30,7 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.constant.userTimelineFilterKey import org.mariotaku.twidere.extension.applyTheme -import org.mariotaku.twidere.loader.UserTimelineLoader +import org.mariotaku.twidere.loader.statuses.UserTimelineLoader import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.timeline.TimelineFilter diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersImportFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersImportFragment.kt index 60c3d4669..e06692adf 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersImportFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/BaseFiltersImportFragment.kt @@ -26,14 +26,14 @@ import org.mariotaku.twidere.activity.BaseActivity import org.mariotaku.twidere.adapter.SelectableUsersAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter.IndicatorPosition -import org.mariotaku.twidere.constant.IntentConstants -import org.mariotaku.twidere.constant.IntentConstants.EXTRA_COUNT +import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.extension.applyTheme import org.mariotaku.twidere.fragment.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader import org.mariotaku.twidere.loader.iface.IExtendedLoader +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.analyzer.PurchaseFinished +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.util.Analyzer import org.mariotaku.twidere.util.DataStoreUtils import org.mariotaku.twidere.util.premium.ExtraFeaturesService @@ -46,18 +46,16 @@ import java.lang.ref.WeakReference abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment(), LoaderManager.LoaderCallbacks?> { - protected var nextCursor: Long = -1 + protected var nextPagination: Pagination? = null private set - protected var prevCursor: Long = -1 - private set - protected var nextPage = 1 + protected var prevPagination: Pagination? = null private set override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) setHasOptionsMenu(true) val loaderArgs = Bundle(arguments) - loaderArgs.putBoolean(IntentConstants.EXTRA_FROM_USER, true) + loaderArgs.putBoolean(EXTRA_FROM_USER, true) loaderManager.initLoader(0, loaderArgs, this) } @@ -126,8 +124,8 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment?> { - val fromUser = args.getBoolean(IntentConstants.EXTRA_FROM_USER) - args.remove(IntentConstants.EXTRA_FROM_USER) + val fromUser = args.getBoolean(EXTRA_FROM_USER) + args.remove(EXTRA_FROM_USER) return onCreateUsersLoader(context, args, fromUser) } @@ -166,10 +164,9 @@ abstract class BaseFiltersImportFragment : AbsContentListRecyclerViewFragment(IntentConstants.EXTRA_ACCOUNT_KEY) - val loader = UserBlocksLoader(context, accountKey, adapter.data, fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return UserBlocksLoader(context, accountKey, adapter.data, fromUser).apply { + pagination = args.getParcelable(EXTRA_PAGINATION) + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersImportMutesFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersImportMutesFragment.kt index 628e1c65d..f9eeb301f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersImportMutesFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/filter/FiltersImportMutesFragment.kt @@ -2,21 +2,23 @@ package org.mariotaku.twidere.fragment.filter import android.content.Context import android.os.Bundle +import org.mariotaku.twidere.constant.IntentConstants import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.MutesUsersLoader +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.MutesUsersLoader import org.mariotaku.twidere.model.UserKey /** * Created by mariotaku on 2016/12/26. */ class FiltersImportMutesFragment : BaseFiltersImportFragment() { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): - CursorSupportUsersLoader { + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val loader = MutesUsersLoader(context, accountKey, adapter.data, fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return MutesUsersLoader(context, accountKey, adapter.data, fromUser).apply { + pagination = args.getParcelable(IntentConstants.EXTRA_PAGINATION) + } } + } \ No newline at end of file diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessagesConversationFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessagesConversationFragment.kt index d03cc5314..ea65cca8b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessagesConversationFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/message/MessagesConversationFragment.kt @@ -279,7 +279,7 @@ class MessagesConversationFragment : AbsContentListRecyclerViewFragment - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.GroupMembersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.GroupMembersLoader import org.mariotaku.twidere.model.UserKey -class GroupMembersFragment : CursorUsersListFragment() { +class GroupMembersFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, - args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val groupId = args.getString(EXTRA_GROUP_ID) val groupName = args.getString(EXTRA_GROUP_NAME) - val loader = GroupMembersLoader(context, accountKey, groupId, groupName, adapter.getData(), + return GroupMembersLoader(context, accountKey, groupId, groupName, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt similarity index 82% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt index 46ad312b9..a32e73e43 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/IncomingFriendshipsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/IncomingFriendshipsFragment.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.annotation.SuppressLint import android.content.Context @@ -26,23 +26,21 @@ import org.mariotaku.twidere.TwidereConstants.USER_TYPE_FANFOU_COM import org.mariotaku.twidere.adapter.ParcelableUsersAdapter import org.mariotaku.twidere.adapter.iface.IUsersAdapter import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.IncomingFriendshipsLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.IncomingFriendshipsLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.view.holder.UserViewHolder -class IncomingFriendshipsFragment : CursorUsersListFragment(), IUsersAdapter.RequestClickListener { +class IncomingFriendshipsFragment : ParcelableUsersFragment(), IUsersAdapter.RequestClickListener { override val showFollow: Boolean = false - override fun onCreateUsersLoader(context: Context, args: Bundle, - fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val loader = IncomingFriendshipsLoader(context, accountKey, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return IncomingFriendshipsLoader(context, accountKey, adapter.getData(), fromUser) } override fun onCreateAdapter(context: Context): ParcelableUsersAdapter { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/MutesUsersListFragment.kt similarity index 71% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/MutesUsersListFragment.kt index 4fce6efa7..8e7e309f9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/MutesUsersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/MutesUsersListFragment.kt @@ -1,41 +1,39 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.MutesUsersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.MutesUsersLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent -class MutesUsersListFragment : CursorUsersListFragment() { +class MutesUsersListFragment : ParcelableUsersFragment() { override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): - CursorSupportUsersLoader { + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val loader = MutesUsersLoader(context, accountKey, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return MutesUsersLoader(context, accountKey, adapter.getData(), fromUser) } override fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/SearchUsersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/SearchUsersFragment.kt new file mode 100644 index 000000000..9e3fcb9a9 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/SearchUsersFragment.kt @@ -0,0 +1,43 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.fragment.users + +import android.content.Context +import android.os.Bundle +import org.mariotaku.twidere.annotation.Referral +import org.mariotaku.twidere.constant.IntentConstants.* +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserSearchLoader +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.Pagination + +class SearchUsersFragment : ParcelableUsersFragment() { + + override val userReferral: String? = Referral.SEARCH_RESULT + + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { + val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) + val query = args.getString(EXTRA_QUERY) + val pagination = args.getParcelable(EXTRA_PAGINATION) + return UserSearchLoader(context, accountKey, query, adapter.getData(), fromUser) + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusFavoritersListFragment.kt similarity index 58% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusFavoritersListFragment.kt index 866c31b61..44181a233 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusFavoritersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusFavoritersListFragment.kt @@ -1,47 +1,48 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle +import org.mariotaku.twidere.adapter.ParcelableUsersAdapter import org.mariotaku.twidere.adapter.iface.ILoadMoreSupportAdapter import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUS_ID -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.StatusFavoritersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.StatusFavoritersLoader import org.mariotaku.twidere.model.UserKey -class StatusFavoritersListFragment : CursorUsersListFragment() { +class StatusFavoritersListFragment : ParcelableUsersFragment() { - override fun onActivityCreated(savedInstanceState: Bundle?) { - super.onActivityCreated(savedInstanceState) - adapter.loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE - } - - override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val statusId = args.getString(EXTRA_STATUS_ID) - val loader = StatusFavoritersLoader(context, accountKey, statusId, adapter.getData(), false) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return StatusFavoritersLoader(context, accountKey, statusId, adapter.getData(), false) + } + + override fun onCreateAdapter(context: Context): ParcelableUsersAdapter { + return super.onCreateAdapter(context).apply { + loadMoreSupportedPosition = ILoadMoreSupportAdapter.NONE + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusRetweetersListFragment.kt similarity index 60% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusRetweetersListFragment.kt index 7523254f8..7ff3cdd6a 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/StatusRetweetersListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/StatusRetweetersListFragment.kt @@ -1,44 +1,40 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUS_ID -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.StatusRetweetersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.StatusRetweetersLoader import org.mariotaku.twidere.model.UserKey -class StatusRetweetersListFragment : CursorUsersListFragment() { +class StatusRetweetersListFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, - args: Bundle, - fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val statusId = args.getString(EXTRA_STATUS_ID) - val loader = StatusRetweetersLoader(context, accountKey, statusId, adapter.getData(), - fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return StatusRetweetersLoader(context, accountKey, statusId, adapter.getData(), fromUser) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserBlocksListFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserBlocksListFragment.kt similarity index 66% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserBlocksListFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserBlocksListFragment.kt index 395421b68..2d264e330 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserBlocksListFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserBlocksListFragment.kt @@ -1,42 +1,39 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.EXTRA_ACCOUNT_KEY -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.UserBlocksLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserBlocksLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent -class UserBlocksListFragment : CursorUsersListFragment() { +class UserBlocksListFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, - args: Bundle, - fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val loader = UserBlocksLoader(context, accountKey, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return UserBlocksLoader(context, accountKey, adapter.getData(), fromUser) } override fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFollowersFragment.kt similarity index 71% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFollowersFragment.kt index 18c919674..a111b86e5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFollowersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFollowersFragment.kt @@ -1,44 +1,42 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.UserFollowersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserFollowersLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent -class UserFollowersFragment : CursorUsersListFragment() { +class UserFollowersFragment : ParcelableUsersFragment() { override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): - CursorSupportUsersLoader { + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - val loader = UserFollowersLoader(context, accountKey, userKey, screenName, - adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return UserFollowersLoader(context, accountKey, userKey, screenName, adapter.getData(), + fromUser) } override fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFriendsFragment.kt similarity index 67% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFriendsFragment.kt index 284c6662c..11ed229fc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserFriendsFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserFriendsFragment.kt @@ -1,44 +1,41 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.UserFriendsLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserFriendsLoader import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.FriendshipTaskEvent -class UserFriendsFragment : CursorUsersListFragment() { +class UserFriendsFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, - args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) - val loader = UserFriendsLoader(context, accountKey, userKey, screenName, adapter.getData(), - fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return UserFriendsLoader(context, accountKey, userKey, screenName, adapter.getData(), fromUser) } override fun shouldRemoveUser(position: Int, event: FriendshipTaskEvent): Boolean { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListMembersFragment.kt similarity index 87% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListMembersFragment.kt index 19e353c77..05c6e71a3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListMembersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListMembersFragment.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle @@ -31,8 +31,11 @@ import org.mariotaku.kpreferences.get import org.mariotaku.twidere.R import org.mariotaku.twidere.constant.IntentConstants.* import org.mariotaku.twidere.constant.nameFirstKey -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.UserListMembersLoader +import org.mariotaku.twidere.fragment.DeleteUserListMembersDialogFragment +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.fragment.UserListFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserListMembersLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey import org.mariotaku.twidere.model.event.UserListMembersChangedEvent @@ -41,21 +44,16 @@ import org.mariotaku.twidere.view.ExtendedRecyclerView import org.mariotaku.twidere.view.holder.UserViewHolder import java.util.* -class UserListMembersFragment : CursorUsersListFragment() { +class UserListMembersFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, - args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { - val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) - val listId = args.getString(EXTRA_LIST_ID) - val userKey = args.getParcelable(EXTRA_USER_KEY) - val screenName = args.getString(EXTRA_SCREEN_NAME) - val listName = args.getString(EXTRA_LIST_NAME) - val loader = UserListMembersLoader(context, accountKey, listId, userKey, screenName, - listName, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader - } + val userList: ParcelableUserList? + get() { + val parent = parentFragment + if (parent is UserListFragment) { + return parent.userList + } + return null + } override fun onActivityCreated(savedInstanceState: Bundle?) { super.onActivityCreated(savedInstanceState) @@ -77,6 +75,17 @@ class UserListMembersFragment : CursorUsersListFragment() { super.onStop() } + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { + val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) + val listId = args.getString(EXTRA_LIST_ID) + val userKey = args.getParcelable(EXTRA_USER_KEY) + val screenName = args.getString(EXTRA_SCREEN_NAME) + val listName = args.getString(EXTRA_LIST_NAME) + return UserListMembersLoader(context, accountKey, listId, userKey, screenName, listName, + adapter.getData(), fromUser) + } + override fun onUserLongClick(holder: UserViewHolder, position: Int): Boolean { return recyclerView.showContextMenuForChild(holder.itemView) } @@ -107,15 +116,6 @@ class UserListMembersFragment : CursorUsersListFragment() { return false } - val userList: ParcelableUserList? - get() { - val parent = parentFragment - if (parent is UserListFragment) { - return parent.userList - } - return null - } - @Subscribe fun onUserListMembersChanged(event: UserListMembersChangedEvent) { val userList = event.userList diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListSubscribersFragment.kt similarity index 65% rename from twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListSubscribersFragment.kt index b65e0e9eb..4089c2247 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/UserListSubscribersFragment.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/fragment/users/UserListSubscribersFragment.kt @@ -1,44 +1,43 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.fragment +package org.mariotaku.twidere.fragment.users import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.* -import org.mariotaku.twidere.loader.CursorSupportUsersLoader -import org.mariotaku.twidere.loader.UserListSubscribersLoader +import org.mariotaku.twidere.fragment.ParcelableUsersFragment +import org.mariotaku.twidere.loader.users.AbsRequestUsersLoader +import org.mariotaku.twidere.loader.users.UserListSubscribersLoader import org.mariotaku.twidere.model.UserKey -class UserListSubscribersFragment : CursorUsersListFragment() { +class UserListSubscribersFragment : ParcelableUsersFragment() { - override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): CursorSupportUsersLoader { + override fun onCreateUsersLoader(context: Context, args: Bundle, fromUser: Boolean): + AbsRequestUsersLoader { val listId = args.getString(EXTRA_LIST_ID) val accountKey = args.getParcelable(EXTRA_ACCOUNT_KEY) val userKey = args.getParcelable(EXTRA_USER_KEY) val screenName = args.getString(EXTRA_SCREEN_NAME) val listName = args.getString(EXTRA_LIST_NAME) - val loader = UserListSubscribersLoader(context, accountKey, - listId, userKey, screenName, listName, adapter.getData(), fromUser) - loader.cursor = nextCursor - loader.page = nextPage - return loader + return UserListSubscribersLoader(context, accountKey, listId, userKey, screenName, listName, + adapter.getData(), fromUser) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CacheUserSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CacheUserSearchLoader.kt index 03e9f73ac..9fda36819 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CacheUserSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CacheUserSearchLoader.kt @@ -3,11 +3,15 @@ package org.mariotaku.twidere.loader import android.annotation.SuppressLint import android.content.Context import org.mariotaku.library.objectcursor.ObjectCursor +import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.sqliteqb.library.Columns import org.mariotaku.sqliteqb.library.Expression +import org.mariotaku.twidere.loader.users.UserSearchLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedArrayList +import org.mariotaku.twidere.model.pagination.PaginatedList import org.mariotaku.twidere.provider.TwidereDataStore.CachedUsers import org.mariotaku.twidere.util.UserColorNameManager import org.mariotaku.twidere.util.Utils @@ -23,7 +27,7 @@ class CacheUserSearchLoader( private val fromNetwork: Boolean, private val fromCache: Boolean, fromUser: Boolean -) : UserSearchLoader(context, accountKey, query, 0, null, fromUser) { +) : UserSearchLoader(context, accountKey, query, null, fromUser) { @Inject internal lateinit var userColorNameManager: UserColorNameManager @@ -31,9 +35,9 @@ class CacheUserSearchLoader( GeneralComponent.get(context).inject(this) } - override fun getUsers(details: AccountDetails): List { - if (query.isEmpty() || !fromNetwork) return emptyList() - return super.getUsers(details) + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { + if (query.isEmpty() || !fromNetwork) return PaginatedArrayList() + return super.getUsers(details, paging) } override fun processUsersData(details: AccountDetails, list: MutableList) { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt deleted file mode 100644 index 58ab71571..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/CursorSupportUsersLoader.kt +++ /dev/null @@ -1,88 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.loader - -import android.content.Context -import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.twitter.model.CursorSupport -import org.mariotaku.microblog.library.twitter.model.Paging -import org.mariotaku.twidere.TwidereConstants.* -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey - -abstract class CursorSupportUsersLoader( - context: Context, - accountKey: UserKey?, - data: List?, - fromUser: Boolean -) : AbsRequestUsersLoader(context, accountKey, data, fromUser), ICursorSupportLoader { - - var page = -1 - override var cursor: Long = 0 - val count: Int - - override var nextCursor: Long = 0 - protected set - override var prevCursor: Long = 0 - protected set - var nextPage: Int = 0 - protected set - - init { - val preferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE) - val loadItemLimit = preferences.getInt(KEY_LOAD_ITEM_LIMIT, DEFAULT_LOAD_ITEM_LIMIT) - count = Math.min(100, loadItemLimit) - } - - protected fun setCursors(cursor: CursorSupport?) { - if (cursor == null) return - nextCursor = cursor.nextCursor - prevCursor = cursor.previousCursor - } - - protected fun incrementPage(users: List) { - if (users.isEmpty()) return - if (page == -1) { - page = 1 - } - nextPage = page + 1 - } - - - @Throws(MicroBlogException::class) - protected abstract fun getUsers(details: AccountDetails, paging: Paging): List - - @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails): List { - val paging = Paging() - paging.count(count) - if (cursor > 0) { - paging.setCursor(cursor) - } else if (page > 1) { - paging.setPage(page) - } - val users = getUsers(details, paging) - incrementPage(users) - return users - } - -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt deleted file mode 100644 index 0dcb56404..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFollowersLoader.kt +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.loader - -import android.content.Context -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.mastodon.Mastodon -import org.mariotaku.microblog.library.mastodon.model.Account -import org.mariotaku.microblog.library.twitter.model.CursorSupport -import org.mariotaku.microblog.library.twitter.model.Paging -import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable -import org.mariotaku.twidere.extension.model.api.toParcelable -import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey - -class UserFollowersLoader( - context: Context, - accountKey: UserKey?, - private val userKey: UserKey?, - private val screenName: String?, - data: List?, - fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { - when (details.type) { - AccountType.MASTODON -> return getMastodonUsers(details, paging).map { - it.toParcelable(details.key) - } - else -> return getMicroBlogUsers(details, paging).map { - it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) - } - } - } - - private fun getMastodonUsers(details: AccountDetails, paging: Paging): List { - val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - if (userKey == null) throw MicroBlogException("Only ID supported") - return mastodon.getFollowers(userKey.id, paging) - } - - private fun getMicroBlogUsers(details: AccountDetails, paging: Paging): List { - val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - when (details.type) { - AccountType.STATUSNET -> if (userKey != null) { - return microBlog.getStatusesFollowersList(userKey.id, paging).also { - setCursors(it as? CursorSupport) - } - } else if (screenName != null) { - return microBlog.getStatusesFollowersListByScreenName(screenName, paging).also { - setCursors(it as? CursorSupport) - } - } - AccountType.FANFOU -> if (userKey != null) { - return microBlog.getUsersFollowers(userKey.id, paging) - } else if (screenName != null) { - return microBlog.getUsersFollowers(screenName, paging) - } - else -> if (userKey != null) { - return microBlog.getFollowersList(userKey.id, paging).also { - setCursors(it as? CursorSupport) - } - } else if (screenName != null) { - return microBlog.getFollowersListByScreenName(screenName, paging).also { - setCursors(it as? CursorSupport) - } - } - } - throw MicroBlogException("user_id or screen_name required") - } - -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt deleted file mode 100644 index cccdd1d6e..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFriendsLoader.kt +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.loader - -import android.content.Context -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.mastodon.Mastodon -import org.mariotaku.microblog.library.mastodon.model.Account -import org.mariotaku.microblog.library.twitter.model.Paging -import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable -import org.mariotaku.twidere.extension.model.api.toParcelable -import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey - -class UserFriendsLoader( - context: Context, - accountKey: UserKey?, - private val userKey: UserKey?, - private val screenName: String?, - data: List?, - fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { - when (details.type) { - AccountType.MASTODON -> return getMastodonUsers(details, paging).map { - it.toParcelable(details.key) - } - else -> return getMicroBlogUsers(details, paging).map { - it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) - } - } - } - - private fun getMastodonUsers(details: AccountDetails, paging: Paging): List { - val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - if (userKey == null) throw MicroBlogException("Only ID supported") - return mastodon.getFollowing(userKey.id, paging) - } - - @Throws(MicroBlogException::class) - private fun getMicroBlogUsers(details: AccountDetails, paging: Paging): List { - val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - when (details.type) { - AccountType.STATUSNET -> if (userKey != null) { - return microBlog.getStatusesFriendsList(userKey.id, paging) - } else if (screenName != null) { - return microBlog.getStatusesFriendsListByScreenName(screenName, paging) - } - AccountType.FANFOU -> if (userKey != null) { - return microBlog.getUsersFriends(userKey.id, paging) - } else if (screenName != null) { - return microBlog.getUsersFriends(screenName, paging) - } - else -> if (userKey != null) { - return microBlog.getFriendsList(userKey.id, paging) - } else if (screenName != null) { - return microBlog.getFriendsListByScreenName(screenName, paging) - } - } - throw MicroBlogException("user_id or screen_name required") - } -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt deleted file mode 100644 index 5edbe763e..000000000 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscribersLoader.kt +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package org.mariotaku.twidere.loader - -import android.content.Context -import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.mastodon.model.Account -import org.mariotaku.microblog.library.twitter.model.Paging -import org.mariotaku.microblog.library.twitter.model.User -import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable -import org.mariotaku.twidere.extension.model.api.toParcelable -import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.model.AccountDetails -import org.mariotaku.twidere.model.ParcelableUser -import org.mariotaku.twidere.model.UserKey - -class UserListSubscribersLoader( - context: Context, - accountKey: UserKey?, - private val listId: String?, - private val userKey: UserKey?, - private val screenName: String?, - private val listName: String?, - data: List?, - fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { - - @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { - when (details.type) { - AccountType.MASTODON -> return getMastodonUsers(details, paging).map { - it.toParcelable(details.key) - } - else -> return getMicroBlogUsers(details, paging).map { - it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) - } - } - } - - private fun getMastodonUsers(details: AccountDetails, paging: Paging): List { - throw MicroBlogException("Not supported") - } - - @Throws(MicroBlogException::class) - private fun getMicroBlogUsers(details: AccountDetails, paging: Paging): List { - val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - if (listId != null) - return microBlog.getUserListSubscribers(listId, paging) - else if (userKey != null) - return microBlog.getUserListSubscribers(listName!!.replace(' ', '-'), userKey.id, paging) - else if (screenName != null) - return microBlog.getUserListSubscribersByScreenName(listName!!.replace(' ', '-'), screenName, paging) - throw MicroBlogException("list_id or list_name and user_id (or screen_name) required") - } - -} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseGroupsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/BaseGroupsLoader.kt similarity index 79% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseGroupsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/BaseGroupsLoader.kt index fda1a8297..2eebc7240 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseGroupsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/BaseGroupsLoader.kt @@ -1,35 +1,36 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.group import android.content.Context import android.support.v4.content.FixedAsyncTaskLoader import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.statusnet.model.Group -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.PageableResponseList import org.mariotaku.twidere.TwidereConstants.LOGTAG -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader import org.mariotaku.twidere.model.ParcelableGroup import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.CursorPagination +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.model.util.ParcelableGroupUtils import org.mariotaku.twidere.util.DebugLog import org.mariotaku.twidere.util.MicroBlogAPIFactory @@ -40,17 +41,19 @@ import java.util.* abstract class BaseGroupsLoader( context: Context, protected val accountKey: UserKey, - override val cursor: Long, data: List? -) : FixedAsyncTaskLoader>(context), ICursorSupportLoader { +) : FixedAsyncTaskLoader>(context), IPaginationLoader { + + override var pagination: Pagination? = null + + override final var nextPagination: Pagination? = null + private set + + override final var prevPagination: Pagination? = null + private set protected val data = NoDuplicatesArrayList() - override final var nextCursor: Long = 0 - private set - override final var prevCursor: Long = 0 - private set - init { if (data != null) { this.data.addAll(data) @@ -72,8 +75,8 @@ abstract class BaseGroupsLoader( if (listLoaded != null) { val listSize = listLoaded.size if (listLoaded is PageableResponseList<*>) { - nextCursor = (listLoaded as CursorSupport).nextCursor - prevCursor = listLoaded.previousCursor + nextPagination = CursorPagination.valueOf(listLoaded.nextCursor) + prevPagination = CursorPagination.valueOf(listLoaded.previousCursor) val dataSize = data.size for (i in 0..listSize - 1) { val group = listLoaded[i] diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserGroupsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/UserGroupsLoader.kt similarity index 88% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserGroupsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/UserGroupsLoader.kt index 3d80594be..13197b147 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserGroupsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/group/UserGroupsLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.group import android.content.Context @@ -34,7 +34,7 @@ class UserGroupsLoader( private val userKey: UserKey?, private val screenName: String?, data: List? -) : BaseGroupsLoader(context, accountKey, 0, data) { +) : BaseGroupsLoader(context, accountKey, data) { @Throws(MicroBlogException::class) override fun getGroups(twitter: MicroBlog): ResponseList { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/ICursorSupportLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/IPaginationLoader.kt similarity index 79% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/ICursorSupportLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/IPaginationLoader.kt index c5f1eb382..be5ca8942 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/ICursorSupportLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/iface/IPaginationLoader.kt @@ -19,13 +19,15 @@ package org.mariotaku.twidere.loader.iface +import org.mariotaku.twidere.model.pagination.Pagination + /** * Created by mariotaku on 15/4/29. */ -interface ICursorSupportLoader { - val cursor: Long get() = -1 +interface IPaginationLoader { + val pagination: Pagination? get() = null - val nextCursor: Long get() = -1 + val nextPagination: Pagination? get() = null - val prevCursor: Long get() = -1 + val prevPagination: Pagination? get() = null } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/AbsRequestStatusesLoader.kt similarity index 97% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/AbsRequestStatusesLoader.kt index bef96aade..929b44cc3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestStatusesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/AbsRequestStatusesLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.accounts.AccountManager import android.content.Context diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt similarity index 96% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt index c28a258ca..02fabe97e 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ConversationLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ConversationLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/DummyParcelableStatusesLoader.kt similarity index 82% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/DummyParcelableStatusesLoader.kt index 495817805..ddc4d729d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/DummyParcelableStatusesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/DummyParcelableStatusesLoader.kt @@ -1,25 +1,26 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context +import org.mariotaku.twidere.loader.statuses.ParcelableStatusesLoader import org.mariotaku.twidere.model.ListResponse import org.mariotaku.twidere.model.ParcelableStatus diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/GroupTimelineLoader.kt similarity index 92% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/GroupTimelineLoader.kt index 30f5f50b9..acaac9c0d 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/GroupTimelineLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -29,6 +29,7 @@ import org.mariotaku.microblog.library.twitter.model.Status import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/IntentExtrasStatusesLoader.kt similarity index 86% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/IntentExtrasStatusesLoader.kt index 0b144ad9e..a923eddda 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IntentExtrasStatusesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/IntentExtrasStatusesLoader.kt @@ -1,27 +1,28 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.os.Bundle import org.mariotaku.twidere.constant.IntentConstants.EXTRA_STATUSES +import org.mariotaku.twidere.loader.statuses.ParcelableStatusesLoader import org.mariotaku.twidere.model.ListResponse import org.mariotaku.twidere.model.ParcelableStatus import java.util.* diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaStatusesSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt similarity index 97% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaStatusesSearchLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt index 9bd575c13..7d1a50df9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaStatusesSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaStatusesSearchLoader.kt @@ -17,7 +17,7 @@ * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -69,10 +69,10 @@ open class MediaStatusesSearchLoader( override fun processPaging(details: AccountDetails, loadItemLimit: Int, paging: Paging) { if (details.type == AccountType.STATUSNET) { - paging.setRpp(loadItemLimit) + paging.rpp(loadItemLimit) val page = page if (page > 0) { - paging.setPage(page) + paging.page(page) } } else { super.processPaging(details, loadItemLimit, paging) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt similarity index 94% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt index 6bf131295..043fced39 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MediaTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/MediaTimelineLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -33,6 +33,8 @@ import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.isOfficial import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader +import org.mariotaku.twidere.loader.statuses.UserTimelineLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey @@ -134,7 +136,7 @@ class MediaTimelineLoader( private fun getMastodonStatuses(account: AccountDetails, paging: Paging): List { val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java) - val option = MastodonTimelineOption() + val option = org.mariotaku.microblog.library.mastodon.model.TimelineOption() option.onlyMedia(true) return UserTimelineLoader.getMastodonStatuses(mastodon, userKey, screenName, paging, option).map { it.toParcelable(account.key) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt new file mode 100644 index 000000000..c0cc28a03 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/NetworkPublicTimelineLoader.kt @@ -0,0 +1,67 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.statuses + +import android.content.Context +import android.database.sqlite.SQLiteDatabase +import android.support.annotation.WorkerThread +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.toParcelable +import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableStatus +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.util.InternalTwitterContentUtils + +class NetworkPublicTimelineLoader( + context: Context, + accountKey: UserKey?, + sinceId: String?, + maxId: String?, + adapterData: List?, + savedStatusesArgs: Array?, + tabPosition: Int, + fromUser: Boolean, + loadingMore: Boolean +) : AbsRequestStatusesLoader(context, accountKey, sinceId, maxId, -1, adapterData, savedStatusesArgs, + tabPosition, fromUser, loadingMore) { + + @Throws(MicroBlogException::class) + override fun getStatuses(account: AccountDetails, paging: Paging): List { + when (account.type) { + AccountType.STATUSNET -> { + val microBlog = account.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getNetworkPublicTimeline(paging).map { + it.toParcelable(account.key, account.type, profileImageSize = profileImageSize) + } + } + else -> throw MicroBlogException("STUB") + } + } + + @WorkerThread + override fun shouldFilterStatus(database: SQLiteDatabase, status: ParcelableStatus): Boolean { + return InternalTwitterContentUtils.isFiltered(database, status, true) + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ParcelableStatusesLoader.kt similarity index 92% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ParcelableStatusesLoader.kt index fb80163f8..94933b80c 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableStatusesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/ParcelableStatusesLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.support.v4.content.FixedAsyncTaskLoader diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/PublicTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/PublicTimelineLoader.kt similarity index 91% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/PublicTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/PublicTimelineLoader.kt index d27ee4f0c..e88e4deb2 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/PublicTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/PublicTimelineLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -28,6 +28,7 @@ import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt similarity index 95% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt index 77674081e..470a3a6b9 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/TweetSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/TweetSearchLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -117,10 +117,10 @@ open class TweetSearchLoader( override fun processPaging(details: AccountDetails, loadItemLimit: Int, paging: Paging) { if (details.type == AccountType.STATUSNET) { - paging.setRpp(loadItemLimit) + paging.rpp(loadItemLimit) val page = page if (page > 0) { - paging.setPage(page) + paging.page(page) } } else { super.processPaging(details, loadItemLimit, paging) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserFavoritesLoader.kt similarity index 95% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserFavoritesLoader.kt index 333035fd7..1011091a0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserFavoritesLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserFavoritesLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -75,7 +75,7 @@ class UserFavoritesLoader( AccountType.FANFOU -> { paging.setCount(loadItemLimit) if (page > 0) { - paging.setPage(page) + paging.page(page) } } else -> { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserListTimelineLoader.kt similarity index 93% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserListTimelineLoader.kt index 2b135253f..11b5d4d67 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserListTimelineLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -29,6 +29,7 @@ import org.mariotaku.microblog.library.twitter.model.ResponseList import org.mariotaku.microblog.library.twitter.model.Status import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserMentionsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt similarity index 88% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserMentionsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt index ff43e5cbc..6ea58dbbd 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserMentionsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserMentionsLoader.kt @@ -1,27 +1,28 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.extension.model.official +import org.mariotaku.twidere.loader.statuses.TweetSearchLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserTimelineLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserTimelineLoader.kt similarity index 94% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserTimelineLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserTimelineLoader.kt index f6491f2b2..b1eab1ce6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserTimelineLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/statuses/UserTimelineLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.statuses import android.content.Context import android.database.sqlite.SQLiteDatabase @@ -42,6 +42,7 @@ import org.mariotaku.twidere.annotation.AccountType import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableStatus import org.mariotaku.twidere.model.UserKey @@ -101,10 +102,10 @@ class UserTimelineLoader( status.quoted_source, null, status.quoted_user_key) } - private fun getMastodonStatuses(account: AccountDetails, paging: Paging): List { + private fun getMastodonStatuses(account: AccountDetails, paging: Paging): List { val mastodon = account.newMicroBlogInstance(context, Mastodon::class.java) val id = userKey?.id ?: throw MicroBlogException("Only ID are supported at this moment") - val option = MastodonTimelineOption() + val option = org.mariotaku.microblog.library.mastodon.model.TimelineOption() if (timelineFilter != null) { option.excludeReplies(!timelineFilter.isIncludeReplies) } @@ -194,7 +195,7 @@ class UserTimelineLoader( companion object { fun getMastodonStatuses(mastodon: Mastodon, userKey: UserKey?, screenName: String?, paging: Paging, - option: MastodonTimelineOption?): List { + option: org.mariotaku.microblog.library.mastodon.model.TimelineOption?): List { val id = userKey?.id ?: throw MicroBlogException("Only ID are supported at this moment") return mastodon.getStatuses(id, paging, option) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/BaseUserListsLoader.kt similarity index 82% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/BaseUserListsLoader.kt index 99243108c..50b845fe0 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/BaseUserListsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/BaseUserListsLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.userlists import android.accounts.AccountManager import android.content.Context @@ -27,7 +27,6 @@ import android.util.Log import org.mariotaku.kpreferences.get import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.PageableResponseList import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.UserList @@ -35,9 +34,11 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.LOGTAG import org.mariotaku.twidere.constant.loadItemLimitKey import org.mariotaku.twidere.extension.model.newMicroBlogInstance -import org.mariotaku.twidere.loader.iface.ICursorSupportLoader +import org.mariotaku.twidere.loader.iface.IPaginationLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.CursorPagination +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.model.util.ParcelableUserListUtils import org.mariotaku.twidere.util.collection.NoDuplicatesArrayList @@ -49,9 +50,8 @@ import javax.inject.Inject abstract class BaseUserListsLoader( context: Context, protected val accountKey: UserKey?, - override val cursor: Long, data: List? -) : FixedAsyncTaskLoader>(context), ICursorSupportLoader { +) : FixedAsyncTaskLoader>(context), IPaginationLoader { @Inject lateinit var preferences: SharedPreferences @@ -59,8 +59,12 @@ abstract class BaseUserListsLoader( private val profileImageSize = context.getString(R.string.profile_image_size) - override var nextCursor: Long = 0 - override var prevCursor: Long = 0 + override var pagination: Pagination? = null + + override var nextPagination: Pagination? = null + protected set + override var prevPagination: Pagination? = null + protected set init { GeneralComponent.get(context).inject(this) @@ -81,9 +85,7 @@ abstract class BaseUserListsLoader( val twitter = details.newMicroBlogInstance(context, MicroBlog::class.java) val paging = Paging() paging.count(preferences[loadItemLimitKey].coerceIn(0, 100)) - if (cursor > 0) { - paging.cursor(cursor) - } + pagination?.applyTo(paging) listLoaded = getUserLists(twitter, paging) } catch (e: MicroBlogException) { Log.w(LOGTAG, e) @@ -92,8 +94,8 @@ abstract class BaseUserListsLoader( if (listLoaded != null) { val listSize = listLoaded.size if (listLoaded is PageableResponseList<*>) { - nextCursor = (listLoaded as CursorSupport).nextCursor - prevCursor = listLoaded.previousCursor + nextPagination = CursorPagination.valueOf(listLoaded.nextCursor) + prevPagination = CursorPagination.valueOf(listLoaded.previousCursor) val dataSize = data.size for (i in 0..listSize - 1) { val list = listLoaded[i] diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListMembershipsLoader.kt similarity index 85% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListMembershipsLoader.kt index 6a2585d2c..92aba37b1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembershipsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListMembershipsLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.userlists import android.content.Context @@ -26,6 +26,7 @@ import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.PageableResponseList import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.UserList +import org.mariotaku.twidere.loader.userlists.BaseUserListsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey @@ -34,9 +35,8 @@ class UserListMembershipsLoader( accountKey: UserKey?, private val userKey: UserKey?, private val screenName: String?, - cursor: Long, data: List? -) : BaseUserListsLoader(context, accountKey, cursor, data) { +) : BaseUserListsLoader(context, accountKey, data) { @Throws(MicroBlogException::class) override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListOwnershipsLoader.kt similarity index 85% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListOwnershipsLoader.kt index 166662fb9..753ebb3c5 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListOwnershipsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListOwnershipsLoader.kt @@ -1,29 +1,30 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.userlists import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.UserList +import org.mariotaku.twidere.loader.userlists.BaseUserListsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey @@ -32,9 +33,8 @@ class UserListOwnershipsLoader( accountKey: UserKey?, private val userKey: UserKey?, private val screenName: String?, - cursor: Long, data: List? -) : BaseUserListsLoader(context, accountKey, cursor, data) { +) : BaseUserListsLoader(context, accountKey, data) { @Throws(MicroBlogException::class) override fun getUserLists(twitter: MicroBlog, paging: Paging): List { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListSubscriptionsLoader.kt similarity index 85% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListSubscriptionsLoader.kt index a9f1e39e2..67ad8e286 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListSubscriptionsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/userlists/UserListSubscriptionsLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.userlists import android.content.Context @@ -26,6 +26,7 @@ import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.twitter.model.PageableResponseList import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.UserList +import org.mariotaku.twidere.loader.userlists.BaseUserListsLoader import org.mariotaku.twidere.model.ParcelableUserList import org.mariotaku.twidere.model.UserKey @@ -34,9 +35,8 @@ class UserListSubscriptionsLoader( accountKey: UserKey?, private val userKey: UserKey?, private val screenName: String?, - cursor: Long, data: List? -) : BaseUserListsLoader(context, accountKey, cursor, data) { +) : BaseUserListsLoader(context, accountKey, data) { @Throws(MicroBlogException::class) override fun getUserLists(twitter: MicroBlog, paging: Paging): PageableResponseList { diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt similarity index 59% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt index a8a9706d7..1d546fa95 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/AbsRequestUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/AbsRequestUsersLoader.kt @@ -1,34 +1,42 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.accounts.AccountManager import android.content.Context +import org.mariotaku.kpreferences.get import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.R +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.constant.loadItemLimitKey +import org.mariotaku.twidere.loader.iface.IPaginationLoader import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ListResponse import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList +import org.mariotaku.twidere.model.pagination.Pagination import org.mariotaku.twidere.model.util.AccountUtils import org.mariotaku.twidere.util.DebugLog +import org.mariotaku.twidere.util.dagger.DependencyHolder import java.util.* abstract class AbsRequestUsersLoader( @@ -36,9 +44,20 @@ abstract class AbsRequestUsersLoader( val accountKey: UserKey?, data: List?, fromUser: Boolean -) : ParcelableUsersLoader(context, data, fromUser) { +) : ParcelableUsersLoader(context, data, fromUser), IPaginationLoader { protected val profileImageSize: String = context.getString(R.string.profile_image_size) + override var pagination: Pagination? = null + override var prevPagination: Pagination? = null + protected set + override var nextPagination: Pagination? = null + protected set + protected val loadItemLimit: Int + + init { + val preferences = DependencyHolder.get(context).preferences + loadItemLimit = preferences[loadItemLimitKey] + } override fun loadInBackground(): List { if (accountKey == null) { @@ -75,9 +94,32 @@ abstract class AbsRequestUsersLoader( } @Throws(MicroBlogException::class) - protected abstract fun getUsers(details: AccountDetails): List + final fun getUsers(details: AccountDetails): List { + val paging = Paging() + paging.applyItemLimit(details, loadItemLimit) + pagination?.applyTo(paging) + val users = getUsers(details, paging) + prevPagination = users.previousPage + nextPagination = users.nextPage + return users + } protected open fun processUsersData(details: AccountDetails, list: MutableList) { Collections.sort(data) } + + protected open fun Paging.applyItemLimit(details: AccountDetails, limit: Int) { + when (details.type) { + AccountType.MASTODON -> { + limit(limit) + } + else -> { + count(limit) + } + } + } + + @Throws(MicroBlogException::class) + protected abstract fun getUsers(details: AccountDetails, paging: Paging): + PaginatedList } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/GroupMembersLoader.kt similarity index 71% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/GroupMembersLoader.kt index 7844ffca1..38377a990 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/GroupMembersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/GroupMembersLoader.kt @@ -1,36 +1,37 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.ResponseList import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList class GroupMembersLoader( context: Context, @@ -39,24 +40,22 @@ class GroupMembersLoader( private val groupName: String?, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { - return getMicroBlogUsers(details, paging).also { - setCursors(it as? CursorSupport) - }.map { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { + return getMicroBlogUsers(details, paging).mapToPaginated(pagination) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } private fun getMicroBlogUsers(details: AccountDetails, paging: Paging): ResponseList { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - if (groupId != null) - return microBlog.getGroupMembers(groupId, paging) - else if (groupName != null) - return microBlog.getGroupMembersByName(groupName, paging) - throw MicroBlogException("list_id or list_name and user_id (or screen_name) required") + when { + groupId != null -> return microBlog.getGroupMembers(groupId, paging) + groupName != null -> return microBlog.getGroupMembersByName(groupName, paging) + else -> throw MicroBlogException("groupId or groupName required") + } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/IncomingFriendshipsLoader.kt similarity index 76% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/IncomingFriendshipsLoader.kt index d52932200..7893b9f02 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/IncomingFriendshipsLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/IncomingFriendshipsLoader.kt @@ -1,65 +1,66 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.api.lookupUsersMapPaginated +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList class IncomingFriendshipsLoader( context: Context, accountKey: UserKey?, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getFollowRequests(paging).map { + return mastodon.getFollowRequests(paging).mapToPaginated { it.toParcelable(details.key) } } AccountType.FANFOU -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.getFriendshipsRequests(paging).map { + return microBlog.getFriendshipsRequests(paging).mapToPaginated(pagination) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } else -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.lookupUsers(microBlog.getIncomingFriendships(paging).also { - setCursors(it as? CursorSupport) - }.iDs).map { + return microBlog.lookupUsersMapPaginated(microBlog.getIncomingFriendships(paging)) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/MutesUsersLoader.kt similarity index 72% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/MutesUsersLoader.kt index 80f04d086..383b1ddd6 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/MutesUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/MutesUsersLoader.kt @@ -1,37 +1,39 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList import org.mariotaku.twidere.util.DataStoreUtils class MutesUsersLoader( @@ -39,36 +41,29 @@ class MutesUsersLoader( accountKey: UserKey?, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { - private var filteredUsers: Array? = null + private val filteredUsers by lazy { DataStoreUtils.getFilteredUserKeys(context) } @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getMutes(paging).map { + return mastodon.getMutes(paging).mapToPaginated { it.toParcelable(details.key) } } else -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.getMutesUsersList(paging).also { - setCursors(it as? CursorSupport) - }.map { + return microBlog.getMutesUsersList(paging).mapToPaginated { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } } } - override fun onLoadInBackground(): List { - filteredUsers = DataStoreUtils.getFilteredUserKeys(context) - return super.onLoadInBackground() - } - override fun processUser(details: AccountDetails, user: ParcelableUser) { - user.is_filtered = filteredUsers?.contains(user.key) ?: false + user.is_filtered = filteredUsers.contains(user.key) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt similarity index 90% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt index 603f5180a..ca4c168ac 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/ParcelableUsersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/ParcelableUsersLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import android.support.v4.content.FixedAsyncTaskLoader diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt similarity index 81% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt index 76b4b128f..0d7f8b390 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusFavoritersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusFavoritersLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.attoparser.config.ParseConfiguration @@ -27,8 +27,13 @@ import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon import org.mariotaku.microblog.library.twitter.TwitterWeb +import org.mariotaku.microblog.library.twitter.model.IDs +import org.mariotaku.microblog.library.twitter.model.IDsAccessor import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.exception.APINotSupportedException +import org.mariotaku.twidere.extension.api.lookupUsersMapPaginated +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.isOfficial @@ -36,6 +41,7 @@ import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList import java.text.ParseException class StatusFavoritersLoader( @@ -44,32 +50,32 @@ class StatusFavoritersLoader( private val statusId: String, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getStatusFavouritedBy(statusId).map { + return mastodon.getStatusFavouritedBy(statusId).mapToPaginated { it.toParcelable(details.key) } } AccountType.TWITTER -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) val ids = if (details.isOfficial(context)) { - microBlog.getStatusActivitySummary(statusId).favoriters.iDs + microBlog.getStatusActivitySummary(statusId).favoriters } else { val web = details.newMicroBlogInstance(context, TwitterWeb::class.java) val htmlUsers = web.getFavoritedPopup(statusId).htmlUsers - parseUserIds(htmlUsers) + IDsAccessor.setIds(IDs(), parseUserIds(htmlUsers)) } - return microBlog.lookupUsers(ids).map { + return microBlog.lookupUsersMapPaginated(ids) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } else -> { - throw MicroBlogException("Not supported") + throw APINotSupportedException(details.type) } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusRetweetersLoader.kt similarity index 64% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusRetweetersLoader.kt index bc2377987..dfec86639 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/StatusRetweetersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/StatusRetweetersLoader.kt @@ -1,23 +1,23 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog @@ -25,12 +25,15 @@ import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.exception.APINotSupportedException import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedArrayList +import org.mariotaku.twidere.model.pagination.PaginatedList class StatusRetweetersLoader( context: Context, @@ -38,26 +41,32 @@ class StatusRetweetersLoader( private val statusId: String, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getStatusFavouritedBy(statusId).map { - it.toParcelable(details.key) + val response = mastodon.getStatusFavouritedBy(statusId) + return PaginatedArrayList(response.size).apply { + response.mapTo(this) { account -> + account.toParcelable(details.key) + } } } AccountType.TWITTER -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) val ids = microBlog.getRetweetersIDs(statusId, paging).iDs - return microBlog.lookupUsers(ids).map { - it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + val response = microBlog.lookupUsers(ids) + return PaginatedArrayList(response.size).apply { + response.mapTo(this) { user -> + user.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } } } else -> { - throw MicroBlogException("Not supported") + throw APINotSupportedException(details.type) } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserBlocksLoader.kt similarity index 75% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserBlocksLoader.kt index 5f53812d3..08cf1d783 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserBlocksLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserBlocksLoader.kt @@ -1,64 +1,68 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon -import org.mariotaku.microblog.library.twitter.model.CursorSupport import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList import org.mariotaku.twidere.util.DataStoreUtils -class UserBlocksLoader(context: Context, accountKey: UserKey?, data: List?, - fromUser: Boolean) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +class UserBlocksLoader( + context: Context, + accountKey: UserKey?, + data: List?, + fromUser: Boolean +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { private var filteredUsers: Array? = null @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.getBlocks(paging).map { + return mastodon.getBlocks(paging).mapToPaginated { it.toParcelable(details.key) } } AccountType.FANFOU -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.getFanfouBlocking(paging).map { + return microBlog.getFanfouBlocking(paging).mapToPaginated(pagination) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } else -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.getBlocksList(paging).also { - setCursors(it as? CursorSupport) - }.map { + return microBlog.getBlocksList(paging).mapToPaginated { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFollowersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFollowersLoader.kt new file mode 100644 index 000000000..6de135261 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFollowersLoader.kt @@ -0,0 +1,103 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.users + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.mastodon.Mastodon +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated +import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated +import org.mariotaku.twidere.extension.model.api.toParcelable +import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList + +class UserFollowersLoader( + context: Context, + accountKey: UserKey?, + userKey: UserKey?, + screenName: String?, + data: List?, + fromUser: Boolean +) : UserRelatedUsersLoader(context, accountKey, userKey, screenName, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getUsersByKey(details: AccountDetails, paging: Paging, userKey: UserKey): PaginatedList { + when (details.type) { + AccountType.MASTODON -> { + val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) + return mastodon.getFollowers(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key) + } + } + AccountType.STATUSNET -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getStatusesFollowersList(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + AccountType.FANFOU -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getUsersFollowers(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + else -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getFollowersList(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + } + } + + @Throws(MicroBlogException::class) + override fun getUsersByScreenName(details: AccountDetails, paging: Paging, screenName: String): PaginatedList { + when (details.type) { + AccountType.MASTODON -> { + throw MicroBlogException("Only ID supported") + } + AccountType.STATUSNET -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getStatusesFollowersListByScreenName(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + AccountType.FANFOU -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getUsersFollowers(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + else -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getFollowersListByScreenName(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + } + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFriendsLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFriendsLoader.kt new file mode 100644 index 000000000..19d43e946 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserFriendsLoader.kt @@ -0,0 +1,104 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.users + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.mastodon.Mastodon +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated +import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated +import org.mariotaku.twidere.extension.model.api.toParcelable +import org.mariotaku.twidere.extension.model.newMicroBlogInstance +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList + +class UserFriendsLoader( + context: Context, + accountKey: UserKey?, + userKey: UserKey?, + screenName: String?, + data: List?, + fromUser: Boolean +) : UserRelatedUsersLoader(context, accountKey, userKey, screenName, data, fromUser) { + + @Throws(MicroBlogException::class) + override fun getUsersByKey(details: AccountDetails, paging: Paging, userKey: UserKey): PaginatedList { + when (details.type) { + AccountType.MASTODON -> { + val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) + return mastodon.getFollowing(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key) + } + } + AccountType.STATUSNET -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getStatusesFriendsList(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + AccountType.FANFOU -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getUsersFriends(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + else -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getFriendsList(userKey.id, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + } + } + + @Throws(MicroBlogException::class) + override fun getUsersByScreenName(details: AccountDetails, paging: Paging, screenName: String): PaginatedList { + when (details.type) { + AccountType.MASTODON -> { + throw MicroBlogException("Only ID supported") + } + AccountType.STATUSNET -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getStatusesFriendsListByScreenName(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + AccountType.FANFOU -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getUsersFriends(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + else -> { + val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) + return microBlog.getFriendsListByScreenName(screenName, paging).mapToPaginated { + it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) + } + } + } + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListMembersLoader.kt new file mode 100644 index 000000000..4e2a216c5 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListMembersLoader.kt @@ -0,0 +1,53 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.users + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.twitter.model.PageableResponseList +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserListMembersLoader( + context: Context, + accountKey: UserKey?, + listId: String?, + userKey: UserKey?, + screenName: String?, + listName: String?, + data: List?, + fromUser: Boolean +) : UserListRelatedUsersLoader(context, accountKey, listId, userKey, screenName, listName, data, fromUser) { + + override fun getByListId(microBlog: MicroBlog, listId: String, paging: Paging): PageableResponseList { + return microBlog.getUserListMembers(listId, paging) + } + + override fun getByUserKey(microBlog: MicroBlog, listName: String, userKey: UserKey, paging: Paging): PageableResponseList { + return microBlog.getUserListMembers(listName, userKey.id, paging) + } + + override fun getByScreenName(microBlog: MicroBlog, listName: String, screenName: String, paging: Paging): PageableResponseList { + return microBlog.getUserListMembersByScreenName(listName, screenName, paging) + } + +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListRelatedUsersLoader.kt similarity index 52% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListRelatedUsersLoader.kt index a588cd072..a03846a46 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserListMembersLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListRelatedUsersLoader.kt @@ -1,39 +1,41 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog import org.mariotaku.microblog.library.MicroBlogException -import org.mariotaku.microblog.library.mastodon.model.Account +import org.mariotaku.microblog.library.twitter.model.PageableResponseList import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.microblog.library.twitter.model.User import org.mariotaku.twidere.annotation.AccountType -import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.exception.APINotSupportedException +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList -class UserListMembersLoader( +abstract class UserListRelatedUsersLoader( context: Context, accountKey: UserKey?, private val listId: String?, @@ -42,34 +44,38 @@ class UserListMembersLoader( private val listName: String?, data: List?, fromUser: Boolean -) : CursorSupportUsersLoader(context, accountKey, data, fromUser) { +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails, paging: Paging): List { + override final fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { - AccountType.MASTODON -> return getMastodonUsers(details, paging).map { - it.toParcelable(details.key) - } - else -> return getMicroBlogUsers(details, paging).map { + AccountType.TWITTER -> return getTwitterUsers(details, paging).mapToPaginated { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } + else -> { + throw APINotSupportedException(details.type) + } } } - private fun getMastodonUsers(details: AccountDetails, paging: Paging): List { - throw MicroBlogException("Not supported") - } + protected abstract fun getByListId(microBlog: MicroBlog, listId: String, paging: Paging): PageableResponseList + + protected abstract fun getByUserKey(microBlog: MicroBlog, listName: String, userKey: UserKey, paging: Paging): PageableResponseList + + protected abstract fun getByScreenName(microBlog: MicroBlog, listName: String, screenName: String, paging: Paging): PageableResponseList @Throws(MicroBlogException::class) - private fun getMicroBlogUsers(details: AccountDetails, paging: Paging): List { + private fun getTwitterUsers(details: AccountDetails, paging: Paging): PageableResponseList { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - if (listId != null) { - return microBlog.getUserListMembers(listId, paging) - } else if (listName != null) { - if (userKey != null) { - return microBlog.getUserListMembers(listName.replace(' ', '-'), userKey.id, paging) - } else if (screenName != null) { - return microBlog.getUserListMembersByScreenName(listName.replace(' ', '-'), screenName, paging) + when { + listId != null -> { + return getByListId(microBlog, listId, paging) + } + listName != null && userKey != null -> { + return getByUserKey(microBlog, listName.replace(' ', '-'), userKey, paging) + } + listName != null && screenName != null -> { + return getByScreenName(microBlog, listName.replace(' ', '-'), screenName, paging) } } throw MicroBlogException("list_id or list_name and user_id (or screen_name) required") diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListSubscribersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListSubscribersLoader.kt new file mode 100644 index 000000000..b3477b6fc --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserListSubscribersLoader.kt @@ -0,0 +1,52 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.users + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlog +import org.mariotaku.microblog.library.twitter.model.PageableResponseList +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.microblog.library.twitter.model.User +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey + +class UserListSubscribersLoader( + context: Context, + accountKey: UserKey?, + listId: String?, + userKey: UserKey?, + screenName: String?, + listName: String?, + data: List?, + fromUser: Boolean +) : UserListRelatedUsersLoader(context, accountKey, listId, userKey, screenName, listName, data, fromUser) { + + override fun getByListId(microBlog: MicroBlog, listId: String, paging: Paging): PageableResponseList { + return microBlog.getUserListSubscribers(listId, paging) + } + + override fun getByUserKey(microBlog: MicroBlog, listName: String, userKey: UserKey, paging: Paging): PageableResponseList { + return microBlog.getUserListSubscribers(listName, userKey.id, paging) + } + + override fun getByScreenName(microBlog: MicroBlog, listName: String, screenName: String, paging: Paging): PageableResponseList { + return microBlog.getUserListSubscribersByScreenName(listName, screenName, paging) + } +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserRelatedUsersLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserRelatedUsersLoader.kt new file mode 100644 index 000000000..99e785bd0 --- /dev/null +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserRelatedUsersLoader.kt @@ -0,0 +1,53 @@ +/* + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.mariotaku.twidere.loader.users + +import android.content.Context +import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.twitter.model.Paging +import org.mariotaku.twidere.model.AccountDetails +import org.mariotaku.twidere.model.ParcelableUser +import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList + +abstract class UserRelatedUsersLoader( + context: Context, + accountKey: UserKey?, + private val userKey: UserKey?, + private val screenName: String?, + data: List?, + fromUser: Boolean +) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { + + @Throws(MicroBlogException::class) + override final fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { + return when { + userKey != null -> getUsersByKey(details, paging, userKey) + screenName != null -> getUsersByScreenName(details, paging, screenName) + else -> throw MicroBlogException("user_id or screen_name required") + } + } + + @Throws(MicroBlogException::class) + protected abstract fun getUsersByKey(details: AccountDetails, paging: Paging, userKey: UserKey): PaginatedList + + @Throws(MicroBlogException::class) + protected abstract fun getUsersByScreenName(details: AccountDetails, paging: Paging, screenName: String): PaginatedList +} diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserSearchLoader.kt similarity index 79% rename from twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt rename to twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserSearchLoader.kt index 859550ad3..9c2c78eb3 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/loader/UserSearchLoader.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/loader/users/UserSearchLoader.kt @@ -1,66 +1,64 @@ /* - * Twidere - Twitter client for Android - * - * Copyright (C) 2012-2014 Mariotaku Lee - * + * Twidere - Twitter client for Android + * + * Copyright (C) 2012-2017 Mariotaku Lee + * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. - * + * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * + * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package org.mariotaku.twidere.loader +package org.mariotaku.twidere.loader.users import android.content.Context import org.mariotaku.microblog.library.MicroBlog -import org.mariotaku.microblog.library.MicroBlogException import org.mariotaku.microblog.library.mastodon.Mastodon import org.mariotaku.microblog.library.twitter.model.Paging import org.mariotaku.twidere.annotation.AccountType +import org.mariotaku.twidere.extension.model.api.mastodon.mapToPaginated import org.mariotaku.twidere.extension.model.api.mastodon.toParcelable +import org.mariotaku.twidere.extension.model.api.microblog.mapToPaginated import org.mariotaku.twidere.extension.model.api.toParcelable import org.mariotaku.twidere.extension.model.newMicroBlogInstance import org.mariotaku.twidere.model.AccountDetails import org.mariotaku.twidere.model.ParcelableUser import org.mariotaku.twidere.model.UserKey +import org.mariotaku.twidere.model.pagination.PaginatedList open class UserSearchLoader( context: Context, accountKey: UserKey?, val query: String, - val page: Int, data: List?, fromUser: Boolean ) : AbsRequestUsersLoader(context, accountKey, data, fromUser) { - @Throws(MicroBlogException::class) - override fun getUsers(details: AccountDetails): List { - val paging = Paging() - paging.page(page) + override fun getUsers(details: AccountDetails, paging: Paging): PaginatedList { when (details.type) { AccountType.MASTODON -> { val mastodon = details.newMicroBlogInstance(context, Mastodon::class.java) - return mastodon.searchAccounts(query, paging).map { + return mastodon.searchAccounts(query, paging).mapToPaginated { it.toParcelable(details.key) } } AccountType.FANFOU -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.searchFanfouUsers(query, paging).map { + return microBlog.searchFanfouUsers(query, paging).mapToPaginated(pagination) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } else -> { val microBlog = details.newMicroBlogInstance(context, MicroBlog::class.java) - return microBlog.searchUsers(query, paging).map { + return microBlog.searchUsers(query, paging).mapToPaginated(pagination) { it.toParcelable(details.key, details.type, profileImageSize = profileImageSize) } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt index 96f9fec45..8cb210f1f 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/IntentUtils.kt @@ -22,6 +22,7 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.TwidereConstants.* import org.mariotaku.twidere.activity.MediaViewerActivity import org.mariotaku.twidere.annotation.Referral +import org.mariotaku.twidere.app.TwidereApplication import org.mariotaku.twidere.constant.chromeCustomTabKey import org.mariotaku.twidere.fragment.SensitiveContentWarningDialogFragment import org.mariotaku.twidere.model.* @@ -71,7 +72,7 @@ object IntentUtils { fun userProfile(user: ParcelableUser, @Referral referral: String? = null): Intent { val uri = LinkCreator.getTwidereUserLink(user.account_key, user.key, user.screen_name) val intent = Intent(Intent.ACTION_VIEW, uri) - intent.setExtrasClassLoader(ParcelableUser::class.java.classLoader) + intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) intent.putExtra(EXTRA_USER, user) if (user.extras != null) { intent.putExtra(EXTRA_PROFILE_URL, user.extras.statusnet_profile_url) @@ -373,16 +374,14 @@ object IntentUtils { } fun openStatus(context: Context, status: ParcelableStatus, activityOptions: Bundle? = null) { - val extras = Bundle() - extras.putParcelable(EXTRA_STATUS, status) val builder = Uri.Builder() builder.scheme(SCHEME_TWIDERE) builder.authority(AUTHORITY_STATUS) builder.appendQueryParameter(QUERY_PARAM_ACCOUNT_KEY, status.account_key.toString()) builder.appendQueryParameter(QUERY_PARAM_STATUS_ID, status.id) val intent = Intent(Intent.ACTION_VIEW, builder.build()) - intent.setExtrasClassLoader(context.classLoader) - intent.putExtras(extras) + intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) + intent.putExtra(EXTRA_STATUS, status) ActivityCompat.startActivity(context, intent, activityOptions) } @@ -494,14 +493,12 @@ object IntentUtils { } fun openUserListDetails(context: Context, userList: ParcelableUserList) { - context.startActivity(userListDetails(context, userList)) + context.startActivity(userListDetails(userList)) } - fun userListDetails(context: Context, userList: ParcelableUserList): Intent { + fun userListDetails(userList: ParcelableUserList): Intent { val userKey = userList.user_key val listId = userList.id - val extras = Bundle() - extras.putParcelable(EXTRA_USER_LIST, userList) val builder = Uri.Builder() builder.scheme(SCHEME_TWIDERE) builder.authority(AUTHORITY_USER_LIST) @@ -509,14 +506,12 @@ object IntentUtils { builder.appendQueryParameter(QUERY_PARAM_USER_KEY, userKey.toString()) builder.appendQueryParameter(QUERY_PARAM_LIST_ID, listId) val intent = Intent(Intent.ACTION_VIEW, builder.build()) - intent.setExtrasClassLoader(context.classLoader) - intent.putExtras(extras) + intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) + intent.putExtra(EXTRA_USER_LIST, userList) return intent } fun openGroupDetails(context: Context, group: ParcelableGroup) { - val extras = Bundle() - extras.putParcelable(EXTRA_GROUP, group) val builder = Uri.Builder() builder.scheme(SCHEME_TWIDERE) builder.authority(AUTHORITY_GROUP) @@ -524,8 +519,8 @@ object IntentUtils { builder.appendQueryParameter(QUERY_PARAM_GROUP_ID, group.id) builder.appendQueryParameter(QUERY_PARAM_GROUP_NAME, group.nickname) val intent = Intent(Intent.ACTION_VIEW, builder.build()) - intent.setExtrasClassLoader(context.classLoader) - intent.putExtras(extras) + intent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) + intent.putExtra(EXTRA_GROUP, group) context.startActivity(intent) } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt index 6b6d76b4f..61dd5d13b 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/MenuUtils.kt @@ -48,6 +48,7 @@ import org.mariotaku.twidere.R import org.mariotaku.twidere.activity.AccountSelectorActivity import org.mariotaku.twidere.activity.BaseActivity import org.mariotaku.twidere.activity.ColorPickerDialogActivity +import org.mariotaku.twidere.app.TwidereApplication import org.mariotaku.twidere.constant.favoriteConfirmationKey import org.mariotaku.twidere.constant.iWantMyStarsBackKey import org.mariotaku.twidere.constant.nameFirstKey @@ -359,7 +360,7 @@ object MenuUtils { val density = res.displayMetrics.density val padding = Math.round(density * 4) val queryIntent = Intent(action) - queryIntent.setExtrasClassLoader(context.classLoader) + queryIntent.setExtrasClassLoader(TwidereApplication::class.java.classLoader) val activities = pm.queryIntentActivities(queryIntent, PackageManager.GET_META_DATA) val parcelableJson = try { JsonSerializer.serialize(obj) diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/api/TwitterConverterFactory.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/api/TwitterConverterFactory.kt index 2b60e47dc..9358b2bb1 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/api/TwitterConverterFactory.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/api/TwitterConverterFactory.kt @@ -25,6 +25,7 @@ import com.bluelinelabs.logansquare.ParameterizedType import org.mariotaku.commons.logansquare.LoganSquareMapperFinder import org.mariotaku.microblog.library.MicroBlogException +import org.mariotaku.microblog.library.mastodon.model.LinkHeaderList import org.mariotaku.microblog.library.twitter.model.ResponseCode import org.mariotaku.microblog.library.twitter.model.TwitterResponse import org.mariotaku.microblog.library.twitter.util.OAuthTokenResponseConverter @@ -45,7 +46,7 @@ import java.lang.reflect.Type object TwitterConverterFactory : LoganSquareConverterFactory() { private val responseConverters = SimpleArrayMap>() - private val sBodyConverters = SimpleArrayMap>() + private val bodyConverters = SimpleArrayMap>() init { responseConverters.put(ResponseCode::class.java, ResponseCode.ResponseConverter()) @@ -71,7 +72,7 @@ object TwitterConverterFactory : LoganSquareConverterFactory @Throws(RestConverter.ConvertException::class) override fun forRequest(type: Type): RestConverter<*, Body, MicroBlogException> { - val converter = sBodyConverters.get(type) + val converter = bodyConverters.get(type) if (converter != null) { return converter } @@ -82,8 +83,9 @@ object TwitterConverterFactory : LoganSquareConverterFactory } override fun processParsedObject(obj: Any, httpResponse: HttpResponse) { - if (obj is TwitterResponse) { - obj.processResponseHeader(httpResponse) + when (obj) { + is TwitterResponse -> obj.processResponseHeader(httpResponse) + is LinkHeaderList<*> -> obj.processResponseHeader(httpResponse) } } } diff --git a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt index 222988bdb..cf2e0e5bc 100644 --- a/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt +++ b/twidere/src/main/kotlin/org/mariotaku/twidere/util/dagger/GeneralComponent.kt @@ -35,6 +35,8 @@ import org.mariotaku.twidere.fragment.ThemedPreferenceDialogFragmentCompat import org.mariotaku.twidere.fragment.filter.FilteredUsersFragment import org.mariotaku.twidere.fragment.media.ExoPlayerPageFragment import org.mariotaku.twidere.loader.* +import org.mariotaku.twidere.loader.statuses.AbsRequestStatusesLoader +import org.mariotaku.twidere.loader.userlists.BaseUserListsLoader import org.mariotaku.twidere.preference.AccountsListPreference import org.mariotaku.twidere.preference.KeyboardShortcutPreference import org.mariotaku.twidere.preference.PremiumEntryPreference