mirror of https://github.com/tasks/tasks
Convert Theme to Kotlin
parent
73d536a0c3
commit
2eac8dd20c
@ -1,64 +0,0 @@
|
||||
package org.tasks.themes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.PixelFormat;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.LayoutInflater;
|
||||
import javax.inject.Inject;
|
||||
import org.tasks.R;
|
||||
|
||||
public class Theme {
|
||||
|
||||
private final ThemeBase themeBase;
|
||||
private final ThemeColor themeColor;
|
||||
private final ThemeAccent themeAccent;
|
||||
|
||||
@Inject
|
||||
public Theme(ThemeBase themeBase, ThemeColor themeColor, ThemeAccent themeAccent) {
|
||||
this.themeBase = themeBase;
|
||||
this.themeColor = themeColor;
|
||||
this.themeAccent = themeAccent;
|
||||
}
|
||||
|
||||
public Theme withThemeColor(ThemeColor themeColor) {
|
||||
return new Theme(themeBase, themeColor, themeAccent);
|
||||
}
|
||||
|
||||
public ThemeBase getThemeBase() {
|
||||
return themeBase;
|
||||
}
|
||||
|
||||
public ThemeColor getThemeColor() {
|
||||
return themeColor;
|
||||
}
|
||||
|
||||
public LayoutInflater getLayoutInflater(Context context) {
|
||||
return (LayoutInflater) wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
}
|
||||
|
||||
public void applyThemeAndStatusBarColor(Activity activity) {
|
||||
applyTheme(activity);
|
||||
themeColor.applyToSystemBars(activity);
|
||||
themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name));
|
||||
}
|
||||
|
||||
public void applyTheme(Activity activity) {
|
||||
themeBase.set(activity);
|
||||
applyToContext(activity);
|
||||
activity.getWindow().setFormat(PixelFormat.RGBA_8888);
|
||||
}
|
||||
|
||||
public void applyToContext(Context context) {
|
||||
Resources.Theme theme = context.getTheme();
|
||||
themeColor.applyStyle(theme);
|
||||
themeAccent.applyStyle(theme);
|
||||
}
|
||||
|
||||
private Context wrap(Context context) {
|
||||
ContextThemeWrapper wrapper = themeBase.wrap(context);
|
||||
applyToContext(wrapper);
|
||||
return wrapper;
|
||||
}
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package org.tasks.themes
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.graphics.PixelFormat
|
||||
import android.view.LayoutInflater
|
||||
import org.tasks.R
|
||||
import javax.inject.Inject
|
||||
|
||||
class Theme @Inject constructor(
|
||||
val themeBase: ThemeBase,
|
||||
val themeColor: ThemeColor,
|
||||
private val themeAccent: ThemeAccent
|
||||
) {
|
||||
fun withThemeColor(themeColor: ThemeColor) = Theme(themeBase, themeColor, themeAccent)
|
||||
|
||||
fun getLayoutInflater(context: Context) =
|
||||
wrap(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
|
||||
|
||||
fun applyThemeAndStatusBarColor(activity: Activity) {
|
||||
applyTheme(activity)
|
||||
themeColor.applyToSystemBars(activity)
|
||||
themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name))
|
||||
}
|
||||
|
||||
fun applyTheme(activity: Activity) {
|
||||
themeBase.set(activity)
|
||||
applyToContext(activity)
|
||||
activity.window.setFormat(PixelFormat.RGBA_8888)
|
||||
}
|
||||
|
||||
fun applyToContext(context: Context) {
|
||||
val theme = context.theme
|
||||
themeColor.applyStyle(theme)
|
||||
themeAccent.applyStyle(theme)
|
||||
}
|
||||
|
||||
private fun wrap(context: Context): Context {
|
||||
val wrapper = themeBase.wrap(context)
|
||||
applyToContext(wrapper)
|
||||
return wrapper
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue