Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Message bar #45

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP message bar
Philipp Heckel committed Nov 24, 2022
commit 1a828e505e3b747c7a532f2549cd42641283838f
13 changes: 12 additions & 1 deletion app/src/main/java/io/heckel/ntfy/ui/DetailActivity.kt
Original file line number Diff line number Diff line change
@@ -189,9 +189,20 @@ class DetailActivity : AppCompatActivity(), ActionMode.Callback, NotificationFra
// Message bar
val messageText: TextInputEditText = findViewById(R.id.detail_message_box)
val messageSendButton: Button = findViewById(R.id.detail_message_send_button)

messageSendButton.setOnClickListener {
lifecycleScope.launch(Dispatchers.IO) {
api.publish(subscriptionBaseUrl, subscriptionTopic, message = messageText.text.toString())
val message = messageText.text.toString()
if (message.isNotEmpty()) {
api.publish(subscriptionBaseUrl, subscriptionTopic, message = message)
messageText.text?.clear()
} else {
runOnUiThread {
Toast
.makeText(this@DetailActivity, getString(R.string.detail_message_bar_empty_message), Toast.LENGTH_LONG)
.show()
}
}
}
}

12 changes: 2 additions & 10 deletions app/src/main/java/io/heckel/ntfy/ui/ShareActivity.kt
Original file line number Diff line number Diff line change
@@ -88,16 +88,8 @@ class ShareActivity : AppCompatActivity() {
errorImage = findViewById(R.id.share_error_image)
errorImage.visibility = View.GONE

val textWatcher = object : TextWatcher {
override fun afterTextChanged(s: Editable?) {
validateInput()
}
override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {
// Nothing
}
override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {
// Nothing
}
val textWatcher = AfterChangedTextWatcher {
validateInput()
}
contentText.addTextChangedListener(textWatcher)
topicText.addTextChangedListener(textWatcher)
58 changes: 45 additions & 13 deletions app/src/main/res/layout/activity_detail.xml
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@
style="@style/CardViewBackground"
android:id="@+id/detail_notification_list_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:visibility="visible" app:layout_constraintBottom_toTopOf="@id/detail_message_box" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent">
android:visibility="visible" app:layout_constraintBottom_toTopOf="@id/detail_message_bar" app:layout_constraintTop_toTopOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintEnd_toEndOf="parent" android:layout_height="0dp">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/detail_notification_list"
android:layout_width="match_parent"
@@ -72,22 +71,49 @@
android:linksClickable="true"
android:autoLink="web"/>
</LinearLayout>
<LinearLayout
<androidx.constraintlayout.widget.ConstraintLayout
style="@style/CardViewBackground"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/detail_message_bar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginStart="3dp" android:layout_marginBottom="3dp" android:layout_marginEnd="3dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/detail_message_box"
app:layout_constraintTop_toBottomOf="@+id/detail_notification_list_container">
<com.google.android.material.textfield.TextInputLayout
style="@style/MessageInputBox"
android:id="@+id/detail_message_box_layout"
android:layout_width="0dp"
android:layout_height="48dp" android:hint="Type a message here"
android:inputType="text|textNoSuggestions"
android:gravity="start|top" android:layout_weight="1"/>
android:layout_height="wrap_content"
app:boxCornerRadiusBottomEnd="24dp"
app:boxCornerRadiusTopEnd="24dp"
app:boxCornerRadiusBottomStart="24dp"
app:boxCornerRadiusTopStart="24dp"
app:boxStrokeWidthFocused="0dp"
app:boxStrokeWidth="0dp"
app:boxBackgroundMode="filled"
app:hintEnabled="false"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/detail_message_send_button"
app:startIconDrawable="@drawable/ic_add_black_24dp"
android:layout_marginStart="7dp"
android:layout_marginBottom="1dp"
android:layout_marginEnd="5dp">

<com.google.android.material.textfield.TextInputEditText
android:id="@+id/detail_message_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textColor="#000000"
android:padding="3dp"
android:textColorLink="#FFFFFF"
android:hint="@string/detail_message_bar_hint"
/>

</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
style="@style/Widget.MaterialComponents.Button.Icon"
android:id="@+id/detail_message_send_button"
@@ -98,8 +124,14 @@
android:insetBottom="0dp"
android:insetLeft="0dp"
android:insetRight="0dp"
app:icon="@drawable/ic_send_white_24dp"/>
</LinearLayout>
app:icon="@drawable/ic_send_white_24dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/detail_message_box_layout"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginEnd="7dp"
android:layout_marginBottom="2dp" android:layout_marginTop="3dp"/>
</androidx.constraintlayout.widget.ConstraintLayout>


</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -166,6 +166,10 @@
<string name="detail_item_download_info_download_failed_expired">download failed, link expired</string>
<string name="detail_item_download_info_download_failed_expires_x">download failed, link expires %1$s</string>

<!-- Detail activity: Message bar -->
<string name="detail_message_bar_hint">Type a message here</string>
<string name="detail_message_bar_empty_message">Type a message first</string>

<!-- Detail activity: Action bar -->
<string name="detail_menu_notifications_enabled">Notifications on</string>
<string name="detail_menu_notifications_disabled_forever">Notifications muted</string>
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -30,4 +30,9 @@
<item name="cornerFamily">rounded</item>
<item name="cornerSize">5dp</item>
</style>

<style name="MessageInputBox" parent="Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense">
<item name="boxBackgroundColor">@color/white</item>
<item name="boxStrokeColor">@color/white</item>
</style>
</resources>