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

84 lines
2.6 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;
import java.util.List;
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;
@Dao
public interface DaoContact {
@Query("SELECT * FROM contact")
List<EntityContact> getContacts();
2019-03-14 18:47:10 +00:00
@Query("SELECT * FROM contact" +
2019-03-15 08:36:23 +00:00
" ORDER BY favorite DESC, times_contacted DESC, last_contacted DESC")
2019-03-14 18:47:10 +00:00
LiveData<List<EntityContact>> liveContacts();
@Query("SELECT * FROM contact" +
2019-03-15 08:36:23 +00:00
" ORDER BY favorite DESC, 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" +
" WHERE email = :email" +
" AND (:type IS NULL OR type = :type)")
2019-03-14 17:46:45 +00:00
EntityContact getContact(Integer type, String email);
2019-02-13 09:24:06 +00:00
@Query("SELECT id AS _id, name, email" +
", CASE type" +
" WHEN " + EntityContact.TYPE_TO + " THEN '>'" +
" WHEN " + EntityContact.TYPE_FROM + " THEN '<'" +
" ELSE '?'" +
" END AS type" +
" FROM contact" +
" WHERE name LIKE :name" +
" AND (:type IS NULL OR type = :type)")
Cursor searchContacts(Integer type, String name);
@Insert
long insertContact(EntityContact contact);
@Update
int updateContact(EntityContact contact);
2019-02-17 16:45:19 +00:00
2019-03-15 08:36:23 +00:00
@Query("UPDATE contact SET favorite = :favorite WHERE id = :id")
int setContactFavorite(long id, boolean favorite);
2019-03-15 08:41:22 +00:00
@Query("DELETE FROM contact WHERE id= :id")
int deleteContact(long id);
2019-03-15 08:50:31 +00:00
@Query("DELETE FROM contact" +
" WHERE last_contacted IS NOT NULL" +
" AND last_contacted < :before" +
" AND NOT favorite")
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
}