Commit 1cfc13aa authored by Niklas Fix's avatar Niklas Fix 🎓

fix no common pools bug

parent 08ea57e7
......@@ -19,6 +19,7 @@ interface FriendsDataSource {
fun onChallengeRequestSuccess(friendName: String)
fun onChallengeRequestFailed(reason : String)
fun onChallengeRequestFailedNoPoolsSelected()
fun onChallengeRequestFailedNoPoolsInCommon()
}
interface GetAllUsersCallback {
......
......@@ -3,6 +3,7 @@ package de.akamu.tudarmstadt.data.friends
import android.os.AsyncTask
import de.akamu.tudarmstadt.api.V2APIDuel
import de.akamu.tudarmstadt.api.V2APIFriend
import de.akamu.tudarmstadt.api.V2APIPool
import de.akamu.tudarmstadt.api.V2APIUser
import de.akamu.tudarmstadt.exceptions.AkamuAPIException
import de.akamu.tudarmstadt.model.User
......@@ -51,16 +52,24 @@ class FriendsDataSourceImpl : FriendsDataSource {
var errorMessage : String = "Oops! Something went wrong..."
private var noPoolsSelected: Boolean = false
private var noPoolsInCommon: Boolean = false
override fun doInBackground(vararg params: Void?): Boolean {
return try {
V2APIDuel.startDuel(friend.id.toInt())
true
val playablePools = V2APIPool.getPlayablePools()
val myPools = playablePools.filter { pool -> pool.isSelected }
if (myPools.isEmpty()) {
noPoolsSelected = true
false
} else {
V2APIDuel.startDuel(friend.id.toInt())
true
}
} catch (ae : AkamuAPIException) {
ae.printStackTrace()
errorMessage = ae.message!!
if (ae.code == 409) {
noPoolsSelected = true
noPoolsInCommon = true
}
false
} catch (e : Exception) {
......@@ -76,6 +85,8 @@ class FriendsDataSourceImpl : FriendsDataSource {
} else {
if (noPoolsSelected) {
callback.onChallengeRequestFailedNoPoolsSelected()
} else if (noPoolsInCommon) {
callback.onChallengeRequestFailedNoPoolsInCommon()
} else {
callback.onChallengeRequestFailed(errorMessage)
}
......
......@@ -205,6 +205,33 @@ class FriendsListFragment : Fragment(),
infoDialog.show()
}
override fun showSendChallengeRequestFailedNoPoolsInCommon() {
lateinit var infoDialog: AlertDialog
val builder = AlertDialog.Builder(context, R.style.DialogStyle)
builder.setTitle(getString(R.string.no_common_questionpools))
val infoTextView = TextView(requireActivity())
infoTextView.text = getString(R.string.no_common_questionpool_info)
infoTextView.setTextColor(ContextCompat.getColor(requireActivity(), R.color.textLight))
val container = FrameLayout(requireActivity())
val params = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
params.leftMargin = resources.getDimensionPixelSize(R.dimen.dialog_margin)
params.rightMargin = resources.getDimensionPixelSize(R.dimen.dialog_margin)
infoTextView.layoutParams = params
container.addView(infoTextView)
builder.setView(container)
builder.setPositiveButton(getString(R.string.select_your_questionpools)) { _: DialogInterface, _: Int ->
(requireActivity() as MainActivity).navigateToChangeQuestionPools()
}
builder.setNegativeButton(getString(R.string.cancel)) { dialog, _ ->
dialog.cancel()
}
infoDialog = builder.create()
infoDialog.show()
}
override fun showSendChallengeRequestSuccess(friendName: String) {
Toast.makeText(requireActivity(), friendName + " " + getString(R.string.prompt_challenged_successful), Toast.LENGTH_SHORT).show()
}
......
......@@ -8,6 +8,7 @@ import android.widget.ImageButton
import android.widget.ImageView
import android.widget.ProgressBar
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.model.Duel
......@@ -137,7 +138,7 @@ class FriendsListAdapter(
sendChallengeButton.visibility = View.VISIBLE
sendChallengeButton.isEnabled = false
sendChallengeButton.animate()?.rotation(360F)?.start()
sendChallengeButton.background = context.getDrawable(R.drawable.md_transparent)
sendChallengeButton.background = ContextCompat.getDrawable(context, R.drawable.md_transparent)
sendChallengeButton.setImageResource(R.drawable.ic_checked_akamu_blue)
}
......
......@@ -18,6 +18,8 @@ interface FriendsListContract {
fun showSendChallengeRequestFailed(reason: String)
/** Let the user know that sending a challenge request has failed because no pool has been selected **/
fun showSendChallengeRequestFailedNoPoolsSelected()
/** Let the user know that sending a challenge request has failed because both players have no common pools **/
fun showSendChallengeRequestFailedNoPoolsInCommon()
/** Let the user know that sending a challenge request was successful **/
fun showSendChallengeRequestSuccess(friendName: String)
/** Bind the SearchListAdapter to the recycler view by passing a list of users **/
......
......@@ -33,6 +33,10 @@ class FriendsListInteractor(private val dataSource: FriendsDataSourceImpl) : Fri
callback.onChallengeRequestFailedNoPoolsSelected()
}
override fun onChallengeRequestFailedNoPoolsInCommon() {
callback.onChallengeRequestFailedNoPoolsInCommon()
}
})
}
......
......@@ -76,6 +76,11 @@ class FriendsListPresenter(
callback.indicateChallengeSentFailed()
}
override fun onChallengeRequestFailedNoPoolsInCommon() {
view?.showSendChallengeRequestFailedNoPoolsInCommon()
callback.indicateChallengeSentFailed()
}
})
}
......
......@@ -225,4 +225,7 @@
href="https://firebase.google.com/terms/crashlytics-app-distribution-data-processing-terms/"> hier</a> finden.</string>
<string name="dse_page8_activate_crashlytics">Crashlytics aktivieren</string>
<string name="dse_page8_help_us">Indem du Crashlytics aktivierst, kannst du uns helfen, Akamu besser zu machen.</string>
<string name="load_user_failed">Nutzer konnte nicht geladen werden: %1$s</string>
<string name="no_common_questionpools">Keine gemeinsamen FragenPools</string>
<string name="no_common_questionpool_info">Um ein Duell spielen zu können, müssen du und dein Freund einen gemeinsamen FragenPool haben. Entweder hat dein Freund noch keine Pools ausgewählt, oder du kannst versuchen, andere Pools zu setzen.</string>
</resources>
\ No newline at end of file
......@@ -277,4 +277,7 @@
href="https://firebase.google.com/terms/crashlytics-app-distribution-data-processing-terms/"> here</a>.</string>
<string name="dse_page8_activate_crashlytics">Activate Crashlytics</string>
<string name="dse_page8_help_us">By enabling Crashlytics you can help us make Akamu better.</string>
<string name="load_user_failed">Failed to load user: %1$s</string>
<string name="no_common_questionpools">No common QuestionPools</string>
<string name="no_common_questionpool_info">In order to play a duel, you and your friend need to have common QuestionPools. Either your friend hasn\'t chosen any pools yet or you can try to select other pools.</string>
</resources>
......@@ -340,5 +340,9 @@
href="https://firebase.google.com/terms/crashlytics-app-distribution-data-processing-terms/"> here</a>.</string>
<string name="dse_page8_activate_crashlytics">Activate Crashlytics</string>
<string name="dse_page8_help_us">By enabling Crashlytics you can help us make Akamu better.</string>
<string name="load_user_failed">Failed to load user: %1$s</string>
<string name="OK" translatable="false">OK</string>
<string name="no_common_questionpools" >No common QuestionPools</string>
<string name="no_common_questionpool_info" >In order to play a duel, you and your friend need to have a common QuestionPool. Either your friend hasn\'t chosen any pools yet or you can try to select other pools.</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment