mirror of
https://github.com/etesync/android
synced 2024-11-26 01:48:34 +00:00
parent
bfe68b9684
commit
d358ac0ba4
@ -142,14 +142,6 @@ class ViewCollectionActivity : BaseActivity(), Refreshable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun onImport(item: MenuItem) {
|
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))
|
startActivity(ImportActivity.newIntent(this@ViewCollectionActivity, account, info))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,6 +144,10 @@ class ImportActivity : BaseActivity(), SelectImportMethod, ResultFragment.OnImpo
|
|||||||
text.setText(R.string.import_button_local)
|
text.setText(R.string.import_button_local)
|
||||||
card.setOnClickListener { mSelectImportMethod!!.importAccount() }
|
card.setOnClickListener { mSelectImportMethod!!.importAccount() }
|
||||||
|
|
||||||
|
if ((activity as ImportActivity).info.type == CollectionInfo.Type.TASKS) {
|
||||||
|
card.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,9 +14,7 @@ import android.os.Bundle
|
|||||||
import android.provider.CalendarContract
|
import android.provider.CalendarContract
|
||||||
import android.provider.ContactsContract
|
import android.provider.ContactsContract
|
||||||
import androidx.fragment.app.DialogFragment
|
import androidx.fragment.app.DialogFragment
|
||||||
import at.bitfire.ical4android.CalendarStorageException
|
import at.bitfire.ical4android.*
|
||||||
import at.bitfire.ical4android.Event
|
|
||||||
import at.bitfire.ical4android.InvalidCalendarException
|
|
||||||
import at.bitfire.vcard4android.BatchOperation
|
import at.bitfire.vcard4android.BatchOperation
|
||||||
import at.bitfire.vcard4android.Contact
|
import at.bitfire.vcard4android.Contact
|
||||||
import at.bitfire.vcard4android.ContactsStorageException
|
import at.bitfire.vcard4android.ContactsStorageException
|
||||||
@ -117,10 +115,10 @@ class ImportFragment : DialogFragment() {
|
|||||||
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
intent.addCategory(Intent.CATEGORY_OPENABLE)
|
||||||
intent.action = Intent.ACTION_GET_CONTENT
|
intent.action = Intent.ACTION_GET_CONTENT
|
||||||
|
|
||||||
if (info.type == CollectionInfo.Type.CALENDAR) {
|
when (info.type) {
|
||||||
intent.type = "text/calendar"
|
CollectionInfo.Type.CALENDAR -> intent.type = "text/calendar"
|
||||||
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
CollectionInfo.Type.TASKS -> intent.type = "text/calendar"
|
||||||
intent.type = "text/x-vcard"
|
CollectionInfo.Type.ADDRESS_BOOK -> intent.type = "text/x-vcard"
|
||||||
}
|
}
|
||||||
|
|
||||||
val chooser = Intent.createChooser(
|
val chooser = Intent.createChooser(
|
||||||
@ -256,6 +254,44 @@ class ImportFragment : DialogFragment() {
|
|||||||
e.printStackTrace()
|
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()
|
entryProcessed()
|
||||||
}
|
}
|
||||||
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
} else if (info.type == CollectionInfo.Type.ADDRESS_BOOK) {
|
||||||
|
Loading…
Reference in New Issue
Block a user