Skip to content

Commit

Permalink
Merge branch 'add_question_feature' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkaDev committed Feb 18, 2022
2 parents 8ce2292 + 07469cd commit 0da7e48
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class AddOwnQuestionPresenter @Inject constructor(
firebaseStorageRef.child(VIDEO_PATH + user.uid + "/" + videoFileName)

val stream = FileInputStream(File(videoAbsolutePath))

Log.d("upload", "Starting to upload video...")
viewState.showError(context.resources.getString(R.string.uploading_question))
val uploadTask = videoFullRef?.putStream(stream)
uploadTask?.addOnFailureListener {
viewState.showError(context.resources.getString(R.string.upload_video_error))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.desiredsoftware.socialquiz.data.model.question.Answer
import com.desiredsoftware.socialquiz.data.model.question.Question
import com.desiredsoftware.socialquiz.data.repository.FirebaseRepository
import com.desiredsoftware.socialquiz.view.IError
import com.google.firebase.storage.StorageReference
import kotlinx.coroutines.launch
import moxy.InjectViewState
import moxy.MvpPresenter
Expand All @@ -16,9 +17,11 @@ import moxy.viewstate.strategy.AddToEndSingleStrategy
import moxy.viewstate.strategy.StateStrategyType
import javax.inject.Inject


@InjectViewState
class QuestionShowingPresenter @Inject constructor(
private var firebaseRepository: FirebaseRepository,
private var firestoreStorage: StorageReference,
private var context: Context
) : MvpPresenter<QuestionShowingPresenter.IQuestionView>() {

Expand Down Expand Up @@ -52,7 +55,10 @@ class QuestionShowingPresenter @Inject constructor(
}
when (questionToShow.questionType) {
Question.Companion.QUESTION_TYPE.VIDEO -> {
viewState.showVideoQuestion(context, questionToShow.questionBody)
val dateRef = firestoreStorage.child(questionToShow.questionBody)
dateRef.downloadUrl.addOnSuccessListener {
viewState.showVideoQuestion(context, it.toString())
}
}
Question.Companion.QUESTION_TYPE.TEXT -> {
viewState.showTextQuestion(context, questionToShow.questionBody)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import android.view.ViewGroup
import android.widget.Toast
import androidx.recyclerview.widget.LinearLayoutManager
import com.bluelinelabs.conductor.RouterTransaction
import com.desiredsoftware.socialquiz.R
import com.desiredsoftware.socialquiz.data.model.question.Answer
import com.desiredsoftware.socialquiz.databinding.ViewControllerQuestionShowingBinding
import com.desiredsoftware.socialquiz.di.App
Expand All @@ -24,6 +25,7 @@ import moxy.presenter.InjectPresenter
import moxy.presenter.ProvidePresenter
import javax.inject.Inject


class QuestionShowingController : MvpController, QuestionShowingPresenter.IQuestionView {
constructor() : super()
constructor (args: Bundle) : super(args)
Expand Down Expand Up @@ -65,11 +67,11 @@ class QuestionShowingController : MvpController, QuestionShowingPresenter.IQuest
.build()

binding.playerView.player = player
player?.let {
it.setMediaItem(MediaItem.fromUri(videoURI))
it.prepare()
it.playWhenReady = true
it.addListener(object : Player.Listener {
player?.let { player ->
player.setMediaItem(MediaItem.fromUri(videoURI))
player.prepare()
player.playWhenReady = true
player.addListener(object : Player.Listener {
override fun onPlaybackStateChanged(state: Int) {
when (state) {
Player.STATE_ENDED -> {
Expand All @@ -92,7 +94,7 @@ class QuestionShowingController : MvpController, QuestionShowingPresenter.IQuest

override fun onPlayerError(error: ExoPlaybackException) {
super.onPlayerError(error)
Toast.makeText(activity, "Playback error, message: ${error.message}", Toast.LENGTH_LONG).show()
Toast.makeText(activity, activity?.resources?.getString(R.string.playback_error), Toast.LENGTH_LONG).show()
error.printStackTrace()
binding.listAnswers.visibility = View.VISIBLE
}
Expand All @@ -106,8 +108,7 @@ class QuestionShowingController : MvpController, QuestionShowingPresenter.IQuest
}

override fun showVideoQuestion(context: Context, questionBodyVideoUri: String) {
// Temporary to prevent Firebase charging
//configurePlayer(context, questionBodyVideoUri)
configurePlayer(context, questionBodyVideoUri)
}

override fun showTextQuestion(context: Context, questionBodyVideoUri: String) {
Expand All @@ -132,9 +133,6 @@ class QuestionShowingController : MvpController, QuestionShowingPresenter.IQuest
adapter = mAdapter
layoutManager = LinearLayoutManager(context)
}

// Temporary to prevent Firebase charging (video switched off)
binding.listAnswers.visibility = View.VISIBLE
}

override fun showError(message: String) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import com.desiredsoftware.socialquiz.MainActivity
import com.desiredsoftware.socialquiz.R
import com.desiredsoftware.socialquiz.di.App
import com.desiredsoftware.socialquiz.presenter.splash.SplashPresenter
import com.desiredsoftware.socialquiz.ui.categories.CategoriesController
import com.desiredsoftware.socialquiz.ui.common.MvpController
import com.desiredsoftware.socialquiz.ui.question.AddOwnQuestionController
import com.firebase.ui.auth.AuthUI
import moxy.presenter.InjectPresenter
import moxy.presenter.ProvidePresenter
Expand Down Expand Up @@ -60,10 +60,7 @@ class SplashController: MvpController, SplashPresenter.ISplashView {
}

override fun runCategoriesScreen() {
// TODO: Return Categories controller to default
// Made for dev process
router?.replaceTopController(RouterTransaction.with(AddOwnQuestionController())
//router?.replaceTopController(RouterTransaction.with(CategoriesController())
router?.replaceTopController(RouterTransaction.with(CategoriesController())
.pushChangeHandler(VerticalChangeHandler())
.popChangeHandler(VerticalChangeHandler()))
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_answer_variant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/buttonAnswer"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:minWidth="160dp"
tools:text="answer variant"
android:layout_gravity="center_horizontal"
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/menu/bottom_nav_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
android:icon="@drawable/ic_categories_24dp"
android:title="@string/title_home" />

<item
android:id="@+id/navigation_profile"
android:icon="@drawable/ic_profile_white_24dp"
android:title="@string/profile" />

<item
android:id="@+id/navigation_add_question"
android:icon="@drawable/ic_add_question_24"
android:title="@string/add_question" />

<item
android:id="@+id/navigation_profile"
android:icon="@drawable/ic_profile_white_24dp"
android:title="@string/profile" />
</menu>
4 changes: 3 additions & 1 deletion app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<string name="choose_your_video">Выбери свой видео вопрос</string>
<string name="video_not_choosen">Добавь видео, покажи себя ;)</string>
<string name="upload_video_error">Ошибка загрузки видео</string>
<string name="upload_video_success">Видео загружено</string>
<string name="playback_error">Ошибка воспроизведения</string>
<string name="uploading_question">Вопрос загружается...</string>
<string name="upload_video_success">Вопрос отправлен на проверку</string>
</resources>
4 changes: 3 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,7 @@
<string name="answer_variant_number">Enter answer here</string>
<string name="video_not_choosen">Video doesn\'t choosen</string>
<string name="upload_video_error">Can\'t upload the video</string>
<string name="upload_video_success">Video uploaded</string>
<string name="upload_video_success">Question is uploaded</string>
<string name="playback_error">Playback error</string>
<string name="uploading_question">Uploading your question...</string>
</resources>

0 comments on commit 0da7e48

Please sign in to comment.