mirror of
https://github.com/nuclearfog/Shitter.git
synced 2025-02-03 12:37:33 +01:00
bugfix
This commit is contained in:
parent
70bacf18e4
commit
7767125386
@ -38,7 +38,7 @@ import twitter4j.conf.ConfigurationBuilder;
|
||||
public class TwitterEngine {
|
||||
|
||||
private final String TWITTER_CONSUMER_KEY = "0EKRHWYcakpCkl8Lr4OcBFMZb";
|
||||
private final String TWITTER_CONSUMER_SECRET = "xxx";
|
||||
private final String TWITTER_CONSUMER_SECRET = "TODO";
|
||||
|
||||
private static TwitterEngine mTwitter;
|
||||
private static long twitterID = -1L;
|
||||
@ -238,7 +238,8 @@ public class TwitterEngine {
|
||||
* @throws TwitterException if access is unavailable
|
||||
*/
|
||||
public List<Tweet> getUserTweets(long userId, long page, long id) throws TwitterException {
|
||||
return convertStatusList(twitter.getUserTimeline(userId, new Paging((int)page,load, id)));
|
||||
List<Status> result = twitter.getUserTimeline(userId, new Paging((int)page,load, id));
|
||||
return convertStatusList(result,true);
|
||||
}
|
||||
|
||||
|
||||
@ -511,6 +512,17 @@ public class TwitterEngine {
|
||||
* @return TwitterStatus
|
||||
*/
|
||||
private List<Tweet> convertStatusList(List<Status> statuses) {
|
||||
return convertStatusList(statuses, false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* convert #twitter4j.Status to Tweet List
|
||||
* @param statuses Twitter4J status List
|
||||
* @param profileflag attach tweets to an User
|
||||
* @return TwitterStatus
|
||||
*/
|
||||
private List<Tweet> convertStatusList(List<Status> statuses, boolean profileflag) {
|
||||
List<Tweet> result = new ArrayList<>();
|
||||
if(statuses.isEmpty())
|
||||
return result;
|
||||
@ -520,10 +532,10 @@ public class TwitterEngine {
|
||||
Status embedded = status.getRetweetedStatus();
|
||||
if(embedded != null) {
|
||||
Tweet retweet = getTweet(embedded, null);
|
||||
Tweet tweet = getTweet(status, retweet);
|
||||
Tweet tweet = getTweet(status, retweet, profileflag);
|
||||
result.add(tweet);
|
||||
} else {
|
||||
Tweet tweet = getTweet(status, null);
|
||||
Tweet tweet = getTweet(status, null, profileflag);
|
||||
result.add(tweet);
|
||||
}
|
||||
} catch (Exception err) {
|
||||
@ -541,14 +553,23 @@ public class TwitterEngine {
|
||||
* @return Tweet item
|
||||
*/
|
||||
private Tweet getTweet(Status status, Tweet retweetedStat) {
|
||||
return getTweet(status, retweetedStat, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param status twitter4j.Status
|
||||
* @param retweetedStat embedded Status
|
||||
* @param profileflag attach tweet to an User
|
||||
* @return Tweet item
|
||||
*/
|
||||
private Tweet getTweet(Status status, Tweet retweetedStat, boolean profileflag) {
|
||||
TwitterUser user = getUser(status.getUser());
|
||||
return new Tweet(status.getId(),status.getRetweetCount(),status.getFavoriteCount(),user,
|
||||
status.getText(),status.getCreatedAt().getTime(),status.getInReplyToScreenName(),
|
||||
getMediaLinks(status),status.getSource(),status.getInReplyToStatusId(),
|
||||
retweetedStat, status.isRetweeted(), status.isFavorited());
|
||||
retweetedStat, status.isRetweeted(), status.isFavorited(),profileflag);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param user Twitter4J User
|
||||
* @return User item
|
||||
|
@ -8,11 +8,11 @@ public class Tweet {
|
||||
public final long time, replyID;
|
||||
public final int retweet, favorit;
|
||||
public final String[] media;
|
||||
public final boolean retweeted, favorized;
|
||||
public final boolean retweeted, favorized, profileflag;
|
||||
|
||||
public Tweet(long tweetID, int retweet, int favorit, TwitterUser user, String tweet, long time,
|
||||
String replyName, String[] media, String source, long replyID, Tweet embedded,
|
||||
boolean retweeted, boolean favorized) {
|
||||
boolean retweeted, boolean favorized, boolean profileflag) {
|
||||
this.tweetID = tweetID;
|
||||
this.user = user;
|
||||
this.retweet = retweet;
|
||||
@ -26,5 +26,6 @@ public class Tweet {
|
||||
this.source = source;
|
||||
this.retweeted = retweeted;
|
||||
this.favorized = favorized;
|
||||
this.profileflag = profileflag;
|
||||
}
|
||||
}
|
@ -14,8 +14,8 @@ public class AppDatabase extends SQLiteOpenHelper
|
||||
|
||||
private static final String tweetTable = "CREATE TABLE IF NOT EXISTS tweet (" +
|
||||
"tweetID INTEGER PRIMARY KEY, userID INTEGER, retweetID INTEGER, replyID INTEGER," +
|
||||
"replyname TEXT, time INTEGER, tweet TEXT, links TEXT, retweet INTEGER, favorite INTEGER," +
|
||||
"retweeted INTEGER, favorized INTEGER, source TEXT, FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
"replyname TEXT, time INTEGER, tweet TEXT, media TEXT, retweet INTEGER, favorite INTEGER," +
|
||||
"statusregister INTEGER, source TEXT, FOREIGN KEY (userID) REFERENCES user(userID));";
|
||||
|
||||
private static final String favoriteTable = "CREATE TABLE IF NOT EXISTS favorit (" +
|
||||
"userID INTEGER, tweetID INTEGER UNIQUE," +
|
||||
|
@ -92,7 +92,7 @@ public class DatabaseAdapter {
|
||||
else if(mode == TWEET) {
|
||||
SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
"INNER JOIN user ON tweet.userID = user.userID"+
|
||||
" WHERE user.userID = "+id+" ORDER BY tweetID DESC";
|
||||
" WHERE user.userID = "+id+" AND statusregister < 4 ORDER BY tweetID DESC";
|
||||
}
|
||||
else if(mode == FAVT) {
|
||||
SQL_GET_HOME = "SELECT * FROM tweet " +
|
||||
@ -224,22 +224,27 @@ public class DatabaseAdapter {
|
||||
long tweetId = cursor.getLong(index);
|
||||
index = cursor.getColumnIndex("retweetID");
|
||||
long retweetId = cursor.getLong(index);
|
||||
index = cursor.getColumnIndex("retweeted");
|
||||
boolean retweeted = cursor.getInt(index) == 1;
|
||||
index = cursor.getColumnIndex("favorized");
|
||||
boolean favorized = cursor.getInt(index) == 1;
|
||||
index = cursor.getColumnIndex("replyname");
|
||||
String replyname = cursor.getString(index);
|
||||
index = cursor.getColumnIndex("replyID");
|
||||
long replyStatusId = cursor.getLong(index);
|
||||
index = cursor.getColumnIndex("source");
|
||||
String source = cursor.getString(index);
|
||||
index = cursor.getColumnIndex("media");
|
||||
String medialinks = cursor.getString(index);
|
||||
index = cursor.getColumnIndex("statusregister");
|
||||
int statusregister = cursor.getInt(index);
|
||||
boolean favorited = (statusregister & 1) == 1;
|
||||
boolean retweeted = (statusregister & 2) == 2;
|
||||
boolean profileflag = (statusregister & 4) == 4;
|
||||
String[] medias = parseMedia(medialinks);
|
||||
|
||||
TwitterUser user = getUser(cursor);
|
||||
Tweet embeddedTweet = null;
|
||||
if(retweetId > 0)
|
||||
embeddedTweet = getStatus(retweetId);
|
||||
return new Tweet(tweetId,retweet,favorit,user,tweettext,time,replyname,null/*TODO*/,
|
||||
source,replyStatusId,embeddedTweet,retweeted,favorized);
|
||||
return new Tweet(tweetId,retweet,favorit,user,tweettext,time,replyname,medias,
|
||||
source,replyStatusId,embeddedTweet,retweeted,favorited,profileflag);
|
||||
}
|
||||
|
||||
|
||||
@ -296,8 +301,25 @@ public class DatabaseAdapter {
|
||||
status.put("source", tweet.source);
|
||||
status.put("replyID", tweet.replyID);
|
||||
status.put("replyname", tweet.replyName);
|
||||
status.put("retweeted",tweet.retweeted);
|
||||
status.put("favorized", tweet.favorized);
|
||||
|
||||
String[] medialinks = tweet.media;
|
||||
StringBuilder media = new StringBuilder();
|
||||
|
||||
for(String link : medialinks) {
|
||||
media.append(link);
|
||||
media.append(";");
|
||||
}
|
||||
status.put("media",media.toString());
|
||||
|
||||
int statusregister = 0;
|
||||
if(tweet.favorized)
|
||||
statusregister += 1;
|
||||
if(tweet.retweeted)
|
||||
statusregister += 2;
|
||||
if(tweet.profileflag)
|
||||
statusregister += 4;
|
||||
|
||||
status.put("statusregister",statusregister);
|
||||
db.insertWithOnConflict("tweet",null, status,SQLiteDatabase.CONFLICT_REPLACE);
|
||||
}
|
||||
|
||||
@ -319,4 +341,19 @@ public class DatabaseAdapter {
|
||||
userColumn.put("follower", user.follower);
|
||||
db.insertWithOnConflict("user",null, userColumn,SQLiteDatabase.CONFLICT_REPLACE);
|
||||
}
|
||||
|
||||
|
||||
private String[] parseMedia(String media) {
|
||||
int index;
|
||||
List<String> links = new ArrayList<>();
|
||||
do {
|
||||
index = media.indexOf(';');
|
||||
if(index > 0 && index < media.length()) {
|
||||
links.add(media.substring(0,index));
|
||||
media = media.substring(index+1);
|
||||
}
|
||||
} while(index >0);
|
||||
String[] result = new String[links.size()];
|
||||
return links.toArray(result);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user