2014-07-18 19:31:03 -07:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2018-09-20 13:27:18 -07:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2020-08-19 10:06:26 +10:00
|
|
|
import androidx.annotation.NonNull;
|
2018-09-20 13:27:18 -07:00
|
|
|
import android.text.TextUtils;
|
2015-06-30 17:45:39 -07:00
|
|
|
|
2015-02-16 02:38:09 -08:00
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator;
|
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
2016-03-23 10:34:41 -07:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-02-16 02:38:09 -08:00
|
|
|
|
2020-01-10 16:35:32 +11:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2018-09-20 13:27:18 -07:00
|
|
|
public class TransportOption implements Parcelable {
|
2015-03-11 14:23:45 -07:00
|
|
|
|
|
|
|
public enum Type {
|
|
|
|
SMS,
|
|
|
|
TEXTSECURE
|
|
|
|
}
|
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
private final @NonNull String text;
|
|
|
|
private final @NonNull Type type;
|
|
|
|
private final @NonNull String composeHint;
|
|
|
|
private final @NonNull CharacterCalculator characterCalculator;
|
|
|
|
private final @NonNull Optional<CharSequence> simName;
|
|
|
|
private final @NonNull Optional<Integer> simSubscriptionId;
|
2015-03-11 14:23:45 -07:00
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
public TransportOption(@NonNull Type type,
|
|
|
|
@NonNull String text,
|
|
|
|
@NonNull String composeHint,
|
|
|
|
@NonNull CharacterCalculator characterCalculator)
|
|
|
|
{
|
2020-08-20 20:36:56 +10:00
|
|
|
this(type, text, composeHint, characterCalculator,
|
2016-02-05 16:10:33 -08:00
|
|
|
Optional.<CharSequence>absent(), Optional.<Integer>absent());
|
|
|
|
}
|
|
|
|
|
|
|
|
public TransportOption(@NonNull Type type,
|
|
|
|
@NonNull String text,
|
|
|
|
@NonNull String composeHint,
|
|
|
|
@NonNull CharacterCalculator characterCalculator,
|
|
|
|
@NonNull Optional<CharSequence> simName,
|
|
|
|
@NonNull Optional<Integer> simSubscriptionId)
|
2015-03-11 14:23:45 -07:00
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
this.text = text;
|
|
|
|
this.composeHint = composeHint;
|
|
|
|
this.characterCalculator = characterCalculator;
|
2016-02-05 16:10:33 -08:00
|
|
|
this.simName = simName;
|
|
|
|
this.simSubscriptionId = simSubscriptionId;
|
2015-03-11 14:23:45 -07:00
|
|
|
}
|
|
|
|
|
2018-09-20 13:27:18 -07:00
|
|
|
TransportOption(Parcel in) {
|
|
|
|
this(Type.valueOf(in.readString()),
|
|
|
|
in.readString(),
|
|
|
|
in.readString(),
|
|
|
|
CharacterCalculator.readFromParcel(in),
|
|
|
|
Optional.fromNullable(TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in)),
|
|
|
|
in.readInt() == 1 ? Optional.of(in.readInt()) : Optional.absent());
|
|
|
|
}
|
2016-02-05 16:10:33 -08:00
|
|
|
|
|
|
|
public @NonNull Type getType() {
|
2015-03-11 14:23:45 -07:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isType(Type type) {
|
|
|
|
return this.type == type;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2015-02-16 02:38:09 -08:00
|
|
|
public boolean isSms() {
|
2015-03-11 14:23:45 -07:00
|
|
|
return type == Type.SMS;
|
2014-07-18 19:31:03 -07:00
|
|
|
}
|
|
|
|
|
2016-04-17 18:09:31 +02:00
|
|
|
public CharacterState calculateCharacters(String messageBody) {
|
|
|
|
return characterCalculator.calculateCharacters(messageBody);
|
2015-02-16 02:38:09 -08:00
|
|
|
}
|
2015-03-11 14:23:45 -07:00
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
public @NonNull String getComposeHint() {
|
2015-03-11 14:23:45 -07:00
|
|
|
return composeHint;
|
|
|
|
}
|
|
|
|
|
2016-02-05 16:10:33 -08:00
|
|
|
public @NonNull String getDescription() {
|
2015-03-11 14:23:45 -07:00
|
|
|
return text;
|
|
|
|
}
|
2016-02-05 16:10:33 -08:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Optional<CharSequence> getSimName() {
|
|
|
|
return simName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Optional<Integer> getSimSubscriptionId() {
|
|
|
|
return simSubscriptionId;
|
|
|
|
}
|
|
|
|
|
2018-09-20 13:27:18 -07:00
|
|
|
@Override
|
|
|
|
public int describeContents() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToParcel(Parcel dest, int flags) {
|
|
|
|
dest.writeString(type.name());
|
|
|
|
dest.writeString(text);
|
|
|
|
dest.writeString(composeHint);
|
|
|
|
CharacterCalculator.writeToParcel(dest, characterCalculator);
|
|
|
|
TextUtils.writeToParcel(simName.orNull(), dest, flags);
|
|
|
|
|
|
|
|
if (simSubscriptionId.isPresent()) {
|
|
|
|
dest.writeInt(1);
|
|
|
|
dest.writeInt(simSubscriptionId.get());
|
|
|
|
} else {
|
|
|
|
dest.writeInt(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static final Creator<TransportOption> CREATOR = new Creator<TransportOption>() {
|
|
|
|
@Override
|
|
|
|
public TransportOption createFromParcel(Parcel in) {
|
|
|
|
return new TransportOption(in);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TransportOption[] newArray(int size) {
|
|
|
|
return new TransportOption[size];
|
|
|
|
}
|
|
|
|
};
|
2015-02-16 02:38:09 -08:00
|
|
|
}
|