add tabLayout for file types (WIP)

quick&dirty, needs to be improved and might contain bugs

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2022-04-27 19:40:55 +02:00
parent 3a1f3242d8
commit cad7b4cb3d
No known key found for this signature in database
GPG key ID: C793F8B59F43CE7B
5 changed files with 74 additions and 6 deletions

View file

@ -5,8 +5,10 @@ import android.util.Log
import android.view.MenuItem import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.ViewModelProvider
import com.google.android.material.tabs.TabLayout
import com.nextcloud.talk.adapters.SharedItemsAdapter import com.nextcloud.talk.adapters.SharedItemsAdapter
import com.nextcloud.talk.databinding.ActivitySharedItemsBinding import com.nextcloud.talk.databinding.ActivitySharedItemsBinding
import com.nextcloud.talk.databinding.ItemReactionsTabBinding
import com.nextcloud.talk.models.database.UserEntity import com.nextcloud.talk.models.database.UserEntity
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_CONVERSATION_NAME
import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN import com.nextcloud.talk.utils.bundle.BundleKeys.KEY_ROOM_TOKEN
@ -32,20 +34,71 @@ class SharedItemsActivity : AppCompatActivity() {
supportActionBar?.title = conversationName supportActionBar?.title = conversationName
supportActionBar?.setDisplayHomeAsUpEnabled(true) supportActionBar?.setDisplayHomeAsUpEnabled(true)
initTabs()
viewModel = ViewModelProvider( viewModel = ViewModelProvider(
this, this,
SharedItemsViewModel.Factory(userEntity, roomToken) SharedItemsViewModel.Factory(userEntity, roomToken)
).get(SharedItemsViewModel::class.java) ).get(SharedItemsViewModel::class.java)
updateItems("media")
viewModel.media.observe(this) { viewModel.media.observe(this) {
Log.d(TAG, "Items received: $it") Log.d(TAG, "Items received: $it")
val adapter = SharedItemsAdapter() val adapter = SharedItemsAdapter()
adapter.items = it.items adapter.items = it.items
adapter.authHeader = it.authHeader adapter.authHeader = it.authHeader
binding.imageRecycler.adapter = adapter binding.imageRecycler.adapter = adapter
adapter.notifyDataSetChanged()
} }
} }
fun updateItems(type: String){
viewModel.loadMediaItems(type)
}
private fun initTabs() {
val tabAudio: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabAudio.text = "audio"
binding.sharedItemsTabs.addTab(tabAudio)
val tabDeckcard: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabDeckcard.text = "deckcard"
binding.sharedItemsTabs.addTab(tabDeckcard)
val tabFile: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabFile.text = "files"
binding.sharedItemsTabs.addTab(tabFile)
val tabLocation: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabLocation.text = "locations"
binding.sharedItemsTabs.addTab(tabLocation)
val tabMedia: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabMedia.text = "media"
binding.sharedItemsTabs.addTab(tabMedia)
val tabVoice: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabVoice.text = "voice"
binding.sharedItemsTabs.addTab(tabVoice)
val tabOther: TabLayout.Tab = binding.sharedItemsTabs.newTab()
tabOther.text = "other"
binding.sharedItemsTabs.addTab(tabOther)
binding.sharedItemsTabs.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
updateItems(tab.text.toString())
}
override fun onTabUnselected(tab: TabLayout.Tab) {
}
override fun onTabReselected(tab: TabLayout.Tab) {
}
})
}
override fun onOptionsItemSelected(item: MenuItem): Boolean { override fun onOptionsItemSelected(item: MenuItem): Boolean {
return if (item.itemId == android.R.id.home) { return if (item.itemId == android.R.id.home) {
onBackPressed() onBackPressed()

View file

@ -49,6 +49,9 @@ class SharedItemsAdapter : RecyclerView.Adapter<SharedItemsAdapter.ViewHolder>()
.setImageRequest(imageRequest) .setImageRequest(imageRequest)
.build() .build()
holder.binding.image.controller = draweeController holder.binding.image.controller = draweeController
// } else if () { TODO check if voice message etc..
} else { } else {
when (currentItem.mimeType) { when (currentItem.mimeType) {
"video/mp4", "video/mp4",

View file

@ -27,13 +27,13 @@ class SharedItemsRepository {
sharedApplication!!.componentApplication.inject(this) sharedApplication!!.componentApplication.inject(this)
} }
fun media(): Observable<Response<ChatShareOverall>>? { fun media(type: String): Observable<Response<ChatShareOverall>>? {
val credentials = ApiUtils.getCredentials(parameters!!.userName, parameters!!.userToken) val credentials = ApiUtils.getCredentials(parameters!!.userName, parameters!!.userToken)
return ncApi.getSharedItems( return ncApi.getSharedItems(
credentials, credentials,
ApiUtils.getUrlForChatSharedItems(1, parameters!!.baseUrl, parameters!!.roomToken), ApiUtils.getUrlForChatSharedItems(1, parameters!!.baseUrl, parameters!!.roomToken),
"media", null, null type, null, null
) )
} }

View file

@ -20,16 +20,16 @@ class SharedItemsViewModel(private val repository: SharedItemsRepository) : View
private val _media: MutableLiveData<SharedMediaItems> by lazy { private val _media: MutableLiveData<SharedMediaItems> by lazy {
MutableLiveData<SharedMediaItems>().also { MutableLiveData<SharedMediaItems>().also {
loadMediaItems() loadMediaItems("media")
} }
} }
val media: LiveData<SharedMediaItems> val media: LiveData<SharedMediaItems>
get() = _media get() = _media
private fun loadMediaItems() { fun loadMediaItems(type: String) {
repository.media()?.subscribeOn(Schedulers.io()) repository.media(type)?.subscribeOn(Schedulers.io())
?.observeOn(AndroidSchedulers.mainThread()) ?.observeOn(AndroidSchedulers.mainThread())
?.subscribe(object : Observer<Response<ChatShareOverall>> { ?.subscribe(object : Observer<Response<ChatShareOverall>> {

View file

@ -31,10 +31,22 @@
android:layout_height="?attr/actionBarSize" android:layout_height="?attr/actionBarSize"
app:layout_constraintTop_toTopOf="parent" /> app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/shared_items_tabs"
android:layout_width="wrap_content"
android:layout_height="@dimen/min_size_clickable_area"
android:layout_marginBottom="8dp"
app:layout_constraintTop_toBottomOf="@id/shared_items_toolbar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:tabGravity="fill"
app:tabMode="scrollable" />
<androidx.core.widget.NestedScrollView <androidx.core.widget.NestedScrollView
android:id="@+id/nestedScrollView"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@+id/shared_items_toolbar"> app:layout_constraintTop_toBottomOf="@+id/shared_items_tabs">
<androidx.recyclerview.widget.RecyclerView <androidx.recyclerview.widget.RecyclerView
android:id="@+id/image_recycler" android:id="@+id/image_recycler"