mirror of
https://github.com/nextcloud/android.git
synced 2024-11-24 06:05:42 +03:00
wip
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
This commit is contained in:
parent
c09fa8c944
commit
0bb5ad643f
9 changed files with 120 additions and 23 deletions
|
@ -24,6 +24,8 @@ package com.nextcloud.ui
|
|||
|
||||
import androidx.test.espresso.intent.rule.IntentsTestRule
|
||||
import com.owncloud.android.AbstractIT
|
||||
import com.owncloud.android.lib.resources.users.ClearAt
|
||||
import com.owncloud.android.lib.resources.users.PredefinedStatus
|
||||
import com.owncloud.android.ui.activity.FileDisplayActivity
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
|
@ -39,6 +41,18 @@ class SetStatusDialogFragmentIT : AbstractIT() {
|
|||
|
||||
sut.show(activity.supportFragmentManager, "")
|
||||
|
||||
val predefinedStatus: ArrayList<PredefinedStatus> = arrayListOf(
|
||||
PredefinedStatus("meeting", "📅", "In a meeting", ClearAt("period", "3600")),
|
||||
PredefinedStatus("commuting", "🚌", "Commuting", ClearAt("period", "1800")),
|
||||
PredefinedStatus("remote-work", "🏡", "Working remotely", ClearAt("end-of", "day")),
|
||||
PredefinedStatus("sick-leave", "🤒", "Out sick", ClearAt("end-of", "day")),
|
||||
PredefinedStatus("vacationing", "🌴", "Vacationing", null)
|
||||
)
|
||||
|
||||
shortSleep()
|
||||
|
||||
activity.runOnUiThread { sut.setPredefinedStatus(predefinedStatus) }
|
||||
|
||||
longSleep()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,9 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ImageView
|
||||
import androidx.annotation.VisibleForTesting
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
@ -43,11 +45,12 @@ import com.owncloud.android.lib.resources.users.Status
|
|||
import com.owncloud.android.ui.StatusDrawable
|
||||
import com.owncloud.android.ui.activity.BaseActivity
|
||||
import com.owncloud.android.ui.activity.DrawerActivity
|
||||
import com.owncloud.android.ui.adapter.PredefinedStatusListAdapter
|
||||
import com.owncloud.android.ui.adapter.UserListAdapter
|
||||
import com.owncloud.android.ui.adapter.UserListItem
|
||||
import com.owncloud.android.utils.DisplayUtils
|
||||
import com.owncloud.android.utils.DisplayUtils.AvatarGenerationListener
|
||||
import kotlinx.android.synthetic.main.account_item.*
|
||||
import kotlinx.android.synthetic.main.dialog_set_status.*
|
||||
import java.util.ArrayList
|
||||
import javax.inject.Inject
|
||||
|
||||
|
@ -61,8 +64,10 @@ class SetStatusDialogFragment : DialogFragment(),
|
|||
private var currentUser: User? = null
|
||||
private lateinit var accountManager: UserAccountManager
|
||||
private lateinit var predefinedStatus: ArrayList<PredefinedStatus>
|
||||
|
||||
@Inject
|
||||
lateinit var arbitraryDataProvider: ArbitraryDataProvider
|
||||
private lateinit var adapter: PredefinedStatusListAdapter
|
||||
|
||||
@Inject
|
||||
lateinit var clientFactory: ClientFactory
|
||||
|
@ -74,12 +79,10 @@ class SetStatusDialogFragment : DialogFragment(),
|
|||
|
||||
val json = arbitraryDataProvider.getValue(currentUser, ArbitraryDataProvider.PREDEFINED_STATUS)
|
||||
|
||||
if (!json.isEmpty()) {
|
||||
if (json.isNotEmpty()) {
|
||||
val myType = object : TypeToken<ArrayList<PredefinedStatus>>() {}.type
|
||||
predefinedStatus = Gson().fromJson(json, myType)
|
||||
}
|
||||
|
||||
val size = predefinedStatus.size
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -95,18 +98,12 @@ class SetStatusDialogFragment : DialogFragment(),
|
|||
super.onViewCreated(view, savedInstanceState)
|
||||
accountManager = (activity as BaseActivity).userAccountManager
|
||||
|
||||
adapter = PredefinedStatusListAdapter()
|
||||
if (this::predefinedStatus.isInitialized) {
|
||||
adapter.list = predefinedStatus
|
||||
}
|
||||
|
||||
private fun getAccountListItems(): List<UserListItem>? {
|
||||
val users = accountManager.allUsers
|
||||
val adapterUserList: MutableList<UserListItem> = ArrayList(users.size)
|
||||
// Remove the current account from the adapter to display only other accounts
|
||||
for (user in users) {
|
||||
if (user != currentUser) {
|
||||
adapterUserList.add(UserListItem(user))
|
||||
}
|
||||
}
|
||||
return adapterUserList
|
||||
predefinedStatusList.adapter = adapter
|
||||
predefinedStatusList.layoutManager = LinearLayoutManager(context)
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -160,4 +157,10 @@ class SetStatusDialogFragment : DialogFragment(),
|
|||
|
||||
view?.invalidate()
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
fun setPredefinedStatus(predefinedStatus: ArrayList<PredefinedStatus>) {
|
||||
adapter.list = predefinedStatus
|
||||
predefinedStatusList.adapter?.notifyDataSetChanged()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -266,7 +266,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
|
|||
statusObject.isNull("icon") ? "" : statusObject.getString("icon"),
|
||||
statusObject.isNull("clearAt") ? -1 : statusObject.getLong("clearAt"));
|
||||
} else {
|
||||
status = new Status(StatusType.offline, "", "", -1);
|
||||
status = new Status(StatusType.OFFLINE, "", "", -1);
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
|
|
|
@ -59,17 +59,17 @@ public class StatusDrawable extends Drawable {
|
|||
|
||||
if (TextUtils.isEmpty(status.getIcon())) {
|
||||
switch (status.getStatus()) {
|
||||
case dnd:
|
||||
case DND:
|
||||
icon = R.drawable.ic_user_status_dnd;
|
||||
backgroundPaint.setColor(whiteBackground);
|
||||
this.context = context;
|
||||
break;
|
||||
|
||||
case online:
|
||||
case ONLINE:
|
||||
backgroundPaint.setColor(onlineStatus);
|
||||
break;
|
||||
|
||||
case away:
|
||||
case AWAY:
|
||||
icon = R.drawable.ic_user_status_away;
|
||||
backgroundPaint.setColor(whiteBackground);
|
||||
this.context = context;
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import android.view.LayoutInflater
|
||||
import android.view.ViewGroup
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.owncloud.android.databinding.PredefinedStatusBinding
|
||||
import com.owncloud.android.lib.resources.users.PredefinedStatus
|
||||
|
||||
class PredefinedStatusListAdapter : RecyclerView.Adapter<PredefinedStatusViewHolder>() {
|
||||
internal var list: List<PredefinedStatus> = emptyList()
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PredefinedStatusViewHolder {
|
||||
val itemBinding = PredefinedStatusBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||
return PredefinedStatusViewHolder(itemBinding)
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: PredefinedStatusViewHolder, position: Int) {
|
||||
holder.bind(list[position])
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return list.size
|
||||
}
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
*
|
||||
* Nextcloud Android client application
|
||||
*
|
||||
* @author Tobias Kaminsky
|
||||
* Copyright (C) 2020 Tobias Kaminsky
|
||||
* Copyright (C) 2020 Nextcloud GmbH
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.owncloud.android.ui.adapter
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.owncloud.android.databinding.PredefinedStatusBinding
|
||||
import com.owncloud.android.lib.resources.users.PredefinedStatus
|
||||
|
||||
class PredefinedStatusViewHolder(private val binding: PredefinedStatusBinding) : RecyclerView.ViewHolder(binding.root) {
|
||||
fun bind(status: PredefinedStatus) {
|
||||
binding.name.text = status.message
|
||||
binding.clearAt.text = status.clearAt?.time // TODO better
|
||||
}
|
||||
}
|
|
@ -56,7 +56,7 @@ public class RetrieveStatusAsyncTask extends AsyncTask<Void, Void, Status> {
|
|||
return (com.owncloud.android.lib.resources.users.Status) result.getSingleData();
|
||||
|
||||
} catch (ClientFactory.CreationException e) {
|
||||
return new com.owncloud.android.lib.resources.users.Status(StatusType.offline, "", "", -1);
|
||||
return new com.owncloud.android.lib.resources.users.Status(StatusType.OFFLINE, "", "", -1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -183,11 +183,11 @@
|
|||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/customStatusList"
|
||||
android:id="@+id/predefinedStatusList"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:itemCount="5"
|
||||
tools:listitem="@layout/custom_status">
|
||||
tools:listitem="@layout/predefined_status">
|
||||
|
||||
</androidx.recyclerview.widget.RecyclerView>
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
tools:text="📆" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:id="@+id/name"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center_vertical"
|
Loading…
Reference in a new issue