mirror of
https://gitlab.linphone.org/BC/public/linphone-android.git
synced 2026-01-30 02:09:20 +00:00
Replaced dots by current page / page count in PDF viewer
This commit is contained in:
parent
54b9ae8cd4
commit
aa34132047
4 changed files with 43 additions and 22 deletions
|
|
@ -14,6 +14,7 @@ import androidx.lifecycle.ViewModelProvider
|
|||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.navigation.fragment.findNavController
|
||||
import androidx.navigation.fragment.navArgs
|
||||
import androidx.viewpager2.widget.ViewPager2.OnPageChangeCallback
|
||||
import kotlinx.coroutines.launch
|
||||
import org.linphone.core.tools.Log
|
||||
import org.linphone.databinding.FileViewerFragmentBinding
|
||||
|
|
@ -39,6 +40,12 @@ class FileViewerFragment : GenericFragment() {
|
|||
|
||||
private val args: FileViewerFragmentArgs by navArgs()
|
||||
|
||||
private val pageChangedListener = object : OnPageChangeCallback() {
|
||||
override fun onPageSelected(position: Int) {
|
||||
viewModel.pdfCurrentPage.value = (position + 1).toString()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
|
|
@ -93,7 +100,6 @@ class FileViewerFragment : GenericFragment() {
|
|||
|
||||
adapter = PdfPagesListAdapter(viewModel)
|
||||
binding.pdfViewPager.adapter = adapter
|
||||
binding.dotsIndicator.attachTo(binding.pdfViewPager)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -152,9 +158,12 @@ class FileViewerFragment : GenericFragment() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
updateScreenSize()
|
||||
binding.pdfViewPager.registerOnPageChangeCallback(pageChangedListener)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
binding.pdfViewPager.unregisterOnPageChangeCallback(pageChangedListener)
|
||||
|
||||
if (binding.videoPlayer.isPlaying) {
|
||||
binding.videoPlayer.pause()
|
||||
viewModel.isVideoPlaying.value = false
|
||||
|
|
|
|||
|
|
@ -40,6 +40,10 @@ class FileViewModel @UiThread constructor() : ViewModel() {
|
|||
|
||||
val isPdf = MutableLiveData<Boolean>()
|
||||
|
||||
val pdfCurrentPage = MutableLiveData<String>()
|
||||
|
||||
val pdfPages = MutableLiveData<String>()
|
||||
|
||||
val isVideo = MutableLiveData<Boolean>()
|
||||
|
||||
val isVideoPlaying = MutableLiveData<Boolean>()
|
||||
|
|
@ -107,7 +111,10 @@ class FileViewModel @UiThread constructor() : ViewModel() {
|
|||
ParcelFileDescriptor.MODE_READ_ONLY
|
||||
)
|
||||
pdfRenderer = PdfRenderer(input)
|
||||
Log.i("$TAG ${pdfRenderer.pageCount} pages in file $file")
|
||||
val count = pdfRenderer.pageCount
|
||||
Log.i("$TAG $count pages in file $file")
|
||||
pdfPages.postValue(count.toString())
|
||||
pdfCurrentPage.postValue("1")
|
||||
pdfRendererReadyEvent.postValue(Event(true))
|
||||
}
|
||||
}
|
||||
|
|
@ -119,6 +126,7 @@ class FileViewModel @UiThread constructor() : ViewModel() {
|
|||
}
|
||||
else -> {
|
||||
path.value = file
|
||||
// TODO FIXME : handle audio & plain text files, open native app for unsupported files
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,19 +53,22 @@
|
|||
android:orientation="horizontal"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}" />
|
||||
|
||||
<com.tbuonomo.viewpagerdotsindicator.DotsIndicator
|
||||
android:id="@+id/dots_indicator"
|
||||
|
||||
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/pages_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:dotsColor="?attr/color_main2_200"
|
||||
app:dotsCornerRadius="8dp"
|
||||
app:dotsSize="13dp"
|
||||
app:dotsSpacing="5dp"
|
||||
app:dotsWidthFactor="2.5"
|
||||
app:selectedDotColor="?attr/color_main1_500"
|
||||
app:progressMode="false"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE}"
|
||||
android:text="@{viewModel.pdfCurrentPage + ` / ` + viewModel.pdfPages, default=`1 / 30`}"
|
||||
android:textColor="@color/white"
|
||||
android:background="#80000000"
|
||||
app:layout_constraintBottom_toTopOf="@id/file_name"
|
||||
app:layout_constraintStart_toStartOf="@id/pdf_view_pager"
|
||||
app:layout_constraintEnd_toEndOf="@id/pdf_view_pager" />
|
||||
|
|
|
|||
|
|
@ -53,19 +53,20 @@
|
|||
android:orientation="horizontal"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}" />
|
||||
|
||||
<com.tbuonomo.viewpagerdotsindicator.DotsIndicator
|
||||
android:id="@+id/dots_indicator"
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
style="@style/default_text_style"
|
||||
android:id="@+id/pages_indicator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE, default=gone}"
|
||||
app:dotsColor="?attr/color_main2_200"
|
||||
app:dotsCornerRadius="8dp"
|
||||
app:dotsSize="13dp"
|
||||
app:dotsSpacing="5dp"
|
||||
app:dotsWidthFactor="2.5"
|
||||
app:selectedDotColor="?attr/color_main1_500"
|
||||
app:progressMode="false"
|
||||
android:paddingStart="5dp"
|
||||
android:paddingEnd="5dp"
|
||||
android:paddingTop="2dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:visibility="@{viewModel.isPdf ? View.VISIBLE : View.GONE}"
|
||||
android:text="@{viewModel.pdfCurrentPage + ` / ` + viewModel.pdfPages, default=`1 / 30`}"
|
||||
android:textColor="@color/white"
|
||||
android:background="#80000000"
|
||||
app:layout_constraintBottom_toTopOf="@id/file_name"
|
||||
app:layout_constraintStart_toStartOf="@id/pdf_view_pager"
|
||||
app:layout_constraintEnd_toEndOf="@id/pdf_view_pager" />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue