ChatFragment.kt 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package io.r_a_d.radio2.ui.chat
  2. import android.os.Bundle
  3. import android.util.Log
  4. import android.view.LayoutInflater
  5. import android.view.View
  6. import android.view.ViewGroup
  7. import android.view.WindowManager
  8. import android.webkit.WebView
  9. import androidx.fragment.app.Fragment
  10. import androidx.lifecycle.ViewModelProviders
  11. import io.r_a_d.radio2.R
  12. class ChatFragment : Fragment() {
  13. private lateinit var chatViewModel: ChatViewModel
  14. override fun onCreateView(
  15. inflater: LayoutInflater,
  16. container: ViewGroup?,
  17. savedInstanceState: Bundle?
  18. ): View? {
  19. activity?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN)
  20. chatViewModel =
  21. ViewModelProviders.of(this).get(ChatViewModel::class.java)
  22. if (!chatViewModel.isChatLoaded)
  23. {
  24. try {
  25. chatViewModel.root = inflater.inflate(R.layout.fragment_chat, container, false)
  26. chatViewModel.webView = chatViewModel.root.findViewById<WebView>(R.id.chat_webview)
  27. chatViewModel.webViewChat = WebViewChat(chatViewModel.webView as WebView)
  28. chatViewModel.webViewChat!!.start()
  29. } catch (e: Exception) {
  30. chatViewModel.root = inflater.inflate(R.layout.fragment_error_chat, container, false)
  31. }
  32. chatViewModel.isChatLoaded = true
  33. Log.d(tag, "webview created")
  34. } else {
  35. Log.d(tag, "webview already created!?")
  36. }
  37. return chatViewModel.root
  38. }
  39. }