mirror of
https://github.com/bitfireAT/davx5-ose.git
synced 2025-12-23 15:07:51 -05:00
DebugInfo: Support viewing jtx Board resources (#1818)
* Support viewing jtxBoard resources from debug info * Correct value of EXTRA_LOCAL_RESOURCE_URI * Correct comment * Use the same intent for journals, notes, calendar and tasks * State working task authorities explicitly * Use edit action to not crash opentasks * Use getViewIntentUriFor for jtx Board tasks * Remove explicit tasks authority for jtx Board * Remove explicit tasks authority for jtx Board * Remove early return statement * Dont handle jtxBoard tasks in LocalTask which is only for Dmfs tasks * Add some kdoc to LocalTask and LocalJtxICalObject * Use when with in list * Add FLAG_GRANT_READ_URI_PERMISSION to the correct intent * Correct line endings to from CRLF to LF
This commit is contained in:
@@ -10,10 +10,14 @@ import at.bitfire.ical4android.JtxCollection
|
||||
import at.bitfire.ical4android.JtxICalObject
|
||||
import at.bitfire.ical4android.JtxICalObjectFactory
|
||||
import at.techbee.jtx.JtxContract
|
||||
import at.techbee.jtx.JtxContract.JtxICalObject.getViewIntentUriFor
|
||||
import com.google.common.base.MoreObjects
|
||||
import java.util.Optional
|
||||
import kotlin.jvm.optionals.getOrNull
|
||||
|
||||
/**
|
||||
* Represents a Journal, Note or Task entry
|
||||
*/
|
||||
class LocalJtxICalObject(
|
||||
collection: JtxCollection<*>,
|
||||
fileName: String?,
|
||||
@@ -84,6 +88,6 @@ class LocalJtxICalObject(
|
||||
.add("flags", flags)
|
||||
.toString()
|
||||
|
||||
override fun getViewUri(context: Context) = null
|
||||
override fun getViewUri(context: Context) = getViewIntentUriFor(id)
|
||||
|
||||
}
|
||||
@@ -15,10 +15,14 @@ import at.bitfire.ical4android.DmfsTaskList
|
||||
import at.bitfire.ical4android.Task
|
||||
import at.bitfire.ical4android.TaskProvider
|
||||
import at.bitfire.synctools.storage.BatchOperation
|
||||
import at.techbee.jtx.JtxContract
|
||||
import com.google.common.base.MoreObjects
|
||||
import org.dmfs.tasks.contract.TaskContract.Tasks
|
||||
import java.util.Optional
|
||||
|
||||
/**
|
||||
* Represents a Dmfs Task (OpenTasks and Tasks.org) entry
|
||||
*/
|
||||
class LocalTask: DmfsTask, LocalResource {
|
||||
|
||||
companion object {
|
||||
@@ -131,13 +135,16 @@ class LocalTask: DmfsTask, LocalResource {
|
||||
)*/
|
||||
.toString()
|
||||
|
||||
override fun getViewUri(context: Context): Uri? {
|
||||
val idNotNull = id ?: return null
|
||||
if (taskList.providerName == TaskProvider.ProviderName.OpenTasks) {
|
||||
val contentUri = Tasks.getContentUri(taskList.providerName.authority)
|
||||
return ContentUris.withAppendedId(contentUri, idNotNull)
|
||||
override fun getViewUri(context: Context): Uri? = id?.let { id ->
|
||||
when (taskList.providerName) {
|
||||
TaskProvider.ProviderName.OpenTasks -> {
|
||||
val contentUri = Tasks.getContentUri(taskList.providerName.authority)
|
||||
ContentUris.withAppendedId(contentUri, id)
|
||||
}
|
||||
// Tasks.org can't handle view content URIs (missing intent-filter)
|
||||
// Jtx Board tasks are [LocalJtxICalObject]s
|
||||
else -> null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,8 @@ import at.bitfire.davdroid.BuildConfig
|
||||
import at.bitfire.davdroid.R
|
||||
import at.bitfire.davdroid.sync.SyncDataType
|
||||
import at.bitfire.davdroid.sync.TasksAppManager
|
||||
import at.bitfire.ical4android.TaskProvider
|
||||
import at.techbee.jtx.JtxContract
|
||||
import com.google.common.base.Ascii
|
||||
import dagger.Lazy
|
||||
import dagger.hilt.android.AndroidEntryPoint
|
||||
@@ -147,25 +149,31 @@ class DebugInfoActivity: AppCompatActivity() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds intent to view the problematic local event, task or contact at given Uri.
|
||||
* Builds intent to view the problematic local resource at given Uri.
|
||||
*
|
||||
* Note that only OpenTasks is supported as tasks provider. TasksOrg and jtxBoard
|
||||
* do not support viewing tasks via intent-filter (yet). See also [at.bitfire.davdroid.sync.SyncNotificationManager.getLocalResourceUri]
|
||||
* Note that the TasksOrg app does not support viewing tasks via intent-filter.
|
||||
* @see [at.bitfire.davdroid.resource.LocalResource.getViewUri]
|
||||
*/
|
||||
private fun buildViewLocalResourceIntent(uri: Uri): Intent? {
|
||||
val activeTasksAuthority = tasksAppManager.get().currentProvider()?.authority
|
||||
return when (uri.authority) {
|
||||
ContactsContract.AUTHORITY ->
|
||||
Intent(Intent.ACTION_VIEW).apply {
|
||||
private fun buildViewLocalResourceIntent(uri: Uri): Intent? =
|
||||
when (uri.authority) {
|
||||
// Support ACTION_VIEW
|
||||
in listOf(
|
||||
CalendarContract.AUTHORITY, // any calendar app
|
||||
JtxContract.JtxICalObject.VIEW_INTENT_HOST // jtx Board for journals, notes, tasks
|
||||
) -> Intent(Intent.ACTION_VIEW, uri)
|
||||
|
||||
// Need ACTION_EDIT (OpenTasks crashes on using ACTION_VIEW)
|
||||
TaskProvider.ProviderName.OpenTasks.authority // OpenTasks app
|
||||
-> Intent(Intent.ACTION_EDIT, uri)
|
||||
|
||||
// Need CONTENT_ITEM_TYPE to be set
|
||||
ContactsContract.AUTHORITY // any contacts app
|
||||
-> Intent(Intent.ACTION_VIEW).apply {
|
||||
setDataAndType(uri, ContactsContract.Contacts.CONTENT_ITEM_TYPE)
|
||||
}
|
||||
|
||||
CalendarContract.AUTHORITY, activeTasksAuthority ->
|
||||
Intent(Intent.ACTION_VIEW, uri)
|
||||
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}?.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
|
||||
/**
|
||||
* Builder for [DebugInfoActivity] intents
|
||||
@@ -215,7 +223,6 @@ class DebugInfoActivity: AppCompatActivity() {
|
||||
if (uri == null)
|
||||
return this
|
||||
intent.putExtra(EXTRA_LOCAL_RESOURCE_URI, uri)
|
||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||
return this
|
||||
}
|
||||
|
||||
@@ -257,7 +264,7 @@ class DebugInfoActivity: AppCompatActivity() {
|
||||
internal const val EXTRA_LOCAL_RESOURCE_SUMMARY = "localResourceSummary"
|
||||
|
||||
/** [Uri] of local resource related to the problem (as [android.os.Parcelable]) */
|
||||
internal const val EXTRA_LOCAL_RESOURCE_URI = "localResourceId"
|
||||
internal const val EXTRA_LOCAL_RESOURCE_URI = "localResourceUri"
|
||||
|
||||
/** logs related to the problem (plain-text [String]) */
|
||||
private const val EXTRA_LOGS = "logs"
|
||||
|
||||
Reference in New Issue
Block a user