Browse Source

Fix #296

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 6 years ago
parent
commit
9a7e8da28c

+ 69 - 27
app/src/main/java/com/nextcloud/talk/controllers/ConversationsListController.java

@@ -43,6 +43,8 @@ import android.view.View;
 import android.view.ViewGroup;
 import android.view.ViewTreeObserver;
 import android.view.inputmethod.EditorInfo;
+import android.widget.ProgressBar;
+import android.widget.RelativeLayout;
 
 import com.bluelinelabs.conductor.RouterTransaction;
 import com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler;
@@ -112,9 +114,15 @@ public class ConversationsListController extends BaseController implements Searc
     @BindView(R.id.recycler_view)
     RecyclerView recyclerView;
 
-    @BindView(R.id.swipe_refresh_layout)
+    @BindView(R.id.swipeRefreshLayoutView)
     SwipeRefreshLayout swipeRefreshLayout;
 
+    @BindView(R.id.progressBar)
+    ProgressBar progressBarView;
+
+    @BindView(R.id.emptyLayout)
+    RelativeLayout emptyLayoutView;
+
     @BindView(R.id.fast_scroller)
     FastScroller fastScroller;
 
@@ -133,6 +141,8 @@ public class ConversationsListController extends BaseController implements Searc
 
     private String credentials;
 
+    private boolean adapterWasNull = true;
+
     public ConversationsListController() {
         super();
         setHasOptionsMenu(true);
@@ -140,7 +150,7 @@ public class ConversationsListController extends BaseController implements Searc
 
     @Override
     protected View inflateView(@NonNull LayoutInflater inflater, @NonNull ViewGroup container) {
-        return inflater.inflate(R.layout.controller_generic_rv, container, false);
+        return inflater.inflate(R.layout.controller_conversations_rv, container, false);
     }
 
     @Override
@@ -152,9 +162,10 @@ public class ConversationsListController extends BaseController implements Searc
             getActionBar().show();
         }
 
-
         if (adapter == null) {
             adapter = new FlexibleAdapter<>(callItems, getActivity(), false);
+        } else {
+            progressBarView.setVisibility(View.GONE);
         }
 
         adapter.addListener(this);
@@ -279,37 +290,58 @@ public class ConversationsListController extends BaseController implements Searc
                 .observeOn(AndroidSchedulers.mainThread())
                 .subscribe(roomsOverall -> {
 
-                    if (roomsOverall != null) {
-                        for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
-                            if (shouldUseLastMessageLayout) {
-                                callItems.add(new ConversationItem(roomsOverall.getOcs().getData().get(i),
-                                        currentUser));
-                            } else {
-                                callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), currentUser));
-                            }
+                    if (adapterWasNull) {
+                        adapterWasNull = false;
+                        progressBarView.setVisibility(View.GONE);
+                    }
+
+                    if (roomsOverall.getOcs().getData().size() > 0) {
+                        if (emptyLayoutView.getVisibility() != View.GONE) {
+                            emptyLayoutView.setVisibility(View.GONE);
                         }
 
+                        if (swipeRefreshLayout.getVisibility() != View.VISIBLE) {
+                            swipeRefreshLayout.setVisibility(View.VISIBLE);
+                        }
+                    } else {
+                        if (emptyLayoutView.getVisibility() != View.VISIBLE) {
+                            emptyLayoutView.setVisibility(View.VISIBLE);
+                        }
+
+                        if (swipeRefreshLayout.getVisibility() != View.GONE) {
+                            swipeRefreshLayout.setVisibility(View.GONE);
+                        }
+                    }
 
-                        if (currentUser.hasSpreedCapabilityWithName("last-room-activity")) {
-                            Collections.sort(callItems, (o1, o2) -> {
-                                Conversation conversation1 = ((ConversationItem) o1).getModel();
-                                Conversation conversation2 = ((ConversationItem) o2).getModel();
-                                return new CompareToBuilder()
-                                        .append(conversation2.isFavorite(), conversation1.isFavorite())
-                                        .append(conversation2.getLastActivity(), conversation1.getLastActivity())
-                                        .toComparison();
-                            });
+                    for (int i = 0; i < roomsOverall.getOcs().getData().size(); i++) {
+                        if (shouldUseLastMessageLayout) {
+                            callItems.add(new ConversationItem(roomsOverall.getOcs().getData().get(i),
+                                    currentUser));
                         } else {
-                            Collections.sort(callItems, (callItem, t1) ->
-                                    Long.compare(((CallItem) t1).getModel().getLastPing(),
-                                            ((CallItem) callItem).getModel().getLastPing()));
+                            callItems.add(new CallItem(roomsOverall.getOcs().getData().get(i), currentUser));
                         }
+                    }
 
-                        adapter.updateDataSet(callItems, true);
 
-                        if (searchItem != null) {
-                            searchItem.setVisible(callItems.size() > 0);
-                        }
+                    if (currentUser.hasSpreedCapabilityWithName("last-room-activity")) {
+                        Collections.sort(callItems, (o1, o2) -> {
+                            Conversation conversation1 = ((ConversationItem) o1).getModel();
+                            Conversation conversation2 = ((ConversationItem) o2).getModel();
+                            return new CompareToBuilder()
+                                    .append(conversation2.isFavorite(), conversation1.isFavorite())
+                                    .append(conversation2.getLastActivity(), conversation1.getLastActivity())
+                                    .toComparison();
+                        });
+                    } else {
+                        Collections.sort(callItems, (callItem, t1) ->
+                                Long.compare(((CallItem) t1).getModel().getLastPing(),
+                                        ((CallItem) callItem).getModel().getLastPing()));
+                    }
+
+                    adapter.updateDataSet(callItems, true);
+
+                    if (searchItem != null) {
+                        searchItem.setVisible(callItems.size() > 0);
                     }
 
                     if (swipeRefreshLayout != null) {
@@ -377,6 +409,16 @@ public class ConversationsListController extends BaseController implements Searc
         swipeRefreshLayout.setOnRefreshListener(() -> fetchData(false));
         swipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
 
+        emptyLayoutView.setOnClickListener(new View.OnClickListener() {
+            @Override
+            public void onClick(View v) {
+                if (getParentController() != null && getParentController().getView() != null) {
+                    ((BottomNavigationView) getParentController().getView().findViewById(R.id.navigation))
+                            .setSelectedItemId(R.id.navigation_contacts);
+                }
+            }
+        });
+
         fastScroller.addOnScrollStateChangeListener(this);
         adapter.setFastScroller(fastScroller);
         fastScroller.setBubbleTextCreator(position -> {

+ 37 - 0
app/src/main/res/drawable/ic_logo_blue.xml

@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ 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/>.
+  -->
+
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+    android:width="24dp"
+    android:height="24dp"
+    android:viewportWidth="24"
+    android:viewportHeight="24">
+
+    <path
+        android:fillColor="#0082C9"
+        android:strokeWidth="0.14"
+        android:pathData="M7.9992,0.999 A6.9994,6.9993,0,0,0,1,7.9986 A6.9994,6.9993,0,0,0,7.9992,14.998
+A6.9994,6.9993,0,0,0,11.63,13.974 C12.4902,14.3158,14.4171,15.33,14.8757,14.8919
+C15.3549,14.4343,14.3131,12.2803,14.0633,11.4799
+A6.9994,6.9993,0,0,0,14.9983,7.9985 A6.9994,6.9993,0,0,0,7.9992,0.9992 Z
+M8,3.6601 A4.3401,4.34,0,0,1,12.34,8.0002 A4.3401,4.34,0,0,1,8,12.34
+A4.3401,4.34,0,0,1,3.66,8.0002 A4.3401,4.34,0,0,1,8,3.6601 Z" />
+</vector>

+ 87 - 0
app/src/main/res/layout/controller_conversations_rv.xml

@@ -0,0 +1,87 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud Talk application
+  ~
+  ~ @author Mario Danic
+  ~ Copyright (C) 2017-2018 Mario Danic <mario@lovelyhq.com>
+  ~
+  ~ 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/>.
+  -->
+
+<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                                                 xmlns:tools="http://schemas.android.com/tools"
+                                                 android:id="@+id/generic_rv_layout"
+                                                 android:layout_width="match_parent"
+                                                 android:layout_height="match_parent"
+                                                 android:background="@color/nc_white_color">
+
+    <ProgressBar
+        android:id="@+id/progressBar"
+        android:layout_width="@dimen/item_height"
+        android:layout_height="@dimen/item_height"
+        android:layout_gravity="center"
+        android:layout_marginEnd="@dimen/activity_horizontal_margin"
+        android:layout_marginLeft="@dimen/activity_horizontal_margin"
+        android:layout_marginRight="@dimen/activity_horizontal_margin"
+        android:layout_marginStart="@dimen/activity_horizontal_margin"
+        android:indeterminate="true"
+        android:indeterminateTint="@color/colorPrimary"
+        android:indeterminateTintMode="src_in"/>
+
+    <RelativeLayout
+        android:id="@+id/emptyLayout"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone">
+
+        <ImageView
+            android:id="@+id/noConversationsImageView"
+            android:layout_width="72dp"
+            android:layout_height="72dp"
+            android:layout_centerInParent="true"
+            android:background="@drawable/ic_logo_blue"/>
+
+        <TextView
+            android:id="@+id/sendHiTextView"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_below="@+id/noConversationsImageView"
+            android:layout_margin="8dp"
+            android:text="@string/nc_conversations_empty"
+            android:textAlignment="center"
+            android:textSize="20sp"/>
+    </RelativeLayout>
+
+    <android.support.v4.widget.SwipeRefreshLayout
+        android:id="@+id/swipeRefreshLayoutView"
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:visibility="gone">
+
+        <FrameLayout
+            android:layout_width="match_parent"
+            android:layout_height="match_parent">
+
+            <android.support.v7.widget.RecyclerView
+                android:id="@+id/recycler_view"
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                tools:listitem="@layout/rv_item_conversation"/>
+
+        </FrameLayout>
+
+    </android.support.v4.widget.SwipeRefreshLayout>
+
+    <include layout="@layout/fast_scroller"/>
+</android.support.design.widget.CoordinatorLayout>

+ 2 - 1
app/src/main/res/values/strings.xml

@@ -203,8 +203,9 @@ Find Nextcloud on https://nextcloud.com</string>
     <string name="nc_description_more_menu_group">Menu for public conversation %1$s</string>
     <string name="nc_description_send_message_button">Send message</string>
 
-    <!-- Chat empty state -->
+    <!-- Empty states -->
     <string name="nc_chat_empty">Tap to be the first to say %1$s!</string>
+    <string name="nc_conversations_empty">You haven\'t talked to anyone yet!\n Tap to start a conversation.</string>
     <string name="nc_hello">Hello</string>
 
 </resources>