2014-07-19 02:31:03 +00:00
|
|
|
package org.thoughtcrime.securesms;
|
|
|
|
|
2018-09-20 20:27:18 +00:00
|
|
|
import android.os.Parcel;
|
|
|
|
import android.os.Parcelable;
|
2020-08-19 00:06:26 +00:00
|
|
|
import androidx.annotation.NonNull;
|
2018-09-20 20:27:18 +00:00
|
|
|
import android.text.TextUtils;
|
2015-07-01 00:45:39 +00:00
|
|
|
|
2015-02-16 10:38:09 +00:00
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator;
|
|
|
|
import org.thoughtcrime.securesms.util.CharacterCalculator.CharacterState;
|
2016-03-23 17:34:41 +00:00
|
|
|
import org.whispersystems.libsignal.util.guava.Optional;
|
2015-02-16 10:38:09 +00:00
|
|
|
|
2020-01-10 05:35:32 +00:00
|
|
|
import network.loki.messenger.R;
|
|
|
|
|
2018-09-20 20:27:18 +00:00
|
|
|
public class TransportOption implements Parcelable {
|
2015-03-11 21:23:45 +00:00
|
|
|
|
|
|
|
public enum Type {
|
|
|
|
SMS,
|
|
|
|
TEXTSECURE
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:10:33 +00: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 21:23:45 +00:00
|
|
|
|
2016-02-06 00:10:33 +00:00
|
|
|
public TransportOption(@NonNull Type type,
|
|
|
|
@NonNull String text,
|
|
|
|
@NonNull String composeHint,
|
|
|
|
@NonNull CharacterCalculator characterCalculator)
|
|
|
|
{
|
2020-08-20 10:36:56 +00:00
|
|
|
this(type, text, composeHint, characterCalculator,
|
2016-02-06 00:10:33 +00: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 21:23:45 +00:00
|
|
|
{
|
|
|
|
this.type = type;
|
|
|
|
this.text = text;
|
|
|
|
this.composeHint = composeHint;
|
|
|
|
this.characterCalculator = characterCalculator;
|
2016-02-06 00:10:33 +00:00
|
|
|
this.simName = simName;
|
|
|
|
this.simSubscriptionId = simSubscriptionId;
|
2015-03-11 21:23:45 +00:00
|
|
|
}
|
|
|
|
|
2018-09-20 20:27:18 +00: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-06 00:10:33 +00:00
|
|
|
|
|
|
|
public @NonNull Type getType() {
|
2015-03-11 21:23:45 +00:00
|
|
|
return type;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isType(Type type) {
|
|
|
|
return this.type == type;
|
2014-07-19 02:31:03 +00:00
|
|
|
}
|
|
|
|
|
2015-02-16 10:38:09 +00:00
|
|
|
public boolean isSms() {
|
2015-03-11 21:23:45 +00:00
|
|
|
return type == Type.SMS;
|
2014-07-19 02:31:03 +00:00
|
|
|
}
|
|
|
|
|
2016-04-17 16:09:31 +00:00
|
|
|
public CharacterState calculateCharacters(String messageBody) {
|
|
|
|
return characterCalculator.calculateCharacters(messageBody);
|
2015-02-16 10:38:09 +00:00
|
|
|
}
|
2015-03-11 21:23:45 +00:00
|
|
|
|
2016-02-06 00:10:33 +00:00
|
|
|
public @NonNull String getComposeHint() {
|
2015-03-11 21:23:45 +00:00
|
|
|
return composeHint;
|
|
|
|
}
|
|
|
|
|
2016-02-06 00:10:33 +00:00
|
|
|
public @NonNull String getDescription() {
|
2015-03-11 21:23:45 +00:00
|
|
|
return text;
|
|
|
|
}
|
2016-02-06 00:10:33 +00:00
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Optional<CharSequence> getSimName() {
|
|
|
|
return simName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@NonNull
|
|
|
|
public Optional<Integer> getSimSubscriptionId() {
|
|
|
|
return simSubscriptionId;
|
|
|
|
}
|
|
|
|
|
2018-09-20 20:27:18 +00: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 10:38:09 +00:00
|
|
|
}
|