Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postprocessing for downloads and implement missing features #1759

Merged
merged 15 commits into from
Dec 11, 2018
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ dependencies {
exclude module: 'support-annotations'
})

implementation 'com.github.TeamNewPipe:NewPipeExtractor:32d316330c26'
implementation 'com.github.TeamNewPipe:NewPipeExtractor:91b1efc97e'

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.23.0'
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/org/schabi/newpipe/Downloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ public long getContentLength(String url) throws IOException {
.build();
response = client.newCall(request).execute();

return Long.parseLong(response.header("Content-Length"));
String contentLength = response.header("Content-Length");
return contentLength == null ? -1 : Long.parseLong(contentLength);
} catch (NumberFormatException e) {
throw new IOException("Invalid content length", e);
} finally {
Expand Down

This file was deleted.

47 changes: 10 additions & 37 deletions app/src/main/java/org/schabi/newpipe/download/DownloadActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,12 @@
import org.schabi.newpipe.settings.SettingsActivity;
import org.schabi.newpipe.util.ThemeHelper;

import io.reactivex.Completable;
import io.reactivex.schedulers.Schedulers;
import us.shandian.giga.service.DownloadManagerService;
import us.shandian.giga.ui.fragment.AllMissionsFragment;
import us.shandian.giga.ui.fragment.MissionsFragment;

public class DownloadActivity extends AppCompatActivity {

private static final String MISSIONS_FRAGMENT_TAG = "fragment_tag";
private DeleteDownloadManager mDeleteDownloadManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -47,32 +43,17 @@ protected void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayShowTitleEnabled(true);
}

mDeleteDownloadManager = new DeleteDownloadManager(this);
mDeleteDownloadManager.restoreState(savedInstanceState);

MissionsFragment fragment = (MissionsFragment) getFragmentManager().findFragmentByTag(MISSIONS_FRAGMENT_TAG);
if (fragment != null) {
fragment.setDeleteManager(mDeleteDownloadManager);
} else {
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
updateFragments();
getWindow().getDecorView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}
}

@Override
protected void onSaveInstanceState(Bundle outState) {
mDeleteDownloadManager.saveState(outState);
super.onSaveInstanceState(outState);
getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
updateFragments();
getWindow().getDecorView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
}
});
}

private void updateFragments() {
MissionsFragment fragment = new AllMissionsFragment();
fragment.setDeleteManager(mDeleteDownloadManager);
MissionsFragment fragment = new MissionsFragment();

getFragmentManager().beginTransaction()
.replace(R.id.frame, fragment, MISSIONS_FRAGMENT_TAG)
Expand All @@ -99,7 +80,6 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.action_settings: {
Intent intent = new Intent(this, SettingsActivity.class);
startActivity(intent);
deletePending();
return true;
}
default:
Expand All @@ -108,14 +88,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
}

@Override
public void onBackPressed() {
super.onBackPressed();
deletePending();
}

private void deletePending() {
Completable.fromAction(mDeleteDownloadManager::deletePending)
.subscribeOn(Schedulers.io())
.subscribe();
public void onRestoreInstanceState(Bundle inState){
super.onRestoreInstanceState(inState);
}
}
Loading