2019-01-05 11:21:26 +00:00
|
|
|
|
/*
|
|
|
|
|
* Copyright © 2013 – 2016 Ricki Hirner (bitfire web engineering).
|
|
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
|
* are made available under the terms of the GNU Public License v3.0
|
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
|
* http://www.gnu.org/licenses/gpl.html
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
package com.etesync.syncadapter.ui
|
|
|
|
|
|
|
|
|
|
import android.accounts.Account
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.content.Intent
|
|
|
|
|
import android.os.Bundle
|
|
|
|
|
import android.view.Menu
|
|
|
|
|
import android.view.MenuItem
|
|
|
|
|
import android.view.View
|
|
|
|
|
import android.widget.EditText
|
2019-04-16 16:14:49 +00:00
|
|
|
|
import androidx.appcompat.app.AlertDialog
|
2019-01-05 11:21:26 +00:00
|
|
|
|
import com.etesync.syncadapter.App
|
|
|
|
|
import com.etesync.syncadapter.R
|
|
|
|
|
import com.etesync.syncadapter.model.CollectionInfo
|
|
|
|
|
import com.etesync.syncadapter.model.JournalEntity
|
|
|
|
|
import com.etesync.syncadapter.resource.LocalCalendar
|
2019-01-29 23:05:36 +00:00
|
|
|
|
import com.etesync.syncadapter.resource.LocalTaskList
|
2019-01-05 11:21:26 +00:00
|
|
|
|
|
|
|
|
|
class EditCollectionActivity : CreateCollectionActivity() {
|
|
|
|
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
|
|
super.onCreate(savedInstanceState)
|
|
|
|
|
|
|
|
|
|
setTitle(R.string.edit_collection)
|
|
|
|
|
|
2020-01-29 13:26:35 +00:00
|
|
|
|
when (info.enumType) {
|
2019-01-29 23:05:36 +00:00
|
|
|
|
CollectionInfo.Type.CALENDAR -> {
|
|
|
|
|
val colorSquare = findViewById<View>(R.id.color)
|
|
|
|
|
colorSquare.setBackgroundColor(info.color ?: LocalCalendar.defaultColor)
|
|
|
|
|
}
|
|
|
|
|
CollectionInfo.Type.TASKS -> {
|
|
|
|
|
val colorSquare = findViewById<View>(R.id.color)
|
|
|
|
|
colorSquare.setBackgroundColor(info.color ?: LocalTaskList.defaultColor)
|
|
|
|
|
}
|
|
|
|
|
CollectionInfo.Type.ADDRESS_BOOK -> {
|
|
|
|
|
}
|
2019-01-05 11:21:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
val edit = findViewById<View>(R.id.display_name) as EditText
|
2019-01-09 20:55:25 +00:00
|
|
|
|
edit.setText(info.displayName)
|
2019-01-05 11:21:26 +00:00
|
|
|
|
|
|
|
|
|
val desc = findViewById<View>(R.id.description) as EditText
|
2019-01-09 20:55:25 +00:00
|
|
|
|
desc.setText(info.description)
|
2019-01-05 11:21:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
|
|
|
|
menuInflater.inflate(R.menu.activity_edit_collection, menu)
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
override fun onDestroy() {
|
|
|
|
|
super.onDestroy()
|
|
|
|
|
|
|
|
|
|
if (parent is Refreshable) {
|
|
|
|
|
(parent as Refreshable).refresh()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fun onDeleteCollection(item: MenuItem) {
|
|
|
|
|
val data = (application as App).data
|
2019-01-09 20:55:25 +00:00
|
|
|
|
val journalCount = data.count(JournalEntity::class.java).where(JournalEntity.SERVICE_MODEL.eq(info.getServiceEntity(data))).get().value()
|
2019-01-05 11:21:26 +00:00
|
|
|
|
|
|
|
|
|
if (journalCount < 2) {
|
|
|
|
|
AlertDialog.Builder(this)
|
|
|
|
|
.setIcon(R.drawable.ic_error_dark)
|
|
|
|
|
.setTitle(R.string.account_delete_collection_last_title)
|
|
|
|
|
.setMessage(R.string.account_delete_collection_last_text)
|
|
|
|
|
.setPositiveButton(android.R.string.ok, null)
|
|
|
|
|
.show()
|
|
|
|
|
} else {
|
|
|
|
|
DeleteCollectionFragment.ConfirmDeleteCollectionFragment.newInstance(account, info).show(supportFragmentManager, null)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
companion object {
|
|
|
|
|
fun newIntent(context: Context, account: Account, info: CollectionInfo): Intent {
|
|
|
|
|
val intent = Intent(context, EditCollectionActivity::class.java)
|
|
|
|
|
intent.putExtra(CreateCollectionActivity.EXTRA_ACCOUNT, account)
|
|
|
|
|
intent.putExtra(CreateCollectionActivity.EXTRA_COLLECTION_INFO, info)
|
|
|
|
|
return intent
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|