Override theme for all fragments

pull/413/head
Alex Baker 8 years ago
parent 3aa3ad3db1
commit 5d8c6211cc

@ -54,6 +54,7 @@ import org.tasks.preferences.Preferences;
import org.tasks.receivers.RepeatConfirmationReceiver;
import org.tasks.themes.Theme;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.EmptyTaskEditFragment;
import org.tasks.ui.NavigationDrawerFragment;
import org.tasks.ui.PriorityControlSet;
@ -181,19 +182,20 @@ public class TaskListActivity extends InjectingAppCompatActivity implements
}
private void loadTaskListFragment(TaskListFragment taskListFragment) {
Filter filter = taskListFragment.filter;
ThemeColor themeColor = filter.tint >= 0
? themeCache.getThemeColor(filter.tint)
: theme.getThemeColor();
themeColor.applyStatusBarColor(drawerLayout);
themeColor.applyStyle(this);
themeColor.applyTaskDescription(this, filter.listingTitle);
FragmentManager fragmentManager = getFragmentManager();
fragmentManager.popBackStackImmediate(null, FragmentManager.POP_BACK_STACK_INCLUSIVE);
fragmentManager.beginTransaction()
.replace(isDoublePaneLayout() ? R.id.master_dual : R.id.single_pane, taskListFragment, TaskListFragment.TAG_TASKLIST_FRAGMENT)
.addToBackStack(TaskListFragment.TAG_TASKLIST_FRAGMENT)
.commit();
Filter filter = taskListFragment.filter;
if (filter.tint >= 0) {
themeCache.getThemeColor(filter.tint).applyStatusBarColor(drawerLayout);
} else {
theme.getThemeColor().applyStatusBarColor(drawerLayout);
}
theme.applyTaskDescription(this, filter.listingTitle);
}
private void loadTaskEditFragment(boolean onCreate, TaskEditFragment taskEditFragment, List<TaskEditControlFragment> taskEditControlFragments) {

@ -81,7 +81,6 @@ import org.tasks.injection.InjectingListFragment;
import org.tasks.notifications.NotificationManager;
import org.tasks.preferences.Preferences;
import org.tasks.themes.ThemeCache;
import org.tasks.themes.ThemeColor;
import org.tasks.ui.CheckBoxes;
import org.tasks.ui.MenuColorizer;
@ -151,7 +150,6 @@ public class TaskListFragment extends InjectingListFragment implements
@Inject Broadcaster broadcaster;
@Inject TagService tagService;
@Inject ThemeCache themeCache;
@Inject ThemeColor themeColor;
@BindView(R.id.swipe_layout) SwipeRefreshLayout swipeRefreshLayout;
@BindView(R.id.swipe_layout_empty) SwipeRefreshLayout emptyView;
@ -177,10 +175,6 @@ public class TaskListFragment extends InjectingListFragment implements
}
}
public ThemeColor getThemeColor() {
return filter.tint >= 0 ? themeCache.getThemeColor(filter.tint) : themeColor;
}
public void setSyncOngoing(final boolean ongoing) {
Activity activity = getActivity();
if (activity != null) {
@ -269,8 +263,6 @@ public class TaskListFragment extends InjectingListFragment implements
callbacks.onNavigationIconClicked();
}
});
ThemeColor color = getThemeColor();
toolbar.setBackgroundColor(color.getPrimaryColor());
inflateMenu(toolbar);
Menu menu = toolbar.getMenu();
for (int i = 0 ; i < menu.size() ; i++) {

@ -1,7 +1,6 @@
package org.tasks.themes;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.PixelFormat;
@ -12,8 +11,6 @@ import org.tasks.R;
import javax.inject.Inject;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
public class Theme {
private final ThemeBase themeBase;
private final ThemeColor themeColor;
@ -39,7 +36,7 @@ public class Theme {
}
public LayoutInflater getLayoutInflater(Context context) {
ContextThemeWrapper wrapper = new ContextThemeWrapper(context, themeBase.getStyle());
ContextThemeWrapper wrapper = themeBase.wrap(context);
applyToContext(wrapper);
return (LayoutInflater) wrapper.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@ -51,24 +48,19 @@ public class Theme {
public void applyThemeAndStatusBarColor(Activity activity) {
applyTheme(activity);
themeColor.applyStatusBarColor(activity);
applyTaskDescription(activity, activity.getString(R.string.app_name));
themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name));
}
public void applyTheme(Activity activity) {
activity.setTheme(themeBase.getStyle());
themeBase.set(activity);
applyToContext(activity);
activity.getWindow().setFormat(PixelFormat.RGBA_8888);
}
public void applyTaskDescription(Activity activity, String description) {
if (atLeastLollipop()) {
activity.setTaskDescription(new ActivityManager.TaskDescription(description, null, themeColor.getPrimaryColor()));
}
}
public void applyToContext(Context context) {
Resources.Theme theme = context.getTheme();
theme.applyStyle(themeColor.getStyle(), true);
theme.applyStyle(themeAccent.getStyle(), true);
themeColor.applyStyle(theme);
themeAccent.apply(theme);
}
}

@ -1,5 +1,7 @@
package org.tasks.themes;
import android.content.res.Resources;
import org.tasks.R;
public class ThemeAccent {
@ -36,6 +38,10 @@ public class ThemeAccent {
this.accentColor = accentColor;
}
public void apply(Resources.Theme theme) {
theme.applyStyle(style, true);
}
public String getName() {
return name;
}
@ -44,10 +50,6 @@ public class ThemeAccent {
return index;
}
public int getStyle() {
return style;
}
public int getAccentColor() {
return accentColor;
}

@ -1,5 +1,9 @@
package org.tasks.themes;
import android.app.Activity;
import android.content.Context;
import android.support.v7.view.ContextThemeWrapper;
import org.tasks.R;
public class ThemeBase {
@ -34,10 +38,6 @@ public class ThemeBase {
return index;
}
public int getStyle() {
return style;
}
public int getDialogStyle() {
return dialogStyle;
}
@ -53,4 +53,12 @@ public class ThemeBase {
public boolean isDarkTheme() {
return index > 0;
}
public ContextThemeWrapper wrap(Context context) {
return new ContextThemeWrapper(context, style);
}
public void set(Activity activity) {
activity.setTheme(style);
}
}

@ -1,10 +1,12 @@
package org.tasks.themes;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.res.Resources;
import android.support.v4.widget.DrawerLayout;
import org.tasks.R;
import org.tasks.ui.NavigationDrawerFragment;
import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop;
@ -59,6 +61,20 @@ public class ThemeColor {
}
}
public void applyStyle(Context context) {
applyStyle(context.getTheme());
}
public void applyStyle(Resources.Theme theme) {
theme.applyStyle(style, true);
}
public void applyTaskDescription(Activity activity, String description) {
if (atLeastLollipop()) {
activity.setTaskDescription(new ActivityManager.TaskDescription(description, null, getPrimaryColor()));
}
}
public String getName() {
return name;
}
@ -67,10 +83,6 @@ public class ThemeColor {
return index;
}
public int getStyle() {
return style;
}
public int getPrimaryColor() {
return colorPrimary;
}

Loading…
Cancel
Save