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.annotation.IntDef; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 20 | import android.app.Dialog; |
| 21 | import android.app.DialogFragment; |
| 22 | import android.app.FragmentManager; |
| 23 | import android.app.FragmentTransaction; |
| 24 | import android.content.DialogInterface; |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 25 | import android.net.Uri; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 26 | import android.os.Bundle; |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 27 | import android.support.v7.app.AlertDialog; |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 28 | import android.text.Html; |
| 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 | c0fe459 | 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 | |
| 36 | import java.lang.annotation.Retention; |
| 37 | import java.lang.annotation.RetentionPolicy; |
| 38 | import java.util.ArrayList; |
Tomasz Mikolajewski | c0fe459 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 39 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 40 | /** |
| 41 | * Alert dialog for operation dialogs. |
| 42 | */ |
| 43 | public class OperationDialogFragment extends DialogFragment { |
| 44 | |
| 45 | public static final int DIALOG_TYPE_UNKNOWN = 0; |
| 46 | public static final int DIALOG_TYPE_FAILURE = 1; |
| 47 | public static final int DIALOG_TYPE_CONVERTED = 2; |
| 48 | |
| 49 | @IntDef(flag = true, value = { |
| 50 | DIALOG_TYPE_UNKNOWN, |
| 51 | DIALOG_TYPE_FAILURE, |
| 52 | DIALOG_TYPE_CONVERTED |
| 53 | }) |
| 54 | |
| 55 | @Retention(RetentionPolicy.SOURCE) |
| 56 | public @interface DialogType {} |
| 57 | |
| 58 | private static final String TAG = "OperationDialogFragment"; |
| 59 | |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 60 | public static void show( |
| 61 | FragmentManager fm, |
| 62 | @DialogType int dialogType, |
| 63 | ArrayList<DocumentInfo> failedSrcList, |
Tomasz Mikolajewski | 664025e | 2017-02-01 11:54:48 +0900 | [diff] [blame] | 64 | ArrayList<Uri> uriList, |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 65 | DocumentStack dstStack, |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 66 | @OpType int operationType) { |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 67 | |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 68 | final Bundle args = new Bundle(); |
| 69 | args.putInt(FileOperationService.EXTRA_DIALOG_TYPE, dialogType); |
Garfield, Tan | 4833477 | 2016-06-28 17:17:38 -0700 | [diff] [blame] | 70 | args.putInt(FileOperationService.EXTRA_OPERATION_TYPE, operationType); |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 71 | args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_DOCS, failedSrcList); |
Tomasz Mikolajewski | c0fe459 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 72 | args.putParcelableArrayList(FileOperationService.EXTRA_FAILED_URIS, uriList); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 73 | |
| 74 | final FragmentTransaction ft = fm.beginTransaction(); |
| 75 | final OperationDialogFragment fragment = new OperationDialogFragment(); |
| 76 | fragment.setArguments(args); |
| 77 | |
| 78 | ft.add(fragment, TAG); |
| 79 | ft.commitAllowingStateLoss(); |
| 80 | } |
| 81 | |
| 82 | @Override |
| 83 | public Dialog onCreateDialog(Bundle inState) { |
| 84 | super.onCreate(inState); |
| 85 | |
| 86 | final @DialogType int dialogType = |
| 87 | getArguments().getInt(FileOperationService.EXTRA_DIALOG_TYPE); |
| 88 | final @OpType int operationType = |
Garfield, Tan | 4833477 | 2016-06-28 17:17:38 -0700 | [diff] [blame] | 89 | getArguments().getInt(FileOperationService.EXTRA_OPERATION_TYPE); |
Steve McKay | 99f1dc3 | 2016-12-29 16:02:01 -0800 | [diff] [blame] | 90 | final ArrayList<Uri> uriList = getArguments().getParcelableArrayList( |
| 91 | FileOperationService.EXTRA_FAILED_URIS); |
| 92 | final ArrayList<DocumentInfo> docList = getArguments().getParcelableArrayList( |
| 93 | FileOperationService.EXTRA_FAILED_DOCS); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 94 | |
| 95 | final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); |
Tomasz Mikolajewski | c0fe459 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 96 | final String message = new MessageBuilder(getContext()).generateListMessage( |
| 97 | dialogType, operationType, docList, uriList); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 98 | |
Tomasz Mikolajewski | c0fe459 | 2017-01-31 16:50:57 +0900 | [diff] [blame] | 99 | builder.setMessage(Html.fromHtml(message)); |
Tomasz Mikolajewski | dd2b31c | 2016-01-22 16:22:51 +0900 | [diff] [blame] | 100 | builder.setPositiveButton( |
| 101 | R.string.close, |
| 102 | new DialogInterface.OnClickListener() { |
| 103 | @Override |
| 104 | public void onClick(DialogInterface dialog, int id) { |
| 105 | dialog.dismiss(); |
| 106 | } |
| 107 | }); |
| 108 | |
| 109 | return builder.create(); |
| 110 | } |
| 111 | } |