mirror of
https://github.com/nextcloud/talk-android.git
synced 2024-11-27 17:08:34 +03:00
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:
parent
3a1f3242d8
commit
cad7b4cb3d
5 changed files with 74 additions and 6 deletions
|
@ -5,8 +5,10 @@ import android.util.Log
|
|||
import android.view.MenuItem
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import com.google.android.material.tabs.TabLayout
|
||||
import com.nextcloud.talk.adapters.SharedItemsAdapter
|
||||
import com.nextcloud.talk.databinding.ActivitySharedItemsBinding
|
||||
import com.nextcloud.talk.databinding.ItemReactionsTabBinding
|
||||
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_ROOM_TOKEN
|
||||
|
@ -32,20 +34,71 @@ class SharedItemsActivity : AppCompatActivity() {
|
|||
supportActionBar?.title = conversationName
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
|
||||
initTabs()
|
||||
|
||||
viewModel = ViewModelProvider(
|
||||
this,
|
||||
SharedItemsViewModel.Factory(userEntity, roomToken)
|
||||
).get(SharedItemsViewModel::class.java)
|
||||
|
||||
updateItems("media")
|
||||
|
||||
viewModel.media.observe(this) {
|
||||
Log.d(TAG, "Items received: $it")
|
||||
val adapter = SharedItemsAdapter()
|
||||
adapter.items = it.items
|
||||
adapter.authHeader = it.authHeader
|
||||
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 {
|
||||
return if (item.itemId == android.R.id.home) {
|
||||
onBackPressed()
|
||||
|
|
|
@ -49,6 +49,9 @@ class SharedItemsAdapter : RecyclerView.Adapter<SharedItemsAdapter.ViewHolder>()
|
|||
.setImageRequest(imageRequest)
|
||||
.build()
|
||||
holder.binding.image.controller = draweeController
|
||||
|
||||
// } else if () { TODO check if voice message etc..
|
||||
|
||||
} else {
|
||||
when (currentItem.mimeType) {
|
||||
"video/mp4",
|
||||
|
|
|
@ -27,13 +27,13 @@ class SharedItemsRepository {
|
|||
sharedApplication!!.componentApplication.inject(this)
|
||||
}
|
||||
|
||||
fun media(): Observable<Response<ChatShareOverall>>? {
|
||||
fun media(type: String): Observable<Response<ChatShareOverall>>? {
|
||||
val credentials = ApiUtils.getCredentials(parameters!!.userName, parameters!!.userToken)
|
||||
|
||||
return ncApi.getSharedItems(
|
||||
credentials,
|
||||
ApiUtils.getUrlForChatSharedItems(1, parameters!!.baseUrl, parameters!!.roomToken),
|
||||
"media", null, null
|
||||
type, null, null
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -20,16 +20,16 @@ class SharedItemsViewModel(private val repository: SharedItemsRepository) : View
|
|||
|
||||
private val _media: MutableLiveData<SharedMediaItems> by lazy {
|
||||
MutableLiveData<SharedMediaItems>().also {
|
||||
loadMediaItems()
|
||||
loadMediaItems("media")
|
||||
}
|
||||
}
|
||||
|
||||
val media: LiveData<SharedMediaItems>
|
||||
get() = _media
|
||||
|
||||
private fun loadMediaItems() {
|
||||
fun loadMediaItems(type: String) {
|
||||
|
||||
repository.media()?.subscribeOn(Schedulers.io())
|
||||
repository.media(type)?.subscribeOn(Schedulers.io())
|
||||
?.observeOn(AndroidSchedulers.mainThread())
|
||||
?.subscribe(object : Observer<Response<ChatShareOverall>> {
|
||||
|
||||
|
|
|
@ -31,10 +31,22 @@
|
|||
android:layout_height="?attr/actionBarSize"
|
||||
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
|
||||
android:id="@+id/nestedScrollView"
|
||||
android:layout_width="match_parent"
|
||||
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
|
||||
android:id="@+id/image_recycler"
|
||||
|
|
Loading…
Reference in a new issue