Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace PrettyTime with DateUtils.getRelativeTimeSpanString() #3567

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ dependencies {
implementation 'io.reactivex.rxjava2:rxjava:2.2.2'
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
implementation 'com.jakewharton.rxbinding2:rxbinding:2.1.1'
implementation 'org.ocpsoft.prettytime:prettytime:4.0.3.Final'

implementation "androidx.room:room-runtime:${roomDbLibVersion}"
implementation "androidx.room:room-rxjava2:${roomDbLibVersion}"
Expand Down
1 change: 0 additions & 1 deletion app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

-dontobfuscate
-keep class org.schabi.newpipe.extractor.timeago.patterns.** { *; }
-keep class org.ocpsoft.prettytime.i18n.** { *; }

-keep class org.mozilla.javascript.** { *; }

Expand Down
2 changes: 0 additions & 2 deletions app/src/main/java/org/schabi/newpipe/about/AboutActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ public class AboutActivity extends AppCompatActivity {
"https://github.com/ReactiveX/RxJava", StandardLicenses.APACHE2),
new SoftwareComponent("RxBinding", "2015 - 2018", "Jake Wharton",
"https://github.com/JakeWharton/RxBinding", StandardLicenses.APACHE2),
new SoftwareComponent("PrettyTime", "2012 - 2020", "Lincoln Baxter, III",
"https://github.com/ocpsoft/prettytime", StandardLicenses.APACHE2),
new SoftwareComponent("Markwon", "2017 - 2020", "Noties",
"https://github.com/noties/Markwon", StandardLicenses.APACHE2),
new SoftwareComponent("Groupie", "2016", "Lisa Wray",
Expand Down
26 changes: 5 additions & 21 deletions app/src/main/java/org/schabi/newpipe/util/Localization.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.DisplayMetrics;

import androidx.annotation.NonNull;
import androidx.annotation.PluralsRes;
import androidx.annotation.StringRes;

import org.ocpsoft.prettytime.PrettyTime;
import org.ocpsoft.prettytime.units.Decade;
import org.schabi.newpipe.R;
import org.schabi.newpipe.extractor.ListExtractor;
import org.schabi.newpipe.extractor.localization.ContentCountry;
Expand Down Expand Up @@ -53,12 +52,11 @@
public final class Localization {

private static final String DOT_SEPARATOR = " • ";
private static PrettyTime prettyTime;

private Localization() { }

public static void init(final Context context) {
initPrettyTime(context);

}

@NonNull
Expand Down Expand Up @@ -290,24 +288,10 @@ public static String localizeDuration(final Context context, final int durationI
}
}

/*//////////////////////////////////////////////////////////////////////////
// Pretty Time
//////////////////////////////////////////////////////////////////////////*/

private static void initPrettyTime(final Context context) {
prettyTime = new PrettyTime(getAppLocale(context));
// Do not use decades as YouTube doesn't either.
prettyTime.removeUnit(Decade.class);
}

private static PrettyTime getPrettyTime() {
return prettyTime;
}

public static String relativeTime(final Calendar calendarTime) {
String time = getPrettyTime().formatUnrounded(calendarTime);
return time.startsWith("-") ? time.substring(1) : time;
//workaround fix for russian showing -1 day ago, -19hrs ago…
return DateUtils.getRelativeTimeSpanString(
calendarTime.getTimeInMillis(), System.currentTimeMillis(),
DateUtils.MINUTE_IN_MILLIS).toString();
}

private static void changeAppLanguage(final Locale loc, final Resources res) {
Expand Down