2012-07-21 07:23:25 +02:00
|
|
|
/**
|
2011-12-20 19:20:44 +01:00
|
|
|
* Copyright (C) 2011 Whisper Systems
|
2012-07-21 07:23:25 +02:00
|
|
|
*
|
2011-12-20 19:20:44 +01:00
|
|
|
* This program 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.
|
|
|
|
*
|
|
|
|
* This program 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.
|
2012-07-21 07:23:25 +02:00
|
|
|
*
|
2011-12-20 19:20:44 +01:00
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
package org.thoughtcrime.securesms.contacts;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.net.Uri;
|
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2021-10-04 09:51:19 +02:00
|
|
|
import org.session.libsession.utilities.GroupRecord;
|
|
|
|
import org.session.libsession.utilities.TextSecurePreferences;
|
2014-12-14 14:53:56 +01:00
|
|
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
2021-10-04 09:51:19 +02:00
|
|
|
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
|
2012-07-21 07:23:25 +02:00
|
|
|
|
|
|
|
import java.util.LinkedList;
|
|
|
|
import java.util.List;
|
2020-03-12 23:35:47 +01:00
|
|
|
|
|
|
|
import network.loki.messenger.R;
|
2011-12-20 19:20:44 +01:00
|
|
|
|
|
|
|
/**
|
2012-10-23 04:17:08 +02:00
|
|
|
* This class was originally a layer of indirection between
|
|
|
|
* ContactAccessorNewApi and ContactAccesorOldApi, which corresponded
|
|
|
|
* to the API changes between 1.x and 2.x.
|
|
|
|
*
|
|
|
|
* Now that we no longer support 1.x, this class mostly serves as a place
|
|
|
|
* to encapsulate Contact-related logic. It's still a singleton, mostly
|
|
|
|
* just because that's how it's currently called from everywhere.
|
2012-07-21 07:23:25 +02:00
|
|
|
*
|
2011-12-20 19:20:44 +01:00
|
|
|
* @author Moxie Marlinspike
|
|
|
|
*/
|
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
public class ContactAccessor {
|
2011-12-20 19:20:44 +01:00
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
private static final ContactAccessor instance = new ContactAccessor();
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public static synchronized ContactAccessor getInstance() {
|
2012-10-23 04:17:08 +02:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getNameFromContact(Context context, Uri uri) {
|
2020-03-12 23:35:47 +01:00
|
|
|
return "Anonymous";
|
2012-10-23 04:17:08 +02:00
|
|
|
}
|
|
|
|
|
2013-10-17 02:28:36 +02:00
|
|
|
public ContactData getContactData(Context context, Uri uri) {
|
|
|
|
return getContactData(context, getNameFromContact(context, uri), Long.parseLong(uri.getLastPathSegment()));
|
|
|
|
}
|
2012-10-23 04:17:08 +02:00
|
|
|
|
|
|
|
private ContactData getContactData(Context context, String displayName, long id) {
|
2020-03-12 23:35:47 +01:00
|
|
|
return new ContactData(id, displayName);
|
2012-10-23 04:17:08 +02:00
|
|
|
}
|
|
|
|
|
2014-12-14 14:53:56 +01:00
|
|
|
public List<String> getNumbersForThreadSearchFilter(Context context, String constraint) {
|
|
|
|
LinkedList<String> numberList = new LinkedList<>();
|
2012-10-23 04:17:08 +02:00
|
|
|
|
2014-12-14 14:53:56 +01:00
|
|
|
GroupDatabase.Reader reader = null;
|
|
|
|
GroupRecord record;
|
|
|
|
|
|
|
|
try {
|
2021-10-04 09:51:19 +02:00
|
|
|
reader = DatabaseComponent.get(context).groupDatabase().getGroupsFilteredByTitle(constraint);
|
2014-12-14 14:53:56 +01:00
|
|
|
|
|
|
|
while ((record = reader.getNext()) != null) {
|
|
|
|
numberList.add(record.getEncodedId());
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
if (reader != null)
|
|
|
|
reader.close();
|
|
|
|
}
|
|
|
|
|
2019-01-14 08:30:54 +01:00
|
|
|
if (context.getString(R.string.note_to_self).toLowerCase().contains(constraint.toLowerCase()) &&
|
|
|
|
!numberList.contains(TextSecurePreferences.getLocalNumber(context)))
|
|
|
|
{
|
|
|
|
numberList.add(TextSecurePreferences.getLocalNumber(context));
|
|
|
|
}
|
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
return numberList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public CharSequence phoneTypeToString(Context mContext, int type, CharSequence label) {
|
2020-03-12 23:35:47 +01:00
|
|
|
return label;
|
2012-10-23 04:17:08 +02:00
|
|
|
}
|
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public static class NumberData implements Parcelable {
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public static final Parcelable.Creator<NumberData> CREATOR = new Parcelable.Creator<NumberData>() {
|
|
|
|
public NumberData createFromParcel(Parcel in) {
|
|
|
|
return new NumberData(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
public NumberData[] newArray(int size) {
|
|
|
|
return new NumberData[size];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
public final String number;
|
|
|
|
public final String type;
|
2011-12-20 19:20:44 +01:00
|
|
|
|
|
|
|
public NumberData(String type, String number) {
|
|
|
|
this.type = type;
|
|
|
|
this.number = number;
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public NumberData(Parcel in) {
|
|
|
|
number = in.readString();
|
|
|
|
type = in.readString();
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeString(number);
|
|
|
|
dest.writeString(type);
|
|
|
|
}
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public static class ContactData implements Parcelable {
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public static final Parcelable.Creator<ContactData> CREATOR = new Parcelable.Creator<ContactData>() {
|
|
|
|
public ContactData createFromParcel(Parcel in) {
|
|
|
|
return new ContactData(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContactData[] newArray(int size) {
|
|
|
|
return new ContactData[size];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
public final long id;
|
|
|
|
public final String name;
|
|
|
|
public final List<NumberData> numbers;
|
2011-12-20 19:20:44 +01:00
|
|
|
|
2012-10-23 04:17:08 +02:00
|
|
|
public ContactData(long id, String name) {
|
|
|
|
this.id = id;
|
|
|
|
this.name = name;
|
|
|
|
this.numbers = new LinkedList<NumberData>();
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public ContactData(Parcel in) {
|
|
|
|
id = in.readLong();
|
|
|
|
name = in.readString();
|
|
|
|
numbers = new LinkedList<NumberData>();
|
|
|
|
in.readTypedList(numbers, NumberData.CREATOR);
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
2012-07-21 07:23:25 +02:00
|
|
|
|
2011-12-20 19:20:44 +01:00
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeLong(id);
|
|
|
|
dest.writeString(name);
|
|
|
|
dest.writeTypedList(numbers);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|