forked from upstream-mirrors/quik
Show character remaining counter when compsing message
This commit is contained in:
@@ -219,6 +219,9 @@ class ComposeActivity : QkThemedActivity<ComposeViewModel>(), ComposeView {
|
|||||||
|
|
||||||
if (title != state.title) title = state.title
|
if (title != state.title) title = state.title
|
||||||
|
|
||||||
|
counter.text = state.remaining
|
||||||
|
counter.setVisible(counter.text.isNotBlank())
|
||||||
|
|
||||||
send.isEnabled = state.canSend
|
send.isEnabled = state.canSend
|
||||||
sendIcon.isEnabled = state.canSend
|
sendIcon.isEnabled = state.canSend
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,5 +34,6 @@ data class ComposeState(
|
|||||||
val archived: Boolean = false,
|
val archived: Boolean = false,
|
||||||
val messages: Pair<Conversation, RealmResults<Message>>? = null,
|
val messages: Pair<Conversation, RealmResults<Message>>? = null,
|
||||||
val attachments: List<Uri> = ArrayList(),
|
val attachments: List<Uri> = ArrayList(),
|
||||||
|
val remaining: String = "",
|
||||||
val canSend: Boolean = false
|
val canSend: Boolean = false
|
||||||
)
|
)
|
||||||
@@ -22,6 +22,7 @@ import android.content.Context
|
|||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.telephony.PhoneNumberUtils
|
import android.telephony.PhoneNumberUtils
|
||||||
|
import android.telephony.SmsMessage
|
||||||
import android.view.KeyEvent
|
import android.view.KeyEvent
|
||||||
import android.view.inputmethod.EditorInfo
|
import android.view.inputmethod.EditorInfo
|
||||||
import com.mlsdev.rximagepicker.RxImagePicker
|
import com.mlsdev.rximagepicker.RxImagePicker
|
||||||
@@ -339,6 +340,24 @@ class ComposeViewModel(intent: Intent) : QkViewModel<ComposeView, ComposeState>(
|
|||||||
.autoDisposable(view.scope())
|
.autoDisposable(view.scope())
|
||||||
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
.subscribe { canSend -> newState { it.copy(canSend = canSend) } }
|
||||||
|
|
||||||
|
// Show the remaining character counter when necessary
|
||||||
|
view.textChangedIntent
|
||||||
|
.observeOn(Schedulers.computation())
|
||||||
|
.map { draft -> SmsMessage.calculateLength(draft, false) }
|
||||||
|
.map { array ->
|
||||||
|
val messages = array[0]
|
||||||
|
val remaining = array[2]
|
||||||
|
|
||||||
|
when {
|
||||||
|
messages <= 1 && remaining > 10 -> ""
|
||||||
|
messages <= 1 && remaining <= 10 -> "$remaining"
|
||||||
|
else -> "$remaining / $messages"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.distinctUntilChanged()
|
||||||
|
.autoDisposable(view.scope())
|
||||||
|
.subscribe { remaining -> newState { it.copy(remaining = remaining) } }
|
||||||
|
|
||||||
// Update the draft whenever the text is changed
|
// Update the draft whenever the text is changed
|
||||||
view.textChangedIntent
|
view.textChangedIntent
|
||||||
.debounce(100, TimeUnit.MILLISECONDS)
|
.debounce(100, TimeUnit.MILLISECONDS)
|
||||||
|
|||||||
@@ -66,7 +66,8 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
android:layout_gravity="bottom"
|
||||||
android:background="@drawable/compose_bar_background"
|
android:background="@drawable/compose_bar_background"
|
||||||
android:gravity="center_vertical">
|
android:gravity="bottom"
|
||||||
|
tools:backgroundTint="@color/backgroundLight">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/messageBackground"
|
android:id="@+id/messageBackground"
|
||||||
@@ -126,24 +127,42 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<LinearLayout
|
||||||
android:id="@+id/send"
|
android:layout_width="wrap_content"
|
||||||
android:layout_width="44dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_height="44dp"
|
|
||||||
android:layout_marginEnd="8dp"
|
android:layout_marginEnd="8dp"
|
||||||
android:background="@drawable/circle"
|
android:orientation="vertical">
|
||||||
android:elevation="4dp"
|
|
||||||
tools:backgroundTint="@color/tools_theme">
|
|
||||||
|
|
||||||
<ImageView
|
<presentation.common.widget.QkTextView
|
||||||
android:id="@+id/sendIcon"
|
android:id="@+id/counter"
|
||||||
android:layout_width="24dp"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="24dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_marginBottom="4dp"
|
||||||
android:src="@drawable/ic_send_black_24dp"
|
android:gravity="center"
|
||||||
tools:tint="@color/textPrimaryDark" />
|
android:textSize="12sp"
|
||||||
|
app:textColor="secondary"
|
||||||
|
tools:text="108 / 2" />
|
||||||
|
|
||||||
</FrameLayout>
|
<FrameLayout
|
||||||
|
android:id="@+id/send"
|
||||||
|
android:layout_width="44dp"
|
||||||
|
android:layout_height="44dp"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:background="@drawable/circle"
|
||||||
|
android:elevation="4dp"
|
||||||
|
tools:backgroundTint="@color/tools_theme">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/sendIcon"
|
||||||
|
android:layout_width="24dp"
|
||||||
|
android:layout_height="24dp"
|
||||||
|
android:layout_gravity="center"
|
||||||
|
android:src="@drawable/ic_send_black_24dp"
|
||||||
|
tools:tint="@color/textPrimaryDark" />
|
||||||
|
|
||||||
|
</FrameLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user