Hide dot indicator in fullscreen album
This commit is contained in:
parent
908d1a54c9
commit
54711d4e81
|
@ -2,7 +2,6 @@ package org.pixeldroid.app.posts
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.MenuItem
|
||||
import android.view.MotionEvent
|
||||
import android.view.View
|
||||
import androidx.activity.viewModels
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
|
@ -12,6 +11,7 @@ import androidx.core.view.WindowInsetsControllerCompat
|
|||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.lifecycle.repeatOnLifecycle
|
||||
import androidx.viewpager2.widget.ViewPager2
|
||||
import kotlinx.coroutines.launch
|
||||
import org.pixeldroid.app.databinding.ActivityAlbumBinding
|
||||
|
||||
|
@ -25,29 +25,43 @@ class AlbumActivity : AppCompatActivity() {
|
|||
val binding = ActivityAlbumBinding.inflate(layoutInflater)
|
||||
setContentView(binding.root)
|
||||
|
||||
binding.albumPager.adapter = AlbumViewPagerAdapter(model.uiState.value.mediaAttachments,
|
||||
binding.albumPager.adapter = AlbumViewPagerAdapter(
|
||||
model.uiState.value.mediaAttachments,
|
||||
sensitive = false,
|
||||
opened = true,
|
||||
//In the activity, we assume we want to show everything
|
||||
alwaysShowNsfw = true,
|
||||
clickCallback = ::clickCallback
|
||||
)
|
||||
binding.albumPager.currentItem = model.uiState.value.index
|
||||
|
||||
binding.albumPager.registerOnPageChangeCallback(object : ViewPager2.OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) { model.positionSelected(position) }
|
||||
})
|
||||
|
||||
if (model.uiState.value.mediaAttachments.size == 1) {
|
||||
binding.albumPager.isUserInputEnabled = false
|
||||
}
|
||||
else if ((model.uiState.value.mediaAttachments.size) > 1) {
|
||||
} else if ((model.uiState.value.mediaAttachments.size) > 1) {
|
||||
binding.postIndicator.setViewPager(binding.albumPager)
|
||||
binding.postIndicator.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.postIndicator.visibility = View.GONE
|
||||
}
|
||||
|
||||
// Not really necessary because the ViewPager saves its state in onSaveInstanceState, but
|
||||
// it's good to stay consistent in case something gets out of sync
|
||||
binding.albumPager.setCurrentItem(model.uiState.value.index, false)
|
||||
|
||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||
supportActionBar?.setDisplayShowTitleEnabled(false)
|
||||
supportActionBar?.setBackgroundDrawable(null)
|
||||
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
model.uiState.collect { uiState ->
|
||||
binding.albumPager.currentItem = uiState.index
|
||||
}
|
||||
}
|
||||
}
|
||||
lifecycleScope.launch {
|
||||
repeatOnLifecycle(Lifecycle.State.STARTED) {
|
||||
model.isActionBarHidden.collect { isActionBarHidden ->
|
||||
|
@ -60,6 +74,7 @@ class AlbumActivity : AppCompatActivity() {
|
|||
// Hide both the status bar and the navigation bar
|
||||
supportActionBar?.hide()
|
||||
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
|
||||
binding.postIndicator.visibility = View.GONE
|
||||
} else {
|
||||
// Configure the behavior of the hidden system bars
|
||||
windowInsetsController.systemBarsBehavior =
|
||||
|
@ -67,6 +82,9 @@ class AlbumActivity : AppCompatActivity() {
|
|||
// Show both the status bar and the navigation bar
|
||||
supportActionBar?.show()
|
||||
windowInsetsController.show(WindowInsetsCompat.Type.systemBars())
|
||||
if ((model.uiState.value.mediaAttachments.size) > 1) {
|
||||
binding.postIndicator.visibility = View.VISIBLE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@ data class AlbumUiState(
|
|||
|
||||
@HiltViewModel
|
||||
class AlbumViewModel @Inject constructor(state: SavedStateHandle) : ViewModel() {
|
||||
fun barHide() {
|
||||
_isActionBarHidden.update { !it }
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ALBUM_IMAGES = "AlbumViewImages"
|
||||
const val ALBUM_INDEX = "AlbumViewIndex"
|
||||
|
@ -39,4 +35,12 @@ class AlbumViewModel @Inject constructor(state: SavedStateHandle) : ViewModel()
|
|||
|
||||
val uiState: StateFlow<AlbumUiState> = _uiState.asStateFlow()
|
||||
val isActionBarHidden: StateFlow<Boolean> = _isActionBarHidden
|
||||
|
||||
fun barHide() {
|
||||
_isActionBarHidden.update { !it }
|
||||
}
|
||||
|
||||
fun positionSelected(position: Int) {
|
||||
_uiState.update { it.copy(index = position) }
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue