Skip to content

Commit

Permalink
Merge pull request #394 from jorgeblacio/fix_for_release_16.4
Browse files Browse the repository at this point in the history
Fix crash on reply with atachments, also removed all non resource text and now using native image picker for profile
  • Loading branch information
danieltigse authored Feb 1, 2019
2 parents 3b665fd + 4171770 commit 246e281
Show file tree
Hide file tree
Showing 37 changed files with 128 additions and 105 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 45
versionName "0.16.3"
versionCode 46
versionName "0.16.4"
applicationId "com.criptext.mail"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
Expand Down
22 changes: 16 additions & 6 deletions src/main/kotlin/com/criptext/mail/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,13 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {

override fun launchExternalActivityForResult(params: ExternalActivityParams) {
when(params){
is ExternalActivityParams.ProfileImagePicker -> {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
type = "image/*"
}
startActivityForResult(intent, FilePickerConst.REQUEST_CODE_PHOTO)
}
is ExternalActivityParams.FilePicker -> {
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
addCategory(Intent.CATEGORY_OPENABLE)
Expand All @@ -380,12 +387,15 @@ abstract class BaseActivity: PinCompatActivity(), IHostActivity {
startActivityForResult(intent, FilePickerConst.REQUEST_CODE_DOC)
}
is ExternalActivityParams.ImagePicker -> {
FilePickerBuilder.getInstance()
.enableVideoPicker(true)
.setMaxCount(params.remaining)
.setActivityTheme(R.style.AppTheme)
.enableCameraSupport(false)
.pickPhoto(this)
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)
}
startActivityForResult(intent, FilePickerConst.REQUEST_CODE_PHOTO)
}
is ExternalActivityParams.Camera -> {
val file = photoUtil.createImageFile()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.criptext.mail

sealed class ExternalActivityParams {
data class FilePicker(val remaining: Int): ExternalActivityParams()
class ProfileImagePicker: ExternalActivityParams()
data class ImagePicker(val remaining: Int): ExternalActivityParams()
data class PinScreen(val isFirstTime: Boolean): ExternalActivityParams()
class Camera: ExternalActivityParams()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ sealed class ActivityMessage {
val composerInputData: ComposerInputData,
val attachments: List<ComposerAttachment>, val fileKey: String?): ActivityMessage()
data class AddAttachments(val filesMetadata: List<Pair<String, Long>>): ActivityMessage()
data class ProfilePictureFile(val image: Bitmap, val path: String): ActivityMessage()
data class ProfilePictureFile(val filesMetadata: Pair<String, Long>): ActivityMessage()
data class UpdateUnreadStatusThread(val threadId: String, val unread: Boolean): ActivityMessage()
data class UpdateLabelsThread(val threadId: String, val selectedLabelIds: List<Long>): ActivityMessage()
data class UpdateThreadPreview(val threadPreview: EmailPreview): ActivityMessage()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class ComposerActivity : BaseActivity() {

private fun setNewAttachmentsAsActivityMessage(data: Intent?, filePickerConst: String?) {
when(filePickerConst){
FilePickerConst.KEY_SELECTED_MEDIA,
FilePickerConst.KEY_SELECTED_DOCS -> {
if(data != null) {
val clipData = data.clipData
Expand Down Expand Up @@ -105,16 +106,6 @@ class ComposerActivity : BaseActivity() {
}
}
}
FilePickerConst.KEY_SELECTED_MEDIA -> {
if(data != null) {
val selectedAttachments = data.getStringArrayListExtra(filePickerConst)
val attachmentsList = selectedAttachments.map {
val size = File(it).length()
Pair(it, size)
}
setActivityMessage(ActivityMessage.AddAttachments(attachmentsList))
}
}
PhotoUtil.KEY_PHOTO_TAKEN -> {
val photo= photoUtil.getPhotoFileFromIntent()
if(photo != null && photo.length() != 0L)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ class ComposerController(private val storage: KeyValueStorage,
is GeneralResult.DeviceRemoved -> onDeviceRemovedRemotely(result)
is GeneralResult.ConfirmPassword -> onPasswordChangedRemotely(result)
is GeneralResult.LinkAccept -> onLinkAccept(result)
is GeneralResult.GetRemoteFile -> onGetRemoteFile(result)
}
}

Expand All @@ -197,7 +198,6 @@ class ComposerController(private val storage: KeyValueStorage,
is ComposerResult.DeleteDraft -> exitToEmailDetailScene()
is ComposerResult.UploadFile -> onUploadFile(result)
is ComposerResult.LoadInitialData -> onLoadedInitialData(result)
is ComposerResult.GetRemoteFile -> onGetRemoteFile(result)
}
}

Expand All @@ -219,9 +219,9 @@ class ComposerController(private val storage: KeyValueStorage,
}
}

private fun onGetRemoteFile(result: ComposerResult.GetRemoteFile) {
private fun onGetRemoteFile(result: GeneralResult.GetRemoteFile) {
when (result) {
is ComposerResult.GetRemoteFile.Success -> {
is GeneralResult.GetRemoteFile.Success -> {
scene.dismissPreparingFileDialog()
model.attachments.addAll(result.remoteFiles.map { ComposerAttachment(it.first, it.second, model.fileKey!!) })
scene.notifyAttachmentSetChanged()
Expand Down Expand Up @@ -438,7 +438,7 @@ class ComposerController(private val storage: KeyValueStorage,
val resolver = host.getContentResolver()
if(resolver != null) {
scene.showPreparingFileDialog()
dataSource.submitRequest(ComposerRequest.GetRemoteFile(
generalDataSource.submitRequest(GeneralRequest.GetRemoteFile(
remoteAttachments.map { it.first }, resolver)
)
}
Expand Down Expand Up @@ -474,9 +474,8 @@ class ComposerController(private val storage: KeyValueStorage,

private fun generateEmailFileKey(){
if(model.fileKey != null) return
model.fileKey = if(model.type is ComposerType.Empty) {
model.fileKey =
FileUtils.generateFileKey()
} else null
}

private fun loadInitialData() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.criptext.mail.db.KeyValueStorage
import com.criptext.mail.db.dao.EmailInsertionDao
import com.criptext.mail.db.models.ActiveAccount
import com.criptext.mail.scenes.composer.workers.*
import com.criptext.mail.utils.generaldatasource.workers.GetRemoteFileWorker
import java.io.File

/**
Expand Down Expand Up @@ -56,11 +57,6 @@ class ComposerDataSource(
userEmailAddress = activeAccount.userEmail,
signature = activeAccount.signature,
publishFn = { res -> flushResults(res) })
is ComposerRequest.GetRemoteFile -> GetRemoteFileWorker(
uris = params.uris,
contentResolver = params.contentResolver,
publishFn = { res -> flushResults(res) }
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@ sealed class ComposerRequest {
val fileKey: String?, val originalId: Long?): ComposerRequest()
class DeleteDraft(val emailId: Long): ComposerRequest()
class UploadAttachment(val filepath: String, val fileKey: String?, val filesSize: Long): ComposerRequest()
class GetRemoteFile(val uris: List<String>, val contentResolver: ContentResolver): ComposerRequest()
class LoadInitialData(val composerType: ComposerType, val emailId: Long): ComposerRequest()
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,4 @@ sealed class ComposerResult {
val message: UIMessage,
val exception: Exception): DeleteDraft()
}

sealed class GetRemoteFile : ComposerResult() {
data class Success(val remoteFiles: List<Pair<String, Long>>): GetRemoteFile()
data class Failure(
val message: UIMessage,
val exception: Exception): GetRemoteFile()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class HTMLEditText(private val richEditor: RichEditor, hint: String){
set(value) {
richEditor.html = value
}
get() = richEditor.html
get() = richEditor.html ?: ""

val view: View = richEditor

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import android.view.Gravity
import android.view.View
import android.widget.LinearLayout
import android.widget.TextView
import com.criptext.mail.BaseActivity
import com.criptext.mail.R
import com.criptext.mail.utils.UIMessage
import com.criptext.mail.utils.getLocalizedUIMessage
Expand All @@ -20,7 +21,7 @@ class MessageAndProgressDialog(val context: Context, val message: UIMessage) {
fun showDialog() {

val dialogBuilder = AlertDialog.Builder(context)
val inflater = (context as AppLockActivity).layoutInflater
val inflater = (context as BaseActivity).layoutInflater
val dialogView = inflater.inflate(R.layout.message_and_progress_dialog, null)

dialogBuilder.setView(dialogView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,20 @@ class ProfileActivity: BaseActivity(){
when(filePickerConst){
FilePickerConst.KEY_SELECTED_MEDIA -> {
if(data != null) {
val selectedAttachments = data.getStringArrayListExtra(filePickerConst)
setActivityMessage(ActivityMessage.ProfilePictureFile(
Utility.getBitmapFromFile(File(selectedAttachments.first())),
selectedAttachments.first()))
val clipData = data.clipData
if(clipData == null) {
data.data?.also { uri ->
val attachment = FileUtils.getPathAndSizeFromUri(uri, contentResolver, this)
if (attachment != null)
setActivityMessage(ActivityMessage.ProfilePictureFile(attachment))
}
}
}
}
PhotoUtil.KEY_PHOTO_TAKEN -> {
val photo= photoUtil.getPhotoFileFromIntent()
if(photo != null && photo.length() != 0L)
setActivityMessage(ActivityMessage.ProfilePictureFile(Utility.getBitmapFromFile(photo), photo.path))
setActivityMessage(ActivityMessage.ProfilePictureFile(Pair(photo.absolutePath, photo.length())))
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.criptext.mail.scenes.signin.data.LinkStatusData
import com.criptext.mail.utils.KeyboardManager
import com.criptext.mail.utils.PinLockUtils
import com.criptext.mail.utils.UIMessage
import com.criptext.mail.utils.Utility
import com.criptext.mail.utils.generaldatasource.data.GeneralRequest
import com.criptext.mail.utils.generaldatasource.data.GeneralResult
import com.criptext.mail.utils.generaldatasource.data.UserDataWriter
Expand All @@ -36,6 +37,7 @@ import com.squareup.picasso.Callback
import com.squareup.picasso.Picasso
import com.squareup.picasso.NetworkPolicy
import com.squareup.picasso.MemoryPolicy
import java.io.File
import java.lang.Exception


Expand All @@ -60,6 +62,7 @@ class ProfileController(
is GeneralResult.LinkAccept -> onLinkAccept(result)
is GeneralResult.SyncAccept -> onSyncAccept(result)
is GeneralResult.ChangeContactName -> onContactNameChanged(result)
is GeneralResult.GetRemoteFile -> onGetRemoteFile(result)
}
}

Expand Down Expand Up @@ -101,7 +104,7 @@ class ProfileController(
override fun onNewGalleryPictureRequested() {
scene.showProfilePictureProgress()
PinLockUtils.setPinLockTimeout(PinLockUtils.TIMEOUT_TO_DISABLE)
host.launchExternalActivityForResult(ExternalActivityParams.ImagePicker(1))
host.launchExternalActivityForResult(ExternalActivityParams.ProfileImagePicker())
}

override fun onDeletePictureRequested() {
Expand Down Expand Up @@ -252,30 +255,57 @@ class ProfileController(
}
}

private fun onGetRemoteFile(result: GeneralResult.GetRemoteFile) {
when (result) {
is GeneralResult.GetRemoteFile.Success -> {
scene.dismissPreparingFileDialog()
setBitmapOnProfileImage(result.remoteFiles.first().first)
}
}
}

override fun onStop() {
websocketEvents.clearListener(webSocketEventListener)
}

private fun setBitmapOnProfileImage(imagePath: String){
val file = File(imagePath)
val bitmapImage = Utility.getBitmapFromFile(file)

scene.showProfilePictureProgress()
val exif = ExifInterface(file.path)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1)
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.postRotate(90f)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.postRotate(180f)
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
else -> {
}
}
val rotatedBitmap = Bitmap.createBitmap(bitmapImage, 0, 0,
bitmapImage.width, bitmapImage.height, matrix, true)
dataSource.submitRequest(ProfileRequest.SetProfilePicture(rotatedBitmap))
scene.updateProfilePicture(rotatedBitmap)
}

private fun handleActivityMessage(activityMessage: ActivityMessage?): Boolean {
PinLockUtils.resetLastMillisPin()
PinLockUtils.setPinLockTimeoutPosition(storage.getInt(KeyValueStorage.StringKey.PINTimeout, 1))
if (activityMessage is ActivityMessage.ProfilePictureFile) {
scene.showProfilePictureProgress()
val exif = ExifInterface(activityMessage.path)
val orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 1)
val matrix = Matrix()
when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> matrix.postRotate(90f)
ExifInterface.ORIENTATION_ROTATE_180 -> matrix.postRotate(180f)
ExifInterface.ORIENTATION_ROTATE_270 -> matrix.postRotate(270f)
else -> {
return if(activityMessage.filesMetadata.second != -1L) {
setBitmapOnProfileImage(activityMessage.filesMetadata.first)
true
}else{
val resolver = host.getContentResolver()
if(resolver != null) {
scene.showPreparingFileDialog()
generalDataSource.submitRequest(GeneralRequest.GetRemoteFile(
listOf(activityMessage.filesMetadata.first), resolver)
)
}
true
}
val rotatedBitmap = Bitmap.createBitmap(activityMessage.image, 0, 0,
activityMessage.image.width, activityMessage.image.height, matrix, true)
dataSource.submitRequest(ProfileRequest.SetProfilePicture(rotatedBitmap))
scene.updateProfilePicture(rotatedBitmap)
return true
}
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.widget.TextView
import android.widget.Toast
import com.criptext.mail.R
import com.criptext.mail.api.models.DeviceInfo
import com.criptext.mail.scenes.settings.privacyandsecurity.pinscreen.MessageAndProgressDialog
import com.criptext.mail.scenes.settings.profile.ui.BottomDialog
import com.criptext.mail.scenes.settings.profile.ui.ProfileNameDialog
import com.criptext.mail.utils.*
Expand All @@ -34,11 +35,14 @@ interface ProfileScene{
fun resetProfilePicture(name: String)
fun showProfilePictureProgress()
fun hideProfilePictureProgress()
fun showPreparingFileDialog()
fun dismissPreparingFileDialog()

class Default(val view: View): ProfileScene{
private lateinit var profileUIObserver: ProfileUIObserver

private val context = view.context
private val preparingFileDialog = MessageAndProgressDialog(context, UIMessage(R.string.preparing_file))


private val backButton: ImageView by lazy {
Expand Down Expand Up @@ -145,6 +149,14 @@ interface ProfileScene{
profilePictureLoading.visibility = View.GONE
}

override fun showPreparingFileDialog() {
preparingFileDialog.showDialog()
}

override fun dismissPreparingFileDialog() {
preparingFileDialog.dismiss()
}

override fun showMessage(message: UIMessage) {
val duration = Toast.LENGTH_LONG
val toast = Toast.makeText(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,11 @@ class GeneralDataSource(override val runner: WorkRunner,
storage = storage,
publishFn = { res -> flushResults(res) }
)
is GeneralRequest.GetRemoteFile -> GetRemoteFileWorker(
uris = params.uris,
contentResolver = params.contentResolver,
publishFn = { res -> flushResults(res) }
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ sealed class GeneralRequest {
data class SyncDenied(val trustedDeviceInfo: DeviceInfo.TrustedDeviceInfo): GeneralRequest()
data class ResendEmail(val emailId: Long, val position: Int): GeneralRequest()
data class ChangeContactName(val fullName: String, val recipientId: String) : GeneralRequest()
class GetRemoteFile(val uris: List<String>, val contentResolver: ContentResolver): GeneralRequest()
}
Loading

0 comments on commit 246e281

Please sign in to comment.