Dbrant has uploaded a new change for review. (
https://gerrit.wikimedia.org/r/352909 )
Change subject: Show message when viewing an offline version of an article.
......................................................................
Show message when viewing an offline version of an article.
Bug: T156082
Change-Id: Ie7def613e1258e633e92a95b2a0bdcbef2853049
---
M app/src/main/java/org/wikipedia/page/PageFragmentLoadState.java
M app/src/main/java/org/wikipedia/util/DateUtil.java
M app/src/main/res/values-qq/strings.xml
M app/src/main/res/values/strings.xml
4 files changed, 35 insertions(+), 1 deletion(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/09/352909/1
diff --git a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.java
b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.java
index aa22c25..673d22f 100644
--- a/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.java
+++ b/app/src/main/java/org/wikipedia/page/PageFragmentLoadState.java
@@ -11,6 +11,7 @@
import android.util.SparseArray;
import android.view.View;
import android.view.ViewGroup;
+import android.widget.Toast;
import org.json.JSONException;
import org.json.JSONObject;
@@ -35,6 +36,7 @@
import org.wikipedia.page.leadimages.LeadImagesHandler;
import org.wikipedia.pageimages.PageImage;
import org.wikipedia.pageimages.PageImagesClient;
+import org.wikipedia.util.DateUtil;
import org.wikipedia.util.DeviceUtil;
import org.wikipedia.util.DimenUtil;
import org.wikipedia.util.L10nUtil;
@@ -44,6 +46,7 @@
import org.wikipedia.views.ObservableWebView;
import org.wikipedia.views.SwipeRefreshLayoutWithScroll;
+import java.text.ParseException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -258,6 +261,9 @@
app.getSessionFunnel().leadSectionFetchEnd();
PageLead lead = rsp.body();
onLeadSectionLoaded(lead, startSequenceNum);
+ if (rsp.raw().cacheResponse() != null) {
+ showPageOfflineMessage(rsp.raw().header("date",
""));
+ }
}
@Override public void onFailure(Call<PageLead> call,
Throwable t) {
@@ -517,6 +523,21 @@
return getRemoteConfig().optBoolean("disableAnonEditing", false);
}
+ private void showPageOfflineMessage(@NonNull String dateHeader) {
+ if (!fragment.isAdded()) {
+ return;
+ }
+ try {
+ String dateStr = DateUtil.getShortDateString(DateUtil
+ .getHttpLastModifiedDate(dateHeader));
+ Toast.makeText(fragment.getContext().getApplicationContext(),
+ fragment.getString(R.string.page_offline_notice_last_date,
dateStr),
+ Toast.LENGTH_LONG).show();
+ } catch (ParseException e) {
+ // ignore
+ }
+ }
+
private JSONObject getRemoteConfig() {
return app.getRemoteConfig().getConfig();
}
diff --git a/app/src/main/java/org/wikipedia/util/DateUtil.java
b/app/src/main/java/org/wikipedia/util/DateUtil.java
index 1f79cd4..06aea45 100644
--- a/app/src/main/java/org/wikipedia/util/DateUtil.java
+++ b/app/src/main/java/org/wikipedia/util/DateUtil.java
@@ -6,6 +6,7 @@
import org.wikipedia.feed.model.UtcDate;
import java.text.DateFormat;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
@@ -25,10 +26,14 @@
}
public static String getFeedCardDateString(@NonNull Calendar date) {
- return getFeedCardDateString(date.getTime());
+ return getShortDateString(date.getTime());
}
public static String getFeedCardDateString(@NonNull Date date) {
+ return getShortDateString(date);
+ }
+
+ public static String getShortDateString(@NonNull Date date) {
// todo: consider allowing TWN date formats. It would be useful to
have but might be
// difficult for translators to write correct format specifiers
without being able to
// test them. We should investigate localization support in date
libraries such as
@@ -42,6 +47,12 @@
return new UtcDate(age);
}
+ public static Date getHttpLastModifiedDate(@NonNull String dateStr) throws
ParseException {
+ SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss
zzz", Locale.ROOT);
+ df.setTimeZone(TimeZone.getTimeZone("UTC"));
+ return df.parse(dateStr);
+ }
+
private DateUtil() {
}
}
diff --git a/app/src/main/res/values-qq/strings.xml
b/app/src/main/res/values-qq/strings.xml
index bf4ae07..0fc2a78 100644
--- a/app/src/main/res/values-qq/strings.xml
+++ b/app/src/main/res/values-qq/strings.xml
@@ -353,6 +353,7 @@
<string name="button_add_to_reading_list">Button text for adding the current
page to a reading list.</string>
<string name="page_offline_notice_cannot_load_while_offline">Message
informing the user that an article cannot be loaded while the app is offline.
This message is followed by page_offline_notice_add_to_reading_list.</string>
<string name="page_offline_notice_add_to_reading_list">Message inviting the
user to add the requested article to a reading list to be donwloaded when the
app is online. This message follows
{{msg-wm|Wikipedia-android-strings-page_offline_notice_cannot_load_while_offline}}.</string>
+ <string name="page_offline_notice_last_date">Message that tells the user
that the current article is loaded from offline storage. The %s symbol is
replaced with the date when the article was saved.</string>
<string name="button_get_directions">Button to obtain directions to the
location specified in the link preview.</string>
<string name="error_no_maps_app">Error displayed when the device does not
have any apps installed that are capable of providing directions to a
location.</string>
<string name="preference_title_show_link_previews">Title of the preference
for enabling or disabling link previews.
diff --git a/app/src/main/res/values/strings.xml
b/app/src/main/res/values/strings.xml
index 9db3cc4..c596131 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -247,6 +247,7 @@
<string name="button_add_to_reading_list">Add to reading list</string>
<string name="page_offline_notice_cannot_load_while_offline">Article
cannot be loaded while offline.</string>
<string name="page_offline_notice_add_to_reading_list">Add the article to
a reading list and it will be downloaded once you\'re back online.</string>
+ <string name="page_offline_notice_last_date">You are reading an offline
version of this article saved on %s.</string>
<string name="button_get_directions">Get directions</string>
<string name="error_no_maps_app">Could not find any apps that provide
directions.</string>
<string name="preference_title_show_link_previews">Show link
previews</string>
--
To view, visit https://gerrit.wikimedia.org/r/352909
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie7def613e1258e633e92a95b2a0bdcbef2853049
Gerrit-PatchSet: 1
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits