Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
2.9 KiB

6 years ago
6 years ago
6 years ago
6 years ago
  1. package eu.faircode.email;
  2. /*
  3. This file is part of FairEmail.
  4. FairEmail is free software: you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation, either version 3 of the License, or
  7. (at your option) any later version.
  8. NetGuard is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with NetGuard. If not, see <http://www.gnu.org/licenses/>.
  14. Copyright 2018 by Marcel Bokhorst (M66B)
  15. */
  16. import android.os.Bundle;
  17. import android.view.LayoutInflater;
  18. import android.view.View;
  19. import android.view.ViewGroup;
  20. import android.widget.ProgressBar;
  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;
  24. import androidx.annotation.NonNull;
  25. import androidx.annotation.Nullable;
  26. import androidx.constraintlayout.widget.Group;
  27. import androidx.lifecycle.Observer;
  28. import androidx.recyclerview.widget.LinearLayoutManager;
  29. import androidx.recyclerview.widget.RecyclerView;
  30. public class FragmentLogs extends FragmentEx {
  31. private RecyclerView rvLog;
  32. private ProgressBar pbWait;
  33. private Group grpReady;
  34. private AdapterLog adapter;
  35. @Override
  36. @Nullable
  37. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  38. setSubtitle(R.string.title_log);
  39. View view = inflater.inflate(R.layout.fragment_logs, container, false);
  40. // Get controls
  41. rvLog = view.findViewById(R.id.rvLog);
  42. pbWait = view.findViewById(R.id.pbWait);
  43. grpReady = view.findViewById(R.id.grpReady);
  44. // Wire controls
  45. rvLog.setHasFixedSize(false);
  46. LinearLayoutManager llm = new LinearLayoutManager(getContext());
  47. rvLog.setLayoutManager(llm);
  48. adapter = new AdapterLog(getContext());
  49. rvLog.setAdapter(adapter);
  50. // Initialize
  51. grpReady.setVisibility(View.GONE);
  52. pbWait.setVisibility(View.VISIBLE);
  53. return view;
  54. }
  55. @Override
  56. public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  57. super.onActivityCreated(savedInstanceState);
  58. long from = new Date().getTime() - 24 * 3600 * 1000L;
  59. DB db = DB.getInstance(getContext());
  60. db.log().liveLogs(from).observe(getViewLifecycleOwner(), new Observer<List<EntityLog>>() {
  61. @Override
  62. public void onChanged(List<EntityLog> logs) {
  63. if (logs == null)
  64. logs = new ArrayList<>();
  65. adapter.set(logs);
  66. pbWait.setVisibility(View.GONE);
  67. grpReady.setVisibility(View.VISIBLE);
  68. }
  69. });
  70. }
  71. }