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.

92 lines
3.6 KiB

6 years ago
  1. package eu.faircode.email;
  2. /*
  3. This file is part of Safe email.
  4. Safe email 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.arch.lifecycle.LiveData;
  17. import android.arch.persistence.room.Dao;
  18. import android.arch.persistence.room.Insert;
  19. import android.arch.persistence.room.OnConflictStrategy;
  20. import android.arch.persistence.room.Query;
  21. import android.arch.persistence.room.Update;
  22. import java.util.List;
  23. @Dao
  24. public interface DaoFolder {
  25. @Query("SELECT * FROM folder WHERE account = :account")
  26. List<EntityFolder> getFolders(long account);
  27. @Query("SELECT * FROM folder WHERE account = :account AND synchronize = :synchronize")
  28. List<EntityFolder> getFolders(long account, boolean synchronize);
  29. @Query("SELECT * FROM folder WHERE account = :account AND type = '" + EntityFolder.TYPE_USER + "'")
  30. List<EntityFolder> getUserFolders(long account);
  31. @Query("SELECT folder.*, account.name AS accountName" +
  32. ", COUNT(message.id) AS messages" +
  33. ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
  34. " FROM folder" +
  35. " LEFT JOIN account ON account.id = folder.account" +
  36. " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
  37. " GROUP BY folder.id")
  38. LiveData<List<TupleFolderEx>> liveFolders();
  39. @Query("SELECT * FROM folder WHERE account = :account")
  40. LiveData<List<EntityFolder>> liveFolders(long account);
  41. @Query("SELECT folder.* FROM folder WHERE folder.id = :id")
  42. LiveData<EntityFolder> liveFolder(long id);
  43. @Query("SELECT folder.*, account.name AS accountName" +
  44. ", COUNT(message.id) AS messages" +
  45. ", SUM(CASE WHEN message.ui_seen = 0 THEN 1 ELSE 0 END) AS unseen" +
  46. " FROM folder" +
  47. " LEFT JOIN account ON account.id = folder.account" +
  48. " LEFT JOIN message ON message.folder = folder.id AND NOT message.ui_hide" +
  49. " WHERE folder.id = :id")
  50. LiveData<TupleFolderEx> liveFolderEx(long id);
  51. @Query("SELECT * FROM folder WHERE id = :id")
  52. EntityFolder getFolder(Long id);
  53. @Query("SELECT * FROM folder WHERE account = :account AND name = :name")
  54. EntityFolder getFolderByName(Long account, String name);
  55. @Query("SELECT folder.* FROM folder" +
  56. " WHERE account = :account AND type = :type")
  57. EntityFolder getFolderByType(long account, String type);
  58. @Query("SELECT * FROM folder WHERE type = '" + EntityFolder.TYPE_OUTBOX + "'")
  59. EntityFolder getOutbox();
  60. @Query("SELECT folder.* FROM folder" +
  61. " JOIN account ON account.id = folder.account" +
  62. " WHERE account.`primary` AND type = :type ")
  63. EntityFolder getPrimaryFolder(String type);
  64. @Insert(onConflict = OnConflictStrategy.REPLACE)
  65. long insertFolder(EntityFolder folder);
  66. @Update
  67. void updateFolder(EntityFolder folder);
  68. @Query("DELETE FROM folder WHERE account= :account AND name = :name")
  69. void deleteFolder(Long account, String name);
  70. }