mirror of
https://github.com/TeamNewPipe/NewPipe.git
synced 2024-11-22 19:12:45 +01:00
Done with the file picker for the download settings
This commit is contained in:
parent
bd43efd2c2
commit
b3fdd2b0cb
@ -4,11 +4,13 @@ import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
@ -63,13 +65,16 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
getFragmentManager().beginTransaction()
|
||||
.replace(android.R.id.content, new SettingsFragment())
|
||||
.commit();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
|
||||
if (requestCode == 233 && resultCode == Activity.RESULT_OK) {
|
||||
if ((requestCode == R.string.download_path_audio_key
|
||||
|| requestCode == R.string.download_path_key)
|
||||
&& resultCode == Activity.RESULT_OK) {
|
||||
|
||||
Uri uri = null;
|
||||
if (data.getBooleanExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false)) {
|
||||
// For JellyBean and above
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
@ -77,7 +82,7 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
if (clip != null) {
|
||||
for (int i = 0; i < clip.getItemCount(); i++) {
|
||||
Uri uri = clip.getItemAt(i).getUri();
|
||||
uri = clip.getItemAt(i).getUri();
|
||||
}
|
||||
}
|
||||
// For Ice Cream Sandwich
|
||||
@ -87,14 +92,22 @@ public class SettingsActivity extends PreferenceActivity {
|
||||
|
||||
if (paths != null) {
|
||||
for (String path: paths) {
|
||||
Uri uri = Uri.parse(path);
|
||||
uri = Uri.parse(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
Uri uri = data.getData();
|
||||
uri = data.getData();
|
||||
}
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
|
||||
|
||||
//requestCode is equal to R.string.download_path_key or
|
||||
//R.string.download_path_audio_key
|
||||
String key = getString(requestCode);
|
||||
String path = data.getData().toString().substring(7);
|
||||
prefs.edit()
|
||||
.putString(key, path)
|
||||
.commit();
|
||||
}
|
||||
else if(requestCode == REQUEST_INSTALL_ORBOT)
|
||||
{
|
||||
|
@ -36,7 +36,7 @@ public class SettingsFragment extends PreferenceFragment
|
||||
private ListPreference defaultAudioFormatPreference;
|
||||
private ListPreference searchLanguagePreference;
|
||||
private Preference downloadPathPreference;
|
||||
private EditTextPreference downloadPathAudioPreference;
|
||||
private Preference downloadPathAudioPreference;
|
||||
private CheckBoxPreference useTorCheckBox;
|
||||
private SharedPreferences defaultPreferences;
|
||||
|
||||
@ -66,8 +66,7 @@ public class SettingsFragment extends PreferenceFragment
|
||||
searchLanguagePreference =
|
||||
(ListPreference) findPreference(SEARCH_LANGUAGE_PREFERENCE);
|
||||
downloadPathPreference = findPreference(DOWNLOAD_PATH_PREFERENCE);
|
||||
downloadPathAudioPreference =
|
||||
(EditTextPreference) findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE);
|
||||
downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE);
|
||||
useTorCheckBox = (CheckBoxPreference) findPreference(USE_TOR_KEY);
|
||||
|
||||
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
|
||||
@ -75,8 +74,12 @@ public class SettingsFragment extends PreferenceFragment
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences,
|
||||
String key) {
|
||||
Activity a = getActivity();
|
||||
|
||||
if(a != null) {
|
||||
if(a == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (key == USE_TOR_KEY)
|
||||
{
|
||||
updateSummary();
|
||||
|
||||
if (defaultPreferences.getBoolean(USE_TOR_KEY, false)) {
|
||||
@ -91,17 +94,34 @@ public class SettingsFragment extends PreferenceFragment
|
||||
App.configureTor(false);
|
||||
}
|
||||
}
|
||||
else if (key == DOWNLOAD_PATH_PREFERENCE)
|
||||
{
|
||||
String downloadPath = sharedPreferences
|
||||
.getString(DOWNLOAD_PATH_PREFERENCE,
|
||||
getString(R.string.download_path_summary));
|
||||
downloadPathPreference
|
||||
.setSummary(downloadPath);
|
||||
}
|
||||
else if (key == DOWNLOAD_PATH_AUDIO_PREFERENCE)
|
||||
{
|
||||
String downloadPath = sharedPreferences
|
||||
.getString(DOWNLOAD_PATH_AUDIO_PREFERENCE,
|
||||
getString(R.string.download_path_audio_summary));
|
||||
downloadPathAudioPreference
|
||||
.setSummary(downloadPath);
|
||||
}
|
||||
}
|
||||
};
|
||||
defaultPreferences.registerOnSharedPreferenceChangeListener(prefListener);
|
||||
|
||||
|
||||
updateSummary();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if(preference.getKey() == downloadPathPreference.getKey())
|
||||
|
||||
if(preference.getKey() == downloadPathPreference.getKey() ||
|
||||
preference.getKey() == downloadPathAudioPreference.getKey())
|
||||
{
|
||||
Activity activity = getActivity();
|
||||
Intent i = new Intent(activity, FilePickerActivity.class);
|
||||
@ -109,8 +129,14 @@ public class SettingsFragment extends PreferenceFragment
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_MULTIPLE, false);
|
||||
i.putExtra(FilePickerActivity.EXTRA_ALLOW_CREATE_DIR, true);
|
||||
i.putExtra(FilePickerActivity.EXTRA_MODE, FilePickerActivity.MODE_DIR);
|
||||
|
||||
activity.startActivityForResult(i, 233);
|
||||
if(preference.getKey() == downloadPathPreference.getKey())
|
||||
{
|
||||
activity.startActivityForResult(i, R.string.download_path_key);
|
||||
}
|
||||
else if (preference.getKey() == downloadPathAudioPreference.getKey())
|
||||
{
|
||||
activity.startActivityForResult(i, R.string.download_path_audio_key);
|
||||
}
|
||||
}
|
||||
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
|
@ -98,7 +98,7 @@
|
||||
android:summary="@string/download_path_summary"
|
||||
android:dialogTitle="@string/download_path_dialog_title" />
|
||||
|
||||
<EditTextPreference
|
||||
<Preference
|
||||
android:key="@string/download_path_audio_key"
|
||||
android:title="@string/download_path_audio_title"
|
||||
android:summary="@string/download_path_audio_summary"
|
||||
|
Loading…
Reference in New Issue
Block a user