From 3aa3ad3db173c84a4d23cab4ce685d37c6776b22 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Wed, 29 Jun 2016 23:30:26 -0500 Subject: [PATCH] Apply tag color to action and status bar --- .../astrid/actfm/TagSettingsActivity.java | 10 +++++++++- .../todoroo/astrid/actfm/TagViewFragment.java | 1 - .../astrid/activity/TaskListActivity.java | 17 +++++++++++++++-- .../astrid/activity/TaskListFragment.java | 10 +++++++++- src/main/java/org/tasks/themes/Theme.java | 12 +++++------- src/main/java/org/tasks/themes/ThemeColor.java | 18 ++++++++++++++++++ 6 files changed, 56 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/todoroo/astrid/actfm/TagSettingsActivity.java b/src/main/java/com/todoroo/astrid/actfm/TagSettingsActivity.java index e85938641..3e25d8f34 100644 --- a/src/main/java/com/todoroo/astrid/actfm/TagSettingsActivity.java +++ b/src/main/java/com/todoroo/astrid/actfm/TagSettingsActivity.java @@ -42,6 +42,7 @@ import org.tasks.injection.ActivityComponent; import org.tasks.injection.ThemedInjectingAppCompatActivity; import org.tasks.preferences.Preferences; import org.tasks.themes.ThemeCache; +import org.tasks.themes.ThemeColor; import org.tasks.ui.MenuColorizer; import javax.inject.Inject; @@ -76,6 +77,7 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity implem @Inject Preferences preferences; @Inject ThemeCache themeCache; @Inject PurchaseHelper purchaseHelper; + @Inject ThemeColor themeColor; @BindView(R.id.tag_name) EditText tagName; @BindView(R.id.toolbar) Toolbar toolbar; @@ -292,9 +294,15 @@ public class TagSettingsActivity extends ThemedInjectingAppCompatActivity implem private void updateTheme() { if (selectedTheme < 0) { themeName.setText(R.string.none); + toolbar.setBackgroundColor(themeColor.getPrimaryColor()); + themeColor.applyStatusBarColor(this); clear.setVisibility(View.GONE); + } else { - themeName.setText(themeCache.getThemeColor(selectedTheme).getName()); + ThemeColor themeColor = themeCache.getThemeColor(selectedTheme); + toolbar.setBackgroundColor(themeColor.getPrimaryColor()); + themeColor.applyStatusBarColor(this); + themeName.setText(themeColor.getName()); clear.setVisibility(View.VISIBLE); } } diff --git a/src/main/java/com/todoroo/astrid/actfm/TagViewFragment.java b/src/main/java/com/todoroo/astrid/actfm/TagViewFragment.java index 3b57cbc49..1c61f1a62 100644 --- a/src/main/java/com/todoroo/astrid/actfm/TagViewFragment.java +++ b/src/main/java/com/todoroo/astrid/actfm/TagViewFragment.java @@ -17,7 +17,6 @@ import com.todoroo.astrid.activity.TaskListFragment; import com.todoroo.astrid.api.AstridApiConstants; import com.todoroo.astrid.api.Filter; import com.todoroo.astrid.api.TagFilter; -import com.todoroo.astrid.core.BuiltInFilterExposer; import com.todoroo.astrid.dao.TagDataDao; import com.todoroo.astrid.data.TagData; import com.todoroo.astrid.tags.TagFilterExposer; diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java index fb29f3b6f..8cd85c484 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java @@ -53,6 +53,7 @@ import org.tasks.preferences.DefaultFilterProvider; import org.tasks.preferences.Preferences; import org.tasks.receivers.RepeatConfirmationReceiver; import org.tasks.themes.Theme; +import org.tasks.themes.ThemeCache; import org.tasks.ui.EmptyTaskEditFragment; import org.tasks.ui.NavigationDrawerFragment; import org.tasks.ui.PriorityControlSet; @@ -62,6 +63,8 @@ import java.util.List; import javax.inject.Inject; +import butterknife.BindView; +import butterknife.ButterKnife; import timber.log.Timber; import static com.todoroo.astrid.activity.TaskEditFragment.newTaskEditFragment; @@ -89,6 +92,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements @Inject TagDataDao tagDataDao; @Inject Theme theme; @Inject Broadcaster broadcaster; + @Inject ThemeCache themeCache; + + @BindView(R.id.drawer_layout) DrawerLayout drawerLayout; public static final int REQUEST_UPGRADE = 505; @@ -114,8 +120,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements setContentView(R.layout.task_list_activity); + ButterKnife.bind(this); + navigationDrawer = getNavigationDrawerFragment(); - DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); navigationDrawer.setUp(drawerLayout); handleIntent(); @@ -180,7 +187,13 @@ public class TaskListActivity extends InjectingAppCompatActivity implements .replace(isDoublePaneLayout() ? R.id.master_dual : R.id.single_pane, taskListFragment, TaskListFragment.TAG_TASKLIST_FRAGMENT) .addToBackStack(TaskListFragment.TAG_TASKLIST_FRAGMENT) .commit(); - theme.applyTaskDescription(this, taskListFragment.filter.listingTitle); + 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 taskEditControlFragments) { diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java index 918f7cdcd..f9d1160f7 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListFragment.java @@ -73,14 +73,15 @@ import com.todoroo.astrid.voice.VoiceInputAssistant; import org.tasks.Broadcaster; import org.tasks.R; -import org.tasks.dialogs.SortDialog; import org.tasks.dialogs.DialogBuilder; +import org.tasks.dialogs.SortDialog; import org.tasks.injection.ForActivity; import org.tasks.injection.FragmentComponent; 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; @@ -150,6 +151,7 @@ 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; @@ -175,6 +177,10 @@ 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) { @@ -263,6 +269,8 @@ 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++) { diff --git a/src/main/java/org/tasks/themes/Theme.java b/src/main/java/org/tasks/themes/Theme.java index 712e6e414..70e4c8ef0 100644 --- a/src/main/java/org/tasks/themes/Theme.java +++ b/src/main/java/org/tasks/themes/Theme.java @@ -30,6 +30,10 @@ public class Theme { return themeBase; } + public ThemeColor getThemeColor() { + return themeColor; + } + public int getDialogStyle() { return themeBase.getDialogStyle(); } @@ -46,7 +50,7 @@ public class Theme { public void applyThemeAndStatusBarColor(Activity activity) { applyTheme(activity); - applyStatusBarColor(activity); + themeColor.applyStatusBarColor(activity); applyTaskDescription(activity, activity.getString(R.string.app_name)); } @@ -56,12 +60,6 @@ public class Theme { activity.getWindow().setFormat(PixelFormat.RGBA_8888); } - private void applyStatusBarColor(Activity activity) { - if (atLeastLollipop()) { - activity.getWindow().setStatusBarColor(themeColor.getColorPrimaryDark()); - } - } - public void applyTaskDescription(Activity activity, String description) { if (atLeastLollipop()) { activity.setTaskDescription(new ActivityManager.TaskDescription(description, null, themeColor.getPrimaryColor())); diff --git a/src/main/java/org/tasks/themes/ThemeColor.java b/src/main/java/org/tasks/themes/ThemeColor.java index ad3a23bf9..979084735 100644 --- a/src/main/java/org/tasks/themes/ThemeColor.java +++ b/src/main/java/org/tasks/themes/ThemeColor.java @@ -1,6 +1,12 @@ package org.tasks.themes; +import android.app.Activity; +import android.support.v4.widget.DrawerLayout; + import org.tasks.R; +import org.tasks.ui.NavigationDrawerFragment; + +import static com.todoroo.andlib.utility.AndroidUtilities.atLeastLollipop; public class ThemeColor { @@ -41,6 +47,18 @@ public class ThemeColor { this.colorPrimaryDark = colorPrimaryDark; } + public void applyStatusBarColor(Activity activity) { + if (atLeastLollipop()) { + activity.getWindow().setStatusBarColor(getColorPrimaryDark()); + } + } + + public void applyStatusBarColor(DrawerLayout drawerLayout) { + if (atLeastLollipop()) { + drawerLayout.setStatusBarBackgroundColor(getColorPrimaryDark()); + } + } + public String getName() { return name; }