Always allow clicking timecodes

This commit is contained in:
ByteHamster 2020-02-01 18:02:19 +01:00
parent 5af5f30bb6
commit 8356226e97
6 changed files with 30 additions and 35 deletions

View File

@ -55,7 +55,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -66,7 +66,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -77,7 +77,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -88,7 +88,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 11 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -99,7 +99,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -110,7 +110,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStr + " here.</p>", 2 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -120,7 +120,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 2 * 60 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 60 * 60 * 1000 + 10 * 60 * 1000 + 12 * 1000 }, timeStrings);
}
@ -132,7 +132,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode " + timeStrings[0] + " here. Hey look another one " + timeStrings[1] + " here!</p>", 3 * 60 * 60 * 1000);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{ 10 * 60 * 1000 + 12 * 1000, 2 * 60 * 1000 + 12 * 1000 }, timeStrings);
}
@ -143,7 +143,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode (" + timeStr + ") here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -154,7 +154,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode [" + timeStr + "] here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -165,7 +165,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, "<p> Some test text with a timecode <" + timeStr + "> here.</p>", Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[]{time}, new String[]{timeStr});
}
@ -181,7 +181,7 @@ public class TimelineTest {
Playable p = newTestPlayable(null, shownotes.toString(), Integer.MAX_VALUE);
Timeline t = new Timeline(context, p);
String res = t.processShownotes(true);
String res = t.processShownotes();
checkLinkCorrect(res, new long[0], new String[0]);
}

View File

@ -85,7 +85,7 @@ public class ItemDescriptionFragment extends Fragment {
@NonNull
private String loadData() {
Timeline timeline = new Timeline(getActivity(), controller.getMedia());
return timeline.processShownotes(true);
return timeline.processShownotes();
}
@Override

View File

@ -24,6 +24,7 @@ import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.google.android.material.snackbar.Snackbar;
import de.danoeh.antennapod.R;
import de.danoeh.antennapod.activity.MainActivity;
import de.danoeh.antennapod.adapter.actionbutton.ItemActionButton;
@ -42,6 +43,7 @@ import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.storage.DownloadRequester;
import de.danoeh.antennapod.core.util.Converter;
import de.danoeh.antennapod.core.util.DateUtils;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.core.util.playback.Timeline;
import de.danoeh.antennapod.view.ShownotesWebView;
import io.reactivex.Observable;
@ -96,6 +98,7 @@ public class ItemFragment extends Fragment {
private Button butAction2;
private Disposable disposable;
private PlaybackController controller;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -124,12 +127,11 @@ public class ItemFragment extends Fragment {
}
webvDescription = layout.findViewById(R.id.webvDescription);
webvDescription.setTimecodeSelectedListener(time -> {
/*if (getActivity() != null && getActivity() instanceof MainActivity) {
PlaybackController pc = ((MainActivity) getActivity()).getPlaybackController();
if (pc != null) {
pc.seekTo(time);
}
}*/
if (controller != null && item.getMedia().getIdentifier().equals(controller.getMedia().getIdentifier())) {
controller.seekTo(time);
} else {
Snackbar.make(getView(), R.string.play_this_to_seek_position, Snackbar.LENGTH_LONG).show();
}
});
registerForContextMenu(webvDescription);
@ -191,6 +193,8 @@ public class ItemFragment extends Fragment {
public void onStart() {
super.onStart();
EventBus.getDefault().register(this);
controller = new PlaybackController(getActivity(), false);
controller.init();
}
@Override
@ -206,6 +210,7 @@ public class ItemFragment extends Fragment {
public void onStop() {
super.onStop();
EventBus.getDefault().unregister(this);
controller.release();
}
@Override
@ -389,7 +394,7 @@ public class ItemFragment extends Fragment {
Context context = getContext();
if (feedItem != null && context != null) {
Timeline t = new Timeline(context, feedItem);
webviewData = t.processShownotes(false);
webviewData = t.processShownotes();
}
return feedItem;
}

View File

@ -3,6 +3,7 @@ package de.danoeh.antennapod.view;
import android.content.ClipData;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.os.Build;
import android.util.AttributeSet;
@ -51,10 +52,7 @@ public class ShownotesWebView extends WebView implements View.OnLongClickListene
}
private void setup() {
if (UserPreferences.getTheme() == R.style.Theme_AntennaPod_Dark
|| UserPreferences.getTheme() == R.style.Theme_AntennaPod_TrueBlack) {
setBackgroundColor(ContextCompat.getColor(getContext(), R.color.black));
}
setBackgroundColor(Color.TRANSPARENT);
if (!NetworkUtils.networkAvailable()) {
getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
// Use cached resources, even if they have expired

View File

@ -106,11 +106,10 @@ public class Timeline {
* This method does NOT change the original shownotes string of the shownotesProvider object and it should
* also not be changed by the caller.
*
* @param addTimecodes True if this method should add timecode links
* @return The processed HTML string.
*/
@NonNull
public String processShownotes(final boolean addTimecodes) {
public String processShownotes() {
final Playable playable = (shownotesProvider instanceof Playable) ? (Playable) shownotesProvider : null;
// load shownotes
@ -155,10 +154,7 @@ public class Timeline {
document.head().appendElement("style").attr("type", "text/css").text(styleStr);
// apply timecode links
if (addTimecodes) {
addTimecodes(document, playable);
}
addTimecodes(document, playable);
return document.toString();
}
@ -188,11 +184,6 @@ public class Timeline {
return -1;
}
public void setShownotesProvider(@NonNull ShownotesProvider shownotesProvider) {
this.shownotesProvider = shownotesProvider;
}
private void addTimecodes(Document document, final Playable playable) {
Elements elementsWithTimeCodes = document.body().getElementsMatchingOwnText(TIMECODE_REGEX);
Log.d(TAG, "Recognized " + elementsWithTimeCodes.size() + " timecodes");

View File

@ -192,6 +192,7 @@
<string name="marked_as_read_label">Marked as played</string>
<string name="mark_read_no_media_label">Mark as read</string>
<string name="marked_as_read_no_media_label">Marked as read</string>
<string name="play_this_to_seek_position">To jump to positions, you need to play the episode</string>
<plurals name="marked_read_batch_label">
<item quantity="one">%d episode marked as played.</item>
<item quantity="other">%d episodes marked as played.</item>