NotificationsActivity.java 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /**
  2. * Nextcloud Android client application
  3. *
  4. * @author Andy Scherzinger
  5. * @author Mario Danic
  6. * Copyright (C) 2017 Andy Scherzinger
  7. * Copyright (C) 2017 Mario Danic
  8. *
  9. * This program is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU Affero General Public License as published by
  11. * the Free Software Foundation, either version 3 of the License, or
  12. * at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. package com.owncloud.android.ui.activity;
  23. import android.accounts.Account;
  24. import android.os.Bundle;
  25. import android.support.v7.widget.RecyclerView;
  26. import android.view.MenuItem;
  27. import android.view.View;
  28. import android.widget.ImageView;
  29. import android.widget.LinearLayout;
  30. import android.widget.ProgressBar;
  31. import android.widget.TextView;
  32. import com.owncloud.android.R;
  33. import com.owncloud.android.authentication.AccountUtils;
  34. import com.owncloud.android.lib.common.operations.RemoteOperation;
  35. import com.owncloud.android.lib.common.operations.RemoteOperationResult;
  36. import com.owncloud.android.lib.common.utils.Log_OC;
  37. import com.owncloud.android.lib.resources.notifications.GetRemoteNotificationsOperation;
  38. import com.owncloud.android.lib.resources.notifications.models.Notification;
  39. import java.util.List;
  40. import butterknife.BindString;
  41. import butterknife.BindView;
  42. import butterknife.ButterKnife;
  43. import butterknife.Unbinder;
  44. /**
  45. * Activity displaying all server side stored activity items.
  46. */
  47. public class NotificationsActivity extends FileActivity {
  48. private static final String TAG = NotificationsActivity.class.getSimpleName();
  49. @BindView(R.id.empty_list_view)
  50. public LinearLayout emptyContentContainer;
  51. @BindView(R.id.empty_list_view_text)
  52. public TextView emptyContentMessage;
  53. @BindView(R.id.empty_list_view_headline)
  54. public TextView emptyContentHeadline;
  55. @BindView(R.id.empty_list_icon)
  56. public ImageView emptyContentIcon;
  57. @BindView(R.id.empty_list_progress)
  58. public ProgressBar emptyContentProgressBar;
  59. @BindView(android.R.id.list)
  60. public RecyclerView recyclerView;
  61. @BindString(R.string.notifications_no_results_headline)
  62. public String noResultsHeadline;
  63. @BindString(R.string.notifications_no_results_message)
  64. public String noResultsMessage;
  65. private Unbinder unbinder;
  66. @Override
  67. protected void onCreate(Bundle savedInstanceState) {
  68. Log_OC.v(TAG, "onCreate() start");
  69. super.onCreate(savedInstanceState);
  70. setContentView(R.layout.notifications_layout);
  71. unbinder = ButterKnife.bind(this);
  72. // setup toolbar
  73. setupToolbar();
  74. // setup drawer
  75. setupDrawer(R.id.nav_notifications);
  76. getSupportActionBar().setTitle(getString(R.string.drawer_item_notifications));
  77. setupContent();
  78. }
  79. /**
  80. * sets up the UI elements and loads all activity items.
  81. */
  82. private void setupContent() {
  83. emptyContentIcon.setImageResource(R.drawable.ic_notification_light_grey);
  84. setEmptyContent(noResultsHeadline,noResultsMessage);
  85. // TODO add all (recycler) view relevant code + data loading + adapter etc.
  86. fetchAndSetData();
  87. }
  88. private void populateList(List<Notification> notifications) {
  89. }
  90. private void fetchAndSetData() {
  91. Thread t = new Thread(new Runnable() {
  92. public void run() {
  93. Account account = AccountUtils.getCurrentOwnCloudAccount(NotificationsActivity.this);
  94. RemoteOperation getRemoteNotificationOperation = new GetRemoteNotificationsOperation();
  95. final RemoteOperationResult result =
  96. getRemoteNotificationOperation.execute(account, NotificationsActivity.this);
  97. if (result.isSuccess() && result.getNotificationData() != null) {
  98. final List<Notification> notifications = result.getNotificationData();
  99. runOnUiThread(new Runnable() {
  100. @Override
  101. public void run() {
  102. populateList(notifications);
  103. emptyContentContainer.setVisibility(View.GONE);
  104. recyclerView.setVisibility(View.VISIBLE);
  105. }
  106. });
  107. } else {
  108. Log_OC.d(TAG, result.getLogMessage());
  109. // show error
  110. runOnUiThread(new Runnable() {
  111. @Override
  112. public void run() {
  113. setEmptyContent(noResultsHeadline, result.getLogMessage());
  114. }
  115. });
  116. }
  117. }
  118. });
  119. t.start();
  120. }
  121. @Override
  122. public boolean onOptionsItemSelected(MenuItem item) {
  123. boolean retval;
  124. switch (item.getItemId()) {
  125. case android.R.id.home:
  126. if (isDrawerOpen()) {
  127. closeDrawer();
  128. } else {
  129. openDrawer();
  130. }
  131. default:
  132. retval = super.onOptionsItemSelected(item);
  133. }
  134. return retval;
  135. }
  136. private void setLoadingMessage() {
  137. emptyContentHeadline.setText(R.string.file_list_loading);
  138. emptyContentMessage.setText("");
  139. emptyContentIcon.setVisibility(View.GONE);
  140. emptyContentProgressBar.setVisibility(View.VISIBLE);
  141. }
  142. private void setEmptyContent(String headline, String message) {
  143. if (emptyContentContainer != null && emptyContentMessage != null) {
  144. emptyContentHeadline.setText(headline);
  145. emptyContentMessage.setText(message);
  146. emptyContentProgressBar.setVisibility(View.GONE);
  147. emptyContentIcon.setVisibility(View.VISIBLE);
  148. }
  149. }
  150. }