From 0ecafb9c9419df4d99d01be4c1d1705fb8f96132 Mon Sep 17 00:00:00 2001
From: Janne Koschinski <janne@kuschku.de>
Date: Sat, 20 Feb 2016 12:33:16 +0100
Subject: [PATCH] Fixed the drawer issues

---
 .../chat/BufferViewConfigSpinnerAdapter.java  |   7 ++--
 .../quasseldroid_ng/ui/chat/MainActivity.java |   6 ++--
 .../chat/drawer/BufferViewConfigAdapter.java  |  31 ++++++++++------
 .../main/res/drawable-hdpi/ic_plus_dark.png   | Bin 0 -> 253 bytes
 .../main/res/drawable-mdpi/ic_plus_dark.png   | Bin 0 -> 171 bytes
 .../main/res/drawable-xhdpi/ic_plus_dark.png  | Bin 0 -> 209 bytes
 .../main/res/drawable-xxhdpi/ic_plus_dark.png | Bin 0 -> 268 bytes
 .../res/drawable-xxxhdpi/ic_plus_dark.png     | Bin 0 -> 313 bytes
 .../main/res/layout-w720dp/activity_main.xml  |   4 ++-
 app/src/main/res/layout/activity_main.xml     |   4 ++-
 .../res/layout/widget_md_spinner_item.xml     |  30 ++++++++++++++++
 app/src/main/res/menu/chat.xml                |  13 ++++---
 app/src/main/res/menu/chatlist.xml            |  34 ++++++++++++++++++
 app/src/main/res/values/attrs.xml             |   1 +
 app/src/main/res/values/styles.xml            |   4 ++-
 15 files changed, 111 insertions(+), 23 deletions(-)
 create mode 100644 app/src/main/res/drawable-hdpi/ic_plus_dark.png
 create mode 100644 app/src/main/res/drawable-mdpi/ic_plus_dark.png
 create mode 100644 app/src/main/res/drawable-xhdpi/ic_plus_dark.png
 create mode 100644 app/src/main/res/drawable-xxhdpi/ic_plus_dark.png
 create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_plus_dark.png
 create mode 100644 app/src/main/res/layout/widget_md_spinner_item.xml
 create mode 100644 app/src/main/res/menu/chatlist.xml

diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/BufferViewConfigSpinnerAdapter.java b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/BufferViewConfigSpinnerAdapter.java
index 7a1eda952..1a2dad4de 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/BufferViewConfigSpinnerAdapter.java
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/BufferViewConfigSpinnerAdapter.java
@@ -36,6 +36,7 @@ import java.util.Set;
 
 import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewConfig;
 import de.kuschku.libquassel.syncables.types.interfaces.QBufferViewManager;
+import de.kuschku.quasseldroid_ng.R;
 import de.kuschku.quasseldroid_ng.ui.theme.AppContext;
 
 public class BufferViewConfigSpinnerAdapter implements ThemedSpinnerAdapter {
@@ -65,7 +66,7 @@ public class BufferViewConfigSpinnerAdapter implements ThemedSpinnerAdapter {
     @Override
     public View getDropDownView(int position, View convertView, ViewGroup parent) {
         LayoutInflater inflater = LayoutInflater.from(new ContextThemeWrapper(parent.getContext(), theme));
-        TextView view = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
+        TextView view = (TextView) inflater.inflate(R.layout.widget_md_spinner_item, parent, false);
         view.setText(((QBufferViewConfig) getItem(position)).bufferViewName());
         return view;
     }
@@ -102,8 +103,8 @@ public class BufferViewConfigSpinnerAdapter implements ThemedSpinnerAdapter {
 
     @Override
     public View getView(int position, View convertView, ViewGroup parent) {
-        LayoutInflater inflater = LayoutInflater.from(new ContextThemeWrapper(parent.getContext(), theme));
-        TextView view = (TextView) inflater.inflate(android.R.layout.simple_list_item_1, parent, false);
+        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
+        TextView view = (TextView) inflater.inflate(R.layout.widget_md_spinner_item, parent, false);
         view.setText(((QBufferViewConfig) getItem(position)).bufferViewName());
         return view;
     }
diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MainActivity.java b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MainActivity.java
index 4295df4a8..fb0caa1bf 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MainActivity.java
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/MainActivity.java
@@ -138,10 +138,13 @@ public class MainActivity extends BoundActivity {
                     drawerLayout.closeDrawer(GravityCompat.START);
             }
         });
+        chatListAdapter.setRecyclerView(chatList);
         chatList.setItemAnimator(new DefaultItemAnimator());
         chatList.setLayoutManager(new LinearLayoutManager(this));
         chatList.setAdapter(chatListAdapter);
 
+        chatListToolbar.inflateMenu(R.menu.chatlist);
+
         DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
         if (drawerLayout != null) {
             ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.material_drawer_open, R.string.material_drawer_close);
@@ -317,14 +320,13 @@ public class MainActivity extends BoundActivity {
         if (thread == null)
             connectToServer(manager.account(context.settings().lastAccount.get()));
         else {
-            if (context.client() != null) {
+            if (context.client() != null && context.client().connectionStatus() == ConnectionChangeEvent.Status.CONNECTED) {
                 onConnected();
             }
         }
     }
 
     private void onConnected() {
-        context.client().backlogManager().init("", context.provider(), context.client());
         context.client().backlogManager().open(status.bufferId);
         if (context.client().bufferViewManager() != null) {
             chatListSpinner.setAdapter(new BufferViewConfigSpinnerAdapter(context, context.client().bufferViewManager()));
diff --git a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/drawer/BufferViewConfigAdapter.java b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/drawer/BufferViewConfigAdapter.java
index 2d1983fa4..507f53d34 100644
--- a/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/drawer/BufferViewConfigAdapter.java
+++ b/app/src/main/java/de/kuschku/quasseldroid_ng/ui/chat/drawer/BufferViewConfigAdapter.java
@@ -21,6 +21,8 @@
 
 package de.kuschku.quasseldroid_ng.ui.chat.drawer;
 
+import android.os.Parcelable;
+import android.support.annotation.Nullable;
 import android.support.v7.widget.LinearLayoutManager;
 import android.support.v7.widget.RecyclerView;
 import android.view.LayoutInflater;
@@ -180,14 +182,7 @@ public class BufferViewConfigAdapter extends ExpandableRecyclerAdapter<NetworkVi
 
     public void selectConfig(int id) {
         QBufferViewConfig newconfig = context.client().bufferViewManager().bufferViewConfig(id);
-        int firstVisible = -1;
-        if (newconfig == config) {
-            RecyclerView list = recyclerView.get();
-            if (list != null) {
-                LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
-                firstVisible = layoutManager.findFirstVisibleItemPosition();
-            }
-        }
+        Parcelable state = (newconfig == config) ? saveState() : null;
 
         if (config != null)
             config.networkList().removeCallback(callback);
@@ -201,15 +196,31 @@ public class BufferViewConfigAdapter extends ExpandableRecyclerAdapter<NetworkVi
             items.add(networkItem);
         }
         config.networkList().addCallback(callback);
-        if (firstVisible != -1) {
+
+        loadState(state);
+    }
+
+    private void loadState(@Nullable Parcelable state) {
+        if (state != null) {
             RecyclerView list = recyclerView.get();
             if (list != null) {
                 LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
-                layoutManager.scrollToPosition(firstVisible);
+                layoutManager.onRestoreInstanceState(state);
             }
         }
     }
 
+    @Nullable
+    private Parcelable saveState() {
+        RecyclerView list = recyclerView.get();
+        if (list != null) {
+            LinearLayoutManager layoutManager = (LinearLayoutManager) list.getLayoutManager();
+            return layoutManager.onSaveInstanceState();
+        } else {
+            return null;
+        }
+    }
+
     public void setSelection(int from, int to) {
 
     }
diff --git a/app/src/main/res/drawable-hdpi/ic_plus_dark.png b/app/src/main/res/drawable-hdpi/ic_plus_dark.png
new file mode 100644
index 0000000000000000000000000000000000000000..e5565772a094e4554dde22234f3831e96fd08d34
GIT binary patch
literal 253
zcmeAS@N?(olHy`uVBq!ia0vp^Dj>|k1|%Oc%$NbB*pj^6U4S$Y{B+)352QE?JR*yM
zv<Dcwoy@ia36>Q&rUPlPeufHm>3$%m!_&nvB;xSfX@Oh~20YHj9|L}Wj;Lb(81e6I
z*hlvQzB@-WQ)hfPkMi<TlvHT>A-S%M!IMAX#{7ep+h^su6g@f^W4+$^u3M9eM-$JB
z;-g2ttm}9^?@7dq`n-9aFZa4$v$<_0*}#yX`DM-~9*37Q_tWNX@@ZPb>Jjj{$?I4}
j`wg31`yWmnVmBFlB07$J*!<%G&`k`Uu6{1-oD!M<{@Gg6

literal 0
HcmV?d00001

diff --git a/app/src/main/res/drawable-mdpi/ic_plus_dark.png b/app/src/main/res/drawable-mdpi/ic_plus_dark.png
new file mode 100644
index 0000000000000000000000000000000000000000..36a5b40fcfb623a5984401c29614b32b0bc7f374
GIT binary patch
literal 171
zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjY)RhkE<hRxemd{22U45`9+AaB
z+5?Q;PG;MI1j`B>(}6TtKSPDj(q%x7nWu|mh{y5d1PRu~43dA^nS#C;T)Y*ySd3>6
zYtIc9PhZV~!xEB)XBO||_h4H5GvP{8pg|BLLt>W*$F$de-9Qr<JYD@<);T3K0RTd`
BEIj}K

literal 0
HcmV?d00001

diff --git a/app/src/main/res/drawable-xhdpi/ic_plus_dark.png b/app/src/main/res/drawable-xhdpi/ic_plus_dark.png
new file mode 100644
index 0000000000000000000000000000000000000000..265017dceb955b9ac5d463e48d4487d7377536bc
GIT binary patch
literal 209
zcmeAS@N?(olHy`uVBq!ia0vp^1|ZDA1|-9oezpTCwj^(N7a$D;Kb?2i11Zh|kH}&m
z?E%JaC$sH9f@KAc=|CE+pW)oQo^T*1#?!?yB;(%O>l=9wDDb#C&iPwj_G-x@!}!2=
zYzJ&E&e+P(FlUz4j@`cvS7fDJGZii9YA|8UWV*z%gwx~pJ^y>V&;B@SR=)iF{)PsV
i|BY}dVFrdjH+iot<}te}RW=W34}+(xpUXO@geCxv=tFt{

literal 0
HcmV?d00001

diff --git a/app/src/main/res/drawable-xxhdpi/ic_plus_dark.png b/app/src/main/res/drawable-xxhdpi/ic_plus_dark.png
new file mode 100644
index 0000000000000000000000000000000000000000..567bbf6b823afa49119054e3e75cec0307d553cb
GIT binary patch
literal 268
zcmeAS@N?(olHy`uVBq!ia0vp^9w5xY1|&n@ZgvM!Y)RhkE<hRxemd{22U45`9+AaB
z8myGT?PRtcNU*HHF&!>=uJQvbkTc!W#WAGf*4vvKc@G;1upC_e`~A$U1IO67G;SM<
z%82#MGX^SRuuq*UXJEYf`@Q_*YfEeHzy8v&Tv&rcgoTTVwXw;;ae+dB04jG!>BiqB
zoHetor+ezdWDb3-UoQDSDc%=TIg)OWb^o6-?Gok*GA_H>4dQyb`njxgN@xNApomLX

literal 0
HcmV?d00001

diff --git a/app/src/main/res/drawable-xxxhdpi/ic_plus_dark.png b/app/src/main/res/drawable-xxxhdpi/ic_plus_dark.png
new file mode 100644
index 0000000000000000000000000000000000000000..5213a1faefba04c467a0c8b71c2a1bc9d0350237
GIT binary patch
literal 313
zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoY)RhkE<hRxemd{22U45`9+AaB
z+5?Q;PG;MI1j`B>(}8pX7+2iB`31;0;_2cTQgQ3;?Sq_$4Fnh*PyYR`Q!XGJ5b@+p
zNWt+%_cM8bia_9A)-~pu?6q6%^h}-yTE~86`0v*+gTat7iRlPS2d99rf|`R5UV+<n
z&Yw%R7w@`T?jDD#)cV!5I-dW`H}LC6w*lfT1_t{g=B7%XymfEI13*Hau6{1-oD!M<
D6qi_Z

literal 0
HcmV?d00001

diff --git a/app/src/main/res/layout-w720dp/activity_main.xml b/app/src/main/res/layout-w720dp/activity_main.xml
index 5f40523c2..e4836f906 100644
--- a/app/src/main/res/layout-w720dp/activity_main.xml
+++ b/app/src/main/res/layout-w720dp/activity_main.xml
@@ -52,7 +52,9 @@
                 <android.support.v7.widget.AppCompatSpinner
                     android:id="@+id/chatListSpinner"
                     android:layout_width="fill_parent"
-                    android:layout_height="match_parent" />
+                    android:layout_height="match_parent"
+                    android:theme="@style/AppTheme.AppBarOverlay"
+                    app:popupTheme="@style/AppTheme.PopupOverlay" />
 
             </android.support.v7.widget.Toolbar>
 
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 6d6116907..cd3cc62ad 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -71,7 +71,9 @@
                     <android.support.v7.widget.AppCompatSpinner
                         android:id="@+id/chatListSpinner"
                         android:layout_width="fill_parent"
-                        android:layout_height="match_parent" />
+                        android:layout_height="match_parent"
+                        android:theme="@style/AppTheme.AppBarOverlay"
+                        app:popupTheme="@style/AppTheme.PopupOverlay" />
 
                 </android.support.v7.widget.Toolbar>
 
diff --git a/app/src/main/res/layout/widget_md_spinner_item.xml b/app/src/main/res/layout/widget_md_spinner_item.xml
new file mode 100644
index 000000000..0a057aeef
--- /dev/null
+++ b/app/src/main/res/layout/widget_md_spinner_item.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ 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/>.
+  -->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+    android:id="@android:id/text1"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:gravity="center_vertical"
+    android:minHeight="?attr/actionBarSize"
+    android:paddingLeft="16dp"
+    android:paddingRight="16dp"
+    android:textAppearance="?android:attr/textAppearanceListItemSmall" />
diff --git a/app/src/main/res/menu/chat.xml b/app/src/main/res/menu/chat.xml
index 5b232764c..026d4bd0e 100644
--- a/app/src/main/res/menu/chat.xml
+++ b/app/src/main/res/menu/chat.xml
@@ -22,14 +22,17 @@
 
 <menu xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:app="http://schemas.android.com/apk/res-auto">
-    <item
-        android:id="@+id/action_reauth"
-        android:title="Reauth"
-        app:showAsAction="ifRoom" />
     <item
         android:id="@+id/action_hide_events"
         android:icon="@drawable/ic_filter_dark"
-        android:orderInCategory="100"
         android:title="@string/labelHideEvents"
         app:showAsAction="ifRoom" />
+    <item
+        android:id="@+id/action_settings"
+        android:title="Settings"
+        app:showAsAction="never" />
+    <item
+        android:id="@+id/action_reauth"
+        android:title="Disconnect"
+        app:showAsAction="never" />
 </menu>
diff --git a/app/src/main/res/menu/chatlist.xml b/app/src/main/res/menu/chatlist.xml
new file mode 100644
index 000000000..6011afc63
--- /dev/null
+++ b/app/src/main/res/menu/chatlist.xml
@@ -0,0 +1,34 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ 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/>.
+  -->
+
+<menu xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto">
+    <item
+        android:icon="@drawable/ic_plus_dark"
+        android:title="Join Channel"
+        app:showAsAction="ifRoom" />
+    <item
+        android:title="Show/Hide Hidden"
+        app:showAsAction="never" />
+    <item
+        android:title="Manage Chat Lists"
+        app:showAsAction="never" />
+</menu>
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
index 89b556f2f..2cf6d8c07 100644
--- a/app/src/main/res/values/attrs.xml
+++ b/app/src/main/res/values/attrs.xml
@@ -91,6 +91,7 @@
     <attr name="iconFilter" format="reference" />
     <attr name="iconDelete" format="reference" />
     <attr name="iconModify" format="reference" />
+    <attr name="iconAdd" format="reference" />
 
     <attr name="cardStyle" format="reference" />
 </resources>
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 2af2ed3c4..c516e4a73 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -48,6 +48,7 @@
         <item name="iconFilter">@drawable/ic_filter_dark</item>
         <item name="iconModify">@drawable/ic_pencil_dark</item>
         <item name="iconDelete">@drawable/ic_delete_dark</item>
+        <item name="iconAdd">@drawable/ic_plus_dark</item>
 
         <item name="cardStyle">@style/CardView.Dark</item>
     </style>
@@ -76,6 +77,7 @@
         <item name="iconFilter">@drawable/ic_filter_light</item>
         <item name="iconModify">@drawable/ic_pencil_light</item>
         <item name="iconDelete">@drawable/ic_delete_light</item>
+        <item name="iconAdd">@drawable/ic_plus_light</item>
 
         <item name="cardStyle">@style/CardView.Light</item>
     </style>
@@ -97,5 +99,5 @@
 
     <style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
 
-    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Dark" />
+    <style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
 </resources>
-- 
GitLab