Updated chapters list
This commit is contained in:
parent
7ec9b00e8b
commit
b9d5ec1a08
|
@ -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<Chapter> {
|
||||
|
||||
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<Chapter> {
|
|||
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<Chapter> {
|
|||
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<Chapter> {
|
|||
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<Chapter> {
|
|||
TextView start;
|
||||
TextView link;
|
||||
TextView duration;
|
||||
ImageButton butPlayChapter;
|
||||
View secondaryActionButton;
|
||||
ImageView secondaryActionIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,86 +1,64 @@
|
|||
<?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"
|
||||
android:id="@+id/container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
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
|
||||
android:id="@+id/txtvStart"
|
||||
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="center_vertical"
|
||||
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">
|
||||
android:layout_height="wrap_content"
|
||||
tools:text="00:00:00"/>
|
||||
|
||||
<TextView
|
||||
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_marginBottom="4dp"
|
||||
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" />
|
||||
tools:text="@sample/episodes.json/data/title"
|
||||
android:ellipsize="end"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvLink"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:maxLines="1"
|
||||
android:visibility="gone"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
tools:visibility="visible"
|
||||
tools:text="Link"
|
||||
tools:background="@android:color/holo_green_dark" />
|
||||
tools:text="https://example.com"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvDuration"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/AntennaPod.TextView.ListItemSecondaryTitle"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:maxLines="1"
|
||||
tools:text="Duration"
|
||||
tools:background="@android:color/holo_green_dark" />
|
||||
|
||||
tools:text="Duration: 00:00:00"/>
|
||||
</LinearLayout>
|
||||
|
||||
<include layout="@layout/vertical_list_divider" />
|
||||
|
||||
<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" />
|
||||
<include layout="@layout/secondary_action"/>
|
||||
|
||||
</LinearLayout>
|
Loading…
Reference in New Issue