From afaa4e02b098f4ec1cac7e49ec629ceed6b0dfeb Mon Sep 17 00:00:00 2001 From: NudeDude Date: Fri, 27 Jul 2018 19:23:46 +0200 Subject: [PATCH] major bugfixes --- .../twidda/backend/ProfileLoader.java | 103 ++++++++++-------- .../twidda/backend/StatusLoader.java | 11 +- .../twidda/backend/TwitterEngine.java | 30 +++-- .../twidda/database/DatabaseAdapter.java | 10 +- app/src/main/res/drawable/favorite_tweet.xml | 4 + app/src/main/res/layout/item_tweet.xml | 18 +-- app/src/main/res/layout/loginpage.xml | 2 +- app/src/main/res/layout/profilepage.xml | 9 +- app/src/main/res/layout/settingpage.xml | 16 ++- app/src/main/res/layout/tweetpage.xml | 12 +- app/src/main/res/layout/tweetwindow.xml | 1 + 11 files changed, 115 insertions(+), 101 deletions(-) create mode 100644 app/src/main/res/drawable/favorite_tweet.xml diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java index 5200249f..7525626f 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/ProfileLoader.java @@ -41,7 +41,7 @@ public class ProfileLoader extends AsyncTask { private static final long IGNORE = 7; private String screenName, username, description, location, follower, following; - private String /* bannerLink,*/ profileImage, link, dateString; + private String profileImage, link, dateString; private TimelineRecycler homeTl, homeFav; private WeakReference ui; private TwitterEngine mTwitter; @@ -54,7 +54,7 @@ public class ProfileLoader extends AsyncTask { private boolean isFollowed = false; private boolean isVerified = false; private boolean isLocked = false; - private boolean muted = false; + private boolean blocked = false; /** * @param context Context to Activity @@ -91,55 +91,53 @@ public class ProfileLoader extends AsyncTask { long id = 1L; try { isHome = homeId == userId; - if(!isHome && MODE != LOAD_DB) + if(!isHome && (MODE==ACTION_FOLLOW||MODE==ACTION_MUTE||MODE==GET_INFORMATION)) { boolean connection[] = mTwitter.getConnection(userId); isFollowing = connection[0]; isFollowed = connection[1]; - muted = connection[2]; + blocked = connection[2]; } - if(MODE == GET_INFORMATION || MODE == LOAD_DB) - { - TwitterUser user; - if(MODE == LOAD_DB) { - user = new DatabaseAdapter(ui.get()).getUser(userId); - if(user == null) - return IGNORE; - } else { - user = mTwitter.getUser(userId); - new DatabaseAdapter(ui.get()).storeUser(user); - } - screenName = user.screenname; - username = user.username; - description = user.bio; - location = user.location; - isVerified = user.isVerified; - isLocked = user.isLocked; - link = user.link; - follower = Integer.toString(user.follower); - following = Integer.toString(user.following); - // bannerLink = user.bannerImg; - profileImage = user.profileImg; - Date d = new Date(user.created); - SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY); - dateString = "seit "+ sdf.format(d); - description = description.replace('\n', ' '); + + TwitterUser user; + DatabaseAdapter database = new DatabaseAdapter(ui.get()); + if(MODE == GET_INFORMATION) { + user = mTwitter.getUser(userId); + database.storeUser(user); + } else { + user = database.getUser(userId); + if(user == null) + return IGNORE; } - else if(MODE == GET_TWEETS) + screenName = user.screenname; + username = user.username; + description = user.bio; + location = user.location; + isVerified = user.isVerified; + isLocked = user.isLocked; + link = user.link; + follower = Integer.toString(user.follower); + following = Integer.toString(user.following); + profileImage = user.profileImg; + Date d = new Date(user.created); + SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy, HH:mm:ss", Locale.GERMANY); + dateString = "seit "+ sdf.format(d); + description = description.replace('\n', ' '); + + if(MODE == GET_TWEETS) { - DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get()); List tweets; if(homeTl.getItemCount() > 0) { id = homeTl.getItemId(0); tweets = mTwitter.getUserTweets(userId,args[2],id); - tweetDb.storeUserTweets(tweets); + database.storeUserTweets(tweets); tweets.addAll(homeTl.getData()); } else { - tweets = tweetDb.getUserTweets(userId); - if(tweets.size() == 0) { + tweets = database.getUserTweets(userId); + if(tweets.size() == 0 && !isLocked) { tweets = mTwitter.getUserTweets(userId,args[2],id); - tweetDb.storeUserTweets(tweets); + database.storeUserTweets(tweets); } } homeTl.setData(tweets); @@ -148,19 +146,18 @@ public class ProfileLoader extends AsyncTask { } else if(MODE == GET_FAVS) { - DatabaseAdapter tweetDb = new DatabaseAdapter(ui.get()); List favorits; if(homeFav.getItemCount() > 0) { id = homeFav.getItemId(0); favorits = mTwitter.getUserFavs(userId,args[2],id); - tweetDb.storeUserFavs(favorits,userId); + database.storeUserFavs(favorits,userId); favorits.addAll(homeFav.getData()); } else { - favorits = tweetDb.getUserFavs(userId); - if(favorits.size() == 0) { + favorits = database.getUserFavs(userId); + if(favorits.size() == 0 && !isLocked) { favorits = mTwitter.getUserFavs(userId,args[2],id); - tweetDb.storeUserFavs(favorits,userId); + database.storeUserFavs(favorits,userId); } } homeFav.setData(favorits); @@ -169,11 +166,23 @@ public class ProfileLoader extends AsyncTask { } else if(MODE == ACTION_FOLLOW) { - isFollowing = mTwitter.toggleFollow(userId); + if(isFollowing) { + mTwitter.followAction(userId,false); + isFollowing = false; + } else { + mTwitter.followAction(userId,true); + isFollowing = true; + } } else if(MODE == ACTION_MUTE) { - muted = mTwitter.toggleBlock(userId); + if(blocked) { + mTwitter.blockAction(userId,false); + blocked = false; + } else { + mTwitter.blockAction(userId,true); + blocked = true; + } } } catch (TwitterException err) { int errCode = err.getErrorCode(); @@ -268,7 +277,7 @@ public class ProfileLoader extends AsyncTask { } else if(mode == ACTION_MUTE) { String text; - if(muted) + if(blocked) text = "gesperrt!"; else text = "entsperrt!"; @@ -282,7 +291,7 @@ public class ProfileLoader extends AsyncTask { tweetsReload.setRefreshing(false); favoritsReload.setRefreshing(false); } - if(!isHome) { + if(!isHome && (mode==ACTION_FOLLOW||mode==ACTION_MUTE||mode==GET_INFORMATION)) { Toolbar tool = connect.findViewById(R.id.profile_toolbar); if(tool.getMenu().size() >= 2) { MenuItem followIcon = tool.getMenu().getItem(1); @@ -294,12 +303,14 @@ public class ProfileLoader extends AsyncTask { followIcon.setIcon(R.drawable.follow); followIcon.setTitle("folgen"); } - if (muted) { + if (blocked) { blockIcon.setIcon(R.drawable.block_enabled); blockIcon.setTitle("entblocken"); + followIcon.setVisible(false); } else { blockIcon.setIcon(R.drawable.block); blockIcon.setTitle("block"); + followIcon.setVisible(true); } } } diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java index cefa1bc4..aae36973 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/StatusLoader.java @@ -56,7 +56,7 @@ public class StatusLoader extends AsyncTask implements View.On private String errorMessage = ""; private boolean retweeted, favorited, toggleImg, verified; private boolean rtFlag = false; - private long tweetReplyID,tweetID, userID, retweeterID; + private long tweetReplyID,tweetID, userID, retweeterID, homeId; private int rtCount, favCount; private int highlight, font; @@ -68,6 +68,7 @@ public class StatusLoader extends AsyncTask implements View.On font = settings.getFontColor(); highlight = settings.getHighlightColor(); toggleImg = settings.loadImages(); + homeId = settings.getUserId(); ui = new WeakReference<>((TweetDetail)c); RecyclerView replyList = ui.get().findViewById(R.id.answer_list); answerAdapter = (TimelineRecycler) replyList.getAdapter(); @@ -99,6 +100,7 @@ public class StatusLoader extends AsyncTask implements View.On } else { tweet = mTwitter.getStatus(tweetID); } + if (tweet.embedded != null) { retweeter = tweet.user.screenname; retweeterID = tweet.user.userID; @@ -130,7 +132,7 @@ public class StatusLoader extends AsyncTask implements View.On rtCount++; retweeted = true; } else { - if(rtCount>0) + if(rtCount > 0) rtCount--; retweeted = false; } @@ -141,9 +143,10 @@ public class StatusLoader extends AsyncTask implements View.On favCount++; favorited = true; } else { - if(rtCount>0) + if(favCount > 0) favCount--; favorited = false; + database.removeFavorite(tweetID,homeId); } } else if(MODE == LOAD_REPLY) { @@ -162,7 +165,7 @@ public class StatusLoader extends AsyncTask implements View.On } else if(MODE == DELETE) { mTwitter.deleteTweet(tweetID); - new DatabaseAdapter(ui.get()).removeStatus(tweetID); + database.removeStatus(tweetID); } if(MODE == LOAD_TWEET || MODE == RETWEET || MODE == FAVORITE) { if(database.containStatus(tweetID)) diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java index 8af3c922..6cc5a39a 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/TwitterEngine.java @@ -277,34 +277,30 @@ public class TwitterEngine { /** * Switch following User - * @param id Uder ID - * @return follow status + * @param userId User ID + * @param action using action * @throws TwitterException if Access is unavailable */ - public boolean toggleFollow(long id) throws TwitterException { - if(getConnection(id)[0]) { - twitter.destroyFriendship(id); - return false; + public void followAction(long userId, boolean action) throws TwitterException { + if(action) { + twitter.createFriendship(userId); } else { - twitter.createFriendship(id); - return true; + twitter.destroyFriendship(userId); } } /** * Switch blocking User - * @param id User ID - * @return Block Status + * @param userId User ID + * @param action using action * @throws TwitterException if Access is unavailable */ - public boolean toggleBlock(long id) throws TwitterException { - if(getConnection(id)[2]){ - twitter.destroyBlock(id); - return false; + public void blockAction(long userId, boolean action) throws TwitterException { + if(action){ + twitter.createBlock(userId); } else { - twitter.createBlock(id); - return true; + twitter.destroyBlock(userId); } } @@ -504,7 +500,7 @@ public class TwitterEngine { try { Status embedded = status.getRetweetedStatus(); if(embedded != null) { - Tweet retweet = getTweet(embedded, null); + Tweet retweet = getTweet(embedded,null); Tweet tweet = getTweet(status, retweet); result.add(tweet); } else { diff --git a/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java b/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java index 9b76820e..18f719a6 100644 --- a/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java +++ b/app/src/main/java/org/nuclearfog/twidda/database/DatabaseAdapter.java @@ -48,7 +48,7 @@ public class DatabaseAdapter { for(int pos = 0; pos < fav.size(); pos++) { Tweet tweet = fav.get(pos); storeStatus(tweet,0,db); - ContentValues favTable = new ContentValues(); + ContentValues favTable = new ContentValues(); favTable.put("tweetID", tweet.tweetID); favTable.put("userID", ownerId); db.insertWithOnConflict("favorit",null,favTable,CONFLICT_IGNORE); @@ -285,12 +285,18 @@ public class DatabaseAdapter { * Lösche Tweet * @param id Tweet ID */ - public void removeStatus(final long id) { + public void removeStatus(long id) { SQLiteDatabase db = dataHelper.getWritableDatabase(); db.delete("tweet", "tweetID="+id, null); db.close(); } + public void removeFavorite(long tweetId,long ownerId) { + SQLiteDatabase db = dataHelper.getWritableDatabase(); + db.delete("favorit","tweetID="+tweetId+" AND userID="+ownerId,null); + db.close(); + } + /** * Suche Tweet in Datenbank diff --git a/app/src/main/res/drawable/favorite_tweet.xml b/app/src/main/res/drawable/favorite_tweet.xml new file mode 100644 index 00000000..c8fd77d9 --- /dev/null +++ b/app/src/main/res/drawable/favorite_tweet.xml @@ -0,0 +1,4 @@ + + + diff --git a/app/src/main/res/layout/item_tweet.xml b/app/src/main/res/layout/item_tweet.xml index 9d202928..0180be7d 100644 --- a/app/src/main/res/layout/item_tweet.xml +++ b/app/src/main/res/layout/item_tweet.xml @@ -100,38 +100,28 @@ android:id="@+id/retweeter" android:layout_width="120dp" android:layout_height="match_parent" - android:layout_marginEnd="5dp" android:singleLine="true" android:textSize="12sp" /> -