Fix notification policy layout for long strings

This commit is contained in:
Grishka 2022-04-29 17:38:48 +03:00
parent a58a279e8c
commit 10a5bf0a82
3 changed files with 45 additions and 9 deletions

View File

@ -9,8 +9,8 @@ android {
applicationId "org.joinmastodon.android"
minSdk 23
targetSdk 31
versionCode 33
versionName "1.0.3"
versionCode 34
versionName "1.0.4"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -0,0 +1,37 @@
package org.joinmastodon.android.ui.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
public class AutoOrientationLinearLayout extends LinearLayout{
public AutoOrientationLinearLayout(Context context){
this(context, null);
}
public AutoOrientationLinearLayout(Context context, AttributeSet attrs){
this(context, attrs, 0);
}
public AutoOrientationLinearLayout(Context context, AttributeSet attrs, int defStyle){
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
int hPadding=getPaddingLeft()+getPaddingRight();
int childrenTotalWidth=0;
for(int i=0;i<getChildCount();i++){
View child=getChildAt(i);
measureChildWithMargins(child, widthMeasureSpec, hPadding, heightMeasureSpec, 0);
childrenTotalWidth+=child.getMeasuredWidth();
}
if(childrenTotalWidth>MeasureSpec.getSize(widthMeasureSpec)-hPadding){
setOrientation(VERTICAL);
}else{
setOrientation(HORIZONTAL);
}
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}
}

View File

@ -1,16 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<org.joinmastodon.android.ui.views.AutoOrientationLinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="32dp"
android:layout_height="wrap_content"
android:layoutDirection="locale"
android:paddingLeft="16dp"
android:paddingRight="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:gravity="center_vertical"
android:textColor="?android:textColorPrimary"
android:textSize="20dp"
@ -19,12 +20,10 @@
android:ellipsize="end"
android:text="@string/notify_me_when"/>
<!-- TODO make this LL vertical when the button doesn't fit -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginStart="8dp"
android:layout_height="32dp"
android:background="@drawable/bg_inline_button"
android:textColor="?android:textColorPrimary"
android:textSize="20dp"
@ -37,4 +36,4 @@
android:ellipsize="middle"
tools:text="@string/notify_followed"/>
</LinearLayout>
</org.joinmastodon.android.ui.views.AutoOrientationLinearLayout>