Fixed multi-line buttons

This commit is contained in:
ByteHamster 2020-01-28 14:45:18 +01:00
parent 3bbe6d55f7
commit cb9c999d43
2 changed files with 83 additions and 70 deletions

View File

@ -107,8 +107,12 @@ public class ItemFragment extends Fragment {
private ImageView imgvCover;
private ProgressBar progbarDownload;
private ProgressBar progbarLoading;
private Button butAction1;
private Button butAction2;
private TextView butAction1Text;
private TextView butAction2Text;
private ImageView butAction1Icon;
private ImageView butAction2Icon;
private View butAction1;
private View butAction2;
private Disposable disposable;
@ -178,6 +182,10 @@ public class ItemFragment extends Fragment {
progbarLoading = layout.findViewById(R.id.progbarLoading);
butAction1 = layout.findViewById(R.id.butAction1);
butAction2 = layout.findViewById(R.id.butAction2);
butAction1Icon = layout.findViewById(R.id.butAction1Icon);
butAction2Icon = layout.findViewById(R.id.butAction2Icon);
butAction1Text = layout.findViewById(R.id.butAction1Text);
butAction2Text = layout.findViewById(R.id.butAction2Text);
butAction1.setOnClickListener(v -> {
if (item == null) {
@ -301,18 +309,18 @@ public class ItemFragment extends Fragment {
}
FeedMedia media = item.getMedia();
@AttrRes int butAction1Icon = 0;
@StringRes int butAction1Text = 0;
@AttrRes int butAction2Icon = 0;
@StringRes int butAction2Text = 0;
@AttrRes int butAction1IconRes = 0;
@StringRes int butAction1TextRes = 0;
@AttrRes int butAction2IconRes = 0;
@StringRes int butAction2TextRes = 0;
if (media == null) {
if (!item.isPlayed()) {
butAction1Icon = R.attr.navigation_accept;
butAction1Text = R.string.mark_read_label;
butAction1IconRes = R.attr.navigation_accept;
butAction1TextRes = R.string.mark_read_label;
}
if (item.getLink() != null) {
butAction2Icon = R.attr.location_web_site;
butAction2Text = R.string.visit_website_label;
butAction2IconRes = R.attr.location_web_site;
butAction2TextRes = R.string.visit_website_label;
}
} else {
if (media.getDuration() > 0) {
@ -320,40 +328,40 @@ public class ItemFragment extends Fragment {
}
boolean isDownloading = DownloadRequester.getInstance().isDownloadingFile(media);
if (!media.isDownloaded()) {
butAction2Icon = R.attr.action_stream;
butAction2Text = R.string.stream_label;
butAction2IconRes = R.attr.action_stream;
butAction2TextRes = R.string.stream_label;
} else {
butAction2Icon = R.attr.content_discard;
butAction2Text = R.string.delete_label;
butAction2IconRes = R.attr.content_discard;
butAction2TextRes = R.string.delete_label;
}
if (isDownloading) {
butAction1Icon = R.attr.navigation_cancel;
butAction1Text = R.string.cancel_label;
butAction1IconRes = R.attr.navigation_cancel;
butAction1TextRes = R.string.cancel_label;
} else if (media.isDownloaded()) {
butAction1Icon = R.attr.av_play;
butAction1Text = R.string.play_label;
butAction1IconRes = R.attr.av_play;
butAction1TextRes = R.string.play_label;
} else {
butAction1Icon = R.attr.av_download;
butAction1Text = R.string.download_label;
butAction1IconRes = R.attr.av_download;
butAction1TextRes = R.string.download_label;
}
}
if (butAction1Icon != 0 && butAction1Text != 0) {
butAction1.setText(butAction1Text);
butAction1.setTransformationMethod(null);
if (butAction1IconRes != 0 && butAction1TextRes != 0) {
butAction1Text.setText(butAction1TextRes);
butAction1Text.setTransformationMethod(null);
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(butAction1Icon, typedValue, true);
butAction1.setCompoundDrawablesWithIntrinsicBounds(typedValue.resourceId, 0, 0, 0);
getContext().getTheme().resolveAttribute(butAction1IconRes, typedValue, true);
butAction1Icon.setImageResource(typedValue.resourceId);
butAction1.setVisibility(View.VISIBLE);
} else {
butAction1.setVisibility(View.INVISIBLE);
}
if (butAction2Icon != 0 && butAction2Text != 0) {
butAction2.setText(butAction2Text);
butAction2.setTransformationMethod(null);
if (butAction2IconRes != 0 && butAction2TextRes != 0) {
butAction2Text.setText(butAction2TextRes);
butAction2Text.setTransformationMethod(null);
TypedValue typedValue = new TypedValue();
getContext().getTheme().resolveAttribute(butAction2Icon, typedValue, true);
butAction2.setCompoundDrawablesWithIntrinsicBounds(typedValue.resourceId, 0, 0, 0);
getContext().getTheme().resolveAttribute(butAction2IconRes, typedValue, true);
butAction2Icon.setImageResource(typedValue.resourceId);
butAction2.setVisibility(View.VISIBLE);
} else {
butAction2.setVisibility(View.INVISIBLE);

View File

@ -105,50 +105,55 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
android:orientation="horizontal"
android:gravity="center_vertical"
tools:background="@android:color/holo_blue_bright">
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<Button
android:id="@+id/butAction1"
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:ellipsize="end"
android:drawablePadding="8dp"
android:textColor="?android:attr/textColorPrimary"
tools:text="Button 1"
tools:background="@android:color/holo_red_light" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<Button
android:id="@+id/butAction2"
style="?attr/buttonBarButtonStyle"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:drawablePadding="8dp"
android:ellipsize="end"
android:textColor="?android:attr/textColorPrimary"
tools:text="Button 2"
tools:background="@android:color/holo_orange_dark" />
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/butAction1"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:gravity="center">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/butAction1Icon"
android:layout_margin="12dp"
tools:src="@drawable/ic_settings_grey600_24dp"/>
<TextView
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:id="@+id/butAction1Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
tools:text="Button 1"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/butAction2"
android:orientation="horizontal"
android:background="?android:attr/selectableItemBackground"
android:gravity="center">
<ImageView
android:layout_width="24dp"
android:layout_height="24dp"
android:id="@+id/butAction2Icon"
android:layout_margin="12dp"
tools:src="@drawable/ic_settings_grey600_24dp"/>
<TextView
android:textAppearance="@style/TextAppearance.AppCompat.Button"
android:id="@+id/butAction2Text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorPrimary"
tools:text="Button 2"/>
</LinearLayout>
</LinearLayout>
<View