From 409a6dac0134ab0e7b74317254cc69aded9c38d2 Mon Sep 17 00:00:00 2001 From: Moez Bhatti Date: Sun, 18 Oct 2015 22:21:45 -0400 Subject: [PATCH] Fixed issue #201 --- .../moez/QKSMS/common/LiveViewManager.java | 2 ++ .../java/com/moez/QKSMS/ui/MainActivity.java | 21 ++++++++++++++++--- .../com/moez/QKSMS/ui/base/QKFragment.java | 16 +++++++++++++- .../QKSMS/ui/view/StarredContactsView.java | 1 + .../ui/welcome/WelcomeNightFragment.java | 5 +++++ 5 files changed, 41 insertions(+), 4 deletions(-) diff --git a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java index a83ce839..927a58a5 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/common/LiveViewManager.java @@ -81,6 +81,8 @@ public class LiveViewManager implements SharedPreferences.OnSharedPreferenceChan /** * Register a LiveView to be notified when this preference is updated. + * Note that you must first register the view, otherwise #refresh() will + * not be called on it * * @param v * @param pref diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java index 7243cbb9..7dfee17d 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/MainActivity.java @@ -28,12 +28,14 @@ import com.google.android.mms.pdu_alt.PduHeaders; import com.moez.QKSMS.R; import com.moez.QKSMS.common.ConversationPrefsHelper; import com.moez.QKSMS.common.DonationManager; +import com.moez.QKSMS.common.LiveViewManager; import com.moez.QKSMS.common.QKRateSnack; import com.moez.QKSMS.common.google.DraftCache; import com.moez.QKSMS.common.utils.KeyboardUtils; import com.moez.QKSMS.common.utils.MessageUtils; import com.moez.QKSMS.common.utils.Units; import com.moez.QKSMS.data.Conversation; +import com.moez.QKSMS.interfaces.LiveView; import com.moez.QKSMS.mmssms.Utils; import com.moez.QKSMS.receiver.IconColorReceiver; import com.moez.QKSMS.transaction.NotificationManager; @@ -57,7 +59,7 @@ import java.net.URLDecoder; import java.util.Collection; public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListener, SlidingMenu.OnCloseListener, - SlidingMenu.OnOpenedListener, SlidingMenu.OnClosedListener { + SlidingMenu.OnOpenedListener, SlidingMenu.OnClosedListener, LiveView { private final String TAG = "MainActivity"; @@ -113,6 +115,9 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen showDialogIfNeeded(savedInstanceState); + LiveViewManager.registerView(this); + LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); + //Adds a small/non intrusive snackbar that asks the user to rate the app SnackEngage.from(this).withSnack(new QKRateSnack().withDuration(BaseSnack.DURATION_LONG)) .build().engageWhenAppropriate(); @@ -205,7 +210,7 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen private void launchWelcomeActivity() { if (mPrefs.getBoolean(SettingsFragment.WELCOME_SEEN, false)) { // User has already seen the welcome screen - return; + // return; } Intent welcomeIntent = new Intent(this, WelcomeActivity.class); @@ -625,7 +630,8 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen * @param hasLockedMessages whether the thread(s) contain locked messages * @param context used to load the various UI elements */ - public static void confirmDeleteThreadDialog(final DeleteThreadListener listener, Collection threadIds, boolean hasLockedMessages, Context context) { + public static void confirmDeleteThreadDialog(final DeleteThreadListener listener, Collection threadIds, + boolean hasLockedMessages, Context context) { View contents = View.inflate(context, R.layout.dialog_delete_thread, null); android.widget.TextView msg = (android.widget.TextView) contents.findViewById(R.id.message); @@ -661,6 +667,15 @@ public class MainActivity extends QKActivity implements SlidingMenu.OnOpenListen .show(); } + @Override + public void refresh() { + // Update the background color. This code is important during the welcome screen setup, when the activity + // in the ThemeManager isn't the MainActivity + findViewById(R.id.menu_frame).getRootView().setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.menu_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + findViewById(R.id.content_frame).setBackgroundColor(ThemeManager.getBackgroundColor()); + } + public static class DeleteThreadListener implements DialogInterface.OnClickListener { private final Collection mThreadIds; private final Conversation.ConversationQueryHandler mHandler; diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java index e1d1fbb7..47cb81e8 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/base/QKFragment.java @@ -3,9 +3,13 @@ package com.moez.QKSMS.ui.base; import android.app.Fragment; import android.os.Bundle; import com.moez.QKSMS.QKSMSApp; +import com.moez.QKSMS.common.LiveViewManager; +import com.moez.QKSMS.interfaces.LiveView; +import com.moez.QKSMS.ui.ThemeManager; +import com.moez.QKSMS.ui.settings.SettingsFragment; import com.squareup.leakcanary.RefWatcher; -public class QKFragment extends Fragment { +public class QKFragment extends Fragment implements LiveView { protected QKActivity mContext; @@ -13,6 +17,9 @@ public class QKFragment extends Fragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mContext = (QKActivity) getActivity(); + + LiveViewManager.registerView(this); + LiveViewManager.registerPreference(this, SettingsFragment.BACKGROUND); } @Override @@ -21,4 +28,11 @@ public class QKFragment extends Fragment { RefWatcher refWatcher = QKSMSApp.getRefWatcher(getActivity()); refWatcher.watch(this); } + + @Override + public void refresh() { + if (getView() != null) { + getView().setBackgroundColor(ThemeManager.getBackgroundColor()); + } + } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java index c8ca9ca2..4c0fd0b4 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/view/StarredContactsView.java @@ -177,5 +177,6 @@ public class StarredContactsView extends LinearLayout implements LoaderManager.L @Override public void refresh() { mIndicator.setColorFilter(ThemeManager.getTextOnBackgroundSecondary(), PorterDuff.Mode.MULTIPLY); + mFavoritesBackground.setBackgroundColor(ThemeManager.getBackgroundColor()); } } diff --git a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java index d5ebe11c..81a43332 100644 --- a/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java +++ b/QKSMS/src/main/java/com/moez/QKSMS/ui/welcome/WelcomeNightFragment.java @@ -92,4 +92,9 @@ public class WelcomeNightFragment extends BaseWelcomeFragment implements BaseWel .commit(); } } + + @Override + public void refresh() { + // Don't let the super class change the background, since we'll handle animations here + } }