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 import android
.app
.DatePickerDialog
;
25 import android
.app
.Dialog
;
26 import android
.content
.DialogInterface
;
27 import android
.os
.Bundle
;
28 import android
.support
.v4
.app
.DialogFragment
;
29 import android
.text
.format
.DateUtils
;
30 import android
.widget
.DatePicker
;
31 import android
.widget
.Toast
;
33 import com
.owncloud
.android
.datamodel
.OCFile
;
34 import com
.owncloud
.android
.ui
.activity
.FileActivity
;
36 import java
.util
.Calendar
;
37 import java
.util
.Date
;
40 * Dialog requesting a date after today.
42 public class ExpirationDatePickerDialogFragment
43 extends DialogFragment
44 implements DatePickerDialog
.OnDateSetListener
{
46 /** Tag for FragmentsManager */
47 public static final String DATE_PICKER_DIALOG
= "DATE_PICKER_DIALOG";
49 /** Constructor arguments */
50 private static final String ARG_FILE
= "ARG_FILE";
52 /** File to bind an expiration date */
56 * Factory method to create new instances
58 * @param file File to bind an expiration date
59 * @return New dialog instance
61 public static ExpirationDatePickerDialogFragment
newInstance(OCFile file
) {
62 Bundle arguments
= new Bundle();
63 arguments
.putParcelable(ARG_FILE
, file
);
65 ExpirationDatePickerDialogFragment dialog
= new ExpirationDatePickerDialogFragment();
66 dialog
.setArguments(arguments
);
73 * @return A new dialog to let the user choose an expiration date that will be bound to a share link.
76 public Dialog
onCreateDialog(Bundle savedInstanceState
) {
78 mFile
= getArguments().getParcelable(ARG_FILE
);
81 final Calendar c
= Calendar
.getInstance();
82 int year
= c
.get(Calendar
.YEAR
);
83 int month
= c
.get(Calendar
.MONTH
);
84 int day
= c
.get(Calendar
.DAY_OF_MONTH
);
86 // Create a new instance of DatePickerDialog, highlighting "tomorrow" as chosen day
87 DatePickerDialog dialog
= new DatePickerDialog(getActivity(), this, year
, month
, day
+ 1);
89 // Prevent days in the past may be chosen
90 DatePicker picker
= dialog
.getDatePicker();
91 picker
.setMinDate(System
.currentTimeMillis() + DateUtils
.DAY_IN_MILLIS
- 1000);
93 // Enforce spinners view; ignored by MD-based theme in Android >=5, but calendar is REALLY buggy
94 // in Android < 5, so let's be sure it never appears (in tablets both spinners and calendar are
96 picker
.setCalendarViewShown(false
);
102 * Called when the user choses an expiration date.
104 * @param view View instance where the date was chosen
105 * @param year Year of the date chosen.
106 * @param monthOfYear Month of the date chosen [0, 11]
107 * @param dayOfMonth Day of the date chosen
110 public void onDateSet(DatePicker view
, int year
, int monthOfYear
, int dayOfMonth
) {
112 Calendar chosenDate
= Calendar
.getInstance();
113 chosenDate
.set(Calendar
.YEAR
, year
);
114 chosenDate
.set(Calendar
.MONTH
, monthOfYear
);
115 chosenDate
.set(Calendar
.DAY_OF_MONTH
, dayOfMonth
);
117 ((FileActivity
)getActivity()).getFileOperationsHelper().setExpirationDateToShareViaLink(