mirror of
https://github.com/nextcloud/android.git
synced 2024-11-27 09:39:25 +03:00
Refactor
Signed-off-by: alperozturk <alper_ozturk@proton.me>
This commit is contained in:
parent
5c8db30dae
commit
30b5d5713f
1 changed files with 39 additions and 28 deletions
|
@ -84,7 +84,6 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
private var selectedDate: Date? = null
|
private var selectedDate: Date? = null
|
||||||
private var calendarPickerOpen = false
|
private var calendarPickerOpen = false
|
||||||
private var datePickerDialog: DatePickerDialog? = null
|
private var datePickerDialog: DatePickerDialog? = null
|
||||||
private var dailyBackupCheckedChangeListener: CompoundButton.OnCheckedChangeListener? = null
|
|
||||||
private var contactsCheckedListener: CompoundButton.OnCheckedChangeListener? = null
|
private var contactsCheckedListener: CompoundButton.OnCheckedChangeListener? = null
|
||||||
private var calendarCheckedListener: CompoundButton.OnCheckedChangeListener? = null
|
private var calendarCheckedListener: CompoundButton.OnCheckedChangeListener? = null
|
||||||
private var user: User? = null
|
private var user: User? = null
|
||||||
|
@ -164,15 +163,22 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setupCheckListeners() {
|
private fun setupCheckListeners() {
|
||||||
dailyBackupCheckedChangeListener =
|
binding.dailyBackup.setOnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
|
||||||
CompoundButton.OnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
|
if (checkAndAskForContactsReadPermission()) {
|
||||||
if (checkAndAskForContactsReadPermission()) {
|
setAutomaticBackup(isChecked)
|
||||||
setAutomaticBackup(isChecked)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
binding.dailyBackup.setOnCheckedChangeListener(dailyBackupCheckedChangeListener)
|
}
|
||||||
|
|
||||||
|
initContactsCheckedListener()
|
||||||
|
binding.contacts.setOnCheckedChangeListener(contactsCheckedListener)
|
||||||
|
|
||||||
|
initCalendarCheckedListener()
|
||||||
|
binding.calendar.setOnCheckedChangeListener(calendarCheckedListener)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun initContactsCheckedListener() {
|
||||||
contactsCheckedListener =
|
contactsCheckedListener =
|
||||||
CompoundButton.OnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
|
CompoundButton.OnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
if (checkAndAskForContactsReadPermission()) {
|
if (checkAndAskForContactsReadPermission()) {
|
||||||
isContactsBackupEnabled = true
|
isContactsBackupEnabled = true
|
||||||
|
@ -183,9 +189,11 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
setBackupNowButtonVisibility()
|
setBackupNowButtonVisibility()
|
||||||
setAutomaticBackup(binding.dailyBackup.isChecked)
|
setAutomaticBackup(binding.dailyBackup.isChecked)
|
||||||
}
|
}
|
||||||
binding.contacts.setOnCheckedChangeListener(contactsCheckedListener)
|
}
|
||||||
|
|
||||||
|
private fun initCalendarCheckedListener() {
|
||||||
calendarCheckedListener =
|
calendarCheckedListener =
|
||||||
CompoundButton.OnCheckedChangeListener { buttonView: CompoundButton?, isChecked: Boolean ->
|
CompoundButton.OnCheckedChangeListener { _: CompoundButton?, isChecked: Boolean ->
|
||||||
if (isChecked) {
|
if (isChecked) {
|
||||||
if (checkAndAskForCalendarReadPermission()) {
|
if (checkAndAskForCalendarReadPermission()) {
|
||||||
isCalendarBackupEnabled = true
|
isCalendarBackupEnabled = true
|
||||||
|
@ -196,7 +204,6 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
setBackupNowButtonVisibility()
|
setBackupNowButtonVisibility()
|
||||||
setAutomaticBackup(binding.dailyBackup.isChecked)
|
setAutomaticBackup(binding.dailyBackup.isChecked)
|
||||||
}
|
}
|
||||||
binding.calendar.setOnCheckedChangeListener(calendarCheckedListener)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun setBackupNowButtonVisibility() {
|
private fun setBackupNowButtonVisibility() {
|
||||||
|
@ -249,10 +256,11 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
KEY_CALENDAR_DAY, -1
|
KEY_CALENDAR_DAY, -1
|
||||||
) != -1
|
) != -1
|
||||||
) {
|
) {
|
||||||
selectedDate = Date(
|
val cal = Calendar.getInstance()
|
||||||
savedInstanceState.getInt(KEY_CALENDAR_YEAR),
|
cal[Calendar.YEAR] = savedInstanceState.getInt(KEY_CALENDAR_YEAR)
|
||||||
savedInstanceState.getInt(KEY_CALENDAR_MONTH), savedInstanceState.getInt(KEY_CALENDAR_DAY)
|
cal[Calendar.MONTH] = savedInstanceState.getInt(KEY_CALENDAR_MONTH)
|
||||||
)
|
cal[Calendar.DAY_OF_MONTH] = savedInstanceState.getInt(KEY_CALENDAR_DAY)
|
||||||
|
selectedDate = cal.time
|
||||||
}
|
}
|
||||||
calendarPickerOpen = true
|
calendarPickerOpen = true
|
||||||
}
|
}
|
||||||
|
@ -280,6 +288,7 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
openDate(null)
|
openDate(null)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val contactsPreferenceActivity = activity as ContactsPreferenceActivity?
|
val contactsPreferenceActivity = activity as ContactsPreferenceActivity?
|
||||||
if (contactsPreferenceActivity != null) {
|
if (contactsPreferenceActivity != null) {
|
||||||
val backupFolderPath = resources.getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR
|
val backupFolderPath = resources.getString(R.string.contacts_backup_folder) + OCFile.PATH_SEPARATOR
|
||||||
|
@ -460,24 +469,24 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
if (isContactsBackupEnabled) {
|
if (isContactsBackupEnabled) {
|
||||||
Log_OC.d(TAG, "Scheduling contacts backup job")
|
Log_OC.d(TAG, "Scheduling contacts backup job")
|
||||||
backgroundJobManager!!.schedulePeriodicContactsBackup(user)
|
backgroundJobManager?.schedulePeriodicContactsBackup(user)
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, "Cancelling contacts backup job")
|
Log_OC.d(TAG, "Cancelling contacts backup job")
|
||||||
backgroundJobManager!!.cancelPeriodicContactsBackup(user)
|
backgroundJobManager?.cancelPeriodicContactsBackup(user)
|
||||||
}
|
}
|
||||||
if (isCalendarBackupEnabled) {
|
if (isCalendarBackupEnabled) {
|
||||||
Log_OC.d(TAG, "Scheduling calendar backup job")
|
Log_OC.d(TAG, "Scheduling calendar backup job")
|
||||||
backgroundJobManager!!.schedulePeriodicCalendarBackup(user)
|
backgroundJobManager?.schedulePeriodicCalendarBackup(user)
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, "Cancelling calendar backup job")
|
Log_OC.d(TAG, "Cancelling calendar backup job")
|
||||||
backgroundJobManager!!.cancelPeriodicCalendarBackup(user)
|
backgroundJobManager?.cancelPeriodicCalendarBackup(user)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log_OC.d(TAG, "Cancelling all backup jobs")
|
Log_OC.d(TAG, "Cancelling all backup jobs")
|
||||||
backgroundJobManager!!.cancelPeriodicContactsBackup(user)
|
backgroundJobManager?.cancelPeriodicContactsBackup(user)
|
||||||
backgroundJobManager!!.cancelPeriodicCalendarBackup(user)
|
backgroundJobManager?.cancelPeriodicCalendarBackup(user)
|
||||||
}
|
}
|
||||||
arbitraryDataProvider!!.storeOrUpdateKeyValue(
|
arbitraryDataProvider?.storeOrUpdateKeyValue(
|
||||||
user.accountName,
|
user.accountName,
|
||||||
ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP,
|
ContactsPreferenceActivity.PREFERENCE_CONTACTS_AUTOMATIC_BACKUP,
|
||||||
enabled.toString()
|
enabled.toString()
|
||||||
|
@ -488,11 +497,7 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
val contactsPreferenceActivity = activity as ContactsPreferenceActivity?
|
val contactsPreferenceActivity = activity as ContactsPreferenceActivity?
|
||||||
|
|
||||||
// check permissions
|
// check permissions
|
||||||
return if (checkSelfPermission(
|
return if (checkSelfPermission(contactsPreferenceActivity!!, Manifest.permission.READ_CONTACTS)) {
|
||||||
contactsPreferenceActivity!!,
|
|
||||||
Manifest.permission.READ_CONTACTS
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
// No explanation needed, request the permission.
|
// No explanation needed, request the permission.
|
||||||
|
@ -551,11 +556,17 @@ class BackupFragment : FileFragment(), OnDateSetListener, Injectable {
|
||||||
val storageManager = contactsPreferenceActivity.storageManager
|
val storageManager = contactsPreferenceActivity.storageManager
|
||||||
val contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString)
|
val contactsBackupFolder = storageManager.getFileByDecryptedRemotePath(contactsBackupFolderString)
|
||||||
val calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString)
|
val calendarBackupFolder = storageManager.getFileByDecryptedRemotePath(calendarBackupFolderString)
|
||||||
|
|
||||||
val backupFiles = storageManager.getFolderContent(contactsBackupFolder, false)
|
val backupFiles = storageManager.getFolderContent(contactsBackupFolder, false)
|
||||||
backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false))
|
backupFiles.addAll(storageManager.getFolderContent(calendarBackupFolder, false))
|
||||||
backupFiles.sortWith { o1: OCFile?, o2: OCFile? ->
|
backupFiles.sortWith { o1: OCFile?, o2: OCFile? ->
|
||||||
o1!!.modificationTimestamp.compareTo(o2!!.modificationTimestamp)
|
if (o1 != null && o2 != null) {
|
||||||
|
o1.modificationTimestamp.compareTo(o2.modificationTimestamp)
|
||||||
|
} else {
|
||||||
|
-1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val cal = Calendar.getInstance()
|
val cal = Calendar.getInstance()
|
||||||
val year: Int
|
val year: Int
|
||||||
val month: Int
|
val month: Int
|
||||||
|
|
Loading…
Reference in a new issue