Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.documentsui; |
| 18 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 19 | import android.app.Dialog; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 20 | import android.content.DialogInterface; |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 21 | import android.net.Uri; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 22 | import android.os.Bundle; |
Tony Huang | 03ef741 | 2019-05-03 19:18:02 +0800 | [diff] [blame] | 23 | import android.text.Html; |
| 24 | |
| 25 | import androidx.annotation.IntDef; |
Tony Huang | 8d8d92f | 2018-09-13 14:41:16 +0800 | [diff] [blame] | 26 | import androidx.fragment.app.DialogFragment; |
| 27 | import androidx.fragment.app.FragmentManager; |
| 28 | import androidx.fragment.app.FragmentTransaction; |
| 29 | |
Steve McKay | d080506 | 2016-09-15 14:30:38 -0700 | [diff] [blame] | 30 | import com.android.documentsui.base.DocumentInfo; |
| 31 | import com.android.documentsui.base.DocumentStack; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 32 | import com.android.documentsui.services.FileOperationService; |
Steve McKay | 946f561 | 2016-02-18 16:08:36 -0800 | [diff] [blame] | 33 | import com.android.documentsui.services.FileOperationService.OpType; |
Tomasz Mikolajewski | 56aeb49 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 34 | import com.android.documentsui.ui.MessageBuilder; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 35 | |
Tony Huang | 03ef741 | 2019-05-03 19:18:02 +0800 | [diff] [blame] | 36 | import com.google.android.material.dialog.MaterialAlertDialogBuilder; |
| 37 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 38 | import java.lang.annotation.Retention; |
| 39 | import java.lang.annotation.RetentionPolicy; |
| 40 | import java.util.ArrayList; |
Tomasz Mikolajewski | 56aeb49 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 41 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 42 | /** |
| 43 | * Alert dialog for operation dialogs. |
| 44 | */ |
| 45 | public class OperationDialogFragment extends DialogFragment { |
| 46 | |
| 47 | public static final int DIALOG_TYPE_UNKNOWN = 0; |
| 48 | public static final int DIALOG_TYPE_FAILURE = 1; |
| 49 | public static final int DIALOG_TYPE_CONVERTED = 2; |
| 50 | |
| 51 | @IntDef(flag = true, value = { |
| 52 | DIALOG_TYPE_UNKNOWN, |
| 53 | DIALOG_TYPE_FAILURE, |
| 54 | DIALOG_TYPE_CONVERTED |
| 55 | }) |
| 56 | |
| 57 | @Retention(RetentionPolicy.SOURCE) |
| 58 | public @interface DialogType {} |
| 59 | |
| 60 | private static final String TAG = "OperationDialogFragment"; |
| 61 | |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 62 | public static void show( |
| 63 | FragmentManager fm, |
| 64 | @DialogType int dialogType, |
| 65 | ArrayList<DocumentInfo> failedSrcList, |
Tomasz Mikolajewski | d573c7d | 2017-02-01 11:54:48 +0900 | [diff] [blame] | 66 | ArrayList<Uri> uriList, |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 67 | DocumentStack dstStack, |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 68 | @OpType int operationType) { |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 69 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 70 | final Bundle args = new Bundle(); |
| 71 | args.putInt(FileOperationService.EXTRA_DIALOG_TYPE, dialogType); |
Garfield, Tan | 4833477 | 2016-06-28 17:17:38 -0700 | [diff] [blame] | 72 | args.putInt(FileOperationService.EXTRA_OPERATION_TYPE, operationType); |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 73 | args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_DOCS, failedSrcList); |
Tomasz Mikolajewski | 56aeb49 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 74 | args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_URIS, uriList); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 75 | |
| 76 | final FragmentTransaction ft = fm.beginTransaction(); |
| 77 | final OperationDialogFragment fragment = new OperationDialogFragment(); |
| 78 | fragment.setArguments(args); |
| 79 | |
| 80 | ft.add(fragment, TAG); |
| 81 | ft.commitAllowingStateLoss(); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Dialog onCreateDialog(Bundle inState) { |
| 86 | super.onCreate(inState); |
| 87 | |
| 88 | final @DialogType int dialogType = |
| 89 | getArguments().getInt(FileOperationService.EXTRA_DIALOG_TYPE); |
| 90 | final @OpType int operationType = |
Garfield, Tan | 4833477 | 2016-06-28 17:17:38 -0700 | [diff] [blame] | 91 | getArguments().getInt(FileOperationService.EXTRA_OPERATION_TYPE); |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 92 | final ArrayList<Uri> uriList = getArguments().getParcelableArrayList( |
| 93 | FileOperationService.EXTRA_FAILED_URIS); |
| 94 | final ArrayList<DocumentInfo> docList = getArguments().getParcelableArrayList( |
| 95 | FileOperationService.EXTRA_FAILED_DOCS); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 96 | |
Tony Huang | 03ef741 | 2019-05-03 19:18:02 +0800 | [diff] [blame] | 97 | final MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(getActivity()); |
Tomasz Mikolajewski | 56aeb49 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 98 | final String message = new MessageBuilder(getContext()).generateListMessage( |
| 99 | dialogType, operationType, docList, uriList); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 100 | |
Tomasz Mikolajewski | 56aeb49 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 101 | builder.setMessage(Html.fromHtml(message)); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 102 | builder.setPositiveButton( |
| 103 | R.string.close, |
| 104 | new DialogInterface.OnClickListener() { |
| 105 | @Override |
| 106 | public void onClick(DialogInterface dialog, int id) { |
| 107 | dialog.dismiss(); |
| 108 | } |
| 109 | }); |
| 110 | |
| 111 | return builder.create(); |
| 112 | } |
| 113 | } |