Converted SwitchPreferenceCompat to Kotlin and fixed the BlockedDialog using the joinCommunity string for some bizarre reason
parent
d3fb440d05
commit
5bd55ea993
@ -1,66 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components;
|
||||
|
||||
import static org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import androidx.preference.CheckBoxPreference;
|
||||
import androidx.preference.Preference;
|
||||
import com.squareup.phrase.Phrase;
|
||||
import network.loki.messenger.R;
|
||||
|
||||
public class SwitchPreferenceCompat extends CheckBoxPreference {
|
||||
|
||||
private static String LOCK_SCREEN_KEY = "pref_android_screen_lock";
|
||||
|
||||
private Preference.OnPreferenceClickListener listener;
|
||||
|
||||
public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
setLayoutRes();
|
||||
}
|
||||
|
||||
public SwitchPreferenceCompat(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||
super(context, attrs, defStyleAttr, defStyleRes);
|
||||
setLayoutRes();
|
||||
}
|
||||
|
||||
public SwitchPreferenceCompat(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setLayoutRes();
|
||||
}
|
||||
|
||||
public SwitchPreferenceCompat(Context context) {
|
||||
super(context);
|
||||
setLayoutRes();
|
||||
}
|
||||
|
||||
private void setLayoutRes() {
|
||||
setWidgetLayoutResource(R.layout.switch_compat_preference);
|
||||
|
||||
if (this.hasKey()) {
|
||||
String key = this.getKey();
|
||||
|
||||
// Substitute app name into lockscreen preference summary
|
||||
if (key.equalsIgnoreCase(LOCK_SCREEN_KEY)) {
|
||||
Context c = getContext();
|
||||
CharSequence substitutedSummaryCS = Phrase.from(c, R.string.lockAppDescription)
|
||||
.put(APP_NAME_KEY, c.getString(R.string.app_name))
|
||||
.format();
|
||||
this.setSummary(substitutedSummaryCS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOnPreferenceClickListener(Preference.OnPreferenceClickListener listener) {
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
if (listener == null || !listener.onPreferenceClick(this)) {
|
||||
super.onClick();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
package org.thoughtcrime.securesms.components
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import androidx.preference.CheckBoxPreference
|
||||
import com.squareup.phrase.Phrase
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
|
||||
import org.thoughtcrime.securesms.ui.getSubbedCharSequence
|
||||
import org.thoughtcrime.securesms.ui.getSubbedString
|
||||
|
||||
class SwitchPreferenceCompat : CheckBoxPreference {
|
||||
private var listener: OnPreferenceClickListener? = null
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context!!, attrs, defStyleAttr) {
|
||||
setLayoutRes()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context!!, attrs, defStyleAttr, defStyleRes) {
|
||||
setLayoutRes()
|
||||
}
|
||||
|
||||
constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {
|
||||
setLayoutRes()
|
||||
}
|
||||
|
||||
constructor(context: Context?) : super(context!!) {
|
||||
setLayoutRes()
|
||||
}
|
||||
|
||||
private fun setLayoutRes() {
|
||||
widgetLayoutResource = R.layout.switch_compat_preference
|
||||
|
||||
if (this.hasKey()) {
|
||||
val key = this.key
|
||||
|
||||
// Substitute app name into lockscreen preference summary
|
||||
if (key.equals(LOCK_SCREEN_KEY, ignoreCase = true)) {
|
||||
val c = context
|
||||
val substitutedSummaryCS = c.getSubbedCharSequence(R.string.lockAppDescription, APP_NAME_KEY to c.getString(R.string.app_name))
|
||||
this.summary = substitutedSummaryCS
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun setOnPreferenceClickListener(listener: OnPreferenceClickListener?) {
|
||||
this.listener = listener
|
||||
}
|
||||
|
||||
override fun onClick() {
|
||||
if (listener == null || !listener!!.onPreferenceClick(this)) {
|
||||
super.onClick()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
private const val LOCK_SCREEN_KEY = "pref_android_screen_lock"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue