Skip to content

Commit

Permalink
fix team list overflow
Browse files Browse the repository at this point in the history
  • Loading branch information
strawberrybread committed Jul 2, 2024
1 parent 2d1d244 commit a032c3f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 62 deletions.
20 changes: 6 additions & 14 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
selectedTeamId = prefData.getSELECTEDTEAMID().toString()
if (selectedTeamId?.isNotEmpty() == true) {
users = RealmMyTeam.getUsers(selectedTeamId, mRealm, "")
val userList = (users as MutableList<RealmUserModel>?)?.map {
val userList = (users as? MutableList<RealmUserModel>)?.map {
User(it.getFullName(), it.name ?: "", "", it.userImage ?: "", "team")
} ?: emptyList()

Expand All @@ -268,22 +268,14 @@ class LoginActivity : SyncActivity(), TeamListAdapter.OnItemClickListener {
prefData.setSAVEDUSERS(updatedUserList)
}

mAdapter = if (mAdapter == null) {
TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this)
if (mAdapter == null) {
mAdapter = TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this)
activityLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this)
activityLoginBinding.recyclerView.adapter = mAdapter
} else {
mAdapter?.clearList()
TeamListAdapter(prefData.getSAVEDUSERS().toMutableList(), this, this)
mAdapter?.updateList(prefData.getSAVEDUSERS().toMutableList())
}

activityLoginBinding.recyclerView.layoutManager = LinearLayoutManager(this)
activityLoginBinding.recyclerView.adapter = mAdapter

val layoutManager: RecyclerView.LayoutManager = object : LinearLayoutManager(this) {
override fun generateDefaultLayoutParams(): RecyclerView.LayoutParams {
return RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
}
activityLoginBinding.recyclerView.layoutManager = layoutManager
activityLoginBinding.recyclerView.isNestedScrollingEnabled = true
activityLoginBinding.recyclerView.setHasFixedSize(true)
}
Expand Down
78 changes: 37 additions & 41 deletions app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -505,55 +505,51 @@ abstract class SyncActivity : ProcessUserDataActivity(), SyncListener, CheckVers
dialogServerUrlBinding.clearData.setOnClickListener {
clearDataDialog(getString(R.string.are_you_sure_you_want_to_clear_data))
}
if (prefData.getMANUALCONFIG()) {
val teams: List<RealmMyTeam> = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").equalTo("status", "active").findAll()
if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" != "") {
dialogServerUrlBinding.team.visibility = View.VISIBLE
teamAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, teamList)
teamAdapter?.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
teamList.clear()
teamList.add("select team")
for (team in teams) {
if (team.isValid) {
teamList.add(team.name)
}
val teams: List<RealmMyTeam> = mRealm.where(RealmMyTeam::class.java).isEmpty("teamId").equalTo("status", "active").findAll()
if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" != "") {
dialogServerUrlBinding.team.visibility = View.VISIBLE
teamAdapter = ArrayAdapter(this, android.R.layout.simple_spinner_item, teamList)
teamAdapter?.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
teamList.clear()
teamList.add("select team")
for (team in teams) {
if (team.isValid) {
teamList.add(team.name)
}
dialogServerUrlBinding.team.adapter = teamAdapter
val lastSelection = prefData.getSELECTEDTEAMID()
if (!lastSelection.isNullOrEmpty()) {
for (i in teams.indices) {
val team = teams[i]
if (team._id != null && team._id == lastSelection && team.isValid) {
val lastSelectedPosition = i + 1
dialogServerUrlBinding.team.setSelection(lastSelectedPosition)
break
}
}
dialogServerUrlBinding.team.adapter = teamAdapter
val lastSelection = prefData.getSELECTEDTEAMID()
if (!lastSelection.isNullOrEmpty()) {
for (i in teams.indices) {
val team = teams[i]
if (team._id != null && team._id == lastSelection && team.isValid) {
val lastSelectedPosition = i + 1
dialogServerUrlBinding.team.setSelection(lastSelectedPosition)
break
}
}
dialogServerUrlBinding.team.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
val currentTeamId = prefData.getSELECTEDTEAMID()
if (currentTeamId != selectedTeam._id) {
prefData.setSELECTEDTEAMID(selectedTeam._id)
if (this@SyncActivity is LoginActivity) {
this@SyncActivity.getTeamMembers()
}
dialog.dismiss()
}
dialogServerUrlBinding.team.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parentView: AdapterView<*>?, selectedItemView: View, position: Int, id: Long) {
if (position > 0) {
val selectedTeam = teams[position - 1]
val currentTeamId = prefData.getSELECTEDTEAMID()
if (currentTeamId != selectedTeam._id) {
prefData.setSELECTEDTEAMID(selectedTeam._id)
if (this@SyncActivity is LoginActivity) {
this@SyncActivity.getTeamMembers()
}
dialog.dismiss()
}
}

override fun onNothingSelected(parentView: AdapterView<*>?) {
// Do nothing when nothing is selected
}
}
} else if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" == "") {
dialogServerUrlBinding.team.visibility = View.GONE
} else {
dialogServerUrlBinding.team.visibility = View.GONE

override fun onNothingSelected(parentView: AdapterView<*>?) { }
}
} else if (teams.isNotEmpty() && "${dialogServerUrlBinding.inputServerUrl.text}" == "") {
dialogServerUrlBinding.team.visibility = View.GONE
} else {
dialogServerUrlBinding.team.visibility = View.GONE
}
dialog.show()
sync(dialog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.databinding.UserListItemBinding
import org.ole.planet.myplanet.model.User

class TeamListAdapter(private val membersList: MutableList<User>, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter<TeamListAdapter.ViewHolder>() {
class TeamListAdapter(private var membersList: MutableList<User>, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter<TeamListAdapter.ViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val binding = UserListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false)
return ViewHolder(binding)
Expand Down Expand Up @@ -38,6 +38,11 @@ class TeamListAdapter(private val membersList: MutableList<User>, val context: C
notifyDataSetChanged()
}

fun updateList(newUserList: MutableList<User>) {
membersList = newUserList
notifyDataSetChanged()
}

class ViewHolder(private val binding: UserListItemBinding) : RecyclerView.ViewHolder(binding.root) {
fun bindView(account: User) {
if (account.fullName?.isEmpty() == true || account.fullName == " ") {
Expand Down
9 changes: 3 additions & 6 deletions app/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,10 +319,9 @@

<LinearLayout
android:id="@+id/ltAvailablaSpace"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintBottom_toTopOf="@+id/recyclerView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/customDeviceName">
Expand Down Expand Up @@ -351,11 +350,9 @@
android:layout_marginTop="@dimen/_10dp"
android:layout_marginEnd="3dp"
android:layout_marginBottom="5dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ltAvailablaSpace"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/ltAvailablaSpace" />

app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</LinearLayout>
Expand Down

0 comments on commit a032c3f

Please sign in to comment.