Browse Source

Highlight selected template

Signed-off-by: alperozturk <alper_ozturk@proton.me>
alperozturk 9 months ago
parent
commit
bcd9941a11

+ 8 - 5
app/src/main/java/com/owncloud/android/ui/adapter/TemplateAdapter.java

@@ -1,6 +1,7 @@
 /*
  * Nextcloud - Android Client
  *
+ * SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
  * SPDX-FileCopyrightText: 2019 Chris Narkiewicz <hello@ezaquarii.com>
  * SPDX-FileCopyrightText: 2018 Tobias Kaminsky <tobias@kaminsky.me>
  * SPDX-FileCopyrightText: 2018 Nextcloud GmbH
@@ -8,6 +9,7 @@
  */
 package com.owncloud.android.ui.adapter;
 
+import android.annotation.SuppressLint;
 import android.content.Context;
 import android.graphics.drawable.Drawable;
 import android.view.LayoutInflater;
@@ -35,11 +37,11 @@ import androidx.recyclerview.widget.RecyclerView;
 public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHolder> {
 
     private TemplateList templateList = new TemplateList();
-    private ClickListener clickListener;
-    private Context context;
-    private CurrentAccountProvider currentAccountProvider;
-    private ClientFactory clientFactory;
-    private String mimetype;
+    private final ClickListener clickListener;
+    private final Context context;
+    private final CurrentAccountProvider currentAccountProvider;
+    private final ClientFactory clientFactory;
+    private final String mimetype;
     private Template selectedTemplate;
     private final ViewThemeUtils viewThemeUtils;
 
@@ -78,6 +80,7 @@ public class TemplateAdapter extends RecyclerView.Adapter<TemplateAdapter.ViewHo
         this.templateList = templateList;
     }
 
+    @SuppressLint("NotifyDataSetChanged")
     public void setTemplateAsActive(Template template) {
         selectedTemplate = template;
         notifyDataSetChanged();

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/dialog/ChooseRichDocumentsTemplateDialogFragment.kt

@@ -435,7 +435,7 @@ class ChooseRichDocumentsTemplateDialogFragment :
         @Deprecated("Deprecated in Java")
         override fun onPostExecute(templateList: List<Template>) {
             val fragment = chooseTemplateDialogFragmentWeakReference.get()
-            if (fragment == null) {
+            if (fragment == null || !fragment.isAdded) {
                 Log_OC.e(TAG, "Error streaming file: no previewMediaFragment!")
                 return
             }

+ 1 - 1
app/src/main/java/com/owncloud/android/ui/dialog/ChooseTemplateDialogFragment.kt

@@ -167,7 +167,7 @@ class ChooseTemplateDialogFragment : DialogFragment(), View.OnClickListener, Tem
         return builder.create()
     }
 
-    @Suppress("TooGenericExceptionCaught") // legacy code
+    @Suppress("TooGenericExceptionCaught")
     private fun fetchTemplate() {
         try {
             val user = currentAccount.user

+ 11 - 0
app/src/main/res/color/card_border_selector.xml

@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="utf-8"?><!--
+  ~ Nextcloud - Android Client
+  ~
+  ~ SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
+  ~ SPDX-License-Identifier: AGPL-3.0-or-later
+  -->
+
+<selector xmlns:android="http://schemas.android.com/apk/res/android">
+    <item android:color="@color/primary" android:state_checked="true"/>
+    <item android:color="@color/grey_600" android:state_checked="false"/>
+</selector>

+ 12 - 0
app/src/main/res/drawable/rounded_rect_8dp.xml

@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+  ~ Nextcloud - Android Client
+  ~
+  ~ SPDX-FileCopyrightText: 2023 ZetaTom
+  ~ SPDX-FileCopyrightText: 2023 Nextcloud GmbH
+  ~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
+-->
+<shape xmlns:android="http://schemas.android.com/apk/res/android"
+    android:shape="rectangle">
+    <corners android:radius="8dp" />
+</shape>

+ 12 - 2
app/src/main/res/layout/template_button.xml

@@ -2,26 +2,36 @@
 <!--
   ~ Nextcloud - Android Client
   ~
+  ~ SPDX-FileCopyrightText: 2024 Alper Ozturk <alper.ozturk@nextcloud.com>
   ~ SPDX-FileCopyrightText: 2021 Andy Scherzinger <info@andy-scherzinger>
   ~ SPDX-FileCopyrightText: 2018 Tobias Kaminsky <tobias@kaminsky.me>
   ~ SPDX-FileCopyrightText: 2018 Nextcloud GmbH
   ~ SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+    android:id="@+id/template_layout"
+    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:clickable="true"
+    android:focusable="true"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
+    android:background="@drawable/rounded_rect_8dp"
+    android:backgroundTint="@color/grey_200"
     android:orientation="vertical"
+    android:layout_marginEnd="@dimen/standard_margin"
+    android:layout_marginBottom="@dimen/standard_margin"
     android:paddingTop="@dimen/standard_padding">
 
     <com.google.android.material.card.MaterialCardView
         android:id="@+id/template_container"
+        android:checkable="true"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_horizontal"
         app:cardElevation="0dp"
-        app:strokeColor="@color/grey_200"
+        app:strokeColor="@color/card_border_selector"
         app:strokeWidth="2dp">
 
         <ImageView