From c4969faa4fb224463c16cdd099866813273b242f Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Thu, 8 Sep 2016 13:11:07 +0200
Subject: [PATCH] Fixed some minor UI issues

---
 .../quasseldroid_ng/ui/settings/Settings.java |   9 +-
 .../preferences/MaterialListPreference.java   | 194 +++++++++++++++++-
 .../MaterialListSummaryPreference.java        |  66 ++++++
 .../kuschku/util/ui/preferences/PrefUtil.java |  95 +++++++++
 .../main/res/layout-w720dp/activity_main.xml  |   1 -
 .../res/layout/activity_channel_detail.xml    |   1 -
 .../res/layout/activity_chatlist_edit.xml     |   1 -
 .../res/layout/activity_chatlist_list.xml     |   1 -
 .../res/layout/activity_identity_edit.xml     |   1 -
 app/src/main/res/layout/activity_main.xml     |   4 +-
 .../main/res/layout/activity_network_edit.xml |   1 -
 .../main/res/layout/activity_network_list.xml |   1 -
 .../layout/activity_networkserver_edit.xml    |   1 -
 .../main/res/layout/activity_nick_list.xml    |   1 -
 app/src/main/res/layout/activity_settings.xml |   1 -
 app/src/main/res/values/attrs.xml             |   1 +
 app/src/main/res/values/colors.xml            |   3 +
 app/src/main/res/values/themes.xml            |  16 +-
 app/src/main/res/xml/pref_appearance.xml      |   2 +-
 19 files changed, 369 insertions(+), 31 deletions(-)
 create mode 100644 app/src/main/java/de/kuschku/util/ui/preferences/MaterialListSummaryPreference.java
 create mode 100644 app/src/main/java/de/kuschku/util/ui/preferences/PrefUtil.java

diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/Settings.java b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/Settings.java
index 67a60e18b..d4257e0c4 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/Settings.java
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/settings/Settings.java
@@ -40,6 +40,9 @@ public class Settings {
     public final BooleanPreference preferenceLag;
     public final IntPreference preferenceFontSize;
 
+
+    private final SharedPreferences.OnSharedPreferenceChangeListener onSharedPreferenceChangeListener;
+
     public Settings(PreferenceStrings prefs, SharedPreferences pref) {
         this.preferenceLastAccount = new StringPreference(pref, prefs.preferenceLastAccount, "");
 
@@ -50,7 +53,7 @@ public class Settings {
         this.preferenceLag = new BooleanPreference(pref, prefs.preferenceLag, false);
         this.preferenceFontSize = new IntPreference(pref, prefs.preferenceFontSize, 14);
 
-        pref.registerOnSharedPreferenceChangeListener((preferences, key) -> {
+        onSharedPreferenceChangeListener = (preferences, key) -> {
             if (prefs.preferenceLastAccount.equals(key)) preferenceLastAccount.change();
 
             if (prefs.preferenceTheme.equals(key)) preferenceTheme.change();
@@ -59,7 +62,9 @@ public class Settings {
             if (prefs.preferenceHostmask.equals(key)) preferenceHostmask.change();
             if (prefs.preferenceLag.equals(key)) preferenceLag.change();
             if (prefs.preferenceFontSize.equals(key)) preferenceFontSize.change();
-        });
+        };
+
+        pref.registerOnSharedPreferenceChangeListener(onSharedPreferenceChangeListener);
     }
 
     public Settings(Context ctx) {
diff --git a/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListPreference.java b/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListPreference.java
index 8df813bdc..eda511cd0 100644
--- a/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListPreference.java
+++ b/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListPreference.java
@@ -21,40 +21,212 @@
 
 package de.kuschku.util.ui.preferences;
 
+import android.annotation.TargetApi;
+import android.app.Dialog;
 import android.content.Context;
+import android.content.DialogInterface;
+import android.os.Build;
+import android.os.Bundle;
+import android.os.Parcel;
+import android.os.Parcelable;
+import android.preference.ListPreference;
+import android.support.annotation.NonNull;
 import android.util.AttributeSet;
 import android.view.View;
+import android.widget.ListView;
+
+import com.afollestad.materialdialogs.MaterialDialog;
+
+import java.lang.reflect.Field;
+
+import de.kuschku.util.annotationbind.AutoBinder;
+
+/**
+ * @author Marc Holder Kluver (marchold), Aidan Follestad (afollestad)
+ */
+public class MaterialListPreference extends ListPreference {
+
+    private Context context;
+    private MaterialDialog mDialog;
 
-public class MaterialListPreference extends com.afollestad.materialdialogs.prefs.MaterialListPreference {
     public MaterialListPreference(Context context) {
         super(context);
-        setSummary(getEntry());
+        init(context, null);
     }
 
     public MaterialListPreference(Context context, AttributeSet attrs) {
         super(context, attrs);
-        setSummary(getEntry());
+        init(context, attrs);
     }
 
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     public MaterialListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
         super(context, attrs, defStyleAttr);
-        setSummary(getEntry());
+        init(context, attrs);
     }
 
+    @TargetApi(Build.VERSION_CODES.LOLLIPOP)
     public MaterialListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
         super(context, attrs, defStyleAttr, defStyleRes);
-        setSummary(getEntry());
+        init(context, attrs);
+    }
+
+    private void init(Context context, AttributeSet attrs) {
+        this.context = context;
+        PrefUtil.setLayoutResource(context, this, attrs);
+        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1)
+            setWidgetLayoutResource(0);
     }
 
     @Override
-    protected void onDialogClosed(boolean positiveResult) {
-        super.onDialogClosed(positiveResult);
-        setSummary(getEntry());
+    public void setEntries(CharSequence[] entries) {
+        super.setEntries(entries);
+        if (mDialog != null)
+            mDialog.setItems(entries);
     }
 
     @Override
-    protected void onBindView(View view) {
-        setSummary(getEntry());
-        super.onBindView(view);
+    public Dialog getDialog() {
+        return mDialog;
+    }
+
+    public ListView getListView() {
+        if (getDialog() == null) return null;
+        return ((MaterialDialog) getDialog()).getListView();
+    }
+
+    @Override
+    protected void showDialog(Bundle state) {
+        if (getEntries() == null || getEntryValues() == null) {
+            throw new IllegalStateException(
+                    "ListPreference requires an entries array and an entryValues array.");
+        }
+
+        int preselect = findIndexOfValue(getValue());
+        MaterialDialog.Builder builder = new MaterialDialog.Builder(context)
+                .title(getDialogTitle())
+                .icon(getDialogIcon())
+                .dismissListener(this)
+                .onAny((dialog, which) -> {
+                    switch (which) {
+                        default:
+                            MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
+                            break;
+                        case NEUTRAL:
+                            MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
+                            break;
+                        case NEGATIVE:
+                            MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
+                            break;
+                    }
+                })
+                .backgroundColor(AutoBinder.obtainColor(de.kuschku.quasseldroid_ng.R.attr.colorBackgroundDialog, context.getTheme()))
+                .negativeText(getNegativeButtonText())
+                .items(getEntries())
+                .autoDismiss(true) // immediately close the dialog after selection
+                .itemsCallbackSingleChoice(preselect, (dialog, itemView, which, text) -> {
+                    onClick(null, DialogInterface.BUTTON_POSITIVE);
+                    if (which >= 0 && getEntryValues() != null) {
+                        try {
+                            Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
+                            clickedIndex.setAccessible(true);
+                            clickedIndex.set(MaterialListPreference.this, which);
+                        } catch (Exception e) {
+                            e.printStackTrace();
+                        }
+                    }
+                    return true;
+                });
+
+        final View contentView = onCreateDialogView();
+        if (contentView != null) {
+            onBindDialogView(contentView);
+            builder.customView(contentView, false);
+        } else {
+            builder.content(getDialogMessage());
+        }
+
+        PrefUtil.registerOnActivityDestroyListener(this, this);
+
+        mDialog = builder.build();
+        if (state != null)
+            mDialog.onRestoreInstanceState(state);
+        onClick(mDialog, DialogInterface.BUTTON_NEGATIVE);
+        mDialog.show();
+    }
+
+    @Override
+    public void onDismiss(DialogInterface dialog) {
+        super.onDismiss(dialog);
+        PrefUtil.unregisterOnActivityDestroyListener(this, this);
+    }
+
+    @Override
+    public void onActivityDestroy() {
+        super.onActivityDestroy();
+        if (mDialog != null && mDialog.isShowing())
+            mDialog.dismiss();
+    }
+
+    @Override
+    protected Parcelable onSaveInstanceState() {
+        final Parcelable superState = super.onSaveInstanceState();
+        Dialog dialog = getDialog();
+        if (dialog == null || !dialog.isShowing()) {
+            return superState;
+        }
+
+        final SavedState myState = new SavedState(superState);
+        myState.isDialogShowing = true;
+        myState.dialogBundle = dialog.onSaveInstanceState();
+        return myState;
+    }
+
+    @Override
+    protected void onRestoreInstanceState(Parcelable state) {
+        if (state == null || !state.getClass().equals(SavedState.class)) {
+            // Didn't save state for us in onSaveInstanceState
+            super.onRestoreInstanceState(state);
+            return;
+        }
+
+        SavedState myState = (SavedState) state;
+        super.onRestoreInstanceState(myState.getSuperState());
+        if (myState.isDialogShowing) {
+            showDialog(myState.dialogBundle);
+        }
+    }
+
+    // From DialogPreference
+    private static class SavedState extends BaseSavedState {
+        public static final Parcelable.Creator<SavedState> CREATOR =
+                new Parcelable.Creator<SavedState>() {
+                    public SavedState createFromParcel(Parcel in) {
+                        return new SavedState(in);
+                    }
+
+                    public SavedState[] newArray(int size) {
+                        return new SavedState[size];
+                    }
+                };
+        boolean isDialogShowing;
+        Bundle dialogBundle;
+
+        public SavedState(Parcel source) {
+            super(source);
+            isDialogShowing = source.readInt() == 1;
+            dialogBundle = source.readBundle();
+        }
+
+        public SavedState(Parcelable superState) {
+            super(superState);
+        }
+
+        @Override
+        public void writeToParcel(@NonNull Parcel dest, int flags) {
+            super.writeToParcel(dest, flags);
+            dest.writeInt(isDialogShowing ? 1 : 0);
+            dest.writeBundle(dialogBundle);
+        }
     }
 }
diff --git a/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListSummaryPreference.java b/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListSummaryPreference.java
new file mode 100644
index 000000000..ea2049323
--- /dev/null
+++ b/app/src/main/java/de/kuschku/util/ui/preferences/MaterialListSummaryPreference.java
@@ -0,0 +1,66 @@
+/*
+ * QuasselDroid - Quassel client for Android
+ * Copyright (C) 2016 Janne Koschinski
+ * Copyright (C) 2016 Ken Børge Viktil
+ * Copyright (C) 2016 Magnus Fjell
+ * Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package de.kuschku.util.ui.preferences;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.util.AttributeSet;
+import android.view.View;
+
+public class MaterialListSummaryPreference extends MaterialListPreference {
+    public MaterialListSummaryPreference(Context context) {
+        super(context);
+        setSummary(getEntry());
+    }
+
+    public MaterialListSummaryPreference(Context context, AttributeSet attrs) {
+        super(context, attrs);
+        setSummary(getEntry());
+    }
+
+    public MaterialListSummaryPreference(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        setSummary(getEntry());
+    }
+
+    public MaterialListSummaryPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+        super(context, attrs, defStyleAttr, defStyleRes);
+        setSummary(getEntry());
+    }
+
+    @Override
+    protected void onDialogClosed(boolean positiveResult) {
+        super.onDialogClosed(positiveResult);
+        setSummary(getEntry());
+    }
+
+    @Override
+    protected void showDialog(Bundle state) {
+        super.showDialog(state);
+    }
+
+    @Override
+    protected void onBindView(View view) {
+        setSummary(getEntry());
+        super.onBindView(view);
+    }
+}
diff --git a/app/src/main/java/de/kuschku/util/ui/preferences/PrefUtil.java b/app/src/main/java/de/kuschku/util/ui/preferences/PrefUtil.java
new file mode 100644
index 000000000..4ec183d58
--- /dev/null
+++ b/app/src/main/java/de/kuschku/util/ui/preferences/PrefUtil.java
@@ -0,0 +1,95 @@
+/*
+ * QuasselDroid - Quassel client for Android
+ * Copyright (C) 2016 Janne Koschinski
+ * Copyright (C) 2016 Ken Børge Viktil
+ * Copyright (C) 2016 Magnus Fjell
+ * Copyright (C) 2016 Martin Sandsmark <martin.sandsmark@kde.org>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the Free
+ * Software Foundation, either version 3 of the License, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package de.kuschku.util.ui.preferences;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.content.res.XmlResourceParser;
+import android.preference.Preference;
+import android.preference.PreferenceManager;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.util.AttributeSet;
+
+import com.afollestad.materialdialogs.commons.R;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author Aidan Follestad (afollestad)
+ */
+class PrefUtil {
+
+    private PrefUtil() {
+    }
+
+    public static void setLayoutResource(@NonNull Context context, @NonNull Preference preference, @Nullable AttributeSet attrs) {
+        boolean foundLayout = false;
+        if (attrs != null) {
+            for (int i = 0; i < attrs.getAttributeCount(); i++) {
+                final String namespace = ((XmlResourceParser) attrs).getAttributeNamespace(0);
+                if (namespace.equals("http://schemas.android.com/apk/res/android") &&
+                        attrs.getAttributeName(i).equals("layout")) {
+                    foundLayout = true;
+                    break;
+                }
+            }
+        }
+
+        boolean useStockLayout = false;
+        if (attrs != null) {
+            TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.Preference, 0, 0);
+            try {
+                useStockLayout = a.getBoolean(R.styleable.Preference_useStockLayout, false);
+            } finally {
+                a.recycle();
+            }
+        }
+
+        if (!foundLayout && !useStockLayout)
+            preference.setLayoutResource(R.layout.md_preference_custom);
+    }
+
+    public static void registerOnActivityDestroyListener(@NonNull Preference preference, @NonNull PreferenceManager.OnActivityDestroyListener listener) {
+        try {
+            PreferenceManager pm = preference.getPreferenceManager();
+            Method method = pm.getClass().getDeclaredMethod(
+                    "registerOnActivityDestroyListener",
+                    PreferenceManager.OnActivityDestroyListener.class);
+            method.setAccessible(true);
+            method.invoke(pm, listener);
+        } catch (Exception ignored) {
+        }
+    }
+
+    public static void unregisterOnActivityDestroyListener(@NonNull Preference preference, @NonNull PreferenceManager.OnActivityDestroyListener listener) {
+        try {
+            PreferenceManager pm = preference.getPreferenceManager();
+            Method method = pm.getClass().getDeclaredMethod(
+                    "unregisterOnActivityDestroyListener",
+                    PreferenceManager.OnActivityDestroyListener.class);
+            method.setAccessible(true);
+            method.invoke(pm, listener);
+        } catch (Exception ignored) {
+        }
+    }
+}
diff --git a/app/src/main/res/layout-w720dp/activity_main.xml b/app/src/main/res/layout-w720dp/activity_main.xml
index 0ee2c2c72..8c95f4d18 100644
--- a/app/src/main/res/layout-w720dp/activity_main.xml
+++ b/app/src/main/res/layout-w720dp/activity_main.xml
@@ -26,7 +26,6 @@
     xmlns:tools="http://schemas.android.com/tools"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="horizontal"
     tools:context=".ui.chat.MainActivity">
 
diff --git a/app/src/main/res/layout/activity_channel_detail.xml b/app/src/main/res/layout/activity_channel_detail.xml
index 19eabf0f7..a6d7d64a8 100644
--- a/app/src/main/res/layout/activity_channel_detail.xml
+++ b/app/src/main/res/layout/activity_channel_detail.xml
@@ -22,7 +22,6 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_chatlist_edit.xml b/app/src/main/res/layout/activity_chatlist_edit.xml
index 877ee28bc..6609355e6 100644
--- a/app/src/main/res/layout/activity_chatlist_edit.xml
+++ b/app/src/main/res/layout/activity_chatlist_edit.xml
@@ -26,7 +26,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_chatlist_list.xml b/app/src/main/res/layout/activity_chatlist_list.xml
index 7069ca753..71d52eb61 100644
--- a/app/src/main/res/layout/activity_chatlist_list.xml
+++ b/app/src/main/res/layout/activity_chatlist_list.xml
@@ -25,7 +25,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_identity_edit.xml b/app/src/main/res/layout/activity_identity_edit.xml
index b67fd114f..47c030253 100644
--- a/app/src/main/res/layout/activity_identity_edit.xml
+++ b/app/src/main/res/layout/activity_identity_edit.xml
@@ -25,7 +25,6 @@
     xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 3332bf0ee..867045ed9 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -27,7 +27,6 @@
     android:id="@+id/drawer_layout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     tools:context=".ui.chat.MainActivity">
 
     <LinearLayout
@@ -47,8 +46,7 @@
     <android.support.design.widget.NavigationView
         android:layout_width="match_parent"
         android:layout_height="match_parent"
-        android:layout_gravity="start"
-        android:background="?attr/colorBackground">
+        android:layout_gravity="start">
 
         <LinearLayout
             android:layout_width="match_parent"
diff --git a/app/src/main/res/layout/activity_network_edit.xml b/app/src/main/res/layout/activity_network_edit.xml
index 865a75d5c..3b18b1c7d 100644
--- a/app/src/main/res/layout/activity_network_edit.xml
+++ b/app/src/main/res/layout/activity_network_edit.xml
@@ -26,7 +26,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_network_list.xml b/app/src/main/res/layout/activity_network_list.xml
index 3c90be389..7f3dcc699 100644
--- a/app/src/main/res/layout/activity_network_list.xml
+++ b/app/src/main/res/layout/activity_network_list.xml
@@ -25,7 +25,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_networkserver_edit.xml b/app/src/main/res/layout/activity_networkserver_edit.xml
index 75d871f89..63110f65c 100644
--- a/app/src/main/res/layout/activity_networkserver_edit.xml
+++ b/app/src/main/res/layout/activity_networkserver_edit.xml
@@ -26,7 +26,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_nick_list.xml b/app/src/main/res/layout/activity_nick_list.xml
index 3c90be389..7f3dcc699 100644
--- a/app/src/main/res/layout/activity_nick_list.xml
+++ b/app/src/main/res/layout/activity_nick_list.xml
@@ -25,7 +25,6 @@
     xmlns:app="http://schemas.android.com/apk/res-auto"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout
diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml
index f91e54994..e56a9a985 100644
--- a/app/src/main/res/layout/activity_settings.xml
+++ b/app/src/main/res/layout/activity_settings.xml
@@ -22,7 +22,6 @@
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:layout_width="match_parent"
     android:layout_height="match_parent"
-    android:background="?attr/colorBackground"
     android:orientation="vertical">
 
     <android.support.design.widget.AppBarLayout xmlns:android="http://schemas.android.com/apk/res/android"
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index 7aa77ac95..8eb1673ab 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -76,6 +76,7 @@
     <attr name="colorBackgroundHighlight" format="color" />
     <attr name="colorBackgroundSecondary" format="color" />
     <attr name="colorBackgroundCard" format="color" />
+    <attr name="colorBackgroundDialog" format="color"/>
 
     <!-- Tint colors for drawer -->
 
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index d877d19e9..c7ba1a8aa 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -34,4 +34,7 @@
 
     <color name="colorAwayLight">#959595</color>
     <color name="colorAwayDark">#939393</color>
+
+    <color name="solarizedLight_background">#FDF6E3</color>
+    <color name="solarizedDark_background">#002B36</color>
 </resources>
diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml
index 393a2286b..f8ef1426d 100644
--- a/app/src/main/res/values/themes.xml
+++ b/app/src/main/res/values/themes.xml
@@ -65,9 +65,11 @@
         <item name="colorForegroundMirc">0x1</item>
 
         <item name="colorBackground">@color/md_light_background</item>
+        <item name="android:windowBackground">@color/md_light_background</item>
         <item name="colorBackgroundHighlight">#ff8811</item>
-        <item name="colorBackgroundSecondary">@android:color/transparent</item>
+        <item name="colorBackgroundSecondary">@null</item>
         <item name="colorBackgroundCard">@color/md_light_cards</item>
+        <item name="colorBackgroundDialog">@color/md_light_background</item>
 
         <item name="colorTintActivity">#88cc33</item>
         <item name="colorTintMessage">#2277dd</item>
@@ -118,9 +120,11 @@
         <item name="colorForegroundMirc">0x0</item>
 
         <item name="colorBackground">@color/md_dark_background</item>
+        <item name="android:windowBackground">@color/md_dark_background</item>
         <item name="colorBackgroundHighlight">#ff8811</item>
-        <item name="colorBackgroundSecondary">@android:color/transparent</item>
+        <item name="colorBackgroundSecondary">@null</item>
         <item name="colorBackgroundCard">@color/md_dark_cards</item>
+        <item name="colorBackgroundDialog">@color/md_dark_background</item>
 
         <item name="colorTintActivity">#88cc33</item>
         <item name="colorTintMessage">#2277dd</item>
@@ -177,9 +181,11 @@
         <item name="colorForegroundMirc">0xF</item>
 
         <item name="colorBackground">#FDF6E3</item>
+        <item name="android:windowBackground">@color/solarizedLight_background</item>
         <item name="colorBackgroundHighlight">#268bd2</item>
-        <item name="colorBackgroundSecondary">#FDF6E3</item>
+        <item name="colorBackgroundSecondary">@null</item>
         <item name="colorBackgroundCard">#EEE8D5</item>
+        <item name="colorBackgroundDialog">#FDF6E3</item>
 
         <item name="colorTintActivity">#88cc33</item>
         <item name="colorTintMessage">#2277dd</item>
@@ -235,9 +241,11 @@
         <item name="colorForegroundMirc">0xF</item>
 
         <item name="colorBackground">#002B36</item>
+        <item name="android:windowBackground">@color/solarizedDark_background</item>
         <item name="colorBackgroundHighlight">#268bd2</item>
-        <item name="colorBackgroundSecondary">#002B36</item>
+        <item name="colorBackgroundSecondary">@null</item>
         <item name="colorBackgroundCard">#073642</item>
+        <item name="colorBackgroundDialog">#002B36</item>
 
         <item name="colorTintActivity">#88cc33</item>
         <item name="colorTintMessage">#2277dd</item>
diff --git a/app/src/main/res/xml/pref_appearance.xml b/app/src/main/res/xml/pref_appearance.xml
index b80318bac..c0b5a5bf4 100644
--- a/app/src/main/res/xml/pref_appearance.xml
+++ b/app/src/main/res/xml/pref_appearance.xml
@@ -21,7 +21,7 @@
 
 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
 
-    <de.kuschku.util.ui.preferences.MaterialListPreference
+    <de.kuschku.util.ui.preferences.MaterialListSummaryPreference
         android:defaultValue="QUASSEL_LIGHT"
         android:entries="@array/preference_theme_entries"
         android:entryValues="@array/preference_theme_values"
-- 
GitLab