fetch poll to set subtitle in message

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-06-08 21:37:46 +02:00 committed by Andy Scherzinger (Rebase PR Action)
parent ae80a4e2ad
commit 81666829b5
2 changed files with 43 additions and 14 deletions

View File

@ -26,6 +26,7 @@ import android.graphics.drawable.Drawable
import android.graphics.drawable.LayerDrawable
import android.os.Build
import android.text.TextUtils
import android.util.Log
import android.view.View
import androidx.core.content.ContextCompat
import androidx.core.content.res.ResourcesCompat
@ -40,11 +41,16 @@ import com.nextcloud.talk.application.NextcloudTalkApplication
import com.nextcloud.talk.application.NextcloudTalkApplication.Companion.sharedApplication
import com.nextcloud.talk.databinding.ItemCustomIncomingPollMessageBinding
import com.nextcloud.talk.models.json.chat.ChatMessage
import com.nextcloud.talk.polls.repositories.model.PollOverall
import com.nextcloud.talk.polls.ui.PollMainDialogFragment
import com.nextcloud.talk.utils.ApiUtils
import com.nextcloud.talk.utils.DisplayUtils
import com.nextcloud.talk.utils.preferences.AppPreferences
import com.stfalcon.chatkit.messages.MessageHolders
import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import javax.inject.Inject
@AutoInjector(NextcloudTalkApplication::class)
@ -129,17 +135,39 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
)
}
// TODO get poll from api
// wait for https://github.com/nextcloud/spreed/pull/7306#issuecomment-1145819317
val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token)
ncApi!!.getPoll(
credentials,
ApiUtils.getUrlForPoll(
message.activeUser?.baseUrl,
roomToken,
pollId
)
).subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<PollOverall> {
override fun onSubscribe(d: Disposable) {
// unused atm
}
// val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token)
// ncApi!!.getPoll(
// credentials,
// ApiUtils.getUrlForPoll(
// message.activeUser?.baseUrl,
// ???????
// )
// )
override fun onNext(pollOverall: PollOverall) {
if (pollOverall.ocs!!.data!!.status == 0) {
binding.messagePollSubtitle.text =
context?.resources?.getString(R.string.message_poll_tap_to_vote)
} else {
binding.messagePollSubtitle.text =
context?.resources?.getString(R.string.message_poll_tap_see_results)
}
}
override fun onError(e: Throwable) {
Log.e(TAG, "Error while fetching poll", e)
}
override fun onComplete() {
// unused atm
}
})
}
}

View File

@ -65,8 +65,8 @@
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/message_poll_icon"
@ -74,7 +74,7 @@
android:layout_height="wrap_content"
android:contentDescription="@null"
android:src="@drawable/ic_baseline_bar_chart_24"
app:tint="@color/high_emphasis_menu_icon"></ImageView>
app:tint="@color/high_emphasis_menu_icon" />
<androidx.emoji.widget.EmojiTextView
android:id="@+id/message_poll_title"
@ -87,10 +87,11 @@
</LinearLayout>
<TextView
android:id="@+id/message_poll_subtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/double_margin_between_elements"
android:text="@string/message_poll_tap_to_vote"></TextView>
android:text="@string/message_poll_tap_to_vote" />
<TextView
android:id="@id/messageTime"