jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/375081 )

Change subject: Update compilation metadata in Local activity, as well as 
Remote.
......................................................................


Update compilation metadata in Local activity, as well as Remote.

A couple of things:
- This updates LocalCompilationsFragment to request compilation metadata,
  so that any new packs that are discovered will immediately be updated
  with correct information.
- Guard against fragment destruction in Local and Remote callbacks.
- In the Compilation class, let's make the Date be @NonNull, because this
  class needs to be serialized by Gson for saving to Prefs (when
  persisting cached compilations), and a null Date does not serialize
  well; in fact it crashes.

Bug: T174716
Change-Id: Ie0c5e1abe5e1d921ff5bf1b62587095fa5244c08
---
M app/src/main/java/org/wikipedia/offline/Compilation.java
M app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
M app/src/main/java/org/wikipedia/offline/RemoteCompilationsFragment.java
3 files changed, 33 insertions(+), 14 deletions(-)

Approvals:
  jenkins-bot: Verified
  Mholloway: Looks good to me, approved



diff --git a/app/src/main/java/org/wikipedia/offline/Compilation.java 
b/app/src/main/java/org/wikipedia/offline/Compilation.java
index f4a2ac7..3896511 100644
--- a/app/src/main/java/org/wikipedia/offline/Compilation.java
+++ b/app/src/main/java/org/wikipedia/offline/Compilation.java
@@ -38,7 +38,7 @@
     @Nullable private Image featureImage;
     private long count;
     private long size; // bytes
-    @Nullable private Date date;
+    @NonNull private Date date = new Date();
 
     @Nullable private String path;
     @Nullable private transient ZimFile file;
@@ -46,6 +46,9 @@
 
     public enum MediaContent {
         ALL, NOVID, NOPIC
+    }
+
+    public Compilation() {
     }
 
     Compilation(@NonNull File file) throws IOException {
@@ -74,13 +77,11 @@
         this.featureImage = new Image(Uri.parse(data[7]), 0, 0);
         this.count = 0;  // currently unused
         this.size = Long.parseLong(data[9]);
-        Date d = null;
         try {
-            d = getIso8601DateFormatShort().parse(data[10]);
+            this.date = getIso8601DateFormatShort().parse(data[10]);
         } catch (ParseException e) {
             L.e(e);
         }
-        this.date = d;
     }
 
     public void copyMetadataFrom(@NonNull Compilation other) {
@@ -146,14 +147,10 @@
 
     @NonNull
     public Date date() {
-        if (date == null) {
-            if (reader != null) {
-                date = reader.getZimDate();
-            } else if (file != null) {
-                date = new Date(file.lastModified());
-            } else {
-                date = new Date();
-            }
+        if (reader != null) {
+            date = reader.getZimDate();
+        } else if (file != null) {
+            date = new Date(file.lastModified());
         }
         return date;
     }
diff --git 
a/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java 
b/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
index 8e0d658..f198877 100644
--- a/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
+++ b/app/src/main/java/org/wikipedia/offline/LocalCompilationsFragment.java
@@ -55,6 +55,7 @@
     private Throwable lastError;
     private CompilationItemAdapter adapter = new CompilationItemAdapter();
     private ItemCallback itemCallback = new ItemCallback();
+    private CompilationClientCallback compilationClientCallback = new 
CompilationClientCallback();
 
     @NonNull private List<Compilation> displayedItems = new ArrayList<>();
 
@@ -64,8 +65,7 @@
 
     @NonNull
     public static LocalCompilationsFragment newInstance() {
-        LocalCompilationsFragment instance = new LocalCompilationsFragment();
-        return instance;
+        return new LocalCompilationsFragment();
     }
 
     @Nullable
@@ -125,6 +125,7 @@
         updating = false;
         lastError = null;
         update();
+        new CompilationClient().request(compilationClientCallback);
     }
 
     public void onCompilationsError(Throwable t) {
@@ -334,6 +335,21 @@
         });
     }
 
+    private class CompilationClientCallback implements 
CompilationClient.Callback {
+        @Override
+        public void success(@NonNull List<Compilation> compilations) {
+            if (!isAdded()) {
+                return;
+            }
+            OfflineManager.instance().updateFromRemoteMetadata(compilations);
+            update();
+        }
+
+        @Override
+        public void error(@NonNull Throwable caught) {
+        }
+    }
+
     @Nullable private Callback callback() {
         return FragmentUtil.getCallback(this, Callback.class);
     }
diff --git 
a/app/src/main/java/org/wikipedia/offline/RemoteCompilationsFragment.java 
b/app/src/main/java/org/wikipedia/offline/RemoteCompilationsFragment.java
index 62c910f..83c6be0 100644
--- a/app/src/main/java/org/wikipedia/offline/RemoteCompilationsFragment.java
+++ b/app/src/main/java/org/wikipedia/offline/RemoteCompilationsFragment.java
@@ -322,6 +322,9 @@
     private class CompilationCallback implements CompilationClient.Callback {
         @Override
         public void success(@NonNull List<Compilation> compilations) {
+            if (!isAdded()) {
+                return;
+            }
             OfflineManager.instance().updateFromRemoteMetadata(compilations);
 
             allItems.clear();
@@ -344,6 +347,9 @@
 
         @Override
         public void error(@NonNull Throwable caught) {
+            if (!isAdded()) {
+                return;
+            }
             updating = false;
             lastError = caught;
             updateEmptyState();

-- 
To view, visit https://gerrit.wikimedia.org/r/375081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ie0c5e1abe5e1d921ff5bf1b62587095fa5244c08
Gerrit-PatchSet: 3
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: Cooltey <[email protected]>
Gerrit-Reviewer: Dbrant <[email protected]>
Gerrit-Reviewer: Mholloway <[email protected]>
Gerrit-Reviewer: Sharvaniharan <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to