From 3f317b231200d7af1fcb581ed0d3e401c4de8b50 Mon Sep 17 00:00:00 2001 From: nuclearfog Date: Mon, 27 Apr 2020 16:49:28 +0200 Subject: [PATCH] added profile banner view --- .../twidda/activity/UserProfile.java | 32 ++- .../twidda/backend/items/TwitterUser.java | 33 ++- app/src/main/res/layout/page_profile.xml | 265 ++++++++++-------- app/src/main/res/values-de-rDE/strings.xml | 1 + app/src/main/res/values/dimens.xml | 7 +- app/src/main/res/values/strings.xml | 1 + 6 files changed, 210 insertions(+), 129 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 02b55246..44518f61 100644 --- a/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java +++ b/app/src/main/java/org/nuclearfog/twidda/activity/UserProfile.java @@ -51,6 +51,7 @@ import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_UP; import static android.view.View.GONE; import static android.view.View.VISIBLE; +import static android.widget.LinearLayout.LayoutParams.WRAP_CONTENT; import static android.widget.Toast.LENGTH_SHORT; import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_LINK; import static org.nuclearfog.twidda.activity.MediaViewer.KEY_MEDIA_TYPE; @@ -80,8 +81,8 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, private TextView tweetTabTxt, favorTabTxt, txtUser, txtScrName; private TextView txtLocation, txtCreated, lnkTxt, bioTxt, follow_back; private Button following, follower; - private ImageView profile; - private View profile_head; + private ImageView profile, banner; + private View profile_head, profile_layer; private ViewPager pager; @Nullable @@ -112,10 +113,12 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, follower = findViewById(R.id.follower); lnkTxt = findViewById(R.id.links); profile = findViewById(R.id.profile_img); + banner = findViewById(R.id.profile_banner); txtUser = findViewById(R.id.profile_username); txtScrName = findViewById(R.id.profile_screenname); txtLocation = findViewById(R.id.location); profile_head = findViewById(R.id.profile_header); + profile_layer = findViewById(R.id.profile_layer); txtCreated = findViewById(R.id.profile_date); follow_back = findViewById(R.id.follow_back); pager = findViewById(R.id.profile_pager); @@ -159,6 +162,7 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, following.setOnClickListener(this); follower.setOnClickListener(this); profile.setOnClickListener(this); + banner.setOnClickListener(this); lnkTxt.setOnClickListener(this); bioTxt.setOnTouchListener(this); } @@ -427,6 +431,15 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, image.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE); startActivity(image); } + + case R.id.profile_banner: + if (user != null) { + Intent image = new Intent(this, MediaViewer.class); + image.putExtra(KEY_MEDIA_LINK, new String[]{user.getBannerLink() + "/1500x500"}); + image.putExtra(KEY_MEDIA_TYPE, MEDIAVIEWER_IMAGE); + startActivity(image); + } + break; } } @@ -509,8 +522,19 @@ public class UserProfile extends AppCompatActivity implements OnClickListener, lnkTxt.setVisibility(GONE); } if (settings.getImageLoad()) { - String link = user.getImageLink() + "_bigger"; - Picasso.get().load(link).into(profile); + if (user.hasBannerImg()) { + String bannerLink = user.getBannerLink() + "/600x200"; + Picasso.get().load(bannerLink).into(banner); + profile_layer.getLayoutParams().height = (int) getResources().getDimension(R.dimen.profile_banner_height); + profile_layer.requestLayout(); + } else { + profile_layer.getLayoutParams().height = WRAP_CONTENT; + profile_layer.requestLayout(); + } + if (user.hasProfileImage()) { + String imgLink = user.getImageLink() + "_bigger"; + Picasso.get().load(imgLink).into(profile); + } } } 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 d1d43712..f1a7096b 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 @@ -33,11 +33,20 @@ public class TwitterUser { userID = user.getId(); username = "" + user.getName(); screenname = '@' + user.getScreenName(); - profileImg = "" + user.getOriginalProfileImageURLHttps(); - bio = getBio(user); link = "" + user.getURLEntity().getExpandedURL(); location = "" + user.getLocation(); - bannerImg = "" + user.getProfileBannerURL(); + bio = getBio(user); + + String profileLink = user.getOriginalProfileImageURLHttps(); + String bannerLink = user.getProfileBannerURL(); + if (profileLink != null) + profileImg = user.getOriginalProfileImageURLHttps(); + else + profileImg = ""; + if (bannerLink != null && bannerLink.length() > 4) + bannerImg = bannerLink.substring(0, bannerLink.length() - 4); + else + bannerImg = ""; isVerified = user.isVerified(); isLocked = user.isProtected(); created = user.getCreatedAt().getTime(); @@ -198,6 +207,24 @@ public class TwitterUser { return favorCount; } + /** + * check if User has Profile image + * + * @return true if user has a profile image set + */ + public boolean hasProfileImage() { + return !profileImg.isEmpty(); + } + + /** + * check if user has a banner image + * + * @return true if user has a banner image set + */ + public boolean hasBannerImg() { + return !bannerImg.isEmpty(); + } + /** * Resolve shortened links from user description * @param user Twitter user diff --git a/app/src/main/res/layout/page_profile.xml b/app/src/main/res/layout/page_profile.xml index 2c8b17f7..f7bc42ed 100644 --- a/app/src/main/res/layout/page_profile.xml +++ b/app/src/main/res/layout/page_profile.xml @@ -31,157 +31,182 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" - android:paddingLeft="@dimen/padding_side" - android:paddingRight="@dimen/padding_side" android:visibility="invisible"> - + android:layout_height="wrap_content"> - - - - - + + android:gravity="bottom" + android:orientation="horizontal" + android:paddingLeft="@dimen/padding_side" + android:paddingRight="@dimen/padding_side"> - + + + + + + android:layout_marginStart="@dimen/margin_layout" + android:layout_marginLeft="@dimen/margin_layout" + android:orientation="vertical"> - + android:orientation="horizontal"> - + - + -