Refactor packages

This commit is contained in:
h4h13 2019-04-20 10:59:45 +05:30
parent c386e1fe93
commit 39b0b4c931
188 changed files with 440 additions and 835 deletions

View file

@ -1,80 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.preference.CheckBoxPreference
import android.preference.Preference
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.CheckBox
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
/**
* @author Aidan Follestad (afollestad)
*/
class ATECheckBoxPreference : CheckBoxPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
try {
val canRecycleLayoutField = Preference::class.java.getDeclaredField("mCanRecycleLayout")
canRecycleLayoutField.isAccessible = true
canRecycleLayoutField.setBoolean(this, true)
} catch (ignored: Exception) {
}
try {
val hasSpecifiedLayout = Preference::class.java.getDeclaredField("mHasSpecifiedLayout")
hasSpecifiedLayout.isAccessible = true
hasSpecifiedLayout.setBoolean(this, true)
} catch (ignored: Exception) {
}
}
override fun onBindView(view: View) {
super.onBindView(view)
val parentCheckbox = findCheckboxView(view)
if (parentCheckbox != null) {
ATH.setTint(parentCheckbox, ThemeStore.accentColor(view.context))
}
}
private fun findCheckboxView(view: View): View? {
if (view is ViewGroup) {
for (i in 0 until view.childCount) {
val child = view.getChildAt(i)
if (child is CheckBox) {
return child
} else if (child is ViewGroup) {
val potentialCheckbox = findCheckboxView(child)
if (potentialCheckbox != null) return potentialCheckbox
}
}
} else if (view is CheckBox) {
return view
}
return null
}
}

View file

@ -1,33 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.util.AttributeSet
import androidx.preference.EditTextPreference
/**
* @author Aidan Follestad (afollestad)
*/
class ATEEditTextPreference : EditTextPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = code.name.monkey.appthemehelper.R.layout.ate_preference_custom
}
}

View file

@ -1,36 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.util.AttributeSet
import android.preference.ListPreference
import code.name.monkey.appthemehelper.R
/**
* @author Aidan Follestad (afollestad)
*/
class ATEListPreference : ListPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
if (summary == null || summary.toString().trim { it <= ' ' }.isEmpty())
summary = "%s"
}
}

View file

@ -1,32 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.preference.ListPreference
import android.util.AttributeSet
import code.name.monkey.appthemehelper.R
/**
* @author Aidan Follestad (afollestad)
*/
class ATEMultiSelectPreference : ListPreference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
}
}

View file

@ -1,32 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.preference.Preference
import android.util.AttributeSet
import code.name.monkey.appthemehelper.R
/**
* @author Aidan Follestad (afollestad)
*/
class ATEPreference : Preference {
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
}
}

View file

@ -1,32 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.content.Context
import android.preference.PreferenceCategory
import android.util.AttributeSet
import android.view.View
import android.widget.TextView
import code.name.monkey.appthemehelper.ThemeStore
class ATEPreferenceCategory : PreferenceCategory {
constructor(context: Context) : super(context) {
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
}
override fun onBindView(view: View) {
super.onBindView(view)
val mTitle = view.findViewById<View>(android.R.id.title) as TextView
mTitle.setTextColor(ThemeStore.accentColor(view.context))
}
}

View file

@ -1,108 +0,0 @@
package code.name.monkey.appthemehelper.common.prefs
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import android.preference.Preference
import android.preference.SwitchPreference
import android.util.AttributeSet
import android.view.View
import android.view.ViewGroup
import android.widget.Switch
import androidx.appcompat.widget.SwitchCompat
import code.name.monkey.appthemehelper.ATH
import code.name.monkey.appthemehelper.R
import code.name.monkey.appthemehelper.ThemeStore
import code.name.monkey.appthemehelper.common.views.ATESwitch
/**
* @author Aidan Follestad (afollestad)
*/
class ATESwitchPreference : SwitchPreference {
private var mSwitch: ATESwitch? = null
constructor(context: Context) : super(context) {
init()
}
constructor(context: Context, attrs: AttributeSet) : super(context, attrs) {
init()
}
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(context, attrs, defStyleAttr) {
init()
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) {
init()
}
private fun init() {
layoutResource = R.layout.ate_preference_custom
if (COMPAT_MODE) {
widgetLayoutResource = R.layout.ate_preference_switch
} else {
try {
val canRecycleLayoutField = Preference::class.java.getDeclaredField("mCanRecycleLayout")
canRecycleLayoutField.isAccessible = true
canRecycleLayoutField.setBoolean(this, true)
} catch (ignored: Exception) {
}
try {
val hasSpecifiedLayout = Preference::class.java.getDeclaredField("mHasSpecifiedLayout")
hasSpecifiedLayout.isAccessible = true
hasSpecifiedLayout.setBoolean(this, true)
} catch (ignored: Exception) {
}
}
}
override fun onBindView(view: View) {
super.onBindView(view)
if (COMPAT_MODE) {
mSwitch = view.findViewById<View>(R.id.switchWidget) as ATESwitch
mSwitch!!.isChecked = isChecked
} else {
val parentSwitch = findSwitchView(view)
if (parentSwitch != null) {
ATH.setTint(parentSwitch, ThemeStore.accentColor(view.context))
}
}
}
private fun findSwitchView(view: View): View? {
if (view is ViewGroup) {
for (i in 0 until view.childCount) {
val child = view.getChildAt(i)
if (child is Switch || child is SwitchCompat) {
return child
} else if (child is ViewGroup) {
val potentialSwitch = findSwitchView(child)
if (potentialSwitch != null) return potentialSwitch
}
}
} else if (view is Switch || view is SwitchCompat) {
return view
}
return null
}
override fun setChecked(checked: Boolean) {
super.setChecked(checked)
if (COMPAT_MODE) {
if (mSwitch != null) {
mSwitch!!.isChecked = checked
}
}
}
companion object {
internal val COMPAT_MODE = Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP
}
}

View file

@ -3,9 +3,8 @@ package code.name.monkey.appthemehelper.common.prefs.supportv7
import android.annotation.TargetApi
import android.content.Context
import android.os.Build
import androidx.preference.CheckBoxPreference
import android.util.AttributeSet
import androidx.preference.CheckBoxPreference
import code.name.monkey.appthemehelper.R
/**

View file

@ -1,7 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_toggle_switch_off"
android:state_checked="false"/>
<item android:drawable="@drawable/ic_toggle_switch"
android:state_checked="true"/>
<item android:drawable="@drawable/ic_toggle_switch_off" android:state_checked="false" />
<item android:drawable="@drawable/ic_toggle_switch" android:state_checked="true" />
</selector>

View file

@ -3,7 +3,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="?android:attr/selectableItemBackground"
android:baselineAligned="false"
android:gravity="center_vertical"
@ -36,12 +35,12 @@
<code.name.monkey.appthemehelper.common.views.ATEPrimaryTextView
android:id="@android:id/title"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:ellipsize="marquee"
style="@style/TextAppearance.MaterialComponents.Subtitle1"
android:fadingEdge="horizontal"
android:singleLine="true"
tools:text="Title" />