Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ android {
dependencies {

implementation fileTree(dir: "libs", include: ["*.jar"])
implementation project(":model")

implementation Dependencies.ANDROIDX_CORE
implementation Dependencies.ANDROIDX_APPCOMPAT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 2,
"identityHash": "7c2e3740a5cde0128360e518cfbe1a61",
"identityHash": "bcf38a9c9bb136e8366175e54f8e40b3",
"entities": [
{
"tableName": "accounts_table",
Expand Down Expand Up @@ -514,7 +514,7 @@
},
{
"tableName": "attachments_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `size` INTEGER NOT NULL, `mimeType` TEXT, `fileName` TEXT NOT NULL, `extension` TEXT NOT NULL, `uploadTimestamp` INTEGER NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `absolutePath` TEXT NOT NULL, PRIMARY KEY(`id`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `size` INTEGER NOT NULL, `mimeType` TEXT, `fileName` TEXT NOT NULL, `extension` TEXT NOT NULL, `uploadTimestamp` INTEGER NOT NULL, `width` INTEGER NOT NULL, `height` INTEGER NOT NULL, `downloadUrl` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -565,8 +565,94 @@
"notNull": true
},
{
"fieldPath": "absolutePath",
"columnName": "absolutePath",
"fieldPath": "downloadUrl",
"columnName": "downloadUrl",
"affinity": "TEXT",
"notNull": true
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "local_attachments_table",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` TEXT NOT NULL, `correspondingAttachmentId` TEXT NOT NULL, `correspondingMessageId` TEXT NOT NULL, `attachmentFileSize` INTEGER NOT NULL, `attachmentMimeType` TEXT, `attachmentFileName` TEXT NOT NULL, `attachmentFileExtension` TEXT NOT NULL, `remoteDownloadUrl` TEXT NOT NULL, `documentStorageType` INTEGER NOT NULL, `localFilePath` TEXT NOT NULL, `localFileName` TEXT NOT NULL, `localStorageDir` TEXT NOT NULL, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "correspondingAttachmentId",
"columnName": "correspondingAttachmentId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "correspondingMessageId",
"columnName": "correspondingMessageId",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "attachmentFileSize",
"columnName": "attachmentFileSize",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "attachmentMimeType",
"columnName": "attachmentMimeType",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "attachmentFileName",
"columnName": "attachmentFileName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "attachmentFileExtension",
"columnName": "attachmentFileExtension",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "remoteDownloadUrl",
"columnName": "remoteDownloadUrl",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "documentStorageType",
"columnName": "documentStorageType",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "localFilePath",
"columnName": "localFilePath",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "localFileName",
"columnName": "localFileName",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "localStorageDir",
"columnName": "localStorageDir",
"affinity": "TEXT",
"notNull": true
}
Expand Down Expand Up @@ -671,7 +757,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '7c2e3740a5cde0128360e518cfbe1a61')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'bcf38a9c9bb136e8366175e54f8e40b3')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ class MainActivity : BaseActivity() {
navController = Navigation.findNavController(this, R.id.container)
NavigationUI.setupWithNavController(binding.navView, navController)
(binding.navView as NavigationBarView).setOnItemReselectedListener {}
AndroidUtils.setNavigationBarColor(window, ColorUtils(this).getPrimaryContainerColor())
val colorUtils = ColorUtils(this)
binding.navView.setBackgroundColor(colorUtils.getPrimaryContainerColor())
AndroidUtils.setNavigationBarColor(window, colorUtils.getPrimaryContainerColor())
database.getLiveDataLoggedInAccount().observe(this) {
it?.let { user ->
if (user.photoUrl.isNotNull()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,15 @@ package com.adityaamolbavadekar.messenger.database.conversations
import android.content.Context
import androidx.room.*
import androidx.sqlite.db.SupportSQLiteDatabase
import com.adityaamolbavadekar.messenger.model.*
import com.adityaamolbavadekar.messenger.model.User
import com.adityaamolbavadekar.messenger.model.ConversationRecord
import com.adityaamolbavadekar.messenger.model.MessageRecord
import com.adityaamolbavadekar.messenger.model.ReactionRecord
import com.adityaamolbavadekar.messenger.model.Recipient
import com.adityaamolbavadekar.messenger.model.Attachment
import com.adityaamolbavadekar.messenger.model.LocalAttachment
import com.adityaamolbavadekar.messenger.model.ConversationRecordRecipientCrossRef
import com.adityaamolbavadekar.messenger.model.ConversationDraftMessage
import com.adityaamolbavadekar.messenger.utils.logging.InternalLogger

@Database(
Expand Down Expand Up @@ -74,6 +82,7 @@ abstract class ApplicationDatabase : RoomDatabase() {
}

private val callback = object : Callback() {

override fun onCreate(db: SupportSQLiteDatabase) {
super.onCreate(db)
InternalLogger.logD("RoomDatabase.Callback", "Database created")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,18 @@ data class Attachment(
)
}

fun from(metadata:FileMetadata,downloadUrl: String): Attachment {
return Attachment(
size = metadata.size,
fileName = metadata.name,
extension = metadata.extension,
uploadTimestamp = System.currentTimeMillis(),
width = 0,
height = 0,
downloadUrl = downloadUrl,
mimeType = metadata.mimeType)
}

fun from(uri: Uri, fileNameWithExtension: String, size: Long, mimeType: String?,downloadUrl: String): Attachment {
var fileExtension = ""
MimeTypeMap.getSingleton().getExtensionFromMimeType(mimeType)?.let {
Expand All @@ -106,9 +118,7 @@ data class Attachment(
fileNameWithExtension.subSequence(fileNameWithExtension.lastIndexOf("."), fileNameWithExtension.lastIndex).toString()
}

val fileNameString = if(fileNameWithExtension.lastIndexOf(".")!=-1)
fileNameWithExtension.subSequence(0,fileNameWithExtension.lastIndexOf(".")).toString()
else fileNameWithExtension
val fileNameString = fileNameWithExtension.substringBeforeLast(".")

return Attachment(
size = size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.*

import com.adityaamolbavadekar.messenger.R

/**
* Represents Local Database (Room) Level Conversation.
* */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.adityaamolbavadekar.messenger.model

import com.adityaamolbavadekar.messenger.R

/**
* For identifying Delivery Status of a message.
* */
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.adityaamolbavadekar.messenger.model

data class FileMetadata(
val name:String,
val nameWithoutExtension:String,
val extension:String,
val mimeType:String?,
val size:Long
)
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import androidx.room.Entity
import androidx.room.PrimaryKey
import java.util.*

import com.adityaamolbavadekar.messenger.R

@Entity(tableName = "accounts_table")
data class User(
var username: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ class ConversationActivity : ParentConversationActivity(), SearchView.OnQueryTex
}
}

initWindowInsetsImeAnimations()
//initWindowInsetsImeAnimations()
}

private fun initWindowInsetsImeAnimations() {
Expand Down Expand Up @@ -428,26 +428,18 @@ class ConversationActivity : ParentConversationActivity(), SearchView.OnQueryTex

override fun onDocumentPicked(docUri: Uri) {
super.onDocumentPicked(docUri)
InternalLogger.logI(TAG,"onDocumentPicked($docUri)")
Dialogs.showDefiniteProgressDialog(this, p = { loader, action ->
cloudStorageManager.uploadDocument(docUri,
metadata = buildStorageMetadata(),
onProgress = { progress ->
InternalLogger.debugInfo(TAG, "Upload document progress = ${progress}%")
InternalLogger.logI(TAG, "Upload document progress = ${progress}%")
action(progress)
},
onSuccess = { downloadUrl ->
val messageId = Id.get()
val map = AndroidUtils.getFileMetadata(docUri, contentResolver!!)
val mimeType = map["mimeType"] as String?
val fileNameWithExtension = (map["name"] as String)
val fileSize = map["size"] as Long
val attachment = Attachment.from(
docUri,
fileNameWithExtension,
fileSize,
mimeType,
downloadUrl
)
val fileMetadata = AndroidUtils.getFileMetadata(docUri, contentResolver!!)
val attachment = Attachment.from(fileMetadata, downloadUrl)
AndroidUtils.saveSentDocumentFile(attachment.extension,docUri, this).also { localFile ->
val localAttachment = LocalAttachment.new(
attachment,
Expand Down Expand Up @@ -494,7 +486,6 @@ class ConversationActivity : ParentConversationActivity(), SearchView.OnQueryTex
showPicturePreview(urisList)
}


companion object {
fun createNewIntent(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,32 @@ class ConversationFragment : BindingHelperFragment<ConversationFragmentBinding>(
setOnAddReplyListener { recipient, messageRecord ->
getConversationActivity().onShouldAddReply(recipient, messageRecord)
}
setOnNavigateToReplyListener { recipient, replyInfo ->
setOnNavigateToReplyListener { _, replyInfo ->
navigateToMessage(replyInfo.correspondingMessageId)
}
setOnDeletionListener(this@ConversationFragment)
setOpenDocumentListener {
val attachment = viewModel.getLocalAttachment(it.id)
Intent(Intent.ACTION_VIEW).apply {
val file = attachment.getFile()
val uri = FileProvider.getUriForFile(
requireContext(),
Constants.FILE_PROVIDER_AUTHORITY,
file
)
setDataAndType(uri, attachment.attachmentMimeType)
flags = Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_GRANT_READ_URI_PERMISSION
try {
requireContext().startActivity(this)
} catch (e: Exception) {
InternalLogger.logE(TAG, "Unable to start file open intent.", e)
Toast.makeText(
viewModel.getLocalAttachment(it.id) { attachment ->
Intent(Intent.ACTION_VIEW).apply {
val file = attachment.getFile()
val uri = FileProvider.getUriForFile(
requireContext(),
requireContext().getString(R.string.unable_to_open_file),
Toast.LENGTH_SHORT
).show()
Constants.FILE_PROVIDER_AUTHORITY,
file
)
setDataAndType(uri, attachment.attachmentMimeType)
flags =
Intent.FLAG_ACTIVITY_NEW_TASK and Intent.FLAG_GRANT_READ_URI_PERMISSION
try {
requireContext().startActivity(this)
} catch (e: Exception) {
InternalLogger.logE(TAG, "Unable to start file open intent.", e)
Toast.makeText(
requireContext(),
requireContext().getString(R.string.unable_to_open_file),
Toast.LENGTH_SHORT
).show()
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.adityaamolbavadekar.messenger.database.conversations.ApplicationDatab
import com.adityaamolbavadekar.messenger.database.conversations.DatabaseAndroidViewModel
import com.adityaamolbavadekar.messenger.managers.CloudDatabaseManager
import com.adityaamolbavadekar.messenger.managers.InternetManager
import com.adityaamolbavadekar.messenger.managers.AuthManager
import com.adityaamolbavadekar.messenger.model.*
import com.adityaamolbavadekar.messenger.notifications.NotificationData
import com.adityaamolbavadekar.messenger.notifications.NotificationSender
Expand All @@ -39,6 +40,7 @@ class ConversationViewModel(private val repo: ApplicationDatabaseRepository) : V
private var lastMessage: MessageRecord? = null
private var isObservingRemoteDatabase = false
private lateinit var conversationId: String
private val myUid: String = AuthManager().uid
private var conversationType = 0
private val _messages: MutableLiveData<List<MessageRecord>> = MutableLiveData(listOf())
val messages: LiveData<List<MessageRecord>> = _messages
Expand Down Expand Up @@ -179,7 +181,7 @@ class ConversationViewModel(private val repo: ApplicationDatabaseRepository) : V

private fun startObservingRemoteP2PData(p2pUid: String, observeStatus: Boolean = true) {
messagesManager.observeMessagesFromDatabaseV2(
me.uid, p2pUid,
myUid, p2pUid,
MessagesChildListener(this).childEventListener
)
if (observeStatus) {
Expand Down Expand Up @@ -329,9 +331,7 @@ class ConversationViewModel(private val repo: ApplicationDatabaseRepository) : V

private fun onLocalConversationDataChanged(data: ConversationWithRecipients) {
_isMessagingRestrictedForMe.postValue(
data.conversationRecord.isMessagingRestrictedForUser(
me.uid
)
data.conversationRecord.isMessagingRestrictedForUser(myUid)
)
_conversationPhoto.postValue(data.conversationRecord.photoUrl)
_conversationTitle.postValue(data.conversationRecord.title)
Expand Down Expand Up @@ -404,7 +404,7 @@ class ConversationViewModel(private val repo: ApplicationDatabaseRepository) : V
repo.insertOrUpdateLocalAttachment(attachment)
}

fun getLocalAttachment(id: String): LocalAttachment {
return repo.getLocalAttachment(id)
fun getLocalAttachment(id: String,callback:(LocalAttachment)->Unit)=viewModelScope.launch {
callback(repo.getLocalAttachment(id))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class MessagesAdapter(private val lifecycleOwner: LifecycleOwner) :
fun setConversationWithRecipients(conversationWithRecipients: ConversationWithRecipients) {
conversationRecord = conversationWithRecipients.conversationRecord
isGroup = conversationWithRecipients.conversationRecord.isGroup
if (conversationWithRecipients.recipients != null || conversationWithRecipients.recipients.isNotEmpty()) {
if (conversationWithRecipients.recipients.size > 0) {
recipients = conversationWithRecipients.recipients
}
}
Expand Down
Loading