Dbrant has uploaded a new change for review. (
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 agains 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, 27 insertions(+), 14 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/apps/android/wikipedia
refs/changes/81/375081/1
diff --git a/app/src/main/java/org/wikipedia/offline/Compilation.java
b/app/src/main/java/org/wikipedia/offline/Compilation.java
index f4a2ac7..1518db9 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;
@@ -74,13 +74,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 +144,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..b3a17ca 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();
--
To view, visit https://gerrit.wikimedia.org/r/375081
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie0c5e1abe5e1d921ff5bf1b62587095fa5244c08
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