Merge branch 'dev' into sepiasearch
This commit is contained in:
commit
5f092e37f9
87 changed files with 2602 additions and 1636 deletions
|
|
@ -22,9 +22,16 @@ package org.schabi.newpipe.util;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import org.schabi.newpipe.MainActivity;
|
||||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.ReCaptchaActivity;
|
||||
|
|
@ -32,6 +39,7 @@ import org.schabi.newpipe.extractor.Info;
|
|||
import org.schabi.newpipe.extractor.InfoItem;
|
||||
import org.schabi.newpipe.extractor.ListExtractor.InfoItemsPage;
|
||||
import org.schabi.newpipe.extractor.ListInfo;
|
||||
import org.schabi.newpipe.extractor.MetaInfo;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.Page;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
|
|
@ -60,6 +68,8 @@ import java.util.List;
|
|||
import io.reactivex.rxjava3.core.Maybe;
|
||||
import io.reactivex.rxjava3.core.Single;
|
||||
|
||||
import static org.schabi.newpipe.extractor.utils.Utils.isNullOrEmpty;
|
||||
|
||||
public final class ExtractorHelper {
|
||||
private static final String TAG = ExtractorHelper.class.getSimpleName();
|
||||
private static final InfoCache CACHE = InfoCache.getInstance();
|
||||
|
|
@ -306,4 +316,73 @@ public final class ExtractorHelper {
|
|||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats the text contained in the meta info list as HTML and puts it into the text view,
|
||||
* while also making the separator visible. If the list is null or empty, or the user chose not
|
||||
* to see meta information, both the text view and the separator are hidden
|
||||
* @param metaInfos a list of meta information, can be null or empty
|
||||
* @param metaInfoTextView the text view in which to show the formatted HTML
|
||||
* @param metaInfoSeparator another view to be shown or hidden accordingly to the text view
|
||||
*/
|
||||
public static void showMetaInfoInTextView(@Nullable final List<MetaInfo> metaInfos,
|
||||
final TextView metaInfoTextView,
|
||||
final View metaInfoSeparator) {
|
||||
final Context context = metaInfoTextView.getContext();
|
||||
final boolean showMetaInfo = PreferenceManager.getDefaultSharedPreferences(context)
|
||||
.getBoolean(context.getString(R.string.show_meta_info_key), true);
|
||||
|
||||
if (!showMetaInfo || metaInfos == null || metaInfos.isEmpty()) {
|
||||
metaInfoTextView.setVisibility(View.GONE);
|
||||
metaInfoSeparator.setVisibility(View.GONE);
|
||||
|
||||
} else {
|
||||
final StringBuilder stringBuilder = new StringBuilder();
|
||||
for (final MetaInfo metaInfo : metaInfos) {
|
||||
if (!isNullOrEmpty(metaInfo.getTitle())) {
|
||||
stringBuilder.append("<b>").append(metaInfo.getTitle()).append("</b>")
|
||||
.append(Localization.DOT_SEPARATOR);
|
||||
}
|
||||
|
||||
String content = metaInfo.getContent().getContent().trim();
|
||||
if (content.endsWith(".")) {
|
||||
content = content.substring(0, content.length() - 1); // remove . at end
|
||||
}
|
||||
stringBuilder.append(content);
|
||||
|
||||
for (int i = 0; i < metaInfo.getUrls().size(); i++) {
|
||||
if (i == 0) {
|
||||
stringBuilder.append(Localization.DOT_SEPARATOR);
|
||||
} else {
|
||||
stringBuilder.append("<br/><br/>");
|
||||
}
|
||||
|
||||
stringBuilder
|
||||
.append("<a href=\"").append(metaInfo.getUrls().get(i)).append("\">")
|
||||
.append(capitalizeIfAllUppercase(metaInfo.getUrlTexts().get(i).trim()))
|
||||
.append("</a>");
|
||||
}
|
||||
}
|
||||
|
||||
metaInfoTextView.setText(HtmlCompat.fromHtml(stringBuilder.toString(),
|
||||
HtmlCompat.FROM_HTML_SEPARATOR_LINE_BREAK_HEADING));
|
||||
metaInfoTextView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
metaInfoTextView.setVisibility(View.VISIBLE);
|
||||
metaInfoSeparator.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
private static String capitalizeIfAllUppercase(final String text) {
|
||||
for (int i = 0; i < text.length(); i++) {
|
||||
if (Character.isLowerCase(text.charAt(i))) {
|
||||
return text; // there is at least a lowercase letter -> not all uppercase
|
||||
}
|
||||
}
|
||||
|
||||
if (text.isEmpty()) {
|
||||
return text;
|
||||
} else {
|
||||
return text.substring(0, 1).toUpperCase() + text.substring(1).toLowerCase();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ import java.util.Locale;
|
|||
|
||||
public final class Localization {
|
||||
|
||||
private static final String DOT_SEPARATOR = " • ";
|
||||
public static final String DOT_SEPARATOR = " • ";
|
||||
private static PrettyTime prettyTime;
|
||||
|
||||
private Localization() { }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue