Browse Source

More work on UI

Signed-off-by: Mario Danic <mario@lovelyhq.com>
Mario Danic 7 years ago
parent
commit
efb79eb70b

+ 101 - 0
app/src/main/java/com/nextcloud/talk/adapters/items/NewCallHeaderItem.java

@@ -0,0 +1,101 @@
+/*
+ * 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/>.
+ */
+
+package com.nextcloud.talk.adapters.items;
+
+import android.view.View;
+import android.widget.RelativeLayout;
+
+import com.nextcloud.talk.R;
+
+import java.util.List;
+
+import butterknife.BindView;
+import butterknife.ButterKnife;
+import eu.davidea.flexibleadapter.FlexibleAdapter;
+import eu.davidea.flexibleadapter.items.AbstractHeaderItem;
+import eu.davidea.flexibleadapter.items.IHeader;
+import eu.davidea.viewholders.FlexibleViewHolder;
+
+public class NewCallHeaderItem extends AbstractHeaderItem<NewCallHeaderItem.HeaderViewHolder>
+        implements IHeader<NewCallHeaderItem.HeaderViewHolder> {
+    private static final String TAG = "NewCallHeaderItem";
+
+    HeaderViewHolder headerViewHolder;
+
+    public NewCallHeaderItem() {
+        super();
+        setSelectable(true);
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        return false;
+    }
+
+    @Override
+    public int getLayoutRes() {
+        return R.layout.rv_item_call_header;
+    }
+
+    @Override
+    public HeaderViewHolder createViewHolder(View view, FlexibleAdapter adapter) {
+        headerViewHolder = new HeaderViewHolder(view, adapter);
+        return headerViewHolder;
+    }
+
+    @Override
+    public void bindViewHolder(FlexibleAdapter adapter, HeaderViewHolder holder, int position, List<Object> payloads) {
+        headerViewHolder = holder;
+
+        if (holder.secondaryRelativeLayout.getVisibility() == View.GONE && adapter.isSelected(position)) {
+            togglePublicCall(true);
+        } else if (holder.initialRelativeLayout.getVisibility() == View.GONE && !adapter.isSelected(position)) {
+            togglePublicCall(false);
+        }
+    }
+
+    public void togglePublicCall(boolean showDescription) {
+        if (!showDescription) {
+            headerViewHolder.secondaryRelativeLayout.setVisibility(View.GONE);
+            headerViewHolder.initialRelativeLayout.setVisibility(View.VISIBLE);
+        } else {
+            headerViewHolder.initialRelativeLayout.setVisibility(View.GONE);
+            headerViewHolder.secondaryRelativeLayout.setVisibility(View.VISIBLE);
+        }
+    }
+
+    static class HeaderViewHolder extends FlexibleViewHolder {
+
+        @BindView(R.id.initial_relative_layout)
+        public RelativeLayout initialRelativeLayout;
+
+        @BindView(R.id.secondary_relative_layout)
+        public RelativeLayout secondaryRelativeLayout;
+
+        /**
+         * Default constructor.
+         */
+        HeaderViewHolder(View view, FlexibleAdapter adapter) {
+            super(view, adapter, true);
+            ButterKnife.bind(this, view);
+        }
+    }
+}

+ 4 - 0
app/src/main/java/com/nextcloud/talk/adapters/items/UserItem.java

@@ -110,6 +110,10 @@ public class UserItem extends AbstractFlexibleItem<UserItem.UserItemViewHolder>
 
         flipView = holder.avatarFlipView;
 
+        if (adapter.isSelected(position) && !flipView.isFlipped()) {
+            flipItemSelection();
+        }
+
         if (adapter.hasSearchText()) {
             FlexibleUtils.highlightText(holder.contactDisplayName, participant.getName(), adapter.getSearchText());
         } else {

+ 31 - 7
app/src/main/java/com/nextcloud/talk/controllers/ContactsController.java

@@ -53,6 +53,7 @@ import com.bluelinelabs.conductor.internal.NoOpControllerChangeHandler;
 import com.nextcloud.talk.R;
 import com.nextcloud.talk.activities.CallActivity;
 import com.nextcloud.talk.adapters.items.EmptyFooterItem;
+import com.nextcloud.talk.adapters.items.NewCallHeaderItem;
 import com.nextcloud.talk.adapters.items.UserHeaderItem;
 import com.nextcloud.talk.adapters.items.UserItem;
 import com.nextcloud.talk.api.NcApi;
@@ -139,6 +140,7 @@ public class ContactsController extends BaseController implements SearchView.OnQ
     private String searchQuery;
 
     private boolean isNewConversationView;
+    private boolean isPublicCall;
 
     private HashMap<String, UserHeaderItem> userHeaderItems = new HashMap<String, UserHeaderItem>();
 
@@ -163,8 +165,12 @@ public class ContactsController extends BaseController implements SearchView.OnQ
     @Override
     protected void onAttach(@NonNull View view) {
         super.onAttach(view);
-        if (getActionBar() != null && isNewConversationView) {
-            getActionBar().setDisplayHomeAsUpEnabled(true);
+        if (isNewConversationView) {
+            checkAndHandleBottomButtons();
+
+            if (getActionBar() != null) {
+                getActionBar().setDisplayHomeAsUpEnabled(true);
+            }
         }
     }
 
@@ -212,10 +218,12 @@ public class ContactsController extends BaseController implements SearchView.OnQ
         if (adapter != null) {
             List<Integer> selectedPositions = adapter.getSelectedPositions();
             for (Integer position : selectedPositions) {
-                UserItem userItem = (UserItem) adapter.getItem(position);
-                adapter.toggleSelection(position);
-                if (userItem != null) {
-                    userItem.flipItemSelection();
+                if (adapter.getItem(position) instanceof UserItem) {
+                    UserItem userItem = (UserItem) adapter.getItem(position);
+                    adapter.toggleSelection(position);
+                    if (userItem != null) {
+                        userItem.flipItemSelection();
+                    }
                 }
             }
         }
@@ -389,10 +397,15 @@ public class ContactsController extends BaseController implements SearchView.OnQ
                                     return firstName.compareToIgnoreCase(secondName);
                                 });
 
+                                if (isNewConversationView) {
+                                    contactItems.add(0, new NewCallHeaderItem());
+                                }
+
                                 adapter.updateDataSet(contactItems, true);
                                 searchItem.setVisible(contactItems.size() > 0);
                                 swipeRefreshLayout.setRefreshing(false);
 
+
                                 if (isNewConversationView) {
                                     checkAndHandleBottomButtons();
                                 }
@@ -569,16 +582,27 @@ public class ContactsController extends BaseController implements SearchView.OnQ
 
                 checkAndHandleBottomButtons();
             }
+        } else if (adapter.getItem(position) instanceof NewCallHeaderItem) {
+            adapter.toggleSelection(position);
+            isPublicCall = adapter.isSelected(position);
+            ((NewCallHeaderItem)adapter.getItem(position)).togglePublicCall(isPublicCall);
+            checkAndHandleBottomButtons();
         }
         return true;
     }
 
     private void checkAndHandleBottomButtons() {
         if (adapter != null && bottomButtonsLinearLayout != null && clearButton != null) {
-            if (adapter.getSelectedItemCount() > 0) {
+            if (adapter.getSelectedItemCount() > 0 || isPublicCall) {
                 if (bottomButtonsLinearLayout.getVisibility() != View.VISIBLE) {
                     bottomButtonsLinearLayout.setVisibility(View.VISIBLE);
                 }
+
+                if (isPublicCall && adapter.getSelectedItemCount() < 2) {
+                    clearButton.setVisibility(View.GONE);
+                } else {
+                    clearButton.setVisibility(View.VISIBLE);
+                }
             } else {
                 bottomButtonsLinearLayout.setVisibility(View.GONE);
             }

+ 1 - 0
app/src/main/java/com/nextcloud/talk/utils/bundle/BundleKeys.java

@@ -37,4 +37,5 @@ public class BundleKeys {
     public static final String KEY_ROOM_TOKEN = "KEY_ROOM_TOKEN";
     public static final String KEY_USER_ENTITY = "KEY_USER_ENTITY";
     public static final String KEY_NEW_CONVERSATION = "KEY_NEW_CONVERSATION";
+    public static final String KEY_IS_PUBLIC_CALL = "KEY_IS_PUBLIC_CALL";
 }

+ 25 - 0
app/src/main/res/drawable/ic_group_black_24px.xml

@@ -0,0 +1,25 @@
+<!--
+  ~ 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 android:autoMirrored="true" android:height="24dp"
+    android:viewportHeight="16.0" android:viewportWidth="16.0"
+    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
+    <path android:fillColor="#FF000000" android:pathData="m9.236,2.166 l-3.182,3.184c-0.707,0.707 -1.038,1.618 -0.988,2.457 0.05,0.839 0.433,1.584 0.988,2.139l1.412,-1.416c-0.567,-0.567 -0.544,-1.219 0.002,-1.766l3.181,-3.182c0.525,-0.525 1.251,-0.523 1.772,-0.002 0.482,0.556 0.527,1.238 -0.004,1.77l-0.82,0.82c0.555,0.785 0.645,1.366 0.593,2.234l1.641,-1.641c1.237,-1.237 1.237,-3.365 0,-4.602 -1.236,-1.236 -3.342,-1.211 -4.596,0.004zM9.943,6.051 L8.529,7.469c0,0 0.003,0 0.004,0 0.55,0.55 0.507,1.258 -0.004,1.77l-3.182,3.182c-0.696,0.592 -1.298,0.471 -1.77,0 -0.626,-0.626 -0.5,-1.268 0,-1.768l0.85,-0.847c-0.556,-0.784 -0.648,-1.365 -0.598,-2.232l-1.666,1.666c-1.239,1.239 -1.236,3.36 0,4.596 1.235,1.235 3.362,1.236 4.598,0l3.182,-3.182c0.709,-0.708 1.04,-1.618 0.991,-2.459 -0.048,-0.84 -0.432,-1.586 -0.989,-2.141z"/>
+</vector>

+ 78 - 0
app/src/main/res/layout/rv_item_call_header.xml

@@ -0,0 +1,78 @@
+<?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/>.
+  -->
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+                xmlns:tools="http://schemas.android.com/tools"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:orientation="vertical">
+
+    <RelativeLayout
+        android:id="@+id/initial_relative_layout"
+        android:layout_width="match_parent"
+        android:layout_height="72dp">
+
+        <ImageView
+            android:id="@+id/public_call_link"
+            android:layout_width="40dp"
+            android:layout_height="40dp"
+            android:layout_centerVertical="true"
+            android:layout_marginStart="24dp"
+            android:src="@drawable/ic_group_black_24px"/>
+
+        <TextView
+            android:id="@+id/description_text"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_centerVertical="true"
+            android:layout_marginEnd="24dp"
+            android:layout_marginStart="8dp"
+            android:layout_toEndOf="@id/public_call_link"
+            android:ellipsize="middle"
+            android:singleLine="true"
+            android:text="@string/nc_public_call"
+            android:textAppearance="?android:attr/textAppearanceListItem"
+            tools:text="@string/nc_public_call"/>
+
+    </RelativeLayout>
+
+    <RelativeLayout
+        android:id="@+id/secondary_relative_layout"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:minHeight="72dp"
+        android:visibility="gone">
+
+        <TextView
+            android:id="@+id/public_explanation_text_View"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_centerInParent="true"
+            android:layout_marginEnd="24dp"
+            android:layout_marginStart="24dp"
+            android:text="@string/nc_public_call_explanation"
+            android:textAlignment="center"
+            android:textAppearance="?android:attr/textAppearanceListItem"
+            tools:text="@string/nc_public_call_explanation"/>
+
+    </RelativeLayout>
+</RelativeLayout>

+ 3 - 0
app/src/main/res/values/strings.xml

@@ -102,6 +102,9 @@
     <!-- Call -->
     <string name="nc_incoming_call">Incoming call</string>
     <string name="nc_nick_guest">Guest</string>
+    <string name="nc_public_call">NEW PUBLIC CALL</string>
+    <string name="nc_public_call_explanation">Public calls let you invite people from outside through a specially
+        crafted link.</string>
 
     <!-- Notification channels -->
     <string name="nc_notification_channel">%1$s on %2$s notification channel</string>