Add subscribed topics to the list of suggesed topics
This commit is contained in:
parent
2da394d65e
commit
118bff0099
6 changed files with 42 additions and 37 deletions
|
@ -63,7 +63,7 @@ class ApiService {
|
|||
}
|
||||
if (body != null) {
|
||||
builder
|
||||
.addHeader("X-Message", message)
|
||||
.addHeader("X-Message", message.replace("\n", "\\n"))
|
||||
.put(body)
|
||||
} else {
|
||||
builder.put(message.toRequestBody())
|
||||
|
|
|
@ -68,9 +68,9 @@ class DetailAdapter(private val activity: Activity, private val repository: Repo
|
|||
private val tagsView: TextView = itemView.findViewById(R.id.detail_item_tags_text)
|
||||
private val menuButton: ImageButton = itemView.findViewById(R.id.detail_item_menu_button)
|
||||
private val attachmentImageView: ImageView = itemView.findViewById(R.id.detail_item_attachment_image)
|
||||
private val attachmentBoxView: View = itemView.findViewById(R.id.share_content_file_box)
|
||||
private val attachmentIconView: ImageView = itemView.findViewById(R.id.share_content_file_icon)
|
||||
private val attachmentInfoView: TextView = itemView.findViewById(R.id.share_content_file_info)
|
||||
private val attachmentBoxView: View = itemView.findViewById(R.id.detail_item_attachment_file_box)
|
||||
private val attachmentIconView: ImageView = itemView.findViewById(R.id.detail_item_attachment_file_icon)
|
||||
private val attachmentInfoView: TextView = itemView.findViewById(R.id.detail_item_attachment_file_info)
|
||||
|
||||
fun bind(notification: Notification) {
|
||||
this.notification = notification
|
||||
|
|
|
@ -15,7 +15,6 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.google.android.material.textfield.TextInputLayout
|
||||
import io.heckel.ntfy.R
|
||||
import io.heckel.ntfy.app.Application
|
||||
import io.heckel.ntfy.db.Subscription
|
||||
import io.heckel.ntfy.msg.ApiService
|
||||
import io.heckel.ntfy.util.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
@ -109,26 +108,32 @@ class ShareActivity : AppCompatActivity() {
|
|||
validateInput()
|
||||
}
|
||||
|
||||
// Populate "last topics"
|
||||
val reversedLastTopics = repository.getLastShareTopics().reversed()
|
||||
lastTopicsList.adapter = TopicAdapter(reversedLastTopics) { topicUrl ->
|
||||
try {
|
||||
val (baseUrl, topic) = splitTopicUrl(topicUrl)
|
||||
topicText.text = topic
|
||||
if (baseUrl == appBaseUrl) {
|
||||
useAnotherServerCheckbox.isChecked = false
|
||||
} else {
|
||||
useAnotherServerCheckbox.isChecked = true
|
||||
baseUrlText.setText(baseUrl)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Invalid topicUrl $topicUrl", e)
|
||||
}
|
||||
}
|
||||
|
||||
// Add baseUrl auto-complete behavior
|
||||
// Things that need the database
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
baseUrls = repository.getSubscriptions()
|
||||
// Populate "suggested topics"
|
||||
val subscriptions = repository.getSubscriptions()
|
||||
val lastShareTopics = repository.getLastShareTopics()
|
||||
val subscribedTopics = subscriptions
|
||||
.map { topicUrl(it.baseUrl, it.topic) }
|
||||
.subtract(lastShareTopics.toSet())
|
||||
val suggestedTopics = lastShareTopics.reversed() + subscribedTopics
|
||||
lastTopicsList.adapter = TopicAdapter(suggestedTopics) { topicUrl ->
|
||||
try {
|
||||
val (baseUrl, topic) = splitTopicUrl(topicUrl)
|
||||
topicText.text = topic
|
||||
if (baseUrl == appBaseUrl) {
|
||||
useAnotherServerCheckbox.isChecked = false
|
||||
} else {
|
||||
useAnotherServerCheckbox.isChecked = true
|
||||
baseUrlText.setText(baseUrl)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
Log.w(TAG, "Invalid topicUrl $topicUrl", e)
|
||||
}
|
||||
}
|
||||
|
||||
// Add baseUrl auto-complete behavior
|
||||
baseUrls = subscriptions
|
||||
.groupBy { it.baseUrl }
|
||||
.map { it.key }
|
||||
.filterNot { it == appBaseUrl }
|
||||
|
@ -136,9 +141,9 @@ class ShareActivity : AppCompatActivity() {
|
|||
val activity = this@ShareActivity
|
||||
activity.runOnUiThread {
|
||||
initBaseUrlDropdown(baseUrls, baseUrlText, baseUrlLayout)
|
||||
useAnotherServerCheckbox.isChecked = if (reversedLastTopics.isNotEmpty()) {
|
||||
useAnotherServerCheckbox.isChecked = if (suggestedTopics.isNotEmpty()) {
|
||||
try {
|
||||
val (baseUrl, _) = splitTopicUrl(reversedLastTopics.first())
|
||||
val (baseUrl, _) = splitTopicUrl(suggestedTopics.first())
|
||||
baseUrl != appBaseUrl
|
||||
} catch (_: Exception) {
|
||||
false
|
||||
|
|
|
@ -130,7 +130,7 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:paddingTop="5dp"
|
||||
android:paddingBottom="3dp"
|
||||
android:text="@string/share_previous_topics"
|
||||
android:text="@string/share_suggested_topics"
|
||||
android:textAlignment="viewStart"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintTop_toBottomOf="@id/share_base_url_layout" app:layout_constraintStart_toStartOf="parent" android:layout_marginTop="13dp"/>
|
||||
|
|
|
@ -87,13 +87,13 @@
|
|||
app:layout_constraintStart_toStartOf="parent" android:layout_marginStart="10dp"
|
||||
app:layout_constraintEnd_toEndOf="parent" android:layout_marginEnd="10dp"
|
||||
app:layout_constraintTop_toBottomOf="@id/detail_item_attachment_image"
|
||||
app:layout_constraintBottom_toTopOf="@id/share_content_file_box"
|
||||
app:layout_constraintBottom_toTopOf="@id/detail_item_attachment_file_box"
|
||||
app:layout_constraintHorizontal_bias="0.0" android:layout_marginTop="2dp"
|
||||
/>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" app:layout_constraintTop_toBottomOf="@id/detail_item_tags_text"
|
||||
android:id="@+id/share_content_file_box" app:layout_constraintStart_toStartOf="parent"
|
||||
android:id="@+id/detail_item_attachment_file_box" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" android:layout_marginStart="10dp" android:layout_marginEnd="10dp"
|
||||
app:layout_constraintBottom_toTopOf="@id/detail_item_padding_bottom"
|
||||
android:visibility="visible" android:layout_marginTop="2dp"
|
||||
|
@ -102,27 +102,27 @@
|
|||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" app:srcCompat="@drawable/ic_cancel_gray_24dp"
|
||||
android:id="@+id/share_content_file_icon" app:layout_constraintStart_toStartOf="parent"
|
||||
android:id="@+id/detail_item_attachment_file_icon" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@+id/share_content_file_info" android:layout_marginEnd="5dp"
|
||||
app:layout_constraintEnd_toStartOf="@+id/detail_item_attachment_file_info" android:layout_marginEnd="5dp"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
/>
|
||||
<TextView
|
||||
android:text="attachment.jpg\n58 MB, not downloaded, expires 1/2/2022 10:30 PM"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/share_content_file_info"
|
||||
android:id="@+id/detail_item_attachment_file_info"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintStart_toEndOf="@+id/share_content_file_icon"
|
||||
app:layout_constraintStart_toEndOf="@+id/detail_item_attachment_file_icon"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/share_content_file_icon"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/share_content_file_icon"/>
|
||||
app:layout_constraintTop_toTopOf="@+id/detail_item_attachment_file_icon"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/detail_item_attachment_file_icon"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="5dp" android:id="@+id/detail_item_padding_bottom"
|
||||
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/share_content_file_box"/>
|
||||
app:layout_constraintTop_toBottomOf="@id/detail_item_attachment_file_box"/>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
|
|
|
@ -196,7 +196,7 @@
|
|||
<string name="share_content_file_text">A file was shared with you</string>
|
||||
<string name="share_content_file_error">Cannot read file infos: %1$s</string>
|
||||
<string name="share_topic_title">Share to</string>
|
||||
<string name="share_previous_topics">Last topics</string>
|
||||
<string name="share_suggested_topics">Suggested topics</string>
|
||||
<string name="share_successful">Message successfully published</string>
|
||||
|
||||
<!-- Notification dialog -->
|
||||
|
|
Loading…
Reference in a new issue