1
0
mirror of https://github.com/etesync/android synced 2024-11-25 17:38:13 +00:00

Import: implement importing tasks from file.

Fixes #74.
This commit is contained in:
Tom Hacohen 2019-05-01 14:47:27 +01:00
parent bfe68b9684
commit d358ac0ba4
3 changed files with 47 additions and 15 deletions

View File

@ -142,14 +142,6 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
}
fun onImport(item: MenuItem) {
if (info.type == CollectionInfo.Type.TASKS) {
val dialog = AlertDialog.Builder(this)
.setIcon(R.drawable.ic_info_dark)
.setTitle("Not Implemented")
.setMessage("Importing tasks is not yet implemented")
dialog.show()
return
}
startActivity(ImportActivity.newIntent(this@ViewCollectionActivity, account, info))
}

View File

@ -144,6 +144,10 @@ class ImportActivity : BaseActivity(), SelectImportMethod, ResultFragment.OnImpo
text.setText(R.string.import_button_local)
card.setOnClickListener { mSelectImportMethod!!.importAccount() }
if ((activity as ImportActivity).info.type == CollectionInfo.Type.TASKS) {
card.visibility = View.GONE
}
return v
}
}

View File

@ -14,9 +14,7 @@ import android.os.Bundle
import android.provider.CalendarContract
import android.provider.ContactsContract
import androidx.fragment.app.DialogFragment
import at.bitfire.ical4android.CalendarStorageException
import at.bitfire.ical4android.Event
import at.bitfire.ical4android.InvalidCalendarException
import at.bitfire.ical4android.*
import at.bitfire.vcard4android.BatchOperation
import at.bitfire.vcard4android.Contact
import at.bitfire.vcard4android.ContactsStorageException
@ -117,10 +115,10 @@ class ImportFragment : DialogFragment() {
intent.addCategory(Intent.CATEGORY_OPENABLE)
intent.action = Intent.ACTION_GET_CONTENT
if (info.type == CollectionInfo.Type.CALENDAR) {
intent.type = "text/calendar"
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
intent.type = "text/x-vcard"
when (info.type) {
CollectionInfo.Type.CALENDAR -> intent.type = "text/calendar"
CollectionInfo.Type.TASKS -> intent.type = "text/calendar"
CollectionInfo.Type.ADDRESS_BOOK -> intent.type = "text/x-vcard"
}
val chooser = Intent.createChooser(
@ -256,6 +254,44 @@ class ImportFragment : DialogFragment() {
e.printStackTrace()
}
entryProcessed()
}
} else if (info.type == CollectionInfo.Type.TASKS) {
val tasks = Task.fromReader(importReader)
importReader.close()
if (tasks.isEmpty()) {
Logger.log.warning("Empty/invalid file.")
result.e = Exception("Empty/invalid file.")
return result
}
result.total = tasks.size.toLong()
finishParsingFile(tasks.size)
val provider = TaskProvider.acquire(context, TaskProvider.ProviderName.OpenTasks)!!
val localTaskList: LocalTaskList?
try {
localTaskList = LocalTaskList.findByName(account, provider, LocalTaskList.Factory, info.uid!!)
if (localTaskList == null) {
throw FileNotFoundException("Failed to load local resource.")
}
} catch (e: FileNotFoundException) {
Logger.log.info("Fail" + e.localizedMessage)
result.e = e
return result
}
for (task in tasks) {
try {
val localTask = LocalTask(localTaskList, task, task.uid, null)
localTask.addAsDirty()
result.added++
} catch (e: CalendarStorageException) {
e.printStackTrace()
}
entryProcessed()
}
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {