Performance Bugfix

This commit is contained in:
NudeDude 2018-03-26 23:13:01 +02:00
parent 9306864162
commit ac663804d7
18 changed files with 234 additions and 205 deletions

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
@ -17,6 +16,7 @@ import android.view.ViewGroup;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import org.nuclearfog.twidda.backend.TwitterEngine;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.database.TrendDatabase;
import org.nuclearfog.twidda.database.DatabaseAdapter;
@ -46,22 +46,23 @@ public class MainActivity extends AppCompatActivity implements
private SwipeRefreshLayout timelineReload,trendReload,mentionReload;
private RecyclerView timelineList, trendList,mentionList;
private MenuItem profile, tweet, search, setting;
private SharedPreferences settings;
private SearchView searchQuery;
private Toolbar toolbar;
private TabHost tabhost;
private String currentTab = "timeline";
private int background, font_color, highlight;
private long homeId = 0L;
private final int REQCODE = 666;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainpage);
settings = getSharedPreferences("settings", 0);
boolean login = settings.getBoolean("login", false);
TwitterEngine mTwitter = TwitterEngine.getInstance(this);
boolean login = mTwitter.loggedIn();
if( !login ) {
Intent i = new Intent(this, LoginPage.class);
startActivityForResult(i,1);
startActivityForResult(i,REQCODE);
} else {
login();
}
@ -70,10 +71,12 @@ public class MainActivity extends AppCompatActivity implements
@Override
protected void onActivityResult(int reqCode, int returnCode, Intent i) {
super.onActivityResult(reqCode,returnCode,i);
if(returnCode == RESULT_OK) {
login();
} else {
finish();
if(reqCode == REQCODE) {
if(returnCode == RESULT_OK) {
login();
} else {
finish();
}
}
}
@ -110,7 +113,7 @@ public class MainActivity extends AppCompatActivity implements
case R.id.action_profile:
intent = new Intent(this, UserProfile.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",settings.getLong("userID", -1));
bundle.putLong("userID",homeId);
bundle.putBoolean("home", true);
intent.putExtras(bundle);
startActivity(intent);
@ -269,6 +272,7 @@ public class MainActivity extends AppCompatActivity implements
* Login Handle
*/
private void login() {
homeId = TwitterEngine.getHomeId();
timelineList = (RecyclerView) findViewById(R.id.tl_list);
trendList = (RecyclerView) findViewById(R.id.tr_list);
mentionList = (RecyclerView) findViewById(R.id.m_list);

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda.backend;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
@ -35,7 +34,7 @@ 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 /* bannerLink,*/ profileImage, link, dateString;
private TimelineRecycler homeTl, homeFav;
private WeakReference<UserProfile> ui;
private TwitterEngine mTwitter;
@ -57,13 +56,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
profileTweets = (RecyclerView) ui.get().findViewById(R.id.ht_list);
profileFavorits = (RecyclerView) ui.get().findViewById(R.id.hf_list);
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);
imgEnabled = mColor.loadImage();
}
@Override
protected Long doInBackground(Long... args) {
long userId = args[0];
@ -80,10 +80,7 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
if(MODE == GET_INFORMATION)
{
DatabaseAdapter userdb = new DatabaseAdapter(ui.get());
TwitterUser user = userdb.getUser(userId);
if(user == null)
user = mTwitter.getUser(userId);
TwitterUser user = mTwitter.getUser(userId);
screenName = user.screenname;
username = user.username;
description = user.bio;
@ -93,9 +90,8 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
link = user.link;
follower = Integer.toString(user.follower);
following = Integer.toString(user.following);
imageLink = user.profileImg;
// bannerLink = user.bannerImg;
fullPbLink = user.fullpb;
profileImage = user.profileImg;
Date d = new Date(user.created);
dateString = "seit "+ DateFormat.getDateTimeInstance().format(d);
}
@ -206,16 +202,14 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
connect.findViewById(R.id.followback).setVisibility(View.VISIBLE);
}
if(imgEnabled) {
Picasso.with(context).load(imageLink).into(profile);
// Picasso.with(context).load(bannerLink).into(banner); // TODO
Picasso.with(context).load(profileImage+"_bigger").into(profile);
profile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
new ImagePopup(context).execute(fullPbLink);
new ImagePopup(context).execute(profileImage);
}
});
}
ui.get().onLoaded();
}
else if(mode == GET_TWEETS)
{
@ -246,8 +240,4 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
}
}
}
public interface OnProfileFinished {
void onLoaded();
}
}

View File

@ -2,9 +2,6 @@ package org.nuclearfog.twidda.backend;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.widget.SwipeRefreshLayout;
@ -21,9 +18,8 @@ import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.io.InputStream;
import com.squareup.picasso.Picasso;
import java.lang.ref.WeakReference;
import java.net.URL;
import java.text.DateFormat;
import java.util.Date;
import java.util.List;
@ -51,10 +47,9 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
private TwitterEngine mTwitter;
private TimelineRecycler tlAdp;
private RecyclerView replyList;
private Bitmap profile_btm;
private String usernameStr, scrNameStr, tweetStr, dateString;
private String repliedUsername, apiName, retweeter;
private String medialinks[];
private String medialinks[], profile_pb;
private String errMSG = "";
private boolean retweeted, favorited, toggleImg, verified;
private boolean rtFlag = false;
@ -66,12 +61,10 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
public StatusLoader(Context c) {
mTwitter = TwitterEngine.getInstance(c);
SharedPreferences settings = c.getSharedPreferences("settings", 0);
toggleImg = settings.getBoolean("image_load", true);
ColorPreferences mColor = ColorPreferences.getInstance(c);
highlight = mColor.getColor(ColorPreferences.HIGHLIGHTING);
font = mColor.getColor(ColorPreferences.FONT_COLOR);
toggleImg = mColor.loadImage();
ui = new WeakReference<>((TweetDetail)c);
replyList = (RecyclerView) ui.get().findViewById(R.id.answer_list);
}
@ -86,12 +79,11 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
long mode = data[1];
try {
Tweet tweet = mTwitter.getStatus(tweetID);
Tweet embeddedTweet = tweet.embedded;
if(embeddedTweet != null) {
if(tweet.embedded != null) {
retweeter = "Retweet "+tweet.user.screenname;
retweeterID = tweet.user.userID;
tweet = mTwitter.getStatus(embeddedTweet.tweetID);
tweetID = embeddedTweet.tweetID;
tweet = tweet.embedded;
tweetID = tweet.tweetID;
rtFlag = true;
}
rt = tweet.retweet;
@ -109,13 +101,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
apiName = formatString(tweet.source);
dateString = DateFormat.getDateTimeInstance().format(new Date(tweet.time));
repliedUsername = tweet.replyName;
if(toggleImg) {
String pbLink = tweet.user.profileImg;
InputStream iStream = new URL(pbLink).openStream();
profile_btm = BitmapFactory.decodeStream(iStream);
medialinks = tweet.media;
}
profile_pb = tweet.user.profileImg+"_bigger";
medialinks = tweet.media;
}
else if(mode == RETWEET) {
if(retweeted) {
@ -223,8 +210,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
tweet_verify.setVisibility(View.VISIBLE);
}
if(toggleImg) {
profile_img.setImageBitmap(profile_btm);
if(medialinks.length != 0) {
Picasso.with(ui.get()).load(profile_pb).into(profile_img);
if(medialinks != null && medialinks.length != 0) {
mediabutton.setVisibility(View.VISIBLE);
mediabutton.setOnClickListener(this);
}
@ -260,6 +247,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
}
private String formatString(String input) {
StringBuilder output = new StringBuilder("gesendet von: ");
boolean openTag = false;
@ -276,6 +264,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
return output.toString();
}
private Spannable highlight(String tweet) {
Spannable sTweet = new SpannableStringBuilder(tweet);
int start = 0;
@ -313,6 +302,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
return sTweet;
}
private Spannable spanning(Spannable sTweet, final int start, final int end) {
sTweet.setSpan(new ClickableSpan() {
@Override
@ -364,7 +354,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
case R.id.answer_reference_detail:
Intent tweet = new Intent(ui.get(), TweetDetail.class);
tweet.putExtra("tweetID",tweetReplyID);
tweet.putExtra("username", repliedUsername);
tweet.putExtra("username", '@'+repliedUsername);
ui.get().startActivity(tweet);
break;

View File

@ -45,6 +45,7 @@ public class TwitterEngine {
private Context context;
private SharedPreferences settings;
private RequestToken reqToken;
private boolean login;
private int load;
@ -55,6 +56,7 @@ public class TwitterEngine {
*/
private TwitterEngine(Context context) {
settings = context.getSharedPreferences("settings", 0);
login = settings.getBoolean("login", false);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setOAuthConsumerKey(TWITTER_CONSUMER_KEY);
builder.setOAuthConsumerSecret(TWITTER_CONSUMER_SECRET);
@ -108,6 +110,7 @@ public class TwitterEngine {
builder.setTweetModeExtended(true);
AccessToken token = new AccessToken(key1,key2);
twitter = new TwitterFactory( builder.build() ).getInstance(token);
login = true;
}
@ -134,12 +137,19 @@ public class TwitterEngine {
*/
private void init() {
String key1,key2;
if( settings.getBoolean("login", false) ) {
if( login ) {
key1 = settings.getString("key1", " ");
key2 = settings.getString("key2", " ");
twitterID = settings.getLong("userID", -1L);
initKeys(key1,key2);
}
twitterID = settings.getLong("userID", -1L);
}
/**
* @return if Twitter4J is registered
*/
public boolean loggedIn() {
return login;
}
@ -420,7 +430,7 @@ public class TwitterEngine {
* @throws TwitterException if Access is unavailable
*/
public void favorite(long id, boolean active) throws TwitterException {
if(!active){
if(!active) {
twitter.createFavorite(id);
} else {
twitter.destroyFavorite(id);
@ -514,7 +524,7 @@ public class TwitterEngine {
* @return User item
*/
private TwitterUser getUser(User user) {
return new TwitterUser(user.getId(),user.getName(),user.getScreenName(),user.getMiniProfileImageURL(),
return new TwitterUser(user.getId(),user.getName(),user.getScreenName(),
user.getOriginalProfileImageURL(),user.getDescription(),user.getLocation(),user.isVerified(),
user.isProtected(),user.getURL(),user.getProfileBannerURL(),user.getCreatedAt().getTime(),
user.getFriendsCount(),user.getFollowersCount());

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda.backend;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
@ -26,7 +25,7 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
private RecyclerView tweetSearch, userSearch;
private TwitterEngine mTwitter;
private WeakReference<SearchPage> ui;
private int background, highlight, font_color;
private int highlight, font_color;
private String error;
boolean imageload;
@ -36,11 +35,9 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
userSearch = (RecyclerView) ui.get().findViewById(R.id.user_result);
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);
SharedPreferences settings = ui.get().getSharedPreferences("settings", 0);
imageload = settings.getBoolean("image_load", true);
imageload = mcolor.loadImage();
}
@Override
@ -60,7 +57,6 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
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());
@ -86,7 +82,6 @@ public class TwitterSearch extends AsyncTask<String, Void, Void> {
SwipeRefreshLayout tweetReload = (SwipeRefreshLayout)connect.findViewById(R.id.searchtweets);
ProgressBar circleLoad = (ProgressBar)connect.findViewById(R.id.search_progress);
circleLoad.setVisibility(View.INVISIBLE);
tweetSearch.setAdapter(tlRc);
userSearch.setAdapter(uAdp);

View File

@ -2,7 +2,6 @@ package org.nuclearfog.twidda.backend;
import android.app.Dialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.support.v7.widget.RecyclerView;
import android.view.Window;
@ -11,6 +10,7 @@ import android.widget.Toast;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.viewadapter.UserRecycler;
import org.nuclearfog.twidda.window.ColorPreferences;
import org.nuclearfog.twidda.window.UserDetail;
import org.nuclearfog.twidda.backend.listitems.*;
@ -41,9 +41,7 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
ui = new WeakReference<>((UserDetail)context);
mTwitter = TwitterEngine.getInstance(context);
userList = (RecyclerView) ui.get().findViewById(R.id.userlist);
// uProgress = (ProgressBar) ui.get().findViewById(R.id.user_progress);
SharedPreferences settings = context.getSharedPreferences("settings", 0);
imageload = settings.getBoolean("image_load", true);
imageload = ColorPreferences.getInstance(ui.get()).loadImage();
circle = new ProgressBar(ui.get());
popup = new Dialog(ui.get());
}
@ -51,7 +49,8 @@ public class UserLists extends AsyncTask <Long, Void, Void> {
@Override
protected void onPreExecute() {
popup.requestWindowFeature(Window.FEATURE_NO_TITLE);
popup.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
if(popup.getWindow() != null)
popup.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
popup.setContentView(circle);
popup.show();
}

View File

@ -2,8 +2,8 @@ package org.nuclearfog.twidda.backend.listitems;
public class Tweet {
public final TwitterUser user;
public final long tweetID;
public final Tweet embedded;
public final long tweetID;
public final String tweet, replyName,source;
public final long time, replyID;
public final int retweet, favorit;

View File

@ -2,7 +2,7 @@ package org.nuclearfog.twidda.backend.listitems;
public class TwitterUser {
public final String username,screenname,bio;
public final String profileImg,fullpb,bannerImg;
public final String profileImg,bannerImg;
public final String location,link;
public final boolean isVerified,isLocked;
public final long userID;
@ -10,13 +10,12 @@ public class TwitterUser {
public final int following, follower;
public TwitterUser(long userID, String username, String screenname, String profileImg,
String fullpb, String bio, String location, boolean isVerified, boolean isLocked,
String link, String bannerImg, long created, int following, int follower) {
String bio, String location, boolean isVerified, boolean isLocked, String link,
String bannerImg, long created, int following, int follower) {
this.userID = userID;
this.username = username;
this.screenname = '@'+screenname;
this.profileImg = profileImg;
this.fullpb = fullpb;
this.bio = bio;
this.link = link;
this.location = location;

View File

@ -22,15 +22,11 @@ public class AppDatabase extends SQLiteOpenHelper
"FOREIGN KEY (userID) REFERENCES user(userID)," +
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));";
private static final String retweetTable = "CREATE TABLE IF NOT EXISTS retweet ("+
"userID INTEGER, tweetID INTEGER UNIQUE," +
"FOREIGN KEY (userID) REFERENCES user(userID)," +
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));";
private static final String timelineTable = "CREATE TABLE IF NOT EXISTS timeline (" +
"tweetID INTEGER UNIQUE, mTweetID INTEGER UNIQUE," +
"FOREIGN KEY (tweetID) REFERENCES tweet(tweetID));" +
"FOREIGN KEY (mTweetID) REFERENCES tweet(tweetID));";
"tweetID INTEGER UNIQUE, FOREIGN KEY (tweetID) REFERENCES tweet(tweetID) );";
private static final String mentionTable = "CREATE TABLE IF NOT EXISTS mention (" +
"tweetID INTEGER UNIQUE, FOREIGN KEY (tweetID) REFERENCES tweet(tweetID) );";
private static final String trendTable = "CREATE TABLE IF NOT EXISTS trend (" +
"trendpos INTEGER PRIMARY KEY, trendname TEXT, trendlink TEXT);";
@ -48,8 +44,8 @@ public class AppDatabase extends SQLiteOpenHelper
db.execSQL(tweetTable);
db.execSQL(trendTable);
db.execSQL(timelineTable);
db.execSQL(mentionTable);
db.execSQL(favoriteTable);
db.execSQL(retweetTable);
}
@Override
@ -58,7 +54,7 @@ public class AppDatabase extends SQLiteOpenHelper
db.execSQL("DROP TABLE IF EXISTS " + "tweet");
db.execSQL("DROP TABLE IF EXISTS " + "favorit");
db.execSQL("DROP TABLE IF EXISTS " + "timeline");
db.execSQL("DROP TABLE IF EXISTS " + "retweet");
db.execSQL("DROP TABLE IF EXISTS " + "mentionTable");
db.execSQL("DROP TABLE IF EXISTS " + "trend");
onCreate(db);
}

View File

@ -19,6 +19,7 @@ public class DatabaseAdapter {
private List<Tweet> tweetlist;
private Context context;
public DatabaseAdapter(Context context) {
dataHelper = AppDatabase.getInstance(context);
tweetlist = new ArrayList<>();
@ -53,8 +54,8 @@ public class DatabaseAdapter {
fav.put("userID", id);
db.insertWithOnConflict("favorit",null,fav,SQLiteDatabase.CONFLICT_REPLACE);
} else if(mode == MENT) {
ment.put("mTweetID", tweet.tweetID);
db.insertWithOnConflict("timeline",null,ment,SQLiteDatabase.CONFLICT_IGNORE);
ment.put("tweetID", tweet.tweetID);
db.insertWithOnConflict("mention",null,ment,SQLiteDatabase.CONFLICT_REPLACE);
}
}
}
@ -68,11 +69,11 @@ public class DatabaseAdapter {
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";
"INNER JOIN user ON tweet.userID = user.userID ORDER BY tweetID DESC";
} 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";
SQL_GET_HOME = "SELECT * FROM mention " +
"INNER JOIN tweet ON mention.tweetID = tweet.tweetID " +
"INNER JOIN user ON tweet.userID = user.userID ORDER BY tweetID ASC";
}
else if(mode == TWEET) {
SQL_GET_HOME = "SELECT * FROM user " +
@ -87,7 +88,7 @@ public class DatabaseAdapter {
Cursor cursor = db.rawQuery(SQL_GET_HOME,null);
if(cursor.moveToFirst()) {
do {
Tweet tweet = getTweet(cursor);
Tweet tweet = getStatus(cursor);
tweetlist.add(tweet);
} while(cursor.moveToNext());
}
@ -97,7 +98,7 @@ public class DatabaseAdapter {
}
public Tweet getTweet(long tweetId) {
public Tweet getStatus(long tweetId) {
SQLiteDatabase search = dataHelper.getReadableDatabase();
Tweet result = null;
String query = "SELECT * FROM tweet " +
@ -105,7 +106,7 @@ public class DatabaseAdapter {
"WHERE tweet.tweetID == " + tweetId;
Cursor cursor = search.rawQuery(query,null);
if(cursor.moveToFirst())
result = getTweet(cursor);
result = getStatus(cursor);
cursor.close();
return result;
}
@ -123,7 +124,7 @@ public class DatabaseAdapter {
}
private Tweet getTweet(Cursor cursor) {
private Tweet getStatus(Cursor cursor) {
int index;
index = cursor.getColumnIndex("time");
long time = cursor.getLong(index);
@ -150,7 +151,7 @@ public class DatabaseAdapter {
TwitterUser user = getUser(cursor);
Tweet embeddedTweet = null;
if(retweetId > 0)
embeddedTweet = getTweet(retweetId);
embeddedTweet = getStatus(retweetId);
return new Tweet(tweetId,retweet,favorit,user,tweettext,time,replyname,null,
source,replyStatusId,embeddedTweet,retweeted,favorized);
}
@ -169,8 +170,6 @@ public class DatabaseAdapter {
boolean locked = cursor.getInt(index) == 1;
index = cursor.getColumnIndex("pbLink");
String profileImg = cursor.getString(index);
index = cursor.getColumnIndex("fullpb");
String fullpb = cursor.getString(index);
index = cursor.getColumnIndex("bio");
String bio = cursor.getString(index);
index = cursor.getColumnIndex("link");
@ -185,15 +184,16 @@ public class DatabaseAdapter {
int following = cursor.getInt(index);
index = cursor.getColumnIndex("follower");
int follower = cursor.getInt(index);
return new TwitterUser(userId, username,screenname,profileImg,fullpb,bio,
return new TwitterUser(userId, username,screenname,profileImg,bio,
location,isVerified,locked,link,banner,createdAt,following,follower);
}
private void storeStatus(Tweet tweet, SQLiteDatabase db, long retweetID) {
ContentValues status = new ContentValues();
ContentValues user = new ContentValues();
TwitterUser mUser = tweet.user;
storeUser(mUser,db);
status.put("tweetID", tweet.tweetID);
status.put("userID", mUser.userID);
@ -208,23 +208,27 @@ public class DatabaseAdapter {
status.put("retweeted",tweet.retweeted);
status.put("favorized", tweet.favorized);
user.put("userID", mUser.userID);
user.put("username", mUser.username);
user.put("scrname", mUser.screenname.substring(1));
user.put("pbLink", mUser.profileImg);
user.put("fullpb", mUser.fullpb);
user.put("verify", mUser.isVerified);
user.put("locked", mUser.isLocked);
user.put("bio", mUser.bio);
user.put("link", mUser.link);
user.put("location", mUser.location);
user.put("banner", mUser.bannerImg);
user.put("createdAt", mUser.created);
user.put("following", mUser.following);
user.put("follower", mUser.follower);
db.insertWithOnConflict("tweet",null, status,SQLiteDatabase.CONFLICT_REPLACE);
db.insertWithOnConflict("user",null, user,SQLiteDatabase.CONFLICT_REPLACE);
}
private void storeUser(TwitterUser user, SQLiteDatabase db) {
ContentValues userColumn = new ContentValues();
userColumn.put("userID", user.userID);
userColumn.put("username", user.username);
userColumn.put("scrname", user.screenname.substring(1));
userColumn.put("pbLink", user.profileImg);
userColumn.put("verify", user.isVerified);
userColumn.put("locked", user.isLocked);
userColumn.put("bio", user.bio);
userColumn.put("link", user.link);
userColumn.put("location", user.location);
userColumn.put("banner", user.bannerImg);
userColumn.put("createdAt", user.created);
userColumn.put("following", user.following);
userColumn.put("follower", user.follower);
db.insertWithOnConflict("user",null, userColumn,SQLiteDatabase.CONFLICT_IGNORE);
}

View File

@ -94,7 +94,7 @@ public class TimelineRecycler extends Adapter<TimelineRecycler.ItemHolder> imple
vh.favorite.setText(favorit);
vh.time.setText(stringTime(tweet.time));
if(img_ldr) {
Picasso.with(parent.getContext()).load(tweet.user.profileImg).into(vh.profile);
Picasso.with(parent.getContext()).load(tweet.user.profileImg+"_mini").into(vh.profile);
}
if(tweet.user.isVerified) {
vh.verify.setVisibility(View.VISIBLE);

View File

@ -61,7 +61,7 @@ public class UserRecycler extends RecyclerView.Adapter<UserRecycler.ItemHolder>
vh.screenname.setText(user.screenname);
vh.username.setText(user.username);
if(loadImage) {
Picasso.with(parent.getContext()).load(user.profileImg).into(vh.profileImg);
Picasso.with(parent.getContext()).load(user.profileImg+"_mini").into(vh.profileImg);
}
if(user.isVerified) {
vh.verifyIco.setVisibility(View.VISIBLE);

View File

@ -13,7 +13,6 @@ import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ProgressBar;
import android.widget.TabHost;
import org.nuclearfog.twidda.R;
@ -80,17 +79,18 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
@Override
public boolean onCreateOptionsMenu(Menu m) {
getMenuInflater().inflate(R.menu.search, m);
SearchView searchQuery = (SearchView)m.findItem(R.id.new_search).getActionView();
final SearchView searchQuery = (SearchView)m.findItem(R.id.new_search).getActionView();
searchQuery.setQueryHint(search);
searchQuery.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String s) {
search = s;
ProgressBar mCircle = (ProgressBar)findViewById(R.id.search_progress);
mCircle.setVisibility(View.VISIBLE);
searchQuery.setQueryHint(search);
findViewById(R.id.search_progress).setVisibility(View.VISIBLE);
tweetSearch.setAdapter(null);
userSearch.setAdapter(null);
getContent();
return false;
return true;
}
@Override
public boolean onQueryTextChange(String s) {
@ -144,7 +144,9 @@ public class SearchPage extends AppCompatActivity implements UserRecycler.OnItem
Intent profile = new Intent(getApplicationContext(), UserProfile.class);
Bundle bundle = new Bundle();
long userID = user.userID;
String username = user.screenname;
bundle.putLong("userID",userID);
bundle.putString("username", username);
profile.putExtras(bundle);
startActivity(profile);
break;

View File

@ -1,7 +1,6 @@
package org.nuclearfog.twidda.window;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.SwipeRefreshLayout;
@ -17,11 +16,13 @@ import android.widget.TabHost;
import android.widget.TextView;
import org.nuclearfog.twidda.R;
import org.nuclearfog.twidda.backend.TwitterEngine;
import org.nuclearfog.twidda.backend.listitems.*;
import org.nuclearfog.twidda.database.DatabaseAdapter;
import org.nuclearfog.twidda.backend.ProfileLoader;
import org.nuclearfog.twidda.viewadapter.TimelineRecycler;
import java.text.DateFormat;
import java.util.List;
/**
@ -30,7 +31,7 @@ import java.util.List;
*/
public class UserProfile extends AppCompatActivity implements View.OnClickListener,
SwipeRefreshLayout.OnRefreshListener, TabHost.OnTabChangeListener,
TimelineRecycler.OnItemClicked, ProfileLoader.OnProfileFinished {
TimelineRecycler.OnItemClicked {
private ProfileLoader mProfile, mTweets, mFavorits;
private SwipeRefreshLayout homeReload, favoriteReload;
@ -39,26 +40,33 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
private boolean home, imageload;
private String username = "";
private String currentTab = "tweets";
int highlight, background, font_color;
@Override
protected void onCreate(Bundle b) {
super.onCreate(b);
setContentView(R.layout.profile);
getExtras(getIntent().getExtras());
Toolbar tool = (Toolbar) findViewById(R.id.profile_toolbar);
setSupportActionBar(tool);
if(getSupportActionBar() != null)
getSupportActionBar().setDisplayShowTitleEnabled(false);
getExtras(getIntent().getExtras());
SharedPreferences settings = getSharedPreferences("settings", 0);
home = userId == settings.getLong("userID", -1);
imageload = settings.getBoolean("image_load", true);
home = userId == TwitterEngine.getHomeId();
ColorPreferences mcolor = ColorPreferences.getInstance(this);
highlight = mcolor.getColor(ColorPreferences.HIGHLIGHTING);
background = mcolor.getColor(ColorPreferences.BACKGROUND);
font_color = mcolor.getColor(ColorPreferences.FONT_COLOR);
imageload = mcolor.loadImage();
homeList = (RecyclerView) findViewById(R.id.ht_list);
homeList.setLayoutManager(new LinearLayoutManager(this));
homeList.setBackgroundColor(background);
favoritList = (RecyclerView)findViewById(R.id.hf_list);
homeList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
favoritList.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
favoritList.setLayoutManager(new LinearLayoutManager(this));
favoritList.setBackgroundColor(background);
homeReload = (SwipeRefreshLayout) findViewById(R.id.hometweets);
favoriteReload = (SwipeRefreshLayout) findViewById(R.id.homefavorits);
TextView txtFollowing = (TextView)findViewById(R.id.following);
TextView txtFollower = (TextView)findViewById(R.id.follower);
TabHost mTab = (TabHost)findViewById(R.id.profile_tab);
@ -68,8 +76,8 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
txtFollower.setOnClickListener(this);
homeReload.setOnRefreshListener(this);
favoriteReload.setOnRefreshListener(this);
initElements();
getProfileInformation();
getProfileTweets();
}
@Override
@ -128,10 +136,10 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
public void onClick(View v) {
switch(v.getId()) {
case R.id.following:
getFollows(0L);
getConnection(0L);
break;
case R.id.follower:
getFollows(1L);
getConnection(1L);
break;
}
}
@ -193,63 +201,84 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
mTab.addTab(tab2);
}
/**
* Tab Content
*/
@Override
public void onLoaded() {
private void getProfileInformation() {
new Thread( new Runnable() {
@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);
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);
homeList.setBackgroundColor(background);
favoritList.setBackgroundColor(background);
if( userTweets.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userTweets,UserProfile.this);
tlRc.setColor(highlight,font_color);
tlRc.toggleImage(imageload);
homeList.setAdapter(tlRc);
} else {
mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L);
@Override
public void run() {
DatabaseAdapter database = new DatabaseAdapter(getApplicationContext());
TwitterUser user = database.getUser(userId);
if(user != null) {
String dateString = "seit "+ DateFormat.getDateTimeInstance().format(user.created);
String followerStr = ""+user.follower;
String followingStr = ""+user.following;
TextView txtUser = (TextView)findViewById(R.id.profile_username);
TextView txtScrName = (TextView)findViewById(R.id.profile_screenname);
TextView txtBio = (TextView)findViewById(R.id.bio);
TextView txtCreated = (TextView)findViewById(R.id.profile_date);
TextView txtFollowing = (TextView)findViewById(R.id.following);
TextView txtFollower = (TextView)findViewById(R.id.follower);
findViewById(R.id.following_icon).setVisibility(View.VISIBLE);
findViewById(R.id.follower_icon).setVisibility(View.VISIBLE);
TextView txtLocation = (TextView)findViewById(R.id.location);
TextView txtLink = (TextView)findViewById(R.id.links);
txtUser.setText(user.username);
txtScrName.setText(user.screenname);
txtBio.setText(user.bio);
txtCreated.setText(dateString);
txtFollower.setText(followerStr);
txtFollowing.setText(followingStr);
if(user.isVerified)
findViewById(R.id.profile_verify).setVisibility(View.VISIBLE);
if(user.isLocked)
findViewById(R.id.profile_locked).setVisibility(View.VISIBLE);
if(user.location != null && !user.location.isEmpty()) {
txtLocation.setText(user.location);
findViewById(R.id.location_img).setVisibility(View.VISIBLE);
}
if( userFavorit.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userFavorit,UserProfile.this);
tlRc.setColor(highlight,font_color);
tlRc.toggleImage(imageload);
favoritList.setAdapter(tlRc);
} else {
mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L);
if(user.link != null && !user.link.isEmpty()) {
txtLink.setText(user.link);
findViewById(R.id.link_img).setVisibility(View.VISIBLE);
}
findViewById(R.id.follower_icon).setVisibility(View.VISIBLE);
findViewById(R.id.following_icon).setVisibility(View.VISIBLE);
}
}
).run();
}
/**
* Profile Information
*/
private void initElements() {
}}).run();
// Refresh
mProfile = new ProfileLoader(this);
mProfile.execute(userId, ProfileLoader.GET_INFORMATION,1L);
}
/**
* @param mode 0L = Following , 1L Follower
*/
private void getFollows(long mode) {
private void getProfileTweets() {
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);
if( userTweets.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userTweets,UserProfile.this);
tlRc.setColor(highlight,font_color);
tlRc.toggleImage(imageload);
homeList.setAdapter(tlRc);
} else {
mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L);
}
if( userFavorit.size() > 0 ) {
TimelineRecycler tlRc = new TimelineRecycler(userFavorit,UserProfile.this);
tlRc.setColor(highlight,font_color);
tlRc.toggleImage(imageload);
favoritList.setAdapter(tlRc);
} else {
mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L);
}
}
private void getConnection(long mode) {
Intent intent = new Intent(getApplicationContext(), UserDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userId);
@ -258,7 +287,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
startActivity(intent);
}
@SuppressWarnings("ConstantConditions")
private void getExtras(Bundle b) {
userId = b.getLong("userID");
username = b.getString("username");

View File

@ -66,7 +66,7 @@
android:layout_gravity="center_vertical"
android:layout_marginEnd="2dp"
android:contentDescription="@string/verify"
android:visibility="invisible"
android:visibility="gone"
app:srcCompat="@drawable/verify" />
<TextView
@ -89,7 +89,7 @@
android:layout_gravity="center_vertical"
android:layout_marginEnd="2dp"
android:contentDescription="@string/profile_locked"
android:visibility="invisible"
android:visibility="gone"
app:srcCompat="@drawable/lock" />
<TextView
@ -114,7 +114,7 @@
android:layout_marginEnd="2dp"
android:background="@drawable/followback"
android:contentDescription="@string/followback"
android:visibility="invisible" />
android:visibility="gone" />
<ImageView
android:id="@+id/following_icon"
@ -192,7 +192,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="web"
android:linksClickable="true" />
android:linksClickable="true"
android:singleLine="true" />
</LinearLayout>

View File

@ -63,26 +63,34 @@
android:layout_height="56dp"
android:contentDescription="@string/profile_image" />
<ImageView
android:id="@+id/tweet_verify"
android:layout_width="16dp"
android:layout_height="16dp"
android:layout_margin="4dp"
android:contentDescription="@string/verify"
android:visibility="invisible"
app:srcCompat="@drawable/verify" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/usernamedetail"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/tweet_verify"
android:layout_width="12dp"
android:layout_height="12dp"
android:layout_marginEnd="4dp"
android:contentDescription="@string/verify"
android:visibility="gone"
app:srcCompat="@drawable/verify" />
<TextView
android:id="@+id/usernamedetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
</LinearLayout>
<TextView
android:id="@+id/scrnamedetail"
@ -94,7 +102,8 @@
android:id="@+id/timedetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true" />
android:singleLine="true"
android:textSize="12sp" />
</LinearLayout>

View File

@ -11,13 +11,12 @@
<item
android:id="@+id/profile_follow"
android:icon="@drawable/follow"
android:title="follow "
android:title="@string/follow"
android:visible="false"
app:showAsAction="ifRoom" />
<item
android:id="@+id/profile_block"
android:icon="@drawable/block"
android:title="Block"
android:visible="false"
app:showAsAction="ifRoom" />
android:title="@string/block"
android:visible="false" />
</menu>

View File

@ -45,4 +45,6 @@
<string name="load_factor">Ladefaktor</string>
<string name="followback">Folgt dir</string>
<string name="load">Anzahl Tweets</string>
<string name="block">Block</string>
<string name="follow">folgen</string>
</resources>