1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-12-23 08:30:44 +00:00

moved on to new sdk, and put settings activity result into its fragment

This commit is contained in:
Christian Schabesberger 2016-07-25 11:12:54 +02:00
parent dc46b3f6c0
commit c0ce14dba5
4 changed files with 93 additions and 81 deletions

View File

@ -7,7 +7,7 @@ android {
defaultConfig {
applicationId "org.schabi.newpipe"
minSdkVersion 15
targetSdkVersion 23
targetSdkVersion 24
versionCode 18
versionName "0.8.0"
}
@ -31,10 +31,10 @@ android {
}
dependencies {
compile 'com.android.support:appcompat-v7:24.1.0'
compile 'com.android.support:support-v4:24.1.0'
compile 'com.android.support:design:24.1.0'
compile 'com.android.support:recyclerview-v7:24.1.0'
compile 'com.android.support:appcompat-v7:24.1.1'
compile 'com.android.support:support-v4:24.1.1'
compile 'com.android.support:design:24.1.1'
compile 'com.android.support:recyclerview-v7:24.1.1'
compile 'org.jsoup:jsoup:1.8.3'
compile 'org.mozilla:rhino:1.7.7'
compile 'info.guardianproject.netcipher:netcipher:1.2'

View File

@ -10,7 +10,6 @@ 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;
@ -20,11 +19,6 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import com.nononsenseapps.filepicker.FilePickerActivity;
import java.util.ArrayList;
import info.guardianproject.netcipher.proxy.OrbotHelper;
/**
* Created by Christian Schabesberger on 31.08.15.
@ -47,9 +41,8 @@ import info.guardianproject.netcipher.proxy.OrbotHelper;
*/
public class SettingsActivity extends PreferenceActivity {
public static final int REQUEST_INSTALL_ORBOT = 0x1234;
private AppCompatDelegate mDelegate = null;
SettingsFragment f = new SettingsFragment();
@Override
protected void onCreate(Bundle savedInstanceBundle) {
@ -63,61 +56,14 @@ public class SettingsActivity extends PreferenceActivity {
actionBar.setDisplayShowTitleEnabled(true);
getFragmentManager().beginTransaction()
.replace(android.R.id.content, new SettingsFragment())
.replace(android.R.id.content, f)
.commit();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
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) {
ClipData clip = data.getClipData();
if (clip != null) {
for (int i = 0; i < clip.getItemCount(); i++) {
uri = clip.getItemAt(i).getUri();
}
}
// For Ice Cream Sandwich
} else {
ArrayList<String> paths = data.getStringArrayListExtra
(FilePickerActivity.EXTRA_PATHS);
if (paths != null) {
for (String path: paths) {
uri = Uri.parse(path);
}
}
}
} else {
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)
{
// try to start tor regardless of resultCode since clicking back after
// installing the app does not necessarily return RESULT_OK
App.configureTor(requestCode == REQUEST_INSTALL_ORBOT
&& OrbotHelper.requestStartTor(this));
}
super.onActivityResult(requestCode, resultCode, data);
f.onActivityResult(requestCode, resultCode, data);
}
@Override

View File

@ -1,8 +1,11 @@
package org.schabi.newpipe;
import android.app.Activity;
import android.content.ClipData;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
@ -13,11 +16,30 @@ import android.preference.PreferenceScreen;
import com.nononsenseapps.filepicker.FilePickerActivity;
import java.util.ArrayList;
import info.guardianproject.netcipher.proxy.OrbotHelper;
/**
* Created by david on 15/06/16.
*
* Copyright (C) Christian Schabesberger 2016 <chris.schabesberger@mailbox.org>
* SettingsFragment.java is part of NewPipe.
*
* NewPipe is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* NewPipe is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with NewPipe. If not, see <http://www.gnu.org/licenses/>.
*/
public class SettingsFragment extends PreferenceFragment
implements SharedPreferences.OnSharedPreferenceChangeListener
{
@ -31,12 +53,13 @@ public class SettingsFragment extends PreferenceFragment
String DOWNLOAD_PATH_AUDIO_PREFERENCE;
String USE_TOR_KEY;
public static final int REQUEST_INSTALL_ORBOT = 0x1234;
private ListPreference defaultResolutionPreference;
private ListPreference defaultAudioFormatPreference;
private ListPreference searchLanguagePreference;
private Preference downloadPathPreference;
private Preference downloadPathAudioPreference;
private CheckBoxPreference useTorCheckBox;
private SharedPreferences defaultPreferences;
@ -66,7 +89,6 @@ public class SettingsFragment extends PreferenceFragment
(ListPreference) findPreference(SEARCH_LANGUAGE_PREFERENCE);
downloadPathPreference = findPreference(DOWNLOAD_PATH_PREFERENCE);
downloadPathAudioPreference = findPreference(DOWNLOAD_PATH_AUDIO_PREFERENCE);
useTorCheckBox = (CheckBoxPreference) findPreference(USE_TOR_KEY);
prefListener = new SharedPreferences.OnSharedPreferenceChangeListener() {
@Override
@ -87,7 +109,7 @@ public class SettingsFragment extends PreferenceFragment
OrbotHelper.requestStartTor(a);
} else {
Intent intent = OrbotHelper.getOrbotInstallIntent(a);
a.startActivityForResult(intent, SettingsActivity.REQUEST_INSTALL_ORBOT);
a.startActivityForResult(intent, REQUEST_INSTALL_ORBOT);
}
} else {
App.configureTor(false);
@ -119,8 +141,8 @@ public class SettingsFragment extends PreferenceFragment
@Override
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
if(preference.getKey() == downloadPathPreference.getKey() ||
preference.getKey() == downloadPathAudioPreference.getKey())
if(preference.getKey().equals(downloadPathPreference.getKey()) ||
preference.getKey().equals(downloadPathAudioPreference.getKey()))
{
Activity activity = getActivity();
Intent i = new Intent(activity, FilePickerActivity.class);
@ -128,11 +150,11 @@ 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);
if(preference.getKey() == downloadPathPreference.getKey())
if(preference.getKey().equals(downloadPathPreference.getKey()))
{
activity.startActivityForResult(i, R.string.download_path_key);
}
else if (preference.getKey() == downloadPathAudioPreference.getKey())
else if (preference.getKey().equals(downloadPathAudioPreference.getKey()))
{
activity.startActivityForResult(i, R.string.download_path_audio_key);
}
@ -141,6 +163,62 @@ public class SettingsFragment extends PreferenceFragment
return super.onPreferenceTreeClick(preferenceScreen, preference);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
Activity a = getActivity();
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) {
ClipData clip = data.getClipData();
if (clip != null) {
for (int i = 0; i < clip.getItemCount(); i++) {
uri = clip.getItemAt(i).getUri();
}
}
// For Ice Cream Sandwich
} else {
ArrayList<String> paths = data.getStringArrayListExtra
(FilePickerActivity.EXTRA_PATHS);
if (paths != null) {
for (String path: paths) {
uri = Uri.parse(path);
}
}
}
} else {
uri = data.getData();
}
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(a);
//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)
.apply();
}
else if(requestCode == REQUEST_INSTALL_ORBOT)
{
// try to start tor regardless of resultCode since clicking back after
// installing the app does not necessarily return RESULT_OK
App.configureTor(requestCode == REQUEST_INSTALL_ORBOT
&& OrbotHelper.requestStartTor(a));
}
super.onActivityResult(requestCode, resultCode, data);
}
// This is used to show the status of some preference in the description
private void updateSummary() {
defaultResolutionPreference.setSummary(

View File

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>