mirror of
https://github.com/mihonapp/mihon.git
synced 2024-11-21 20:47:03 -05:00
Add IME_FLAG_NO_PERSONALIZED_LEARNING flag to text input when incognito is enabled (#5801)
* Add IME_FLAG_NO_PERSONALIZED_LEARNING flag to text input when incognito is enabled Tested with Gboard only. * Revert "Add IME_FLAG_NO_PERSONALIZED_LEARNING flag to text input when incognito is enabled" This reverts commit 068399db * Add IME_FLAG_NO_PERSONALIZED_LEARNING flag to text inputs when incognito is enabled Source preference is not affected. * Source preference stuff
This commit is contained in:
parent
7fa80ae556
commit
3ea84cf0ce
15 changed files with 128 additions and 13 deletions
|
@ -27,6 +27,7 @@ import eu.kanade.tachiyomi.source.ConfigurableSource
|
|||
import eu.kanade.tachiyomi.source.Source
|
||||
import eu.kanade.tachiyomi.source.getPreferenceKey
|
||||
import eu.kanade.tachiyomi.ui.base.controller.NucleusController
|
||||
import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito
|
||||
import timber.log.Timber
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
|
@ -113,6 +114,13 @@ class SourcePreferencesController(bundle: Bundle? = null) :
|
|||
pref.isIconSpaceReserved = false
|
||||
pref.order = Int.MAX_VALUE // reset to default order
|
||||
|
||||
// Apply incognito IME for EditTextPreference
|
||||
if (pref is EditTextPreference) {
|
||||
pref.setOnBindEditTextListener {
|
||||
it.setIncognito(viewScope)
|
||||
}
|
||||
}
|
||||
|
||||
newScreen.removePreference(pref)
|
||||
screen.addPreference(pref)
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.appcompat.widget.SearchView
|
||||
import androidx.core.view.inputmethod.EditorInfoCompat
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
/**
|
||||
* A custom [SearchView] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions
|
||||
* if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag.
|
||||
*/
|
||||
class TachiyomiSearchView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.searchViewStyle
|
||||
) : SearchView(context, attrs, defStyleAttr) {
|
||||
|
||||
private var scope: CoroutineScope? = null
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||
Injekt.get<PreferencesHelper>().incognitoMode().asImmediateFlow {
|
||||
imeOptions = if (it) {
|
||||
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING
|
||||
} else {
|
||||
imeOptions and EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING.inv()
|
||||
}
|
||||
}.launchIn(scope!!)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
scope?.cancel()
|
||||
scope = null
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package eu.kanade.tachiyomi.widget
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.widget.EditText
|
||||
import androidx.core.view.inputmethod.EditorInfoCompat
|
||||
import com.google.android.material.textfield.TextInputEditText
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asImmediateFlow
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
|
||||
/**
|
||||
* A custom [TextInputEditText] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions
|
||||
* if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag.
|
||||
*
|
||||
* @see setIncognito
|
||||
*/
|
||||
class TachiyomiTextInputEditText @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.editTextStyle
|
||||
) : TextInputEditText(context, attrs, defStyleAttr) {
|
||||
|
||||
private var scope: CoroutineScope? = null
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
scope = CoroutineScope(SupervisorJob() + Dispatchers.Main)
|
||||
setIncognito(scope!!)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
scope?.cancel()
|
||||
scope = null
|
||||
}
|
||||
|
||||
companion object {
|
||||
/**
|
||||
* Sets Flow to this [EditText] that sets [EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING] to imeOptions
|
||||
* if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag.
|
||||
*/
|
||||
fun EditText.setIncognito(viewScope: CoroutineScope) {
|
||||
Injekt.get<PreferencesHelper>().incognitoMode().asImmediateFlow {
|
||||
imeOptions = if (it) {
|
||||
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING
|
||||
} else {
|
||||
imeOptions and EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING.inv()
|
||||
}
|
||||
}.launchIn(viewScope)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
android:tint="?attr/colorAccent"
|
||||
app:srcCompat="@drawable/ic_chevron_left_black_24dp" />
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:id="@+id/myNumber"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
android:layout_weight="1"
|
||||
android:gravity="center_vertical|start">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:id="@+id/nav_view_item"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:hint="@string/username">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:id="@+id/username"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@ -27,7 +27,7 @@
|
|||
android:hint="@string/password"
|
||||
app:endIconMode="password_toggle">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
android:hint="@string/title"
|
||||
app:endIconMode="clear_text">
|
||||
|
||||
<com.google.android.material.textfield.TextInputEditText
|
||||
<eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText
|
||||
android:id="@+id/title_input_edit_text"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_travel_explore_24dp"
|
||||
android:title="@string/action_global_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="ifRoom|collapseActionView" />
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
android:id="@+id/action_search"
|
||||
android:icon="@drawable/ic_search_24dp"
|
||||
android:title="@string/action_search"
|
||||
app:actionViewClass="androidx.appcompat.widget.SearchView"
|
||||
app:actionViewClass="eu.kanade.tachiyomi.widget.TachiyomiSearchView"
|
||||
app:iconTint="?attr/colorOnToolbar"
|
||||
app:showAsAction="collapseActionView|ifRoom" />
|
||||
|
||||
|
|
Loading…
Reference in a new issue