Skip to content

Commit

Permalink
Fix file viewer behavior when API returns empty file contents
Browse files Browse the repository at this point in the history
  • Loading branch information
Fs00 authored and maniac103 committed Jul 6, 2024
1 parent 4aa009b commit 8d11775
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions app/src/main/java/com/gh4a/activities/FileViewerActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import com.meisolsson.githubsdk.service.repositories.RepositoryContentService;

import java.util.List;
import java.util.Objects;

import io.reactivex.Single;

Expand Down Expand Up @@ -364,8 +365,16 @@ private void loadFile(boolean force) {
.subscribe(result -> {
if (result.isPresent()) {
mContent = result.get();
onDataReady();
setContentEmpty(false);
// When file size is >1 and <100 MB, the GH API endpoint returns a successful response
// but does not include the file contents in the response payload.
// See https://docs.github.com/en/rest/repos/contents#get-repository-content
boolean fileContentIsMissing = mContent.size() > 0 && Objects.equals(mContent.content(), "");
if (fileContentIsMissing) {
openUnsuitableFileAndFinish();
} else {
onDataReady();
setContentEmpty(false);
}
} else {
setContentEmpty(true);
setContentShown(true);
Expand Down

0 comments on commit 8d11775

Please sign in to comment.