Commit 75f52e78 authored by Niklas Fix's avatar Niklas Fix 🎓

add info box if user has no pools (#59)

parent 1d022a34
......@@ -28,6 +28,8 @@ interface DashboardContract {
fun onLoadUserSuccess(user: User)
/** Let the user know what went wrong when loading the avatar **/
fun onLoadUserFail(reason: String)
/** Show infor Box **/
fun showInfoBox()
/** Destroys the login token on logout */
fun destroyLoginToken()
/** Finish the Activity **/
......@@ -45,6 +47,8 @@ interface DashboardContract {
fun onLogoutClick() : Boolean
/** Load app user from server **/
fun loadAppUserFromServer()
/** Fetch user's pools **/
fun fetchPools()
}
}
\ No newline at end of file
package de.akamu.tudarmstadt.features.dashboard
import de.akamu.tudarmstadt.data.questionpools.QuestionPoolsDataSource
import de.akamu.tudarmstadt.data.questionpools.QuestionPoolsDataSourceImpl
import de.akamu.tudarmstadt.data.user.UserDataSource
import de.akamu.tudarmstadt.features.questionpools.QuestionPoolsInteractor
import de.akamu.tudarmstadt.interactors.UserInteractor
import de.akamu.tudarmstadt.model.Pool
import de.akamu.tudarmstadt.model.User
import de.akamu.tudarmstadt.util.AppUserUtil
class DashboardPresenter(private var view: DashboardContract.View?, private val interactor: UserInteractor) : DashboardContract.Presenter {
......@@ -44,6 +49,22 @@ class DashboardPresenter(private var view: DashboardContract.View?, private val
})
}
override fun fetchPools() {
val qp_interactor = QuestionPoolsInteractor(QuestionPoolsDataSourceImpl())
qp_interactor.fetchPlayablePools(object : QuestionPoolsDataSource.FetchPlayablePoolsCallback {
override fun onFetchPlayablePoolsSuccess(pools: ArrayList<Pool>) {
if(AppUserUtil.checkIfUserNeedsPools(pools)) {
view?.showInfoBox()
}
}
override fun onFetchPlayablePoolsFailed(reason: String) {
// silent
}
})
}
override fun stop() {
view = null
}
......
......@@ -89,6 +89,8 @@ class MainActivity : BaseActivity(), DashboardContract.View, NextLevelEventHandl
fillProfile()
setupBottomNavigation()
presenter.fetchPools()
when(intent.getIntExtra(Constants.KEY_MAINACTIVITY_PAGE, 0)) {
Constants.DUEL_LIST_FRAGMENT -> navigateToDuelList()
Constants.CHALLENGE_FRAGMENT -> navigateToChallenge()
......@@ -112,6 +114,8 @@ class MainActivity : BaseActivity(), DashboardContract.View, NextLevelEventHandl
super.onActivityResult(requestCode, resultCode, data)
if (data?.getBooleanExtra("finishActivity", false) == true) {
finish()
} else if (data?.getBooleanExtra("hasSelectedPools", false) == true) {
constraintlayout_main_info.visibility = View.GONE
}
}
......@@ -237,4 +241,13 @@ class MainActivity : BaseActivity(), DashboardContract.View, NextLevelEventHandl
textview_mainactivity_next_lvl.text = user?.level?.plus(1).toString()
ProgressBarAddNewPointsAnimation.animate(progressbar_mainactivity_lvl, AppUserUtil.getUserProgress(user!!), this)
}
override fun showInfoBox() {
constraintlayout_main_info.visibility = View.VISIBLE
button_main_needs_pools.setOnClickListener {
val i = Intent(this, QuestionPoolsActivity::class.java)
i.putExtra(Constants.KEY_NEEDS_POOL, true)
startActivityForResult(i, Constants.MAIN_ACTIVITY_REQ_CODE)
}
}
}
package de.akamu.tudarmstadt.features.questionpools
import android.app.Activity
import android.content.Intent
import android.os.Bundle
import android.transition.TransitionManager
import android.view.MenuItem
......@@ -14,6 +16,7 @@ import de.akamu.tudarmstadt.BaseActivity
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.data.questionpools.QuestionPoolsDataSourceImpl
import de.akamu.tudarmstadt.model.Pool
import de.akamu.tudarmstadt.util.Constants
import de.akamu.tudarmstadt.util.Extensions.Companion.toast
import de.akamu.tudarmstadt.util.SortOrder
import kotlinx.android.synthetic.main.activity_question_pools.*
......@@ -38,6 +41,8 @@ class QuestionPoolsActivity :
presenter = QuestionPoolsPresenter(QuestionPoolsInteractor(QuestionPoolsDataSourceImpl()), this)
presenter.userNeedsPools = intent.getBooleanExtra(Constants.KEY_NEEDS_POOL, false)
button_question_pools_filter.visibility = View.GONE
recyclerView_myQPs.visibility = View.GONE
layout_dotloader_qps.visibility = View.VISIBLE
......@@ -105,14 +110,12 @@ class QuestionPoolsActivity :
presenter.addOrRemovePool(pools)
}
// TODO: needs string reources
override fun showUpdatingUserPoolsSuccess() {
toast("Successfully updated your pools.")
toast(getString(R.string.updated_pools_success))
}
// TODO: needs string reources
override fun showUpdatingUserPoolsFailed(reason: String) {
toast("Failed to update pool due to $reason")
toast(getString(R.string.updated_pools_failed, reason))
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
......@@ -123,4 +126,19 @@ class QuestionPoolsActivity :
return false
}
override fun onBackPressed() {
if (!presenter.userNeedsPools) {
returnAndCloseInfoBox()
} else {
super.onBackPressed()
}
}
override fun returnAndCloseInfoBox() {
val data = Intent()
data.putExtra("hasSelectedPools", true)
setResult(Activity.RESULT_OK, data)
finish()
}
}
......@@ -11,9 +11,11 @@ interface QuestionPoolsContract {
fun bindAdapter(pools: ArrayList<Pool>)
fun showUpdatingUserPoolsSuccess()
fun showUpdatingUserPoolsFailed(reason: String)
fun returnAndCloseInfoBox()
}
interface Presenter : BasePresenter {
var userNeedsPools: Boolean
fun fetchPools()
fun addOrRemovePool(pools: ArrayList<Pool>)
}
......
......@@ -2,10 +2,13 @@ package de.akamu.tudarmstadt.features.questionpools
import de.akamu.tudarmstadt.data.questionpools.QuestionPoolsDataSource
import de.akamu.tudarmstadt.model.Pool
import de.akamu.tudarmstadt.util.AppUserUtil
class QuestionPoolsPresenter(private val interactor: QuestionPoolsInteractor, var view: QuestionPoolsContract.View?)
: QuestionPoolsContract.Presenter {
override var userNeedsPools: Boolean = false
init {
view?.presenter = this
}
......@@ -14,6 +17,7 @@ class QuestionPoolsPresenter(private val interactor: QuestionPoolsInteractor, va
interactor.fetchPlayablePools(object : QuestionPoolsDataSource.FetchPlayablePoolsCallback {
override fun onFetchPlayablePoolsSuccess(pools: ArrayList<Pool>) {
view?.bindAdapter(pools)
userNeedsPools = AppUserUtil.checkIfUserNeedsPools(pools)
}
override fun onFetchPlayablePoolsFailed(reason: String) {
......@@ -27,6 +31,7 @@ class QuestionPoolsPresenter(private val interactor: QuestionPoolsInteractor, va
interactor.updateUserPools(pools, object : QuestionPoolsDataSource.UpdateUserPoolsCallback {
override fun onUpdateUserPoolsSuccess() {
view?.showUpdatingUserPoolsSuccess()
userNeedsPools = AppUserUtil.checkIfUserNeedsPools(pools)
}
override fun onUpdateUserPoolsFailed(reason: String) {
......
......@@ -5,6 +5,7 @@ import com.google.android.gms.tasks.Tasks
import com.google.firebase.iid.FirebaseInstanceId
import de.akamu.tudarmstadt.App
import de.akamu.tudarmstadt.R
import de.akamu.tudarmstadt.model.Pool
import de.akamu.tudarmstadt.model.User
import kotlin.math.floor
import kotlin.math.sqrt
......@@ -43,6 +44,15 @@ class AppUserUtil {
return (frac * 100).toInt()
}
fun checkIfUserNeedsPools(pools: ArrayList<Pool>): Boolean {
for (pool in pools) {
if (pool.isSelected) {
return false
}
}
return true
}
/**
* Saves/updates the user's login token
*
......
......@@ -35,6 +35,7 @@ class Constants {
const val KEY_UNAUTHORIZED = "KEY_UNAUTHORIZED"
const val KEY_DSE_INFO = "DSE_INFO"
const val KEY_MAINACTIVITY_PAGE = "KEY_MAINACTIVITY_PAGE"
const val KEY_NEEDS_POOL = "KEY_NEEDS_POOL"
// ARG KEYS
const val KEY_OPTION_ANSWER = "OPTION_ANSWER"
......
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="?android:attr/colorControlHighlight">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="#000000" />
<corners android:radius="64dp" />
</shape>
</item>
<item android:drawable="@drawable/oval_plain_white"/>
</ripple>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<shape android:shape="rectangle">
<corners android:radius="1000dp" />
<solid android:color="@color/white" />
<padding
android:bottom="4dp"
android:left="4dp"
android:right="4dp"
android:top="4dp" />
</shape>
</item>
</selector>
\ No newline at end of file
......@@ -172,6 +172,45 @@
</androidx.constraintlayout.widget.ConstraintLayout>
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintlayout_main_info"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/constraintlayout_main_header"
app:layout_constraintBottom_toTopOf="@id/fragments_frame_dashboard"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:background="@color/colorInfoBlock"
android:visibility="gone">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:textColor="@color/darkText"
android:padding="6dp"
android:text="@string/info_needs_pools"
android:layout_weight="0.6"/>
<Button
android:id="@+id/button_main_needs_pools"
style="@style/AppButtonWhite"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:text="@string/choose_pools"
android:layout_margin="6dp"
android:layout_weight="0.3"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<FrameLayout
android:id="@+id/fragments_frame_dashboard"
android:layout_width="0dp"
......@@ -180,7 +219,7 @@
app:layout_constraintBottom_toTopOf="@id/main_bottom_nav"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/constraintlayout_main_header" />
app:layout_constraintTop_toBottomOf="@+id/constraintlayout_main_info" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/main_bottom_nav"
......
......@@ -33,6 +33,8 @@
<color name="iconAccent">#40a8c4</color>
<color name="iconBlack">#FFFFFF</color>
<color name="colorInfoBlock">#055165</color>
<!--TRANSPARENT -->
<color name="transparent">#00000000</color>
......
......@@ -33,6 +33,8 @@
<color name="iconAccent">#40a8c4</color>
<color name="iconBlack">#000000</color>
<color name="colorInfoBlock">#FFC857</color>
<!--TRANSPARENT -->
<color name="transparent">#00000000</color>
......
......@@ -27,6 +27,13 @@
<item name="android:textStyle">bold</item>
</style>
<style name="AppButtonWhite">
<item name="android:background">@drawable/button_circle_ripple_white
</item>
<item name="android:textColor">@color/akamu_blue</item>
<item name="android:textStyle">bold</item>
</style>
<style name="AppButtonBorders">
<item name="android:background">@drawable/button_borders_ripple</item>
<item name="android:textColor">@color/akamu_blue</item>
......
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