Fixed crash with file viewer since using onViewCreated instead of onActivityCreated
This commit is contained in:
parent
e2a39b868e
commit
42bb6b8635
6 changed files with 57 additions and 65 deletions
|
@ -29,13 +29,10 @@ import androidx.navigation.fragment.findNavController
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.files.viewmodels.AudioFileViewModel
|
import org.linphone.activities.main.files.viewmodels.AudioFileViewModel
|
||||||
import org.linphone.activities.main.files.viewmodels.AudioFileViewModelFactory
|
import org.linphone.activities.main.files.viewmodels.AudioFileViewModelFactory
|
||||||
import org.linphone.activities.main.fragments.SecureFragment
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
|
||||||
import org.linphone.databinding.FileAudioViewerFragmentBinding
|
import org.linphone.databinding.FileAudioViewerFragmentBinding
|
||||||
|
|
||||||
class AudioViewerFragment : SecureFragment<FileAudioViewerFragmentBinding>() {
|
class AudioViewerFragment : GenericViewerFragment<FileAudioViewerFragmentBinding>() {
|
||||||
private lateinit var viewModel: AudioFileViewModel
|
private lateinit var viewModel: AudioFileViewModel
|
||||||
private lateinit var sharedViewModel: SharedMainViewModel
|
|
||||||
|
|
||||||
private lateinit var mediaController: MediaController
|
private lateinit var mediaController: MediaController
|
||||||
|
|
||||||
|
@ -47,24 +44,15 @@ class AudioViewerFragment : SecureFragment<FileAudioViewerFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
sharedViewModel = requireActivity().run {
|
|
||||||
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val content = sharedViewModel.contentToOpen.value
|
val content = sharedViewModel.contentToOpen.value
|
||||||
content ?: return
|
content ?: return
|
||||||
|
|
||||||
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
|
||||||
?.setContent(content)
|
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
AudioFileViewModelFactory(content)
|
AudioFileViewModelFactory(content)
|
||||||
)[AudioFileViewModel::class.java]
|
)[AudioFileViewModel::class.java]
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
isSecure = arguments?.getBoolean("Secure") ?: false
|
|
||||||
|
|
||||||
mediaController = object : MediaController(requireContext()) {
|
mediaController = object : MediaController(requireContext()) {
|
||||||
// This hack is even if media controller is showed with timeout=0
|
// This hack is even if media controller is showed with timeout=0
|
||||||
// Once a control is touched, it will disappear 3 seconds later anyway
|
// Once a control is touched, it will disappear 3 seconds later anyway
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2010-2021 Belledonne Communications SARL.
|
||||||
|
*
|
||||||
|
* This file is part of linphone-android
|
||||||
|
* (see https://www.linphone.org).
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU 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 General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
package org.linphone.activities.main.files.fragments
|
||||||
|
|
||||||
|
import android.os.Bundle
|
||||||
|
import android.view.View
|
||||||
|
import androidx.databinding.ViewDataBinding
|
||||||
|
import androidx.lifecycle.ViewModelProvider
|
||||||
|
import org.linphone.R
|
||||||
|
import org.linphone.activities.main.fragments.SecureFragment
|
||||||
|
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
||||||
|
|
||||||
|
abstract class GenericViewerFragment<T : ViewDataBinding> : SecureFragment<T>() {
|
||||||
|
protected lateinit var sharedViewModel: SharedMainViewModel
|
||||||
|
|
||||||
|
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||||
|
super.onViewCreated(view, savedInstanceState)
|
||||||
|
|
||||||
|
sharedViewModel = requireActivity().run {
|
||||||
|
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
||||||
|
}
|
||||||
|
|
||||||
|
isSecure = arguments?.getBoolean("Secure") ?: false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onStart() {
|
||||||
|
super.onStart()
|
||||||
|
|
||||||
|
val content = sharedViewModel.contentToOpen.value
|
||||||
|
content ?: return
|
||||||
|
|
||||||
|
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
||||||
|
?.setContent(content)
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,13 +26,10 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.files.viewmodels.ImageFileViewModel
|
import org.linphone.activities.main.files.viewmodels.ImageFileViewModel
|
||||||
import org.linphone.activities.main.files.viewmodels.ImageFileViewModelFactory
|
import org.linphone.activities.main.files.viewmodels.ImageFileViewModelFactory
|
||||||
import org.linphone.activities.main.fragments.SecureFragment
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
|
||||||
import org.linphone.databinding.FileImageViewerFragmentBinding
|
import org.linphone.databinding.FileImageViewerFragmentBinding
|
||||||
|
|
||||||
class ImageViewerFragment : SecureFragment<FileImageViewerFragmentBinding>() {
|
class ImageViewerFragment : GenericViewerFragment<FileImageViewerFragmentBinding>() {
|
||||||
private lateinit var viewModel: ImageFileViewModel
|
private lateinit var viewModel: ImageFileViewModel
|
||||||
private lateinit var sharedViewModel: SharedMainViewModel
|
|
||||||
|
|
||||||
override fun getLayoutId(): Int = R.layout.file_image_viewer_fragment
|
override fun getLayoutId(): Int = R.layout.file_image_viewer_fragment
|
||||||
|
|
||||||
|
@ -42,22 +39,13 @@ class ImageViewerFragment : SecureFragment<FileImageViewerFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
sharedViewModel = requireActivity().run {
|
|
||||||
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val content = sharedViewModel.contentToOpen.value
|
val content = sharedViewModel.contentToOpen.value
|
||||||
content ?: return
|
content ?: return
|
||||||
|
|
||||||
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
|
||||||
?.setContent(content)
|
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
ImageFileViewModelFactory(content)
|
ImageFileViewModelFactory(content)
|
||||||
)[ImageFileViewModel::class.java]
|
)[ImageFileViewModel::class.java]
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
isSecure = arguments?.getBoolean("Secure") ?: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,13 +26,10 @@ import org.linphone.R
|
||||||
import org.linphone.activities.main.files.adapters.PdfPagesListAdapter
|
import org.linphone.activities.main.files.adapters.PdfPagesListAdapter
|
||||||
import org.linphone.activities.main.files.viewmodels.PdfFileViewModel
|
import org.linphone.activities.main.files.viewmodels.PdfFileViewModel
|
||||||
import org.linphone.activities.main.files.viewmodels.PdfFileViewModelFactory
|
import org.linphone.activities.main.files.viewmodels.PdfFileViewModelFactory
|
||||||
import org.linphone.activities.main.fragments.SecureFragment
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
|
||||||
import org.linphone.databinding.FilePdfViewerFragmentBinding
|
import org.linphone.databinding.FilePdfViewerFragmentBinding
|
||||||
|
|
||||||
class PdfViewerFragment : SecureFragment<FilePdfViewerFragmentBinding>() {
|
class PdfViewerFragment : GenericViewerFragment<FilePdfViewerFragmentBinding>() {
|
||||||
private lateinit var viewModel: PdfFileViewModel
|
private lateinit var viewModel: PdfFileViewModel
|
||||||
private lateinit var sharedViewModel: SharedMainViewModel
|
|
||||||
private lateinit var adapter: PdfPagesListAdapter
|
private lateinit var adapter: PdfPagesListAdapter
|
||||||
|
|
||||||
override fun getLayoutId(): Int = R.layout.file_pdf_viewer_fragment
|
override fun getLayoutId(): Int = R.layout.file_pdf_viewer_fragment
|
||||||
|
@ -42,24 +39,15 @@ class PdfViewerFragment : SecureFragment<FilePdfViewerFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
sharedViewModel = requireActivity().run {
|
|
||||||
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val content = sharedViewModel.contentToOpen.value
|
val content = sharedViewModel.contentToOpen.value
|
||||||
content ?: return
|
content ?: return
|
||||||
|
|
||||||
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
|
||||||
?.setContent(content)
|
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
PdfFileViewModelFactory(content)
|
PdfFileViewModelFactory(content)
|
||||||
)[PdfFileViewModel::class.java]
|
)[PdfFileViewModel::class.java]
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
isSecure = arguments?.getBoolean("Secure") ?: false
|
|
||||||
|
|
||||||
adapter = PdfPagesListAdapter(viewModel)
|
adapter = PdfPagesListAdapter(viewModel)
|
||||||
binding.pdfViewPager.adapter = adapter
|
binding.pdfViewPager.adapter = adapter
|
||||||
adapter.notifyDataSetChanged()
|
adapter.notifyDataSetChanged()
|
||||||
|
|
|
@ -25,13 +25,10 @@ import androidx.lifecycle.ViewModelProvider
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.files.viewmodels.TextFileViewModel
|
import org.linphone.activities.main.files.viewmodels.TextFileViewModel
|
||||||
import org.linphone.activities.main.files.viewmodels.TextFileViewModelFactory
|
import org.linphone.activities.main.files.viewmodels.TextFileViewModelFactory
|
||||||
import org.linphone.activities.main.fragments.SecureFragment
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
|
||||||
import org.linphone.databinding.FileTextViewerFragmentBinding
|
import org.linphone.databinding.FileTextViewerFragmentBinding
|
||||||
|
|
||||||
class TextViewerFragment : SecureFragment<FileTextViewerFragmentBinding>() {
|
class TextViewerFragment : GenericViewerFragment<FileTextViewerFragmentBinding>() {
|
||||||
private lateinit var viewModel: TextFileViewModel
|
private lateinit var viewModel: TextFileViewModel
|
||||||
private lateinit var sharedViewModel: SharedMainViewModel
|
|
||||||
|
|
||||||
override fun getLayoutId(): Int = R.layout.file_text_viewer_fragment
|
override fun getLayoutId(): Int = R.layout.file_text_viewer_fragment
|
||||||
|
|
||||||
|
@ -40,22 +37,13 @@ class TextViewerFragment : SecureFragment<FileTextViewerFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
sharedViewModel = requireActivity().run {
|
|
||||||
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val content = sharedViewModel.contentToOpen.value
|
val content = sharedViewModel.contentToOpen.value
|
||||||
content ?: return
|
content ?: return
|
||||||
|
|
||||||
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
|
||||||
?.setContent(content)
|
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
TextFileViewModelFactory(content)
|
TextFileViewModelFactory(content)
|
||||||
)[TextFileViewModel::class.java]
|
)[TextFileViewModel::class.java]
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
isSecure = arguments?.getBoolean("Secure") ?: false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,14 +28,11 @@ import androidx.navigation.fragment.findNavController
|
||||||
import org.linphone.R
|
import org.linphone.R
|
||||||
import org.linphone.activities.main.files.viewmodels.VideoFileViewModel
|
import org.linphone.activities.main.files.viewmodels.VideoFileViewModel
|
||||||
import org.linphone.activities.main.files.viewmodels.VideoFileViewModelFactory
|
import org.linphone.activities.main.files.viewmodels.VideoFileViewModelFactory
|
||||||
import org.linphone.activities.main.fragments.SecureFragment
|
|
||||||
import org.linphone.activities.main.viewmodels.SharedMainViewModel
|
|
||||||
import org.linphone.core.tools.Log
|
import org.linphone.core.tools.Log
|
||||||
import org.linphone.databinding.FileVideoViewerFragmentBinding
|
import org.linphone.databinding.FileVideoViewerFragmentBinding
|
||||||
|
|
||||||
class VideoViewerFragment : SecureFragment<FileVideoViewerFragmentBinding>() {
|
class VideoViewerFragment : GenericViewerFragment<FileVideoViewerFragmentBinding>() {
|
||||||
private lateinit var viewModel: VideoFileViewModel
|
private lateinit var viewModel: VideoFileViewModel
|
||||||
private lateinit var sharedViewModel: SharedMainViewModel
|
|
||||||
|
|
||||||
private lateinit var mediaController: MediaController
|
private lateinit var mediaController: MediaController
|
||||||
|
|
||||||
|
@ -46,24 +43,15 @@ class VideoViewerFragment : SecureFragment<FileVideoViewerFragmentBinding>() {
|
||||||
|
|
||||||
binding.lifecycleOwner = this
|
binding.lifecycleOwner = this
|
||||||
|
|
||||||
sharedViewModel = requireActivity().run {
|
|
||||||
ViewModelProvider(this).get(SharedMainViewModel::class.java)
|
|
||||||
}
|
|
||||||
|
|
||||||
val content = sharedViewModel.contentToOpen.value
|
val content = sharedViewModel.contentToOpen.value
|
||||||
content ?: return
|
content ?: return
|
||||||
|
|
||||||
(childFragmentManager.findFragmentById(R.id.top_bar_fragment) as? TopBarFragment)
|
|
||||||
?.setContent(content)
|
|
||||||
|
|
||||||
viewModel = ViewModelProvider(
|
viewModel = ViewModelProvider(
|
||||||
this,
|
this,
|
||||||
VideoFileViewModelFactory(content)
|
VideoFileViewModelFactory(content)
|
||||||
)[VideoFileViewModel::class.java]
|
)[VideoFileViewModel::class.java]
|
||||||
binding.viewModel = viewModel
|
binding.viewModel = viewModel
|
||||||
|
|
||||||
isSecure = arguments?.getBoolean("Secure") ?: false
|
|
||||||
|
|
||||||
mediaController = object : MediaController(requireContext()) {
|
mediaController = object : MediaController(requireContext()) {
|
||||||
// This is to prevent the first back key press to only hide to media controls
|
// This is to prevent the first back key press to only hide to media controls
|
||||||
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
|
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
|
||||||
|
|
Loading…
Reference in a new issue