forked from starifly/NekoBoxForAndroid
-
Notifications
You must be signed in to change notification settings - Fork 0
Reopen profile picker on reselect + WebDAV icons #42
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
46 changes: 46 additions & 0 deletions
46
app/src/main/java/io/nekohasekai/sagernet/widget/ReselectableSpinner.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,46 @@ | ||
| package io.nekohasekai.sagernet.widget | ||
|
|
||
| import android.content.Context | ||
| import android.util.AttributeSet | ||
| import androidx.appcompat.widget.AppCompatSpinner | ||
|
|
||
| class ReselectableSpinner @JvmOverloads constructor( | ||
| context: Context, attrs: AttributeSet? = null | ||
| ) : AppCompatSpinner(context, attrs) { | ||
|
|
||
| var onPopupClosed: (() -> Unit)? = null | ||
|
|
||
| /** | ||
| * Android's [Spinner] has no official "popup dismissed" callback, so we use | ||
| * the window regaining focus as a proxy: when the dropdown popup closes, | ||
| * focus returns to this spinner's window. This is intentionally a best-effort | ||
| * signal, not a precise one — [onPopupClosed] may also fire for unrelated | ||
| * focus changes (app foregrounding, keyboard/IME show-hide, system dialogs, | ||
| * permission prompts, orientation changes, etc.). Callers must therefore | ||
| * treat it only as a hint and stay correct if it fires spuriously (the | ||
| * OutboundPreference reselect logic does, by re-checking value/position). | ||
| */ | ||
| override fun onWindowFocusChanged(hasWindowFocus: Boolean) { | ||
| super.onWindowFocusChanged(hasWindowFocus) | ||
| if (hasWindowFocus) onPopupClosed?.invoke() | ||
| } | ||
|
|
||
| override fun setSelection(position: Int) { | ||
| val reselected = position == selectedItemPosition | ||
| super.setSelection(position) | ||
| if (reselected) notifyReselected(position) | ||
| } | ||
|
|
||
| override fun setSelection(position: Int, animate: Boolean) { | ||
| val reselected = position == selectedItemPosition | ||
| super.setSelection(position, animate) | ||
| if (reselected) notifyReselected(position) | ||
| } | ||
|
hawkff marked this conversation as resolved.
|
||
|
|
||
| private fun notifyReselected(position: Int) { | ||
| if (position < 0) return | ||
| onItemSelectedListener?.onItemSelected( | ||
| this, selectedView, position, adapter?.getItemId(position) ?: 0L | ||
| ) | ||
| } | ||
| } | ||
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,10 @@ | ||
| <vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:width="24dp" | ||
| android:height="24dp" | ||
| android:viewportWidth="24" | ||
| android:viewportHeight="24" | ||
| android:tint="?attr/colorControlNormal"> | ||
| <path | ||
| android:fillColor="@android:color/white" | ||
| android:pathData="M20,6h-8.17l-2,-2H4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V8c0,-1.1 -0.9,-2 -2,-2zM20,18H4V8h16v10z" /> | ||
| </vector> |
25 changes: 25 additions & 0 deletions
25
app/src/main/res/layout/preference_dropdown_reselectable.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,25 @@ | ||
| <?xml version="1.0" encoding="utf-8"?> | ||
| <!-- | ||
| Mirror of androidx's preference_dropdown_material.xml, with the anchor spinner | ||
| swapped for ReselectableSpinner so re-selecting the current item still fires a | ||
| selection callback. The (invisible) spinner is only the popup anchor; the | ||
| visible row comes from the standard @layout/preference_material include, so the | ||
| appearance is identical to a normal dropdown preference. | ||
| --> | ||
| <FrameLayout | ||
| xmlns:android="http://schemas.android.com/apk/res/android" | ||
| android:layout_width="match_parent" | ||
| android:layout_height="wrap_content"> | ||
|
|
||
| <io.nekohasekai.sagernet.widget.ReselectableSpinner | ||
| android:id="@+id/spinner" | ||
| android:layout_width="0dp" | ||
| android:layout_height="wrap_content" | ||
| android:layout_marginStart="@dimen/preference_dropdown_padding_start" | ||
| android:layout_marginLeft="@dimen/preference_dropdown_padding_start" | ||
| android:spinnerMode="dropdown" | ||
| android:visibility="invisible" /> | ||
|
|
||
| <include layout="@layout/preference_material" /> | ||
|
|
||
| </FrameLayout> |
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.