Skip to content

Commit

Permalink
Merge pull request #309 from fga-gpp-mds/feature/120
Browse files Browse the repository at this point in the history
Feature/120
  • Loading branch information
Geovannioj authored May 21, 2018
2 parents 08b1e84 + 2f7a816 commit 5057a48
Show file tree
Hide file tree
Showing 26 changed files with 277 additions and 113 deletions.
2 changes: 1 addition & 1 deletion project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
android:label="CommentsActivity"
android:screenOrientation="portrait" />
<activity
android:name=".MatchScene.MatchView"
android:name=".MatchScene.MatchFragment"
android:label="MatchActivity"
android:screenOrientation="portrait" />
</application>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ interface ChallengeBusinessLogic {
*
* @param request variable that gets the request from the 'send challenge' button
*/
fun requestMessageForChallenger(request: ChallengeModel.ChallengeButtonRequest.Request)
fun requestChallenger(request: ChallengeModel.ChallengeButtonRequest.Request)
}

/**
Expand Down Expand Up @@ -79,10 +79,10 @@ class ChallengeInteractor : ChallengeBusinessLogic {
*
* @param request
*/
override fun requestMessageForChallenger(request: ChallengeModel.ChallengeButtonRequest.Request) {
override fun requestChallenger(request: ChallengeModel.ChallengeButtonRequest.Request) {

worker.fetchMessageForChallenge(request) { response ->
this.presenter?.formatMessage(response)
worker.generateChallenge(request) { response ->
this.presenter?.formatMatch(response)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package com.nexte.nexte.ChallengeScene
import com.nexte.nexte.MatchScene.MatchModel
import com.nexte.nexte.Player

/**
Expand Down Expand Up @@ -79,16 +80,21 @@ class ChallengeModel {
* Responsible for the user of the challenge
*
* @param username is the challenged user
* @param challenge is the challenge
*/
class Response(var username: String)
class Response(var username: String,
var challenge: MatchModel.MatchData)

/**
* Class responsible to show a confirmation message informing that a challenged
* has been sent
*
* @param messageForChallenger message with the confirmation of the challenge sent
* @param matchMessage indicate the response of the challenge
*/
class ViewModel(var messageForChallenger: String)
class ViewModel(var messageForChallenger: String,
var matchMessage: String,
var matchData : MatchModel.MatchData?)
}

// ---------- Aux classes ----------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ interface ChallengePresentationLogic {
*
* @param response contains unformatted data received from [ChallengeModel]
*/
fun formatMessage(response : ChallengeModel.ChallengeButtonRequest.Response)
fun formatMatch(response : ChallengeModel.ChallengeButtonRequest.Response)

/**
* Method responsible to format the message tho inform that there are no
Expand Down Expand Up @@ -95,12 +95,17 @@ class ChallengePresenter : ChallengePresentationLogic {
*
* @param response contains unformatted data received from [ChallengeWorker]
*/
override fun formatMessage(response: ChallengeModel.ChallengeButtonRequest.Response) {
val message: String
override fun formatMatch(response: ChallengeModel.ChallengeButtonRequest.Response) {

message = String.format("Desafio enviado com sucesso para o jogador %s", response.username)
val message: String = String.format("Desafio enviado com sucesso para o jogador %s", response.username)

val viewModel = ChallengeModel.ChallengeButtonRequest.ViewModel(message)
val matchMessage: String = if(response.challenge.challenged.name != ""){
"Você já enviou um desafio"
} else{
""
}

val viewModel = ChallengeModel.ChallengeButtonRequest.ViewModel(message, matchMessage, response.challenge)

viewChallenge?.displayMessage(viewModel)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import android.content.Context
import android.os.Bundle
import android.support.v4.app.Fragment
import android.support.v4.app.FragmentManager
import android.support.v4.app.FragmentPagerAdapter
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
Expand All @@ -14,8 +13,12 @@ import com.nexte.nexte.R
import kotlinx.android.synthetic.main.activity_challenger_sent.*
import kotlinx.android.synthetic.main.columns_challenged.view.*
import android.app.AlertDialog
import android.support.v4.app.FragmentStatePagerAdapter
import android.support.v4.view.PagerAdapter
import android.widget.Button
import android.widget.TextView
import com.nexte.nexte.MatchScene.MatchFragment
import com.nexte.nexte.MatchScene.MatchModel
import com.nexte.nexte.UserSingleton
import kotlinx.android.synthetic.main.activity_challenger.*

Expand Down Expand Up @@ -63,24 +66,18 @@ interface ChallengeDisplayLogic {
*/
class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {

var match: MatchModel.MatchData?= null
var recyclerView: RecyclerView?= null
var sendChallengeButton: Button?= null
var expandedLosses: TextView?= null
var expandedWins: TextView?= null
var expandedRankingTextView: TextView?= null
var expandedName: TextView?= null
var noPlayersText: TextView?= null
var message: TextView?= null
var interactor: ChallengeBusinessLogic? = null
private val context: Context? = null

/**
* This object is used for avoid magic numbers
*/
companion object {

const val playerRanking = 8 //simulates the logged player ranking
}

/**
* Method called whenever the view is created, responsible for create first
* request and set listeners
Expand All @@ -90,7 +87,7 @@ class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {
super.onCreate(savedInstanceState)
this.setContentView(R.layout.activity_challenger)
this.setupChallengeScene()
viewpager.adapter = ViewPagerAdapter(supportFragmentManager)
viewpager.adapter = ViewPagerAdapter(supportFragmentManager, this)
tabs.setupWithViewPager(viewpager)
}

Expand Down Expand Up @@ -143,11 +140,21 @@ class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {
*/
override fun displayMessage(viewModel: ChallengeModel.ChallengeButtonRequest.ViewModel) {

if(viewModel.matchMessage != ""){
this.match = viewModel.matchData
this.message?.text = viewModel.matchMessage
this.message?.visibility = View.VISIBLE
this.sendChallengeButton?.isEnabled = false
this.viewpager.adapter.notifyDataSetChanged()
}


val builder = AlertDialog.Builder(this)

builder.setCancelable(true)
builder.setMessage(viewModel.messageForChallenger)
builder.setPositiveButton("Ok", { dialogInterface, _ ->
this.tabs.getTabAt(1)?.select()
dialogInterface.cancel()
})

Expand Down Expand Up @@ -255,7 +262,12 @@ class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {
viewContext.expandedRankingTextView = view?.findViewById(R.id.expandedRankingTextView)
viewContext.expandedWins = view?.findViewById(R.id.expandedWins)
viewContext.noPlayersText = view?.findViewById(R.id.noPlayersText)
} else {
viewContext.message = view?.findViewById(R.id.message)
if(viewContext.match != null){
viewContext.message?.visibility = View.VISIBLE
}
}
else {
view = inflater?.inflate(R.layout.activity_challenger_received, container, false)
}
return view
Expand All @@ -269,33 +281,38 @@ class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {

sendChallengeButton?.setOnClickListener {
val request = ChallengeModel.ChallengeButtonRequest.Request(this.expandedName.text.toString())
(context as ChallengeView).interactor?.requestMessageForChallenger(request)
(context as ChallengeView).interactor?.requestChallenger(request)
}

val request = ChallengeModel.ShowRankingPlayersRequest.Request(UserSingleton.getUserInformations().rankingPosition)
(context as ChallengeView).interactor?.requestPlayersToChallenge(request)
}

}
}

/**
* Adapter Class that populates the fragment
*/
class ViewPagerAdapter (fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) {
class ViewPagerAdapter (fragmentManager: FragmentManager,
var context: Context) : FragmentStatePagerAdapter(fragmentManager) {

private val pageTitles = listOf("Tenistas", "Enviados", "Recebidos")

private val pageTitles = listOf("Enviados", "Recebidos")
override fun getItemPosition(`object`: Any?): Int {
return PagerAdapter.POSITION_NONE
}

override fun getCount(): Int {

return pageTitles.size
}

override fun getItem(position: Int): Fragment {

val tabFragment = TabFragment()

return tabFragment.getInstance(position)
return if(position == 1){
MatchFragment().getInstance((context as ChallengeView).match)
} else{
TabFragment().getInstance(position)
}
}

override fun getPageTitle(position: Int): CharSequence {
Expand Down Expand Up @@ -362,6 +379,11 @@ class ChallengeView : AppCompatActivity(), ChallengeDisplayLogic {
context.removePlayerDetailedInfo()
context.sendChallengeButton?.isEnabled = false
}
if(context.match != null){
context.sendChallengeButton?.isEnabled = false
}


}

override fun getItemCount(): Int {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.nexte.nexte.ChallengeScene

import com.nexte.nexte.MatchScene.MatchModel
import com.nexte.nexte.Player
import com.nexte.nexte.R
import com.nexte.nexte.UserSingleton

/**
* Class responsible to do request for anywhere, format Response and
Expand Down Expand Up @@ -67,12 +70,16 @@ class ChallengeWorker {
* @param request Challenge Model request that contains needed information to send to server
* @param completion Method to call on parent class
*/
fun fetchMessageForChallenge(request: ChallengeModel.ChallengeButtonRequest.Request,
completion: (ChallengeModel.ChallengeButtonRequest.Response) -> Unit) {
fun generateChallenge(request: ChallengeModel.ChallengeButtonRequest.Request,
completion: (ChallengeModel.ChallengeButtonRequest.Response) -> Unit) {

val user = request.userChallenged

val response = ChallengeModel.ChallengeButtonRequest.Response(user)
val challenged = MatchModel.MatchPlayer(user, R.mipmap.ic_launcher_round)
val challenger = MatchModel.MatchPlayer(UserSingleton.getUserInformations().name, R.mipmap.ic_launcher_round)
val match = MatchModel.MatchData(challenged, challenger)

val response = ChallengeModel.ChallengeButtonRequest.Response(user, match)

completion(response)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,11 @@ class StoryAdapterRealm: StoryAdapter{
likesIdRealmList.add(like)
}

val storyRealm = StoryRealm(id = id, winnerId = winnerId, winnerSetResult = winnerSetResult, loserId = loserId, loserSetResult = loserSetResult, date = date, commentsId = commentsIdRealmList, likesId = likesIdRealmList)
val storyRealm = StoryRealm(id = id, winnerId = winnerId,
winnerSetResult = winnerSetResult, loserId = loserId,
loserSetResult = loserSetResult, date = date,
commentsId = commentsIdRealmList,
likesId = likesIdRealmList)
return storyRealm
}

Expand Down
1 change: 1 addition & 0 deletions project/app/src/main/java/com/nexte/nexte/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MainActivity : AppCompatActivity() {
bottom_nav_view.setOnNavigationItemReselectedListener(mOnNavigationItemReselectedListener)
this.bottom_nav_view.selectedItemId = R.id.profile


loginButton.setOnClickListener {
val intent = Intent(this, LoginView::class.java)
startActivity(intent)
Expand Down
Loading

0 comments on commit 5057a48

Please sign in to comment.