Commit 8bd4a150 authored by Adrien Béraud's avatar Adrien Béraud
Browse files

conversation: cleanup

Change-Id: I05050b3c73ddfe62e0e31c7c13f5280f08c2e9c8
parent db218d66
......@@ -593,12 +593,10 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
private fun writeToFile(data: Uri) {
val path = mCurrentFileAbsolutePath ?: return
val cr = context?.contentResolver ?: return
val input = File(path)
mCompositeDisposable.add(
copyFileToUri(cr, input, data)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ Toast.makeText(context, R.string.file_saved_successfully, Toast.LENGTH_SHORT).show() })
{ Toast.makeText(context, R.string.generic_error, Toast.LENGTH_SHORT).show() })
mCompositeDisposable.add(copyFileToUri(cr, File(path), data)
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ Toast.makeText(context, R.string.file_saved_successfully, Toast.LENGTH_SHORT).show() })
{ Toast.makeText(context, R.string.generic_error, Toast.LENGTH_SHORT).show() })
}
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<String>, grantResults: IntArray) {
......@@ -753,16 +751,6 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
presenter.pause()
}
override fun onPause() {
super.onPause()
//presenter.pause();
}
override fun onResume() {
super.onResume()
//presenter.resume(mIsBubble);
}
override fun onDestroy() {
mCompositeDisposable.dispose()
super.onDestroy()
......@@ -997,16 +985,16 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu)
val visible = binding!!.cvMessageInput.visibility == View.VISIBLE
if (mAudioCallBtn != null) mAudioCallBtn!!.isVisible = visible
if (mVideoCallBtn != null) mVideoCallBtn!!.isVisible = visible
mAudioCallBtn?.isVisible = visible
mVideoCallBtn?.isVisible = visible
}
override fun switchToUnknownView(contactDisplayName: String) {
override fun switchToUnknownView(name: String) {
binding?.apply {
cvMessageInput.visibility = View.GONE
unknownContactPrompt.visibility = View.VISIBLE
trustRequestPrompt.visibility = View.GONE
tvTrustRequestMessage.text = String.format(getString(R.string.message_contact_not_trusted), contactDisplayName)
tvTrustRequestMessage.text = getString(R.string.message_contact_not_trusted, name)
trustRequestMessageLayout.visibility = View.VISIBLE
currentBottomView = unknownContactPrompt
}
......@@ -1014,12 +1002,12 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
updateListPadding()
}
override fun switchToIncomingTrustRequestView(contactDisplayName: String) {
override fun switchToIncomingTrustRequestView(name: String) {
binding?.apply {
cvMessageInput.visibility = View.GONE
unknownContactPrompt.visibility = View.GONE
trustRequestPrompt.visibility = View.VISIBLE
tvTrustRequestMessage.text = String.format(getString(R.string.message_contact_not_trusted_yet), contactDisplayName)
tvTrustRequestMessage.text = getString(R.string.message_contact_not_trusted_yet, name)
trustRequestMessageLayout.visibility = View.VISIBLE
currentBottomView = trustRequestPrompt
}
......@@ -1051,6 +1039,7 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
requireActivity().invalidateOptionsMenu()
updateListPadding()
}
override fun switchToEndedView() {
binding?.apply {
cvMessageInput.visibility = View.GONE
......@@ -1077,13 +1066,13 @@ class ConversationFragment : BaseSupportFragment<ConversationPresenter, Conversa
}
private fun setLoading(isLoading: Boolean) {
if (binding == null) return
val binding = binding ?: return
if (isLoading) {
binding!!.btnTakePicture.visibility = View.GONE
binding!!.pbDataTransfer.visibility = View.VISIBLE
binding.btnTakePicture.visibility = View.GONE
binding.pbDataTransfer.visibility = View.VISIBLE
} else {
binding!!.btnTakePicture.visibility = View.VISIBLE
binding!!.pbDataTransfer.visibility = View.GONE
binding.btnTakePicture.visibility = View.VISIBLE
binding.pbDataTransfer.visibility = View.GONE
}
}
......
......@@ -392,14 +392,14 @@ class TvConversationFragment : BaseSupportFragment<ConversationPresenter, Conver
* @param currentFile DataTransfer of the file that is going to be stored
* @param fileAbsolutePath absolute path of the file we want to save
*/
override fun startSaveFile(currentFile: DataTransfer, fileAbsolutePath: String) {
override fun startSaveFile(file: DataTransfer, fileAbsolutePath: String) {
mCurrentFileAbsolutePath = fileAbsolutePath
try {
// Use Android Storage File Access to download the file
val downloadFileIntent = Intent(Intent.ACTION_CREATE_DOCUMENT)
downloadFileIntent.type = getMimeTypeFromExtension(currentFile.extension)
downloadFileIntent.type = getMimeTypeFromExtension(file.extension)
downloadFileIntent.addCategory(Intent.CATEGORY_OPENABLE)
downloadFileIntent.putExtra(Intent.EXTRA_TITLE, currentFile.displayName)
downloadFileIntent.putExtra(Intent.EXTRA_TITLE, file.displayName)
startActivityForResult(downloadFileIntent, REQUEST_CODE_SAVE_FILE)
} catch (e: Exception) {
Log.i(TAG, "No app detected for saving files.")
......@@ -408,7 +408,7 @@ class TvConversationFragment : BaseSupportFragment<ConversationPresenter, Conver
if (!directory.exists()) {
directory.mkdirs()
}
writeToFile(Uri.fromFile(File(directory, currentFile.displayName)))
writeToFile(Uri.fromFile(File(directory, file.displayName)))
}
}
......
......@@ -40,7 +40,7 @@ interface ConversationView {
fun goToCallActivityWithResult(accountId: String, conversationUri: Uri, contactUri: Uri, withCamera: Boolean)
fun goToContactActivity(accountId: String, uri: Uri)
fun switchToUnknownView(name: String)
fun switchToIncomingTrustRequestView(message: String)
fun switchToIncomingTrustRequestView(name: String)
fun switchToConversationView()
fun switchToSyncingView()
fun switchToEndedView()
......@@ -57,7 +57,7 @@ interface ConversationView {
fun setLastDisplayed(interaction: Interaction)
fun setConversationColor(integer: Int)
fun setConversationSymbol(symbol: CharSequence)
fun startSaveFile(currentFile: DataTransfer, fileAbsolutePath: String)
fun startSaveFile(file: DataTransfer, fileAbsolutePath: String)
fun startShareLocation(accountId: String, contactId: String)
fun showMap(accountId: String, contactId: String, open: Boolean)
fun hideMap()
......
......@@ -1223,8 +1223,7 @@ class AccountService(
if (request == null)
request = TrustRequest(accountId, fromUri, received * 1000L, message, conversationId)
else request.vCard = Ezvcard.parse(message).first()
val vcard = request.vCard
if (vcard != null) {
request.vCard?.let { vcard ->
val contact = account.getContactFromCache(fromUri)
if (!contact.detailsLoaded) {
// VCardUtils.savePeerProfileToDisk(vcard, accountId, from + ".vcf", mDeviceRuntimeService.provideFilesDir());
......@@ -1312,32 +1311,26 @@ class AccountService(
val authorUri = Uri.fromId(author)
val timestamp = message["timestamp"]!!.toLong() * 1000
val contact = conversation.findContact(authorUri) ?: account.getContactFromCache(authorUri)
var interaction: Interaction
when (type) {
"initial" -> {
if (conversation.mode.blockingFirst() == Conversation.Mode.OneToOne) {
val interaction: Interaction = when (type) {
"initial" -> if (conversation.mode.blockingFirst() == Conversation.Mode.OneToOne) {
val invited = message["invited"]!!
var invitedContact = conversation.findContact(Uri.fromId(invited))
if (invitedContact == null) {
invitedContact = account.getContactFromCache(invited)
}
invitedContact.addedDate = Date(timestamp)
interaction = ContactEvent(invitedContact).setEvent(ContactEvent.Event.fromConversationAction("add"))
ContactEvent(invitedContact).setEvent(ContactEvent.Event.fromConversationAction("add"))
} else {
interaction = Interaction(conversation, Interaction.InteractionType.INVALID)
Interaction(conversation, Interaction.InteractionType.INVALID)
}
}
"member" -> {
val action = message["action"]!!
val uri = message["uri"]!!
var member = conversation.findContact(Uri.fromId(uri))
if (member == null) {
member = account.getContactFromCache(uri)
}
val member = conversation.findContact(Uri.fromId(uri)) ?: account.getContactFromCache(uri)
member.addedDate = Date(timestamp)
interaction = ContactEvent(member).setEvent(ContactEvent.Event.fromConversationAction(action))
ContactEvent(member).setEvent(ContactEvent.Event.fromConversationAction(action))
}
"text/plain" -> interaction = TextMessage(author, account.accountId, timestamp, conversation, message["body"]!!, !contact.isUser)
"text/plain" -> TextMessage(author, account.accountId, timestamp, conversation, message["body"]!!, !contact.isUser)
"application/data-transfer+json" -> {
try {
val fileName = message["displayName"]!!
......@@ -1352,22 +1345,22 @@ class AccountService(
totalA[0] = message["totalSize"]!!.toLong()
}
val path = File(paths[0]!!)
interaction = DataTransfer(fileId, account.accountId, author, fileName, contact.isUser, timestamp, totalA[0], progressA[0])
interaction.daemonPath = path
val isComplete = path.exists() && progressA[0] == totalA[0]
Log.w(TAG, "add DataTransfer at " + paths[0] + " with progress " + progressA[0] + "/" + totalA[0])
interaction.status = if (isComplete) InteractionStatus.TRANSFER_FINISHED else InteractionStatus.FILE_AVAILABLE
//}
DataTransfer(fileId, account.accountId, author, fileName, contact.isUser, timestamp, totalA[0], progressA[0]).apply {
daemonPath = path
status = if (isComplete) InteractionStatus.TRANSFER_FINISHED else InteractionStatus.FILE_AVAILABLE
}
} catch (e: Exception) {
interaction = Interaction(conversation, Interaction.InteractionType.INVALID)
Interaction(conversation, Interaction.InteractionType.INVALID)
}
}
"application/call-history+json" -> {
interaction = Call(null, account.accountId, authorUri.rawUriString, if (contact.isUser) Call.Direction.OUTGOING else Call.Direction.INCOMING,timestamp)
interaction.duration = message["duration"]!!.toLong()
}
"merge" -> interaction = Interaction(conversation, Interaction.InteractionType.INVALID)
else -> interaction = Interaction(conversation, Interaction.InteractionType.INVALID)
"application/call-history+json" ->
Call(null, account.accountId, authorUri.rawUriString, if (contact.isUser) Call.Direction.OUTGOING else Call.Direction.INCOMING,timestamp).apply {
duration = message["duration"]!!.toLong()
}
"merge" -> Interaction(conversation, Interaction.InteractionType.INVALID)
else -> Interaction(conversation, Interaction.InteractionType.INVALID)
}
interaction.contact = contact
interaction.setSwarmInfo(conversation.uri.rawRingId, id, if (StringUtils.isEmpty(parent)) null else parent)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment