Performance raised
This commit is contained in:
NudeDude 2018-03-23 17:10:23 +01:00
parent 58d7018ae4
commit 0df5849649
7 changed files with 54 additions and 57 deletions

View File

@ -19,7 +19,7 @@ import android.widget.TabHost.TabSpec;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.database.TrendDatabase;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.backend.Registration;
import org.nuclearfog.twidda.backend.MainPage;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
@ -328,14 +328,14 @@ public class MainActivity extends AppCompatActivity implements
TimelineRecycler mentRc = (TimelineRecycler) mentionList.getAdapter();
if(tlRc == null || tlRc.getItemCount() == 0) {
TweetDatabase tweetDeck = new TweetDatabase(getApplicationContext());
List<Tweet> tweets = tweetDeck.load(TweetDatabase.HOME, -1L);
DatabaseAdapter tweetDeck = new DatabaseAdapter(getApplicationContext());
List<Tweet> tweets = tweetDeck.load(DatabaseAdapter.HOME, -1L);
tlRc = new TimelineRecycler(tweets, MainActivity.this);
timelineList.setAdapter(tlRc);
}
if(mentRc == null || mentRc.getItemCount() == 0) {
TweetDatabase mentDeck = new TweetDatabase(getApplicationContext());
List<Tweet> tweets = mentDeck.load(TweetDatabase.MENT,-1L);
DatabaseAdapter mentDeck = new DatabaseAdapter(getApplicationContext());
List<Tweet> tweets = mentDeck.load(DatabaseAdapter.MENT,-1L);
mentRc = new TimelineRecycler(tweets, MainActivity.this);
mentionList.setAdapter(mentRc);
}

View File

@ -1,7 +1,7 @@
package org.nuclearfog.twidda.backend;
import org.nuclearfog.twidda.database.TrendDatabase;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.MainActivity;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
@ -62,7 +62,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
int page = args[1];
long id = 1L;
try {
TweetDatabase tweetDb = new TweetDatabase(ui.get());
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
switch (MODE) {
case HOME:
List<Tweet> tweets;
@ -70,11 +70,11 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
if(timelineAdapter != null && timelineAdapter.getItemCount() > 0) {
id = timelineAdapter.getItemId(0);
tweets = mTwitter.getHome(page,id);
tweetDb.store(tweets, TweetDatabase.HOME,-1L);
tweetDb.store(tweets, DatabaseAdapter.HOME,-1L);
tweets.addAll(timelineAdapter.getData());
} else {
tweets = mTwitter.getHome(page,id);
tweetDb.store(tweets, TweetDatabase.HOME,-1L);
tweetDb.store(tweets, DatabaseAdapter.HOME,-1L);
}
timelineAdapter = new TimelineRecycler(tweets, ui.get());
timelineAdapter.setColor(highlight, font);
@ -95,11 +95,11 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
if(mentionAdapter != null && mentionAdapter.getItemCount() != 0) {
id = mentionAdapter.getItemId(0);
mention = mTwitter.getMention(page,id);
tweetDb.store(mention,TweetDatabase.MENT,-1L);
tweetDb.store(mention, DatabaseAdapter.MENT,-1L);
mention.addAll(mentionAdapter.getData());
} else {
mention = mTwitter.getMention(page,id);
tweetDb.store(mention,TweetDatabase.MENT,-1L);
tweetDb.store(mention, DatabaseAdapter.MENT,-1L);
}
mentionAdapter = new TimelineRecycler(mention, ui.get());
mentionAdapter.setColor(highlight, font);

View File

@ -12,7 +12,7 @@ import android.widget.TextView;
import android.widget.Toast;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.UserProfile;
@ -73,13 +73,17 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
isHome = TwitterEngine.getHomeId() == userId;
if(!isHome)
{
isFollowing = mTwitter.getConnection(userId, true);
isFollowed = mTwitter.getConnection(userId, false);
muted = mTwitter.getBlocked(userId);
boolean connection[] = mTwitter.getConnection(userId);
isFollowing = connection[0];
isFollowed = connection[1];
muted = connection[2];
}
if(MODE == GET_INFORMATION)
{
TwitterUser user = mTwitter.getUser(userId);
DatabaseAdapter userdb = new DatabaseAdapter(ui.get());
TwitterUser user = userdb.getUser(userId);
if(user == null)
user = mTwitter.getUser(userId);
screenName = user.screenname;
username = user.username;
description = user.bio;
@ -97,17 +101,17 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(MODE == GET_TWEETS)
{
TweetDatabase tweetDb = new TweetDatabase(ui.get());
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> tweets;
homeTl = (TimelineRecycler) profileTweets.getAdapter();
if(homeTl != null && homeTl.getItemCount() > 0) {
id = homeTl.getItemId(0);
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.store(tweets,TweetDatabase.TWEET, userId);
tweetDb.store(tweets, DatabaseAdapter.TWEET, userId);
tweets.addAll(homeTl.getData());
} else {
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.store(tweets,TweetDatabase.TWEET, userId);
tweetDb.store(tweets, DatabaseAdapter.TWEET, userId);
}
homeTl = new TimelineRecycler(tweets,ui.get());
homeTl.setColor(highlight,font);
@ -115,17 +119,17 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(MODE == GET_FAVS)
{
TweetDatabase tweetDb = new TweetDatabase(ui.get());
DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get());
List<Tweet> favorits;
homeFav = (TimelineRecycler) profileFavorits.getAdapter();
if(homeFav != null && homeFav.getItemCount() > 0) {
id = homeFav.getItemId(0);
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.store(favorits,TweetDatabase.FAVT, userId);
tweetDb.store(favorits, DatabaseAdapter.FAVT, userId);
favorits.addAll(homeFav.getData());
} else {
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.store(favorits,TweetDatabase.FAVT, userId);
tweetDb.store(favorits, DatabaseAdapter.FAVT, userId);
}
homeFav = new TimelineRecycler(favorits,ui.get());
homeFav.setColor(highlight,font);

View File

@ -30,7 +30,7 @@ import java.util.List;
import twitter4j.TwitterException;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
@ -120,7 +120,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
else if(mode == RETWEET) {
if(retweeted) {
mTwitter.retweet(tweetID, true);
new TweetDatabase(ui.get()).removeStatus(tweetID);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
retweeted = false;
rt--;
} else {
@ -156,12 +156,12 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
else if(mode == DELETE) {
mTwitter.deleteTweet(tweetID);
new TweetDatabase(ui.get()).removeStatus(tweetID);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
}
}catch(TwitterException e) {
int err = e.getErrorCode();
if(err == 144) { // gelöscht
new TweetDatabase(ui.get()).removeStatus(tweetID);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
}
errMSG = e.getMessage();
return ERROR;

View File

@ -17,6 +17,7 @@ import twitter4j.MediaEntity;
import twitter4j.Paging;
import twitter4j.Query;
import twitter4j.QueryResult;
import twitter4j.Relationship;
import twitter4j.Status;
import twitter4j.StatusUpdate;
import twitter4j.Trends;
@ -241,28 +242,18 @@ public class TwitterEngine {
/**
* Get Connection between Home and another User
* @param id User ID
* @param following mode following = true , follower = false
* @return result
* @throws TwitterException if Access is unavailable
* Efficient Access of Connection Information
* @param id User ID compared with Home ID
* @return array of connection states Index 0: Following, 1: Follow, 2: blocked
* @throws TwitterException if Connection is unavailable
*/
public boolean getConnection(long id,boolean following) throws TwitterException {
if(following)
return twitter.showFriendship(twitterID,id).isSourceFollowingTarget();
else
return twitter.showFriendship(twitterID,id).isTargetFollowingSource();
}
/**
* Get Block Status
* @param id User ID
* @return if target is blocked
* @throws TwitterException if Access is unavailable
*/
public boolean getBlocked(long id) throws TwitterException {
return twitter.showFriendship(twitter.getId(),id).isSourceBlockingTarget();
public boolean[] getConnection(long id) throws TwitterException {
Relationship connect = twitter.showFriendship(twitterID,id);
boolean connection[] = new boolean[3];
connection[0] = connect.isSourceFollowingTarget();
connection[1] = connect.isTargetFollowingSource();
connection[2] = connect.isSourceBlockingTarget();
return connection;
}
@ -273,7 +264,7 @@ public class TwitterEngine {
* @throws TwitterException if Access is unavailable
*/
public boolean toggleFollow(long id) throws TwitterException {
if(getConnection(id,false)) {
if(getConnection(id)[1]) {
twitter.destroyFriendship(id);
return false;
} else {
@ -290,7 +281,7 @@ public class TwitterEngine {
* @throws TwitterException if Access is unavailable
*/
public boolean toggleBlock(long id) throws TwitterException {
if(getBlocked(id)){
if(getConnection(id)[2]){
twitter.destroyBlock(id);
return false;
} else {

View File

@ -8,7 +8,7 @@ import android.database.sqlite.SQLiteDatabase;
import java.util.ArrayList;
import java.util.List;
public class TweetDatabase {
public class DatabaseAdapter {
public static final int FAVT = 1;
public static final int TWEET = 2;
@ -19,7 +19,7 @@ public class TweetDatabase {
private List<Tweet> tweetlist;
private Context context;
public TweetDatabase(Context context) {
public DatabaseAdapter(Context context) {
dataHelper = AppDatabase.getInstance(context);
tweetlist = new ArrayList<>();
this.context = context;
@ -193,8 +193,10 @@ public class TweetDatabase {
private void storeStatus(Tweet tweet, SQLiteDatabase db, long retweetID) {
ContentValues status = new ContentValues();
ContentValues user = new ContentValues();
TwitterUser mUser = tweet.user;
status.put("tweetID", tweet.tweetID);
status.put("userID", mUser.userID);
status.put("time", tweet.time);
status.put("tweet", tweet.tweet);
status.put("retweet", tweet.retweet);
@ -205,7 +207,7 @@ public class TweetDatabase {
status.put("replyname", tweet.replyName);
status.put("retweeted",tweet.retweeted);
status.put("favorized", tweet.favorized);
TwitterUser mUser = tweet.user;
user.put("userID", mUser.userID);
user.put("username", mUser.username);
user.put("scrname", mUser.screenname.substring(1));

View File

@ -18,7 +18,7 @@ import android.widget.TextView;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.backend.ProfileLoader;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
@ -207,10 +207,10 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
int background = mcolor.getColor(ColorPreferences.BACKGROUND);
int font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
TweetDatabase mTweet = new TweetDatabase(getApplicationContext());
TweetDatabase fTweet = new TweetDatabase(getApplicationContext());
List<Tweet> userTweets = mTweet.load(TweetDatabase.TWEET,userId);
List<Tweet> userFavorit = fTweet.load(TweetDatabase.FAVT,userId);
DatabaseAdapter mTweet = new DatabaseAdapter(getApplicationContext());
DatabaseAdapter fTweet = new DatabaseAdapter(getApplicationContext());
List<Tweet> userTweets = mTweet.load(DatabaseAdapter.TWEET,userId);
List<Tweet> userFavorit = fTweet.load(DatabaseAdapter.FAVT,userId);
mTweets = new ProfileLoader(UserProfile.this);
mFavorits = new ProfileLoader(UserProfile.this);