2  *   ownCloud Android client application 
   4  *   @author David A. Velasco 
   5  *   Copyright (C) 2015 ownCloud Inc. 
   7  *   This program is free software: you can redistribute it and/or modify 
   8  *   it under the terms of the GNU General Public License version 2, 
   9  *   as published by the Free Software Foundation. 
  11  *   This program is distributed in the hope that it will be useful, 
  12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of 
  13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
  14  *   GNU General Public License for more details. 
  16  *   You should have received a copy of the GNU General Public License 
  17  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. 
  21 package com
.owncloud
.android
.ui
.dialog
; 
  24  *  Dialog requiring confirmation before removing a given OCFile.   
  26  *  Triggers the removal according to the user response. 
  29 import android
.app
.Dialog
; 
  30 import android
.os
.Bundle
; 
  32 import com
.owncloud
.android
.R
; 
  33 import com
.owncloud
.android
.datamodel
.FileDataStorageManager
; 
  34 import com
.owncloud
.android
.datamodel
.OCFile
; 
  35 import com
.owncloud
.android
.ui
.activity
.ComponentsGetter
; 
  36 import com
.owncloud
.android
.ui
.dialog
.ConfirmationDialogFragment
.ConfirmationDialogFragmentListener
; 
  38 public class RemoveFileDialogFragment 
extends ConfirmationDialogFragment 
 
  39 implements ConfirmationDialogFragmentListener 
{ 
  41     private OCFile mTargetFile
; 
  43     private static final String ARG_TARGET_FILE 
= "TARGET_FILE"; 
  46      * Public factory method to create new RemoveFileDialogFragment instances. 
  48      * @param file            File to remove. 
  49      * @return                Dialog ready to show. 
  51     public static RemoveFileDialogFragment 
newInstance(OCFile file
) { 
  52         RemoveFileDialogFragment frag 
= new RemoveFileDialogFragment(); 
  53         Bundle args 
= new Bundle(); 
  55         int messageStringId 
= R
.string
.confirmation_remove_alert
; 
  57         int posBtn 
= R
.string
.confirmation_remove_remote
; 
  59         if (file
.isFolder()) { 
  60             messageStringId 
= R
.string
.confirmation_remove_folder_alert
; 
  61             posBtn 
= R
.string
.confirmation_remove_remote_and_local
; 
  62             negBtn 
= R
.string
.confirmation_remove_local
; 
  63         } else if (file
.isDown()) { 
  64             posBtn 
= R
.string
.confirmation_remove_remote_and_local
; 
  65             negBtn 
= R
.string
.confirmation_remove_local
; 
  68         args
.putInt(ARG_CONF_RESOURCE_ID
, messageStringId
); 
  69         args
.putStringArray(ARG_CONF_ARGUMENTS
, new String
[]{file
.getFileName()}); 
  70         args
.putInt(ARG_POSITIVE_BTN_RES
, posBtn
); 
  71         args
.putInt(ARG_NEUTRAL_BTN_RES
, R
.string
.common_no
); 
  72         args
.putInt(ARG_NEGATIVE_BTN_RES
, negBtn
); 
  73         args
.putParcelable(ARG_TARGET_FILE
, file
); 
  74         frag
.setArguments(args
); 
  80     public Dialog 
onCreateDialog(Bundle savedInstanceState
) { 
  81         Dialog dialog 
= super.onCreateDialog(savedInstanceState
); 
  82         mTargetFile 
= getArguments().getParcelable(ARG_TARGET_FILE
); 
  84         setOnConfirmationListener(this); 
  90      * Performs the removal of the target file, both locally and in the server. 
  93     public void onConfirmation(String callerTag
) { 
  94         ComponentsGetter cg 
= (ComponentsGetter
)getActivity(); 
  95         FileDataStorageManager storageManager 
= cg
.getStorageManager(); 
  96         if (storageManager
.getFileById(mTargetFile
.getFileId()) != null
) { 
  97             cg
.getFileOperationsHelper().removeFile(mTargetFile
, false
); 
 102      * Performs the removal of the local copy of the target file 
 105     public void onCancel(String callerTag
) { 
 106         ComponentsGetter cg 
= (ComponentsGetter
)getActivity(); 
 107         cg
.getFileOperationsHelper().removeFile(mTargetFile
, true
); 
 111     public void onNeutral(String callerTag
) { 
 112         // nothing to do here