diff --git a/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java b/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java index f6e6da8b4..fa18621ac 100644 --- a/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java +++ b/app/src/main/java/de/danoeh/antennapod/adapter/ChaptersListAdapter.java @@ -1,36 +1,26 @@ package de.danoeh.antennapod.adapter; import android.content.Context; -import androidx.annotation.NonNull; -import androidx.core.content.ContextCompat; -import android.text.Layout; -import android.text.Selection; -import android.text.Spannable; -import android.text.Spanned; -import android.text.style.ClickableSpan; -import android.text.util.Linkify; import android.view.LayoutInflater; -import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.widget.ArrayAdapter; -import android.widget.ImageButton; +import android.widget.ImageView; import android.widget.TextView; - +import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import de.danoeh.antennapod.R; import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.Converter; +import de.danoeh.antennapod.core.util.IntentUtils; import de.danoeh.antennapod.core.util.ThemeUtils; import de.danoeh.antennapod.core.util.playback.Playable; public class ChaptersListAdapter extends ArrayAdapter { - private static final String TAG = "ChapterListAdapter"; private Playable media; - - private int defaultTextColor; private final Callback callback; public ChaptersListAdapter(Context context, int textViewResourceId, Callback callback) { @@ -58,11 +48,11 @@ public class ChaptersListAdapter extends ArrayAdapter { convertView = inflater.inflate(R.layout.simplechapter_item, parent, false); holder.view = convertView; holder.title = convertView.findViewById(R.id.txtvTitle); - defaultTextColor = holder.title.getTextColors().getDefaultColor(); holder.start = convertView.findViewById(R.id.txtvStart); holder.link = convertView.findViewById(R.id.txtvLink); holder.duration = convertView.findViewById(R.id.txtvDuration); - holder.butPlayChapter = convertView.findViewById(R.id.butPlayChapter); + holder.secondaryActionButton = convertView.findViewById(R.id.secondaryActionButton); + holder.secondaryActionIcon = convertView.findViewById(R.id.secondaryActionIcon); convertView.setTag(holder); } else { holder = (Holder) convertView.getTag(); @@ -82,60 +72,15 @@ public class ChaptersListAdapter extends ArrayAdapter { holder.duration.setText(getContext().getString(R.string.chapter_duration, Converter.getDurationStringLong((int) duration))); - if (sc.getLink() != null) { + if (sc.getLink() == null) { + holder.link.setVisibility(View.GONE); + } else { holder.link.setVisibility(View.VISIBLE); holder.link.setText(sc.getLink()); - Linkify.addLinks(holder.link, Linkify.WEB_URLS); - } else { - holder.link.setVisibility(View.GONE); + holder.link.setOnClickListener(v -> IntentUtils.openInBrowser(getContext(), sc.getLink())); } - holder.link.setMovementMethod(null); - holder.link.setOnTouchListener((v, event) -> { - // from - // http://stackoverflow.com/questions/7236840/android-textview-linkify-intercepts-with-parent-view-gestures - TextView widget = (TextView) v; - Object text = widget.getText(); - if (text instanceof Spanned) { - Spannable buffer = (Spannable) text; - - int action = event.getAction(); - - if (action == MotionEvent.ACTION_UP - || action == MotionEvent.ACTION_DOWN) { - int x = (int) event.getX(); - int y = (int) event.getY(); - - x -= widget.getTotalPaddingLeft(); - y -= widget.getTotalPaddingTop(); - - x += widget.getScrollX(); - y += widget.getScrollY(); - - Layout layout = widget.getLayout(); - int line = layout.getLineForVertical(y); - int off = layout.getOffsetForHorizontal(line, x); - - ClickableSpan[] link = buffer.getSpans(off, off, - ClickableSpan.class); - - if (link.length != 0) { - if (action == MotionEvent.ACTION_UP) { - link[0].onClick(widget); - } else if (action == MotionEvent.ACTION_DOWN) { - Selection.setSelection(buffer, - buffer.getSpanStart(link[0]), - buffer.getSpanEnd(link[0])); - } - return true; - } - } - - } - - return false; - - }); - holder.butPlayChapter.setOnClickListener(v -> { + holder.secondaryActionIcon.setImageResource(ThemeUtils.getDrawableFromAttr(getContext(), R.attr.av_play)); + holder.secondaryActionButton.setOnClickListener(v -> { if (callback != null) { callback.onPlayChapterButtonClicked(position); } @@ -147,8 +92,6 @@ public class ChaptersListAdapter extends ArrayAdapter { holder.view.setBackgroundColor(playingBackGroundColor); } else { holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); - holder.title.setTextColor(defaultTextColor); - holder.start.setTextColor(defaultTextColor); } return convertView; @@ -160,7 +103,8 @@ public class ChaptersListAdapter extends ArrayAdapter { TextView start; TextView link; TextView duration; - ImageButton butPlayChapter; + View secondaryActionButton; + ImageView secondaryActionIcon; } @Override diff --git a/app/src/main/res/layout/simplechapter_item.xml b/app/src/main/res/layout/simplechapter_item.xml index 0d02eac1a..86927f32c 100644 --- a/app/src/main/res/layout/simplechapter_item.xml +++ b/app/src/main/res/layout/simplechapter_item.xml @@ -1,86 +1,64 @@ - - - + android:baselineAligned="false" + android:descendantFocusability="blocksDescendants"> + android:layout_width="0dp" + android:layout_height="wrap_content" + android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding" + android:layout_marginRight="@dimen/listitem_threeline_textrightpadding" + android:layout_marginEnd="@dimen/listitem_threeline_textrightpadding" + android:layout_marginTop="@dimen/listitem_threeline_verticalpadding" + android:layout_marginLeft="16dp" + android:layout_marginStart="16dp" + android:layout_weight="1" + android:orientation="vertical"> + android:id="@+id/txtvStart" + style="@style/AntennaPod.TextView.ListItemSecondaryTitle" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + tools:text="00:00:00"/> + android:id="@+id/txtvTitle" + style="@style/AntennaPod.TextView.ListItemPrimaryTitle" + android:layout_width="match_parent" + android:layout_height="wrap_content" + tools:text="@sample/episodes.json/data/title" + android:ellipsize="end"/> + + - + tools:text="Duration: 00:00:00"/> - + - - - \ No newline at end of file +