added userlist v1 implementation, added userlist methods, added trend v1 implementation, added trend methods
This commit is contained in:
parent
1fa3f847e5
commit
f6556b3ed6
|
@ -640,7 +640,7 @@ public class AppSettings extends AppCompatActivity implements OnClickListener, O
|
|||
*
|
||||
* @param err exception from twitter
|
||||
*/
|
||||
public void onError(EngineException err) {
|
||||
public void onError(ErrorHandler.TwitterError err) {
|
||||
ErrorHandler.handleFailure(this, err);
|
||||
}
|
||||
|
||||
|
|
|
@ -211,7 +211,7 @@ public class ListAdapter extends Adapter<ViewHolder> {
|
|||
vh.textViews[1].setText(item.getDescription());
|
||||
vh.textViews[2].setText(owner.getUsername());
|
||||
vh.textViews[3].setText(owner.getScreenname());
|
||||
vh.textViews[4].setText(formatCreationTime(item.getCreatedAt()));
|
||||
vh.textViews[4].setText(formatCreationTime(item.getTimestamp()));
|
||||
vh.textViews[5].setText(NUM_FORMAT.format(item.getMemberCount()));
|
||||
vh.textViews[6].setText(NUM_FORMAT.format(item.getSubscriberCount()));
|
||||
if (settings.imagesEnabled() && !owner.getImageUrl().isEmpty()) {
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.os.AsyncTask;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.backend.apiold.EngineException;
|
||||
import org.nuclearfog.twidda.backend.apiold.TwitterEngine;
|
||||
import org.nuclearfog.twidda.backend.api.Twitter;
|
||||
import org.nuclearfog.twidda.backend.api.TwitterException;
|
||||
import org.nuclearfog.twidda.backend.lists.UserLists;
|
||||
import org.nuclearfog.twidda.fragments.UserListFragment;
|
||||
|
||||
|
@ -37,24 +37,23 @@ public class ListLoader extends AsyncTask<Long, Void, UserLists> {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
private EngineException twException;
|
||||
private final WeakReference<UserListFragment> callback;
|
||||
private final TwitterEngine mTwitter;
|
||||
private final Type listType;
|
||||
|
||||
private final long userId;
|
||||
private final String ownerName;
|
||||
private TwitterException twException;
|
||||
private WeakReference<UserListFragment> callback;
|
||||
private Twitter twitter;
|
||||
private Type listType;
|
||||
private long userId;
|
||||
private String ownerName;
|
||||
|
||||
/**
|
||||
* @param callback callback to update information
|
||||
* @param fragment callback to update information
|
||||
* @param listType type of list to load
|
||||
* @param userId ID of the userlist
|
||||
* @param ownerName alternative if user id is not defined
|
||||
*/
|
||||
public ListLoader(UserListFragment callback, Type listType, long userId, String ownerName) {
|
||||
public ListLoader(UserListFragment fragment, Type listType, long userId, String ownerName) {
|
||||
super();
|
||||
mTwitter = TwitterEngine.getInstance(callback.getContext());
|
||||
this.callback = new WeakReference<>(callback);
|
||||
twitter = Twitter.get(fragment.getContext());
|
||||
callback = new WeakReference<>(fragment);
|
||||
this.listType = listType;
|
||||
this.userId = userId;
|
||||
this.ownerName = ownerName;
|
||||
|
@ -65,12 +64,12 @@ public class ListLoader extends AsyncTask<Long, Void, UserLists> {
|
|||
protected UserLists doInBackground(Long[] param) {
|
||||
try {
|
||||
if (listType == Type.LOAD_USERLISTS) {
|
||||
return mTwitter.getUserList(userId, ownerName, param[0]);
|
||||
return twitter.getUserListOwnerships(userId, ownerName, param[0]);
|
||||
}
|
||||
if (listType == Type.LOAD_MEMBERSHIPS) {
|
||||
return mTwitter.getUserListMemberships(userId, ownerName, param[0]);
|
||||
return twitter.getUserListMemberships(userId, ownerName, param[0]);
|
||||
}
|
||||
} catch (EngineException twException) {
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
|
|
|
@ -3,8 +3,8 @@ package org.nuclearfog.twidda.backend;
|
|||
import android.os.AsyncTask;
|
||||
|
||||
import org.nuclearfog.twidda.activities.AppSettings;
|
||||
import org.nuclearfog.twidda.backend.apiold.EngineException;
|
||||
import org.nuclearfog.twidda.backend.apiold.TwitterEngine;
|
||||
import org.nuclearfog.twidda.backend.api.Twitter;
|
||||
import org.nuclearfog.twidda.backend.api.TwitterException;
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
|
@ -18,23 +18,23 @@ import java.util.List;
|
|||
*/
|
||||
public class LocationLoader extends AsyncTask<Void, Void, List<Location>> {
|
||||
|
||||
private EngineException twException;
|
||||
private TwitterException twException;
|
||||
private WeakReference<AppSettings> callback;
|
||||
private TwitterEngine mTwitter;
|
||||
private Twitter twitter;
|
||||
|
||||
|
||||
public LocationLoader(AppSettings callback) {
|
||||
super();
|
||||
this.callback = new WeakReference<>(callback);
|
||||
mTwitter = TwitterEngine.getInstance(callback);
|
||||
twitter = Twitter.get(callback);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected List<Location> doInBackground(Void[] v) {
|
||||
try {
|
||||
return mTwitter.getLocations();
|
||||
} catch (EngineException twException) {
|
||||
return twitter.getLocations();
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
}
|
||||
return null;
|
||||
|
|
|
@ -4,8 +4,8 @@ import android.os.AsyncTask;
|
|||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import org.nuclearfog.twidda.backend.apiold.EngineException;
|
||||
import org.nuclearfog.twidda.backend.apiold.TwitterEngine;
|
||||
import org.nuclearfog.twidda.backend.api.Twitter;
|
||||
import org.nuclearfog.twidda.backend.api.TwitterException;
|
||||
import org.nuclearfog.twidda.database.AppDatabase;
|
||||
import org.nuclearfog.twidda.fragments.TrendFragment;
|
||||
import org.nuclearfog.twidda.model.Trend;
|
||||
|
@ -13,7 +13,6 @@ import org.nuclearfog.twidda.model.Trend;
|
|||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
/**
|
||||
* Background task to load a list of location specific trends
|
||||
*
|
||||
|
@ -23,21 +22,21 @@ import java.util.List;
|
|||
public class TrendLoader extends AsyncTask<Integer, Void, List<Trend>> {
|
||||
|
||||
@Nullable
|
||||
private EngineException twException;
|
||||
private TwitterException twException;
|
||||
private final WeakReference<TrendFragment> callback;
|
||||
private final TwitterEngine mTwitter;
|
||||
private final Twitter twitter;
|
||||
private final AppDatabase db;
|
||||
private final boolean isEmpty;
|
||||
|
||||
/**
|
||||
* @param callback callback to update data
|
||||
* @param fragment callback to update data
|
||||
*/
|
||||
public TrendLoader(TrendFragment callback) {
|
||||
public TrendLoader(TrendFragment fragment) {
|
||||
super();
|
||||
this.callback = new WeakReference<>(callback);
|
||||
db = new AppDatabase(callback.getContext());
|
||||
mTwitter = TwitterEngine.getInstance(callback.getContext());
|
||||
isEmpty = callback.isEmpty();
|
||||
callback = new WeakReference<>(fragment);
|
||||
db = new AppDatabase(fragment.getContext());
|
||||
twitter = Twitter.get(fragment.getContext());
|
||||
isEmpty = fragment.isEmpty();
|
||||
}
|
||||
|
||||
|
||||
|
@ -49,15 +48,15 @@ public class TrendLoader extends AsyncTask<Integer, Void, List<Trend>> {
|
|||
if (isEmpty) {
|
||||
trends = db.getTrends(woeId);
|
||||
if (trends.isEmpty()) {
|
||||
trends = mTwitter.getTrends(woeId);
|
||||
trends = twitter.getTrends(woeId);
|
||||
db.storeTrends(trends, woeId);
|
||||
}
|
||||
} else {
|
||||
trends = mTwitter.getTrends(woeId);
|
||||
trends = twitter.getTrends(woeId);
|
||||
db.storeTrends(trends, woeId);
|
||||
}
|
||||
return trends;
|
||||
} catch (EngineException twException) {
|
||||
} catch (TwitterException twException) {
|
||||
this.twException = twException;
|
||||
} catch (Exception err) {
|
||||
err.printStackTrace();
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package org.nuclearfog.twidda.backend.api;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
|
||||
/**
|
||||
* API v1.1 implementation of Trend location
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
class LocationV1 implements Location {
|
||||
|
||||
private int id;
|
||||
private String name;
|
||||
|
||||
LocationV1(JSONObject json) {
|
||||
id = json.optInt("woeid");
|
||||
String placeName = json.optString("name");
|
||||
String country = json.optString("country");
|
||||
|
||||
if (!country.isEmpty() && !country.equals(placeName))
|
||||
name = country + ", " + placeName;
|
||||
else
|
||||
name = placeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.nuclearfog.twidda.backend.api;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.model.Trend;
|
||||
|
||||
/**
|
||||
* API v 1.1 implementation for a twitter trend
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
class TrendV1 implements Trend {
|
||||
|
||||
private int rank;
|
||||
private int popularity;
|
||||
private String name;
|
||||
|
||||
TrendV1(JSONObject json, int rank) {
|
||||
name = json.optString("name");
|
||||
popularity = json.optInt("tweet_volume");
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPopularity() {
|
||||
return popularity;
|
||||
}
|
||||
}
|
|
@ -7,11 +7,14 @@ import android.os.Build;
|
|||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.lists.UserLists;
|
||||
import org.nuclearfog.twidda.backend.lists.Users;
|
||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||
import org.nuclearfog.twidda.backend.utils.TLSSocketFactory;
|
||||
import org.nuclearfog.twidda.backend.utils.Tokens;
|
||||
import org.nuclearfog.twidda.database.ExcludeDatabase;
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
import org.nuclearfog.twidda.model.Trend;
|
||||
import org.nuclearfog.twidda.model.Tweet;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
|
@ -59,10 +62,14 @@ public class Twitter {
|
|||
private static final String SHOW_TWEET = API + "1.1/statuses/show.json";
|
||||
private static final String SHOW_HOME = API + "1.1/statuses/home_timeline.json";
|
||||
private static final String SHOW_MENTIONS = API + "1.1/statuses/mentions_timeline.json";
|
||||
private static final String SHOW_USER_TL = API + "1.1/statuses/user_timeline.json";
|
||||
private static final String SHOW_USER_FAV = API + "1.1/favorites/list.json";
|
||||
private static final String SHOW_LIST_TWEETS = API + "1.1/lists/statuses.json";
|
||||
private static final String SEARCH_TWEETS = API + "1.1/search/tweets.json";
|
||||
private static final String USER_TIMELINE = API + "1.1/statuses/user_timeline.json";
|
||||
private static final String USER_FAVORITS = API + "1.1/favorites/list.json";
|
||||
private static final String LIST_TWEETS = API + "1.1/lists/statuses.json";
|
||||
private static final String TWEET_SEARCH = API + "1.1/search/tweets.json";
|
||||
private static final String TRENDS = API + "1.1/trends/place.json";
|
||||
private static final String LOCATIONS = API + "1.1/trends/available.json";
|
||||
private static final String USER_LIST_OWNERSHIP = API + "1.1/lists/list.json";
|
||||
private static final String USER_LIST_MEMBERSHIP = API + "1.1/lists/memberships.json";
|
||||
public static final String REQUEST_URL = AUTHENTICATE + "?oauth_token=";
|
||||
|
||||
private static Twitter instance;
|
||||
|
@ -318,7 +325,7 @@ public class Twitter {
|
|||
params.add("max_id=" + maxId);
|
||||
params.add("q=" + StringTools.encode(search+ " +exclude:retweets"));
|
||||
params.add("result_type=recent");
|
||||
List<Tweet> result = getTweets1(SEARCH_TWEETS, params);
|
||||
List<Tweet> result = getTweets1(TWEET_SEARCH, params);
|
||||
if (settings.filterResults())
|
||||
filterTweets(result);
|
||||
return result;
|
||||
|
@ -350,6 +357,73 @@ public class Twitter {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* get location trends
|
||||
*
|
||||
* @param id world ID
|
||||
* @return trend list
|
||||
*/
|
||||
public List<Trend> getTrends(int id) throws TwitterException {
|
||||
List<String> params = new ArrayList<>(2);
|
||||
params.add("id=" + id);
|
||||
try {
|
||||
Response response = get(TRENDS, params);
|
||||
if (response.body() != null) {
|
||||
if (response.code() == 200) {
|
||||
JSONArray json = new JSONArray(response.body().string());
|
||||
JSONArray trends = json.getJSONObject(0).getJSONArray("trends");
|
||||
List<Trend> result = new ArrayList<>(trends.length() + 1);
|
||||
for (int pos = 0 ; pos < trends.length() ; pos++) {
|
||||
JSONObject trend = trends.getJSONObject(pos);
|
||||
result.add(new TrendV1(trend, pos + 1));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
throw new TwitterException(json);
|
||||
}
|
||||
} else {
|
||||
throw new TwitterException(response);
|
||||
}
|
||||
} catch (IOException err) {
|
||||
throw new TwitterException(err);
|
||||
} catch (JSONException err) {
|
||||
throw new TwitterException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get available locations for trends
|
||||
*
|
||||
* @return list of locations
|
||||
*/
|
||||
public List<Location> getLocations() throws TwitterException {
|
||||
//SHOW_LOCATIONS
|
||||
try {
|
||||
Response response = get(LOCATIONS, new ArrayList<>(0));
|
||||
if (response.body() != null) {
|
||||
if (response.code() == 200) {
|
||||
JSONArray locations = new JSONArray(response.body().string());
|
||||
List<Location> result = new ArrayList<>(locations.length() + 1);
|
||||
for (int pos = 0 ; pos < locations.length() ; pos++) {
|
||||
JSONObject location = locations.getJSONObject(pos);
|
||||
result.add(new LocationV1(location));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
throw new TwitterException(json);
|
||||
}
|
||||
} else {
|
||||
throw new TwitterException(response);
|
||||
}
|
||||
} catch (IOException err) {
|
||||
throw new TwitterException(err);
|
||||
} catch (JSONException err) {
|
||||
throw new TwitterException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* show current user's home timeline
|
||||
*
|
||||
|
@ -397,7 +471,7 @@ public class Twitter {
|
|||
if (maxId > 1)
|
||||
params.add("max_id=" + maxId);
|
||||
params.add("user_id=" + userId);
|
||||
return getTweets1(SHOW_USER_TL, params);
|
||||
return getTweets1(USER_TIMELINE, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -415,7 +489,7 @@ public class Twitter {
|
|||
if (maxId > 1)
|
||||
params.add("max_id=" + maxId);
|
||||
params.add("screen_name=" + screen_name);
|
||||
return getTweets1(SHOW_USER_TL, params);
|
||||
return getTweets1(USER_TIMELINE, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -433,7 +507,7 @@ public class Twitter {
|
|||
if (maxId > 1)
|
||||
params.add("max_id=" + maxId);
|
||||
params.add("user_id=" + userId);
|
||||
return getTweets1(SHOW_USER_FAV, params);
|
||||
return getTweets1(USER_FAVORITS, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -451,7 +525,7 @@ public class Twitter {
|
|||
if (maxId > 1)
|
||||
params.add("max_id=" + maxId);
|
||||
params.add("screen_name=" + screen_name);
|
||||
return getTweets1(SHOW_USER_FAV, params);
|
||||
return getTweets1(USER_FAVORITS, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -469,7 +543,7 @@ public class Twitter {
|
|||
if (maxId > 1)
|
||||
params.add("max_id=" + maxId);
|
||||
params.add("list_id=" + listId);
|
||||
return getTweets1(SHOW_LIST_TWEETS, params);
|
||||
return getTweets1(LIST_TWEETS, params);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -491,7 +565,7 @@ public class Twitter {
|
|||
params.add("max_id=" + maxId);
|
||||
params.add("result_type=recent");
|
||||
params.add("q=" + StringTools.encode("to:" + name + " +exclude:retweets"));
|
||||
List<Tweet> result = getTweets1(SEARCH_TWEETS, params);
|
||||
List<Tweet> result = getTweets1(TWEET_SEARCH, params);
|
||||
List<Tweet> replies = new LinkedList<>();
|
||||
for (Tweet reply : result) {
|
||||
if (reply.getReplyId() == tweetId) {
|
||||
|
@ -531,6 +605,44 @@ public class Twitter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* return userlists an user is owning or following
|
||||
*
|
||||
* @param userId ID of the user
|
||||
* @param screen_name screen name of the user (without '@')
|
||||
* @param cursor list cursor
|
||||
* @return list of userlists
|
||||
*/
|
||||
public UserLists getUserListOwnerships(long userId, String screen_name, long cursor) throws TwitterException {
|
||||
List<String> params = new ArrayList<>(3);
|
||||
if (userId > 0)
|
||||
params.add("user_id=" + userId);
|
||||
else
|
||||
params.add("screen_name=" + screen_name);
|
||||
UserLists result = getUserlists(USER_LIST_OWNERSHIP, params);
|
||||
result.setCursors(cursor, -1); // this endpoint doesn't support cursors
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* return userlists an user is added to
|
||||
*
|
||||
* @param userId ID of the user
|
||||
* @param screen_name screen name of the user (without '@')
|
||||
* @param cursor list cursor
|
||||
* @return list of userlists
|
||||
*/
|
||||
public UserLists getUserListMemberships(long userId, String screen_name, long cursor) throws TwitterException {
|
||||
List<String> params = new ArrayList<>(5);
|
||||
if (userId > 0)
|
||||
params.add("user_id=" + userId);
|
||||
else
|
||||
params.add("screen_name=" + screen_name);
|
||||
params.add("count=" + settings.getListSize());
|
||||
params.add("cursor=" + cursor);
|
||||
return getUserlists(USER_LIST_MEMBERSHIP, params);
|
||||
}
|
||||
|
||||
/**
|
||||
* lookup single user
|
||||
*
|
||||
|
@ -682,6 +794,51 @@ public class Twitter {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get a list of userlists
|
||||
* @param endpoint endpoint to get the userlists from
|
||||
* @param params additional parameter
|
||||
* @return list of userlists
|
||||
*/
|
||||
private UserLists getUserlists(String endpoint, List<String> params) throws TwitterException {
|
||||
params.add(UserV1.INCLUDE_ENTITIES);
|
||||
try {
|
||||
Response response = get(endpoint, params);
|
||||
if (response.body() != null) {
|
||||
if (response.code() == 200) {
|
||||
JSONArray array;
|
||||
UserLists result = new UserLists();
|
||||
String body = response.body().string();
|
||||
// add cursors if available
|
||||
if (body.startsWith("{")) {
|
||||
JSONObject json = new JSONObject(body);
|
||||
array = json.getJSONArray("lists");
|
||||
long prevCursor = json.optLong("previous_cursor");
|
||||
long nextCursor = json.optLong("next_cursor");
|
||||
result.setCursors(prevCursor, nextCursor);
|
||||
} else {
|
||||
array = new JSONArray(body);
|
||||
}
|
||||
long currentId = settings.getCurrentUserId();
|
||||
for (int pos = 0 ; pos < array.length() ; pos++) {
|
||||
JSONObject item = array.getJSONObject(pos);
|
||||
result.add(new UserListV1(item, currentId));
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
throw new TwitterException(json);
|
||||
}
|
||||
} else {
|
||||
throw new TwitterException(response);
|
||||
}
|
||||
} catch (IOException err) {
|
||||
throw new TwitterException(err);
|
||||
} catch (JSONException err) {
|
||||
throw new TwitterException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* filter tweets from blocked users
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
package org.nuclearfog.twidda.backend.api;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
import org.nuclearfog.twidda.backend.utils.StringTools;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
import org.nuclearfog.twidda.model.UserList;
|
||||
|
||||
class UserListV1 implements UserList {
|
||||
|
||||
private long id;
|
||||
private long time;
|
||||
private String title;
|
||||
private String description;
|
||||
private int memberCount;
|
||||
private int subscriberCount;
|
||||
private boolean isPrivate;
|
||||
private boolean following;
|
||||
private boolean isOwner;
|
||||
private User owner;
|
||||
|
||||
|
||||
UserListV1(JSONObject json, long currentId) throws JSONException {
|
||||
id = json.optInt("id");
|
||||
title = json.optString("name");
|
||||
description = json.optString("description");
|
||||
memberCount = json.optInt("member_count");
|
||||
subscriberCount = json.optInt("subscriber_count");
|
||||
isPrivate = json.optString("mode").equals("private");
|
||||
following = json.optBoolean("following");
|
||||
time = StringTools.getTime(json.optString("created_at"));
|
||||
owner = new UserV1(json.getJSONObject("user"));
|
||||
isOwner = currentId == owner.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTimestamp() {
|
||||
return time;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
@Override
|
||||
public User getListOwner() {
|
||||
return owner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrivate() {
|
||||
return isPrivate;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isFollowing() {
|
||||
return following;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMemberCount() {
|
||||
return memberCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSubscriberCount() {
|
||||
return subscriberCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isListOwner() {
|
||||
return isOwner;
|
||||
}
|
||||
}
|
|
@ -1,54 +0,0 @@
|
|||
package org.nuclearfog.twidda.backend.apiold;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
|
||||
|
||||
/**
|
||||
* implementation for Twitter4J location
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
class LocationV1 implements Location {
|
||||
|
||||
private String placeName = "";
|
||||
private int worldId;
|
||||
|
||||
|
||||
LocationV1(twitter4j.Location location) {
|
||||
String country = location.getCountryName();
|
||||
String placeName = location.getName();
|
||||
|
||||
if (country != null && placeName != null) {
|
||||
if (!country.isEmpty() && !country.equals(placeName))
|
||||
this.placeName = country + ", " + placeName;
|
||||
else
|
||||
this.placeName = "" + placeName;
|
||||
}
|
||||
this.worldId = location.getWoeid();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return placeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return worldId;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return placeName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof LocationV1)
|
||||
return ((LocationV1) obj).worldId == worldId;
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package org.nuclearfog.twidda.backend.apiold;
|
||||
|
||||
import org.nuclearfog.twidda.model.Trend;
|
||||
|
||||
/**
|
||||
* Twitter Trend implementation for Twitter4J
|
||||
*
|
||||
* @author nuclearfog
|
||||
*/
|
||||
class TrendV1 implements Trend {
|
||||
|
||||
private int rank;
|
||||
private int range;
|
||||
private String trendName = "";
|
||||
|
||||
|
||||
TrendV1(twitter4j.Trend trend, int rank) {
|
||||
if (trend.getName() != null)
|
||||
this.trendName = trend.getName();
|
||||
this.range = trend.getTweetVolume();
|
||||
this.rank = rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return trendName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRank() {
|
||||
return rank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getPopularity() {
|
||||
return range;
|
||||
}
|
||||
}
|
|
@ -16,9 +16,7 @@ import org.nuclearfog.twidda.backend.utils.TLSSocketFactory;
|
|||
import org.nuclearfog.twidda.backend.utils.Tokens;
|
||||
import org.nuclearfog.twidda.database.ExcludeDatabase;
|
||||
import org.nuclearfog.twidda.database.GlobalSettings;
|
||||
import org.nuclearfog.twidda.model.Location;
|
||||
import org.nuclearfog.twidda.model.Relation;
|
||||
import org.nuclearfog.twidda.model.Trend;
|
||||
import org.nuclearfog.twidda.model.Tweet;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
import org.nuclearfog.twidda.model.UserList;
|
||||
|
@ -31,7 +29,6 @@ import java.io.InputStream;
|
|||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.TreeSet;
|
||||
|
@ -134,44 +131,6 @@ public class TwitterEngine {
|
|||
mTwitter.isInitialized = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Trending Hashtags
|
||||
*
|
||||
* @param woeId Yahoo World ID
|
||||
* @return Trend Resource
|
||||
* @throws EngineException if access is unavailable
|
||||
*/
|
||||
public List<Trend> getTrends(int woeId) throws EngineException {
|
||||
try {
|
||||
int index = 1;
|
||||
List<Trend> result = new LinkedList<>();
|
||||
twitter4j.Trend[] trends = twitter.getPlaceTrends(woeId).getTrends();
|
||||
for (twitter4j.Trend trend : trends)
|
||||
result.add(new TrendV1(trend, index++));
|
||||
return result;
|
||||
} catch (Exception err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get available locations
|
||||
*
|
||||
* @return list of locations
|
||||
* @throws EngineException if access is unavailable
|
||||
*/
|
||||
public List<Location> getLocations() throws EngineException {
|
||||
try {
|
||||
List<Location> result = new LinkedList<>();
|
||||
List<twitter4j.Location> locations = twitter.getAvailableTrends();
|
||||
for (twitter4j.Location location : locations)
|
||||
result.add(new LocationV1(location));
|
||||
return result;
|
||||
} catch (Exception err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User
|
||||
*
|
||||
|
@ -580,60 +539,6 @@ public class TwitterEngine {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get user list
|
||||
*
|
||||
* @param userId id of the list owner
|
||||
* @param cursor list cursor to set the start point
|
||||
* @return list information
|
||||
* @throws EngineException if access is unavailable
|
||||
*/
|
||||
public UserLists getUserList(long userId, String username, long cursor) throws EngineException {
|
||||
try {
|
||||
List<twitter4j.UserList> lists;
|
||||
if (userId > 0)
|
||||
lists = twitter.getUserLists(userId);
|
||||
else
|
||||
lists = twitter.getUserLists(username);
|
||||
long prevCursor = cursor > 0 ? cursor : 0;
|
||||
long nextCursor = 0;
|
||||
UserLists result = new UserLists(prevCursor, nextCursor); // todo add paging system
|
||||
for (twitter4j.UserList list : lists)
|
||||
result.add(new UserListV1(list, twitter.getId()));
|
||||
return result;
|
||||
} catch (Exception err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* get the lists the user has been added to
|
||||
*
|
||||
* @param userId ID of the user
|
||||
* @param username alternative to userId if id is '0'
|
||||
* @param cursor list cursor
|
||||
* @return a list of user lists
|
||||
* @throws EngineException if access is unavailable
|
||||
*/
|
||||
public UserLists getUserListMemberships(long userId, String username, long cursor) throws EngineException {
|
||||
try {
|
||||
int count = settings.getListSize();
|
||||
PagableResponseList<twitter4j.UserList> lists;
|
||||
if (userId > 0)
|
||||
lists = twitter.getUserListMemberships(userId, count, cursor);
|
||||
else
|
||||
lists = twitter.getUserListMemberships(username, count, cursor);
|
||||
long prevCursor = cursor > 0 ? cursor : 0;
|
||||
long nextCursor = lists.getNextCursor();
|
||||
UserLists result = new UserLists(prevCursor, nextCursor);
|
||||
for (twitter4j.UserList list : lists)
|
||||
result.add(new UserListV1(list, twitter.getId()));
|
||||
return result;
|
||||
} catch (Exception err) {
|
||||
throw new EngineException(err);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* load user list information
|
||||
*
|
||||
|
|
|
@ -60,7 +60,7 @@ class UserListV1 implements UserList {
|
|||
* @return date long format
|
||||
*/
|
||||
@Override
|
||||
public long getCreatedAt() {
|
||||
public long getTimestamp() {
|
||||
return createdAt;
|
||||
}
|
||||
|
||||
|
|
|
@ -67,6 +67,12 @@ public class UserLists extends LinkedList<UserList> {
|
|||
return nextCursor;
|
||||
}
|
||||
|
||||
|
||||
public void setCursors(long prevCursor, long nextCursor) {
|
||||
this.prevCursor = prevCursor;
|
||||
this.nextCursor = nextCursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* replace whole list including cursors
|
||||
*
|
||||
|
|
|
@ -111,7 +111,7 @@ public class TrendFragment extends ListFragment implements TrendClickListener {
|
|||
*
|
||||
* @param error Twitter exception
|
||||
*/
|
||||
public void onError(@Nullable EngineException error) {
|
||||
public void onError(@Nullable ErrorHandler.TwitterError error) {
|
||||
ErrorHandler.handleFailure(requireContext(), error);
|
||||
setRefresh(false);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.nuclearfog.twidda.activities.UserProfile;
|
|||
import org.nuclearfog.twidda.adapter.ListAdapter;
|
||||
import org.nuclearfog.twidda.adapter.ListAdapter.ListClickListener;
|
||||
import org.nuclearfog.twidda.backend.ListLoader;
|
||||
import org.nuclearfog.twidda.backend.apiold.EngineException;
|
||||
import org.nuclearfog.twidda.backend.lists.UserLists;
|
||||
import org.nuclearfog.twidda.model.User;
|
||||
import org.nuclearfog.twidda.backend.utils.ErrorHandler;
|
||||
|
@ -197,7 +196,7 @@ public class UserListFragment extends ListFragment implements ListClickListener
|
|||
*
|
||||
* @param error Twitter exception
|
||||
*/
|
||||
public void onError(@Nullable EngineException error) {
|
||||
public void onError(@Nullable ErrorHandler.TwitterError error) {
|
||||
ErrorHandler.handleFailure(requireContext(), error);
|
||||
adapter.disableLoading();
|
||||
setRefresh(false);
|
||||
|
|
|
@ -17,7 +17,7 @@ public interface UserList extends Serializable {
|
|||
/**
|
||||
* @return date of creation
|
||||
*/
|
||||
long getCreatedAt();
|
||||
long getTimestamp();
|
||||
|
||||
/**
|
||||
* @return title of the list
|
||||
|
|
Loading…
Reference in New Issue