diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt index 98dcb68d58..8a979e97ad 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/LoginActivity.kt @@ -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?)?.map { + val userList = (users as? MutableList)?.map { User(it.getFullName(), it.name ?: "", "", it.userImage ?: "", "team") } ?: emptyList() @@ -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) } diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt index 6b203b7bee..da262b740a 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/sync/SyncActivity.kt @@ -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 = 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 = 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) diff --git a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt index 400ff3d400..40cec475aa 100644 --- a/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt +++ b/app/src/main/java/org/ole/planet/myplanet/ui/userprofile/TeamListAdapter.kt @@ -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, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter() { +class TeamListAdapter(private var membersList: MutableList, val context: Context, private val onItemClickListener: OnItemClickListener) : RecyclerView.Adapter() { override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { val binding = UserListItemBinding.inflate(LayoutInflater.from(parent.context), parent, false) return ViewHolder(binding) @@ -38,6 +38,11 @@ class TeamListAdapter(private val membersList: MutableList, val context: C notifyDataSetChanged() } + fun updateList(newUserList: MutableList) { + membersList = newUserList + notifyDataSetChanged() + } + class ViewHolder(private val binding: UserListItemBinding) : RecyclerView.ViewHolder(binding.root) { fun bindView(account: User) { if (account.fullName?.isEmpty() == true || account.fullName == " ") { diff --git a/app/src/main/res/layout/activity_login.xml b/app/src/main/res/layout/activity_login.xml index 51851d2fce..38aeb0a864 100644 --- a/app/src/main/res/layout/activity_login.xml +++ b/app/src/main/res/layout/activity_login.xml @@ -319,10 +319,9 @@ @@ -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" />