mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-02-02 03:36:48 +01:00
- Bugfix : Player did not always display the current chapter correctly.
- Added support for links in SimpleChapters
This commit is contained in:
parent
f564c9a6e2
commit
3281723326
@ -1,7 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp" >
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="8dp" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvStart"
|
||||
@ -17,9 +18,22 @@
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_margin="8dp"
|
||||
android:layout_toLeftOf="@id/txtvStart"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/txtvLink"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_below="@id/txtvTitle"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:layout_toLeftOf="@id/txtvStart"
|
||||
android:focusable="false"
|
||||
android:focusableInTouchMode="false"
|
||||
android:maxLines="2" />
|
||||
|
||||
</RelativeLayout>
|
@ -28,6 +28,8 @@ import android.view.SurfaceHolder;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
@ -166,9 +168,8 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
AlertDialog.Builder stDialog = new AlertDialog.Builder(this);
|
||||
stDialog.setTitle(R.string.sleep_timer_label);
|
||||
stDialog.setMessage(getString(R.string.time_left_label)
|
||||
+ Converter
|
||||
.getDurationStringLong((int) playbackService
|
||||
.getSleepTimerTimeLeft()));
|
||||
+ Converter.getDurationStringLong((int) playbackService
|
||||
.getSleepTimerTimeLeft()));
|
||||
stDialog.setPositiveButton(R.string.disable_sleeptimer_label,
|
||||
new DialogInterface.OnClickListener() {
|
||||
|
||||
@ -367,9 +368,11 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
@Override
|
||||
protected void onProgressUpdate(Void... v) {
|
||||
super.onProgressUpdate();
|
||||
int currentPosition = playbackService.getPlayer()
|
||||
.getCurrentPosition();
|
||||
media.setPosition(currentPosition);
|
||||
txtvPosition.setText(Converter
|
||||
.getDurationStringLong(playbackService.getPlayer()
|
||||
.getCurrentPosition()));
|
||||
.getDurationStringLong(currentPosition));
|
||||
txtvLength.setText(Converter
|
||||
.getDurationStringLong(playbackService.getPlayer()
|
||||
.getDuration()));
|
||||
@ -788,6 +791,7 @@ public class MediaplayerActivity extends SherlockFragmentActivity implements
|
||||
sCChapterFragment.setListAdapter(new SCListAdapter(
|
||||
activity, 0, activity.media.getItem()
|
||||
.getSimpleChapters()));
|
||||
|
||||
return sCChapterFragment;
|
||||
default:
|
||||
return CoverFragment.newInstance(null);
|
||||
|
@ -12,10 +12,19 @@ import de.danoeh.antennapod.storage.DownloadRequester;
|
||||
import de.danoeh.antennapod.util.Converter;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.text.Layout;
|
||||
import android.text.Selection;
|
||||
import android.text.Spannable;
|
||||
import android.text.Spanned;
|
||||
import android.text.format.DateUtils;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.text.style.ClickableSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageView;
|
||||
@ -45,6 +54,7 @@ public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
||||
convertView = inflater.inflate(R.layout.simplechapter_item, null);
|
||||
holder.title = (TextView) convertView.findViewById(R.id.txtvTitle);
|
||||
holder.start = (TextView) convertView.findViewById(R.id.txtvStart);
|
||||
holder.link = (TextView) convertView.findViewById(R.id.txtvLink);
|
||||
convertView.setTag(holder);
|
||||
} else {
|
||||
holder = (Holder) convertView.getTag();
|
||||
@ -52,12 +62,68 @@ public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
||||
}
|
||||
|
||||
holder.title.setText(sc.getTitle());
|
||||
holder.start.setText(Converter.getDurationStringLong((int) sc.getStart()));
|
||||
holder.start.setText(Converter.getDurationStringLong((int) sc
|
||||
.getStart()));
|
||||
if (sc.getLink() != null) {
|
||||
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.setMovementMethod(null);
|
||||
holder.link.setOnTouchListener(new OnTouchListener() {
|
||||
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event) {
|
||||
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;
|
||||
|
||||
}
|
||||
});
|
||||
SimpleChapter current = sc.getItem().getCurrentChapter();
|
||||
if (current != null) {
|
||||
if (current == sc) {
|
||||
holder.title.setTextColor(convertView.getResources().getColor(R.color.bright_blue));
|
||||
holder.title.setTextColor(convertView.getResources().getColor(
|
||||
R.color.bright_blue));
|
||||
} else {
|
||||
holder.title.setTextColor(Color.parseColor("black"));
|
||||
}
|
||||
@ -71,6 +137,53 @@ public class SCListAdapter extends ArrayAdapter<SimpleChapter> {
|
||||
static class Holder {
|
||||
TextView title;
|
||||
TextView start;
|
||||
TextView link;
|
||||
}
|
||||
|
||||
private LinkMovementMethod linkMovementMethod = new LinkMovementMethod() {
|
||||
|
||||
@Override
|
||||
public boolean onTouchEvent(TextView widget, Spannable buffer,
|
||||
MotionEvent event) {
|
||||
Object text = widget.getText();
|
||||
if (text instanceof Spanned) {
|
||||
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;
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
}
|
||||
|
@ -38,18 +38,25 @@ public class FeedItem extends FeedComponent {
|
||||
this.read = true;
|
||||
}
|
||||
|
||||
public SimpleChapter getCurrentChapter() {
|
||||
/** Get the chapter that fits the position. */
|
||||
public SimpleChapter getCurrentChapter(int position) {
|
||||
SimpleChapter current = null;
|
||||
if (simpleChapters != null) {
|
||||
SimpleChapter current = simpleChapters.get(0);
|
||||
current = simpleChapters.get(0);
|
||||
for (SimpleChapter sc : simpleChapters) {
|
||||
if (media.getPosition() > current.getStart() &&
|
||||
media.getPosition() <= sc.getStart()) {
|
||||
return current;
|
||||
if (sc.getStart() > position) {
|
||||
break;
|
||||
} else {
|
||||
current = sc;
|
||||
}
|
||||
current = sc;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
return current;
|
||||
}
|
||||
|
||||
/** Calls getCurrentChapter with current position. */
|
||||
public SimpleChapter getCurrentChapter() {
|
||||
return getCurrentChapter(media.getPosition());
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
|
@ -505,9 +505,11 @@ public class FeedManager {
|
||||
|
||||
/** Get a Feed Item by its id and its feed */
|
||||
public FeedItem getFeedItem(long id, Feed feed) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getId() == id) {
|
||||
return item;
|
||||
if (feed != null) {
|
||||
for (FeedItem item : feed.getItems()) {
|
||||
if (item.getId() == id) {
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
Log.e(TAG, "Couldn't find FeedItem with id " + id);
|
||||
|
@ -53,7 +53,9 @@ public class CoverFragment extends SherlockFragment {
|
||||
if (feedId != -1 && itemId != -1) {
|
||||
Feed feed = manager.getFeed(feedId);
|
||||
item = manager.getFeedItem(itemId, feed);
|
||||
media = item.getMedia();
|
||||
if (item != null) {
|
||||
media = item.getMedia();
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, TAG + " was called with invalid arguments");
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user