Sfoglia il codice sorgente

Aligned icons + Cleaned code + Implemented listeners

Signed-off-by: Kilian Périsset <kilian.perisset@infomaniak.com>
Kilian Périsset 4 anni fa
parent
commit
01a597d391

+ 29 - 20
src/main/java/com/nextcloud/ui/ChooseAccountFragment.kt → src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt

@@ -1,3 +1,23 @@
+/*
+ * Nextcloud Android client application
+ *
+ * @author Infomaniak Network SA
+ * Copyright (C) 2020 Infomaniak Network SA
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or 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 AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
 package com.nextcloud.ui
 
 import android.graphics.drawable.Drawable
@@ -5,18 +25,12 @@ import android.os.Bundle
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
-import android.widget.FrameLayout
 import android.widget.ImageView
-import android.widget.LinearLayout
-import android.widget.RelativeLayout
 import androidx.core.content.ContextCompat
-import androidx.core.graphics.drawable.DrawableCompat
 import androidx.fragment.app.DialogFragment
-import androidx.recyclerview.widget.LinearLayoutManager
 import com.nextcloud.client.account.User
 import com.nextcloud.client.account.UserAccountManager
 import com.owncloud.android.R
-import com.owncloud.android.lib.common.utils.Log_OC
 import com.owncloud.android.ui.activity.BaseActivity
 import com.owncloud.android.ui.activity.DrawerActivity
 import com.owncloud.android.ui.adapter.UserListAdapter
@@ -24,12 +38,12 @@ import com.owncloud.android.ui.adapter.UserListItem
 import com.owncloud.android.utils.DisplayUtils
 import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
 import kotlinx.android.synthetic.main.account_item.*
-import kotlinx.android.synthetic.main.fragment_choose_account.*
+import kotlinx.android.synthetic.main.dialog_choose_account.*
 import java.util.ArrayList
 
 private const val ARG_CURRENT_USER_PARAM = "currentUser"
 
-class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserListAdapter.ClickListener {
+class ChooseAccountDialogFragment : DialogFragment(), AvatarGenerationListener, UserListAdapter.ClickListener {
     private var currentUser: User? = null
     private lateinit var accountManager: UserAccountManager
 
@@ -55,27 +69,21 @@ class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserLi
             account.text = user.accountName
 
             // Defining user right indicator
-            account_menu.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable
-                .ic_check_circle)?.let { icon -> DrawableCompat.wrap(icon) })
-            val tintedCheck = ContextCompat.getDrawable(requireContext(), R.drawable.account_circle_white)?.let { DrawableCompat.wrap(it) }
+            account_menu.setImageDrawable(ContextCompat.getDrawable(requireContext(), R.drawable.ic_check_circle))
 
             // Creating adapter for accounts list
             val adapter = UserListAdapter(activity as BaseActivity,
                 accountManager,
                 getAccountListItems(),
-                tintedCheck,
+                null,
                 this,
                 false, false)
-            accounts_list.setHasFixedSize(true)
-            accounts_list.layoutManager = LinearLayoutManager(activity)
             accounts_list.adapter = adapter
 
-            /*
             // Creating listeners for quick-actions
-            user_layout.setOnClickListener {
+            current_account.setOnClickListener {
                 dismiss()
             }
-            */
             add_account.setOnClickListener {
                 (activity as DrawerActivity).openAddAccount()
             }
@@ -88,6 +96,7 @@ class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserLi
     private fun getAccountListItems(): List<UserListItem>? {
         val users = accountManager.allUsers
         val adapterUserList: MutableList<UserListItem> = ArrayList(users.size)
+        // Remove the current account from the adapter to display only other accounts
         for (user in users) {
             if (user != currentUser) {
                 adapterUserList.add(UserListItem(user))
@@ -102,7 +111,7 @@ class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserLi
     companion object {
         @JvmStatic
         fun newInstance(user: User) =
-            ChooseAccountFragment().apply {
+            ChooseAccountDialogFragment().apply {
                 arguments = Bundle().apply {
                     putParcelable(ARG_CURRENT_USER_PARAM, user)
                 }
@@ -111,7 +120,7 @@ class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserLi
 
     override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                               savedInstanceState: Bundle?): View? {
-        return inflater.inflate(R.layout.fragment_choose_account, container, false)
+        return inflater.inflate(R.layout.dialog_choose_account, container, false)
     }
 
     override fun shouldCallGeneratedCallback(tag: String?, callContext: Any?): Boolean {
@@ -127,6 +136,6 @@ class ChooseAccountFragment : DialogFragment(), AvatarGenerationListener, UserLi
     }
 
     override fun onOptionItemClicked(user: User?, view: View?) {
-        // Todo : Implement the onOptionItemClicked
+        // Un-needed for this context
     }
 }

+ 3 - 2
src/main/java/com/owncloud/android/ui/activity/DrawerActivity.java

@@ -9,6 +9,7 @@
  * Copyright (C) 2016 Nextcloud
  * Copyright (C) 2016 ownCloud Inc.
  * Copyright (C) 2020 Chris Narkiewicz <hello@ezaquarii.com>
+ * Copyright (C) 2020 Infomaniak Network SA
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -62,7 +63,7 @@ import com.nextcloud.client.onboarding.FirstRunActivity;
 import com.nextcloud.client.preferences.AppPreferences;
 import com.nextcloud.client.preferences.DarkMode;
 import com.nextcloud.java.util.Optional;
-import com.nextcloud.ui.ChooseAccountFragment;
+import com.nextcloud.ui.ChooseAccountDialogFragment;
 import com.owncloud.android.MainApp;
 import com.owncloud.android.R;
 import com.owncloud.android.authentication.PassCodeManager;
@@ -510,7 +511,7 @@ public abstract class DrawerActivity extends ToolbarActivity
     }
 
     public void showManageAccountsDialog() {
-        ChooseAccountFragment choseAccountDialog = ChooseAccountFragment.newInstance(accountManager.getUser());
+        ChooseAccountDialogFragment choseAccountDialog = ChooseAccountDialogFragment.newInstance(accountManager.getUser());
         choseAccountDialog.show(getSupportFragmentManager(), "fragment_chose_account");
     }
 

+ 2 - 4
src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -309,8 +309,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
                                       getUserListItems(),
                                       tintedCheck,
                                       this,
-                                      multipleAccountsSupported, false
-                                  );
+                                      multipleAccountsSupported, false);
                                   recyclerView.setAdapter(userListAdapter);
                                   runOnUiThread(() -> userListAdapter.notifyDataSetChanged());
                               } catch (OperationCanceledException e) {
@@ -362,8 +361,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
                                                       userListItemArray,
                                                       tintedCheck,
                                                       this,
-                                                      multipleAccountsSupported, false
-                );
+                                                      multipleAccountsSupported, false);
                 recyclerView.setAdapter(userListAdapter);
             } else {
                 onBackPressed();

+ 60 - 59
src/main/res/layout/account_item.xml

@@ -1,10 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
+
 <!--
   Nextcloud Android client application
 
   Copyright (C) 2016 Andy Scherzinger
   Copyright (C) 2016 Nextcloud
   Copyright (C) 2016 ownCloud
+  Copyright (C) 2020 Infomaniak Network SA
 
   This program is free software; you can redistribute it and/or
   modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
@@ -19,34 +21,33 @@
   You should have received a copy of the GNU Affero 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"
+
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     xmlns:tools="http://schemas.android.com/tools"
-    android:id="@+id/user_layout"
     android:layout_width="match_parent"
     android:layout_height="@dimen/account_item_layout_height"
+    android:background="?attr/selectableItemBackground"
     android:orientation="horizontal"
-    android:foreground="?attr/selectableItemBackground"
     tools:ignore="UnusedAttribute">
 
     <FrameLayout
         android:id="@+id/avatar_container"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
-        android:layout_centerVertical="true"
-        android:layout_alignParentStart="true">
+        android:layout_alignParentStart="true"
+        android:layout_centerVertical="true">
 
         <ImageView
             android:id="@+id/user_icon"
             android:layout_width="@dimen/user_icon_size"
             android:layout_height="@dimen/user_icon_size"
             android:layout_gravity="top|start"
-            android:layout_marginBottom="@dimen/account_item_layout_user_image_margin"
             android:layout_marginStart="@dimen/account_item_layout_user_image_left_start_margin"
-            android:layout_marginEnd="@dimen/account_item_layout_user_image_margin"
             android:layout_marginTop="@dimen/account_item_layout_user_image_margin"
-            android:src="@drawable/folder"
-            android:contentDescription="@string/avatar"/>
+            android:layout_marginEnd="@dimen/account_item_layout_user_image_margin"
+            android:layout_marginBottom="@dimen/account_item_layout_user_image_margin"
+            android:contentDescription="@string/avatar"
+            android:src="@drawable/folder" />
 
         <ImageView
             android:id="@+id/ticker"
@@ -54,60 +55,60 @@
             android:layout_height="18dp"
             android:layout_gravity="bottom|end"
             android:background="@drawable/round_bgnd"
-            android:src="@drawable/account_circle_white"
-            android:contentDescription="@string/active_user"/>
+            android:contentDescription="@string/active_user"
+            android:src="@drawable/account_circle_white" />
     </FrameLayout>
 
 
-        <LinearLayout
+    <LinearLayout
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_centerInParent="true"
+        android:layout_marginEnd="25dp"
+        android:layout_toEndOf="@id/avatar_container"
+        android:orientation="vertical"
+        android:paddingStart="3dp"
+        android:paddingEnd="@dimen/zero">
+
+        <TextView
+            android:id="@+id/user_name"
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
-            android:layout_centerInParent="true"
-            android:layout_toEndOf="@id/avatar_container"
-            android:orientation="vertical"
-            android:paddingEnd="@dimen/zero"
-            android:layout_marginEnd="25dp"
-            android:paddingStart="3dp">
-
-            <TextView
-                android:id="@+id/user_name"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginEnd="@dimen/standard_double_margin"
-                android:layout_marginStart="@dimen/standard_half_margin"
-                android:layout_marginTop="@dimen/standard_quarter_margin"
-                android:ellipsize="end"
-                android:gravity="bottom"
-                android:maxLines="1"
-                android:text="@string/placeholder_filename"
-                android:textAppearance="?android:attr/textAppearanceListItem"/>
-
-            <TextView
-                android:id="@+id/account"
-                android:layout_width="match_parent"
-                android:layout_height="wrap_content"
-                android:layout_marginBottom="@dimen/standard_quarter_margin"
-                android:layout_marginEnd="@dimen/standard_double_margin"
-                android:layout_marginStart="@dimen/standard_half_margin"
-                android:ellipsize="end"
-                android:gravity="top"
-                android:maxLines="1"
-                android:text="@string/placeholder_sentence"
-                android:textColor="?android:attr/textColorSecondary"/>
-
-        </LinearLayout>
+            android:layout_marginStart="@dimen/standard_half_margin"
+            android:layout_marginTop="@dimen/standard_quarter_margin"
+            android:layout_marginEnd="@dimen/standard_double_margin"
+            android:ellipsize="end"
+            android:gravity="bottom"
+            android:maxLines="1"
+            android:text="@string/placeholder_filename"
+            android:textAppearance="?android:attr/textAppearanceListItem" />
 
-        <ImageView
-            android:id="@+id/account_menu"
-            android:layout_width="wrap_content"
-            android:layout_height="match_parent"
-            android:layout_centerVertical="true"
-            android:layout_alignParentEnd="true"
-            android:clickable="true"
-            android:contentDescription="@string/overflow_menu"
-            android:focusable="true"
-            android:paddingEnd="@dimen/alternate_padding"
-            android:paddingStart="@dimen/standard_half_padding"
-            android:src="@drawable/ic_dots_vertical"/>
+        <TextView
+            android:id="@+id/account"
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_marginStart="@dimen/standard_half_margin"
+            android:layout_marginEnd="@dimen/standard_double_margin"
+            android:layout_marginBottom="@dimen/standard_quarter_margin"
+            android:ellipsize="end"
+            android:gravity="top"
+            android:maxLines="1"
+            android:text="@string/placeholder_sentence"
+            android:textColor="?android:attr/textColorSecondary" />
+
+    </LinearLayout>
+
+    <ImageView
+        android:id="@+id/account_menu"
+        android:layout_width="wrap_content"
+        android:layout_height="match_parent"
+        android:layout_alignParentEnd="true"
+        android:layout_centerVertical="true"
+        android:clickable="true"
+        android:contentDescription="@string/overflow_menu"
+        android:focusable="true"
+        android:paddingStart="@dimen/standard_half_padding"
+        android:paddingEnd="@dimen/alternate_padding"
+        android:src="@drawable/ic_dots_vertical" />
 
 </RelativeLayout>

+ 97 - 0
src/main/res/layout/dialog_choose_account.xml

@@ -0,0 +1,97 @@
+<!--
+  Nextcloud Android client application
+
+  Copyright (C) 2020 Infomaniak Network SA
+
+  This program is free software: you can redistribute it and/or modify
+  it under the terms of the GNU General Public License version 2,
+  as published by the Free Software Foundation.
+
+  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/>.
+-->
+
+<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:orientation="vertical"
+    android:padding="5dp"
+    tools:context="com.nextcloud.ui.ChooseAccountDialogFragment">
+
+    <include
+        android:id="@+id/current_account"
+        layout="@layout/account_item"
+        app:layout_constraintBottom_toTopOf="@id/separator_line"
+        app:layout_constraintStart_toStartOf="parent" />
+
+    <View
+        android:id="@+id/separator_line"
+        android:layout_width="0dp"
+        android:layout_height="1dp"
+        android:background="@color/account_separator"
+        app:layout_constraintBottom_toBottomOf="@+id/current_account"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent" />
+
+    <androidx.recyclerview.widget.RecyclerView
+        android:id="@+id/accounts_list"
+        android:layout_width="0dp"
+        android:layout_height="wrap_content"
+        app:layout_constrainedHeight="true"
+        android:layout_marginBottom="@dimen/account_action_button_vertical_margin"
+        app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
+        app:layout_constraintBottom_toTopOf="@+id/add_account"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent"
+        app:layout_constraintTop_toBottomOf="@+id/separator_line" />
+
+    <com.google.android.material.button.MaterialButton
+        android:id="@+id/add_account"
+        style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
+        android:layout_width="0dp"
+        android:layout_height="@dimen/account_action_button_height"
+        android:layout_marginStart="@dimen/account_action_button_margin"
+        android:layout_marginEnd="@dimen/account_action_button_margin"
+        android:paddingStart="10dp"
+        android:paddingEnd="0dp"
+        android:text="@string/prefs_add_account"
+        android:textAlignment="textStart"
+        android:textAllCaps="false"
+        android:textColor="@color/fontAppbar"
+        app:icon="@drawable/ic_account_plus"
+        app:iconGravity="start"
+        app:iconPadding="22dp"
+        app:iconTint="@color/fontAppbar"
+        app:layout_constraintBottom_toTopOf="@+id/manage_accounts"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent" />
+
+    <com.google.android.material.button.MaterialButton
+        android:id="@+id/manage_accounts"
+        style="@style/Widget.MaterialComponents.Button.TextButton.Icon"
+        android:layout_width="0dp"
+        android:layout_height="@dimen/account_action_button_height"
+        android:layout_marginStart="@dimen/account_action_button_margin"
+        android:layout_marginEnd="@dimen/account_action_button_margin"
+        android:paddingStart="12dp"
+        android:paddingEnd="0dp"
+        android:text="@string/prefs_manage_accounts"
+        android:textAlignment="textStart"
+        android:textAllCaps="false"
+        android:textColor="@color/fontAppbar"
+        app:icon="@drawable/ic_settings"
+        app:iconGravity="start"
+        app:iconPadding="20dp"
+        app:iconTint="@color/fontAppbar"
+        app:layout_constraintBottom_toBottomOf="parent"
+        app:layout_constraintEnd_toEndOf="parent"
+        app:layout_constraintStart_toStartOf="parent" />
+
+</androidx.constraintlayout.widget.ConstraintLayout>

+ 0 - 68
src/main/res/layout/fragment_choose_account.xml

@@ -1,68 +0,0 @@
-<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
-    xmlns:app="http://schemas.android.com/apk/res-auto"
-    xmlns:tools="http://schemas.android.com/tools"
-    android:layout_width="match_parent"
-    android:layout_height="match_parent"
-    android:orientation="vertical"
-    android:padding="5dp"
-    tools:context="com.nextcloud.ui.ChooseAccountFragment">
-
-    <include
-        android:id="@+id/current_account"
-        layout="@layout/account_item"
-        app:layout_constraintBottom_toTopOf="@id/separator_line"
-        app:layout_constraintStart_toStartOf="parent" />
-
-    <View
-        android:id="@+id/separator_line"
-        android:layout_width="0dp"
-        android:layout_height="1dp"
-        android:background="@color/account_separator"
-        app:layout_constraintBottom_toBottomOf="@+id/current_account"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent" />
-
-    <androidx.recyclerview.widget.RecyclerView
-        android:id="@+id/accounts_list"
-        android:layout_width="0dp"
-        android:layout_height="wrap_content"
-        app:layout_constrainedHeight="true"
-        app:layout_constraintBottom_toTopOf="@+id/add_account"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        app:layout_constraintTop_toBottomOf="@+id/separator_line" />
-
-    <TextView
-        android:id="@+id/add_account"
-        android:layout_width="0dp"
-        android:layout_height="40dp"
-        android:drawableStart="@drawable/ic_account_plus"
-        android:drawablePadding="25dp"
-        android:foreground="?attr/selectableItemBackground"
-        android:gravity="center_vertical"
-        android:paddingStart="24dp"
-        android:text="Add account"
-        android:textAppearance="?android:attr/textAppearanceListItem"
-        android:textColor="@color/black"
-        app:layout_constraintBottom_toTopOf="@+id/manage_accounts"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        tools:ignore="RtlSymmetry" />
-
-    <TextView
-        android:id="@+id/manage_accounts"
-        android:layout_width="0dp"
-        android:layout_height="40dp"
-        android:drawableStart="@drawable/ic_settings"
-        android:drawablePadding="25dp"
-        android:foreground="?attr/selectableItemBackground"
-        android:gravity="center_vertical"
-        android:paddingStart="24dp"
-        android:text="Manage account"
-        android:textAppearance="?android:attr/textAppearanceListItem"
-        android:textColor="@color/black"
-        app:layout_constraintBottom_toBottomOf="parent"
-        app:layout_constraintEnd_toEndOf="parent"
-        app:layout_constraintStart_toStartOf="parent"
-        tools:ignore="RtlSymmetry" />
-</androidx.constraintlayout.widget.ConstraintLayout>

+ 3 - 0
src/main/res/values/dims.xml

@@ -144,4 +144,7 @@
     <dimen name="button_corner_radius">24dp</dimen>
     <integer name="media_grid_width">4</integer>
     <dimen name="copy_internal_link_padding">10dp</dimen>
+    <dimen name="account_action_button_margin">8dp</dimen>
+    <dimen name="account_action_button_height">50dp</dimen>
+    <dimen name="account_action_button_vertical_margin">10dp</dimen>
 </resources>