Extract some utility methods from CommentInfoItemHolder
This commit is contained in:
parent
4b6392df54
commit
ad68f784ae
5 changed files with 80 additions and 81 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import static org.schabi.newpipe.MainActivity.DEBUG;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
|
@ -22,6 +24,7 @@ import org.ocpsoft.prettytime.units.Decade;
|
|||
import org.schabi.newpipe.R;
|
||||
import org.schabi.newpipe.extractor.ListExtractor;
|
||||
import org.schabi.newpipe.extractor.localization.ContentCountry;
|
||||
import org.schabi.newpipe.extractor.localization.DateWrapper;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.AudioTrackType;
|
||||
|
||||
|
|
@ -214,6 +217,14 @@ public final class Localization {
|
|||
String.valueOf(replyCount));
|
||||
}
|
||||
|
||||
public static String likeCount(final Context context, final int likeCount) {
|
||||
if (likeCount < 0) {
|
||||
return "-";
|
||||
} else {
|
||||
return shortCount(context, likeCount);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDurationString(final long duration) {
|
||||
final String output;
|
||||
|
||||
|
|
@ -333,6 +344,20 @@ public final class Localization {
|
|||
return prettyTime.formatUnrounded(offsetDateTime);
|
||||
}
|
||||
|
||||
public static String relativeTimeOrTextual(final DateWrapper parsed,
|
||||
final String textual,
|
||||
@Nullable final Context context) {
|
||||
if (parsed == null) {
|
||||
return textual;
|
||||
} else if (DEBUG && context != null && PreferenceManager
|
||||
.getDefaultSharedPreferences(context)
|
||||
.getBoolean(context.getString(R.string.show_original_time_ago_key), false)) {
|
||||
return relativeTime(parsed.offsetDateTime()) + " (" + textual + ")";
|
||||
} else {
|
||||
return relativeTime(parsed.offsetDateTime());
|
||||
}
|
||||
}
|
||||
|
||||
public static void assureCorrectAppLanguage(final Context c) {
|
||||
final Resources res = c.getResources();
|
||||
final DisplayMetrics dm = res.getDisplayMetrics();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package org.schabi.newpipe.util;
|
||||
|
||||
import static android.text.TextUtils.isEmpty;
|
||||
import static org.schabi.newpipe.util.ListHelper.getUrlAndNonTorrentStreams;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
|
|
@ -17,6 +18,7 @@ import androidx.appcompat.app.AlertDialog;
|
|||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
|
||||
|
|
@ -29,8 +31,11 @@ import org.schabi.newpipe.RouterActivity;
|
|||
import org.schabi.newpipe.about.AboutActivity;
|
||||
import org.schabi.newpipe.database.feed.model.FeedGroupEntity;
|
||||
import org.schabi.newpipe.download.DownloadActivity;
|
||||
import org.schabi.newpipe.error.ErrorUtil;
|
||||
import org.schabi.newpipe.extractor.NewPipe;
|
||||
import org.schabi.newpipe.extractor.StreamingService;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfo;
|
||||
import org.schabi.newpipe.extractor.comments.CommentsInfoItem;
|
||||
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
|
||||
import org.schabi.newpipe.extractor.stream.AudioStream;
|
||||
import org.schabi.newpipe.extractor.stream.DeliveryMethod;
|
||||
|
|
@ -41,6 +46,7 @@ import org.schabi.newpipe.extractor.stream.VideoStream;
|
|||
import org.schabi.newpipe.fragments.MainFragment;
|
||||
import org.schabi.newpipe.fragments.detail.VideoDetailFragment;
|
||||
import org.schabi.newpipe.fragments.list.channel.ChannelFragment;
|
||||
import org.schabi.newpipe.fragments.list.comments.CommentRepliesFragment;
|
||||
import org.schabi.newpipe.fragments.list.kiosk.KioskFragment;
|
||||
import org.schabi.newpipe.fragments.list.playlist.PlaylistFragment;
|
||||
import org.schabi.newpipe.fragments.list.search.SearchFragment;
|
||||
|
|
@ -476,6 +482,29 @@ public final class NavigationHelper {
|
|||
item.getServiceId(), uploaderUrl, item.getUploaderName());
|
||||
}
|
||||
|
||||
public static void openCommentAuthorIfPresent(@NonNull final FragmentActivity activity,
|
||||
final CommentsInfoItem comment) {
|
||||
if (isEmpty(comment.getUploaderUrl())) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
openChannelFragment(activity.getSupportFragmentManager(), comment.getServiceId(),
|
||||
comment.getUploaderUrl(), comment.getUploaderName());
|
||||
} catch (final Exception e) {
|
||||
ErrorUtil.showUiErrorSnackbar(activity, "Opening channel fragment", e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void openCommentRepliesFragment(@NonNull final FragmentActivity activity,
|
||||
final CommentsInfo commentsInfo,
|
||||
final CommentsInfoItem commentsInfoItem) {
|
||||
defaultTransaction(activity.getSupportFragmentManager())
|
||||
.replace(R.id.fragment_holder,
|
||||
new CommentRepliesFragment(commentsInfo, commentsInfoItem))
|
||||
.addToBackStack(null)
|
||||
.commit();
|
||||
}
|
||||
|
||||
public static void openPlaylistFragment(final FragmentManager fragmentManager,
|
||||
final int serviceId, final String url,
|
||||
@NonNull final String name) {
|
||||
|
|
|
|||
|
|
@ -144,6 +144,14 @@ public final class ServiceHelper {
|
|||
.orElse("<unknown>");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static StreamingService getServiceById(final int serviceId) {
|
||||
return ServiceList.all().stream()
|
||||
.filter(s -> s.getServiceId() == serviceId)
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
}
|
||||
|
||||
public static void setSelectedServiceId(final Context context, final int serviceId) {
|
||||
String serviceName;
|
||||
try {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue