2021-11-04 11:13:24 +00:00
|
|
|
/*
|
2022-03-10 13:26:50 +00:00
|
|
|
* Copyright (c) 2022 Proton Technologies AG
|
2021-11-04 11:13:24 +00:00
|
|
|
*
|
|
|
|
* This file is part of ProtonMail.
|
|
|
|
*
|
|
|
|
* ProtonMail is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* ProtonMail is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with ProtonMail. If not, see https://www.gnu.org/licenses/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package ch.protonmail.android.activities
|
|
|
|
|
|
|
|
import android.app.Activity
|
|
|
|
import android.content.Context
|
|
|
|
import android.content.Intent
|
|
|
|
import androidx.activity.result.contract.ActivityResultContract
|
2021-11-08 12:24:31 +00:00
|
|
|
import ch.protonmail.android.activities.composeMessage.ComposeMessageActivity
|
|
|
|
import ch.protonmail.android.activities.settings.EXTRA_CURRENT_MAILBOX_LABEL_ID
|
|
|
|
import ch.protonmail.android.activities.settings.EXTRA_CURRENT_MAILBOX_LOCATION
|
|
|
|
import ch.protonmail.android.contacts.ContactsActivity
|
2021-11-04 11:13:24 +00:00
|
|
|
import ch.protonmail.android.core.Constants
|
|
|
|
import ch.protonmail.android.utils.AppUtil
|
|
|
|
|
2021-11-08 12:24:31 +00:00
|
|
|
class StartSettings : ActivityResultContract<StartSettings.Input, Unit?>() {
|
|
|
|
|
|
|
|
override fun createIntent(context: Context, input: Input): Intent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(context, SettingsActivity::class.java)).apply {
|
|
|
|
putExtra(EXTRA_CURRENT_MAILBOX_LOCATION, input.locationType.messageLocationTypeValue)
|
|
|
|
putExtra(EXTRA_CURRENT_MAILBOX_LABEL_ID, input.labelId)
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, result: Intent?): Unit? {
|
|
|
|
if (resultCode != Activity.RESULT_OK) return null
|
|
|
|
return Unit
|
|
|
|
}
|
2021-11-04 11:13:24 +00:00
|
|
|
|
|
|
|
data class Input(
|
|
|
|
val locationType: Constants.MessageLocationType,
|
|
|
|
val labelId: String?,
|
|
|
|
)
|
2021-11-08 12:24:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
class StartContacts : ActivityResultContract<Unit, Unit?>() {
|
|
|
|
|
|
|
|
override fun createIntent(context: Context, input: Unit): Intent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(context, ContactsActivity::class.java))
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, result: Intent?): Unit? {
|
|
|
|
if (resultCode != Activity.RESULT_OK) return null
|
|
|
|
return Unit
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class StartCompose : ActivityResultContract<StartCompose.Input, Unit?>() {
|
|
|
|
|
|
|
|
override fun createIntent(context: Context, input: Input): Intent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(context, ComposeMessageActivity::class.java)).apply {
|
|
|
|
input.messageId?.let { putExtra(ComposeMessageActivity.EXTRA_MESSAGE_ID, it) }
|
|
|
|
input.isInline?.let { putExtra(ComposeMessageActivity.EXTRA_MESSAGE_RESPONSE_INLINE, it) }
|
|
|
|
input.addressId?.let { putExtra(ComposeMessageActivity.EXTRA_MESSAGE_ADDRESS_ID, it) }
|
|
|
|
}
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, result: Intent?): Unit? {
|
|
|
|
if (resultCode != Activity.RESULT_OK) return null
|
|
|
|
return Unit
|
|
|
|
}
|
|
|
|
|
|
|
|
data class Input(
|
|
|
|
val messageId: String? = null,
|
|
|
|
val isInline: Boolean? = null,
|
|
|
|
val addressId: String? = null,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
class StartSearch : ActivityResultContract<Unit, Unit?>() {
|
|
|
|
|
|
|
|
override fun createIntent(context: Context, input: Unit): Intent =
|
|
|
|
AppUtil.decorInAppIntent(Intent(context, SearchActivity::class.java))
|
|
|
|
|
|
|
|
override fun parseResult(resultCode: Int, result: Intent?): Unit? {
|
|
|
|
if (resultCode != Activity.RESULT_OK) return null
|
|
|
|
return Unit
|
|
|
|
}
|
2021-11-04 11:13:24 +00:00
|
|
|
}
|