From c9c2dd6d7a9c3a38856d17e79090af03ebf8de92 Mon Sep 17 00:00:00 2001 From: Alex Baker Date: Sun, 17 Jul 2016 13:39:54 -0500 Subject: [PATCH] More attempts at fixing day/night --- .../astrid/activity/TaskListActivity.java | 17 ++++++++--- .../java/org/tasks/analytics/Tracking.java | 1 + .../ThemedInjectingAppCompatActivity.java | 28 +++++++++++++++++-- src/main/java/org/tasks/themes/Theme.java | 10 +++++-- .../tasks/ui/NavigationDrawerFragment.java | 5 +--- src/main/res/values/keys.xml | 2 ++ 6 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java index 1cdf61dba..a9dd4a92f 100644 --- a/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java +++ b/src/main/java/com/todoroo/astrid/activity/TaskListActivity.java @@ -45,6 +45,8 @@ import com.todoroo.astrid.timers.TimerControlSet; import org.tasks.Broadcaster; import org.tasks.R; +import org.tasks.analytics.Tracker; +import org.tasks.analytics.Tracking; import org.tasks.dialogs.SortDialog; import org.tasks.fragments.CommentBarFragment; import org.tasks.fragments.TaskEditControlSetFragmentManager; @@ -99,6 +101,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements @Inject Broadcaster broadcaster; @Inject ThemeCache themeCache; @Inject SyncAdapterHelper syncAdapterHelper; + @Inject Tracker tracker; @BindView(R.id.drawer_layout) DrawerLayout drawerLayout; @@ -123,8 +126,6 @@ public class TaskListActivity extends InjectingAppCompatActivity implements protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - theme.applyTheme(this, getDelegate()); - currentNightMode = getNightMode(); startupService.onStartupApplication(this); @@ -238,9 +239,9 @@ public class TaskListActivity extends InjectingAppCompatActivity implements protected void onResume() { super.onResume(); - getDelegate().applyDayNight(); if (currentNightMode != getNightMode()) { - recreate(); + tracker.reportEvent(Tracking.Events.NIGHT_MODE_MISMATCH); + restart(); return; } @@ -271,6 +272,13 @@ public class TaskListActivity extends InjectingAppCompatActivity implements } } + public void restart() { + Intent intent = getIntent(); + intent.putExtra(TaskListActivity.OPEN_FILTER, getCurrentFilter()); + finish(); + startActivity(intent); + } + private int getNightMode() { return getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK; } @@ -278,6 +286,7 @@ public class TaskListActivity extends InjectingAppCompatActivity implements @Override public void inject(ActivityComponent component) { component.inject(this); + theme.applyTheme(this); } @Override diff --git a/src/main/java/org/tasks/analytics/Tracking.java b/src/main/java/org/tasks/analytics/Tracking.java index f2b34813c..293044648 100644 --- a/src/main/java/org/tasks/analytics/Tracking.java +++ b/src/main/java/org/tasks/analytics/Tracking.java @@ -17,6 +17,7 @@ public class Tracking { GTASK_DISABLED(R.string.tracking_category_google_tasks, R.string.tracking_action_off), GTASK_LOGOUT(R.string.tracking_category_google_tasks, R.string.tracking_action_clear), GTASK_MOVE(R.string.tracking_category_google_tasks, R.string.tracking_action_move), + NIGHT_MODE_MISMATCH(R.string.tracking_category_event, R.string.tracking_event_night_mode_mismatch), SET_PREFERENCE(R.string.tracking_category_preferences, 0); public final int category; diff --git a/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java b/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java index 1d23ea7f9..1a9f2e546 100644 --- a/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java +++ b/src/main/java/org/tasks/injection/ThemedInjectingAppCompatActivity.java @@ -1,19 +1,43 @@ package org.tasks.injection; import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import org.tasks.analytics.Tracker; +import org.tasks.locale.Locale; import org.tasks.themes.Theme; import javax.inject.Inject; -public abstract class ThemedInjectingAppCompatActivity extends InjectingAppCompatActivity { +public abstract class ThemedInjectingAppCompatActivity extends AppCompatActivity implements InjectingActivity { + private ActivityComponent activityComponent; + @Inject Tracker tracker; @Inject Theme theme; + public ThemedInjectingAppCompatActivity() { + Locale.INSTANCE.applyOverrideConfiguration(this); + } + @Override protected void onCreate(Bundle savedInstanceState) { + activityComponent = ((InjectingApplication) getApplication()).getComponent().plus(new ActivityModule(this)); + inject(activityComponent); + setTitle(null); + theme.applyTheme(this); + theme.applyStatusBarColor(this); super.onCreate(savedInstanceState); + } + + @Override + protected void onResume() { + super.onResume(); + + tracker.showScreen(getClass().getSimpleName()); + } - theme.applyThemeAndStatusBarColor(this, getDelegate()); + @Override + public ActivityComponent getComponent() { + return activityComponent; } } diff --git a/src/main/java/org/tasks/themes/Theme.java b/src/main/java/org/tasks/themes/Theme.java index 182adf657..54c7db8fa 100644 --- a/src/main/java/org/tasks/themes/Theme.java +++ b/src/main/java/org/tasks/themes/Theme.java @@ -45,13 +45,17 @@ public class Theme { } public void applyThemeAndStatusBarColor(Activity activity, AppCompatDelegate delegate) { - applyTheme(activity, delegate); + delegate.applyDayNight(); + applyTheme(activity); + applyStatusBarColor(activity); + } + + public void applyStatusBarColor(Activity activity) { themeColor.applyStatusBarColor(activity); themeColor.applyTaskDescription(activity, activity.getString(R.string.app_name)); } - public void applyTheme(Activity activity, AppCompatDelegate delegate) { - delegate.applyDayNight(); + public void applyTheme(Activity activity) { themeBase.set(activity); applyToContext(activity); activity.getWindow().setFormat(PixelFormat.RGBA_8888); diff --git a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java index c9d4342ba..4842bcf77 100644 --- a/src/main/java/org/tasks/ui/NavigationDrawerFragment.java +++ b/src/main/java/org/tasks/ui/NavigationDrawerFragment.java @@ -93,10 +93,7 @@ public class NavigationDrawerFragment extends InjectingFragment { } if (data.getBooleanExtra(AppearancePreferences.EXTRA_RESTART, false)) { TaskListActivity activity = (TaskListActivity) getActivity(); - Intent intent = activity.getIntent(); - intent.putExtra(TaskListActivity.OPEN_FILTER, activity.getCurrentFilter()); - activity.finish(); - activity.startActivity(intent); + activity.restart(); } } else if ((requestCode == NavigationDrawerFragment.REQUEST_NEW_LIST || requestCode == TaskListFragment.ACTIVITY_REQUEST_NEW_FILTER) && diff --git a/src/main/res/values/keys.xml b/src/main/res/values/keys.xml index 9c2c65249..d006fc07e 100644 --- a/src/main/res/values/keys.xml +++ b/src/main/res/values/keys.xml @@ -286,12 +286,14 @@ Tags IAB Gtask + Event Add Start Move On Off Clear + Night Mismatch tesla_unread_enabled purchased_tesla_unread purchased_tasker