Skip to content

Commit

Permalink
Merge pull request #401 from jorgeblacio/release_16_7
Browse files Browse the repository at this point in the history
Various fixes.
  • Loading branch information
danieltigse authored Feb 14, 2019
2 parents 1e3c3c7 + 3f6c35c commit 2342044
Show file tree
Hide file tree
Showing 22 changed files with 98 additions and 69 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ android {
defaultConfig {
minSdkVersion 21
targetSdkVersion 28
versionCode 48
versionName "0.16.6"
versionCode 49
versionName "0.16.7"
applicationId "com.criptext.mail"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
36 changes: 17 additions & 19 deletions src/main/kotlin/com/criptext/mail/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ import droidninja.filepicker.FilePickerBuilder
import droidninja.filepicker.FilePickerConst
import uk.co.chrisjenx.calligraphy.CalligraphyContextWrapper
import java.io.File
import java.lang.Exception
import java.util.*


Expand Down Expand Up @@ -145,7 +146,11 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
}else{
model = cacheModel
}
controller = initController(model)
try {
controller = initController(model)
} catch (ex: Exception) {
restartApplication()
}
}

override fun onStart() {
Expand Down Expand Up @@ -206,7 +211,7 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
is EmailDetailParams -> EmailDetailSceneModel(params.threadId,
params.currentLabel, params.threadPreview, params.doReply)
is ComposerParams -> ComposerModel(params.type)
is SettingsParams -> SettingsModel()
is SettingsParams -> SettingsModel(params.hasChangedTheme)
is SignatureParams -> SignatureModel(params.recipientId)
is RecoveryEmailParams -> RecoveryEmailModel(params.isConfirmed, params.recoveryEmail)
is ChangePasswordParams -> ChangePasswordModel()
Expand Down Expand Up @@ -324,23 +329,19 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
return IntentExtrasData.IntentExtrasSend(intent.action, listOf(attachment))
}
}else{
if(clipData.itemCount < EmailUtils.ATTACHMENT_LIMIT) {
val attachmentList = mutableListOf<Pair<String, Long>>()
for (i in 0 until clipData.itemCount) {
clipData.getItemAt(i).also { item ->
if (item.uri != null) {
val attachment = FileUtils.getPathAndSizeFromUri(item.uri,
contentResolver, this)
if (attachment != null)
attachmentList.add(attachment)
}
val attachmentList = mutableListOf<Pair<String, Long>>()
for (i in 0 until clipData.itemCount) {
clipData.getItemAt(i).also { item ->
if (item.uri != null) {
val attachment = FileUtils.getPathAndSizeFromUri(item.uri,
contentResolver, this)
if (attachment != null)
attachmentList.add(attachment)
}
}
if (attachmentList.isNotEmpty())
return IntentExtrasData.IntentExtrasSend(intent.action, attachmentList)
}else{
return IntentExtrasData.IntentErrorMessage(Intent.ACTION_APP_ERROR, UIMessage(R.string.too_many_files))
}
if (attachmentList.isNotEmpty())
return IntentExtrasData.IntentExtrasSend(intent.action, attachmentList)
}
}
}
Expand Down Expand Up @@ -381,7 +382,6 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
putExtra("remaining", params.remaining)
type = "*/*"
}
startActivityForResult(intent, FilePickerConst.REQUEST_CODE_DOC)
Expand All @@ -390,7 +390,6 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true)
putExtra("remaining", params.remaining)
val mimeTypes = arrayOf("image/*", "video/*")
type = "*/*"
putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes)
Expand Down Expand Up @@ -488,7 +487,6 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {

override fun setAppTheme(themeResource: Int) {
setTheme(themeResource)
recreate()
}

override fun contextMenuRegister(view: View) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/com/criptext/mail/ExternalActivityParams.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.criptext.mail


sealed class ExternalActivityParams {
data class FilePicker(val remaining: Int): ExternalActivityParams()
class FilePicker: ExternalActivityParams()
class ProfileImagePicker: ExternalActivityParams()
data class ImagePicker(val remaining: Int): ExternalActivityParams()
class ImagePicker: ExternalActivityParams()
data class PinScreen(val isFirstTime: Boolean): ExternalActivityParams()
class Camera: ExternalActivityParams()
class InviteFriend: ExternalActivityParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,15 @@ class UpdateMailboxWorker(
newData["name"] = dbEvents.getFromContactByEmailId(email.id)[0].name
newData["email"] = dbEvents.getFromContactByEmailId(email.id)[0].email
val emailAddress = newData["email"]
val bm = if(emailAddress != null && EmailAddressUtils.isFromCriptextDomain(emailAddress))
val bm = try {
if(emailAddress != null && EmailAddressUtils.isFromCriptextDomain(emailAddress))
Picasso.get().load(Hosts.restApiBaseUrl
.plus("/user/avatar/${EmailAddressUtils.extractRecipientIdFromCriptextAddress(emailAddress)}")).get()
else
.plus("/user/avatar/${EmailAddressUtils.extractRecipientIdFromCriptextAddress(emailAddress)}")).get()
else
null
} catch (ex: Exception){
null
}

if(shouldCallAgain) {
PushResult.UpdateMailbox.SuccessAndRepeat(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,22 +87,17 @@ class ComposerActivity : BaseActivity() {
setActivityMessage(ActivityMessage.AddAttachments(listOf(attachment)))
}
}else{
val remaining = data.getIntExtra("remaining", 0)
if(clipData.itemCount < remaining) {
val attachmentList = mutableListOf<Pair<String, Long>>()
for (i in 0 until clipData.itemCount) {
clipData.getItemAt(i).also { item ->
val attachment = FileUtils.getPathAndSizeFromUri(item.uri, contentResolver,
this)
if (attachment != null)
attachmentList.add(attachment)
}
val attachmentList = mutableListOf<Pair<String, Long>>()
for (i in 0 until clipData.itemCount) {
clipData.getItemAt(i).also { item ->
val attachment = FileUtils.getPathAndSizeFromUri(item.uri, contentResolver,
this)
if (attachment != null)
attachmentList.add(attachment)
}
if (attachmentList.isNotEmpty())
setActivityMessage(ActivityMessage.AddAttachments(attachmentList))
}else{
setActivityMessage(ActivityMessage.ShowUIMessage(UIMessage(R.string.too_many_files)))
}
if (attachmentList.isNotEmpty())
setActivityMessage(ActivityMessage.AddAttachments(attachmentList))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,12 @@ class ComposerController(private val storage: KeyValueStorage,

override fun onNewFileAttachmentRequested() {
PinLockUtils.setPinLockTimeout(PinLockUtils.TIMEOUT_TO_DISABLE)
val remaining = EmailUtils.ATTACHMENT_LIMIT - model.attachments.size
host.launchExternalActivityForResult(ExternalActivityParams.FilePicker(remaining))
host.launchExternalActivityForResult(ExternalActivityParams.FilePicker())
}

override fun onNewGalleryAttachmentRequested() {
PinLockUtils.setPinLockTimeout(PinLockUtils.TIMEOUT_TO_DISABLE)
val remaining = EmailUtils.ATTACHMENT_LIMIT - model.attachments.size
host.launchExternalActivityForResult(ExternalActivityParams.ImagePicker(remaining))
host.launchExternalActivityForResult(ExternalActivityParams.ImagePicker())
}

override fun sendDialogButtonPressed() {
Expand Down Expand Up @@ -155,10 +153,7 @@ class ComposerController(private val storage: KeyValueStorage,
override fun onAttachmentButtonClicked() {
if(host.checkPermissions(BaseActivity.RequestCode.writeAccess.ordinal,
Manifest.permission.WRITE_EXTERNAL_STORAGE)){
if(model.attachments.size < EmailUtils.ATTACHMENT_LIMIT)
scene.showAttachmentsBottomDialog(this)
else
scene.showError(UIMessage(R.string.attachment_limit_reached, arrayOf(EmailUtils.ATTACHMENT_LIMIT)))
scene.showAttachmentsBottomDialog(this)
}
}

Expand Down Expand Up @@ -260,7 +255,7 @@ class ComposerController(private val storage: KeyValueStorage,
}
is ComposerResult.UploadFile.MaxFilesExceeds -> {
removeAttachmentByPath(result.filepath)
scene.showMaxFilesExceedsDialog()
model.filesExceedingMaxEmailSize.add(FileUtils.getName(result.filepath))
handleNextUpload()
}
is ComposerResult.UploadFile.PayloadTooLarge -> {
Expand Down Expand Up @@ -453,9 +448,14 @@ class ComposerController(private val storage: KeyValueStorage,
return
}
val attachmentToUpload = model.attachments.firstOrNull { it.uploadProgress == -1 } ?: return
val composerAttachment = getAttachmentByPath(attachmentToUpload.filepath) ?: return
composerAttachment.uploadProgress = 0
uploadSelectedFile(attachmentToUpload.filepath, composerAttachment.fileKey)
val composerAttachment = getAttachmentByPath(attachmentToUpload.filepath)
if(composerAttachment == null){
scene.showMaxFilesExceedsDialog()
return
}else {
composerAttachment.uploadProgress = 0
uploadSelectedFile(attachmentToUpload.filepath, composerAttachment.fileKey)
}
}

private fun handleActivityMessage(activityMessage: ActivityMessage?): Boolean {
Expand Down Expand Up @@ -635,10 +635,7 @@ class ComposerController(private val storage: KeyValueStorage,
scene.showError(UIMessage(R.string.permission_filepicker_rationale))
return
}
if(model.attachments.size < EmailUtils.ATTACHMENT_LIMIT)
scene.showAttachmentsBottomDialog(observer)
else
scene.showError(UIMessage(R.string.attachment_limit_reached, arrayOf(EmailUtils.ATTACHMENT_LIMIT)))
scene.showAttachmentsBottomDialog(observer)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ class ComposerModel(val type: ComposerType) {

var attachments: ArrayList<ComposerAttachment> = ArrayList()

val filesExceedingMaxEmailSize = mutableListOf<String>()
val filesExceedingMaxFileSize = mutableListOf<Pair<String, String>>()

var isUploadingAttachments = false

val to = LinkedList<Contact>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ interface ComposerScene {
override fun showMaxFilesExceedsDialog(){
val builder = AlertDialog.Builder(ctx)
val size = FileUtils.readableFileSize(EmailUtils.ATTACHMENT_SIZE_LIMIT.toLong(), 1000)
builder.setTitle(ctx.resources.getString(R.string.error_attach_file))
builder.setTitle(ctx.resources.getString(R.string.error_email_max_files_title))
.setMessage(ctx.resources.getString(R.string.error_email_max_size, size))
.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ class EmailDetailActivity: BaseActivity() {
when (result.type) {
WebView.HitTestResult.IMAGE_TYPE,
WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE -> {
val inflater = menuInflater
inflater.inflate(R.menu.web_view_image_menu, menu)
(controller as EmailDetailSceneController).onCreateContextMenu(result.extra)
if(result.extra != null && result.extra!!.startsWith("file://")) {
val inflater = menuInflater
inflater.inflate(R.menu.web_view_image_menu, menu)
(controller as EmailDetailSceneController).onCreateContextMenu(result.extra)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class FullEmailListAdapter(private val mContext : Context,
return if(isExpanded) fullEmails.size + 2 else MAX_SIZE_FOR_COLLAPSE
}

fun getEmailsSize(): Int{
return fullEmails.size
}

override fun getItemId(position: Int): Long {
if(isPositionFooter(position)) {
return -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class FullEmailHolder(view: View) : ParentEmailHolder(view) {

showStartGuideMenu(emailListener, fullEmail)

setAttachments(fileDetails, emailListener)
setAttachments(fileDetails, emailListener, adapter)

emailListener?.contextMenuRegister(bodyWebView)

Expand Down Expand Up @@ -277,13 +277,22 @@ class FullEmailHolder(view: View) : ParentEmailHolder(view) {
setIcons(fullEmail.email.delivered)
}

private fun setAttachments(files: List<FileDetail>, emailListener: FullEmailListAdapter.OnFullEmailEventListener?){
private fun setAttachments(files: List<FileDetail>, emailListener: FullEmailListAdapter.OnFullEmailEventListener?,
fullEmailListAdapter: FullEmailListAdapter){
val nonInlineFiles = files.filter { it.file.cid == null }
val adapter = FileListAdapter(view.context, nonInlineFiles)
val mLayoutManager = LinearLayoutManager(view.context)
adapter.observer = object: AttachmentViewObserver {
override fun onAttachmentViewClick(position: Int) {
emailListener?.onAttachmentSelected(adapterPosition - 1, position)
val emailPosition = if(!fullEmailListAdapter.isExpanded) {
if(adapterPosition == 1)
adapterPosition - 1
else
fullEmailListAdapter.getEmailsSize() - 1
} else {
adapterPosition - 1
}
emailListener?.onAttachmentSelected(emailPosition, position)
}
override fun onRemoveAttachmentClicked(position: Int) {}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package com.criptext.mail.scenes.params

import com.criptext.mail.scenes.settings.SettingsActivity

class SettingsParams: SceneParams(){
class SettingsParams(val hasChangedTheme: Boolean = false): SceneParams(){
override val activityClass = SettingsActivity::class.java
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ class SettingsController(
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
host.setAppTheme(R.style.AppTheme)
}
host.exitToScene(SettingsParams(true), null, false, true)
}

override fun onResendDeviceLinkAuth() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.criptext.mail.scenes.label_chooser.data.LabelWrapper
import com.criptext.mail.scenes.settings.devices.DeviceItem
import com.criptext.mail.validation.FormInputState

class SettingsModel{
class SettingsModel(var hasChangedTheme: Boolean = false){
var fullName: String = ""
var signature: String = ""
val labels : ArrayList<LabelWrapper> = ArrayList()
Expand All @@ -20,7 +20,6 @@ class SettingsModel{
var hasReadReceipts: Boolean = false
var recoveryEmail: String = ""
var replyToEmail: String? = null
var hasChangedTheme: Boolean = false

var isWaitingForSync = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ interface SettingsScene{
fun dismissSyncBeginDialog()
fun dismissReplyToEmailDialog()
fun syncBeginDialogDenied()
fun clearThemeSwitchListener()


var settingsUIObserver: SettingsUIObserver?
Expand Down Expand Up @@ -273,6 +274,10 @@ interface SettingsScene{
generalView.enable2FASwitch(true)
}

override fun clearThemeSwitchListener() {
generalView.disableDarkThemeSwitch()
}

override fun enableTwoFASwitch(isEnabled: Boolean) {
generalView.enable2FASwitch(isEnabled)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ class GeneralSettingsView(view: View, title: String): TabView(view, title) {
setSwitchListener()
}

fun disableDarkThemeSwitch(){
darkThemeSwitch.setOnCheckedChangeListener { _, _ -> }
}

fun setDarkTheme(hasDarkTheme: Boolean){
darkThemeSwitch.setOnCheckedChangeListener { _, _ -> }
darkThemeSwitch.isChecked = hasDarkTheme
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/com/criptext/mail/utils/Utility.kt
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ class Utility {

private fun getAvatarLetters(fullName: String): String{
val cleanedName = fullName.trim()
if(cleanedName.isEmpty()) return ""
val firstLetter = cleanedName.toCharArray()[0].toString().toUpperCase()
val secondLetter = if(cleanedName.contains(" "))
cleanedName[cleanedName.lastIndexOf(" ") + 1].toString().toUpperCase()
Expand Down
Loading

0 comments on commit 2342044

Please sign in to comment.