Prechádzať zdrojové kódy

Fix tints in user lists

Signed-off-by: Álvaro Brey <alvaro.brey@nextcloud.com>
Álvaro Brey 2 rokov pred
rodič
commit
d0a9fa2c72

+ 2 - 15
app/src/main/java/com/nextcloud/ui/ChooseAccountDialogFragment.kt

@@ -29,7 +29,6 @@ import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
 import android.widget.ImageView
-import androidx.core.content.ContextCompat
 import androidx.fragment.app.DialogFragment
 import com.google.android.material.dialog.MaterialAlertDialogBuilder
 import com.nextcloud.client.account.User
@@ -48,8 +47,6 @@ import com.owncloud.android.ui.adapter.UserListItem
 import com.owncloud.android.ui.asynctasks.RetrieveStatusAsyncTask
 import com.owncloud.android.utils.DisplayUtils
 import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
-import com.owncloud.android.utils.theme.ThemeColorUtils
-import com.owncloud.android.utils.theme.ThemeDrawableUtils
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils
 import javax.inject.Inject
 
@@ -76,12 +73,6 @@ class ChooseAccountDialogFragment :
     @Inject
     lateinit var viewThemeUtils: ViewThemeUtils
 
-    @Inject
-    lateinit var themeColorUtils: ThemeColorUtils
-
-    @Inject
-    lateinit var themeDrawableUtils: ThemeDrawableUtils
-
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         arguments?.let {
@@ -124,10 +115,7 @@ class ChooseAccountDialogFragment :
             binding.currentAccount.account.text = user.accountName
 
             // Defining user right indicator
-            val icon = themeDrawableUtils.tintDrawable(
-                ContextCompat.getDrawable(requireContext(), R.drawable.ic_check_circle),
-                themeColorUtils.primaryColor(requireContext(), true)
-            )
+            val icon = viewThemeUtils.platform.tintPrimaryDrawable(requireContext(), R.drawable.ic_check_circle)
             binding.currentAccount.accountMenu.setImageDrawable(icon)
 
             // Creating adapter for accounts list
@@ -139,8 +127,7 @@ class ChooseAccountDialogFragment :
                 false,
                 false,
                 true,
-                themeColorUtils,
-                themeDrawableUtils
+                viewThemeUtils
             )
 
             binding.accountsList.adapter = adapter

+ 3 - 6
app/src/main/java/com/owncloud/android/ui/activity/ManageAccountsActivity.java

@@ -156,8 +156,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
                                               multipleAccountsSupported,
                                               true,
                                               true,
-                                              themeColorUtils,
-                                              themeDrawableUtils);
+                                              viewThemeUtils);
 
         recyclerView.setAdapter(userListAdapter);
         recyclerView.setLayoutManager(new LinearLayoutManager(this));
@@ -312,8 +311,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
                                       multipleAccountsSupported,
                                       false,
                                       true,
-                                      themeColorUtils,
-                                      themeDrawableUtils);
+                                      viewThemeUtils);
                                   recyclerView.setAdapter(userListAdapter);
                                   runOnUiThread(() -> userListAdapter.notifyDataSetChanged());
                               } catch (OperationCanceledException e) {
@@ -367,8 +365,7 @@ public class ManageAccountsActivity extends FileActivity implements UserListAdap
                                                       multipleAccountsSupported,
                                                       false,
                                                       true,
-                                                      themeColorUtils,
-                                                      themeDrawableUtils);
+                                                      viewThemeUtils);
                 recyclerView.setAdapter(userListAdapter);
             } else {
                 onBackPressed();

+ 7 - 11
app/src/main/java/com/owncloud/android/ui/adapter/UserListAdapter.java

@@ -42,8 +42,7 @@ import com.owncloud.android.databinding.AccountItemBinding;
 import com.owncloud.android.lib.common.OwnCloudAccount;
 import com.owncloud.android.lib.common.utils.Log_OC;
 import com.owncloud.android.utils.DisplayUtils;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
-import com.owncloud.android.utils.theme.ThemeDrawableUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.util.ArrayList;
 import java.util.List;
@@ -70,8 +69,7 @@ public class UserListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
     private final boolean showAddAccount;
     private final boolean showDotsMenu;
     private boolean highlightCurrentlyActiveAccount;
-    private final ThemeColorUtils themeColorUtils;
-    private final ThemeDrawableUtils themeDrawableUtils;
+    private final ViewThemeUtils viewThemeUtils;
 
     public UserListAdapter(Context context,
                            UserAccountManager accountManager,
@@ -80,8 +78,7 @@ public class UserListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
                            boolean showAddAccount,
                            boolean showDotsMenu,
                            boolean highlightCurrentlyActiveAccount,
-                           ThemeColorUtils themeColorUtils,
-                           ThemeDrawableUtils themeDrawableUtils) {
+                           final ViewThemeUtils viewThemeUtils) {
         this.context = context;
         this.accountManager = accountManager;
         this.values = values;
@@ -92,8 +89,7 @@ public class UserListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
         this.clickListener = clickListener;
         this.showAddAccount = showAddAccount;
         this.showDotsMenu = showDotsMenu;
-        this.themeColorUtils = themeColorUtils;
-        this.themeDrawableUtils = themeDrawableUtils;
+        this.viewThemeUtils = viewThemeUtils;
         this.highlightCurrentlyActiveAccount = highlightCurrentlyActiveAccount;
     }
 
@@ -112,7 +108,7 @@ public class UserListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
             return new AccountViewHolderItem(AccountItemBinding.inflate(LayoutInflater.from(context),
                                                                         parent,
                                                                         false),
-                                             themeDrawableUtils);
+                                             viewThemeUtils);
         } else {
             return new AddAccountViewHolderItem(
                 AccountActionBinding.inflate(LayoutInflater.from(context), parent, false));
@@ -201,11 +197,11 @@ public class UserListAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
         private final AccountItemBinding binding;
         private User user;
 
-        AccountViewHolderItem(@NonNull AccountItemBinding binding, ThemeDrawableUtils themeDrawableUtils) {
+        AccountViewHolderItem(@NonNull AccountItemBinding binding, final ViewThemeUtils viewThemeUtils) {
             super(binding.getRoot());
             this.binding = binding;
 
-            themeDrawableUtils.tintDrawable(binding.ticker.getDrawable(), themeColorUtils.primaryColor(context, true));
+            viewThemeUtils.platform.tintPrimaryDrawable(context, binding.ticker.getDrawable());
 
             binding.getRoot().setOnClickListener(this);
             if (showDotsMenu) {

+ 1 - 7
app/src/main/java/com/owncloud/android/ui/dialog/MultipleAccountsDialog.java

@@ -43,8 +43,6 @@ import com.owncloud.android.R;
 import com.owncloud.android.databinding.MultipleAccountsBinding;
 import com.owncloud.android.ui.adapter.UserListAdapter;
 import com.owncloud.android.ui.adapter.UserListItem;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
-import com.owncloud.android.utils.theme.ThemeDrawableUtils;
 import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import java.util.ArrayList;
@@ -53,16 +51,13 @@ import java.util.List;
 import javax.inject.Inject;
 
 import androidx.annotation.NonNull;
-import androidx.appcompat.app.AlertDialog;
 import androidx.fragment.app.DialogFragment;
 import androidx.recyclerview.widget.LinearLayoutManager;
 
 public class MultipleAccountsDialog extends DialogFragment implements Injectable, UserListAdapter.ClickListener {
 
     @Inject UserAccountManager accountManager;
-    @Inject ThemeColorUtils themeColorUtils;
     @Inject ViewThemeUtils viewThemeUtils;
-    @Inject ThemeDrawableUtils themeDrawableUtils;
     public boolean highlightCurrentlyActiveAccount = true;
 
     @NonNull
@@ -87,8 +82,7 @@ public class MultipleAccountsDialog extends DialogFragment implements Injectable
                                                       false,
                                                       highlightCurrentlyActiveAccount,
                                                       false,
-                                                      themeColorUtils,
-                                                      themeDrawableUtils);
+                                                      viewThemeUtils);
 
         binding.list.setHasFixedSize(true);
         binding.list.setLayoutManager(new LinearLayoutManager(activity));

+ 5 - 12
app/src/test/java/com/owncloud/android/ui/adapter/UserListAdapterTest.java

@@ -22,8 +22,7 @@ package com.owncloud.android.ui.adapter;
 
 import com.owncloud.android.R;
 import com.owncloud.android.ui.activity.ManageAccountsActivity;
-import com.owncloud.android.utils.theme.ThemeColorUtils;
-import com.owncloud.android.utils.theme.ThemeDrawableUtils;
+import com.owncloud.android.utils.theme.newm3.ViewThemeUtils;
 
 import org.junit.Before;
 import org.junit.Test;
@@ -46,10 +45,7 @@ public class UserListAdapterTest {
     private ManageAccountsActivity manageAccountsActivity;
 
     @Mock
-    private ThemeColorUtils themeColorUtils;
-
-    @Mock
-    private ThemeDrawableUtils themeDrawableUtils;
+    private ViewThemeUtils viewThemeUtils;
 
     /**
      * Setting up and mocking the manageAccountsActivity class, and then mocking the method calls in the construction of
@@ -74,8 +70,7 @@ public class UserListAdapterTest {
                                               true,
                                               true,
                                               true,
-                                              themeColorUtils,
-                                              themeDrawableUtils);
+                                              viewThemeUtils);
         assertEquals(0, userListAdapter.getItemCount());
     }
 
@@ -95,8 +90,7 @@ public class UserListAdapterTest {
                                               true,
                                               true,
                                               true,
-                                              themeColorUtils,
-                                              themeDrawableUtils);
+                                              viewThemeUtils);
 
         assertEquals(2, userListAdapter.getItemCount());
     }
@@ -118,8 +112,7 @@ public class UserListAdapterTest {
                                               true,
                                               true,
                                               true,
-                                              themeColorUtils,
-                                              themeDrawableUtils);
+                                              viewThemeUtils);
 
         UserListItem userListItem1 = new UserListItem();
         UserListItem userListItem2 = new UserListItem();