Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions app/src/main/java/org/schabi/newpipe/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import org.schabi.newpipe.util.Constants;
import org.schabi.newpipe.util.KioskTranslator;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.ServiceHelper;
import org.schabi.newpipe.util.StateSaver;
import org.schabi.newpipe.util.ThemeHelper;
Expand Down Expand Up @@ -422,17 +421,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
return;
}
}
switch (requestCode) {
case PermissionHelper.DOWNLOADS_REQUEST_CODE:
NavigationHelper.openDownloads(this);
break;
case PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE:
Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.fragment_holder);
if (fragment instanceof VideoDetailFragment) {
((VideoDetailFragment) fragment).openDownloadDialog();
}
break;
}
}

/**
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/java/org/schabi/newpipe/RouterActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,8 @@ private void handleChoice(final String selectedChoiceKey) {
}

if (selectedChoiceKey.equals(getString(R.string.download_key))) {
if (PermissionHelper.checkStoragePermissions(this, PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
selectionIsDownload = true;
openDownloadDialog();
}
selectionIsDownload = true;
openDownloadDialog();
return;
}

Expand Down Expand Up @@ -453,9 +451,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
return;
}
}
if (requestCode == PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE) {
openDownloadDialog();
}
}

private static class AdapterChoiceItem {
Expand Down
36 changes: 4 additions & 32 deletions app/src/main/java/org/schabi/newpipe/download/DownloadDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
import org.schabi.newpipe.report.UserAction;
import org.schabi.newpipe.util.FilenameUtils;
import org.schabi.newpipe.util.ListHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.SecondaryStreamHelper;
import org.schabi.newpipe.util.StreamItemAdapter;
import org.schabi.newpipe.util.StreamItemAdapter.StreamSizeWrapper;
Expand Down Expand Up @@ -173,10 +172,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (DEBUG)
Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]");
if (!PermissionHelper.checkStoragePermissions(getActivity(), PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
getDialog().dismiss();
return;
}

context = getContext();

Expand Down Expand Up @@ -217,32 +212,6 @@ public void onServiceConnected(ComponentName cname, IBinder service) {
okButton.setEnabled(true);

context.unbindService(this);

// check of download paths are defined
if (!askForSavePath) {
String msg = "";
if (mainStorageVideo == null) msg += getString(R.string.download_path_title);
if (mainStorageAudio == null)
msg += getString(R.string.download_path_audio_title);

if (!msg.isEmpty()) {
String title;
if (mainStorageVideo == null && mainStorageAudio == null) {
title = getString(R.string.general_error);
msg = getString(R.string.no_available_dir) + ":\n" + msg;
} else {
title = msg;
msg = getString(R.string.no_available_dir);
}

new AlertDialog.Builder(context)
.setPositiveButton(android.R.string.ok, null)
.setTitle(title)
.setMessage(msg)
.create()
.show();
}
}
}

@Override
Expand Down Expand Up @@ -602,6 +571,9 @@ private void prepareSelectedDownload() {
// * save path not defined (via download settings)
// * the user as checked the "ask where to download" option

if (!askForSavePath)
Toast.makeText(context, getString(R.string.no_available_dir), Toast.LENGTH_LONG).show();

StoredFileHelper.requestSafWithFileCreation(this, REQUEST_DOWNLOAD_PATH_SAF, filename, mime);
return;
}
Expand Down Expand Up @@ -773,7 +745,6 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {
// more download logic: select muxer, subtitle converter, etc.
switch (radioStreamsGroup.getCheckedRadioButtonId()) {
case R.id.audio_button:
threads = 1;// use unique thread for subtitles due small file size
kind = 'a';
selectedStream = audioStreamsAdapter.getItem(selectedAudioIndex);

Expand Down Expand Up @@ -808,6 +779,7 @@ private void continueSelectedDownload(@NonNull StoredFileHelper storage) {
}
break;
case R.id.subtitle_button:
threads = 1;// use unique thread for subtitles due small file size
kind = 's';
selectedStream = subtitleStreamsAdapter.getItem(selectedSubtitleIndex);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -385,10 +385,7 @@ public void onClick(View v) {
}
break;
case R.id.detail_controls_download:
if (PermissionHelper.checkStoragePermissions(activity,
PermissionHelper.DOWNLOAD_DIALOG_REQUEST_CODE)) {
this.openDownloadDialog();
}
this.openDownloadDialog();
break;
case R.id.detail_uploader_root_layout:
if (TextUtils.isEmpty(currentInfo.getUploaderUrl())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.support.annotation.StringRes;
import android.support.v7.preference.Preference;
import android.util.Log;
import android.widget.Toast;

import com.nononsenseapps.filepicker.Utils;

Expand Down Expand Up @@ -64,7 +63,6 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}

if (hasInvalidPath(DOWNLOAD_PATH_VIDEO_PREFERENCE) || hasInvalidPath(DOWNLOAD_PATH_AUDIO_PREFERENCE)) {
Toast.makeText(ctx, R.string.download_pick_path, Toast.LENGTH_SHORT).show();
updatePreferencesSummary();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Environment;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -66,8 +67,10 @@ public static void initSettings(Context context) {
PreferenceManager.setDefaultValues(context, R.xml.video_audio_settings, true);
PreferenceManager.setDefaultValues(context, R.xml.debug_settings, true);

getVideoDownloadFolder(context);
getAudioDownloadFolder(context);
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
getVideoDownloadFolder(context);
getAudioDownloadFolder(context);
}
}

private static void getVideoDownloadFolder(Context context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,9 +446,6 @@ public static void openSettings(Context context) {
}

public static boolean openDownloads(Activity activity) {
if (!PermissionHelper.checkStoragePermissions(activity, PermissionHelper.DOWNLOADS_REQUEST_CODE)) {
return false;
}
Intent intent = new Intent(activity, DownloadActivity.class);
activity.startActivity(intent);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
import org.schabi.newpipe.R;

public class PermissionHelper {
public static final int DOWNLOAD_DIALOG_REQUEST_CODE = 778;
public static final int DOWNLOADS_REQUEST_CODE = 777;


public static boolean checkStoragePermissions(Activity activity, int requestCode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
Expand Down
22 changes: 20 additions & 2 deletions app/src/main/java/us/shandian/giga/get/DownloadInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ public class DownloadInitializer extends Thread {
mConn = null;
}

private static void safeClose(HttpURLConnection con) {
try {
con.getInputStream().close();
} catch (Exception e) {
// nothing to do
}
}

@Override
public void run() {
if (mMission.current > 0) mMission.resetState(false, true, DownloadMission.ERROR_NOTHING);

int retryCount = 0;
int httpCode = 204;

while (true) {
try {
if (mMission.blocks == null && mMission.current == 0) {
Expand All @@ -43,11 +53,16 @@ public void run() {
for (int i = 0; i < mMission.urls.length && mMission.running; i++) {
mConn = mMission.openConnection(mMission.urls[i], mId, -1, -1);
mMission.establishConnection(mId, mConn);
safeClose(mConn);

if (Thread.interrupted()) return;
long length = Utility.getContentLength(mConn);

if (i == 0) mMission.length = length;
if (i == 0) {
httpCode = mConn.getResponseCode();
mMission.length = length;
}

if (length > 0) finalLength += length;
if (length < lowestSize) lowestSize = length;
}
Expand All @@ -68,13 +83,15 @@ public void run() {
// ask for the current resource length
mConn = mMission.openConnection(mId, -1, -1);
mMission.establishConnection(mId, mConn);
safeClose(mConn);

if (!mMission.running || Thread.interrupted()) return;

httpCode = mConn.getResponseCode();
mMission.length = Utility.getContentLength(mConn);
}

if (mMission.length == 0 || mConn.getResponseCode() == 204) {
if (mMission.length == 0 || httpCode == 204) {
mMission.notifyError(DownloadMission.ERROR_HTTP_NO_CONTENT, null);
return;
}
Expand All @@ -92,6 +109,7 @@ public void run() {
// Open again
mConn = mMission.openConnection(mId, mMission.length - 10, mMission.length);
mMission.establishConnection(mId, mConn);
safeClose(mConn);

if (!mMission.running || Thread.interrupted()) return;

Expand Down
25 changes: 9 additions & 16 deletions app/src/main/java/us/shandian/giga/get/DownloadRunnable.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public void run() {
}

SharpStream f;
InputStream is = null;

try {
f = mMission.storage.getStream();
Expand Down Expand Up @@ -114,16 +113,16 @@ public void run() {

f.seek(mMission.offsets[mMission.current] + start);

is = mConn.getInputStream();
try (InputStream is = mConn.getInputStream()) {
byte[] buf = new byte[DownloadMission.BUFFER_SIZE];
int len;

byte[] buf = new byte[DownloadMission.BUFFER_SIZE];
int len;

while (start < end && mMission.running && (len = is.read(buf, 0, buf.length)) != -1) {
f.write(buf, 0, len);
start += len;
block.done += len;
mMission.notifyProgress(len);
while (start < end && mMission.running && (len = is.read(buf, 0, buf.length)) != -1) {
f.write(buf, 0, len);
start += len;
block.done += len;
mMission.notifyProgress(len);
}
}

if (DEBUG && mMission.running) {
Expand All @@ -143,12 +142,6 @@ public void run() {
}
}

try {
if (is != null) is.close();
} catch (Exception err) {
// nothing to do
}

try {
f.close();
} catch (Exception err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void run() {
mMission.notifyProgress(len);
}

// if thread goes interrupted check if the last part mIs written. This avoid re-download the whole file
// if thread goes interrupted check if the last part is written. This avoid re-download the whole file
done = len == -1;
} catch (Exception e) {
dispose();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package us.shandian.giga.service;

import android.Manifest;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
Expand Down Expand Up @@ -30,7 +28,6 @@
import android.support.annotation.StringRes;
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.content.PermissionChecker;
import android.util.Log;
import android.util.SparseArray;
import android.widget.Toast;
Expand Down Expand Up @@ -257,18 +254,20 @@ public void onDestroy() {

@Override
public IBinder onBind(Intent intent) {
/*
int permissionCheck;
// if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
// permissionCheck = PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
// if (permissionCheck == PermissionChecker.PERMISSION_DENIED) {
// Toast.makeText(this, "Permission denied (read)", Toast.LENGTH_SHORT).show();
// }
// }
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN) {
permissionCheck = PermissionChecker.checkSelfPermission(this, Manifest.permission.READ_EXTERNAL_STORAGE);
if (permissionCheck == PermissionChecker.PERMISSION_DENIED) {
Toast.makeText(this, "Permission denied (read)", Toast.LENGTH_SHORT).show();
}
}

permissionCheck = PermissionChecker.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE);
if (permissionCheck == PermissionChecker.PERMISSION_DENIED) {
Toast.makeText(this, "Permission denied (write)", Toast.LENGTH_SHORT).show();
}
*/

return mBinder;
}
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<string name="msg_running_detail">Toque para ver detalles</string>
<string name="msg_wait">Por favor espere…</string>
<string name="msg_copied">Copiado al portapapeles</string>
<string name="no_available_dir">Por favor, seleccione un directorio de descarga disponible</string>
<string name="no_available_dir">Por favor, defina un directorio de descarga mas tarde en ajustes</string>
<string name="could_not_load_image">No se pudo cargar la imagen</string>
<string name="app_ui_crash">La interfaz de la app dejó de funcionar</string>
<string name="info_labels">Lo sucedido:\\nPetición:\\nIdioma del contenido:\\nServicio:\\nHora GMT:\\nPaquete:\\nVersión:\\nVersión del SO:</string>
Expand Down Expand Up @@ -458,7 +458,6 @@ abrir en modo popup</string>
<string name="error_progress_lost">Se perdió el progreso porque el archivo fue eliminado</string>
<string name="error_timeout">Tiempo de espera excedido</string>

<string name="download_pick_path">Seleccione los directorios de descarga</string>
<string name="downloads_storage_ask_title">Preguntar dónde descargar</string>
<string name="downloads_storage_ask_summary">Se preguntará dónde guardar cada descarga</string>
<string name="downloads_storage_ask_summary_kitkat">Se preguntará dónde guardar cada descarga.\nHabilita esta opción si quieres descargar en la tarjeta SD externa</string>
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@
<string name="msg_running_detail">Tap for details</string>
<string name="msg_wait">Please wait…</string>
<string name="msg_copied">Copied to clipboard</string>
<string name="no_available_dir">Please select an available download folder</string>
<string name="no_available_dir">Please define an download folder later in settings</string>
<string name="msg_popup_permission">This permission is needed to\nopen in popup mode</string>
<string name="one_item_deleted">1 item deleted.</string>
<!-- Checksum types -->
Expand Down Expand Up @@ -553,8 +553,6 @@
<string name="start_downloads">Start downloads</string>
<string name="pause_downloads">Pause downloads</string>

<string name="download_pick_path">Select the downloads save path</string>

<string name="downloads_storage_ask_title">Ask where to download</string>
<string name="downloads_storage_ask_summary">You will be asked where to save each download</string>
<string name="downloads_storage_ask_summary_kitkat">You will be asked where to save each download.\nEnable this option if you want download to the external SD Card</string>
Expand Down