Search in sources :

Example 11 with ContactsPreferenceActivity

use of com.owncloud.android.ui.activity.ContactsPreferenceActivity in project android by nextcloud.

the class ContactsBackupFragment method openDate.

public void openDate(@Nullable Date savedDate) {
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
    String backupFolderString = getResources().getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR;
    OCFile backupFolder = contactsPreferenceActivity.getStorageManager().getFileByPath(backupFolderString);
    List<OCFile> backupFiles = contactsPreferenceActivity.getStorageManager().getFolderContent(backupFolder, false);
    Collections.sort(backupFiles, new Comparator<OCFile>() {

        @Override
        public int compare(OCFile o1, OCFile o2) {
            if (o1.getModificationTimestamp() == o2.getModificationTimestamp()) {
                return 0;
            }
            if (o1.getModificationTimestamp() > o2.getModificationTimestamp()) {
                return 1;
            } else {
                return -1;
            }
        }
    });
    Calendar cal = Calendar.getInstance();
    int year;
    int month;
    int day;
    if (savedDate == null) {
        year = cal.get(Calendar.YEAR);
        month = cal.get(Calendar.MONTH) + 1;
        day = cal.get(Calendar.DAY_OF_MONTH);
    } else {
        year = savedDate.getYear();
        month = savedDate.getMonth();
        day = savedDate.getDay();
    }
    if (backupFiles.size() > 0 && backupFiles.get(backupFiles.size() - 1) != null) {
        datePickerDialog = new DatePickerDialog(contactsPreferenceActivity, this, year, month, day);
        datePickerDialog.getDatePicker().setMaxDate(backupFiles.get(backupFiles.size() - 1).getModificationTimestamp());
        datePickerDialog.getDatePicker().setMinDate(backupFiles.get(0).getModificationTimestamp());
        datePickerDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                selectedDate = null;
            }
        });
        datePickerDialog.show();
    } else {
        Toast.makeText(contactsPreferenceActivity, R.string.contacts_preferences_something_strange_happened, Toast.LENGTH_SHORT).show();
    }
}
Also used : OCFile(com.owncloud.android.datamodel.OCFile) ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) DatePickerDialog(android.app.DatePickerDialog) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar)

Example 12 with ContactsPreferenceActivity

use of com.owncloud.android.ui.activity.ContactsPreferenceActivity in project android by nextcloud.

the class ContactsBackupFragment method startContactsBackupJob.

private void startContactsBackupJob() {
    final ContactsPreferenceActivity contactsPreferenceActivity = (ContactsPreferenceActivity) getActivity();
    PersistableBundleCompat bundle = new PersistableBundleCompat();
    bundle.putString(ContactsBackupJob.ACCOUNT, contactsPreferenceActivity.getAccount().name);
    bundle.putBoolean(ContactsBackupJob.FORCE, true);
    new JobRequest.Builder(ContactsBackupJob.TAG).setExtras(bundle).startNow().setUpdateCurrent(false).build().schedule();
    Snackbar.make(getView().findViewById(R.id.contacts_linear_layout), R.string.contacts_preferences_backup_scheduled, Snackbar.LENGTH_LONG).show();
}
Also used : ContactsPreferenceActivity(com.owncloud.android.ui.activity.ContactsPreferenceActivity) PersistableBundleCompat(com.evernote.android.job.util.support.PersistableBundleCompat) JobRequest(com.evernote.android.job.JobRequest)

Aggregations

ContactsPreferenceActivity (com.owncloud.android.ui.activity.ContactsPreferenceActivity)12 View (android.view.View)3 TextView (android.widget.TextView)3 BindView (butterknife.BindView)3 Intent (android.content.Intent)2 OCFile (com.owncloud.android.datamodel.OCFile)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 DatePickerDialog (android.app.DatePickerDialog)1 DialogInterface (android.content.DialogInterface)1 IntentFilter (android.content.IntentFilter)1 Snackbar (android.support.design.widget.Snackbar)1 Fragment (android.support.v4.app.Fragment)1 ActionBar (android.support.v7.app.ActionBar)1 AppCompatButton (android.support.v7.widget.AppCompatButton)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 RecyclerView (android.support.v7.widget.RecyclerView)1 CheckedTextView (android.widget.CheckedTextView)1 CompoundButton (android.widget.CompoundButton)1 ImageView (android.widget.ImageView)1