From 65fd98fd79f66203b10a37f93dc440b7034e3033 Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Wed, 29 Apr 2020 02:39:52 +0200 Subject: [PATCH] modified profile layout, fixed crash, bug fix --- .../twidda/activity/UserProfile.java | 7 +- .../twidda/backend/items/Tweet.java | 11 +-- .../twidda/backend/items/TwitterUser.java | 67 +++++++++---------- app/src/main/res/layout/page_profile.xml | 11 +-- app/src/main/res/values/dimens.xml | 5 +- 5 files changed, 54 insertions(+), 47 deletions(-) diff --git a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java index 44518f61..6113a673 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java @@ -71,8 +71,9 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, OnTouchListener, OnTagClickListener, OnTabSelectedListener { public static final String KEY_PROFILE_ID = "profile_uid"; - private static final int REQUEST_PROFILE_CHANGED = 1; public static final int RETURN_PROFILE_CHANGED = 2; + private static final int REQUEST_PROFILE_CHANGED = 1; + private static final int TRANSPARENCY = 0xafffffff; private ProfileLoader profileAsync; private FragmentAdapter adapter; @@ -130,6 +131,9 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, getSupportActionBar().setDisplayShowTitleEnabled(false); FontTool.setViewFontAndColor(settings, root); + txtUser.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY); + txtScrName.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY); + follow_back.setBackgroundColor(settings.getBackgroundColor() & TRANSPARENCY); bioTxt.setMovementMethod(LinkMovementMethod.getInstance()); tab.setSelectedTabIndicatorColor(settings.getHighlightColor()); bioTxt.setLinkTextColor(settings.getHighlightColor()); @@ -431,6 +435,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, image.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE); startActivity(image); } + break; case R.id.profile_banner: if (user != null) { diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/items/Tweet.java b/app/src/main/java/org/nuclearfog/twidda/backend/items/Tweet.java index 97c2e06a..526da2f1 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/items/Tweet.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/items/Tweet.java @@ -121,23 +121,24 @@ public class Tweet { public Tweet(long tweetID, int retweetCount, int favoriteCount, TwitterUser user, String tweet, long time, String replyName, long replyUserId, String[] medias, String source, long replyID, Tweet embedded, long myRetweetId, boolean retweeted, boolean favored, String place, String geo) { + this.tweetID = tweetID; this.user = user; this.retweetCount = retweetCount; this.favoriteCount = favoriteCount; - this.tweet = tweet; this.time = time; this.replyID = replyID; this.embedded = embedded; - this.replyName = replyName; this.medias = medias; - this.source = source; this.retweeted = retweeted; this.favored = favored; this.myRetweetId = myRetweetId; this.replyUserId = replyUserId; - this.locationName = place; - this.locationCoordinates = geo; + this.tweet = tweet != null ? tweet : ""; + this.source = source != null ? source : ""; + this.replyName = replyName != null ? replyName : ""; + this.locationName = place != null ? place : ""; + this.locationCoordinates = geo != null ? geo : ""; } /** diff --git a/app/src/main/java/org/nuclearfog/twidda/backend/items/TwitterUser.java b/app/src/main/java/org/nuclearfog/twidda/backend/items/TwitterUser.java index f1a7096b..6baa31a7 100644 --- a/app/src/main/java/org/nuclearfog/twidda/backend/items/TwitterUser.java +++ b/app/src/main/java/org/nuclearfog/twidda/backend/items/TwitterUser.java @@ -30,23 +30,37 @@ public class TwitterUser { private final String bannerImg; public TwitterUser(User user) { - userID = user.getId(); - username = "" + user.getName(); - screenname = '@' + user.getScreenName(); - link = "" + user.getURLEntity().getExpandedURL(); - location = "" + user.getLocation(); - bio = getBio(user); - - String profileLink = user.getOriginalProfileImageURLHttps(); + String username = user.getName(); + String screenname = user.getScreenName(); + String link = user.getURLEntity().getExpandedURL(); + String location = user.getLocation(); + String profileImg = user.getOriginalProfileImageURLHttps(); String bannerLink = user.getProfileBannerURL(); - if (profileLink != null) - profileImg = user.getOriginalProfileImageURLHttps(); - else - profileImg = ""; + String bio = user.getDescription(); + + this.username = username != null ? username : ""; + this.screenname = screenname != null ? '@' + user.getScreenName() : ""; + this.link = link != null ? link : ""; + this.location = location != null ? location : ""; + this.profileImg = profileImg != null ? profileImg : ""; + + if (bio != null && !bio.isEmpty()) { + URLEntity[] entities = user.getDescriptionURLEntities(); + StringBuilder bioBuilder = new StringBuilder(user.getDescription()); + for (int i = entities.length - 1; i >= 0; i--) { + URLEntity entity = entities[i]; + bioBuilder.replace(entity.getStart(), entity.getEnd(), entity.getExpandedURL()); + } + this.bio = bioBuilder.toString(); + } else { + this.bio = ""; + } if (bannerLink != null && bannerLink.length() > 4) bannerImg = bannerLink.substring(0, bannerLink.length() - 4); else bannerImg = ""; + + userID = user.getId(); isVerified = user.isVerified(); isLocked = user.isProtected(); created = user.getCreatedAt().getTime(); @@ -62,13 +76,13 @@ public class TwitterUser { long created, int following, int follower, int tweetCount, int favorCount) { 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.username = username != null ? username : ""; + this.screenname = screenname != null ? screenname : ""; + this.profileImg = profileImg != null ? profileImg : ""; + this.bio = bio != null ? bio : ""; + this.link = link != null ? link : ""; + this.location = location != null ? location : ""; + this.bannerImg = bannerImg != null ? bannerImg : ""; this.isVerified = isVerified; this.isLocked = isLocked; this.created = created; @@ -225,21 +239,6 @@ public class TwitterUser { return !bannerImg.isEmpty(); } - /** - * Resolve shortened links from user description - * @param user Twitter user - * @return Description String - */ - private String getBio(User user) { - URLEntity[] entities = user.getDescriptionURLEntities(); - StringBuilder bio = new StringBuilder("" + user.getDescription()); - for (int i = entities.length - 1; i >= 0; i--) { - URLEntity entity = entities[i]; - bio.replace(entity.getStart(), entity.getEnd(), entity.getExpandedURL()); - } - return bio.toString(); - } - @NonNull @Override public String toString() { diff --git a/app/src/main/res/layout/page_profile.xml b/app/src/main/res/layout/page_profile.xml index f7bc42ed..22a7cc52 100644 --- a/app/src/main/res/layout/page_profile.xml +++ b/app/src/main/res/layout/page_profile.xml @@ -77,9 +77,10 @@ 5dp 1dp 1dp - 155dp + 140dp 2dp - 40dp + 5dp + 2dp \ No newline at end of file