Fix settings UI

Signed-off-by: Mario Danic <mario@lovelyhq.com>
This commit is contained in:
Mario Danic 2020-04-24 21:41:54 +02:00
parent 7fc78b854d
commit 3a29fda42c
No known key found for this signature in database
GPG Key ID: CDE0BBD2738C4CC0
7 changed files with 40 additions and 11 deletions

View File

@ -56,6 +56,14 @@ class UsersRepositoryImpl(private val usersDao: UsersDao) : UsersRepository {
}
}
override fun getUsersLiveDataWithoutActive(): LiveData<List<User>> {
return usersDao.getUsersLiveDataWithoutActive().distinctUntilChanged().map { usersList ->
usersList.map {
it.toUser()
}
}
}
override suspend fun getUserWithUsernameAndServer(
username: String,
server: String

View File

@ -32,6 +32,7 @@ interface UsersRepository {
fun getUsers(): List<UserNgEntity>
fun getUserWithId(id: Long): UserNgEntity
fun getUsersLiveData(): LiveData<List<User>>
fun getUsersLiveDataWithoutActive(): LiveData<List<User>>
suspend fun getUserWithUsernameAndServer(username: String, server: String): UserNgEntity?
suspend fun updateUser(user: UserNgEntity): Int
suspend fun insertUser(user: UserNgEntity): Long

View File

@ -60,12 +60,7 @@ open class SettingsPresenter<T : Any>(context: Context, onElementClick: ((Page,
holder.itemView.background.alpha = 191
holder.itemView.userMoreOptionsView.visibility = View.INVISIBLE
} else {
if (user.status == UserStatus.ACTIVE) {
holder.itemView.setBackgroundColor(context.resources.getColor(R.color.colorPrimary))
holder.itemView.background.alpha = 191
} else {
holder.itemView.setBackgroundColor(0)
}
holder.itemView.setBackgroundColor(0)
holder.itemView.userMoreOptionsView.visibility = View.VISIBLE
holder.itemView.userMoreOptionsView.setOnClickListener {
onMoreOptionsClick?.invoke(user)

View File

@ -96,6 +96,12 @@ class SettingsView(private val bundle: Bundle? = null) : BaseView() {
)
}
view.activeUserMoreOptions.setOnClickListener {
viewModel.activeUser.value?.let {
onMoreOptionsClick(it.toUser())
}
}
showFallbackAvatar(view.avatar_image)
viewModel.activeUser.observe(this@SettingsView) { user ->

View File

@ -40,7 +40,7 @@ class SettingsViewModel constructor(
private val apiErrorHandler: ApiErrorHandler,
private val globalService: GlobalService
) : BaseViewModel<SettingsView>(application) {
val users = usersRepository.getUsersLiveData()
val users = usersRepository.getUsersLiveDataWithoutActive()
val activeUser = globalService.currentUserLiveData
private suspend fun setUserAsActiveWithId(id: Long): Boolean {

View File

@ -39,6 +39,9 @@ abstract class UsersDao {
@Query("SELECT * from users ORDER BY status DESC")
abstract fun getUsersLiveData(): LiveData<List<UserNgEntity>>
@Query("SELECT * from users WHERE status != 2 ORDER BY status DESC")
abstract fun getUsersLiveDataWithoutActive(): LiveData<List<UserNgEntity>>
@Query("DELETE FROM users WHERE id = :id")
abstract suspend fun deleteUserWithId(id: Long)

View File

@ -45,25 +45,41 @@
<androidx.emoji.widget.EmojiTextView
android:id="@+id/display_name_text"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/avatar_image"
android:layout_centerHorizontal="true"
android:paddingStart="32dp"
android:textAlignment="center"
android:layout_alignBaseline="@id/avatar_image"
android:layout_marginTop="@dimen/margin_between_elements"
android:layout_marginStart="8dp"
tools:text="Important user"
android:layout_toStartOf="@id/activeUserMoreOptions"
android:textColor="@color/nc_incoming_text_default" />
<TextView
android:id="@+id/base_url_text"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/display_name_text"
android:paddingStart="32dp"
android:layout_marginStart="8dp"
android:layout_centerHorizontal="true"
android:layout_margin="4dp"
android:textAlignment="center"
android:layout_toStartOf="@id/activeUserMoreOptions"
tools:text="nextcloud.com"
android:textColor="@color/nc_incoming_text_default"
android:layout_marginBottom="8dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/display_name_text"
android:layout_alignBottom="@id/base_url_text"
android:src="@drawable/ic_baseline_more_vert_24"
android:id="@+id/activeUserMoreOptions"
android:layout_alignParentEnd="true"
android:layout_marginHorizontal="8dp"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"