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
This commit is contained in:
Ivan Kupalov 2020-02-25 19:57:28 +01:00 committed by GitHub
parent d9c802982e
commit 656644b7cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 29 additions and 7 deletions

View File

@ -167,6 +167,7 @@ public class NotificationsFragment extends SFragment implements
private boolean alwaysShowSensitiveMedia; private boolean alwaysShowSensitiveMedia;
private boolean alwaysOpenSpoiler; private boolean alwaysOpenSpoiler;
private boolean showNotificationsFilter; private boolean showNotificationsFilter;
private boolean showingError;
// Each element is either a Notification for loading data or a Placeholder // Each element is either a Notification for loading data or a Placeholder
private final PairedList<Either<Placeholder, Notification>, NotificationViewData> notifications private final PairedList<Either<Placeholder, Notification>, NotificationViewData> notifications
@ -280,7 +281,7 @@ public class NotificationsFragment extends SFragment implements
private void updateFilterVisibility() { private void updateFilterVisibility() {
CoordinatorLayout.LayoutParams params = CoordinatorLayout.LayoutParams params =
(CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams(); (CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams();
if (showNotificationsFilter) { if (showNotificationsFilter && !showingError && !notifications.isEmpty()) {
appBarOptions.setExpanded(true, false); appBarOptions.setExpanded(true, false);
appBarOptions.setVisibility(View.VISIBLE); appBarOptions.setVisibility(View.VISIBLE);
//Set content behaviour to hide filter on scroll //Set content behaviour to hide filter on scroll
@ -392,6 +393,7 @@ public class NotificationsFragment extends SFragment implements
@Override @Override
public void onRefresh() { public void onRefresh() {
this.statusView.setVisibility(View.GONE); this.statusView.setVisibility(View.GONE);
this.showingError = false;
Either<Placeholder, Notification> first = CollectionsKt.firstOrNull(this.notifications); Either<Placeholder, Notification> first = CollectionsKt.firstOrNull(this.notifications);
String topId; String topId;
if (first != null && first.isRight()) { if (first != null && first.isRight()) {
@ -669,6 +671,7 @@ public class NotificationsFragment extends SFragment implements
//Show friend elephant //Show friend elephant
this.statusView.setVisibility(View.VISIBLE); this.statusView.setVisibility(View.VISIBLE);
this.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null); this.statusView.setup(R.drawable.elephant_friend_empty, R.string.message_empty, null);
updateFilterVisibility();
//Update adapter //Update adapter
updateAdapter(); updateAdapter();
@ -994,6 +997,7 @@ public class NotificationsFragment extends SFragment implements
} else { } else {
swipeRefreshLayout.setEnabled(true); swipeRefreshLayout.setEnabled(true);
} }
updateFilterVisibility();
swipeRefreshLayout.setRefreshing(false); swipeRefreshLayout.setRefreshing(false);
progressBar.setVisibility(View.GONE); progressBar.setVisibility(View.GONE);
} }
@ -1009,6 +1013,7 @@ public class NotificationsFragment extends SFragment implements
} else if (this.notifications.isEmpty()) { } else if (this.notifications.isEmpty()) {
this.statusView.setVisibility(View.VISIBLE); this.statusView.setVisibility(View.VISIBLE);
swipeRefreshLayout.setEnabled(false); swipeRefreshLayout.setEnabled(false);
this.showingError = true;
if (exception instanceof IOException) { if (exception instanceof IOException) {
this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> { this.statusView.setup(R.drawable.elephant_offline, R.string.error_network, __ -> {
this.progressBar.setVisibility(View.VISIBLE); this.progressBar.setVisibility(View.VISIBLE);
@ -1022,6 +1027,7 @@ public class NotificationsFragment extends SFragment implements
return Unit.INSTANCE; return Unit.INSTANCE;
}); });
} }
updateFilterVisibility();
} }
Log.e(TAG, "Fetch failure: " + exception.getMessage()); Log.e(TAG, "Fetch failure: " + exception.getMessage());

View File

@ -39,7 +39,7 @@ class BackgroundMessageView @JvmOverloads constructor(
fun setup(@DrawableRes imageRes: Int, @StringRes messageRes: Int, fun setup(@DrawableRes imageRes: Int, @StringRes messageRes: Int,
clickListener: ((v: View) -> Unit)? = null) { clickListener: ((v: View) -> Unit)? = null) {
messageTextView.setText(messageRes) messageTextView.setText(messageRes)
messageTextView.setCompoundDrawablesWithIntrinsicBounds(0, imageRes, 0, 0) imageView.setImageResource(imageRes)
button.setOnClickListener(clickListener) button.setOnClickListener(clickListener)
button.visible(clickListener != null) button.visible(clickListener != null)
} }

View File

@ -39,7 +39,9 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toBottomOf="@id/appbar"
tools:visibility="visible"
app:layout_constrainedHeight="true" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -36,7 +36,8 @@
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:visibility="visible" /> tools:visibility="visible"
app:layout_constrainedHeight="true" />
<androidx.core.widget.ContentLoadingProgressBar <androidx.core.widget.ContentLoadingProgressBar
android:id="@+id/topProgressBar" android:id="@+id/topProgressBar"

View File

@ -53,7 +53,7 @@
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout" android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior"> app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView

View File

@ -1,6 +1,19 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android" <merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"> xmlns:tools="http://schemas.android.com/tools"
tools:gravity="center_horizontal"
tools:orientation="vertical"
tools:parentTag="android.widget.LinearLayout">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="4dp"
android:layout_weight="1"
android:contentDescription="@null"
android:scaleType="centerInside"
tools:src="@drawable/elephant_offline" />
<TextView <TextView
android:id="@+id/messageTextView" android:id="@+id/messageTextView"
@ -13,7 +26,6 @@
android:paddingRight="16dp" android:paddingRight="16dp"
android:textAlignment="center" android:textAlignment="center"
android:textSize="?attr/status_text_medium" android:textSize="?attr/status_text_medium"
tools:drawableTop="@drawable/elephant_offline"
tools:text="@string/error_network" /> tools:text="@string/error_network" />
<Button <Button
@ -22,5 +34,6 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
android:layout_marginBottom="4dp"
android:text="@string/action_retry" /> android:text="@string/action_retry" />
</merge> </merge>