Show statistics above description on feed info page (#7161)

This commit is contained in:
ByteHamster 2024-05-03 21:42:14 +02:00 committed by GitHub
parent 292a21f8f8
commit cb1a03cd8d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 110 additions and 132 deletions

View File

@ -15,8 +15,6 @@ import android.view.LayoutInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.activity.result.ActivityResultLauncher; import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts; import androidx.activity.result.contract.ActivityResultContracts;
@ -27,13 +25,12 @@ import androidx.documentfile.provider.DocumentFile;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide; import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions; 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.appbar.MaterialToolbar;
import com.google.android.material.dialog.MaterialAlertDialogBuilder; import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.snackbar.Snackbar; import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity; import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.databinding.FeedinfoBinding;
import de.danoeh.antennapod.ui.TransitionEffect; import de.danoeh.antennapod.ui.TransitionEffect;
import de.danoeh.antennapod.storage.database.DBReader; import de.danoeh.antennapod.storage.database.DBReader;
import de.danoeh.antennapod.storage.database.FeedDatabaseWriter; import de.danoeh.antennapod.storage.database.FeedDatabaseWriter;
@ -69,17 +66,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
private Feed feed; private Feed feed;
private Disposable disposable; private Disposable disposable;
private ImageView imgvCover; private FeedinfoBinding viewBinding;
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;
public static FeedInfoFragment newInstance(Feed feed) { public static FeedInfoFragment newInstance(Feed feed) {
FeedInfoFragment fragment = new FeedInfoFragment(); FeedInfoFragment fragment = new FeedInfoFragment();
@ -110,58 +97,45 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) { @Nullable Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.feedinfo, null); viewBinding = FeedinfoBinding.inflate(inflater);
toolbar = root.findViewById(R.id.toolbar); viewBinding.toolbar.setTitle("");
toolbar.setTitle(""); viewBinding.toolbar.inflateMenu(R.menu.feedinfo);
toolbar.inflateMenu(R.menu.feedinfo); viewBinding.toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack());
toolbar.setNavigationOnClickListener(v -> getParentFragmentManager().popBackStack()); viewBinding.toolbar.setOnMenuItemClickListener(this);
toolbar.setOnMenuItemClickListener(this);
refreshToolbarState(); refreshToolbarState();
AppBarLayout appBar = root.findViewById(R.id.appBar); ToolbarIconTintManager iconTintManager = new ToolbarIconTintManager(getContext(),
CollapsingToolbarLayout collapsingToolbar = root.findViewById(R.id.collapsing_toolbar); viewBinding.toolbar, viewBinding.collapsingToolbar) {
ToolbarIconTintManager iconTintManager = new ToolbarIconTintManager(getContext(), toolbar, collapsingToolbar) {
@Override @Override
protected void doTint(Context themedContext) { 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)); .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)); .setIcon(AppCompatResources.getDrawable(themedContext, R.drawable.ic_share));
} }
}; };
iconTintManager.updateTint(); iconTintManager.updateTint();
appBar.addOnOffsetChangedListener(iconTintManager); viewBinding.appBar.addOnOffsetChangedListener(iconTintManager);
imgvCover = root.findViewById(R.id.imgvCover); viewBinding.header.butShowInfo.setVisibility(View.INVISIBLE);
txtvTitle = root.findViewById(R.id.txtvTitle); viewBinding.header.butShowSettings.setVisibility(View.INVISIBLE);
txtvAuthorHeader = root.findViewById(R.id.txtvAuthor); viewBinding.header.butFilter.setVisibility(View.INVISIBLE);
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 // https://github.com/bumptech/glide/issues/529
imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000)); viewBinding.imgvBackground.setColorFilter(new LightingColorFilter(0xff828282, 0x000000));
txtvDescription = root.findViewById(R.id.txtvDescription); viewBinding.urlLabel.setOnClickListener(copyUrlToClipboard);
txtvUrl = root.findViewById(R.id.txtvUrl);
lblSupport = root.findViewById(R.id.lblSupport);
txtvFundingUrl = root.findViewById(R.id.txtvFundingUrl);
txtvUrl.setOnClickListener(copyUrlToClipboard);
long feedId = getArguments().getLong(EXTRA_FEED_ID); long feedId = getArguments().getLong(EXTRA_FEED_ID);
getParentFragmentManager().beginTransaction().replace(R.id.statisticsFragmentContainer, getParentFragmentManager().beginTransaction().replace(R.id.statisticsFragmentContainer,
FeedStatisticsFragment.newInstance(feedId, false), "feed_statistics_fragment") FeedStatisticsFragment.newInstance(feedId, false), "feed_statistics_fragment")
.commitAllowingStateLoss(); .commitAllowingStateLoss();
root.findViewById(R.id.btnvOpenStatistics).setOnClickListener(view -> { viewBinding.statisticsButton.setOnClickListener(view -> {
StatisticsFragment fragment = new StatisticsFragment(); StatisticsFragment fragment = new StatisticsFragment();
((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.SLIDE); ((MainActivity) getActivity()).loadChildFragment(fragment, TransitionEffect.SLIDE);
}); });
return root; return viewBinding.getRoot();
} }
@Override @Override
@ -186,13 +160,14 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
@Override @Override
public void onConfigurationChanged(@NonNull Configuration newConfig) { public void onConfigurationChanged(@NonNull Configuration newConfig) {
super.onConfigurationChanged(newConfig); super.onConfigurationChanged(newConfig);
if (header == null || infoContainer == null) { if (viewBinding == null) {
return; return;
} }
int horizontalSpacing = (int) getResources().getDimension(R.dimen.additional_horizontal_spacing); int horizontalSpacing = (int) getResources().getDimension(R.dimen.additional_horizontal_spacing);
header.setPadding(horizontalSpacing, header.getPaddingTop(), horizontalSpacing, header.getPaddingBottom()); viewBinding.header.getRoot().setPadding(horizontalSpacing, viewBinding.header.getRoot().getPaddingTop(),
infoContainer.setPadding(horizontalSpacing, infoContainer.getPaddingTop(), horizontalSpacing, viewBinding.header.getRoot().getPaddingBottom());
horizontalSpacing, infoContainer.getPaddingBottom()); viewBinding.infoContainer.setPadding(horizontalSpacing, viewBinding.infoContainer.getPaddingTop(),
horizontalSpacing, viewBinding.infoContainer.getPaddingBottom());
} }
private void showFeed() { private void showFeed() {
@ -206,7 +181,7 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
.error(R.color.light_gray) .error(R.color.light_gray)
.fitCenter() .fitCenter()
.dontAnimate()) .dontAnimate())
.into(imgvCover); .into(viewBinding.header.imgvCover);
Glide.with(this) Glide.with(this)
.load(feed.getImageUrl()) .load(feed.getImageUrl())
.apply(new RequestOptions() .apply(new RequestOptions()
@ -214,27 +189,26 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
.error(R.color.image_readability_tint) .error(R.color.image_readability_tint)
.transform(new FastBlurTransformation()) .transform(new FastBlurTransformation())
.dontAnimate()) .dontAnimate())
.into(imgvBackground); .into(viewBinding.imgvBackground);
txtvTitle.setText(feed.getTitle()); viewBinding.header.txtvTitle.setText(feed.getTitle());
txtvTitle.setMaxLines(6); viewBinding.header.txtvTitle.setMaxLines(6);
String description = HtmlToPlainText.getPlainText(feed.getDescription()); String description = HtmlToPlainText.getPlainText(feed.getDescription());
txtvDescription.setText(description); viewBinding.descriptionLabel.setText(description);
if (!TextUtils.isEmpty(feed.getAuthor())) { if (!TextUtils.isEmpty(feed.getAuthor())) {
txtvAuthorHeader.setText(feed.getAuthor()); viewBinding.header.txtvAuthor.setText(feed.getAuthor());
} }
txtvUrl.setText(feed.getDownloadUrl()); viewBinding.urlLabel.setText(feed.getDownloadUrl());
txtvUrl.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0); viewBinding.urlLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0);
if (feed.getPaymentLinks() == null || feed.getPaymentLinks().size() == 0) { if (feed.getPaymentLinks() == null || feed.getPaymentLinks().size() == 0) {
lblSupport.setVisibility(View.GONE); viewBinding.supportHeadingLabel.setVisibility(View.GONE);
txtvFundingUrl.setVisibility(View.GONE); viewBinding.supportUrl.setVisibility(View.GONE);
} else { } else {
lblSupport.setVisibility(View.VISIBLE);
ArrayList<FeedFunding> fundingList = feed.getPaymentLinks(); ArrayList<FeedFunding> fundingList = feed.getPaymentLinks();
// Filter for duplicates, but keep items in the order that they have in the feed. // 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.append("\n");
} }
str = new StringBuilder(StringUtils.trim(str.toString())); str = new StringBuilder(StringUtils.trim(str.toString()));
txtvFundingUrl.setText(str.toString()); viewBinding.supportUrl.setText(str.toString());
} }
refreshToolbarState(); refreshToolbarState();
@ -275,11 +249,13 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
} }
private void refreshToolbarState() { private void refreshToolbarState() {
toolbar.getMenu().findItem(R.id.reconnect_local_folder).setVisible(feed != null && feed.isLocalFeed()); viewBinding.toolbar.getMenu().findItem(R.id.reconnect_local_folder).setVisible(
toolbar.getMenu().findItem(R.id.share_item).setVisible(feed != null && !feed.isLocalFeed()); feed != null && feed.isLocalFeed());
toolbar.getMenu().findItem(R.id.visit_website_item).setVisible(feed != null && feed.getLink() != null 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())))); && 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 @Override
@ -310,8 +286,9 @@ public class FeedInfoFragment extends Fragment implements MaterialToolbar.OnMenu
@Override @Override
protected void setUrl(String url) { protected void setUrl(String url) {
feed.setDownloadUrl(url); feed.setDownloadUrl(url);
txtvUrl.setText(feed.getDownloadUrl()); viewBinding.urlLabel.setText(feed.getDownloadUrl());
txtvUrl.setCompoundDrawablesRelativeWithIntrinsicBounds(0, 0, R.drawable.ic_paperclip, 0); viewBinding.urlLabel.setCompoundDrawablesRelativeWithIntrinsicBounds(
0, 0, R.drawable.ic_paperclip, 0);
} }
}.show(); }.show();
} else { } else {

View File

@ -69,70 +69,7 @@
android:paddingHorizontal="@dimen/additional_horizontal_spacing"> android:paddingHorizontal="@dimen/additional_horizontal_spacing">
<TextView <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:textColor="?android:attr/textColorPrimary"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/txtvUrl"
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" />
<TextView
android:id="@+id/lblSupport"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:text="@string/support_funding_label"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/txtvFundingUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="8"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:linksClickable="true"
android:autoLink="web"
tools:background="@android:color/holo_green_dark" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:text="@string/description_label"
android:textColor="?android:attr/textColorPrimary"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/txtvDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/design_time_lorem_ipsum"
android:textIsSelectable="true"
tools:background="@android:color/holo_green_dark" />
<TextView
android:id="@+id/lblStatistics"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
@ -148,7 +85,7 @@
android:layout_height="wrap_content" /> android:layout_height="wrap_content" />
<Button <Button
android:id="@+id/btnvOpenStatistics" android:id="@+id/statisticsButton"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:minWidth="0dp" android:minWidth="0dp"
@ -156,6 +93,70 @@
android:text="@string/statistics_view_all" android:text="@string/statistics_view_all"
style="@style/Widget.MaterialComponents.Button.TextButton" /> style="@style/Widget.MaterialComponents.Button.TextButton" />
<TextView
android:id="@+id/supportHeadingLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:text="@string/support_funding_label"
android:textColor="?android:attr/textColorPrimary"
android:textSize="18sp"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/supportUrl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="8"
android:paddingTop="4dp"
android:paddingBottom="4dp"
android:linksClickable="true"
android:autoLink="web"
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"
android:layout_marginTop="16dp"
android:layout_marginBottom="4dp"
android:text="@string/description_label"
android:textColor="?android:attr/textColorPrimary"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/descriptionLabel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/design_time_lorem_ipsum"
android:textIsSelectable="true"
tools:background="@android:color/holo_green_dark" />
<TextView
android:id="@+id/urlHeadingLabel"
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:textColor="?android:attr/textColorPrimary"
tools:background="@android:color/holo_red_light" />
<TextView
android:id="@+id/urlLabel"
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" />
</LinearLayout> </LinearLayout>
</androidx.core.widget.NestedScrollView> </androidx.core.widget.NestedScrollView>