Skip to content

Commit

Permalink
Passing answers variant to question builder and uploading video imple…
Browse files Browse the repository at this point in the history
…mented
  • Loading branch information
kirkaDev committed Feb 17, 2022
1 parent c926d3f commit a9e5f5d
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 34 deletions.
17 changes: 0 additions & 17 deletions .idea/deploymentTargetDropDown.xml

This file was deleted.

4 changes: 3 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package com.desiredsoftware.socialquiz.data.model.question

import java.io.Serializable

class Answer(val answer: String,
val isCorrect: Boolean) : Serializable
class Answer(
var answer: String,
var isCorrect: Boolean) : Serializable
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.desiredsoftware.socialquiz.presenter.question

import android.content.Context
import android.util.Log
import com.desiredsoftware.socialquiz.R
import com.desiredsoftware.socialquiz.data.model.category.Category
import com.desiredsoftware.socialquiz.data.model.question.Answer
import com.desiredsoftware.socialquiz.data.model.question.Question
Expand Down Expand Up @@ -34,7 +35,9 @@ class AddOwnQuestionPresenter @Inject constructor(
var answers: MutableList<Answer> = MutableList(answersCount) {
Answer("", false)
}
var videoAbsolutePath: String = ""

// Path get from intent after recording
var videoAbsolutePath = String()

fun initVideoUrl(videoAbsolutePath: String) {
this.videoAbsolutePath = videoAbsolutePath
Expand All @@ -57,11 +60,10 @@ class AddOwnQuestionPresenter @Inject constructor(
}
}

fun uploadVideoToStorage(videoAbsolutePath: String) {
fun uploadVideoToStorage(videoFileName: String, videoAbsolutePath: String) {
presenterScope.launch {
var videoFullRef: StorageReference? = null
firebaseUser?.let { user ->
val videoFileName = user.uid + ".mp4"
videoFullRef = firebaseStorageRef.child(VIDEO_PATH + videoFileName)

val stream = FileInputStream(File(videoAbsolutePath))
Expand Down Expand Up @@ -89,7 +91,6 @@ class AddOwnQuestionPresenter @Inject constructor(
questionId = firebaseUser.uid + unixTimestamp
// categoryId - should be set from spinner in controller already
answerVariants = answers

questionBody = firebaseUser.uid + unixTimestamp
questionAuthorUid = firebaseUser.uid
questionType = Question.Companion.QUESTION_TYPE.VIDEO
Expand Down Expand Up @@ -120,18 +121,32 @@ class AddOwnQuestionPresenter @Inject constructor(
return false
}

if (proposedQuestion.questionAuthorUid.isNullOrEmpty()) {
if (proposedQuestion.questionBody.isEmpty()) {
Log.d("checkQuestionContract", "questionBody is empty")
return false
}

if (proposedQuestion.questionAuthorUid.isEmpty()) {
Log.d(
"checkQuestionContract",
"firebaseUser.uid = ${proposedQuestion.questionAuthorUid}"
)
return false
}

// If this instruction runs then all properties is filled and probably, ok
Log.d("checkQuestionContract", "contract is OK!")
return true
}

fun sendQuestion() {

if (videoAbsolutePath.isNotEmpty())
{
uploadVideoToStorage(proposedQuestion.questionBody, videoAbsolutePath)
}
else{
viewState.showError(context.resources.getString(R.string.video_not_choosen))
}
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,22 @@ package com.desiredsoftware.socialquiz.ui.question.adapters
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.widget.AppCompatButton
import androidx.appcompat.widget.AppCompatEditText
import androidx.appcompat.widget.AppCompatTextView
import androidx.core.widget.addTextChangedListener
import androidx.recyclerview.widget.RecyclerView
import com.desiredsoftware.socialquiz.R
import com.desiredsoftware.socialquiz.data.model.question.Answer

class OwnAnswerVariantsAdapter(val answerVariants: MutableList<Answer>):
class OwnAnswerVariantsAdapter(var answerVariants: MutableList<Answer>) :
RecyclerView.Adapter<OwnAnswerVariantsAdapter.ViewHolder>() {

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.item_own_question_answer_variant, parent, false))
return ViewHolder(
LayoutInflater.from(parent.context)
.inflate(R.layout.item_own_question_answer_variant, parent, false)
)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
Expand All @@ -25,13 +29,30 @@ class OwnAnswerVariantsAdapter(val answerVariants: MutableList<Answer>):
return answerVariants.size
}

class ViewHolder(itemView: View): RecyclerView.ViewHolder(itemView) {
fun bind(answerVariant: Answer, position: Int){
val answerEditText = itemView.findViewById<AppCompatEditText>(R.id.answerVariantEditText)
inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
fun bind(answerVariant: Answer, position: Int) {
val answerEditText =
itemView.findViewById<AppCompatEditText>(R.id.answerVariantEditText)
val answerLabel = itemView.findViewById<AppCompatTextView>(R.id.answerLabel)

answerLabel.text = itemView.context.getString(R.string.answer_number, (position+1).toString())
val answerIsCorrectButton = itemView.findViewById<AppCompatButton>(R.id.isCorrectButton)

answerLabel.text =
itemView.context.getString(R.string.answer_number, (position + 1).toString())
answerEditText.hint = itemView.context.getString(R.string.answer_variant_number)

answerEditText.addTextChangedListener {
answerVariant.answer = it.toString()
}

answerIsCorrectButton.setOnClickListener {
answerVariant.isCorrect = true
answerVariants.forEach { answer ->
if (answer != answerVariant) {
answer.isCorrect = false
}
}
}
}
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
<string name="answer_number">Ответ %1$s</string>
<string name="answer_variant_number">Напиши ответ</string>
<string name="choose_your_video">Выбери свой видео вопрос</string>
<string name="video_not_choosen">Добавь видео, покажи себя ;)</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@
<string name="submit_for_approval">Submit for approval</string>
<string name="answer_number">Answer %1$s</string>
<string name="answer_variant_number">Enter answer here</string>
<string name="video_not_choosen">Video doesn\'t choosen</string>
</resources>

0 comments on commit a9e5f5d

Please sign in to comment.