From 656644b7cbc79a2411692e92a1f57db2259ada23 Mon Sep 17 00:00:00 2001 From: Ivan Kupalov Date: Tue, 25 Feb 2020 19:57:28 +0100 Subject: [PATCH] Make image in BackgroundMessageView adapt to the height, fix #1618 (#1649) * Make image in BackgroundMessageView adapt to the height, fix #1618 * Hide filters panel when showing status view in notifications --- .../tusky/fragment/NotificationsFragment.java | 8 +++++++- .../tusky/view/BackgroundMessageView.kt | 2 +- app/src/main/res/layout/activity_lists.xml | 4 +++- app/src/main/res/layout/fragment_timeline.xml | 3 ++- .../layout/fragment_timeline_notifications.xml | 2 +- .../main/res/layout/view_background_message.xml | 17 +++++++++++++++-- 6 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index d82a86a7..64805a6a 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -167,6 +167,7 @@ public class NotificationsFragment extends SFragment implements private boolean alwaysShowSensitiveMedia; private boolean alwaysOpenSpoiler; private boolean showNotificationsFilter; + private boolean showingError; // Each element is either a Notification for loading data or a Placeholder private final PairedList, NotificationViewData> notifications @@ -280,7 +281,7 @@ public class NotificationsFragment extends SFragment implements private void updateFilterVisibility() { CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams(); - if (showNotificationsFilter) { + if (showNotificationsFilter && !showingError && !notifications.isEmpty()) { appBarOptions.setExpanded(true, false); appBarOptions.setVisibility(View.VISIBLE); //Set content behaviour to hide filter on scroll @@ -392,6 +393,7 @@ public class NotificationsFragment extends SFragment implements @Override public void onRefresh() { this.statusView.setVisibility(View.GONE); + this.showingError = false; Either first = CollectionsKt.firstOrNull(this.notifications); String topId; if (first != null && first.isRight()) { @@ -669,6 +671,7 @@ public class NotificationsFragment extends SFragment implements //Show friend elephant this.statusView.setVisibility(View.VISIBLE); this.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null); + updateFilterVisibility(); //Update adapter updateAdapter(); @@ -994,6 +997,7 @@ public class NotificationsFragment extends SFragment implements } else { swipeRefreshLayout.setEnabled(true); } + updateFilterVisibility(); swipeRefreshLayout.setRefreshing(false); progressBar.setVisibility(View.GONE); } @@ -1009,6 +1013,7 @@ public class NotificationsFragment extends SFragment implements } else if (this.notifications.isEmpty()) { this.statusView.setVisibility(View.VISIBLE); swipeRefreshLayout.setEnabled(false); + this.showingError = true; if (exception instanceof IOException) { this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> { this.progressBar.setVisibility(View.VISIBLE); @@ -1022,6 +1027,7 @@ public class NotificationsFragment extends SFragment implements return Unit.INSTANCE; }); } + updateFilterVisibility(); } Log.e(TAG, "Fetch failure: " + exception.getMessage()); diff --git a/app/src/main/java/com/keylesspalace/tusky/view/BackgroundMessageView.kt b/app/src/main/java/com/keylesspalace/tusky/view/BackgroundMessageView.kt index e39566f4..4789ac3c 100644 --- a/app/src/main/java/com/keylesspalace/tusky/view/BackgroundMessageView.kt +++ b/app/src/main/java/com/keylesspalace/tusky/view/BackgroundMessageView.kt @@ -39,7 +39,7 @@ class BackgroundMessageView @JvmOverloads constructor( fun setup(@DrawableRes imageRes: Int, @StringRes messageRes: Int, clickListener: ((v: View) -> Unit)? = null) { messageTextView.setText(messageRes) - messageTextView.setCompoundDrawablesWithIntrinsicBounds(0, imageRes, 0, 0) + imageView.setImageResource(imageRes) button.setOnClickListener(clickListener) button.visible(clickListener != null) } diff --git a/app/src/main/res/layout/activity_lists.xml b/app/src/main/res/layout/activity_lists.xml index 45b01066..663d90d2 100644 --- a/app/src/main/res/layout/activity_lists.xml +++ b/app/src/main/res/layout/activity_lists.xml @@ -39,7 +39,9 @@ app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" - app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@id/appbar" + tools:visibility="visible" + app:layout_constrainedHeight="true" /> diff --git a/app/src/main/res/layout/fragment_timeline.xml b/app/src/main/res/layout/fragment_timeline.xml index 0b5c57b8..79f7fdb3 100644 --- a/app/src/main/res/layout/fragment_timeline.xml +++ b/app/src/main/res/layout/fragment_timeline.xml @@ -36,7 +36,8 @@ app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" - tools:visibility="visible" /> + tools:visibility="visible" + app:layout_constrainedHeight="true" /> + xmlns:tools="http://schemas.android.com/tools" + tools:gravity="center_horizontal" + tools:orientation="vertical" + tools:parentTag="android.widget.LinearLayout"> + +