Merge branch 'last-updated-time' into 'master'
Improve display of last updated time See merge request !519
This commit is contained in:
commit
7cf5f2496c
@ -32,6 +32,7 @@ import android.text.Html;
|
|||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
import android.text.format.DateUtils;
|
||||||
import android.text.style.CharacterStyle;
|
import android.text.style.CharacterStyle;
|
||||||
import android.text.style.TypefaceSpan;
|
import android.text.style.TypefaceSpan;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
@ -518,6 +519,26 @@ public final class Utils {
|
|||||||
return (int) TimeUnit.MILLISECONDS.toDays(msDiff);
|
return (int) TimeUnit.MILLISECONDS.toDays(msDiff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String formatLastUpdated(@NonNull Resources res, @NonNull Date date) {
|
||||||
|
long msDiff = Calendar.getInstance().getTimeInMillis() - date.getTime();
|
||||||
|
long days = msDiff / DateUtils.DAY_IN_MILLIS;
|
||||||
|
long weeks = msDiff / (DateUtils.DAY_IN_MILLIS * 7);
|
||||||
|
long months = msDiff / (DateUtils.DAY_IN_MILLIS * 30);
|
||||||
|
long years = msDiff / (DateUtils.DAY_IN_MILLIS * 365);
|
||||||
|
|
||||||
|
if (days < 1) {
|
||||||
|
return res.getString(R.string.details_last_updated_today);
|
||||||
|
} else if (weeks < 1) {
|
||||||
|
return res.getQuantityString(R.plurals.details_last_update_days, (int) days, days);
|
||||||
|
} else if (months < 1) {
|
||||||
|
return res.getQuantityString(R.plurals.details_last_update_months, (int) months, months);
|
||||||
|
} else if (years < 1) {
|
||||||
|
return res.getQuantityString(R.plurals.details_last_update_weeks, (int) weeks, weeks);
|
||||||
|
} else {
|
||||||
|
return res.getQuantityString(R.plurals.details_last_update_years, (int) years, years);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Need this to add the unimplemented support for ordered and unordered
|
// Need this to add the unimplemented support for ordered and unordered
|
||||||
// lists to Html.fromHtml().
|
// lists to Html.fromHtml().
|
||||||
public static class HtmlTagHandler implements Html.TagHandler {
|
public static class HtmlTagHandler implements Html.TagHandler {
|
||||||
|
@ -33,9 +33,11 @@ import android.widget.LinearLayout;
|
|||||||
import android.widget.ProgressBar;
|
import android.widget.ProgressBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||||
import com.nostra13.universalimageloader.core.ImageLoader;
|
import com.nostra13.universalimageloader.core.ImageLoader;
|
||||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||||
|
|
||||||
import org.fdroid.fdroid.Preferences;
|
import org.fdroid.fdroid.Preferences;
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -408,15 +410,8 @@ public class AppDetailsRecyclerViewAdapter
|
|||||||
authorView.setVisibility(View.GONE);
|
authorView.setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
if (app.lastUpdated != null) {
|
if (app.lastUpdated != null) {
|
||||||
int daysSince = Utils.daysSince(app.lastUpdated);
|
Resources res = lastUpdateView.getContext().getResources();
|
||||||
String text;
|
lastUpdateView.setText(Utils.formatLastUpdated(res, app.lastUpdated));
|
||||||
Resources resources = lastUpdateView.getContext().getResources();
|
|
||||||
if (daysSince < 1) {
|
|
||||||
text = resources.getString(R.string.details_last_updated_today);
|
|
||||||
} else {
|
|
||||||
text = resources.getQuantityString(R.plurals.details_last_update_days, daysSince, daysSince);
|
|
||||||
}
|
|
||||||
lastUpdateView.setText(text);
|
|
||||||
lastUpdateView.setVisibility(View.VISIBLE);
|
lastUpdateView.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
lastUpdateView.setVisibility(View.GONE);
|
lastUpdateView.setVisibility(View.GONE);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package org.fdroid.fdroid.views.main;
|
package org.fdroid.fdroid.views.main;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Resources;
|
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
@ -15,6 +14,7 @@ import android.support.v7.widget.RecyclerView;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.fdroid.fdroid.R;
|
import org.fdroid.fdroid.R;
|
||||||
import org.fdroid.fdroid.UpdateService;
|
import org.fdroid.fdroid.UpdateService;
|
||||||
import org.fdroid.fdroid.Utils;
|
import org.fdroid.fdroid.Utils;
|
||||||
@ -122,15 +122,7 @@ class WhatsNewViewBinder implements LoaderManager.LoaderCallbacks<Cursor> {
|
|||||||
if (lastUpdate == null) {
|
if (lastUpdate == null) {
|
||||||
emptyStateText.append(activity.getString(R.string.latest__empty_state__never_updated));
|
emptyStateText.append(activity.getString(R.string.latest__empty_state__never_updated));
|
||||||
} else {
|
} else {
|
||||||
int daysSince = Utils.daysSince(lastUpdate);
|
emptyStateText.append(Utils.formatLastUpdated(activity.getResources(), lastUpdate));
|
||||||
Resources resources = activity.getResources();
|
|
||||||
String text;
|
|
||||||
if (daysSince < 1) {
|
|
||||||
text = resources.getString(R.string.details_last_updated_today);
|
|
||||||
} else {
|
|
||||||
text = resources.getQuantityString(R.plurals.details_last_update_days, daysSince, daysSince);
|
|
||||||
}
|
|
||||||
emptyStateText.append(text);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -554,4 +554,16 @@
|
|||||||
<item quantity="one">Updated %1$s day ago</item>
|
<item quantity="one">Updated %1$s day ago</item>
|
||||||
<item quantity="other">Updated %1$s days ago</item>
|
<item quantity="other">Updated %1$s days ago</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<plurals name="details_last_update_weeks">
|
||||||
|
<item quantity="one">Updated %1$s week ago</item>
|
||||||
|
<item quantity="other">Updated %1$s weeks ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="details_last_update_months">
|
||||||
|
<item quantity="one">Updated %1$s month ago</item>
|
||||||
|
<item quantity="other">Updated %1$s months ago</item>
|
||||||
|
</plurals>
|
||||||
|
<plurals name="details_last_update_years">
|
||||||
|
<item quantity="one">Updated %1$s year ago</item>
|
||||||
|
<item quantity="other">Updated %1$s years ago</item>
|
||||||
|
</plurals>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user