package fr.neamar.kiss;

import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.preference.PreferenceManager;
import android.view.Window;
import android.view.WindowManager;

/**
 * Created by neamar on 19/03/17.
 */

public class UiTweaks {
    static void updateThemePrimaryColor(Activity activity) {
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity);
        String primaryColorOverride = prefs.getString("primary-color", "");

        // Circuit breaker, keep default behavior.
        if (primaryColorOverride.isEmpty()) {
            return;
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            int mainColor = Color.parseColor(primaryColorOverride);
            Window window = activity.getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

            // Update status bar color
            window.setStatusBarColor(mainColor);

        }
    }
}

@@ -18,16 +18,46 @@
 .kiss;%0A%0A
+import android.app.ActionBar;%0A
 import a
@@ -77,16 +77,16 @@
 tivity;%0A
-
 import a
@@ -150,16 +150,64 @@
 .Color;%0A
+import android.graphics.drawable.ColorDrawable;%0A
 import a
@@ -756,16 +756,85 @@
      %7D%0A%0A
+        int primaryColor = Color.parseColor(primaryColorOverride);%0A%0A%0A
         
@@ -898,76 +898,8 @@
 ) %7B%0A
-            int mainColor = Color.parseColor(primaryColorOverride);%0A
     
@@ -1199,21 +1199,199 @@
 lor(
-mainColor
+primaryColor);%0A        %7D%0A%0A        ActionBar actionBar = activity.getActionBar();%0A        if(actionBar != null) %7B%0A            actionBar.setBackgroundDrawable(new ColorDrawable(primaryColor)
 );%0A
-%0A
     

Update actionbar color in settings