Simple email application for Android. Original source code: https://framagit.org/dystopia-project/simple-email

96 lines
3.3 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 java.util.List;
  17. import androidx.lifecycle.LiveData;
  18. import androidx.room.Dao;
  19. import androidx.room.Insert;
  20. import androidx.room.Query;
  21. import androidx.room.Update;
  22. @Dao
  23. public interface DaoAccount {
  24. @Query("SELECT * FROM account")
  25. List<EntityAccount> getAccounts();
  26. @Query("SELECT * FROM account WHERE synchronize = :synchronize")
  27. List<EntityAccount> getAccounts(boolean synchronize);
  28. @Query("SELECT * FROM account")
  29. LiveData<List<EntityAccount>> liveAccounts();
  30. @Query("SELECT * FROM account WHERE synchronize = :synchronize")
  31. LiveData<List<EntityAccount>> liveAccounts(boolean synchronize);
  32. @Query("SELECT * FROM account WHERE id = :id")
  33. EntityAccount getAccount(long id);
  34. @Query("SELECT * FROM account WHERE `primary`")
  35. EntityAccount getPrimaryAccount();
  36. @Query("SELECT COUNT(*) FROM account WHERE synchronize")
  37. int getSynchronizingAccountCount();
  38. @Query("SELECT * FROM account WHERE `primary`")
  39. LiveData<EntityAccount> livePrimaryAccount();
  40. @Query("SELECT * FROM account WHERE id = :id")
  41. LiveData<EntityAccount> liveAccount(long id);
  42. @Query("SELECT" +
  43. " (SELECT COUNT(account.id) FROM account WHERE synchronize) AS accounts" +
  44. ", (SELECT COUNT(operation.id) FROM operation" +
  45. " JOIN message ON message.id = operation.message" +
  46. " JOIN account ON account.id = message.account" +
  47. " WHERE synchronize) AS operations" +
  48. ", (SELECT COUNT(message.id) FROM message" +
  49. " JOIN folder ON folder.id = message.folder" +
  50. " JOIN operation ON operation.message = message.id AND operation.name = '" + EntityOperation.SEND + "'" +
  51. " WHERE NOT message.ui_seen" +
  52. " AND folder.type = '" + EntityFolder.OUTBOX + "') AS unsent")
  53. LiveData<TupleAccountStats> liveStats();
  54. @Insert
  55. long insertAccount(EntityAccount account);
  56. @Update
  57. void updateAccount(EntityAccount account);
  58. @Query("UPDATE account SET seen_until = :time WHERE id = :id")
  59. int setAccountSeenUntil(long id, long time);
  60. @Query("UPDATE account SET state = :state WHERE id = :id")
  61. int setAccountState(long id, String state);
  62. @Query("UPDATE account SET password = :password WHERE id = :id")
  63. int setAccountPassword(long id, String password);
  64. @Query("UPDATE account SET error = :error WHERE id = :id")
  65. int setAccountError(long id, String error);
  66. @Query("UPDATE account SET `primary` = 0")
  67. void resetPrimary();
  68. @Query("DELETE FROM account WHERE id = :id")
  69. void deleteAccount(long id);
  70. }