1
0
mirror of https://github.com/etesync/android synced 2024-12-23 07:08:16 +00:00

Implement collection creation.

This commit is contained in:
Tom Hacohen 2020-08-27 16:39:11 +03:00
parent 74b4ef3ee9
commit b9d3dc691b
3 changed files with 63 additions and 14 deletions

View File

@ -207,19 +207,31 @@ class AccountActivity : BaseActivity(), Toolbar.OnMenuItemClickListener, PopupMe
val info: CollectionInfo
when (item.itemId) {
R.id.create_calendar -> {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.CALENDAR
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
if (settings.isLegacy) {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.CALENDAR
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
} else {
startActivity(CollectionActivity.newCreateCollectionIntent(this@AccountActivity, account, ETEBASE_TYPE_CALENDAR))
}
}
R.id.create_tasklist -> {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.TASKS
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
if (settings.isLegacy) {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.TASKS
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
} else {
startActivity(CollectionActivity.newCreateCollectionIntent(this@AccountActivity, account, ETEBASE_TYPE_TASKS))
}
}
R.id.create_addressbook -> {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.ADDRESS_BOOK
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
if (settings.isLegacy) {
info = CollectionInfo()
info.enumType = CollectionInfo.Type.ADDRESS_BOOK
startActivity(CreateCollectionActivity.newIntent(this@AccountActivity, account, info))
} else {
startActivity(CollectionActivity.newCreateCollectionIntent(this@AccountActivity, account, ETEBASE_TYPE_ADDRESS_BOOK))
}
}
R.id.install_tasksorg -> {
installPackage(tasksOrgPackage)

View File

@ -11,6 +11,7 @@ import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.observe
import com.etebase.client.CollectionManager
import com.etebase.client.CollectionMetadata
import com.etesync.syncadapter.*
import com.etesync.syncadapter.ui.BaseActivity
import org.jetbrains.anko.doAsync
@ -44,8 +45,16 @@ class CollectionActivity() : BaseActivity() {
replace(R.id.fragment_container, ViewCollectionFragment())
}
} else if (colType != null) {
supportFragmentManager.commit {
// replace(R.id.fragment_container, CreateCollectionFragment(colType))
model.observe(this) {
doAsync {
val meta = CollectionMetadata(colType, "")
val cachedCollection = CachedCollection(it.colMgr.create(meta, ""), meta)
uiThread {
supportFragmentManager.commit {
replace(R.id.fragment_container, EditCollectionFragment(cachedCollection, true))
}
}
}
}
}
}

View File

@ -9,6 +9,7 @@ import android.widget.EditText
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.Fragment
import androidx.fragment.app.activityViewModels
import androidx.fragment.app.commit
import androidx.fragment.app.viewModels
import com.etebase.client.Collection
import com.etebase.client.exceptions.EtebaseException
@ -22,7 +23,7 @@ import org.jetbrains.anko.doAsync
import org.jetbrains.anko.uiThread
import yuku.ambilwarna.AmbilWarnaDialog
class EditCollectionFragment(private val cachedCollection: CachedCollection) : Fragment() {
class EditCollectionFragment(private val cachedCollection: CachedCollection, private val isCreating: Boolean = false) : Fragment() {
private val model: AccountViewModel by activityViewModels()
private val collectionModel: CollectionViewModel by activityViewModels()
private val loadingModel: LoadingViewModel by viewModels()
@ -42,7 +43,25 @@ class EditCollectionFragment(private val cachedCollection: CachedCollection) : F
}
fun updateTitle() {
(activity as? BaseActivity?)?.supportActionBar?.setTitle(R.string.edit_collection)
cachedCollection.let {
var titleId: Int = R.string.create_calendar
if (isCreating) {
when (cachedCollection.meta.collectionType) {
Constants.ETEBASE_TYPE_CALENDAR -> {
titleId = R.string.create_calendar
}
Constants.ETEBASE_TYPE_TASKS -> {
titleId = R.string.create_tasklist
}
Constants.ETEBASE_TYPE_ADDRESS_BOOK -> {
titleId = R.string.create_addressbook
}
}
} else {
titleId = R.string.edit_collection
}
(activity as? BaseActivity?)?.supportActionBar?.setTitle(titleId)
}
}
private fun initUi(inflater: LayoutInflater, v: View) {
@ -98,6 +117,9 @@ class EditCollectionFragment(private val cachedCollection: CachedCollection) : F
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
super.onCreateOptionsMenu(menu, inflater)
inflater.inflate(R.menu.fragment_edit_collection, menu)
if (isCreating) {
menu.findItem(R.id.on_delete).setVisible(false)
}
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
@ -184,7 +206,13 @@ class EditCollectionFragment(private val cachedCollection: CachedCollection) : F
val col = cachedCollection.col
col.meta = meta
uploadCollection(col)
parentFragmentManager.popBackStack()
if (isCreating) {
parentFragmentManager.commit {
replace(R.id.fragment_container, ViewCollectionFragment())
}
} else {
parentFragmentManager.popBackStack()
}
} catch (e: EtebaseException) {
uiThread {
AlertDialog.Builder(requireContext())