mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
Drafts
This commit is contained in:
parent
1c92b17ecc
commit
e674f70155
@ -6,7 +6,6 @@ import android.content.res.Resources
|
||||
import android.database.Cursor
|
||||
import android.graphics.Rect
|
||||
import android.os.Bundle
|
||||
import android.util.Log
|
||||
import android.view.ActionMode
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
@ -23,6 +22,7 @@ import kotlinx.android.synthetic.main.view_input_bar_recording.*
|
||||
import kotlinx.android.synthetic.main.view_input_bar_recording.view.*
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.messaging.mentions.MentionsManager
|
||||
import org.session.libsession.utilities.Util
|
||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
|
||||
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarButton
|
||||
import org.thoughtcrime.securesms.conversation.v2.input_bar.InputBarDelegate
|
||||
@ -32,6 +32,8 @@ import org.thoughtcrime.securesms.conversation.v2.menus.ConversationActionModeCa
|
||||
import org.thoughtcrime.securesms.conversation.v2.menus.ConversationMenuHelper
|
||||
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase
|
||||
import org.thoughtcrime.securesms.database.DraftDatabase.Drafts
|
||||
import org.thoughtcrime.securesms.database.model.MessageRecord
|
||||
import org.thoughtcrime.securesms.loki.utilities.toPx
|
||||
import org.thoughtcrime.securesms.mms.GlideApp
|
||||
@ -95,6 +97,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
setUpRecyclerView()
|
||||
setUpToolBar()
|
||||
setUpInputBar()
|
||||
restoreDraftIfNeeded()
|
||||
}
|
||||
|
||||
private fun setUpRecyclerView() {
|
||||
@ -144,11 +147,24 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
cameraButton.layoutParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)
|
||||
}
|
||||
|
||||
private fun restoreDraftIfNeeded() {
|
||||
val draftDB = DatabaseFactory.getDraftDatabase(this)
|
||||
val drafts = draftDB.getDrafts(threadID)
|
||||
draftDB.clearDrafts(threadID)
|
||||
val text = drafts.find { it.type == DraftDatabase.Draft.TEXT }?.value ?: return
|
||||
inputBar.text = text
|
||||
}
|
||||
|
||||
override fun onPrepareOptionsMenu(menu: Menu): Boolean {
|
||||
ConversationMenuHelper.onPrepareOptionsMenu(menu, menuInflater, thread, this) { onOptionsItemSelected(it) }
|
||||
super.onPrepareOptionsMenu(menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
saveDraft()
|
||||
super.onDestroy()
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Updating & Animation
|
||||
@ -379,4 +395,15 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
|
||||
return hitRect.contains(x, y)
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region General
|
||||
private fun saveDraft() {
|
||||
val text = inputBar.text.trim()
|
||||
if (text.isEmpty()) { return }
|
||||
val drafts = Drafts()
|
||||
drafts.add(DraftDatabase.Draft(DraftDatabase.Draft.TEXT, text))
|
||||
val draftDB = DatabaseFactory.getDraftDatabase(this)
|
||||
draftDB.insertDrafts(threadID, drafts)
|
||||
}
|
||||
// endregion
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.input_bar
|
||||
|
||||
import android.content.Context
|
||||
import android.text.Editable
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.view.LayoutInflater
|
||||
@ -24,6 +25,10 @@ class InputBar : RelativeLayout, InputBarEditTextDelegate, QuoteViewDelegate {
|
||||
var delegate: InputBarDelegate? = null
|
||||
var additionalContentHeight = 0
|
||||
|
||||
var text: String
|
||||
get() { return inputBarEditText.text.toString() }
|
||||
set(value) { inputBarEditText.setText(value) }
|
||||
|
||||
private val attachmentsButton by lazy { InputBarButton(context, R.drawable.ic_plus_24) }
|
||||
private val microphoneButton by lazy { InputBarButton(context, R.drawable.ic_microphone) }
|
||||
private val sendButton by lazy { InputBarButton(context, R.drawable.ic_arrow_up, true) }
|
||||
|
@ -1,9 +1,11 @@
|
||||
package org.thoughtcrime.securesms.conversation.v2.input_bar
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.text.Layout
|
||||
import android.text.StaticLayout
|
||||
import android.util.AttributeSet
|
||||
import android.util.Log
|
||||
import android.widget.RelativeLayout
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import org.thoughtcrime.securesms.conversation.v2.utilities.TextUtilities
|
||||
@ -13,6 +15,7 @@ import kotlin.math.min
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class InputBarEditText : AppCompatEditText {
|
||||
private val screenWidth get() = Resources.getSystem().displayMetrics.widthPixels
|
||||
var delegate: InputBarEditTextDelegate? = null
|
||||
|
||||
private val snMinHeight = toPx(40.0f, resources)
|
||||
@ -25,6 +28,10 @@ class InputBarEditText : AppCompatEditText {
|
||||
override fun onTextChanged(text: CharSequence, start: Int, lengthBefore: Int, lengthAfter: Int) {
|
||||
super.onTextChanged(text, start, lengthBefore, lengthAfter)
|
||||
delegate?.inputBarEditTextContentChanged(text)
|
||||
// Calculate the width manually to get it right even before layout has happened (i.e.
|
||||
// when restoring a draft)
|
||||
val width = (screenWidth - 2 * toPx(64.0f, resources)).roundToInt()
|
||||
if (width < 0) { return } // screenWidth initially evaluates to 0
|
||||
val height = TextUtilities.getIntrinsicHeight(text, paint, width).toFloat()
|
||||
val constrainedHeight = min(max(height, snMinHeight), snMaxHeight)
|
||||
if (constrainedHeight.roundToInt() == this.height) { return }
|
||||
|
Loading…
Reference in New Issue
Block a user