浏览代码

Merge pull request #12070 from nextcloud/feature/use-m3-loading-dialog

Use Material Design 3 For Loading Popup
Andy Scherzinger 1 年之前
父节点
当前提交
65440f9107

+ 4 - 0
app/src/androidTest/java/com/owncloud/android/ui/dialog/DialogFragmentIT.java

@@ -92,6 +92,7 @@ import androidx.activity.result.contract.ActivityResultContract;
 import androidx.annotation.NonNull;
 import androidx.fragment.app.DialogFragment;
 import androidx.test.espresso.intent.rule.IntentsTestRule;
+import androidx.test.rule.GrantPermissionRule;
 import kotlin.Unit;
 
 import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;
@@ -108,6 +109,9 @@ public class DialogFragmentIT extends AbstractIT {
         return activityRule.launchActivity(intent);
     }
 
+    @Rule
+    public GrantPermissionRule permissionRule = GrantPermissionRule.grant(
+        android.Manifest.permission.POST_NOTIFICATIONS);
 
     @After
     public void quitLooperIfNeeded() {

+ 0 - 88
app/src/main/java/com/owncloud/android/ui/dialog/LoadingDialog.java

@@ -1,88 +0,0 @@
-/*
- *   ownCloud Android client application
- *
- *   Copyright (C) 2015 ownCloud Inc.
- *
- *   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/>.
- *
- */
-package com.owncloud.android.ui.dialog;
-
-import android.app.Dialog;
-import android.os.Bundle;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.Window;
-import android.widget.ProgressBar;
-import android.widget.TextView;
-
-import com.nextcloud.client.di.Injectable;
-import com.owncloud.android.R;
-import com.owncloud.android.utils.theme.ViewThemeUtils;
-
-import javax.inject.Inject;
-
-import androidx.annotation.NonNull;
-import androidx.fragment.app.DialogFragment;
-
-public class LoadingDialog extends DialogFragment implements Injectable {
-
-    @Inject ViewThemeUtils viewThemeUtils;
-    private String mMessage;
-
-    @Override
-    public void onCreate(Bundle savedInstanceState) {
-        super.onCreate(savedInstanceState);
-        setRetainInstance(true);
-        setCancelable(false);
-    }
-
-    public static LoadingDialog newInstance(String message) {
-        LoadingDialog loadingDialog = new LoadingDialog();
-        loadingDialog.mMessage = message;
-        return loadingDialog;
-    }
-
-    @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
-        // Create a view by inflating desired layout
-        View v = inflater.inflate(R.layout.loading_dialog, container,  false);
-
-        // set value
-        TextView tv = v.findViewById(R.id.loadingText);
-        tv.setText(mMessage);
-
-        // set progress wheel color
-        ProgressBar progressBar = v.findViewById(R.id.loadingBar);
-        viewThemeUtils.platform.tintDrawable(requireContext(), progressBar.getIndeterminateDrawable());
-
-        return v;
-    }
-
-    @NonNull
-    @Override
-    public Dialog onCreateDialog(Bundle savedInstanceState) {
-        Dialog dialog = super.onCreateDialog(savedInstanceState);
-        dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
-        return dialog;
-    }
-
-    @Override
-    public void onDestroyView() {
-        if (getDialog() != null && getRetainInstance()) {
-            getDialog().setDismissMessage(null);
-        }
-        super.onDestroyView();
-    }
-}

+ 79 - 0
app/src/main/java/com/owncloud/android/ui/dialog/LoadingDialog.kt

@@ -0,0 +1,79 @@
+/*
+ *   ownCloud Android client application
+ *
+ *   Copyright (C) 2015 ownCloud Inc.
+ *
+ *   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/>.
+ *
+ */
+package com.owncloud.android.ui.dialog
+
+import android.os.Bundle
+import android.view.LayoutInflater
+import android.view.View
+import android.view.ViewGroup
+import androidx.fragment.app.DialogFragment
+import com.nextcloud.android.common.ui.theme.utils.ColorRole
+import com.nextcloud.client.di.Injectable
+import com.owncloud.android.databinding.LoadingDialogBinding
+import com.owncloud.android.utils.theme.ViewThemeUtils
+import javax.inject.Inject
+
+class LoadingDialog : DialogFragment(), Injectable {
+
+    @JvmField
+    @Inject
+    var viewThemeUtils: ViewThemeUtils? = null
+
+    private var mMessage: String? = null
+    private lateinit var binding: LoadingDialogBinding
+
+    override fun onCreate(savedInstanceState: Bundle?) {
+        super.onCreate(savedInstanceState)
+
+        retainInstance = true
+        isCancelable = false
+    }
+
+    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
+        binding = LoadingDialogBinding.inflate(inflater, container, false)
+        binding.loadingText.text = mMessage
+
+        val loadingDrawable = binding.loadingBar.indeterminateDrawable
+        if (loadingDrawable != null) {
+            viewThemeUtils?.platform?.tintDrawable(requireContext(), loadingDrawable)
+        }
+
+        viewThemeUtils?.platform?.colorViewBackground(binding.loadingLayout, ColorRole.SURFACE_VARIANT)
+
+        return binding.root
+    }
+
+    override fun onDestroyView() {
+        if (dialog != null && retainInstance) {
+            dialog?.setDismissMessage(null)
+        }
+
+        super.onDestroyView()
+    }
+
+    companion object {
+
+        @JvmStatic
+        fun newInstance(message: String?): LoadingDialog {
+            val loadingDialog = LoadingDialog()
+            loadingDialog.mMessage = message
+            return loadingDialog
+        }
+    }
+}

+ 4 - 3
app/src/main/res/layout/loading_dialog.xml

@@ -16,7 +16,8 @@
   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 -->
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+<LinearLayout
+    xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/loadingLayout"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
@@ -25,14 +26,14 @@
 
     <ProgressBar
         android:id="@+id/loadingBar"
-        style="?android:attr/progressBarStyle"
+        style="@style/Widget.Material3.CircularProgressIndicator"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_gravity="center_vertical"
         android:indeterminate="true"
         android:indeterminateOnly="false"/>
 
-    <TextView
+    <com.google.android.material.textview.MaterialTextView
         android:id="@+id/loadingText"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"