LogsActivity.java 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * ownCloud Android client application
  3. *
  4. * Copyright (C) 2015 ownCloud Inc.
  5. * Copyright (C) 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 General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.owncloud.android.ui.activity;
  20. import android.graphics.PorterDuff;
  21. import android.os.Bundle;
  22. import android.view.Menu;
  23. import android.view.MenuItem;
  24. import android.widget.Button;
  25. import com.nextcloud.client.di.ViewModelFactory;
  26. import com.nextcloud.client.logger.ui.LogsAdapter;
  27. import com.nextcloud.client.logger.ui.LogsViewModel;
  28. import com.owncloud.android.R;
  29. import com.owncloud.android.utils.ThemeUtils;
  30. import javax.inject.Inject;
  31. import androidx.lifecycle.ViewModelProvider;
  32. import androidx.recyclerview.widget.LinearLayoutManager;
  33. import androidx.recyclerview.widget.RecyclerView;
  34. import butterknife.BindView;
  35. import butterknife.ButterKnife;
  36. import butterknife.OnClick;
  37. import butterknife.Unbinder;
  38. public class LogsActivity extends ToolbarActivity {
  39. private Unbinder unbinder;
  40. @BindView(R.id.deleteLogHistoryButton)
  41. Button deleteHistoryButton;
  42. @BindView(R.id.sendLogHistoryButton)
  43. Button sendHistoryButton;
  44. @BindView(R.id.logsList)
  45. RecyclerView logListView;
  46. @Inject ViewModelFactory viewModelFactory;
  47. private LogsViewModel vm;
  48. @Override
  49. public boolean onPrepareOptionsMenu(Menu menu) {
  50. return super.onPrepareOptionsMenu(menu);
  51. }
  52. @Override
  53. protected void onCreate(Bundle savedInstanceState) {
  54. super.onCreate(savedInstanceState);
  55. setContentView(R.layout.logs_activity);
  56. unbinder = ButterKnife.bind(this);
  57. final LogsAdapter logsAdapter = new LogsAdapter(this);
  58. logListView.setLayoutManager(new LinearLayoutManager(this));
  59. logListView.setAdapter(logsAdapter);
  60. vm = new ViewModelProvider(this, viewModelFactory).get(LogsViewModel.class);
  61. vm.getEntries().observe(this, logsAdapter::setEntries);
  62. vm.load();
  63. setupToolbar();
  64. setTitle(getText(R.string.actionbar_logger));
  65. if (getSupportActionBar() != null) {
  66. getSupportActionBar().setDisplayHomeAsUpEnabled(true);
  67. }
  68. sendHistoryButton.getBackground().setColorFilter(ThemeUtils.primaryColor(this), PorterDuff.Mode.SRC_ATOP);
  69. deleteHistoryButton.setTextColor(ThemeUtils.primaryColor(this, true));
  70. }
  71. @Override
  72. public boolean onOptionsItemSelected(MenuItem item) {
  73. boolean retval = true;
  74. switch (item.getItemId()) {
  75. case android.R.id.home:
  76. finish();
  77. break;
  78. default:
  79. retval = super.onOptionsItemSelected(item);
  80. break;
  81. }
  82. return retval;
  83. }
  84. @OnClick(R.id.deleteLogHistoryButton)
  85. void deleteLogs() {
  86. vm.deleteAll();
  87. finish();
  88. }
  89. @OnClick(R.id.sendLogHistoryButton)
  90. void sendLogs() {
  91. vm.send();
  92. }
  93. @Override
  94. protected void onDestroy() {
  95. super.onDestroy();
  96. unbinder.unbind();
  97. }
  98. }