-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCreateMessageActivity.kt
More file actions
132 lines (120 loc) · 4.77 KB
/
Copy pathCreateMessageActivity.kt
File metadata and controls
132 lines (120 loc) · 4.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* © 2016-present FlowCrypt a.s. Limitations apply. Contact human@flowcrypt.com
* Contributors: denbond7
*/
package com.flowcrypt.email.ui.activity
import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import android.widget.Toast
import androidx.activity.OnBackPressedCallback
import androidx.activity.enableEdgeToEdge
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import androidx.navigation.NavHostController
import androidx.navigation.ui.AppBarConfiguration
import com.flowcrypt.email.Constants
import com.flowcrypt.email.R
import com.flowcrypt.email.api.email.model.AttachmentInfo
import com.flowcrypt.email.api.email.model.IncomingMessageInfo
import com.flowcrypt.email.api.email.model.ServiceInfo
import com.flowcrypt.email.api.retrofit.response.base.Result
import com.flowcrypt.email.database.entity.AccountEntity
import com.flowcrypt.email.databinding.ActivityCreateMessageBinding
import com.flowcrypt.email.extensions.decrementSafely
import com.flowcrypt.email.extensions.incrementSafely
import com.flowcrypt.email.extensions.toast
import com.flowcrypt.email.model.MessageEncryptionType
import com.flowcrypt.email.model.MessageType
import com.flowcrypt.email.ui.activity.fragment.dialog.ChoosePublicKeyDialogFragment
import com.flowcrypt.email.util.FileAndDirectoryUtils
import com.flowcrypt.email.util.FlavorSettings
import java.io.File
/**
* This activity describes a logic of send encrypted or standard message.
*
* @author Denys Bondarenko
*/
class CreateMessageActivity : BaseActivity<ActivityCreateMessageBinding>(),
ChoosePublicKeyDialogFragment.OnLoadKeysProgressListener {
override fun inflateBinding(inflater: LayoutInflater): ActivityCreateMessageBinding =
ActivityCreateMessageBinding.inflate(layoutInflater)
override fun initAppBarConfiguration(): AppBarConfiguration {
return AppBarConfiguration(topLevelDestinationIds = emptySet(), fallbackOnNavigateUpListener = {
if (navController.navigateUp()) {
true
} else {
finish()
false
}
})
}
override val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (navController.currentDestination?.id == R.id.createMessageFragment) {
onBackPressed()
} else {
navController.navigateUp()
}
}
private fun onBackPressed() {
isEnabled = false
onBackPressedDispatcher.onBackPressed()
}
}
override fun onCreate(savedInstanceState: Bundle?) {
enableEdgeToEdge()
super.onCreate(savedInstanceState)
(navController as? NavHostController)?.enableOnBackPressed(true)
isNavigationArrowDisplayed = true
val navGraph = navController.navInflater.inflate(R.navigation.create_msg_graph)
navController.setGraph(navGraph, intent.extras)
FileAndDirectoryUtils.cleanDir(File(cacheDir, Constants.DRAFT_CACHE_DIR))
applyInsetsToSupportEdgeToEdge()
}
override fun onAccountInfoRefreshed(accountEntity: AccountEntity?) {
super.onAccountInfoRefreshed(accountEntity)
//check create a message from extra info when account didn't setup
if (activeAccount == null) {
toast(R.string.setup_app, Toast.LENGTH_LONG)
finish()
startActivity(Intent(this, MainActivity::class.java))
}
}
override fun onLoadKeysProgress(status: Result.Status) {
if (status == Result.Status.LOADING) {
FlavorSettings.getCountingIdlingResource().incrementSafely(this@CreateMessageActivity)
} else {
FlavorSettings.getCountingIdlingResource().decrementSafely(this@CreateMessageActivity)
}
}
fun applyInsetsToSupportEdgeToEdge() {
ViewCompat.setOnApplyWindowInsetsListener(binding.root) { _, insets ->
val bars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
binding.appBarLayout.updatePadding(top = bars.top)
binding.root.updatePadding(bottom = bars.bottom)
insets
}
}
companion object {
fun generateIntent(
context: Context?,
@MessageType messageType: Int,
msgEncryptionType: MessageEncryptionType = MessageEncryptionType.ENCRYPTED,
msgInfo: IncomingMessageInfo? = null,
attachments: Array<AttachmentInfo>? = null,
serviceInfo: ServiceInfo? = null
): Intent {
val intent = Intent(context, CreateMessageActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK
intent.putExtra("incomingMessageInfo", msgInfo)
intent.putExtra("attachments", attachments)
intent.putExtra("messageType", messageType)
intent.putExtra("encryptedByDefault", msgEncryptionType == MessageEncryptionType.ENCRYPTED)
intent.putExtra("serviceInfo", serviceInfo)
return intent
}
}
}