Native rewrite #878
2 changed files with 55 additions and 25 deletions
|
@ -102,6 +102,7 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
private static final int RELATED_CONTENT_SIZE = 16;
|
private static final int RELATED_CONTENT_SIZE = 16;
|
||||||
private static boolean startingShareActivity;
|
private static boolean startingShareActivity;
|
||||||
|
|
||||||
|
private boolean loadingNewClaim;
|
||||||
private boolean stopServiceReceived;
|
private boolean stopServiceReceived;
|
||||||
private boolean downloadInProgress;
|
private boolean downloadInProgress;
|
||||||
private boolean downloadRequested;
|
private boolean downloadRequested;
|
||||||
|
@ -189,6 +190,11 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
renderTotalDuration();
|
renderTotalDuration();
|
||||||
scheduleElapsedPlayback();
|
scheduleElapsedPlayback();
|
||||||
hideBuffering();
|
hideBuffering();
|
||||||
|
|
||||||
|
if (loadingNewClaim) {
|
||||||
|
MainActivity.appPlayer.setPlayWhenReady(true);
|
||||||
|
loadingNewClaim = false;
|
||||||
|
}
|
||||||
} else if (playbackState == Player.STATE_BUFFERING) {
|
} else if (playbackState == Player.STATE_BUFFERING) {
|
||||||
showBuffering();
|
showBuffering();
|
||||||
} else {
|
} else {
|
||||||
|
@ -245,10 +251,7 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initialFileLoadDone = false;
|
onNewClaim(newUrl);
|
||||||
currentUrl = newUrl;
|
|
||||||
logUrlEvent(newUrl);
|
|
||||||
resetViewCount();
|
|
||||||
ClaimCacheKey key = new ClaimCacheKey();
|
ClaimCacheKey key = new ClaimCacheKey();
|
||||||
key.setClaimId(newClaimId);
|
key.setClaimId(newClaimId);
|
||||||
if (!Helper.isNullOrEmpty(newUrl) && newUrl.contains("#")) {
|
if (!Helper.isNullOrEmpty(newUrl) && newUrl.contains("#")) {
|
||||||
|
@ -256,6 +259,35 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
key.setCanonicalUrl(newUrl);
|
key.setCanonicalUrl(newUrl);
|
||||||
key.setShortUrl(newUrl);
|
key.setShortUrl(newUrl);
|
||||||
}
|
}
|
||||||
|
loadClaimForCacheKey(key, newUrl);
|
||||||
|
} else if (!Helper.isNullOrEmpty(newUrl)) {
|
||||||
|
if (currentUrl != null && currentUrl.equalsIgnoreCase(newUrl)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
onNewClaim(newUrl);
|
||||||
|
ClaimCacheKey key = new ClaimCacheKey();
|
||||||
|
key.setPermanentUrl(newUrl);
|
||||||
|
key.setCanonicalUrl(newUrl);
|
||||||
|
key.setShortUrl(newUrl);
|
||||||
|
loadClaimForCacheKey(key, newUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onNewClaim(String url) {
|
||||||
|
loadingNewClaim = true;
|
||||||
|
initialFileLoadDone = false;
|
||||||
|
currentUrl = url;
|
||||||
|
logUrlEvent(url);
|
||||||
|
resetViewCount();
|
||||||
|
|
||||||
|
if (MainActivity.appPlayer != null) {
|
||||||
|
MainActivity.appPlayer.setPlayWhenReady(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadClaimForCacheKey(ClaimCacheKey key, String url) {
|
||||||
if (Lbry.claimCache.containsKey(key)) {
|
if (Lbry.claimCache.containsKey(key)) {
|
||||||
claim = Lbry.claimCache.get(key);
|
claim = Lbry.claimCache.get(key);
|
||||||
checkAndResetNowPlayingClaim();
|
checkAndResetNowPlayingClaim();
|
||||||
|
@ -269,9 +301,7 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.file_view_claim_display_area).setVisibility(View.INVISIBLE);
|
findViewById(R.id.file_view_claim_display_area).setVisibility(View.INVISIBLE);
|
||||||
MainActivity.clearNowPlayingClaim(this);
|
MainActivity.clearNowPlayingClaim(this);
|
||||||
resolveUrl(newUrl);
|
resolveUrl(url);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -956,8 +986,11 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception error) {
|
public void onError(Exception error, boolean saveFile) {
|
||||||
showError(getString(R.string.unable_to_view_url, currentUrl));
|
showError(getString(R.string.unable_to_view_url, currentUrl));
|
||||||
|
if (saveFile) {
|
||||||
|
onDownloadAborted();
|
||||||
|
}
|
||||||
restoreMainActionButton();
|
restoreMainActionButton();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -1335,15 +1368,12 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
String uri = intent.getStringExtra("uri");
|
String uri = intent.getStringExtra("uri");
|
||||||
String outpoint = intent.getStringExtra("outpoint");
|
String outpoint = intent.getStringExtra("outpoint");
|
||||||
String fileInfoJson = intent.getStringExtra("file_info");
|
String fileInfoJson = intent.getStringExtra("file_info");
|
||||||
|
if (claim == null || uri == null || outpoint == null || (fileInfoJson == null && !"abort".equals(downloadAction))) {
|
||||||
if (uri == null || outpoint == null || (fileInfoJson == null && !"abort".equals(downloadAction))) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (claim != null && !claim.getPermanentUrl().equalsIgnoreCase(uri)) {
|
if (claim != null && !claim.getPermanentUrl().equalsIgnoreCase(uri)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ("abort".equals(downloadAction)) {
|
if ("abort".equals(downloadAction)) {
|
||||||
// handle download aborted
|
// handle download aborted
|
||||||
onDownloadAborted();
|
onDownloadAborted();
|
||||||
|
|
|
@ -59,7 +59,7 @@ public class GetFileTask extends AsyncTask<Void, Void, LbryFile> {
|
||||||
if (file != null) {
|
if (file != null) {
|
||||||
handler.onSuccess(file, saveFile);
|
handler.onSuccess(file, saveFile);
|
||||||
} else {
|
} else {
|
||||||
handler.onError(error);
|
handler.onError(error, saveFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,6 @@ public class GetFileTask extends AsyncTask<Void, Void, LbryFile> {
|
||||||
public interface GetFileHandler {
|
public interface GetFileHandler {
|
||||||
void beforeStart();
|
void beforeStart();
|
||||||
void onSuccess(LbryFile file, boolean saveFile);
|
void onSuccess(LbryFile file, boolean saveFile);
|
||||||
void onError(Exception error);
|
void onError(Exception error, boolean saveFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue