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,25 +259,52 @@ public class FileViewActivity extends AppCompatActivity {
|
||||||
key.setCanonicalUrl(newUrl);
|
key.setCanonicalUrl(newUrl);
|
||||||
key.setShortUrl(newUrl);
|
key.setShortUrl(newUrl);
|
||||||
}
|
}
|
||||||
if (Lbry.claimCache.containsKey(key)) {
|
loadClaimForCacheKey(key, newUrl);
|
||||||
claim = Lbry.claimCache.get(key);
|
} else if (!Helper.isNullOrEmpty(newUrl)) {
|
||||||
checkAndResetNowPlayingClaim();
|
if (currentUrl != null && currentUrl.equalsIgnoreCase(newUrl)) {
|
||||||
if (claim.getFile() == null) {
|
return;
|
||||||
loadFile();
|
|
||||||
} else {
|
|
||||||
initialFileLoadDone = true;
|
|
||||||
checkInitialFileLoadDone();
|
|
||||||
}
|
|
||||||
renderClaim();
|
|
||||||
} else {
|
|
||||||
findViewById(R.id.file_view_claim_display_area).setVisibility(View.INVISIBLE);
|
|
||||||
MainActivity.clearNowPlayingClaim(this);
|
|
||||||
resolveUrl(newUrl);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)) {
|
||||||
|
claim = Lbry.claimCache.get(key);
|
||||||
|
checkAndResetNowPlayingClaim();
|
||||||
|
if (claim.getFile() == null) {
|
||||||
|
loadFile();
|
||||||
|
} else {
|
||||||
|
initialFileLoadDone = true;
|
||||||
|
checkInitialFileLoadDone();
|
||||||
|
}
|
||||||
|
renderClaim();
|
||||||
|
} else {
|
||||||
|
findViewById(R.id.file_view_claim_display_area).setVisibility(View.INVISIBLE);
|
||||||
|
MainActivity.clearNowPlayingClaim(this);
|
||||||
|
resolveUrl(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void registerSdkReceiver() {
|
private void registerSdkReceiver() {
|
||||||
IntentFilter filter = new IntentFilter();
|
IntentFilter filter = new IntentFilter();
|
||||||
filter.addAction(LbrynetService.ACTION_STOP_SERVICE);
|
filter.addAction(LbrynetService.ACTION_STOP_SERVICE);
|
||||||
|
@ -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