Skip to content

Commit 53fccbf

Browse files
author
Patrick Jackson
committed
bug fixes on android & iOS
1 parent b7dc3c9 commit 53fccbf

File tree

14 files changed

+80
-45
lines changed

14 files changed

+80
-45
lines changed

android/src/main/java/com/willowtreeapps/namegame/store/QuestionFragment.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,12 @@ import nl.dionsegijn.konfetti.models.Size
1919
import android.widget.Button
2020
import androidx.core.content.res.ResourcesCompat
2121
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
22+
import com.willowtreeapps.common.Actions
2223
import com.willowtreeapps.common.Logger
2324
import com.willowtreeapps.common.middleware.UiActions
2425
import com.willowtreeapps.namegame.*
26+
import org.reduxkotlin.ClearView
27+
import org.reduxkotlin.DetachView
2528
import java.util.*
2629

2730

@@ -93,6 +96,7 @@ class QuestionFragment : BaseNameGameViewFragment<QuestionView>(), QuestionView,
9396
private var lastSelectedBtn: Button? = null
9497

9598
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
99+
super.onCreateView(inflater, container, savedInstanceState)
96100
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(activity!!)
97101
return inflater.inflate(R.layout.fragment_question, container, false)
98102
}
@@ -114,7 +118,10 @@ class QuestionFragment : BaseNameGameViewFragment<QuestionView>(), QuestionView,
114118

115119
override fun onBackPressed(): Boolean {
116120
//TODO revisit this - is needed with presenter middleware
117-
// NameGameApp.gameEngine().detachView(this)
121+
// dispatch(DetachView(this))
122+
// dispatch(ClearView(this))
123+
dispatch(UiActions.BackPressOnQuestions())
124+
closeMic()
118125
// presenter.onBackPressed()
119126
return false
120127
}

android/src/main/java/com/willowtreeapps/namegame/store/StartFragment.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ import android.os.Bundle
44
import android.view.LayoutInflater
55
import android.view.View
66
import android.view.ViewGroup
7-
import androidx.fragment.app.Fragment
87
import com.willowtreeapps.common.middleware.UiActions
98
import com.willowtreeapps.common.ui.StartView
109
import com.willowtreeapps.namegame.*
1110
import kotlinx.android.synthetic.main.fragment_start.*
1211

13-
class StartFragment : Fragment(), StartView {
12+
class StartFragment : BaseNameGameViewFragment<StartView>(), StartView {
1413

1514
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
1615
return inflater.inflate(R.layout.fragment_start, container, false)
1716
}
1817

1918
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
19+
super.onViewCreated(view, savedInstanceState)
2020
btn_start.setOnClickListener { dispatch(UiActions.StartGameTapped()) }
2121
btn_settings.setOnClickListener { dispatch(UiActions.SettingsTapped()) }
2222
}
@@ -26,7 +26,9 @@ class StartFragment : Fragment(), StartView {
2626
}
2727

2828
override fun showLoading() {
29-
loading_spinner.visibility = View.VISIBLE
29+
activity?.runOnUiThread {
30+
loading_spinner.visibility = View.VISIBLE
31+
}
3032
}
3133

3234
override fun showError(msg: String) {

android/src/main/res/layout/fragment_start.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
android:layout_height="wrap_content"
6969
android:indeterminateTint="@color/colorPrimary"
7070
android:visibility="gone"
71+
tools:visibility="visible"
7172
app:layout_constraintBottom_toBottomOf="parent"
7273
app:layout_constraintEnd_toEndOf="parent"
7374
app:layout_constraintHorizontal_bias="0.5"

common/src/commonMain/kotlin/com/willowtreeapps/common/AppState.kt

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ data class AppState(val isLoadingItems: Boolean = false,
2424
else -> "TIME'S UP!!"
2525
}
2626

27-
val currentQuestion: Question?
28-
get() = if (questions.size > currentQuestionIndex)
29-
questions[currentQuestionIndex]
30-
else
31-
null
27+
val currentQuestion: Question
28+
get() = questions[currentQuestionIndex]
29+
3230

3331
fun currentQuestionItem() = currentQuestion!!.choices.find { it.id == currentQuestion!!.itemId }!!
3432

common/src/commonMain/kotlin/com/willowtreeapps/common/Reducers.kt

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.willowtreeapps.common
22

33
import com.willowtreeapps.common.Actions.*
4-
import com.willowtreeapps.common.middleware.UiActions
54
import com.willowtreeapps.common.util.NO_MATCH
65
import com.willowtreeapps.common.util.match
76
import org.reduxkotlin.*
@@ -29,19 +28,19 @@ val reducer: Reducer<AppState> = { state: AppState, action ->
2928
answerName = action.name
3029
Question.Status.CORRECT
3130
} else {
32-
val correctIndex = state.currentQuestion?.choices?.indexOfFirst { it.id == state.currentQuestion?.itemId }
33-
val matchingIndex = match(action.name, state.currentQuestion!!.choices.map { it.displayName() })
31+
val correctIndex = state.currentQuestion.choices.indexOfFirst { it.id == state.currentQuestion.itemId }
32+
val matchingIndex = match(action.name, state.currentQuestion.choices.map { it.displayName() })
3433
when (matchingIndex) {
3534
NO_MATCH -> {
3635
answerName = null
3736
Question.Status.INCORRECT
3837
}
3938
correctIndex -> {
40-
answerName = state.currentQuestion!!.choices[matchingIndex].displayName()
39+
answerName = state.currentQuestion.choices[matchingIndex].displayName()
4140
Question.Status.CORRECT
4241
}
4342
else -> {
44-
answerName = state.currentQuestion!!.choices[matchingIndex].displayName()
43+
answerName = state.currentQuestion.choices[matchingIndex].displayName()
4544
Question.Status.INCORRECT
4645
}
4746
}
@@ -54,7 +53,7 @@ val reducer: Reducer<AppState> = { state: AppState, action ->
5453
state.copy(questions = newQuestions, waitingForNextQuestion = true)
5554
}
5655
is NextQuestionAction -> state.copy(waitingForNextQuestion = false, currentQuestionIndex = state.currentQuestionIndex + 1)
57-
is GameCompleteAction -> state.copy(waitingForNextQuestion = false, currentQuestionIndex = state.currentQuestionIndex + 1)
56+
is GameCompleteAction -> state.copy(waitingForNextQuestion = false)
5857
is ResetGameStateAction -> AppState.INITIAL_STATE.copy(settings = state.settings)
5958
is StartQuestionTimerAction -> state.copy(questionClock = action.initialValue)
6059
is DecrementCountDownAction -> state.copy(questionClock = state.questionClock - 1)

common/src/commonMain/kotlin/com/willowtreeapps/common/middleware/UiMiddleware.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ package com.willowtreeapps.common.middleware
33
import com.willowtreeapps.common.*
44
import com.willowtreeapps.common.util.debounce
55
import com.willowtreeapps.common.util.isAndroid
6-
import org.reduxkotlin.Dispatcher
7-
import org.reduxkotlin.Middleware
8-
import org.reduxkotlin.Store
9-
import org.reduxkotlin.middleware
6+
import org.reduxkotlin.*
107
import kotlin.coroutines.CoroutineContext
118

129
fun uiMiddleware(networkThunks: NetworkThunks,
@@ -70,6 +67,12 @@ fun uiMiddleware(networkThunks: NetworkThunks,
7067
is UiActions.CategoryPicked -> dispatch(Actions.ChangeCategorySettingsAction(action.categoryId))
7168
is UiActions.NumQuestionsPicked -> dispatch(Actions.ChangeNumQuestionsSettingsAction(action.numQuestions))
7269
is UiActions.MicrophoneModeToggled -> dispatch(Actions.ChangeMicrophoneModeSettingsAction(action.enabled))
70+
is UiActions.BackPressOnQuestions -> {
71+
dispatch(timerThunks.stopTimer())
72+
dispatch(timerThunks.cancelDelayed())
73+
dispatch(Actions.ResetGameStateAction())
74+
// dispatch(NavigationActions.NavigateTo(Screen.START))
75+
}
7376
else -> next(action)
7477
}
7578
}
@@ -87,5 +90,6 @@ class UiActions {
8790
class EndGameTapped
8891
class ProfileImageDidShow
8992
data class NamePicked(val name: String)
93+
class BackPressOnQuestions
9094
}
9195

common/src/commonMain/kotlin/com/willowtreeapps/common/ui/QuestionView.kt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,19 @@ interface QuestionView : GameBaseView {
2727
}
2828

2929
val questionPresenter = presenter<QuestionView> {{
30-
withSingleField({ it.questionClock }, { setTimerText(state.toQuestionViewState()) })
30+
+{ state.questionClock }+ { setTimerText(state.toQuestionViewState()) }
3131

32-
withSingleField({
33-
it.currentQuestion?.itemId?.id ?: Any()
34-
}, { showProfile(state.toQuestionViewState()) })
32+
+{ state.currentQuestion.itemId.id } + { showProfile(state.toQuestionViewState()) }
3533

36-
withSingleField({ it.waitingForNextQuestion }) {
34+
+{ state.waitingForNextQuestion } + {
3735
if (state.waitingForNextQuestion) {
3836
if (state.settings.microphoneMode) {
3937
closeMic()
4038
if (!state.isGameComplete()) {
4139
store.dispatch(UiActions.NextQuestionDelayed())
4240
}
4341
}
44-
when (state.currentQuestion?.status) {
42+
when (state.currentQuestion.status) {
4543
Question.Status.CORRECT -> {
4644
showCorrectAnswer(state.toQuestionViewState(), state.isGameComplete())
4745
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.willowtreeapps.common.util
2+
3+
import org.reduxkotlin.AttachView
4+
import org.reduxkotlin.DetachView
5+
import org.reduxkotlin.View
6+
import org.reduxkotlin.rootDispatch
7+
8+
//Here only until a solution is found for rootDispatch & AttachView class not
9+
//visible from swift.
10+
fun attachView(view: View) = rootDispatch(AttachView(view))
11+
fun detachView(view: View) = rootDispatch(DetachView(view))
12+
fun clearView(view: View) = rootDispatch(DetachView(view))

iOS/NameGame/NameGame.xcodeproj/project.pbxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@
388388
);
389389
runOnlyForDeploymentPostprocessing = 0;
390390
shellPath = /bin/sh;
391-
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n#move to the xcode-frameworks folder\n#cd \"$SRCROOT/../../common/build/xcode-frameworks\"\ncd \"$SRCROOT/../../\"\n\n#run the gradle task\n./gradlew :common:build -PXCODE_CONFIGURATION=${CONFIGURATION}\n";
391+
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\n#move to the xcode-frameworks folder\n#cd \"$SRCROOT/../../common/build/xcode-frameworks\"\ncd \"$SRCROOT/../../\"\n\n#run the gradle task\n#./gradlew :common:build -PXCODE_CONFIGURATION=${CONFIGURATION}\n./gradlew packforxcode -PXCODE_CONFIGURATION=${CONFIGURATION}\n\n";
392392
};
393393
277D0BB52D26BF640FE16445 /* [CP] Check Pods Manifest.lock */ = {
394394
isa = PBXShellScriptBuildPhase;

iOS/NameGame/NameGame/BaseNameGameViewController.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import UIKit
33
import common
44

55

6-
class BaseNameViewController : UIViewController, View {
6+
class BaseNameViewController : UIViewController, Presenter_middlewareView {
7+
8+
79
required init?(coder aDecoder: NSCoder) {
810
let appDelegate = UIApplication.shared.delegate as! AppDelegate
911
appDelegate.initilize()
@@ -13,12 +15,12 @@ class BaseNameViewController : UIViewController, View {
1315

1416
override func viewDidDisappear(_ animated: Bool) {
1517
super.viewWillAppear(animated)
16-
PresenterInjecterKt.rootDispatch(DetachView(view: self))
18+
PresenterInjectorKt.detachView(view: self)
1719
}
1820

1921
override func viewWillAppear(_ animated: Bool) {
2022
super.viewWillAppear(animated)
21-
PresenterInjecterKt.rootDispatch(AttachView(view: self))
23+
PresenterInjectorKt.attachView(view: self)
2224
}
2325

2426
}

0 commit comments

Comments
 (0)