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.

107 lines
3.6 KiB

  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 com.google.android.material.floatingactionbutton.FloatingActionButton;
  22. import java.util.ArrayList;
  23. import java.util.List;
  24. import androidx.annotation.NonNull;
  25. import androidx.annotation.Nullable;
  26. import androidx.constraintlayout.widget.Group;
  27. import androidx.fragment.app.FragmentTransaction;
  28. import androidx.lifecycle.Observer;
  29. import androidx.recyclerview.widget.LinearLayoutManager;
  30. import androidx.recyclerview.widget.RecyclerView;
  31. public class FragmentAccounts extends FragmentEx {
  32. private RecyclerView rvAccount;
  33. private ProgressBar pbWait;
  34. private Group grpReady;
  35. private FloatingActionButton fab;
  36. private AdapterAccount adapter;
  37. @Override
  38. @Nullable
  39. public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  40. setSubtitle(R.string.title_list_accounts);
  41. View view = inflater.inflate(R.layout.fragment_accounts, container, false);
  42. // Get controls
  43. rvAccount = view.findViewById(R.id.rvAccount);
  44. pbWait = view.findViewById(R.id.pbWait);
  45. grpReady = view.findViewById(R.id.grpReady);
  46. fab = view.findViewById(R.id.fab);
  47. // Wire controls
  48. rvAccount.setHasFixedSize(false);
  49. LinearLayoutManager llm = new LinearLayoutManager(getContext());
  50. rvAccount.setLayoutManager(llm);
  51. adapter = new AdapterAccount(getContext());
  52. rvAccount.setAdapter(adapter);
  53. fab.setOnClickListener(new View.OnClickListener() {
  54. @Override
  55. public void onClick(View view) {
  56. FragmentAccount fragment = new FragmentAccount();
  57. fragment.setArguments(new Bundle());
  58. FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
  59. fragmentTransaction.replace(R.id.content_frame, fragment).addToBackStack("account");
  60. fragmentTransaction.commit();
  61. }
  62. });
  63. // Initialize
  64. grpReady.setVisibility(View.GONE);
  65. pbWait.setVisibility(View.VISIBLE);
  66. return view;
  67. }
  68. @Override
  69. public void onActivityCreated(@Nullable Bundle savedInstanceState) {
  70. super.onActivityCreated(savedInstanceState);
  71. // Observe accounts
  72. DB.getInstance(getContext()).account().liveAccounts().observe(getViewLifecycleOwner(), new Observer<List<EntityAccount>>() {
  73. @Override
  74. public void onChanged(@Nullable List<EntityAccount> accounts) {
  75. if (accounts == null)
  76. accounts = new ArrayList<>();
  77. adapter.set(accounts);
  78. pbWait.setVisibility(View.GONE);
  79. grpReady.setVisibility(View.VISIBLE);
  80. }
  81. });
  82. }
  83. }