Cleanup
This commit is contained in:
NudeDude 2018-04-01 23:05:25 +02:00
parent ec6805aff7
commit 4759bea6ec
8 changed files with 104 additions and 67 deletions

View File

@ -71,7 +71,6 @@ public class MainActivity extends AppCompatActivity implements
if(reqCode == REQCODE) {
if(returnCode == RESULT_OK) {
login();
setTabContent();
} else {
finish();
}
@ -140,6 +139,7 @@ public class MainActivity extends AppCompatActivity implements
trendList.setAdapter(null);
mentionList.setAdapter(null);
setTabContent();
settingChanged = false;
}
}

View File

@ -12,6 +12,7 @@ import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ProgressBar;
import org.nuclearfog.twidda.R;
import java.io.InputStream;
import java.net.URL;
@ -36,12 +37,13 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> implements Butt
@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(mCircle);
popup.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
ImagePopup.this.cancel(true);
cancel(true);
}
});
popup.show();
@ -89,9 +91,8 @@ public class ImagePopup extends AsyncTask<String, Void, Boolean> implements Butt
left.setOnClickListener(this);
right.setOnClickListener(this);
}
} try {
popup.show();
} catch(Exception err){}
}
} else {
popup.dismiss();
}

View File

@ -32,7 +32,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
public static final long GET_TWEETS = 0x2;
public static final long GET_FAVS = 0x3;
public static final long ACTION_MUTE = 0x4;
public static final long LOAD_DB = 0x5;
private static final long FAILURE = 0x6;
private static final long IGNORE = 0x9;
private String screenName, username, description, location, follower, following;
private RecyclerView profileTweets, profileFavorits;
@ -80,9 +82,16 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
isFollowed = connection[1];
muted = connection[2];
}
if(MODE == GET_INFORMATION)
if(MODE == GET_INFORMATION || MODE == LOAD_DB)
{
TwitterUser user = mTwitter.getUser(userId);
TwitterUser user;
if(MODE == LOAD_DB) {
user = new DatabaseAdapter(ui.get()).getUser(userId);
if(user == null)
return IGNORE;
} else {
user = mTwitter.getUser(userId);
}
screenName = user.screenname;
username = user.username;
description = user.bio;
@ -159,9 +168,9 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
int errCode = err.getErrorCode();
if(errCode != 136 && errCode != -1){
errMsg = err.getMessage();
return FAILURE;
}
err.printStackTrace();
return FAILURE;
}
catch(Exception err) {
errMsg = err.getMessage();
@ -178,23 +187,21 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
return;
final Context context = connect;
TextView txtUser = (TextView)connect.findViewById(R.id.profile_username);
TextView txtScrName = (TextView)connect.findViewById(R.id.profile_screenname);
TextView txtBio = (TextView)connect.findViewById(R.id.bio);
TextView txtLocation = (TextView)connect.findViewById(R.id.location);
TextView txtLink = (TextView)connect.findViewById(R.id.links);
TextView txtCreated = (TextView)connect.findViewById(R.id.profile_date);
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 locationIcon = (ImageView)connect.findViewById(R.id.location_img);
connect.findViewById(R.id.following_icon).setVisibility(View.VISIBLE);
connect.findViewById(R.id.follower_icon).setVisibility(View.VISIBLE);
SwipeRefreshLayout tweetsReload = (SwipeRefreshLayout)connect.findViewById(R.id.hometweets);
SwipeRefreshLayout favoritsReload = (SwipeRefreshLayout)connect.findViewById(R.id.homefavorits);
if(mode == GET_INFORMATION || mode == LOAD_DB) {
TextView txtUser = (TextView)connect.findViewById(R.id.profile_username);
TextView txtScrName = (TextView)connect.findViewById(R.id.profile_screenname);
TextView txtBio = (TextView)connect.findViewById(R.id.bio);
TextView txtLocation = (TextView)connect.findViewById(R.id.location);
TextView txtLink = (TextView)connect.findViewById(R.id.links);
TextView txtCreated = (TextView)connect.findViewById(R.id.profile_date);
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 locationIcon = (ImageView)connect.findViewById(R.id.location_img);
connect.findViewById(R.id.following_icon).setVisibility(View.VISIBLE);
connect.findViewById(R.id.follower_icon).setVisibility(View.VISIBLE);
if(mode == GET_INFORMATION) {
txtUser.setText(username);
txtScrName.setText(screenName);
txtBio.setText(description);
@ -231,16 +238,20 @@ public class ProfileLoader extends AsyncTask<Long,Void,Long> {
else if(mode == GET_TWEETS)
{
profileTweets.setAdapter(homeTl);
SwipeRefreshLayout tweetsReload = (SwipeRefreshLayout)connect.findViewById(R.id.hometweets);
tweetsReload.setRefreshing(false);
}
else if(mode == GET_FAVS)
{
profileFavorits.setAdapter(homeFav);
SwipeRefreshLayout favoritsReload = (SwipeRefreshLayout)connect.findViewById(R.id.homefavorits);
favoritsReload.setRefreshing(false);
}
else if(mode == FAILURE)
{
Toast.makeText(context,"Fehler: "+errMsg,Toast.LENGTH_LONG).show();
SwipeRefreshLayout tweetsReload = (SwipeRefreshLayout)connect.findViewById(R.id.hometweets);
SwipeRefreshLayout favoritsReload = (SwipeRefreshLayout)connect.findViewById(R.id.homefavorits);
tweetsReload.setRefreshing(false);
favoritsReload.setRefreshing(false);
}

View File

@ -43,6 +43,8 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
public static final long DELETE = 2;
public static final long LOAD_TWEET = 3;
public static final long LOAD_REPLY = 4;
public static final long LOAD_DB = 5;
private static final long IGNORE = 6;
private TwitterEngine mTwitter;
private TimelineRecycler tlAdp;
@ -76,9 +78,18 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
@Override
protected Long doInBackground(Long... data) {
tweetID = data[0];
long mode = data[1];
final long MODE = data[1];
Tweet tweet;
try {
Tweet tweet = mTwitter.getStatus(tweetID);
if(MODE == LOAD_DB) {
tweet = new DatabaseAdapter(ui.get()).getStatus(tweetID);
if(tweet == null)
return IGNORE;
}
else
tweet = mTwitter.getStatus(tweetID);
if(MODE == LOAD_REPLY)
new DatabaseAdapter(ui.get()).storeStatus(tweet);
if(tweet.embedded != null) {
retweeter = tweet.user.screenname;
retweeterID = tweet.user.userID;
@ -91,7 +102,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
retweeted = tweet.retweeted;
favorited = tweet.favorized;
if(mode == LOAD_TWEET) {
if(MODE == LOAD_TWEET || MODE == LOAD_DB) {
tweetReplyID = tweet.replyID;
verified = tweet.user.isVerified;
tweetStr = tweet.tweet;
@ -104,7 +115,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
profile_pb = tweet.user.profileImg+"_bigger";
medialinks = tweet.media;
}
else if(mode == RETWEET) {
else if(MODE == RETWEET) {
if(retweeted) {
mTwitter.retweet(tweetID, true);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
@ -116,7 +127,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
rt++;
}
}
else if(mode == FAVORITE) {
else if(MODE == FAVORITE) {
if(favorited) {
mTwitter.favorite(tweetID, true);
favorited = false;
@ -127,7 +138,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
fav++;
}
}
else if(mode == LOAD_REPLY) {
else if(MODE == LOAD_REPLY) {
List<Tweet> answers;
String replyname = tweet.user.screenname;
tlAdp = (TimelineRecycler) replyList.getAdapter();
@ -141,7 +152,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
tlAdp = new TimelineRecycler(answers,ui.get());
tlAdp.setColor(highlight, font);
}
else if(mode == DELETE) {
else if(MODE == DELETE) {
mTwitter.deleteTweet(tweetID);
new DatabaseAdapter(ui.get()).removeStatus(tweetID);
}
@ -156,7 +167,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
errMSG = err.getMessage();
return ERROR;
}
return mode;
return MODE;
}
@Override
@ -164,32 +175,24 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
TweetDetail connect = ui.get();
if(connect == null)
return;
TextView tweet = (TextView)connect.findViewById(R.id.tweet_detailed);
TextView username = (TextView)connect.findViewById(R.id.usernamedetail);
TextView scrName = (TextView)connect.findViewById(R.id.scrnamedetail);
TextView date = (TextView)connect.findViewById(R.id.timedetail);
TextView replyName = (TextView)connect.findViewById(R.id.answer_reference_detail);
TextView txtAns = (TextView)connect.findViewById(R.id.no_ans_detail);
TextView txtRet = (TextView)connect.findViewById(R.id.no_rt_detail);
TextView txtFav = (TextView)connect.findViewById(R.id.no_fav_detail);
TextView used_api = (TextView)connect.findViewById(R.id.used_api);
TextView userRetweet = (TextView)connect.findViewById(R.id.rt_info);
SwipeRefreshLayout ansReload = (SwipeRefreshLayout)connect.findViewById(R.id.answer_reload);
ImageView profile_img = (ImageView)connect.findViewById(R.id.profileimage_detail);
ImageView tweet_verify =(ImageView)connect.findViewById(R.id.tweet_verify);
Button retweetButton = (Button)connect.findViewById(R.id.rt_button_detail);
Button favoriteButton = (Button)connect.findViewById(R.id.fav_button_detail);
Button mediabutton = (Button)connect.findViewById(R.id.image_attach);
Button answer = (Button) connect.findViewById(R.id.answer_button);
if(mode == LOAD_TWEET) {
if(mode == LOAD_TWEET ||mode == LOAD_DB) {
TextView tweet = (TextView)connect.findViewById(R.id.tweet_detailed);
TextView username = (TextView)connect.findViewById(R.id.usernamedetail);
TextView scrName = (TextView)connect.findViewById(R.id.scrnamedetail);
TextView date = (TextView)connect.findViewById(R.id.timedetail);
TextView replyName = (TextView)connect.findViewById(R.id.answer_reference_detail);
TextView used_api = (TextView)connect.findViewById(R.id.used_api);
TextView txtRet = (TextView)connect.findViewById(R.id.no_rt_detail);
TextView txtFav = (TextView)connect.findViewById(R.id.no_fav_detail);
ImageView profile_img = (ImageView)connect.findViewById(R.id.profileimage_detail);
tweet.setMovementMethod(LinkMovementMethod.getInstance());
tweet.setText(highlight(tweetStr));
username.setText(usernameStr);
scrName.setText(scrNameStr);
date.setText(dateString);
used_api.setText(apiName);
String favStr = Integer.toString(fav);
String rtStr = Integer.toString(rt);
txtFav.setText(favStr);
@ -204,38 +207,52 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
if(rtFlag) {
String retPrompt = "Retweet "+retweeter;
TextView userRetweet = (TextView)connect.findViewById(R.id.rt_info);
userRetweet.setText(retPrompt);
userRetweet.setOnClickListener(this);
userRetweet.setVisibility(View.VISIBLE);
}
if(verified) {
ImageView tweet_verify =(ImageView)connect.findViewById(R.id.tweet_verify);
tweet_verify.setVisibility(View.VISIBLE);
}
if(toggleImg) {
Picasso.with(ui.get()).load(profile_pb).into(profile_img);
if(medialinks != null && medialinks.length != 0) {
Button mediabutton = (Button)connect.findViewById(R.id.image_attach);
mediabutton.setVisibility(View.VISIBLE);
mediabutton.setOnClickListener(this);
}
}
Button retweetButton = (Button)connect.findViewById(R.id.rt_button_detail);
Button favoriteButton = (Button)connect.findViewById(R.id.fav_button_detail);
Button answer = (Button) connect.findViewById(R.id.answer_button);
setIcons(favoriteButton, retweetButton);
profile_img.setOnClickListener(this);
answer.setOnClickListener(this);
}
else if(mode == RETWEET) {
String rtStr = Integer.toString(rt);
TextView txtRet = (TextView)connect.findViewById(R.id.no_rt_detail);
Button retweetButton = (Button)connect.findViewById(R.id.rt_button_detail);
Button favoriteButton = (Button)connect.findViewById(R.id.fav_button_detail);
txtRet.setText(rtStr);
setIcons(favoriteButton, retweetButton);
}
else if(mode == FAVORITE) {
String favStr = Integer.toString(fav);
TextView txtFav = (TextView)connect.findViewById(R.id.no_fav_detail);
Button retweetButton = (Button)connect.findViewById(R.id.rt_button_detail);
Button favoriteButton = (Button)connect.findViewById(R.id.fav_button_detail);
txtFav.setText(favStr);
setIcons(favoriteButton, retweetButton);
}
else if(mode == LOAD_REPLY) {
replyList.setAdapter(tlAdp);
SwipeRefreshLayout ansReload = (SwipeRefreshLayout)connect.findViewById(R.id.answer_reload);
ansReload.setRefreshing(false);
String ansStr = Integer.toString(tlAdp.getItemCount());
TextView txtAns = (TextView)connect.findViewById(R.id.no_ans_detail);
txtAns.setText(ansStr);
}
else if(mode == DELETE) {
@ -244,6 +261,7 @@ public class StatusLoader extends AsyncTask<Long, Void, Long> implements View.On
}
else {
Toast.makeText(ui.get(), "Fehler beim Laden: "+errMSG, Toast.LENGTH_LONG).show();
SwipeRefreshLayout ansReload = (SwipeRefreshLayout)connect.findViewById(R.id.answer_reload);
if(ansReload.isRefreshing()) {
ansReload.setRefreshing(false);
}

View File

@ -20,7 +20,6 @@ import twitter4j.QueryResult;
import twitter4j.Relationship;
import twitter4j.Status;
import twitter4j.StatusUpdate;
import twitter4j.Trends;
import twitter4j.Twitter;
import twitter4j.TwitterException;
import twitter4j.TwitterFactory;
@ -36,8 +35,8 @@ import twitter4j.conf.ConfigurationBuilder;
*/
public class TwitterEngine {
private final String TWITTER_CONSUMER_KEY = "1JwXJbVrvGWrc9SSKPnnEWslJ";
private final String TWITTER_CONSUMER_SECRET = "xxx";
private final String TWITTER_CONSUMER_KEY = "0EKRHWYcakpCkl8Lr4OcBFMZb";
private final String TWITTER_CONSUMER_SECRET = "RQrf0uQus5v7IMuYgdlVeBuLw1ApRJhxcAMM8MyUVRh1nKSxnR";
private static TwitterEngine mTwitter;
private static long twitterID = -1L;

View File

@ -36,14 +36,7 @@ public class DatabaseAdapter {
for(int pos = 0; pos < stats.size(); pos++) {
Tweet tweet = stats.get(pos);
Tweet rtStat = tweet.embedded;
if(rtStat != null) {
storeStatus(rtStat, db,-1L);
storeStatus(tweet, db, rtStat.tweetID);
} else {
storeStatus(tweet, db, -1L);
}
storeStatus(tweet,db);
if(mode != TWEET) {
if(mode == HOME) {
@ -188,10 +181,25 @@ public class DatabaseAdapter {
location,isVerified,locked,link,banner,createdAt,following,follower);
}
public void storeStatus(Tweet tweet) {
storeStatus(tweet, dataHelper.getWritableDatabase());
}
private void storeStatus(Tweet tweet, SQLiteDatabase db, long retweetID) {
public void storeUSer(TwitterUser user) {
storeUser(user, dataHelper.getWritableDatabase());
}
private void storeStatus(Tweet tweet, SQLiteDatabase db) {
ContentValues status = new ContentValues();
Tweet rtStat = tweet.embedded;
long rtId = -1;
if(rtStat != null) {
storeStatus(rtStat, db);
rtId = rtStat.tweetID;
}
TwitterUser mUser = tweet.user;
storeUser(mUser,db);
@ -201,7 +209,7 @@ public class DatabaseAdapter {
status.put("tweet", tweet.tweet);
status.put("retweet", tweet.retweet);
status.put("favorite", tweet.favorit);
status.put("retweetID", retweetID);
status.put("retweetID", rtId);
status.put("source", tweet.source);
status.put("replyID", tweet.replyID);
status.put("replyname", tweet.replyName);

View File

@ -170,7 +170,7 @@ public class TweetDetail extends AppCompatActivity implements View.OnClickListen
tweetaction.setBackgroundColor(backgroundColor);
answer_list.setBackgroundColor(backgroundColor);
txtTw.setTextColor(fontColor);
new StatusLoader(this).execute(tweetID, StatusLoader.LOAD_DB);
mStat = new StatusLoader(this);
mReply = new StatusLoader(this);
mStat.execute(tweetID, StatusLoader.LOAD_TWEET);

View File

@ -55,7 +55,6 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
background = settings.getInt("background_color", 0xff0f114a);
font_color = settings.getInt("font_color", 0xffffffff);
highlight = settings.getInt("highlight_color", 0xffff00ff);
//imageload = settings.getBoolean("image_load",true);
homeList = (RecyclerView) findViewById(R.id.ht_list);
homeList.setLayoutManager(new LinearLayoutManager(this));
@ -202,6 +201,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
mTweets = new ProfileLoader(this);
mFavorits = new ProfileLoader(this);
mProfile = new ProfileLoader(this);
new ProfileLoader(this).execute(userId, ProfileLoader.LOAD_DB, 1L);
mProfile.execute(userId, ProfileLoader.GET_INFORMATION,1L);
mTweets.execute(userId, ProfileLoader.GET_TWEETS,1L);
mFavorits.execute(userId, ProfileLoader.GET_FAVS,1L);
@ -209,7 +209,7 @@ public class UserProfile extends AppCompatActivity implements View.OnClickListen
private void getConnection(long mode) {
Intent intent = new Intent(getApplicationContext(), UserDetail.class);
Intent intent = new Intent(this, UserDetail.class);
Bundle bundle = new Bundle();
bundle.putLong("userID",userId);
bundle.putLong("mode",mode);