2017-09-03 06:04:18 +00:00
|
|
|
package org.schabi.newpipe.settings;
|
|
|
|
|
|
|
|
import android.app.Activity;
|
New MP4 muxer + Queue changes + Storage fixes
Main changes:
* correctly check the available space (CircularFile.java)
* misc cleanup (CircularFile.java)
* use the "Error Reporter" for non-http errors
* rewrite network state checking and add better support for API 21 (Lollipop) or higher
* implement "metered networks"
* add buttons in "Downloads" activity to start/pause all pending downloads, ignoring the queue flag or if the network is "metered"
* add workaround for VPN connections and/or network switching. Example: switching WiFi to 3G
* rewrite DataReader ¡Webm muxer is now 57% more faster!
* rewrite CircularFile, use file buffers instead of memory buffers. Less troubles in low-end devices
* fix missing offset for KaxCluster (WebMWriter.java), manifested as no thumbnails on file explorers
Download queue:
* remember queue status, unless the user pause the download (un-queue)
* semi-automatic downloads, between networks. Effective if the user create a new download or the downloads activity is starts
* allow enqueue failed downloads
* new option, queue limit, enabled by default. Used to allow one or multiple downloads at same time
Miscellaneous:
* fix crash while selecting details/error menu (mistake on MissionFragment.java)
* misc serialize changes (DownloadMission.java)
* minor UI tweaks
* allow overwrite paused downloads
* fix wrong icons for grid/list button in downloads
* add share option
* implement #2006
* correct misspelled word in strings.xml (es) (cmn)
* fix MissionAdapter crash during device shutdown
New Mp4Muxer + required changes:
* new mp4 muxer (from dash only) with this, muxing on Android 7 is possible now!!!
* re-work in SharpStream
* drop mp4 dash muxer
* misc changes: add warning in SecondaryStreamHelper.java,
* strip m4a DASH files to normal m4a format (youtube only)
Fix storage issues:
* warn to the user if is choosing a "read only" download directory (for external SD Cards), useless is rooted :)
* "write proof" allow post-processing resuming only if the device ran out of space
* implement "insufficient storage" error for downloads
2019-03-23 01:54:07 +00:00
|
|
|
import android.app.AlertDialog;
|
2019-04-16 00:31:33 +00:00
|
|
|
import android.content.ContentResolver;
|
2019-04-05 17:45:39 +00:00
|
|
|
import android.content.Context;
|
2017-09-03 06:04:18 +00:00
|
|
|
import android.content.Intent;
|
2019-04-05 17:45:39 +00:00
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Build;
|
2017-09-03 06:04:18 +00:00
|
|
|
import android.os.Bundle;
|
2020-01-31 21:49:43 +00:00
|
|
|
import android.util.Log;
|
|
|
|
import android.widget.Toast;
|
|
|
|
|
2019-10-04 12:59:08 +00:00
|
|
|
import androidx.annotation.StringRes;
|
|
|
|
import androidx.preference.Preference;
|
2018-03-08 13:39:24 +00:00
|
|
|
|
2019-04-09 21:38:34 +00:00
|
|
|
import com.nononsenseapps.filepicker.Utils;
|
|
|
|
|
2017-09-03 06:04:18 +00:00
|
|
|
import org.schabi.newpipe.R;
|
2017-09-18 12:29:43 +00:00
|
|
|
import org.schabi.newpipe.util.FilePickerActivityHelper;
|
2017-09-03 06:04:18 +00:00
|
|
|
|
New MP4 muxer + Queue changes + Storage fixes
Main changes:
* correctly check the available space (CircularFile.java)
* misc cleanup (CircularFile.java)
* use the "Error Reporter" for non-http errors
* rewrite network state checking and add better support for API 21 (Lollipop) or higher
* implement "metered networks"
* add buttons in "Downloads" activity to start/pause all pending downloads, ignoring the queue flag or if the network is "metered"
* add workaround for VPN connections and/or network switching. Example: switching WiFi to 3G
* rewrite DataReader ¡Webm muxer is now 57% more faster!
* rewrite CircularFile, use file buffers instead of memory buffers. Less troubles in low-end devices
* fix missing offset for KaxCluster (WebMWriter.java), manifested as no thumbnails on file explorers
Download queue:
* remember queue status, unless the user pause the download (un-queue)
* semi-automatic downloads, between networks. Effective if the user create a new download or the downloads activity is starts
* allow enqueue failed downloads
* new option, queue limit, enabled by default. Used to allow one or multiple downloads at same time
Miscellaneous:
* fix crash while selecting details/error menu (mistake on MissionFragment.java)
* misc serialize changes (DownloadMission.java)
* minor UI tweaks
* allow overwrite paused downloads
* fix wrong icons for grid/list button in downloads
* add share option
* implement #2006
* correct misspelled word in strings.xml (es) (cmn)
* fix MissionAdapter crash during device shutdown
New Mp4Muxer + required changes:
* new mp4 muxer (from dash only) with this, muxing on Android 7 is possible now!!!
* re-work in SharpStream
* drop mp4 dash muxer
* misc changes: add warning in SecondaryStreamHelper.java,
* strip m4a DASH files to normal m4a format (youtube only)
Fix storage issues:
* warn to the user if is choosing a "read only" download directory (for external SD Cards), useless is rooted :)
* "write proof" allow post-processing resuming only if the device ran out of space
* implement "insufficient storage" error for downloads
2019-03-23 01:54:07 +00:00
|
|
|
import java.io.File;
|
2019-04-05 17:45:39 +00:00
|
|
|
import java.io.IOException;
|
2019-04-09 21:38:34 +00:00
|
|
|
import java.io.UnsupportedEncodingException;
|
2019-04-16 00:31:33 +00:00
|
|
|
import java.net.URI;
|
2019-04-09 21:38:34 +00:00
|
|
|
import java.net.URLDecoder;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
2019-04-05 17:45:39 +00:00
|
|
|
|
|
|
|
import us.shandian.giga.io.StoredDirectoryHelper;
|
New MP4 muxer + Queue changes + Storage fixes
Main changes:
* correctly check the available space (CircularFile.java)
* misc cleanup (CircularFile.java)
* use the "Error Reporter" for non-http errors
* rewrite network state checking and add better support for API 21 (Lollipop) or higher
* implement "metered networks"
* add buttons in "Downloads" activity to start/pause all pending downloads, ignoring the queue flag or if the network is "metered"
* add workaround for VPN connections and/or network switching. Example: switching WiFi to 3G
* rewrite DataReader ¡Webm muxer is now 57% more faster!
* rewrite CircularFile, use file buffers instead of memory buffers. Less troubles in low-end devices
* fix missing offset for KaxCluster (WebMWriter.java), manifested as no thumbnails on file explorers
Download queue:
* remember queue status, unless the user pause the download (un-queue)
* semi-automatic downloads, between networks. Effective if the user create a new download or the downloads activity is starts
* allow enqueue failed downloads
* new option, queue limit, enabled by default. Used to allow one or multiple downloads at same time
Miscellaneous:
* fix crash while selecting details/error menu (mistake on MissionFragment.java)
* misc serialize changes (DownloadMission.java)
* minor UI tweaks
* allow overwrite paused downloads
* fix wrong icons for grid/list button in downloads
* add share option
* implement #2006
* correct misspelled word in strings.xml (es) (cmn)
* fix MissionAdapter crash during device shutdown
New Mp4Muxer + required changes:
* new mp4 muxer (from dash only) with this, muxing on Android 7 is possible now!!!
* re-work in SharpStream
* drop mp4 dash muxer
* misc changes: add warning in SecondaryStreamHelper.java,
* strip m4a DASH files to normal m4a format (youtube only)
Fix storage issues:
* warn to the user if is choosing a "read only" download directory (for external SD Cards), useless is rooted :)
* "write proof" allow post-processing resuming only if the device ran out of space
* implement "insufficient storage" error for downloads
2019-03-23 01:54:07 +00:00
|
|
|
|
2020-01-31 21:49:43 +00:00
|
|
|
import static org.schabi.newpipe.util.Localization.assureCorrectAppLanguage;
|
|
|
|
|
2017-09-03 06:04:18 +00:00
|
|
|
public class DownloadSettingsFragment extends BasePreferenceFragment {
|
2020-03-31 17:20:15 +00:00
|
|
|
public static final boolean IGNORE_RELEASE_ON_OLD_PATH = true;
|
2019-04-05 17:45:39 +00:00
|
|
|
private static final int REQUEST_DOWNLOAD_VIDEO_PATH = 0x1235;
|
2017-09-03 06:04:18 +00:00
|
|
|
private static final int REQUEST_DOWNLOAD_AUDIO_PATH = 0x1236;
|
2020-03-31 17:20:15 +00:00
|
|
|
private String downloadPathVideoPreference;
|
|
|
|
private String downloadPathAudioPreference;
|
|
|
|
private String storageUseSafPreference;
|
2017-09-03 06:04:18 +00:00
|
|
|
|
2019-04-05 17:45:39 +00:00
|
|
|
private Preference prefPathVideo;
|
|
|
|
private Preference prefPathAudio;
|
2019-04-19 19:18:19 +00:00
|
|
|
private Preference prefStorageAsk;
|
2019-04-09 21:38:34 +00:00
|
|
|
|
2019-04-05 17:45:39 +00:00
|
|
|
private Context ctx;
|
|
|
|
|
2017-09-03 06:04:18 +00:00
|
|
|
@Override
|
2021-03-22 20:38:36 +00:00
|
|
|
public void onCreatePreferences(final Bundle savedInstanceState, final String rootKey) {
|
|
|
|
addPreferencesFromResource(R.xml.download_settings);
|
2017-09-03 06:04:18 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
downloadPathVideoPreference = getString(R.string.download_path_video_key);
|
|
|
|
downloadPathAudioPreference = getString(R.string.download_path_audio_key);
|
|
|
|
storageUseSafPreference = getString(R.string.storage_use_saf);
|
2019-08-14 18:30:34 +00:00
|
|
|
final String downloadStorageAsk = getString(R.string.downloads_storage_ask);
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
prefPathVideo = findPreference(downloadPathVideoPreference);
|
|
|
|
prefPathAudio = findPreference(downloadPathAudioPreference);
|
2019-08-14 18:30:34 +00:00
|
|
|
prefStorageAsk = findPreference(downloadStorageAsk);
|
2019-04-09 21:38:34 +00:00
|
|
|
|
|
|
|
updatePreferencesSummary();
|
2019-08-14 18:30:34 +00:00
|
|
|
updatePathPickers(!defaultPreferences.getBoolean(downloadStorageAsk, false));
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2019-04-19 19:18:19 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
|
|
prefStorageAsk.setSummary(R.string.downloads_storage_ask_summary);
|
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (hasInvalidPath(downloadPathVideoPreference)
|
|
|
|
|| hasInvalidPath(downloadPathAudioPreference)) {
|
2019-04-19 19:18:19 +00:00
|
|
|
updatePreferencesSummary();
|
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2019-04-19 19:18:19 +00:00
|
|
|
prefStorageAsk.setOnPreferenceChangeListener((preference, value) -> {
|
|
|
|
updatePathPickers(!(boolean) value);
|
2019-04-05 17:45:39 +00:00
|
|
|
return true;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public void onAttach(final Context context) {
|
2019-04-05 17:45:39 +00:00
|
|
|
super.onAttach(context);
|
|
|
|
ctx = context;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onDetach() {
|
|
|
|
super.onDetach();
|
|
|
|
ctx = null;
|
2019-04-19 19:18:19 +00:00
|
|
|
prefStorageAsk.setOnPreferenceChangeListener(null);
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 21:38:34 +00:00
|
|
|
private void updatePreferencesSummary() {
|
2020-03-31 17:20:15 +00:00
|
|
|
showPathInSummary(downloadPathVideoPreference, R.string.download_path_summary,
|
|
|
|
prefPathVideo);
|
|
|
|
showPathInSummary(downloadPathAudioPreference, R.string.download_path_audio_summary,
|
|
|
|
prefPathAudio);
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
private void showPathInSummary(final String prefKey, @StringRes final int defaultString,
|
|
|
|
final Preference target) {
|
2019-04-09 21:38:34 +00:00
|
|
|
String rawUri = defaultPreferences.getString(prefKey, null);
|
|
|
|
if (rawUri == null || rawUri.isEmpty()) {
|
|
|
|
target.setSummary(getString(defaultString));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-16 00:31:33 +00:00
|
|
|
if (rawUri.charAt(0) == File.separatorChar) {
|
|
|
|
target.setSummary(rawUri);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (rawUri.startsWith(ContentResolver.SCHEME_FILE)) {
|
|
|
|
target.setSummary(new File(URI.create(rawUri)).getPath());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 21:38:34 +00:00
|
|
|
try {
|
|
|
|
rawUri = URLDecoder.decode(rawUri, StandardCharsets.UTF_8.name());
|
2020-08-16 08:24:58 +00:00
|
|
|
} catch (final UnsupportedEncodingException e) {
|
2019-04-09 21:38:34 +00:00
|
|
|
// nothing to do
|
|
|
|
}
|
|
|
|
|
|
|
|
target.setSummary(rawUri);
|
2019-04-05 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
private boolean isFileUri(final String path) {
|
2019-04-16 00:31:33 +00:00
|
|
|
return path.charAt(0) == File.separatorChar || path.startsWith(ContentResolver.SCHEME_FILE);
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
private boolean hasInvalidPath(final String prefKey) {
|
2020-08-16 08:24:58 +00:00
|
|
|
final String value = defaultPreferences.getString(prefKey, null);
|
2019-04-19 19:18:19 +00:00
|
|
|
return value == null || value.isEmpty();
|
2019-04-05 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
private void updatePathPickers(final boolean enabled) {
|
2019-04-19 19:18:19 +00:00
|
|
|
prefPathVideo.setEnabled(enabled);
|
|
|
|
prefPathAudio.setEnabled(enabled);
|
2019-04-05 17:45:39 +00:00
|
|
|
}
|
|
|
|
|
2019-04-09 21:38:34 +00:00
|
|
|
// FIXME: after releasing the old path, all downloads created on the folder becomes inaccessible
|
2020-03-31 17:20:15 +00:00
|
|
|
private void forgetSAFTree(final Context context, final String oldPath) {
|
2019-04-16 00:31:33 +00:00
|
|
|
if (IGNORE_RELEASE_ON_OLD_PATH) {
|
2019-04-09 21:38:34 +00:00
|
|
|
return;
|
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (oldPath == null || oldPath.isEmpty() || isFileUri(oldPath)) {
|
|
|
|
return;
|
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2019-04-16 00:31:33 +00:00
|
|
|
try {
|
2020-08-16 08:24:58 +00:00
|
|
|
final Uri uri = Uri.parse(oldPath);
|
2019-04-09 21:38:34 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
context.getContentResolver()
|
|
|
|
.releasePersistableUriPermission(uri, StoredDirectoryHelper.PERMISSION_FLAGS);
|
|
|
|
context.revokeUriPermission(uri, StoredDirectoryHelper.PERMISSION_FLAGS);
|
2019-04-09 21:38:34 +00:00
|
|
|
|
2019-04-16 00:31:33 +00:00
|
|
|
Log.i(TAG, "Revoke old path permissions success on " + oldPath);
|
2020-08-16 08:24:58 +00:00
|
|
|
} catch (final Exception err) {
|
2019-04-16 00:31:33 +00:00
|
|
|
Log.e(TAG, "Error revoking old path permissions on " + oldPath, err);
|
2019-04-05 17:45:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
private void showMessageDialog(@StringRes final int title, @StringRes final int message) {
|
2020-08-16 08:24:58 +00:00
|
|
|
final AlertDialog.Builder msg = new AlertDialog.Builder(ctx);
|
2019-04-05 17:45:39 +00:00
|
|
|
msg.setTitle(title);
|
|
|
|
msg.setMessage(message);
|
2020-01-31 21:49:43 +00:00
|
|
|
msg.setPositiveButton(getString(R.string.finish), null);
|
2019-04-05 17:45:39 +00:00
|
|
|
msg.show();
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public boolean onPreferenceTreeClick(final Preference preference) {
|
2017-09-03 06:04:18 +00:00
|
|
|
if (DEBUG) {
|
2020-03-31 17:20:15 +00:00
|
|
|
Log.d(TAG, "onPreferenceTreeClick() called with: "
|
|
|
|
+ "preference = [" + preference + "]");
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
final String key = preference.getKey();
|
|
|
|
final int request;
|
2019-04-19 19:18:19 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (key.equals(storageUseSafPreference)) {
|
|
|
|
Toast.makeText(getContext(), R.string.download_choose_new_path,
|
|
|
|
Toast.LENGTH_LONG).show();
|
2019-09-01 21:49:45 +00:00
|
|
|
return true;
|
2020-03-31 17:20:15 +00:00
|
|
|
} else if (key.equals(downloadPathVideoPreference)) {
|
2019-04-19 19:18:19 +00:00
|
|
|
request = REQUEST_DOWNLOAD_VIDEO_PATH;
|
2020-03-31 17:20:15 +00:00
|
|
|
} else if (key.equals(downloadPathAudioPreference)) {
|
2019-04-19 19:18:19 +00:00
|
|
|
request = REQUEST_DOWNLOAD_AUDIO_PATH;
|
|
|
|
} else {
|
|
|
|
return super.onPreferenceTreeClick(preference);
|
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
final Intent i;
|
2020-03-31 17:20:15 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
|
|
|
&& NewPipeSettings.useStorageAccessFramework(ctx)) {
|
2019-04-19 19:18:19 +00:00
|
|
|
i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE)
|
|
|
|
.putExtra("android.content.extra.SHOW_ADVANCED", true)
|
2020-03-31 17:20:15 +00:00
|
|
|
.addFlags(Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
|
|
|
| StoredDirectoryHelper.PERMISSION_FLAGS);
|
2019-04-19 19:18:19 +00:00
|
|
|
} else {
|
|
|
|
i = new Intent(getActivity(), FilePickerActivityHelper.class)
|
|
|
|
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_MULTIPLE, false)
|
|
|
|
.putExtra(FilePickerActivityHelper.EXTRA_ALLOW_CREATE_DIR, true)
|
2020-03-31 17:20:15 +00:00
|
|
|
.putExtra(FilePickerActivityHelper.EXTRA_MODE,
|
|
|
|
FilePickerActivityHelper.MODE_DIR);
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-19 19:18:19 +00:00
|
|
|
startActivityForResult(i, request);
|
|
|
|
|
|
|
|
return true;
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-03-31 17:20:15 +00:00
|
|
|
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
|
2020-01-31 21:49:43 +00:00
|
|
|
assureCorrectAppLanguage(getContext());
|
2017-09-03 06:04:18 +00:00
|
|
|
super.onActivityResult(requestCode, resultCode, data);
|
|
|
|
if (DEBUG) {
|
2020-03-31 17:20:15 +00:00
|
|
|
Log.d(TAG, "onActivityResult() called with: "
|
|
|
|
+ "requestCode = [" + requestCode + "], "
|
|
|
|
+ "resultCode = [" + resultCode + "], data = [" + data + "]"
|
2019-04-05 17:45:39 +00:00
|
|
|
);
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (resultCode != Activity.RESULT_OK) {
|
|
|
|
return;
|
|
|
|
}
|
2018-03-08 13:39:24 +00:00
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
final String key;
|
2020-03-31 17:20:15 +00:00
|
|
|
if (requestCode == REQUEST_DOWNLOAD_VIDEO_PATH) {
|
|
|
|
key = downloadPathVideoPreference;
|
|
|
|
} else if (requestCode == REQUEST_DOWNLOAD_AUDIO_PATH) {
|
|
|
|
key = downloadPathAudioPreference;
|
|
|
|
} else {
|
2019-04-05 17:45:39 +00:00
|
|
|
return;
|
2020-03-31 17:20:15 +00:00
|
|
|
}
|
New MP4 muxer + Queue changes + Storage fixes
Main changes:
* correctly check the available space (CircularFile.java)
* misc cleanup (CircularFile.java)
* use the "Error Reporter" for non-http errors
* rewrite network state checking and add better support for API 21 (Lollipop) or higher
* implement "metered networks"
* add buttons in "Downloads" activity to start/pause all pending downloads, ignoring the queue flag or if the network is "metered"
* add workaround for VPN connections and/or network switching. Example: switching WiFi to 3G
* rewrite DataReader ¡Webm muxer is now 57% more faster!
* rewrite CircularFile, use file buffers instead of memory buffers. Less troubles in low-end devices
* fix missing offset for KaxCluster (WebMWriter.java), manifested as no thumbnails on file explorers
Download queue:
* remember queue status, unless the user pause the download (un-queue)
* semi-automatic downloads, between networks. Effective if the user create a new download or the downloads activity is starts
* allow enqueue failed downloads
* new option, queue limit, enabled by default. Used to allow one or multiple downloads at same time
Miscellaneous:
* fix crash while selecting details/error menu (mistake on MissionFragment.java)
* misc serialize changes (DownloadMission.java)
* minor UI tweaks
* allow overwrite paused downloads
* fix wrong icons for grid/list button in downloads
* add share option
* implement #2006
* correct misspelled word in strings.xml (es) (cmn)
* fix MissionAdapter crash during device shutdown
New Mp4Muxer + required changes:
* new mp4 muxer (from dash only) with this, muxing on Android 7 is possible now!!!
* re-work in SharpStream
* drop mp4 dash muxer
* misc changes: add warning in SecondaryStreamHelper.java,
* strip m4a DASH files to normal m4a format (youtube only)
Fix storage issues:
* warn to the user if is choosing a "read only" download directory (for external SD Cards), useless is rooted :)
* "write proof" allow post-processing resuming only if the device ran out of space
* implement "insufficient storage" error for downloads
2019-03-23 01:54:07 +00:00
|
|
|
|
2019-04-05 17:45:39 +00:00
|
|
|
Uri uri = data.getData();
|
|
|
|
if (uri == null) {
|
|
|
|
showMessageDialog(R.string.general_error, R.string.invalid_directory);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-09 21:38:34 +00:00
|
|
|
|
2019-08-14 18:30:34 +00:00
|
|
|
// revoke permissions on the old save path (required for SAF only)
|
2020-12-23 02:20:43 +00:00
|
|
|
final Context context = requireContext();
|
2019-08-14 18:30:34 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
forgetSAFTree(context, defaultPreferences.getString(key, ""));
|
2019-04-05 17:45:39 +00:00
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
|
|
|
|
&& !FilePickerActivityHelper.isOwnFileUri(context, uri)) {
|
2019-08-14 18:30:34 +00:00
|
|
|
// steps to acquire the selected path:
|
|
|
|
// 1. acquire permissions on the new save path
|
|
|
|
// 2. save the new path, if step(2) was successful
|
2019-04-05 17:45:39 +00:00
|
|
|
try {
|
2020-03-31 17:20:15 +00:00
|
|
|
context.grantUriPermission(context.getPackageName(), uri,
|
|
|
|
StoredDirectoryHelper.PERMISSION_FLAGS);
|
2019-04-09 21:38:34 +00:00
|
|
|
|
2020-08-16 08:24:58 +00:00
|
|
|
final StoredDirectoryHelper mainStorage
|
|
|
|
= new StoredDirectoryHelper(context, uri, null);
|
2019-04-09 21:38:34 +00:00
|
|
|
Log.i(TAG, "Acquiring tree success from " + uri.toString());
|
|
|
|
|
2020-03-31 17:20:15 +00:00
|
|
|
if (!mainStorage.canWrite()) {
|
2019-04-09 21:38:34 +00:00
|
|
|
throw new IOException("No write permissions on " + uri.toString());
|
2020-03-31 17:20:15 +00:00
|
|
|
}
|
2020-08-16 08:24:58 +00:00
|
|
|
} catch (final IOException err) {
|
2019-04-09 21:38:34 +00:00
|
|
|
Log.e(TAG, "Error acquiring tree from " + uri.toString(), err);
|
2019-04-05 17:45:39 +00:00
|
|
|
showMessageDialog(R.string.general_error, R.string.no_available_dir);
|
|
|
|
return;
|
New MP4 muxer + Queue changes + Storage fixes
Main changes:
* correctly check the available space (CircularFile.java)
* misc cleanup (CircularFile.java)
* use the "Error Reporter" for non-http errors
* rewrite network state checking and add better support for API 21 (Lollipop) or higher
* implement "metered networks"
* add buttons in "Downloads" activity to start/pause all pending downloads, ignoring the queue flag or if the network is "metered"
* add workaround for VPN connections and/or network switching. Example: switching WiFi to 3G
* rewrite DataReader ¡Webm muxer is now 57% more faster!
* rewrite CircularFile, use file buffers instead of memory buffers. Less troubles in low-end devices
* fix missing offset for KaxCluster (WebMWriter.java), manifested as no thumbnails on file explorers
Download queue:
* remember queue status, unless the user pause the download (un-queue)
* semi-automatic downloads, between networks. Effective if the user create a new download or the downloads activity is starts
* allow enqueue failed downloads
* new option, queue limit, enabled by default. Used to allow one or multiple downloads at same time
Miscellaneous:
* fix crash while selecting details/error menu (mistake on MissionFragment.java)
* misc serialize changes (DownloadMission.java)
* minor UI tweaks
* allow overwrite paused downloads
* fix wrong icons for grid/list button in downloads
* add share option
* implement #2006
* correct misspelled word in strings.xml (es) (cmn)
* fix MissionAdapter crash during device shutdown
New Mp4Muxer + required changes:
* new mp4 muxer (from dash only) with this, muxing on Android 7 is possible now!!!
* re-work in SharpStream
* drop mp4 dash muxer
* misc changes: add warning in SecondaryStreamHelper.java,
* strip m4a DASH files to normal m4a format (youtube only)
Fix storage issues:
* warn to the user if is choosing a "read only" download directory (for external SD Cards), useless is rooted :)
* "write proof" allow post-processing resuming only if the device ran out of space
* implement "insufficient storage" error for downloads
2019-03-23 01:54:07 +00:00
|
|
|
}
|
2019-04-05 17:45:39 +00:00
|
|
|
} else {
|
2020-08-16 08:24:58 +00:00
|
|
|
final File target = Utils.getFileForUri(uri);
|
2019-04-09 21:38:34 +00:00
|
|
|
if (!target.canWrite()) {
|
2020-03-31 17:20:15 +00:00
|
|
|
showMessageDialog(R.string.download_to_sdcard_error_title,
|
|
|
|
R.string.download_to_sdcard_error_message);
|
2019-04-09 21:38:34 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
uri = Uri.fromFile(target);
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
2019-04-09 21:38:34 +00:00
|
|
|
|
|
|
|
defaultPreferences.edit().putString(key, uri.toString()).apply();
|
|
|
|
updatePreferencesSummary();
|
2017-09-03 06:04:18 +00:00
|
|
|
}
|
|
|
|
}
|