FairEmail/app/src/main/java/eu/faircode/email/DaoContact.java

91 lines
3.2 KiB
Java
Raw Normal View History

2019-02-13 09:24:06 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2019 by Marcel Bokhorst (M66B)
*/
import android.database.Cursor;
2019-03-14 18:47:10 +00:00
import androidx.lifecycle.LiveData;
2019-02-13 09:24:06 +00:00
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;
import java.util.List;
2019-02-13 09:24:06 +00:00
@Dao
public interface DaoContact {
2019-03-14 18:47:10 +00:00
@Query("SELECT * FROM contact" +
2019-03-17 08:26:17 +00:00
" WHERE account = :account")
List<EntityContact> getContacts(long account);
@Query("SELECT contact.*, account.name AS accountName" +
" FROM contact" +
2019-06-07 15:01:06 +00:00
" JOIN accountprop AS account ON account.id = contact.account" +
2019-03-16 18:30:56 +00:00
" ORDER BY times_contacted DESC, last_contacted DESC")
2019-03-17 08:26:17 +00:00
LiveData<List<TupleContactEx>> liveContacts();
2019-03-14 18:47:10 +00:00
@Query("SELECT * FROM contact" +
2019-03-17 08:26:17 +00:00
" WHERE state <> " + EntityContact.STATE_IGNORE +
2019-03-16 16:58:57 +00:00
" ORDER BY" +
2019-03-17 08:26:17 +00:00
" CASE WHEN state = " + EntityContact.STATE_FAVORITE + " THEN 0 ELSE 1 END" +
", CASE WHEN avatar IS NULL THEN 1 ELSE 0 END" +
2019-03-16 16:58:57 +00:00
", times_contacted DESC" +
", last_contacted DESC" +
" LIMIT :count")
List<EntityContact> getFrequentlyContacted(int count);
2019-02-13 09:24:06 +00:00
@Query("SELECT *" +
" FROM contact" +
2019-03-17 08:26:17 +00:00
" WHERE account = :account" +
" AND type = :type" +
2019-04-24 09:59:28 +00:00
" AND email = :email COLLATE NOCASE")
2019-03-17 08:26:17 +00:00
EntityContact getContact(long account, int type, String email);
2019-02-13 09:24:06 +00:00
@Query("SELECT id AS _id, name, email" +
" FROM contact" +
2019-03-17 08:26:17 +00:00
" WHERE (:account IS NULL OR account = :account)" +
" AND (:type IS NULL OR type = :type)" +
2019-03-17 09:23:05 +00:00
" AND (email LIKE :query COLLATE NOCASE OR name LIKE :query COLLATE NOCASE)" +
" AND state <> " + EntityContact.STATE_IGNORE +
2019-04-06 07:24:10 +00:00
" GROUP BY name, email" +
" ORDER BY" +
" CASE WHEN name IS NULL THEN 1 ELSE 0 END" +
", name COLLATE NOCASE, email COLLATE NOCASE")
2019-03-17 08:26:17 +00:00
Cursor searchContacts(Long account, Integer type, String query);
2019-02-13 09:24:06 +00:00
@Insert
long insertContact(EntityContact contact);
@Update
int updateContact(EntityContact contact);
2019-02-17 16:45:19 +00:00
2019-03-17 08:26:17 +00:00
@Query("UPDATE contact SET state = :state WHERE id = :id")
2019-03-15 11:31:26 +00:00
int setContactState(long id, int state);
2019-03-15 08:36:23 +00:00
2019-03-15 08:50:31 +00:00
@Query("DELETE FROM contact" +
" WHERE last_contacted IS NOT NULL" +
" AND last_contacted < :before" +
2019-03-17 08:26:17 +00:00
" AND state <> " + EntityContact.STATE_FAVORITE)
2019-03-15 08:50:31 +00:00
int deleteContacts(long before);
2019-03-15 08:41:22 +00:00
@Query("DELETE FROM contact")
2019-02-17 16:45:19 +00:00
int clearContacts();
2019-02-13 09:24:06 +00:00
}