Major Cleanup
This commit is contained in:
NudeDude 2018-03-16 19:39:24 +01:00
parent 1fee5209e6
commit 8d7455d22e
20 changed files with 622 additions and 556 deletions

View File

@ -17,6 +17,7 @@ import android.view.ViewGroup;
import android.widget.TabHost;
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.backend.Registration;
@ -31,6 +32,8 @@ import org.nuclearfog.twidda.window.AppSettings;
import org.nuclearfog.twidda.window.TweetDetail;
import org.nuclearfog.twidda.window.TweetPopup;
import java.util.List;
/**
* MainPage of the App
* @see Registration Registing App in Twitter
@ -50,7 +53,7 @@ public class MainActivity extends AppCompatActivity implements
private TabHost tabhost;
private boolean settingFlag = false;
private String currentTab = "timeline";
private int background, font_color;
private int background, font_color, highlight;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -221,10 +224,12 @@ public class MainActivity extends AppCompatActivity implements
case R.id.tl_list:
if(!timelineReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) timelineList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Tweet tweet = tlAdp.getData().get(position);
if(tweet.embedded != null)
tweet = tweet.embedded;
long tweetID = tweet.tweetID;
long userID = tweet.userID;
String username = tweet.screenname;
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
@ -241,9 +246,8 @@ public class MainActivity extends AppCompatActivity implements
Intent intent = new Intent(con, SearchPage.class);
Bundle bundle = new Bundle();
bundle.putString("search", search);
if(search.startsWith("#")) {
if(search.startsWith("#"))
bundle.putString("Addition", search);
}
intent.putExtras(bundle);
startActivity(intent);
}
@ -251,10 +255,12 @@ public class MainActivity extends AppCompatActivity implements
case R.id.m_list:
if(!mentionReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) mentionList.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Tweet tweet = tlAdp.getData().get(position);
if(tweet.embedded != null)
tweet = tweet.embedded;
long tweetID = tweet.tweetID;
long userID = tweet.userID;
String username = tweet.screenname;
Intent intent = new Intent(con, TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
@ -323,24 +329,31 @@ public class MainActivity extends AppCompatActivity implements
ColorPreferences mColor = ColorPreferences.getInstance(con);
background = mColor.getColor(ColorPreferences.BACKGROUND);
font_color = mColor.getColor(ColorPreferences.FONT_COLOR);
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
timelineList.setBackgroundColor(background);
trendList.setBackgroundColor(background);
mentionList.setBackgroundColor(background);
TimelineRecycler rlRc = (TimelineRecycler) timelineList.getAdapter();
TrendRecycler trendRc = (TrendRecycler) trendList.getAdapter();
TimelineRecycler mentRc = (TimelineRecycler) mentionList.getAdapter();
if(rlRc == null || rlRc.getItemCount() == 0) {
TweetDatabase tweetDeck = new TweetDatabase(con,TweetDatabase.HOME_TL, 0L);
rlRc = new TimelineRecycler(tweetDeck, MainActivity.this);
TweetDatabase tweetDeck = new TweetDatabase(con);
List<Tweet> tweets = tweetDeck.load(TweetDatabase.HOME, -1L);
rlRc = new TimelineRecycler(tweets, MainActivity.this);
} if(mentRc == null || mentRc.getItemCount() == 0) {
TweetDatabase mentDeck = new TweetDatabase(con, TweetDatabase.GET_MENT, 0L);
mentRc = new TimelineRecycler(mentDeck, MainActivity.this);
TweetDatabase mentDeck = new TweetDatabase(con);
List<Tweet> tweets = mentDeck.load(TweetDatabase.MENT,-1L);
mentRc = new TimelineRecycler(tweets, MainActivity.this);
} if(trendRc == null || trendRc.getItemCount() == 0) {
TrendDatabase trendDeck = new TrendDatabase(con);
trendRc = new TrendRecycler(trendDeck, MainActivity.this);
}
rlRc.setColor(background,font_color);
rlRc.setColor(highlight,font_color);
trendRc.setColor(background,font_color);
mentRc.setColor(background,font_color);
mentRc.setColor(highlight,font_color);
timelineList.setAdapter(rlRc);
trendList.setAdapter(trendRc);
mentionList.setAdapter(mentRc);

View File

@ -33,13 +33,13 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> implements Butt
popup.requestWindowFeature(Window.FEATURE_NO_TITLE);
popup.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
popup.setContentView(mBar);
popup.show();
popup.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ImagePopup.this.cancel(true);
}
});
popup.show();
}
@Override

View File

@ -13,8 +13,11 @@ import android.support.v7.widget.RecyclerView;
import android.widget.Toast;
import android.content.Context;
import android.os.AsyncTask;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.window.ColorPreferences;
import java.lang.ref.WeakReference;
import java.util.List;
public class MainPage extends AsyncTask<Integer, Void, Integer> {
@ -29,6 +32,8 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
private TimelineRecycler timelineAdapter, mentionAdapter;
private TrendRecycler trendsAdapter;
private int woeid;
private String errMsg;
private int highlight, font;
/**
* Main View
@ -42,10 +47,13 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
timelineList = (RecyclerView)ui.get().findViewById(R.id.tl_list);
trendList = (RecyclerView)ui.get().findViewById(R.id.tr_list);
mentionList = (RecyclerView)ui.get().findViewById(R.id.m_list);
ColorPreferences mColor = ColorPreferences.getInstance(ui.get());
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
font = mColor.getColor(ColorPreferences.FONT_COLOR);
}
/**
* @param args [0] Executing Mode: (0)HomeTL, (1)Trend, (2)Mention
* @param args [0] Execution Mode: (0)HomeTL, (1)Trend, (2)Mention
* @return success
*/
@Override
@ -54,16 +62,22 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
int page = args[1];
long id = 1L;
try {
TweetDatabase tweetDb = new TweetDatabase(ui.get());
switch (MODE) {
case HOME:
List<Tweet> tweets;
timelineAdapter = (TimelineRecycler) timelineList.getAdapter();
if(timelineAdapter != null && timelineAdapter.getItemCount() > 0) {
id = timelineAdapter.getItemId(0);
timelineAdapter.getData().insert(mTwitter.getHome(page,id),true);
tweets = mTwitter.getHome(page,id);
tweetDb.store(tweets, TweetDatabase.HOME,-1L);
tweets.addAll(timelineAdapter.getData());
} else {
TweetDatabase mTweets = new TweetDatabase(mTwitter.getHome(page,id), ui.get(),TweetDatabase.HOME_TL,0);
timelineAdapter = new TimelineRecycler(mTweets,ui.get());
tweets = mTwitter.getHome(page,id);
tweetDb.store(tweets, TweetDatabase.HOME,-1L);
}
timelineAdapter = new TimelineRecycler(tweets, ui.get());
timelineAdapter.setColor(highlight, font);
break;
case TRND:
@ -75,18 +89,23 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
break;
case MENT:
List<Tweet> mention;
mentionAdapter = (TimelineRecycler) mentionList.getAdapter();
if(mentionAdapter != null && mentionAdapter.getItemCount() != 0) {
id = mentionAdapter.getItemId(0);
mentionAdapter.getData().insert(mTwitter.getMention(page,id),true);
mention = mTwitter.getMention(page,id);
tweetDb.store(mention,TweetDatabase.MENT,-1L);
mention.addAll(mentionAdapter.getData());
} else {
TweetDatabase mention = new TweetDatabase(mTwitter.getMention(page,id), ui.get(),TweetDatabase.GET_MENT,0);
mentionAdapter = new TimelineRecycler(mention,ui.get());
mention = mTwitter.getMention(page,id);
tweetDb.store(mention,TweetDatabase.MENT,-1L);
}
mentionAdapter = new TimelineRecycler(mention, ui.get());
mentionAdapter.setColor(highlight, font);
break;
}
} catch (Exception e){
e.printStackTrace();
errMsg = e.getMessage();
return FAIL;
}
return MODE;
@ -104,12 +123,8 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
switch(MODE) {
case HOME:
timelineRefresh.setRefreshing(false);
if(timelineList.getAdapter().getItemCount() == 0) {
timelineList.setAdapter(timelineAdapter);
} else {
timelineAdapter.notifyDataSetChanged();
}
timelineRefresh.setRefreshing(false);
break;
case TRND:
@ -122,12 +137,8 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
break;
case MENT:
mentionRefresh.setRefreshing(false);
if(mentionList.getAdapter().getItemCount() == 0) {
mentionList.setAdapter(mentionAdapter);
} else {
mentionAdapter.notifyDataSetChanged();
}
mentionRefresh.setRefreshing(false);
break;
case FAIL:
@ -135,7 +146,7 @@ public class MainPage extends AsyncTask<Integer, Void, Integer> {
timelineRefresh.setRefreshing(false);
trendRefresh.setRefreshing(false);
mentionRefresh.setRefreshing(false);
Toast.makeText(context, context.getString(R.string.connection_failure), Toast.LENGTH_LONG).show();
Toast.makeText(context, "Fehler: "+errMsg, Toast.LENGTH_LONG).show();
}
}
}

View File

@ -14,11 +14,14 @@ import android.widget.Toast;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.UserProfile;
import org.nuclearfog.twidda.backend.listitems.*;
import java.lang.ref.WeakReference;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
import twitter4j.User;
import com.squareup.picasso.Picasso;
@ -33,10 +36,11 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
private String screenName, username, description, location, follower, following;
private RecyclerView profileTweets, profileFavorits;
private String imageLink, bannerLink, fullPbLink, link, dateString;
private String imageLink,/* bannerLink,*/ fullPbLink, link, dateString;
private TimelineRecycler homeTl, homeFav;
private WeakReference<UserProfile> ui;
private TwitterEngine mTwitter;
private int font, highlight;
private boolean isHome = false;
private boolean imgEnabled = false;
private boolean isFollowing = false;
@ -56,6 +60,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
mTwitter = TwitterEngine.getInstance(context);
SharedPreferences settings = context.getSharedPreferences("settings", 0);
imgEnabled = settings.getBoolean("image_load",true);
ColorPreferences mColor = ColorPreferences.getInstance(ui.get());
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
font = mColor.getColor(ColorPreferences.FONT_COLOR);
}
@Override
@ -63,7 +70,6 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
long userId = args[0];
final long MODE = args[1];
long id = 1L;
try {
isHome = TwitterEngine.getHomeId() == userId;
if(!isHome)
@ -85,47 +91,61 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
follower = Integer.toString(user.getFollowersCount());
following = Integer.toString(user.getFriendsCount());
imageLink = user.getProfileImageURL();
bannerLink = user.getProfileBannerMobileURL();
// bannerLink = user.getProfileBannerMobileURL();
fullPbLink = user.getOriginalProfileImageURL();
Date d = user.getCreatedAt();
dateString = "seit "+ DateFormat.getDateTimeInstance().format(d);
}
else if(MODE == GET_TWEETS)
{
TweetDatabase tweetDb = new TweetDatabase(ui.get());
List<Tweet> tweets;
homeTl = (TimelineRecycler) profileTweets.getAdapter();
if(homeTl != null && homeTl.getItemCount() > 0) {
id = homeTl.getItemId(0);
homeTl.getData().insert(mTwitter.getUserTweets(userId,args[2],id),true);
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.store(tweets,TweetDatabase.TWEET, userId);
tweets.addAll(homeTl.getData());
} else {
TweetDatabase hTweets = new TweetDatabase(mTwitter.getUserTweets(userId,args[2],id),ui.get(),TweetDatabase.USER_TL,userId);
homeTl = new TimelineRecycler(hTweets,ui.get());
tweets = mTwitter.getUserTweets(userId,args[2],id);
tweetDb.store(tweets,TweetDatabase.TWEET, userId);
}
homeTl = new TimelineRecycler(tweets,ui.get());
homeTl.setColor(highlight,font);
}
else if(MODE == GET_FAVS)
{
TweetDatabase tweetDb = new TweetDatabase(ui.get());
List<Tweet> favorits;
homeFav = (TimelineRecycler) profileFavorits.getAdapter();
if(homeFav != null && homeFav.getItemCount() > 0) {
id = homeFav.getItemId(0);
homeFav.getData().insert(mTwitter.getUserFavs(userId,args[2],id),true);
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.store(favorits,TweetDatabase.FAVT, userId);
favorits.addAll(homeFav.getData());
} else {
TweetDatabase fTweets = new TweetDatabase(mTwitter.getUserFavs(userId,args[2],id),ui.get(),TweetDatabase.FAV_TL,userId);
homeFav = new TimelineRecycler(fTweets,ui.get());
favorits = mTwitter.getUserFavs(userId,args[2],id);
tweetDb.store(favorits,TweetDatabase.FAVT, userId);
}
homeFav = new TimelineRecycler(favorits,ui.get());
homeFav.setColor(highlight,font);
}
else if(MODE == ACTION_FOLLOW)
{
if(isFollowing)
if(isFollowing) {
isFollowing = mTwitter.toggleFollow(userId);
else
} else {
isFollowing = mTwitter.toggleFollow(userId);
}
}
else if(MODE == ACTION_MUTE)
{
if(muted)
if(muted) {
muted = mTwitter.toggleBlock(userId);
else
} else {
muted = mTwitter.toggleBlock(userId);
}
}
} catch(Exception err) {
err.printStackTrace();
return FAILURE;
@ -135,12 +155,10 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
@Override
protected void onPostExecute(Long mode) {
UserProfile connect = ui.get();
if(connect == null)
return;
final Context context = connect.getApplicationContext();
final Context context = connect;
TextView txtUser = (TextView)connect.findViewById(R.id.profile_username);
TextView txtScrName = (TextView)connect.findViewById(R.id.profile_screenname);
@ -151,7 +169,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
TextView txtFollowing = (TextView)connect.findViewById(R.id.following);
TextView txtFollower = (TextView)connect.findViewById(R.id.follower);
ImageView profile = (ImageView)connect.findViewById(R.id.profile_img);
ImageView banner = (ImageView)connect.findViewById(R.id.banner);
//ImageView banner = (ImageView)connect.findViewById(R.id.banner);
ImageView linkIcon = (ImageView)connect.findViewById(R.id.link_img);
ImageView verifier = (ImageView)connect.findViewById(R.id.profile_verify);
ImageView followback = (ImageView)connect.findViewById(R.id.followback);
@ -199,18 +217,12 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
else if(mode == GET_TWEETS)
{
if(profileTweets.getAdapter() == null)
profileTweets.setAdapter(homeTl);
else
homeTl.notifyDataSetChanged();
tweetsReload.setRefreshing(false);
}
else if(mode == GET_FAVS)
{
if(profileFavorits.getAdapter() == null)
profileFavorits.setAdapter(homeFav);
else
homeFav.notifyDataSetChanged();
favoritsReload.setRefreshing(false);
}
else if(mode == FAILURE)
@ -220,16 +232,17 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
favoritsReload.setRefreshing(false);
}
if(!isHome) {
if(isFollowing)
if(isFollowing) {
tool.getMenu().getItem(1).setIcon(R.drawable.follow_enabled);
else
} else {
tool.getMenu().getItem(1).setIcon(R.drawable.follow);
if(muted)
} if(muted) {
tool.getMenu().getItem(2).setIcon(R.drawable.block_enabled);
else
} else {
tool.getMenu().getItem(2).setIcon(R.drawable.block);
}
}
}
public interface OnProfileFinished {
void onLoaded();

View File

@ -21,18 +21,17 @@ import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import twitter4j.MediaEntity;
import twitter4j.TwitterException;
import twitter4j.User;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.TweetDetail;
import org.nuclearfog.twidda.backend.listitems.*;
public class StatusLoader extends AsyncTask<Long, Void, Long> {
@ -44,7 +43,6 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
public static final long LOAD_REPLY = 4;
private TwitterEngine mTwitter;
private List<twitter4j.Status> answers;
private TimelineRecycler tlAdp;
private RecyclerView replyList;
private Bitmap profile_btm;
@ -56,16 +54,17 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
private boolean rtFlag = false;
private long userReply, tweetReplyID;
private int rt, fav;
private int highlight;
private int highlight, font;
private WeakReference<TweetDetail> ui;
public StatusLoader(Context c) {
mTwitter = TwitterEngine.getInstance(c);
answers = new ArrayList<>();
SharedPreferences settings = c.getSharedPreferences("settings", 0);
toggleImg = settings.getBoolean("image_load", true);
highlight = ColorPreferences.getInstance(c).getColor(ColorPreferences.HIGHLIGHTING);
ColorPreferences mColor = ColorPreferences.getInstance(c);
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
font = mColor.getColor(ColorPreferences.FONT_COLOR);
ui = new WeakReference<>((TweetDetail)c);
replyList = (RecyclerView) ui.get().findViewById(R.id.answer_list);
@ -80,49 +79,40 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
long tweetID = data[0];
long mode = data[1];
try {
twitter4j.Status currentTweet = mTwitter.getStatus(tweetID);
twitter4j.Status embeddedTweet = currentTweet.getRetweetedStatus();
Tweet tweet = mTwitter.getStatus(tweetID);
Tweet embeddedTweet = tweet.embedded;
if(embeddedTweet != null) {
retweeter = "Retweet @"+currentTweet.getUser().getScreenName();
currentTweet = mTwitter.getStatus(embeddedTweet.getId());
tweetID = currentTweet.getId();
retweeter = "Retweet @"+tweet.screenname;
tweet = mTwitter.getStatus(embeddedTweet.tweetID);
tweetID = embeddedTweet.tweetID;
rtFlag = true;
}
rt = currentTweet.getRetweetCount();
fav = currentTweet.getFavoriteCount();
retweeted = currentTweet.isRetweetedByMe();
favorited = currentTweet.isFavorited();
User user = currentTweet.getUser();
rt = tweet.retweet;
fav = tweet.favorit;
retweeted = tweet.retweeted;
favorited = tweet.favorized;
if(mode == LOAD_TWEET) {
userReply = currentTweet.getInReplyToUserId();
tweetReplyID = currentTweet.getInReplyToStatusId();
tweetStr = currentTweet.getText();
verified = user.isVerified();
usernameStr = user.getName();
scrNameStr = '@'+user.getScreenName();
apiName = formatString(currentTweet.getSource());
dateString = DateFormat.getDateTimeInstance().format(currentTweet.getCreatedAt());
tweetReplyID = tweet.replyID;
verified = tweet.verified;
tweetStr = tweet.tweet;
usernameStr = tweet.username;
scrNameStr = '@'+tweet.screenname;
apiName = formatString(tweet.source);
dateString = DateFormat.getDateTimeInstance().format(new Date(tweet.time));
repliedUsername = tweet.replyName;
if(userReply > 0)
repliedUsername = currentTweet.getInReplyToScreenName();
if(toggleImg) {
String pbLink = user.getProfileImageURL();
String pbLink = tweet.profileImg;
InputStream iStream = new URL(pbLink).openStream();
profile_btm = BitmapFactory.decodeStream(iStream);
MediaEntity[] media = currentTweet.getMediaEntities();
medialinks = new String[media.length];
for(int i = 0 ; i < media.length ; i++) {
medialinks[i] = media[i].getMediaURL();
}
medialinks = tweet.media;
}
}
else if(mode == RETWEET) {
if(retweeted) {
mTwitter.retweet(tweetID, true);
TweetDatabase.delete(ui.get(), tweetID);
TweetDatabase.removeStatus(ui.get(), tweetID);
retweeted = false;
rt--;
} else {
@ -143,20 +133,27 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
}
}
else if(mode == LOAD_REPLY) {
String replyname = user.getScreenName();
List<Tweet> answers;
String replyname = tweet.screenname;
tlAdp = (TimelineRecycler) replyList.getAdapter();
if(tlAdp != null && tlAdp.getItemCount() > 0)
if(tlAdp != null && tlAdp.getItemCount() > 0) {
tweetID = tlAdp.getItemId(0);
answers = mTwitter.getAnswers(replyname, tweetID);
answers.addAll(tlAdp.getData());
} else {
answers = mTwitter.getAnswers(replyname, tweetID);
}
tlAdp = new TimelineRecycler(answers,ui.get());
tlAdp.setColor(highlight, font);
}
else if(mode == DELETE) {
mTwitter.deleteTweet(tweetID);
TweetDatabase.delete(ui.get(),tweetID);
TweetDatabase.removeStatus(ui.get(),tweetID);
}
}catch(TwitterException e) {
int err = e.getErrorCode();
if(err == 144) { // gelöscht
TweetDatabase.delete(ui.get(),tweetID);
TweetDatabase.removeStatus(ui.get(),tweetID);
errMSG = e.getMessage();
}
e.printStackTrace();
@ -170,12 +167,10 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
@Override
protected void onPostExecute(Long mode) {
TweetDetail connect = ui.get();
if(connect == null)
return;
final Context c = connect.getApplicationContext();
final Context c = connect;
TextView tweet = (TextView)connect.findViewById(R.id.tweet_detailed);
TextView username = (TextView)connect.findViewById(R.id.usernamedetail);
@ -252,15 +247,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> {
setIcons(favoriteButton, retweetButton);
}
else if(mode == LOAD_REPLY) {
if(tlAdp == null || tlAdp.getItemCount() == 0) {
TweetDatabase tweetDatabase = new TweetDatabase(answers,c);
tlAdp = new TimelineRecycler(tweetDatabase,(ui.get()));
replyList.setAdapter(tlAdp);
} else {
TweetDatabase twDb = tlAdp.getData();
twDb.insert(answers,false);
tlAdp.notifyDataSetChanged();
}
ansReload.setRefreshing(false);
String ansStr = Integer.toString(tlAdp.getItemCount());
txtAns.setText(ansStr);

View File

@ -1,5 +1,7 @@
package org.nuclearfog.twidda.backend;
import org.nuclearfog.twidda.backend.listitems.*;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
@ -10,7 +12,8 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import twitter4j.PagableResponseList;
import twitter4j.IDs;
import twitter4j.MediaEntity;
import twitter4j.Paging;
import twitter4j.Query;
import twitter4j.QueryResult;
@ -144,8 +147,8 @@ public class TwitterEngine {
* @return List of Tweets
* @throws TwitterException if access is unavailable
*/
public List<Status> getHome(int page, long lastId) throws TwitterException {
return twitter.getHomeTimeline(new Paging(page,load,lastId));
public List<Tweet> getHome(int page, long lastId) throws TwitterException {
return convertStatusList(twitter.getHomeTimeline(new Paging(page,load,lastId)));
}
@ -156,8 +159,8 @@ public class TwitterEngine {
* @return List of Mention Tweets
* @throws TwitterException if access is unavailable
*/
public List<Status> getMention(int page, long id) throws TwitterException {
return twitter.getMentionsTimeline(new Paging(page,load,id));
public List<Tweet> getMention(int page, long id) throws TwitterException {
return convertStatusList(twitter.getMentionsTimeline(new Paging(page,/*load*/5,id)));
}
@ -168,13 +171,13 @@ public class TwitterEngine {
* @return List of Tweets
* @throws TwitterException if acces is unavailable
*/
public List<Status> searchTweets(String search, long id) throws TwitterException {
public List<Tweet> searchTweets(String search, long id) throws TwitterException {
Query q = new Query();
q.setQuery(search+" +exclude:retweets");
q.setCount(load);
q.setSinceId(id);
QueryResult result = twitter.search(q);
return result.getTweets();
return convertStatusList(result.getTweets());
}
@ -195,8 +198,8 @@ public class TwitterEngine {
* @return List of Users
* @throws TwitterException if access is unavailable
*/
public List<User> searchUsers(String search) throws TwitterException {
return twitter.searchUsers(search, -1);
public List<TwitterUser> searchUsers(String search) throws TwitterException {
return convertUserList(twitter.searchUsers(search, -1));
}
/**
@ -206,8 +209,8 @@ public class TwitterEngine {
* @return List of User Tweets
* @throws TwitterException if access is unavailable
*/
public List<Status> getUserTweets(long userId, long page, long id) throws TwitterException {
return twitter.getUserTimeline(userId, new Paging((int)page,load, id));
public List<Tweet> getUserTweets(long userId, long page, long id) throws TwitterException {
return convertStatusList(twitter.getUserTimeline(userId, new Paging((int)page,load, id)));
}
/**
@ -217,8 +220,8 @@ public class TwitterEngine {
* @return List of User Favs
* @throws TwitterException if access is unavailable
*/
public List<Status> getUserFavs(long userId, long page, long id) throws TwitterException {
return twitter.getFavorites(userId,new Paging((int)page,load,id));
public List<Tweet> getUserFavs(long userId, long page, long id) throws TwitterException {
return convertStatusList(twitter.getFavorites(userId,new Paging((int)page,load,id)));
}
/**
@ -252,7 +255,7 @@ public class TwitterEngine {
* @throws TwitterException if Access is unavailable
*/
public boolean getBlocked(long id) throws TwitterException {
return twitter.showFriendship(twitter.getId(),id).isSourceMutingTarget();
return twitter.showFriendship(twitter.getId(),id).isSourceBlockingTarget();
}
@ -295,8 +298,9 @@ public class TwitterEngine {
* @return List of Following User
* @throws TwitterException if Access is unavailable
*/
public PagableResponseList<User> getFollowing(long id, long cursor) throws TwitterException {
return twitter.getFriendsList(id, cursor, load);
public List<TwitterUser> getFollowing(long id, long cursor) throws TwitterException {
IDs userIDs = twitter.getFriendsIDs(id,cursor,load);
return convertUserList(twitter.lookupUsers(userIDs.getIDs()));
}
/**
@ -305,8 +309,9 @@ public class TwitterEngine {
* @return List of Follower
* @throws TwitterException if Access is unavailable
*/
public PagableResponseList<User> getFollower(long id, long cursor) throws TwitterException {
return twitter.getFollowersList(id,cursor, load);
public List<TwitterUser> getFollower(long id, long cursor) throws TwitterException {
IDs userIDs = twitter.getFollowersIDs(id,cursor,load);
return convertUserList(twitter.lookupUsers(userIDs.getIDs()));
}
/**
@ -354,8 +359,15 @@ public class TwitterEngine {
* @return Tweet Object
* @throws TwitterException if Access is unavailable
*/
public Status getStatus(long id) throws TwitterException {
return twitter.showStatus(id);
public Tweet getStatus(long id) throws TwitterException {
Status status = twitter.showStatus(id);
Status retweet = status.getRetweetedStatus();
if(retweet != null ) {
Tweet embedded = getTweet(retweet,null);
return getTweet(status,embedded);
} else {
return getTweet(status,null);
}
}
/**
@ -365,7 +377,7 @@ public class TwitterEngine {
* @return List of Answers
* @throws TwitterException if Access is unavailable
*/
public List<Status> getAnswers(String name, long id) throws TwitterException {
public List<Tweet> getAnswers(String name, long id) throws TwitterException {
List<Status> answers = new ArrayList<>();
Query query = new Query("to:"+name+" since_id:"+id+" -filter:retweets");
query.setCount(load);
@ -376,7 +388,7 @@ public class TwitterEngine {
answers.add(reply);
}
}
return answers;
return convertStatusList(answers);
}
/**
@ -414,18 +426,71 @@ public class TwitterEngine {
* @return List of users or empty list if no match
* @throws TwitterException if Access is unavailable
*/
public List<User> getRetweeter(long tweetID, long cursor) throws TwitterException {
Status embeddedStat = getStatus(tweetID).getRetweetedStatus();
public List<TwitterUser> getRetweeter(long tweetID, long cursor) throws TwitterException {
Tweet embeddedStat = getStatus(tweetID).embedded;
if(embeddedStat != null)
tweetID = embeddedStat.getId();
long[] userIds = twitter.getRetweeterIds(tweetID,load,cursor).getIDs();
tweetID = embeddedStat.tweetID;
long[] userIds = twitter.getRetweeterIds(tweetID,load).getIDs();
if(userIds.length == 0) {
return new ArrayList<>();
} else {
return twitter.lookupUsers(userIds);
return convertUserList(twitter.lookupUsers(userIds));
}
}
/**
* convert #twitter4j.User to TwitterUser List
* @param users Twitter4J user List
* @return #TwitterEngine.TwitteUser
*/
private List<TwitterUser> convertUserList(List<User> users) {
List <TwitterUser> result = new ArrayList<>();
for(User user : users) {
TwitterUser item = new TwitterUser(user.getId(), user.getName(), user.getScreenName(),
user.getMiniProfileImageURL(),user.getDescription(), user.getLocation(),user.isVerified(),
user.isProtected(), user.getURL(), user.getProfileBannerURL());
result.add(item);
}
return result;
}
private List<Tweet> convertStatusList(List<Status> statuses) {
List<Tweet> result = new ArrayList<>();
for(Status status : statuses) {
Status embedded = status.getRetweetedStatus();
if(embedded != null) {
Tweet retweet = getTweet(embedded, null);
Tweet tweet = getTweet(status, retweet);
result.add(tweet);
} else {
Tweet tweet = getTweet(status, null);
result.add(tweet);
}
}
return result;
}
private Tweet getTweet(Status status, Tweet retweetedStat) {
User user = status.getUser();
return new Tweet(status.getId(), user.getId(), user.getName(), user.getScreenName(),
status.getRetweetCount(),status.getFavoriteCount(),user.getMiniProfileImageURL(),
status.getText(),status.getCreatedAt().getTime(), status.getInReplyToScreenName(),
getMediaLinks(status),status.getSource(), status.getInReplyToStatusId(), user.isVerified(),
retweetedStat, status.isRetweetedByMe(), status.isFavorited());
}
private String[] getMediaLinks(Status status) {
MediaEntity[] mediaEntities = status.getMediaEntities();
String medialinks[] = new String[mediaEntities.length];
byte i = 0;
for(MediaEntity media : mediaEntities) {
medialinks[i++] = media.getMediaURL();
}
return medialinks;
}
/**
* @param id Tweet ID
* @throws TwitterException if Access is unavailable

View File

@ -6,16 +6,17 @@ import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.SearchPage;
import org.nuclearfog.twidda.backend.listitems.*;
import java.lang.ref.WeakReference;
import java.util.List;
public class TwitterSearch extends AsyncTask<String, Void, Void> {
@ -24,7 +25,8 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
private RecyclerView tweetSearch, userSearch;
private TwitterEngine mTwitter;
private WeakReference<SearchPage> ui;
private int background, font_color;
private int background, highlight, font_color;
private String error;
public TwitterSearch(Context context) {
ui = new WeakReference<>((SearchPage)context);
@ -33,6 +35,7 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
mTwitter = TwitterEngine.getInstance(context);
ColorPreferences mcolor = ColorPreferences.getInstance(context);
background = mcolor.getColor(ColorPreferences.BACKGROUND);
highlight = mcolor.getColor(ColorPreferences.HIGHLIGHTING);
font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
}
@ -42,34 +45,45 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
long id = 1L;
try {
tlRc = (TimelineRecycler) tweetSearch.getAdapter();
if(tlRc != null) {
uAdp = (UserRecycler) userSearch.getAdapter();
if(tlRc != null && tlRc.getItemCount() > 0) {
id = tlRc.getItemId(0);
tlRc.getData().insert(mTwitter.searchTweets(strSearch,id),false);
List<Tweet> tweets = mTwitter.searchTweets(strSearch,id);
tweets.addAll(tlRc.getData());
tlRc = new TimelineRecycler(tweets,ui.get());
} else {
tlRc = new TimelineRecycler(new TweetDatabase(mTwitter.searchTweets(strSearch,id),ui.get()),ui.get());
tlRc.setColor(background,font_color);
List<Tweet> tweets = mTwitter.searchTweets(strSearch,id);
tlRc = new TimelineRecycler(tweets,ui.get());
}
if(uAdp == null ||uAdp.getItemCount() == 0) {
List<TwitterUser> user = mTwitter.searchUsers(strSearch);
uAdp = new UserRecycler(user, ui.get());
}
tlRc.setColor(highlight,font_color);
uAdp.setColor(background,font_color);
} catch(Exception err) {
error = err.getMessage();
}
uAdp = new UserRecycler(new UserDatabase(ui.get(), mTwitter.searchUsers(strSearch)),ui.get());
} catch(Exception err){err.printStackTrace();}
return null;
}
@Override
protected void onPostExecute(Void v) {
SearchPage connect = ui.get();
if(connect == null)
return;
if(error != null)
Toast.makeText(connect, "Fehler beim Laden: "+error, Toast.LENGTH_LONG).show();
SwipeRefreshLayout tweetReload = (SwipeRefreshLayout)connect.findViewById(R.id.searchtweets);
ProgressBar circleLoad = (ProgressBar)connect.findViewById(R.id.search_progress);
circleLoad.setVisibility(View.INVISIBLE);
if(tweetSearch.getAdapter() == null) {
tweetSearch.setAdapter(tlRc);
} else {
tlRc.notifyDataSetChanged();
}
userSearch.setAdapter(uAdp);
tweetReload.setRefreshing(false);
}

View File

@ -7,12 +7,13 @@ import android.view.View;
import android.widget.ProgressBar;
import android.widget.Toast;
import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
import org.nuclearfog.twidda.window.UserDetail;
import org.nuclearfog.twidda.backend.listitems.*;
import java.lang.ref.WeakReference;
import java.util.List;
public class UserLists extends AsyncTask <Long, Void, Void> {
@ -48,28 +49,16 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
try {
usrAdp = (UserRecycler) userList.getAdapter();
if(mode == FOLLOWING) {
if(usrAdp == null) {
UserDatabase udb = new UserDatabase(ui.get(),mTwitter.getFollowing(id,cursor));
usrAdp = new UserRecycler(udb,ui.get());
} else {
UserDatabase uDb = usrAdp.getData();
uDb.addLast(mTwitter.getFollowing(id,cursor));
usrAdp.notifyDataSetChanged();
}
List<TwitterUser> user = mTwitter.getFollowing(id,cursor);
usrAdp = new UserRecycler(user,ui.get());
}
else if(mode == FOLLOWERS) {
if(usrAdp == null) {
UserDatabase udb = new UserDatabase(ui.get(),mTwitter.getFollower(id,cursor));
usrAdp = new UserRecycler(udb,ui.get());
} else {
UserDatabase uDb = usrAdp.getData();
uDb.addLast(mTwitter.getFollower(id,cursor));
usrAdp.notifyDataSetChanged();
}
List<TwitterUser> user = mTwitter.getFollower(id,cursor);
usrAdp = new UserRecycler(user,ui.get());
}
else if(mode == RETWEETER) {
UserDatabase udb = new UserDatabase(ui.get(),mTwitter.getRetweeter(id,cursor));
usrAdp = new UserRecycler(udb,ui.get());
List<TwitterUser> user = mTwitter.getRetweeter(id,cursor);
usrAdp = new UserRecycler(user,ui.get());
}
/*else if(mode == FAVORISER) {
// GET FAV USERS TODO

View File

@ -0,0 +1,33 @@
package org.nuclearfog.twidda.backend.listitems;
public class Tweet {
public final long tweetID, userID;
public final Tweet embedded;
public final String username, screenname, profileImg, tweet, replyName,source;
public final long time, replyID;
public final int retweet, favorit;
public final boolean verified, retweeted, favorized;
public final String[] media;
public Tweet(long tweetID, long userID, String username, String screenname, int retweet, int favorit,
String profileImg, String tweet, long time, String replyName, String[] media, String source,
long replyID, boolean verified, Tweet embedded, boolean retweeted, boolean favorized) {
this.tweetID = tweetID;
this.userID = userID;
this.username = username;
this.screenname = screenname;
this.profileImg = profileImg;
this.retweet = retweet;
this.favorit = favorit;
this.tweet = tweet;
this.time = time;
this.replyID = replyID;
this.verified = verified;
this.embedded = embedded;
this.favorized = favorized;
this.retweeted = retweeted;
this.replyName = replyName;
this.media = media;
this.source = source;
}
}

View File

@ -0,0 +1,24 @@
package org.nuclearfog.twidda.backend.listitems;
public class TwitterUser {
public final String username,screenname,bio;
public final String profileImg,bannerImg;
public final String location,link;
public final boolean isVerified,isLocked;
public final long userID;
public TwitterUser(long userID, String username, String screenname, String profileImg,
String bio, String location, boolean isVerified, boolean isLocked,
String link, String bannerImg) {
this.userID = userID;
this.username = username;
this.screenname = screenname;
this.profileImg = profileImg;
this.bio = bio;
this.link = link;
this.location = location;
this.bannerImg = bannerImg;
this.isVerified = isVerified;
this.isLocked = isLocked;
}
}

View File

@ -9,12 +9,12 @@ public class AppDatabase extends SQLiteOpenHelper
private static final String userTable = "CREATE TABLE IF NOT EXISTS user ("+
"userID INTEGER PRIMARY KEY, username TEXT," +
"scrname TEXT, pbLink TEXT, banner TEXT, bio TEXT,"+
"location TEXT, link TEXT, verify INTEGER);";
"location TEXT, link TEXT, verify INTEGER, locked INTEGER);";
private static final String tweetTable = "CREATE TABLE IF NOT EXISTS tweet (" +
"tweetID INTEGER PRIMARY KEY, userID INTEGER, retweetID INTEGER," +
"time INTEGER, tweet TEXT, retweet INTEGER, favorite INTEGER," +
"FOREIGN KEY (userID) REFERENCES user(userID));";
"tweetID INTEGER PRIMARY KEY, userID INTEGER, retweetID INTEGER, replyID INTEGER," +
"replyname TEXT, time INTEGER, tweet TEXT, retweet INTEGER, favorite 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," +

View File

@ -1,151 +1,57 @@
package org.nuclearfog.twidda.database;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.backend.listitems.*;
import android.content.ContentValues;
import android.content.Context;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import twitter4j.Status;
import twitter4j.User;
public class TweetDatabase {
public static final int HOME_TL = 0;
public static final int FAV_TL = 1;
public static final int USER_TL = 2;
public static final int GET_MENT = 4;
public static final int FAVT = 1;
public static final int TWEET = 2;
public static final int HOME = 3;
public static final int MENT = 4;
private AppDatabase dataHelper;
private List<String> user,scrname,tweet,pbLink;
private List<Long> userId,tweetId,timeMillis, retweetId;
private List<Integer> noRT,noFav, verify;
private boolean toggleImg;
private int limit;
private int size = 0;
private int mode = 0;
private long CurrentId = 0;
private List<Tweet> tweetlist;
/**
* Store & Read Data
* @param stats Twitter Status
* @param context Current Activity's Context
* @param mode which type of data should be stored
* @param CurrentId current User ID
* @see #HOME_TL#FAV_TL#USER_TL
*/
public TweetDatabase(List<Status> stats, Context context, final int mode,long CurrentId) {
this.CurrentId = CurrentId;
this.mode = mode;
initialize(context);
store(stats);
load();
public TweetDatabase(Context context) {
dataHelper = AppDatabase.getInstance(context);
tweetlist = new ArrayList<>();
}
/**
* Read Data
* @param context MainActivity Context
* @param mode {@link #FAV_TL #GET_MENT}
* @param CurrentId current ID (USER OR TWEET)
*/
public TweetDatabase(Context context, final int mode, long CurrentId) {
this.CurrentId = CurrentId;
this.mode = mode;
initialize(context);
load();
}
/**
* this Constructor is used by twitter search
* no need to store in SQLITE
* @param stats SearchWindow Result Tweets
*/
public TweetDatabase(List<Status> stats, Context context) {
initialize(context);
add(stats);
}
/**
* Add new Elements to the List
* @param stats List of Tweets
* @param store if True, data will be stored in SQL
*/
public void insert(List<Status> stats, boolean store) {
if(store)
store(stats);
addFirst(stats);
}
/**
* Remove Tweet from Database
* @param c Current Context
* @param id Tweet ID
*/
public static void delete(Context c, long id) {
SQLiteDatabase db = AppDatabase.getInstance(c).getWritableDatabase();
db.delete("tweet", "tweetID"+"="+id, null);
db.close();
}
private void store(List<Status> stats) {
public void store(List<Tweet> stats, int mode, long id) {
SQLiteDatabase db = dataHelper.getWritableDatabase();
ContentValues user = new ContentValues();
ContentValues tweet = new ContentValues();
ContentValues home = new ContentValues();
ContentValues fav = new ContentValues();
ContentValues ment = new ContentValues();
for(int pos = 0; pos < stats.size(); pos++) {
Status stat = stats.get(pos);
User usr = stat.getUser();
Status rtStat = stat.getRetweetedStatus();
Tweet tweet = stats.get(pos);
Tweet rtStat = tweet.embedded;
if(rtStat != null) {
tweet.put("retweeter",usr.getScreenName());
stat = rtStat;
usr = rtStat.getUser();
storeStatus(rtStat, db,-1L);
storeStatus(tweet, db, rtStat.tweetID);
} else {
tweet.put("retweeter","\t");
storeStatus(tweet, db, -1L);
}
user.put("userID",usr.getId());
user.put("username", usr.getName());
user.put("scrname",'@'+usr.getScreenName());
user.put("pbLink", usr.getMiniProfileImageURL());
user.put("banner", usr.getProfileBannerURL());
user.put("bio",usr.getDescription());
user.put("location",usr.getLocation());
user.put("link",usr.getURL());
user.put("verify", usr.isVerified() ? 1 : 0);
tweet.put("userID", usr.getId());
tweet.put("tweetID", stat.getId());
tweet.put("time", stat.getCreatedAt().getTime());
tweet.put("tweet", stat.getText());
tweet.put("retweet", stat.getRetweetCount());
tweet.put("favorite", stat.getFavoriteCount());
home.put("tweetID", stat.getId());
fav.put("tweetID", stat.getId());
fav.put("userID", CurrentId);
ment.put("mTweetID",stat.getId());
db.insertWithOnConflict("user",null, user,SQLiteDatabase.CONFLICT_IGNORE);
db.insertWithOnConflict("tweet",null, tweet,SQLiteDatabase.CONFLICT_REPLACE);
if(mode!=USER_TL) {
if(mode == HOME_TL) {
if(mode != TWEET) {
if(mode == HOME) {
home.put("tweetID", tweet.tweetID);
db.insertWithOnConflict("timeline",null,home,SQLiteDatabase.CONFLICT_REPLACE);
} else if(mode == FAV_TL) {
} else if(mode == FAVT) {
fav.put("tweetID", tweet.tweetID);
fav.put("userID", id);
db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_REPLACE);
} else if(mode == GET_MENT) {
} else if(mode == MENT) {
ment.put("mTweetID", tweet.tweetID);
db.insertWithOnConflict("timeline",null,ment,SQLiteDatabase.CONFLICT_IGNORE);
}
}
@ -153,220 +59,129 @@ public class TweetDatabase {
db.close();
}
private void load() {
public List<Tweet> load(int mode, long id) {
SQLiteDatabase db = dataHelper.getReadableDatabase();
int index;
size = 0;
String SQL_GET_HOME=" ";
if(mode==HOME_TL) {
if(mode == HOME) {
SQL_GET_HOME = "SELECT * FROM timeline " +
"INNER JOIN tweet ON timeline.tweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID=user.userID ORDER BY tweetID DESC";
} else if(mode==GET_MENT) {
} else if(mode == MENT) {
SQL_GET_HOME = "SELECT * FROM timeline " +
"INNER JOIN tweet ON timeline.mTweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID=user.userID ORDER BY tweetID ASC";
limit = 5;
}
else if(mode==USER_TL) {
else if(mode == TWEET) {
SQL_GET_HOME = "SELECT * FROM user " +
"INNER JOIN tweet ON tweet.userID = user.userID"+
" WHERE user.userID = "+CurrentId+ " ORDER BY tweetID DESC";
} else if(mode==FAV_TL) {
" WHERE user.userID = "+id+ " ORDER BY tweetID DESC";
} else if(mode == FAVT) {
SQL_GET_HOME = "SELECT * FROM favorit " +
"INNER JOIN tweet ON favorit.tweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID = user.userID " +
"WHERE favorit.userID = "+CurrentId+" ORDER BY tweetID DESC";
"WHERE favorit.userID = "+id+" ORDER BY tweetID DESC";
}
Cursor cursor = db.rawQuery(SQL_GET_HOME,null);
if(cursor.moveToFirst()) {
do {
index = cursor.getColumnIndex("time");
timeMillis.add(cursor.getLong(index));
index = cursor.getColumnIndex("tweet");
tweet.add( cursor.getString(index));
index = cursor.getColumnIndex("retweet");
noRT.add( cursor.getInt(index));
index = cursor.getColumnIndex("favorite");
noFav.add( cursor.getInt(index));
index = cursor.getColumnIndex("username");
user.add(cursor.getString(index));
index = cursor.getColumnIndex("scrname");
scrname.add(cursor.getString(index));
index = cursor.getColumnIndex("verify");
verify.add(cursor.getInt(index));
index = cursor.getColumnIndex("pbLink");
pbLink.add(cursor.getString(index));
index = cursor.getColumnIndex("userID");
userId.add(cursor.getLong(index));
index = cursor.getColumnIndex("tweetID");
tweetId.add(cursor.getLong(index));
// index = cursor.getColumnIndex("retweetID");
//retweetId.add(cursor.getLong(index));
size++;
} while(cursor.moveToNext() && size < limit);
Tweet tweet = getTweet(cursor);
/* if(tweet.embedded != null)
tweetlist.add(tweet.embedded);
else*/
tweetlist.add(tweet);
} while(cursor.moveToNext());
}
cursor.close();
db.close();
return tweetlist;
}
public int getSize() {
return size;
}
public int getRetweet(int pos){return noRT.get(pos);}
public int getFavorite(int pos){return noFav.get(pos);}
public long getUserID(int pos){return userId.get(pos);}
public long getTweetId(int pos){return tweetId.get(pos);}
public long getTime(int pos){return timeMillis.get(pos);}
public String getUsername(int pos){return user.get(pos);}
public String getScreenname(int pos){return scrname.get(pos);}
public String getTweet(int pos){return tweet.get(pos);}
public String getDate(int pos){return timeToString(getTime(pos));}
public String getPbLink(int pos){return pbLink.get(pos);}
public boolean loadImages(){return toggleImg;}
public boolean isVerified(int pos){return verify.get(pos) == 1;}
public SpannableStringBuilder getHighlightedTweet(Context c, int pos) {
String tweet = getTweet(pos);
int highlight = ColorPreferences.getInstance(c).getColor(ColorPreferences.HIGHLIGHTING);
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
int start = 0;
boolean marked = false;
for(int i = 0 ; i < tweet.length() ; i++) {
char current = tweet.charAt(i);
switch(current){
case '@':
start = i;
marked = true;
break;
case '#':
start = i;
marked = true;
break;
case '\'':
case '\"':
case '\n':
case ')':
case '(':
case ':':
case ' ':
case '.':
case ',':
case '!':
case '?':
case '-':
if(marked)
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
marked = false;
break;
}
if(i == tweet.length()-1 && marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return sTweet;
private Tweet searchTweet(long tweetId) {
SQLiteDatabase search = dataHelper.getReadableDatabase();
Tweet result = null;
String query = "SELECT * FROM tweet " +
"INNER JOIN user ON user.userID = tweet.userID " +
"WHERE tweet.tweetID == " + tweetId;
Cursor cursor = search.rawQuery(query,null);
if(cursor.moveToFirst())
result = getTweet(cursor);
cursor.close();
return result;
}
/**
* Convert Time to String
* @param mills TweetDetail Time
* @return Formatted String
*/
private String timeToString(long mills) {
Calendar now = Calendar.getInstance();
long diff = now.getTimeInMillis() - mills;
long seconds = diff / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
long weeks = days / 7;
if(weeks > 4) {
Date tweetDate = new Date(mills);
return new SimpleDateFormat("dd.MM.yyyy").format(tweetDate);
private Tweet getTweet(Cursor cursor){
int index = cursor.getColumnIndex("time");
long time = cursor.getLong(index);
index = cursor.getColumnIndex("tweet");
String tweettext = cursor.getString(index);
index = cursor.getColumnIndex("retweet");
int retweet = cursor.getInt(index);
index = cursor.getColumnIndex("favorite");
int favorit = cursor.getInt(index);
index = cursor.getColumnIndex("username");
String username = cursor.getString(index);
index = cursor.getColumnIndex("scrname");
String screenname = cursor.getString(index);
index = cursor.getColumnIndex("verify");
boolean isVerified = cursor.getInt(index) == 1;
index = cursor.getColumnIndex("pbLink");
String profileImg = cursor.getString(index);
index = cursor.getColumnIndex("userID");
long userId = cursor.getLong(index);
index = cursor.getColumnIndex("tweetID");
long tweetId = cursor.getLong(index);
index = cursor.getColumnIndex("retweetID");
long retweetId = cursor.getLong(index);
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);
Tweet embeddedTweet = null;
if(retweetId > 0) {
embeddedTweet = searchTweet(retweetId);
}
if(weeks > 0)
return "vor "+weeks+" w";
if(days > 0)
return "vor "+days+" d";
if(hours > 0)
return "vor "+hours+" h";
if(minutes > 0)
return "vor "+minutes+" m";
else
return "vor "+seconds+" s";
return new Tweet(tweetId,userId,username,screenname,retweet,favorit,
profileImg,tweettext, time, replyname, null, source, replyStatusId,
isVerified,embeddedTweet,false,false);
}
private void initialize(Context c) {
dataHelper = AppDatabase.getInstance(c);
SharedPreferences settings = c.getSharedPreferences("settings", 0);
limit = settings.getInt("limit", 200);
toggleImg = settings.getBoolean("image_load", true);
initArray();
private void storeStatus(Tweet tweet, SQLiteDatabase db, long retweetID) {
ContentValues status = new ContentValues();
ContentValues user = new ContentValues();
status.put("userID", tweet.userID);
status.put("tweetID", tweet.tweetID);
status.put("time", tweet.time);
status.put("tweet", tweet.tweet);
status.put("retweet", tweet.retweet);
status.put("favorite", tweet.favorit);
status.put("retweetID", retweetID);
status.put("source", tweet.source);
status.put("replyID", tweet.replyID);
status.put("replyname", tweet.replyName);
user.put("userID", tweet.userID);
user.put("username", tweet.username);
user.put("scrname", tweet.screenname);
user.put("pbLink", tweet.profileImg);
user.put("verify", tweet.verified);
db.insertWithOnConflict("tweet",null, status,SQLiteDatabase.CONFLICT_REPLACE);
db.insertWithOnConflict("user",null, user,SQLiteDatabase.CONFLICT_REPLACE);
}
private void add(List<Status> stats) {
for(Status stat: stats) {
Status rtStat = stat.getRetweetedStatus();
User usr = stat.getUser();
tweetId.add(stat.getId());
if(rtStat != null) {
stat = rtStat;
usr = rtStat.getUser();
}
user.add(usr.getName());
scrname.add('@'+usr.getScreenName());
tweet.add(stat.getText());
noRT.add(stat.getRetweetCount());
noFav.add(stat.getFavoriteCount());
userId.add(usr.getId());
pbLink.add(usr.getMiniProfileImageURL());
verify.add(usr.isVerified() ? 1 : 0);
timeMillis.add(stat.getCreatedAt().getTime());
size++;
}
}
private void addFirst(List<Status> stats) {
for(int index = stats.size()-1 ; index >= 0 ; index--) {
Status stat = stats.get(index);
Status rtStat = stat.getRetweetedStatus();
User usr = stat.getUser();
tweetId.add(0,stat.getId());
if(rtStat != null) {
// retweetId.add(usr.getScreenName());
stat = rtStat;
usr = rtStat.getUser();
}
user.add(0,usr.getName());
scrname.add(0,'@'+usr.getScreenName());
tweet.add(0,stat.getText());
noRT.add(0,stat.getRetweetCount());
noFav.add(0,stat.getFavoriteCount());
userId.add(0,usr.getId());
pbLink.add(0,usr.getMiniProfileImageURL());
verify.add(0,usr.isVerified() ? 1 : 0);
timeMillis.add(0,stat.getCreatedAt().getTime());
size++;
}
}
private void initArray() {
user = new ArrayList<>();
scrname = new ArrayList<>();
tweet = new ArrayList<>();
noRT = new ArrayList<>();
noFav = new ArrayList<>();
userId = new ArrayList<>();
pbLink = new ArrayList<>();
tweetId = new ArrayList<>();
verify = new ArrayList<>();
retweetId = new ArrayList<>();
timeMillis = new ArrayList<>();
public static void removeStatus(Context c, long id) {
SQLiteDatabase db = AppDatabase.getInstance(c).getWritableDatabase();
db.delete("tweet", "tweetID"+"="+id, null);
db.close();
}
}

View File

@ -2,6 +2,9 @@ package org.nuclearfog.twidda.viewadapter;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.Adapter;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,43 +14,50 @@ import android.support.v7.widget.RecyclerView.ViewHolder;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.backend.listitems.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> implements View.OnClickListener {
private TweetDatabase mTweets;
private ViewGroup parent;
private OnItemClicked mListener;
private int background = 0x00000000;
private List<Tweet> tweets;
private int highlight = 0xFFFFFFFF;
private int font_color = 0xFFFFFFFF;
/**
* @param mListener Item Click Listener
*/
public TimelineRecycler(TweetDatabase mTweets, OnItemClicked mListener) {
public TimelineRecycler(List<Tweet> tweets, OnItemClicked mListener) {
this.tweets = tweets;
this.mListener = mListener;
this.mTweets = mTweets;
}
public void setColor(int background, int font_color) {
this.background = background;
public void setColor(int highlight, int font_color) {
this.highlight = highlight;
this.font_color = font_color;
}
public TweetDatabase getData() {
return mTweets;
public List<Tweet> getData() {
return tweets;
}
@Override
public int getItemCount(){
return mTweets.getSize();
return tweets.size();
}
@Override
public long getItemId(int pos){
return mTweets.getTweetId(pos);
return tweets.get(pos).tweetID;
}
@ -55,7 +65,6 @@ public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> imple
public ItemHolder onCreateViewHolder(ViewGroup parent, int index) {
this.parent = parent;
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.tweet, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
return new ItemHolder(v);
}
@ -63,17 +72,20 @@ public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> imple
@Override
public void onBindViewHolder(ItemHolder vh, int index) {
Tweet tweet = tweets.get(index);
String retweet = Integer.toString(tweet.retweet);
String favorit = Integer.toString(tweet.favorit);
vh.tweet.setTextColor(font_color);
vh.username.setText(mTweets.getUsername(index));
vh.screenname.setText(mTweets.getScreenname(index));
vh.tweet.setText(mTweets.getHighlightedTweet(parent.getContext(),index));
vh.retweet.setText(Integer.toString(mTweets.getRetweet(index)));
vh.favorite.setText(Integer.toString(mTweets.getFavorite(index)));
vh.time.setText(mTweets.getDate(index));
if(mTweets.loadImages()) {
Picasso.with(parent.getContext()).load(mTweets.getPbLink(index)).into(vh.profile);
vh.username.setText(tweet.username);
vh.screenname.setText(tweet.screenname);
vh.tweet.setText(highlight(tweet.tweet));
vh.retweet.setText(retweet);
vh.favorite.setText(favorit);
vh.time.setText(stringTime(tweet.time));
if(tweet.profileImg != null) {
Picasso.with(parent.getContext()).load(tweet.profileImg).into(vh.profile);
}
if(mTweets.isVerified(index)) {
if(tweet.verified) {
vh.verify.setVisibility(View.VISIBLE);
} else {
vh.verify.setVisibility(View.INVISIBLE);
@ -90,6 +102,72 @@ public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> imple
}
private String stringTime(long mills) {
Calendar now = Calendar.getInstance();
long diff = now.getTimeInMillis() - mills;
long seconds = diff / 1000;
long minutes = seconds / 60;
long hours = minutes / 60;
long days = hours / 24;
long weeks = days / 7;
if(weeks > 4) {
Date tweetDate = new Date(mills);
return SimpleDateFormat.getDateInstance().format(tweetDate);
}
if(weeks > 0)
return "vor "+weeks+" w";
if(days > 0)
return "vor "+days+" d";
if(hours > 0)
return "vor "+hours+" h";
if(minutes > 0)
return "vor "+minutes+" m";
else
return "vor "+seconds+" s";
}
public SpannableStringBuilder highlight(String tweet) {
SpannableStringBuilder sTweet = new SpannableStringBuilder(tweet);
int start = 0;
boolean marked = false;
for(int i = 0 ; i < tweet.length() ; i++) {
char current = tweet.charAt(i);
switch(current){
case '@':
start = i;
marked = true;
break;
case '#':
start = i;
marked = true;
break;
case '\'':
case '\"':
case '\n':
case ')':
case '(':
case ':':
case ' ':
case '.':
case ',':
case '!':
case '?':
case '-':
if(marked)
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
marked = false;
break;
}
if(i == tweet.length()-1 && marked) {
sTweet.setSpan(new ForegroundColorSpan(highlight),start,i+1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return sTweet;
}
class ItemHolder extends ViewHolder {
public TextView username, screenname, tweet, retweet;
public TextView favorite, retweeter, time;

View File

@ -1,5 +1,8 @@
package org.nuclearfog.twidda.viewadapter;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.listitems.*;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
@ -7,35 +10,41 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import java.util.List;
import com.squareup.picasso.Picasso;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.UserDatabase;
public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder> implements View.OnClickListener {
private UserDatabase mUser;
private List<TwitterUser> mUser;
private OnItemClicked mListener;
private ViewGroup parent;
private int background = 0x00000000;
private int font_color = 0xFFFFFFFF;
public UserRecycler(UserDatabase mUser, OnItemClicked mListener) {
public UserRecycler(List<TwitterUser> mUser, OnItemClicked mListener) {
this.mListener = mListener;
this.mUser = mUser;
}
public UserDatabase getData(){return mUser; }
public List<TwitterUser> getData(){return mUser; }
public void setColor(int background, int font_color) {
this.background = background;
this.font_color = font_color;
}
@Override
public int getItemCount(){
return mUser.getSize();
return mUser.size();
}
@Override
public long getItemId(int pos){
return mUser.getUserID(pos);
return mUser.get(pos).userID;
}
@ -43,29 +52,33 @@ public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder>
public ItemHolder onCreateViewHolder(ViewGroup parent, int index) {
this.parent = parent;
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.useritem, parent,false);
v.setBackgroundColor(background);
v.setOnClickListener(this);
return new ItemHolder(v);
}
@Override
public void onBindViewHolder(ItemHolder vh, int index) {
vh.screenname.setText(mUser.getScreenname(index));
vh.username.setText(mUser.getUsername(index));
if(mUser.loadImages()) {
Picasso.with(parent.getContext()).load(mUser.getImageUrl(index)).into(vh.profileImg);
TwitterUser user = mUser.get(index);
vh.screenname.setText(user.screenname);
vh.username.setText(user.username);
if(user.profileImg != null) {
Picasso.with(parent.getContext()).load(user.profileImg).into(vh.profileImg);
}
if(mUser.isVerified(index)) {
if(user.isVerified) {
vh.verifyIco.setVisibility(View.VISIBLE);
} else {
vh.verifyIco.setVisibility(View.INVISIBLE);
}
if(mUser.isLocked(index)) {
if(user.isLocked) {
vh.lockIco.setVisibility(View.VISIBLE);
} else {
vh.lockIco.setVisibility(View.INVISIBLE);
}
}
@Override
public void onClick(View view) {
ViewGroup p = UserRecycler.this.parent;
@ -74,6 +87,7 @@ public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder>
mListener.onItemClick(view, p, position);
}
class ItemHolder extends ViewHolder {
ImageView profileImg, verifyIco, lockIco;
TextView username, screenname;
@ -87,6 +101,7 @@ public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder>
}
}
public interface OnItemClicked {
void onItemClick(View v, ViewGroup parent, int position);
}

View File

@ -16,8 +16,7 @@ import android.widget.ProgressBar;
import android.widget.TabHost;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import org.nuclearfog.twidda.backend.TwitterSearch;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
@ -39,14 +38,17 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
super.onCreate(b);
setContentView(R.layout.search);
getExtras(getIntent().getExtras());
int background = ColorPreferences.getInstance(this).getColor(ColorPreferences.BACKGROUND);
Toolbar tool = (Toolbar) findViewById(R.id.search_toolbar);
tweetSearch = (RecyclerView) findViewById(R.id.tweet_result);
userSearch = (RecyclerView) findViewById(R.id.user_result);
tweetReload = (SwipeRefreshLayout) findViewById(R.id.searchtweets);
tweetSearch.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
userSearch.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
tweetSearch.setBackgroundColor(background);
userSearch.setBackgroundColor(background);
setSupportActionBar(tool);
if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false);
@ -121,10 +123,10 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
case R.id.tweet_result:
if(!tweetReload.isRefreshing()) {
TimelineRecycler tlAdp = (TimelineRecycler) tweetSearch.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Tweet tweet = tlAdp.getData().get(position);
long tweetID = tweet.tweetID;
long userID = tweet.userID;
String username = tweet.screenname;
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
@ -136,10 +138,10 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
break;
case R.id.user_result:
UserRecycler uAdp = (UserRecycler) userSearch.getAdapter();
UserDatabase uDb = uAdp.getData();
TwitterUser user = uAdp.getData().get(position);
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
long userID = uDb.getUserID(position);
long userID = user.userID;
bundle.putLong("userID",userID);
profile.putExtras(bundle);
startActivity(profile);
@ -163,7 +165,6 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
tab1.setContent(R.id.searchtweets);
tab1.setIndicator("",getResources().getDrawable(R.drawable.search));
tabhost.addTab(tab1);
TabHost.TabSpec tab2 = tabhost.newTabSpec("user_result");
tab2.setContent(R.id.user_result);
tab2.setIndicator("",getResources().getDrawable(R.drawable.user));

View File

@ -12,17 +12,15 @@ import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import static android.content.DialogInterface.*;
import org.nuclearfog.twidda.backend.StatusLoader;
import org.nuclearfog.twidda.backend.TwitterEngine;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
@ -99,7 +97,7 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
case R.id.answer_button:
intent = new Intent(getApplicationContext(), TweetPopup.class);
bundle.putLong("TweetID", tweetID);
bundle.putString("Addition", username);
bundle.putString("Addition", '@'+username);
intent.putExtras(bundle);
startActivity(intent);
break;
@ -161,9 +159,9 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
@Override
public void onItemClick(View view, ViewGroup parent, int position) {
TimelineRecycler tlAdp = (TimelineRecycler) answer_list.getAdapter();
TweetDatabase twDB = tlAdp.getData();
long userID = twDB.getUserID(position);
long tweetID = twDB.getTweetId(position);
Tweet tweet = tlAdp.getData().get(position);
long userID = tweet.userID;
long tweetID = tweet.tweetID;
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userID);

View File

@ -12,7 +12,7 @@ import android.view.View;
import android.view.ViewGroup;
import org.nuclearfog.twidda.backend.UserLists;
import org.nuclearfog.twidda.database.UserDatabase;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
@ -73,9 +73,9 @@ public class UserDetail extends AppCompatActivity implements UserRecycler.OnItem
@Override
public void onItemClick(View view, ViewGroup parent, int position) {
UserRecycler uAdp = (UserRecycler) userListview.getAdapter();
UserDatabase uDB = uAdp.getData();
long userID = uDB.getUserID(position);
String username = uDB.getScreenname(position);
TwitterUser user = uAdp.getData().get(position);
long userID = user.userID;
String username = user.screenname;
Intent intent = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userID);

View File

@ -16,11 +16,13 @@ import android.widget.TabHost;
import android.widget.TextView;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.StatusLoader;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.database.TweetDatabase;
import org.nuclearfog.twidda.backend.ProfileLoader;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import java.util.List;
/**
* User Profile Class uses AsyncTask
* @see ProfileLoader
@ -162,10 +164,12 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
} else {
tlAdp = (TimelineRecycler) homeFavorits.getAdapter();
}
TweetDatabase twDB = tlAdp.getData();
long tweetID = twDB.getTweetId(position);
long userID = twDB.getUserID(position);
String username = twDB.getScreenname(position);
Tweet tweet = tlAdp.getData().get(position);
if(tweet.embedded != null)
tweet = tweet.embedded;
long tweetID = tweet.tweetID;
long userID = tweet.userID;
String username = tweet.screenname;
Intent intent = new Intent(getApplicationContext(), TweetDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("tweetID",tweetID);
@ -198,24 +202,29 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
@Override
public void run() {
ColorPreferences mcolor = ColorPreferences.getInstance(getApplicationContext());
int highlight = mcolor.getColor(ColorPreferences.HIGHLIGHTING);
int background = mcolor.getColor(ColorPreferences.BACKGROUND);
int font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
TweetDatabase mTweet = new TweetDatabase(UserProfile.this, TweetDatabase.USER_TL, userId);
TweetDatabase fTweet = new TweetDatabase(UserProfile.this, TweetDatabase.FAV_TL, userId);
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);
mTweets = new ProfileLoader(UserProfile.this);
mFavorits = new ProfileLoader(UserProfile.this);
if( mTweet.getSize() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(mTweet,UserProfile.this);
tlRc.setColor(background,font_color);
homeTweets.setBackgroundColor(background);
homeFavorits.setBackgroundColor(background);
if( userTweets.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userTweets,UserProfile.this);
tlRc.setColor(highlight,font_color);
homeTweets.setAdapter(tlRc);
} else {
mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L);
}
if( fTweet.getSize() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(fTweet,UserProfile.this);
tlRc.setColor(background,font_color);
if( userFavorit.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userFavorit,UserProfile.this);
tlRc.setColor(highlight,font_color);
homeFavorits.setAdapter(tlRc);
} else {
mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L);

View File

@ -50,6 +50,7 @@
android:contentDescription="@string/profile_image" />
<LinearLayout
android:id="@+id/banner"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

View File

@ -105,7 +105,7 @@
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true"
android:textSize="24sp" />
android:textSize="18sp" />
<TextView
android:id="@+id/used_api"