Check if releasesList is empty (#2183)

When deserializing with Gson, non-existent blocks are assigned to null
https://github.com/google/gson/issues/513
This commit is contained in:
Howard Wu 2022-10-18 19:29:25 +08:00 committed by GitHub
parent 4c6d748be3
commit 993c429f90
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 58 additions and 16 deletions

View File

@ -209,9 +209,9 @@ public class RepoLoader {
if (module != null) {
releases = module.getReleases();
if (!module.releasesLoaded) {
if (channel.equals(channels[1]) && !module.getBetaReleases().isEmpty()) {
if (channel.equals(channels[1]) && !(module.getBetaReleases() != null && module.getBetaReleases().isEmpty())) {
releases = module.getBetaReleases();
} else if (channel.equals(channels[2]) && !module.getSnapshotReleases().isEmpty())
} else if (channel.equals(channels[2]) && !(module.getSnapshotReleases() != null && module.getSnapshotReleases().isEmpty()))
releases = module.getSnapshotReleases();
}
}

View File

@ -20,6 +20,8 @@
package org.lsposed.manager.repo.model;
import androidx.annotation.Nullable;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@ -32,6 +34,7 @@ public class Collaborator {
@Expose
private String name;
@Nullable
public String getLogin() {
return login;
}
@ -40,6 +43,7 @@ public class Collaborator {
this.login = login;
}
@Nullable
public String getName() {
return name;
}

View File

@ -104,6 +104,7 @@ public class OnlineModule {
private Integer stargazerCount;
public boolean releasesLoaded = false;
@Nullable
public String getName() {
return name;
}
@ -112,6 +113,7 @@ public class OnlineModule {
this.name = name;
}
@Nullable
public String getDescription() {
return description;
}
@ -120,6 +122,7 @@ public class OnlineModule {
this.description = description;
}
@Nullable
public String getUrl() {
return url;
}
@ -128,6 +131,7 @@ public class OnlineModule {
this.url = url;
}
@Nullable
public String getHomepageUrl() {
return homepageUrl;
}
@ -136,6 +140,7 @@ public class OnlineModule {
this.homepageUrl = homepageUrl;
}
@Nullable
public List<Collaborator> getCollaborators() {
return collaborators;
}
@ -144,10 +149,12 @@ public class OnlineModule {
this.collaborators = collaborators;
}
@Nullable
public List<Release> getReleases() {
return releases;
}
@Nullable
public String getLatestReleaseTime() {
return latestReleaseTime;
}
@ -156,6 +163,7 @@ public class OnlineModule {
this.releases = releases;
}
@Nullable
public String getReadme() {
return readme;
}
@ -164,6 +172,7 @@ public class OnlineModule {
this.readme = readme;
}
@Nullable
public String getReadmeHTML() {
return readmeHTML;
}
@ -172,7 +181,7 @@ public class OnlineModule {
this.readmeHTML = readmeHTML;
}
@Nullable
public String getSummary() {
return summary;
}
@ -181,6 +190,7 @@ public class OnlineModule {
this.summary = summary;
}
@Nullable
public List<String> getScope() {
return scope;
}
@ -189,6 +199,7 @@ public class OnlineModule {
this.scope = scope;
}
@Nullable
public String getSourceUrl() {
return sourceUrl;
}
@ -205,6 +216,7 @@ public class OnlineModule {
this.hide = hide;
}
@Nullable
public List<Object> getAdditionalAuthors() {
return additionalAuthors;
}
@ -213,6 +225,7 @@ public class OnlineModule {
this.additionalAuthors = additionalAuthors;
}
@Nullable
public String getUpdatedAt() {
return updatedAt;
}
@ -221,6 +234,7 @@ public class OnlineModule {
this.updatedAt = updatedAt;
}
@Nullable
public String getCreatedAt() {
return createdAt;
}
@ -229,6 +243,7 @@ public class OnlineModule {
this.createdAt = createdAt;
}
@Nullable
public Integer getStargazerCount() {
return stargazerCount;
}
@ -237,6 +252,7 @@ public class OnlineModule {
this.stargazerCount = stargazerCount;
}
@Nullable
public String getLatestRelease() {
return latestRelease;
}
@ -265,10 +281,12 @@ public class OnlineModule {
return latestSnapshotReleaseTime;
}
@Nullable
public List<Release> getBetaReleases() {
return betaReleases;
}
@Nullable
public List<Release> getSnapshotReleases() {
return snapshotReleases;
}

View File

@ -20,6 +20,8 @@
package org.lsposed.manager.repo.model;
import androidx.annotation.Nullable;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@ -59,6 +61,7 @@ public class Release {
@Expose
private List<ReleaseAsset> releaseAssets = new ArrayList<>();
@Nullable
public String getName() {
return name;
}
@ -67,6 +70,7 @@ public class Release {
this.name = name;
}
@Nullable
public String getUrl() {
return url;
}
@ -75,6 +79,7 @@ public class Release {
this.url = url;
}
@Nullable
public String getDescription() {
return description;
}
@ -83,6 +88,7 @@ public class Release {
this.description = description;
}
@Nullable
public String getDescriptionHTML() {
return descriptionHTML;
}
@ -91,6 +97,7 @@ public class Release {
this.descriptionHTML = descriptionHTML;
}
@Nullable
public String getCreatedAt() {
return createdAt;
}
@ -99,6 +106,7 @@ public class Release {
this.createdAt = createdAt;
}
@Nullable
public String getPublishedAt() {
return publishedAt;
}
@ -107,6 +115,7 @@ public class Release {
this.publishedAt = publishedAt;
}
@Nullable
public String getUpdatedAt() {
return updatedAt;
}
@ -115,6 +124,7 @@ public class Release {
this.updatedAt = updatedAt;
}
@Nullable
public String getTagName() {
return tagName;
}
@ -123,6 +133,7 @@ public class Release {
this.tagName = tagName;
}
@Nullable
public Boolean getIsPrerelease() {
return isPrerelease;
}
@ -131,6 +142,7 @@ public class Release {
this.isPrerelease = isPrerelease;
}
@Nullable
public List<ReleaseAsset> getReleaseAssets() {
return releaseAssets;
}

View File

@ -20,6 +20,8 @@
package org.lsposed.manager.repo.model;
import androidx.annotation.Nullable;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@ -35,6 +37,7 @@ public class ReleaseAsset {
@Expose
private String downloadUrl;
@Nullable
public String getName() {
return name;
}
@ -43,6 +46,7 @@ public class ReleaseAsset {
this.name = name;
}
@Nullable
public String getContentType() {
return contentType;
}
@ -51,6 +55,7 @@ public class ReleaseAsset {
this.contentType = contentType;
}
@Nullable
public String getDownloadUrl() {
return downloadUrl;
}

View File

@ -356,7 +356,7 @@ public class RepoFragment extends BaseFragment implements RepoLoader.RepoListene
int sort = App.getPreferences().getInt("repo_sort", 0);
boolean upgradableFirst = App.getPreferences().getBoolean("upgradable_first", true);
ConcurrentHashMap<String, Boolean> upgradable = new ConcurrentHashMap<>();
fullList = modules.parallelStream().filter((onlineModule -> !onlineModule.isHide() && !onlineModule.getReleases().isEmpty()))
fullList = modules.parallelStream().filter((onlineModule -> !onlineModule.isHide() && !(onlineModule.getReleases() != null && onlineModule.getReleases().isEmpty())))
.sorted((a, b) -> {
if (upgradableFirst) {
var aUpgrade = upgradable.computeIfAbsent(a.getName(), n -> getUpgradableVer(a) != null);

View File

@ -238,7 +238,7 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
if (releaseAdapter != null) {
runAsync(releaseAdapter::loadItems);
}
if (module.getReleases().size() == 1) {
if ((module.getReleases() != null ? module.getReleases().size() : 1) == 1) {
showHint(R.string.module_release_no_more, true);
}
}
@ -282,13 +282,16 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
holder.title.setText(R.string.module_information_homepage);
holder.description.setText(module.getHomepageUrl());
} else if (position == collaboratorsRow) {
holder.title.setText(R.string.module_information_collaborators);
List<Collaborator> collaborators = module.getCollaborators();
if (collaborators == null) return;
holder.title.setText(R.string.module_information_collaborators);
SpannableStringBuilder sb = new SpannableStringBuilder();
ListIterator<Collaborator> iterator = collaborators.listIterator();
while (iterator.hasNext()) {
Collaborator collaborator = iterator.next();
String name = collaborator.getName() == null ? collaborator.getLogin() : collaborator.getName();
var collaboratorLogin = collaborator.getLogin();
if (collaboratorLogin == null) continue;
String name = collaborator.getName() == null ? collaboratorLogin : collaborator.getName();
sb.append(name);
CustomTabsURLSpan span = new CustomTabsURLSpan(requireActivity(), String.format("https://github.com/%s", collaborator.getLogin()));
sb.setSpan(span, sb.length() - name.length(), sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
@ -374,16 +377,16 @@ public class RepoItemFragment extends BaseFragment implements RepoLoader.RepoLis
if (releases == null) releases = module.getReleases();
List<Release> tmpList;
if (channel.equals(channels[0])) {
tmpList = releases.parallelStream().filter(t -> {
if (t.getIsPrerelease()) return false;
var name = t.getName().toLowerCase(LocaleDelegate.getDefaultLocale());
return !name.startsWith("snapshot") && !name.startsWith("nightly");
}).collect(Collectors.toList());
tmpList = releases != null ? releases.parallelStream().filter(t -> {
if (Boolean.TRUE.equals(t.getIsPrerelease())) return false;
var name = t.getName() != null ? t.getName().toLowerCase(LocaleDelegate.getDefaultLocale()) : null;
return !(name != null && name.startsWith("snapshot")) && !(name != null && name.startsWith("nightly"));
}).collect(Collectors.toList()) : null;
} else if (channel.equals(channels[1])) {
tmpList = releases.parallelStream().filter(t -> {
var name = t.getName().toLowerCase(LocaleDelegate.getDefaultLocale());
return !name.startsWith("snapshot") && !name.startsWith("nightly");
}).collect(Collectors.toList());
tmpList = releases != null ? releases.parallelStream().filter(t -> {
var name = t.getName() != null ? t.getName().toLowerCase(LocaleDelegate.getDefaultLocale()) : null;
return !(name != null && name.startsWith("snapshot")) && !(name != null && name.startsWith("nightly"));
}).collect(Collectors.toList()) : null;
} else tmpList = releases;
runOnUiThread(() -> {
items = tmpList;