mirror of
https://github.com/nextcloud/talk-android
synced 2025-07-10 06:14:10 +01:00
open poll dialog
Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
parent
f2025332ab
commit
bf05445561
@ -34,11 +34,13 @@ import autodagger.AutoInjector
|
||||
import coil.load
|
||||
import com.amulyakhare.textdrawable.TextDrawable
|
||||
import com.nextcloud.talk.R
|
||||
import com.nextcloud.talk.activities.MainActivity
|
||||
import com.nextcloud.talk.api.NcApi
|
||||
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.ui.PollVoteDialogFragment
|
||||
import com.nextcloud.talk.ui.bottom.sheet.ProfileBottomSheet
|
||||
import com.nextcloud.talk.utils.ApiUtils
|
||||
import com.nextcloud.talk.utils.DisplayUtils
|
||||
@ -98,30 +100,48 @@ class IncomingPollMessageViewHolder(incomingView: View, payload: Any) : MessageH
|
||||
}
|
||||
|
||||
private fun setPollPreview(message: ChatMessage) {
|
||||
var pollId: String?
|
||||
var pollName: String? = ""
|
||||
var pollId: Int? = null
|
||||
var pollName: String? = null
|
||||
|
||||
if (message.messageParameters != null && message.messageParameters!!.size > 0) {
|
||||
for (key in message.messageParameters!!.keys) {
|
||||
val individualHashMap: Map<String?, String?> = message.messageParameters!![key]!!
|
||||
if (individualHashMap["type"] == "talk-poll") {
|
||||
pollId = individualHashMap["id"]
|
||||
pollName = individualHashMap["name"]
|
||||
pollId = Integer.parseInt(individualHashMap["id"])
|
||||
pollName = individualHashMap["name"].toString()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
binding.messagePollTitle.text = pollName
|
||||
if (pollId != null && pollName != null) {
|
||||
binding.messagePollTitle.text = pollName
|
||||
|
||||
// TODO: how to get room token here?
|
||||
// val credentials = ApiUtils.getCredentials(message.activeUser?.username, message.activeUser?.token)
|
||||
// ncApi!!.getPoll(
|
||||
// credentials,
|
||||
// ApiUtils.getUrlForPoll(
|
||||
// message.activeUser?.baseUrl,
|
||||
// ???????
|
||||
// )
|
||||
// )
|
||||
// TODO: how to get room token here?
|
||||
val roomToken = "???????????????????????????"
|
||||
|
||||
|
||||
binding.bubble.setOnClickListener {
|
||||
val pollVoteDialog = PollVoteDialogFragment.newInstance(
|
||||
message.activeUser!!, roomToken, pollId,
|
||||
pollName
|
||||
)
|
||||
pollVoteDialog.show(
|
||||
(binding.messagePollIcon.context as MainActivity).supportFragmentManager,
|
||||
TAG
|
||||
)
|
||||
}
|
||||
|
||||
// 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,
|
||||
// ???????
|
||||
// )
|
||||
// )
|
||||
}
|
||||
}
|
||||
|
||||
private fun setAvatarAndAuthorOnMessageItem(message: ChatMessage) {
|
||||
|
@ -0,0 +1,4 @@
|
||||
package com.nextcloud.talk.polls.model
|
||||
|
||||
class PollModel {
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package com.nextcloud.talk.polls.repositories
|
||||
|
||||
interface DialogPollRepository {
|
||||
|
||||
data class Parameters(
|
||||
val userName: String,
|
||||
val userToken: String,
|
||||
val baseUrl: String,
|
||||
val roomToken: String,
|
||||
val pollId: Int
|
||||
)
|
||||
}
|
@ -0,0 +1,83 @@
|
||||
package com.nextcloud.talk.polls.ui
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import autodagger.AutoInjector
|
||||
import com.nextcloud.talk.application.NextcloudTalkApplication
|
||||
import com.nextcloud.talk.databinding.DialogPollVoteBinding
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.polls.viewmodels.PollViewModel
|
||||
|
||||
var user: UserEntity? = null
|
||||
var pollId: Int? = null
|
||||
var roomToken: String? = null
|
||||
var pollTitle: String? = null
|
||||
|
||||
@AutoInjector(NextcloudTalkApplication::class)
|
||||
class PollVoteDialogFragment : DialogFragment() {
|
||||
|
||||
private lateinit var binding: DialogPollVoteBinding
|
||||
private lateinit var viewModel: PollViewModel
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
NextcloudTalkApplication.sharedApplication!!.componentApplication.inject(this)
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
binding = DialogPollVoteBinding.inflate(LayoutInflater.from(context))
|
||||
|
||||
return AlertDialog.Builder(requireContext())
|
||||
.setView(binding.root)
|
||||
.create()
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
|
||||
return binding.root
|
||||
}
|
||||
|
||||
@SuppressLint("DefaultLocale")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
binding.messagePollTitle.text = pollTitle
|
||||
|
||||
|
||||
|
||||
viewModel.viewState.observe(this) { state ->
|
||||
// when (state) {
|
||||
// }
|
||||
}
|
||||
|
||||
viewModel.initialize(user!!, roomToken!!, pollId!!)
|
||||
}
|
||||
|
||||
/**
|
||||
* Fragment creator
|
||||
*/
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(
|
||||
userEntity: UserEntity,
|
||||
roomTokenParam: String,
|
||||
id: Int,
|
||||
name: String
|
||||
): PollVoteDialogFragment {
|
||||
user = userEntity // TODO replace with "putParcelable" like in SetStatusDialogFragment???
|
||||
roomToken = roomTokenParam
|
||||
pollId = id
|
||||
pollTitle = name
|
||||
|
||||
val dialogFragment = PollVoteDialogFragment()
|
||||
return dialogFragment
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.nextcloud.talk.polls.viewmodels
|
||||
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.ViewModel
|
||||
import com.nextcloud.talk.models.database.UserEntity
|
||||
import com.nextcloud.talk.polls.model.PollModel
|
||||
import com.nextcloud.talk.polls.repositories.DialogPollRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class PollViewModel @Inject constructor(private val repository: DialogPollRepository) : ViewModel() {
|
||||
|
||||
private lateinit var repositoryParameters: DialogPollRepository.Parameters
|
||||
|
||||
sealed interface ViewState
|
||||
object InitialState : ViewState
|
||||
open class PollOpenState(val poll: PollModel) : ViewState
|
||||
open class PollClosedState(val poll: PollModel) : ViewState
|
||||
|
||||
private val _viewState: MutableLiveData<ViewState> = MutableLiveData(InitialState)
|
||||
val viewState: LiveData<ViewState>
|
||||
get() = _viewState
|
||||
|
||||
fun initialize(userEntity: UserEntity, roomToken: String, pollId: Int) {
|
||||
repositoryParameters = DialogPollRepository.Parameters(
|
||||
userEntity.userId,
|
||||
userEntity.token,
|
||||
userEntity.baseUrl,
|
||||
roomToken,
|
||||
pollId
|
||||
)
|
||||
// loadAvailableTypes()
|
||||
}
|
||||
}
|
81
app/src/main/res/layout/dialog_poll_vote.xml
Normal file
81
app/src/main/res/layout/dialog_poll_vote.xml
Normal file
@ -0,0 +1,81 @@
|
||||
<!--
|
||||
Nextcloud Android client application
|
||||
|
||||
@author Marcel Hibbe
|
||||
Copyright (C) 2021 Marcel Hibbe <dev@mhibbe.de>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License version 2,
|
||||
as published by the Free Software Foundation.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/message_poll_icon"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:contentDescription="@null"
|
||||
android:src="@drawable/ic_baseline_bar_chart_24"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:tint="@color/high_emphasis_menu_icon" />
|
||||
|
||||
<androidx.emoji.widget.EmojiTextView
|
||||
android:id="@+id/message_poll_title"
|
||||
android:layout_width="257dp"
|
||||
android:layout_height="55dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:textAlignment="viewStart"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintStart_toEndOf="@id/message_poll_icon"
|
||||
app:layout_constraintTop_toTopOf="@+id/message_poll_icon"
|
||||
tools:text="This is the poll title?" />
|
||||
|
||||
<RadioGroup
|
||||
android:id="@+id/radioGroup"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="203dp"
|
||||
app:layout_constraintStart_toStartOf="@+id/message_poll_icon"
|
||||
app:layout_constraintTop_toBottomOf="@+id/message_poll_title">
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false"
|
||||
android:text="yes" />
|
||||
|
||||
<RadioButton
|
||||
android:id="@+id/radioButton2"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:checked="false"
|
||||
android:text="no" />
|
||||
|
||||
</RadioGroup>
|
||||
|
||||
<com.google.android.material.button.MaterialButton
|
||||
android:id="@+id/setStatus"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/nc_common_submit"
|
||||
android:theme="@style/Button.Primary"
|
||||
app:cornerRadius="@dimen/button_corner_radius"
|
||||
app:layout_constraintEnd_toEndOf="@+id/message_poll_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/radioGroup" />
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
@ -27,6 +27,7 @@
|
||||
<string name="nc_common_skip">Skip</string>
|
||||
<string name="nc_common_set">Set</string>
|
||||
<string name="nc_common_error_sorry">Sorry, something went wrong!</string>
|
||||
<string name="nc_common_submit">Submit</string>
|
||||
|
||||
<!-- Bottom Navigation -->
|
||||
<string name="nc_settings">Settings</string>
|
||||
|
Loading…
Reference in New Issue
Block a user