-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
add proxy settings #12691
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
Open
fokin33
wants to merge
1
commit into
TeamNewPipe:dev
Choose a base branch
from
fokin33:add_proxy_settings
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
add proxy settings #12691
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
app/src/main/java/org/schabi/newpipe/settings/ProxyManager.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| package org.schabi.newpipe.settings; | ||
|
|
||
| import android.content.Context; | ||
| import android.content.SharedPreferences; | ||
|
|
||
| import androidx.preference.PreferenceManager; | ||
|
|
||
| import java.net.InetSocketAddress; | ||
| import java.net.Proxy; | ||
|
|
||
| /** | ||
| * A class to manage proxy settings. | ||
| */ | ||
| public class ProxyManager { | ||
|
|
||
| private final SharedPreferences sharedPreferences; | ||
|
|
||
| /** | ||
| * Creates a new ProxyManager. | ||
| * @param context the context to use | ||
| */ | ||
| public ProxyManager(final Context context) { | ||
| this.sharedPreferences = | ||
| PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()); | ||
| } | ||
|
|
||
| /** | ||
| * Checks if the proxy is enabled. | ||
| * @return true if the proxy is enabled, false otherwise | ||
| */ | ||
| public boolean isProxyEnabled() { | ||
| return sharedPreferences.getBoolean("use_proxy", false); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the proxy host. | ||
| * @return the proxy host | ||
| */ | ||
| public String getProxyHost() { | ||
| return sharedPreferences.getString("proxy_host", "127.0.0.1"); | ||
| } | ||
|
|
||
| /** | ||
| * Gets the proxy port. | ||
| * @return the proxy port | ||
| */ | ||
| public int getProxyPort() { | ||
| final String portString = sharedPreferences.getString("proxy_port", "1080"); | ||
| try { | ||
| return Integer.parseInt(portString); | ||
| } catch (final NumberFormatException e) { | ||
| return 1080; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the proxy type. | ||
| * @return the proxy type | ||
| */ | ||
| public Proxy.Type getProxyType() { | ||
| final String type = sharedPreferences.getString("proxy_type", "SOCKS"); | ||
| if ("SOCKS".equals(type)) { | ||
| return Proxy.Type.SOCKS; | ||
| } else { | ||
| return Proxy.Type.HTTP; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Gets the proxy. | ||
| * @return the proxy, or null if the proxy is not enabled | ||
| */ | ||
| public Proxy getProxy() { | ||
| if (!isProxyEnabled()) { | ||
| return null; | ||
| } | ||
| return new Proxy(getProxyType(), new InetSocketAddress(getProxyHost(), getProxyPort())); | ||
| } | ||
| } |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/schabi/newpipe/settings/ProxySettingsFragment.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package org.schabi.newpipe.settings; | ||
|
|
||
| import android.os.Bundle; | ||
|
|
||
| import androidx.annotation.Nullable; | ||
| import androidx.preference.ListPreference; | ||
|
|
||
| import org.schabi.newpipe.R; | ||
|
|
||
| /** | ||
| * A fragment that displays proxy settings. | ||
| */ | ||
| public class ProxySettingsFragment extends BasePreferenceFragment { | ||
|
|
||
| @Override | ||
| public void onCreatePreferences(@Nullable final Bundle savedInstanceState, | ||
| @Nullable final String rootKey) { | ||
| addPreferencesFromResource(R.xml.proxy_settings); | ||
|
|
||
| final ListPreference proxyTypePreference = findPreference("proxy_type"); | ||
| if (proxyTypePreference != null) { | ||
| proxyTypePreference.setSummaryProvider( | ||
| ListPreference.SimpleSummaryProvider.getInstance()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <menu xmlns:android="http://schemas.android.com/apk/res/android" | ||
| xmlns:app="http://schemas.android.com/apk/res-auto"> | ||
| <item | ||
| android:id="@+id/action_search" | ||
| android:icon="@drawable/ic_search" | ||
| android:title="@string/search" | ||
| app:showAsAction="ifRoom" /> | ||
| </menu> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <string name="proxy_settings_title">Настройки прокси</string> | ||
| <string name="use_proxy">Использовать прокси</string> | ||
| <string name="use_proxy_summary">Перенаправлять трафик через прокси</string> | ||
| <string name="proxy_host">Хост прокси</string> | ||
| <string name="proxy_host_summary">Имя хоста или IP-адрес прокси</string> | ||
| <string name="proxy_port">Порт прокси</string> | ||
| <string name="proxy_port_summary">Номер порта прокси</string> | ||
| <string name="proxy_port_dialog_message">Введите номер порта прокси</string> | ||
| </resources> |
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is a good idea to separate the strings so that strings.xml is not cluttered too much. However, I think this should be done for all strings at the same time in a separate PR. Please make this a section in string.xml for now. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <resources> | ||
| <string name="proxy_settings_title">Proxy Settings</string> | ||
| <string name="use_proxy">Use proxy</string> | ||
| <string name="use_proxy_summary">Redirect traffic through a proxy</string> | ||
| <string name="proxy_host">Proxy host</string> | ||
| <string name="proxy_host_summary">Hostname or IP address of the proxy</string> | ||
| <string name="proxy_port">Proxy port</string> | ||
| <string name="proxy_port_summary">Port number of the proxy</string> | ||
| <string name="proxy_port_dialog_message">Enter the proxy port number</string> | ||
| <string name="proxy_type">Proxy type</string> | ||
| <string-array name="proxy_type_entries"> | ||
| <item>HTTP</item> | ||
| <item>SOCKS</item> | ||
| </string-array> | ||
| <string-array name="proxy_type_values"> | ||
| <item>HTTP</item> | ||
| <item>SOCKS</item> | ||
| </string-array> | ||
| </resources> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where does this file come from?