-
-
Notifications
You must be signed in to change notification settings - Fork 199
Implement proxy preferences #726
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
micaplush
wants to merge
9
commits into
grote:master
Choose a base branch
from
micaplush:proxy-settings
base: master
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
Changes from 6 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8e65c86
Implement proxy preferences
micaplush 66c83f6
Use Log.e for parsing errors in proxy settings
micaplush ce83c52
Add myself to contributors
micaplush c73843e
Fix broken call to Log in SettingsManager
micaplush a1ea52d
Use a SwitchPreference for toggling network proxy usage
micaplush f945e3f
Implement validation for proxy preferences
micaplush 84a3e7a
Use Patterns for proxy host validation
micaplush a93f491
Test proxy connection on proxy preference changes
micaplush b889dcd
Explicitly allow "localhost" for proxy host preference
micaplush 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
112 changes: 112 additions & 0 deletions
112
app/src/main/java/de/grobox/transportr/ui/ValidatedEditTextPreference.kt
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,112 @@ | ||
| /* | ||
| * Transportr | ||
| * | ||
| * Copyright (c) 2013 - 2020 Torsten Grote | ||
| * | ||
| * This program 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. | ||
| * | ||
| * This program 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package de.grobox.transportr.ui | ||
|
|
||
| import android.content.Context | ||
| import android.content.res.TypedArray | ||
| import android.text.Editable | ||
| import android.text.TextWatcher | ||
| import android.util.AttributeSet | ||
| import android.view.inputmethod.InputMethodManager | ||
| import android.widget.Button | ||
| import android.widget.EditText | ||
| import android.widget.TextView | ||
| import androidx.appcompat.app.AlertDialog | ||
| import androidx.preference.Preference | ||
| import de.grobox.transportr.R | ||
|
|
||
| /** | ||
| * An editable text preference that gives immediate user feedback by | ||
| * disabling the "OK" button of the edit dialog if the entered text | ||
| * does not match the validation criteria. | ||
| * | ||
| * Validation can be configured by setting the <code>validate</code> | ||
| * property. | ||
| */ | ||
| class ValidatedEditTextPreference(ctx: Context, attrs: AttributeSet) : | ||
| Preference(ctx, attrs, R.attr.preferenceStyle) { | ||
|
|
||
| var validate: ((String) -> Boolean) = { true } | ||
| private var persistedValue: String = "" | ||
| private var currentValue: String = persistedValue | ||
|
|
||
| init { | ||
| setSummaryProvider { persistedValue } | ||
|
|
||
| setOnPreferenceClickListener { | ||
| currentValue = persistedValue | ||
|
|
||
| val dialog = AlertDialog.Builder(ctx) | ||
| .setTitle(title) | ||
| .setView(R.layout.dialog_validated_edit_text_preference) | ||
| .setCancelable(true) | ||
| .setPositiveButton(R.string.ok) { dialogInterface, _ -> | ||
| dialogInterface.dismiss() | ||
| persistString(currentValue) | ||
| persistedValue = currentValue | ||
| notifyChanged() | ||
| } | ||
| .setNegativeButton(R.string.cancel) { dialogInterface, _ -> | ||
| dialogInterface.cancel() | ||
| currentValue = persistedValue | ||
| } | ||
| .create() | ||
| dialog.show() | ||
|
|
||
| val editText = dialog.findViewById<EditText>(R.id.text_input)!! | ||
| val okButton = dialog.findViewById<Button>(android.R.id.button1)!! | ||
|
|
||
| fun updateUIForValidity() { | ||
| okButton.isEnabled = validate(currentValue) | ||
| } | ||
| updateUIForValidity() | ||
|
|
||
| editText.setText(currentValue, TextView.BufferType.NORMAL) | ||
| editText.addTextChangedListener(object : TextWatcher { | ||
| override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} | ||
|
|
||
| override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} | ||
|
|
||
| override fun afterTextChanged(text: Editable?) { | ||
| currentValue = text.toString() | ||
| updateUIForValidity() | ||
| } | ||
| }) | ||
| editText.postDelayed({ | ||
| editText.requestFocus() | ||
| editText.setSelection(currentValue.length) | ||
| val inputMethodManager = ctx.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager | ||
| inputMethodManager.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT) | ||
| }, 100) | ||
|
|
||
| true | ||
| } | ||
| } | ||
|
|
||
| override fun onGetDefaultValue(a: TypedArray?, index: Int): String? { | ||
| return a!!.getString(index) | ||
| } | ||
|
|
||
| override fun onSetInitialValue(defaultValue: Any?) { | ||
| super.onSetInitialValue(defaultValue) | ||
| persistedValue = getPersistedString(defaultValue?.toString()) ?: persistedValue | ||
| currentValue = persistedValue | ||
| } | ||
| } |
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
12 changes: 12 additions & 0 deletions
12
app/src/main/res/layout/dialog_validated_edit_text_preference.xml
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,12 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <LinearLayout | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content" | ||
| android:paddingHorizontal="20dp"> | ||
|
|
||
| <EditText android:id="@+id/text_input" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"/> | ||
|
|
||
| </LinearLayout> |
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
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.
Uh oh!
There was an error while loading. Please reload this page.