Updated chapters list

This commit is contained in:
ByteHamster 2020-02-06 23:16:12 +01:00
parent 7ec9b00e8b
commit b9d5ec1a08
2 changed files with 60 additions and 138 deletions

View File

@ -1,36 +1,26 @@
package de.danoeh.antennapod.adapter; package de.danoeh.antennapod.adapter;
import android.content.Context; 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.LayoutInflater;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageButton; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import de.danoeh.antennapod.R; import de.danoeh.antennapod.R;
import de.danoeh.antennapod.core.feed.Chapter; import de.danoeh.antennapod.core.feed.Chapter;
import de.danoeh.antennapod.core.util.ChapterUtils; import de.danoeh.antennapod.core.util.ChapterUtils;
import de.danoeh.antennapod.core.util.Converter; 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.ThemeUtils;
import de.danoeh.antennapod.core.util.playback.Playable; import de.danoeh.antennapod.core.util.playback.Playable;
public class ChaptersListAdapter extends ArrayAdapter<Chapter> { public class ChaptersListAdapter extends ArrayAdapter<Chapter> {
private static final String TAG = "ChapterListAdapter"; private static final String TAG = "ChapterListAdapter";
private Playable media; private Playable media;
private int defaultTextColor;
private final Callback callback; private final Callback callback;
public ChaptersListAdapter(Context context, int textViewResourceId, Callback callback) { public ChaptersListAdapter(Context context, int textViewResourceId, Callback callback) {
@ -58,11 +48,11 @@ public class ChaptersListAdapter extends ArrayAdapter<Chapter> {
convertView = inflater.inflate(R.layout.simplechapter_item, parent, false); convertView = inflater.inflate(R.layout.simplechapter_item, parent, false);
holder.view = convertView; holder.view = convertView;
holder.title = convertView.findViewById(R.id.txtvTitle); holder.title = convertView.findViewById(R.id.txtvTitle);
defaultTextColor = holder.title.getTextColors().getDefaultColor();
holder.start = convertView.findViewById(R.id.txtvStart); holder.start = convertView.findViewById(R.id.txtvStart);
holder.link = convertView.findViewById(R.id.txtvLink); holder.link = convertView.findViewById(R.id.txtvLink);
holder.duration = convertView.findViewById(R.id.txtvDuration); 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); convertView.setTag(holder);
} else { } else {
holder = (Holder) convertView.getTag(); holder = (Holder) convertView.getTag();
@ -82,60 +72,15 @@ public class ChaptersListAdapter extends ArrayAdapter<Chapter> {
holder.duration.setText(getContext().getString(R.string.chapter_duration, holder.duration.setText(getContext().getString(R.string.chapter_duration,
Converter.getDurationStringLong((int) 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.setVisibility(View.VISIBLE);
holder.link.setText(sc.getLink()); holder.link.setText(sc.getLink());
Linkify.addLinks(holder.link, Linkify.WEB_URLS); holder.link.setOnClickListener(v -> IntentUtils.openInBrowser(getContext(), sc.getLink()));
} else {
holder.link.setVisibility(View.GONE);
} }
holder.link.setMovementMethod(null); holder.secondaryActionIcon.setImageResource(ThemeUtils.getDrawableFromAttr(getContext(), R.attr.av_play));
holder.link.setOnTouchListener((v, event) -> { holder.secondaryActionButton.setOnClickListener(v -> {
// 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 -> {
if (callback != null) { if (callback != null) {
callback.onPlayChapterButtonClicked(position); callback.onPlayChapterButtonClicked(position);
} }
@ -147,8 +92,6 @@ public class ChaptersListAdapter extends ArrayAdapter<Chapter> {
holder.view.setBackgroundColor(playingBackGroundColor); holder.view.setBackgroundColor(playingBackGroundColor);
} else { } else {
holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); holder.view.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
holder.title.setTextColor(defaultTextColor);
holder.start.setTextColor(defaultTextColor);
} }
return convertView; return convertView;
@ -160,7 +103,8 @@ public class ChaptersListAdapter extends ArrayAdapter<Chapter> {
TextView start; TextView start;
TextView link; TextView link;
TextView duration; TextView duration;
ImageButton butPlayChapter; View secondaryActionButton;
ImageView secondaryActionIcon;
} }
@Override @Override

View File

@ -1,86 +1,64 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="horizontal" android:orientation="horizontal"
tools:background="@android:color/darker_gray"> android:gravity="center_vertical"
android:baselineAligned="false"
android:descendantFocusability="blocksDescendants">
<LinearLayout
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">
<TextView <TextView
android:id="@+id/txtvStart" android:id="@+id/txtvStart"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle" style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" tools:text="00:00:00"/>
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
android:layout_marginStart="@dimen/listitem_threeline_horizontalpadding"
android:gravity="center_vertical"
tools:text="Start"
tools:background="@android:color/holo_green_dark" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginBottom="@dimen/listitem_threeline_verticalpadding"
android:layout_marginLeft="@dimen/listitem_threeline_horizontalpadding"
android:layout_marginStart="@dimen/listitem_threeline_horizontalpadding"
android:layout_marginRight="@dimen/listitem_threeline_horizontalpadding"
android:layout_marginEnd="@dimen/listitem_threeline_horizontalpadding"
android:layout_marginTop="@dimen/listitem_threeline_verticalpadding"
android:layout_weight="1"
android:gravity="center_vertical"
android:orientation="vertical"
tools:background="@android:color/holo_red_dark">
<TextView <TextView
android:id="@+id/txtvTitle" android:id="@+id/txtvTitle"
android:layout_width="wrap_content" style="@style/AntennaPod.TextView.ListItemPrimaryTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginBottom="4dp" tools:text="@sample/episodes.json/data/title"
android:ellipsize="end" android:ellipsize="end"/>
android:maxLines="2"
android:textColor="?android:attr/textColorPrimary"
android:textSize="16sp"
tools:text="Chapter title"
tools:background="@android:color/holo_green_dark" />
<TextView <TextView
android:id="@+id/txtvLink" android:id="@+id/txtvLink"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" android:focusableInTouchMode="false"
android:maxLines="1"
android:visibility="gone" android:visibility="gone"
android:background="?attr/selectableItemBackground"
tools:visibility="visible" tools:visibility="visible"
tools:text="Link" tools:text="https://example.com"/>
tools:background="@android:color/holo_green_dark" />
<TextView <TextView
android:id="@+id/txtvDuration" android:id="@+id/txtvDuration"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
android:focusable="false" android:focusable="false"
android:focusableInTouchMode="false" android:focusableInTouchMode="false"
android:maxLines="1" tools:text="Duration: 00:00:00"/>
tools:text="Duration"
tools:background="@android:color/holo_green_dark" />
</LinearLayout> </LinearLayout>
<include layout="@layout/vertical_list_divider" /> <include layout="@layout/secondary_action"/>
<ImageButton xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/butPlayChapter"
android:layout_width="@dimen/listview_secondary_button_width"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:clickable="false"
android:contentDescription="@string/chapters_label"
android:focusable="false"
android:focusableInTouchMode="false"
android:src="?attr/av_play"
tools:src="@drawable/ic_play_arrow_white_36dp"
tools:background="@android:color/holo_green_dark" />
</LinearLayout> </LinearLayout>