mirror of https://github.com/M66B/FairEmail.git
parent
c9308e71ff
commit
5b124c8ce4
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,58 @@
|
||||
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;
|
||||
|
||||
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();
|
||||
|
||||
@Query("SELECT *" +
|
||||
" FROM contact" +
|
||||
" WHERE email = :email" +
|
||||
" AND (:type IS NULL OR type = :type)")
|
||||
List<EntityContact> getContacts(Integer type, String email);
|
||||
|
||||
@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);
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
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 org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.Index;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
// https://developer.android.com/training/data-storage/room/defining-data
|
||||
|
||||
@Entity(
|
||||
tableName = EntityContact.TABLE_NAME,
|
||||
foreignKeys = {
|
||||
},
|
||||
indices = {
|
||||
@Index(value = {"email", "type"}, unique = true),
|
||||
@Index(value = {"name", "type"}),
|
||||
}
|
||||
)
|
||||
public class EntityContact implements Serializable {
|
||||
static final String TABLE_NAME = "contact";
|
||||
|
||||
static final int TYPE_TO = 0;
|
||||
static final int TYPE_FROM = 1;
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
public Long id;
|
||||
@NonNull
|
||||
public int type;
|
||||
@NonNull
|
||||
public String email;
|
||||
public String name;
|
||||
|
||||
public JSONObject toJSON() throws JSONException {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("id", id);
|
||||
json.put("type", type);
|
||||
json.put("email", email);
|
||||
json.put("name", name);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static EntityContact fromJSON(JSONObject json) throws JSONException {
|
||||
EntityContact contact = new EntityContact();
|
||||
// id
|
||||
contact.type = json.getInt("type");
|
||||
contact.email = json.getString("email");
|
||||
if (json.has("name"))
|
||||
contact.name = json.getString("name");
|
||||
return contact;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return (name == null ? email : name + " <" + email + ">");
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeightSmall"
|
||||
android:paddingStart="?android:attr/listPreferredItemPaddingStart"
|
||||
android:paddingEnd="?android:attr/listPreferredItemPaddingEnd">
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text1"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Text1"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@android:id/text2"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="6dp"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:text="Text2"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toStartOf="@+id/tvType"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/text1" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvType"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text=""
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Small"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@android:id/text1" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in new issue