diff options
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java | 113 | ||||
-rw-r--r-- | app/src/main/res/layout/feedinfo.xml | 63 |
2 files changed, 77 insertions, 99 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java index f46f685f9..aabb0852e 100644 --- a/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/ui/screen/feed/FeedInfoFragment.java @@ -15,8 +15,6 @@ import android.view.LayoutInflater; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.contract.ActivityResultContracts; @@ -27,13 +25,12 @@ import androidx.documentfile.provider.DocumentFile; import androidx.fragment.app.Fragment; import com.bumptech.glide.Glide; import com.bumptech.glide.request.RequestOptions; -import com.google.android.material.appbar.AppBarLayout; -import com.google.android.material.appbar.CollapsingToolbarLayout; import com.google.android.material.appbar.MaterialToolbar; import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.snackbar.Snackbar; import de.danoeh.antennapod.R; import de.danoeh.antennapod.activity.MainActivity; +import de.danoeh.antennapod.databinding.FeedinfoBinding; import de.danoeh.antennapod.ui.TransitionEffect; import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.storage.database.FeedDatabaseWriter; @@ -69,17 +66,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu private Feed feed; private Disposable disposable; - private ImageView imgvCover; - private TextView txtvTitle; - private TextView txtvDescription; - private TextView txtvFundingUrl; - private TextView lblSupport; - private TextView txtvUrl; - private TextView txtvAuthorHeader; - private ImageView imgvBackground; - private View infoContainer; - private View header; - private MaterialToolbar toolbar; + private FeedinfoBinding viewBinding; public static FeedInfoFragment newInstance(Feed feed) { FeedInfoFragment fragment = new FeedInfoFragment(); @@ -110,58 +97,45 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { - View root = inflater.inflate(R.layout.feedinfo, null); - toolbar = root.findViewById(R.id.toolbar); - toolbar.setTitle(""); - toolbar.inflateMenu(R.menu.feedinfo); - toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); - toolbar.setOnMenuItemClickListener(this); + viewBinding = FeedinfoBinding.inflate(inflater); + viewBinding.toolbar.setTitle(""); + viewBinding.toolbar.inflateMenu(R.menu.feedinfo); + viewBinding.toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); + viewBinding.toolbar.setOnMenuItemClickListener(this); refreshToolbarState(); - AppBarLayout appBar = root.findViewById(R.id.appBar); - CollapsingToolbarLayout collapsingToolbar = root.findViewById(R.id.collapsing_toolbar); - ToolbarIconTintManager iconTintManager = new ToolbarIconTintManager(getContext(), toolbar, collapsingToolbar) { + ToolbarIconTintManager iconTintManager = new ToolbarIconTintManager(getContext(), + viewBinding.toolbar, viewBinding.collapsingToolbar) { @Override protected void doTint(Context themedContext) { - toolbar.getMenu().findItem(R.id.visit_website_item) + viewBinding.toolbar.getMenu().findItem(R.id.visit_website_item) .setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_web)); - toolbar.getMenu().findItem(R.id.share_item) + viewBinding.toolbar.getMenu().findItem(R.id.share_item) .setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_share)); } }; iconTintManager.updateTint(); - appBar.addOnOffsetChangedListener(iconTintManager); - - imgvCover = root.findViewById(R.id.imgvCover); - txtvTitle = root.findViewById(R.id.txtvTitle); - txtvAuthorHeader = root.findViewById(R.id.txtvAuthor); - imgvBackground = root.findViewById(R.id.imgvBackground); - header = root.findViewById(R.id.headerContainer); - infoContainer = root.findViewById(R.id.infoContainer); - root.findViewById(R.id.butShowInfo).setVisibility(View.INVISIBLE); - root.findViewById(R.id.butShowSettings).setVisibility(View.INVISIBLE); - root.findViewById(R.id.butFilter).setVisibility(View.INVISIBLE); - // https://github.com/bumptech/glide/issues/529 - imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000)); + viewBinding.appBar.addOnOffsetChangedListener(iconTintManager); - txtvDescription = root.findViewById(R.id.txtvDescription); - txtvUrl = root.findViewById(R.id.txtvUrl); - lblSupport = root.findViewById(R.id.lblSupport); - txtvFundingUrl = root.findViewById(R.id.txtvFundingUrl); + viewBinding.header.butShowInfo.setVisibility(View.INVISIBLE); + viewBinding.header.butShowSettings.setVisibility(View.INVISIBLE); + viewBinding.header.butFilter.setVisibility(View.INVISIBLE); + // https://github.com/bumptech/glide/issues/529 + viewBinding.imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000)); - txtvUrl.setOnClickListener(copyUrlToClipboard); + viewBinding.urlLabel.setOnClickListener(copyUrlToClipboard); long feedId = getArguments().getLong(EXTRA_FEED_ID); getParentFragmentManager().beginTransaction().replace(R.id.statisticsFragmentContainer, FeedStatisticsFragment.newInstance(feedId, false), "feed_statistics_fragment") .commitAllowingStateLoss(); - root.findViewById(R.id.btnvOpenStatistics).setOnClickListener(view -> { + viewBinding.statisticsButton.setOnClickListener(view -> { StatisticsFragment fragment = new StatisticsFragment(); ((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.SLIDE); }); - return root; + return viewBinding.getRoot(); } @Override @@ -186,13 +160,14 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu @Override public void onConfigurationChanged(@NonNull Configuration newConfig) { super.onConfigurationChanged(newConfig); - if (header == null || infoContainer == null) { + if (viewBinding == null) { return; } int horizontalSpacing = (int) getResources().getDimension(R.dimen.additional_horizontal_spacing); - header.setPadding(horizontalSpacing, header.getPaddingTop(), horizontalSpacing, header.getPaddingBottom()); - infoContainer.setPadding(horizontalSpacing, infoContainer.getPaddingTop(), - horizontalSpacing, infoContainer.getPaddingBottom()); + viewBinding.header.getRoot().setPadding(horizontalSpacing, viewBinding.header.getRoot().getPaddingTop(), + horizontalSpacing, viewBinding.header.getRoot().getPaddingBottom()); + viewBinding.infoContainer.setPadding(horizontalSpacing, viewBinding.infoContainer.getPaddingTop(), + horizontalSpacing, viewBinding.infoContainer.getPaddingBottom()); } private void showFeed() { @@ -206,7 +181,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu .error(R.color.light_gray) .fitCenter() .dontAnimate()) - .into(imgvCover); + .into(viewBinding.header.imgvCover); Glide.with(this) .load(feed.getImageUrl()) .apply(new RequestOptions() @@ -214,27 +189,26 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu .error(R.color.image_readability_tint) .transform(new FastBlurTransformation()) .dontAnimate()) - .into(imgvBackground); + .into(viewBinding.imgvBackground); - txtvTitle.setText(feed.getTitle()); - txtvTitle.setMaxLines(6); + viewBinding.header.txtvTitle.setText(feed.getTitle()); + viewBinding.header.txtvTitle.setMaxLines(6); String description = HtmlToPlainText.getPlainText(feed.getDescription()); - txtvDescription.setText(description); + viewBinding.descriptionLabel.setText(description); if (!TextUtils.isEmpty(feed.getAuthor())) { - txtvAuthorHeader.setText(feed.getAuthor()); + viewBinding.header.txtvAuthor.setText(feed.getAuthor()); } - txtvUrl.setText(feed.getDownloadUrl()); - txtvUrl.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0); + viewBinding.urlLabel.setText(feed.getDownloadUrl()); + viewBinding.urlLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0); if (feed.getPaymentLinks() == null || feed.getPaymentLinks().size() == 0) { - lblSupport.setVisibility(View.GONE); - txtvFundingUrl.setVisibility(View.GONE); + viewBinding.supportHeadingLabel.setVisibility(View.GONE); + viewBinding.supportUrl.setVisibility(View.GONE); } else { - lblSupport.setVisibility(View.VISIBLE); ArrayList<FeedFunding> fundingList = feed.getPaymentLinks(); // Filter for duplicates, but keep items in the order that they have in the feed. @@ -260,7 +234,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu str.append("\n"); } str = new StringBuilder(StringUtils.trim(str.toString())); - txtvFundingUrl.setText(str.toString()); + viewBinding.supportUrl.setText(str.toString()); } refreshToolbarState(); @@ -275,11 +249,13 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu } private void refreshToolbarState() { - toolbar.getMenu().findItem(R.id.reconnect_local_folder).setVisible(feed != null && feed.isLocalFeed()); - toolbar.getMenu().findItem(R.id.share_item).setVisible(feed != null && !feed.isLocalFeed()); - toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null + viewBinding.toolbar.getMenu().findItem(R.id.reconnect_local_folder).setVisible( + feed != null && feed.isLocalFeed()); + viewBinding.toolbar.getMenu().findItem(R.id.share_item).setVisible(feed != null && !feed.isLocalFeed()); + viewBinding.toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed != null + && feed.getLink() != null && IntentUtils.isCallable(getContext(), new Intent(Intent.ACTION_VIEW, Uri.parse(feed.getLink())))); - toolbar.getMenu().findItem(R.id.edit_feed_url_item).setVisible(feed != null && !feed.isLocalFeed()); + viewBinding.toolbar.getMenu().findItem(R.id.edit_feed_url_item).setVisible(feed != null && !feed.isLocalFeed()); } @Override @@ -310,8 +286,9 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu @Override protected void setUrl(String url) { feed.setDownloadUrl(url); - txtvUrl.setText(feed.getDownloadUrl()); - txtvUrl.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0); + viewBinding.urlLabel.setText(feed.getDownloadUrl()); + viewBinding.urlLabel.setCompoundDrawablesRelativeWithIntrinsicBounds( + 0, 0, R.drawable.ic_paperclip, 0); } }.show(); } else { diff --git a/app/src/main/res/layout/feedinfo.xml b/app/src/main/res/layout/feedinfo.xml index c3ca87a5a..1a6d8ce93 100644 --- a/app/src/main/res/layout/feedinfo.xml +++ b/app/src/main/res/layout/feedinfo.xml @@ -69,30 +69,32 @@ android:paddingHorizontal="@dimen/additional_horizontal_spacing"> <TextView - android:id="@+id/lblUrl" + android:id="@+id/statisticsHeadingLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:textSize="18sp" android:layout_marginTop="16dp" - android:layout_marginBottom="4dp" - android:text="@string/url_label" + android:textSize="18sp" + android:layout_marginBottom="8dp" + android:text="@string/statistics_label" android:textColor="?android:attr/textColorPrimary" tools:background="@android:color/holo_red_light" /> - <TextView - android:id="@+id/txtvUrl" + <androidx.fragment.app.FragmentContainerView + android:id="@+id/statisticsFragmentContainer" + android:layout_width="match_parent" + android:layout_height="wrap_content" /> + + <Button + android:id="@+id/statisticsButton" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:background="?attr/selectableItemBackground" - android:maxLines="4" - android:paddingTop="4dp" - android:paddingBottom="4dp" - android:drawablePadding="4dp" - tools:background="@android:color/holo_green_dark" - tools:text="http://www.example.com/feed" /> + android:minWidth="0dp" + android:minHeight="0dp" + android:text="@string/statistics_view_all" + style="@style/Widget.MaterialComponents.Button.TextButton" /> <TextView - android:id="@+id/lblSupport" + android:id="@+id/supportHeadingLabel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="16dp" @@ -103,7 +105,7 @@ tools:background="@android:color/holo_red_light" /> <TextView - android:id="@+id/txtvFundingUrl" + android:id="@+id/supportUrl" android:layout_width="match_parent" android:layout_height="wrap_content" android:maxLines="8" @@ -114,6 +116,7 @@ tools:background="@android:color/holo_green_dark" /> <TextView + android:id="@+id/descriptionHeadingLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18sp" @@ -124,7 +127,7 @@ tools:background="@android:color/holo_red_light" /> <TextView - android:id="@+id/txtvDescription" + android:id="@+id/descriptionLabel" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="@string/design_time_lorem_ipsum" @@ -132,29 +135,27 @@ tools:background="@android:color/holo_green_dark" /> <TextView - android:id="@+id/lblStatistics" + android:id="@+id/urlHeadingLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_marginTop="16dp" android:textSize="18sp" - android:layout_marginBottom="8dp" - android:text="@string/statistics_label" + android:layout_marginTop="16dp" + android:layout_marginBottom="4dp" + android:text="@string/url_label" android:textColor="?android:attr/textColorPrimary" tools:background="@android:color/holo_red_light" /> - <androidx.fragment.app.FragmentContainerView - android:id="@+id/statisticsFragmentContainer" - android:layout_width="match_parent" - android:layout_height="wrap_content" /> - - <Button - android:id="@+id/btnvOpenStatistics" + <TextView + android:id="@+id/urlLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:minWidth="0dp" - android:minHeight="0dp" - android:text="@string/statistics_view_all" - style="@style/Widget.MaterialComponents.Button.TextButton" /> + android:background="?attr/selectableItemBackground" + android:maxLines="4" + android:paddingTop="4dp" + android:paddingBottom="4dp" + android:drawablePadding="4dp" + tools:background="@android:color/holo_green_dark" + tools:text="http://www.example.com/feed" /> </LinearLayout> |