LogsActivity.kt 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /*
  2. * Nextcloud Android client application
  3. *
  4. * @author Chris Narkiewicz
  5. * Copyright (C) 2019 Chris Narkiewicz <hello@ezaquarii.com>
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU Affero General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU Affero General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Affero General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. package com.nextcloud.client.logger.ui
  21. import android.os.Bundle
  22. import android.view.Menu
  23. import android.view.MenuItem
  24. import android.widget.ProgressBar
  25. import androidx.appcompat.widget.SearchView
  26. import androidx.databinding.DataBindingUtil
  27. import androidx.lifecycle.Observer
  28. import androidx.lifecycle.ViewModelProvider
  29. import androidx.recyclerview.widget.LinearLayoutManager
  30. import androidx.recyclerview.widget.RecyclerView
  31. import com.nextcloud.client.di.ViewModelFactory
  32. import com.owncloud.android.R
  33. import com.owncloud.android.databinding.LogsActivityBinding
  34. import com.owncloud.android.ui.activity.ToolbarActivity
  35. import com.owncloud.android.utils.ThemeUtils
  36. import javax.inject.Inject
  37. class LogsActivity : ToolbarActivity() {
  38. @Inject
  39. protected lateinit var viewModelFactory: ViewModelFactory
  40. private lateinit var vm: LogsViewModel
  41. private lateinit var binding: LogsActivityBinding
  42. private lateinit var logsAdapter: LogsAdapter
  43. private val searchBoxListener = object : SearchView.OnQueryTextListener {
  44. override fun onQueryTextSubmit(query: String): Boolean {
  45. return false
  46. }
  47. override fun onQueryTextChange(newText: String): Boolean {
  48. vm.filter(newText)
  49. return false
  50. }
  51. }
  52. override fun onCreate(savedInstanceState: Bundle?) {
  53. super.onCreate(savedInstanceState)
  54. vm = ViewModelProvider(this, viewModelFactory).get(LogsViewModel::class.java)
  55. binding = DataBindingUtil.setContentView<LogsActivityBinding>(this, R.layout.logs_activity).apply {
  56. lifecycleOwner = this@LogsActivity
  57. vm = this@LogsActivity.vm
  58. }
  59. findViewById<ProgressBar>(R.id.logs_loading_progress).apply {
  60. ThemeUtils.themeProgressBar(context, this)
  61. }
  62. logsAdapter = LogsAdapter(this)
  63. findViewById<RecyclerView>(R.id.logsList).apply {
  64. layoutManager = LinearLayoutManager(this@LogsActivity)
  65. adapter = logsAdapter
  66. }
  67. vm.entries.observe(this, Observer { logsAdapter.entries = it })
  68. vm.load()
  69. setupToolbar()
  70. supportActionBar?.setDisplayHomeAsUpEnabled(true)
  71. supportActionBar?.apply { ThemeUtils.setColoredTitle(this, getString(R.string.logs_title), baseContext) }
  72. ThemeUtils.tintBackButton(supportActionBar, baseContext)
  73. }
  74. override fun onCreateOptionsMenu(menu: Menu): Boolean {
  75. menuInflater.inflate(R.menu.activity_logs, menu)
  76. (menu.findItem(R.id.action_search).actionView as SearchView).apply {
  77. setOnQueryTextListener(searchBoxListener)
  78. ThemeUtils.themeSearchView(this, true, context)
  79. }
  80. return super.onCreateOptionsMenu(menu)
  81. }
  82. override fun onOptionsItemSelected(item: MenuItem): Boolean {
  83. var retval = true
  84. when (item.itemId) {
  85. android.R.id.home -> finish()
  86. R.id.action_delete_logs -> vm.deleteAll()
  87. R.id.action_send_logs -> vm.send()
  88. R.id.action_refresh_logs -> vm.load()
  89. else -> retval = super.onOptionsItemSelected(item)
  90. }
  91. return retval
  92. }
  93. }