Skip to content

Commit

Permalink
Merge pull request #328 from fga-gpp-mds/feature/121-2
Browse files Browse the repository at this point in the history
Feature/121 2
  • Loading branch information
luis-gustavo authored May 27, 2018
2 parents 1cc8132 + 5578fae commit 7384c64
Show file tree
Hide file tree
Showing 33 changed files with 586 additions and 817 deletions.
4 changes: 2 additions & 2 deletions project/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
android:name=".LoginScene.LoginView"
android:label="Login" />
<activity
android:name=".RankingScene.RankingView"
android:name=".RankingScene.RankingFragment"
android:screenOrientation="portrait" />
<activity
android:name=".FeedScene.FeedFragment"
android:label="@string/title_activity_feed_view"
android:screenOrientation="portrait" />
<activity
android:name=".ShowProfileScene.ShowProfileView"
android:name=".ShowProfileScene.ShowProfileFragment"
android:label="@string/title_activity_show_profile"
android:theme="@style/AppTheme.NoActionBar" />
<!--<activity-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.nexte.nexte.Entities.User

import java.util.*

@Suppress("DEPRECATION")

object UserMocker {

fun generateUsers(): List<User> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class LoginModel {
class AccountKit {

companion object {
const val ACCOUNTKIT_CODE = 13
const val accountKit_code = 13
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic {
super.onActivityResult(requestCode, resultCode, data)

when (requestCode) {
LoginModel.AccountKit.ACCOUNTKIT_CODE -> {
LoginModel.AccountKit.accountKit_code -> {
this.getAccount()
}
}
Expand Down Expand Up @@ -138,7 +138,7 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic {
val configBuilder = AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.PHONE,
AccountKitActivity.ResponseType.TOKEN)
intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, configBuilder.build())
startActivityForResult(intent, LoginModel.AccountKit.ACCOUNTKIT_CODE)
startActivityForResult(intent, LoginModel.AccountKit.accountKit_code)
}

/**
Expand All @@ -149,7 +149,7 @@ class LoginView : AppCompatActivity(), LoginDisplayLogic {
val builder = AccountKitConfiguration.AccountKitConfigurationBuilder(LoginType.EMAIL,
AccountKitActivity.ResponseType.TOKEN)
intent.putExtra(AccountKitActivity.ACCOUNT_KIT_ACTIVITY_CONFIGURATION, builder.build())
startActivityForResult(intent, LoginModel.AccountKit.ACCOUNTKIT_CODE)
startActivityForResult(intent, LoginModel.AccountKit.accountKit_code)
}

/**
Expand Down
43 changes: 22 additions & 21 deletions project/app/src/main/java/com/nexte/nexte/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,30 @@ import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.nexte.nexte.LoginScene.*
import com.nexte.nexte.ShowProfileScene.ShowProfileView
import kotlinx.android.synthetic.main.activity_main.*
import com.nexte.nexte.ShowProfileScene.ShowProfileFragment
import android.support.design.widget.BottomNavigationView
import android.support.v4.app.Fragment
import android.util.Log
import android.widget.Button
import com.nexte.nexte.ChallengeScene.ChallengeView
import com.nexte.nexte.FeedScene.FeedFragment
import com.nexte.nexte.RankingScene.RankingFragment

import com.nexte.nexte.RankingScene.RankingView
class MainActivity : AppCompatActivity() {

private var bottomNavView: BottomNavigationView?= null
private var loginButton: Button?= null

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
bottom_nav_view.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
bottom_nav_view.setOnNavigationItemReselectedListener(mOnNavigationItemReselectedListener)
this.bottom_nav_view.selectedItemId = R.id.profile
bottomNavView =this.findViewById(R.id.bottom_nav_view)
loginButton = this.findViewById(R.id.loginButton)

loginButton.setOnClickListener {
bottomNavView?.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener)
bottomNavView?.setOnNavigationItemReselectedListener(mOnNavigationItemReselectedListener)
bottomNavView?.selectedItemId = R.id.profile
loginButton?.setOnClickListener {
val intent = Intent(this, LoginView::class.java)
startActivity(intent)
}
Expand All @@ -34,19 +37,17 @@ class MainActivity : AppCompatActivity() {
private val mOnNavigationItemReselectedListener = BottomNavigationView.OnNavigationItemReselectedListener { item ->
when(item.itemId) {
R.id.profile -> {
Log.e("Resultado d", item.itemId.toString())
/* Do Nothing*/
}
}
}
private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->

private val mOnNavigationItemSelectedListener = BottomNavigationView.OnNavigationItemSelectedListener { item ->
Log.e("Resultado do item", item.itemId.toString())
when (item.itemId) {
R.id.feed -> {
val feedFragment = FeedFragment().getInstance()
openFragment(feedFragment)
return@OnNavigationItemSelectedListener true

}

R.id.challenge -> {
Expand All @@ -56,27 +57,27 @@ class MainActivity : AppCompatActivity() {
}

R.id.ranking -> {
val intent = Intent(this, RankingView::class.java)
startActivity(intent)
val rankingFragment = RankingFragment().getInstance()
openFragment(rankingFragment)
return@OnNavigationItemSelectedListener true
}

R.id.profile -> {
val showProfileFragment = ShowProfileView.newInstance()
val showProfileFragment = ShowProfileFragment().getInstance(UserSingleton.getUserInformations().name)
openFragment(showProfileFragment)
return@OnNavigationItemSelectedListener true

} else -> {
return@OnNavigationItemSelectedListener true
}
return@OnNavigationItemSelectedListener true
}
}
}

private fun openFragment(fragment: Fragment) {
var transaction = supportFragmentManager.beginTransaction()
val transaction = supportFragmentManager.beginTransaction()
transaction.replace(R.id.frame_layout,fragment)
transaction.addToBackStack(null)
transaction.commit()
}

}

Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package com.nexte.nexte.RankingScene

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.constraint.ConstraintLayout
import android.support.constraint.ConstraintSet
import android.support.v4.app.Fragment
import android.support.v7.widget.ContentFrameLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.nexte.nexte.R
import com.nexte.nexte.ShowProfileScene.ShowProfileView
import com.nexte.nexte.ShowProfileScene.ShowProfileFragment
import com.nexte.nexte.UserSingleton
import kotlinx.android.synthetic.main.activity_ranking.*
import kotlinx.android.synthetic.main.row_ranking.view.*
import android.support.v7.widget.DividerItemDecoration
import com.nexte.nexte.Entities.Challenge.ChallengeManager
Expand All @@ -33,50 +31,62 @@ interface RankingDisplayLogic {

/**
* Class that implements [RankingDisplayLogic]
*
* @property interactor responsible to receive request and send it to worker
*/
class RankingView : AppCompatActivity(), RankingDisplayLogic {
class RankingFragment : Fragment(), RankingDisplayLogic {

var interactor: RankingInteractor? = null
var interactor: RankingInteractor? = null //interactor responsible to receive request and send it to worker
var rankingRecyclerView: RecyclerView?= null
var fixedFragment: ContentFrameLayout?= null
var rankingConstraintLayout: ConstraintLayout?= null
var userManager: UserManager? = null
var challengeManager: ChallengeManager? = null
var challengeManager: ChallengeManager?= null

fun getInstance() : RankingFragment{
return RankingFragment()
}

/**
* Method called on scene creation
*
* @param savedInstanceState
*/

override fun onCreate(savedInstanceState: Bundle?) {

userManager = UserManager()
challengeManager = ChallengeManager()

super.onCreate(savedInstanceState)
setContentView(R.layout.activity_ranking)

rankingRecyclerView.layoutManager = LinearLayoutManager(this)
this.setupRankingScene()
}

override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val view: View? = inflater?.inflate(R.layout.activity_ranking, container, false)

val dividerItemDecoration = DividerItemDecoration(this, requestedOrientation)
rankingRecyclerView.addItemDecoration(dividerItemDecoration)
fixedFragment = view?.findViewById(R.id.fixedFragment)
rankingRecyclerView = view?.findViewById(R.id.rankingRecyclerView)
rankingConstraintLayout = view?.findViewById(R.id.rankingConstraintLayout)
rankingRecyclerView?.layoutManager = LinearLayoutManager(this.activity)
val dividerItemDecoration = DividerItemDecoration(this.activity, DividerItemDecoration.VERTICAL)
rankingRecyclerView?.addItemDecoration(dividerItemDecoration)

val fragmentTransaction = supportFragmentManager.beginTransaction()
val fragmentTransaction = fragmentManager.beginTransaction()
fragmentTransaction.replace(R.id.fixedFragment, FixedRowRankingFragment())
fragmentTransaction.commit()

this.createGetPlayersRequest()

this.rankingRecyclerView.addOnScrollListener(OnScrollRankingRecyclerView(
this.rankingRecyclerView?.addOnScrollListener(OnScrollRankingRecyclerView(
UserSingleton.getUserInformations().rankingPosition, this))

setFixedRanking(this, this.rankingRecyclerView, UserSingleton.getUserInformations().rankingPosition)
}

return view
}

private fun goToShowProfileView() {
val intent = Intent(this, ShowProfileView::class.java)
startActivity(intent)
private fun goToShowProfileView(name: String?) {
val fragment = ShowProfileFragment().getInstance(name)
fragmentManager.beginTransaction().replace(R.id.frame_layout, fragment).addToBackStack(null).commit()
}


Expand All @@ -103,25 +113,25 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
/**
* Function responsible to define when or where the fixed ranking row should appear
*
* @param context indicates the context that the fragment is contained in
* @param fragment indicates the fragment that this fragment is contained in
* @param recyclerView indicates the recycler view that will be used to control how the fixed row will be displayed
* @param playerRanking Indicates the player position that will be shown on screen, and it is used for comparision.
*/
private fun setFixedRanking(context: Context, recyclerView: RecyclerView?, playerRanking: Int) {
private fun setFixedRanking(fragment: Fragment, recyclerView: RecyclerView?, playerRanking: Int) {

val constraintSet = ConstraintSet()
val rankingView = context as RankingView
val rankingView = fragment as RankingFragment
val layoutManager = recyclerView?.layoutManager as LinearLayoutManager

if(layoutManager.findFirstCompletelyVisibleItemPosition() <= playerRanking - 1
&& playerRanking - 1 <= layoutManager.findLastCompletelyVisibleItemPosition()) {

rankingView.fixedFragment.visibility = View.INVISIBLE
rankingView.fixedFragment?.visibility = View.INVISIBLE
}

else if (playerRanking - 1 > layoutManager.findLastCompletelyVisibleItemPosition()) {

rankingView.fixedFragment.visibility = View.VISIBLE
rankingView.fixedFragment?.visibility = View.VISIBLE
constraintSet.clone(rankingView.rankingConstraintLayout)
constraintSet.clear(R.id.fixedFragment, ConstraintSet.BOTTOM)
constraintSet.clear(R.id.fixedFragment, ConstraintSet.TOP)
Expand All @@ -131,7 +141,7 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {

else if (playerRanking - 1 < layoutManager.findFirstCompletelyVisibleItemPosition()){

rankingView.fixedFragment.visibility = View.VISIBLE
rankingView.fixedFragment?.visibility = View.VISIBLE
constraintSet.clone(rankingView.rankingConstraintLayout)
constraintSet.clear(R.id.fixedFragment, ConstraintSet.BOTTOM)
constraintSet.clear(R.id.fixedFragment, ConstraintSet.TOP)
Expand All @@ -144,13 +154,13 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
* Class responsible to control recycler view scrolling
*
* @param playerRanking indicates the position of the logged user
* @param context indicates the context that the recycler view is inserted in
* @param fragment indicates the fragment that the recycler view is inserted in
*/
private class OnScrollRankingRecyclerView(val playerRanking: Int, val context: Context) : RecyclerView.OnScrollListener() {
private class OnScrollRankingRecyclerView(val playerRanking: Int, val fragment: Fragment) : RecyclerView.OnScrollListener() {

override fun onScrolled(recyclerView: RecyclerView?, dx: Int, dy: Int) {

(context as RankingView).setFixedRanking(context, recyclerView, playerRanking)
(fragment as RankingFragment).setFixedRanking(fragment, recyclerView, playerRanking)
}
}

Expand Down Expand Up @@ -186,17 +196,17 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
*/
override fun displayRankingInScreen(viewModel: RankingModel.ViewModel) {

rankingRecyclerView.adapter = RankingAdapter(viewModel.formattedPlayers, this)
rankingRecyclerView?.adapter = RankingAdapter(viewModel.formattedPlayers, this)
}

/**
* Class responsible to expand user information on click
*
* @property playerInformation List of formatted information
* @property context Context that will show this adapter
* @property fragment Fragment that will show this adapter
*/
class RankingAdapter(private val playerInformation: List<RankingModel.FormattedPlayerInfo>,
private val context: Context): RecyclerView.Adapter<RecyclerView.ViewHolder>() {
private val fragment: Fragment): RecyclerView.Adapter<RecyclerView.ViewHolder>() {

private var expandedId = -1

Expand All @@ -209,7 +219,7 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
*/
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {

val inflater = LayoutInflater.from(context)
val inflater = LayoutInflater.from(fragment.activity)
val view: View?

view = inflater.inflate(R.layout.row_ranking, parent, false)
Expand Down Expand Up @@ -254,7 +264,7 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
itemHolder?.lastGame?.text = item.player.userLastGame
itemHolder?.efficiency?.text = item.player.userEfficiency
itemHolder?.profileButton?.setOnClickListener{
(context as RankingView).goToShowProfileView()
(fragment as RankingFragment).goToShowProfileView(item.player.userName)
}

if(expandedId == itemHolder?.layoutPosition) {
Expand All @@ -278,14 +288,14 @@ class RankingView : AppCompatActivity(), RankingDisplayLogic {
*/
inner class ItemHolder(v: View): RecyclerView.ViewHolder(v) {

var nameText = v.name
var rankingText = v.position
var victory = v.victory
var lastGame = v.lastGame
var expandedView = v.expandedView
var efficiency = v.efficiency
var profileButton = v.profileButton
var playerCategory = v.playerCategory
var nameText = v.name!!
var rankingText = v.position!!
var victory = v.victory!!
var lastGame = v.lastGame!!
var expandedView = v.expandedView!!
var efficiency = v.efficiency!!
var profileButton = v.profileButton!!
var playerCategory = v.playerCategory!!
}
}
}
Loading

0 comments on commit 7384c64

Please sign in to comment.