mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-23 08:27:30 +00:00
Remove unused longmessage package
This commit is contained in:
commit
984c3763b6
@ -235,10 +235,6 @@
|
|||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
android:theme="@style/Theme.Session.DayNight">
|
android:theme="@style/Theme.Session.DayNight">
|
||||||
</activity>
|
</activity>
|
||||||
<activity
|
|
||||||
android:name="org.thoughtcrime.securesms.longmessage.LongMessageActivity"
|
|
||||||
android:screenOrientation="portrait"
|
|
||||||
android:theme="@style/Theme.Session.DayNight" />
|
|
||||||
<activity
|
<activity
|
||||||
android:name="org.thoughtcrime.securesms.DatabaseUpgradeActivity"
|
android:name="org.thoughtcrime.securesms.DatabaseUpgradeActivity"
|
||||||
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
|
android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize"
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.longmessage;
|
|
||||||
|
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A wrapper around a {@link MessageRecord} and its extra text attachment expanded into a string
|
|
||||||
* held in memory.
|
|
||||||
*/
|
|
||||||
class LongMessage {
|
|
||||||
|
|
||||||
private final MessageRecord messageRecord;
|
|
||||||
private final String fullBody;
|
|
||||||
|
|
||||||
LongMessage(MessageRecord messageRecord, String fullBody) {
|
|
||||||
this.messageRecord = messageRecord;
|
|
||||||
this.fullBody = fullBody;
|
|
||||||
}
|
|
||||||
|
|
||||||
MessageRecord getMessageRecord() {
|
|
||||||
return messageRecord;
|
|
||||||
}
|
|
||||||
|
|
||||||
String getFullBody() {
|
|
||||||
return !TextUtils.isEmpty(fullBody) ? fullBody : messageRecord.getBody();
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,91 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.longmessage;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.text.Spannable;
|
|
||||||
import android.text.method.LinkMovementMethod;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.widget.TextView;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import org.session.libsession.utilities.Address;
|
|
||||||
import org.session.libsession.utilities.Util;
|
|
||||||
import org.session.libsession.utilities.recipients.Recipient;
|
|
||||||
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity;
|
|
||||||
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageContentView;
|
|
||||||
|
|
||||||
import network.loki.messenger.R;
|
|
||||||
|
|
||||||
public class LongMessageActivity extends PassphraseRequiredActionBarActivity {
|
|
||||||
|
|
||||||
private static final String KEY_ADDRESS = "address";
|
|
||||||
private static final String KEY_MESSAGE_ID = "message_id";
|
|
||||||
private static final String KEY_IS_MMS = "is_mms";
|
|
||||||
|
|
||||||
private static final int MAX_DISPLAY_LENGTH = 64 * 1024;
|
|
||||||
|
|
||||||
private TextView textBody;
|
|
||||||
|
|
||||||
private LongMessageViewModel viewModel;
|
|
||||||
|
|
||||||
public static Intent getIntent(@NonNull Context context, @NonNull Address conversationAddress, long messageId, boolean isMms) {
|
|
||||||
Intent intent = new Intent(context, LongMessageActivity.class);
|
|
||||||
intent.putExtra(KEY_ADDRESS, conversationAddress.serialize());
|
|
||||||
intent.putExtra(KEY_MESSAGE_ID, messageId);
|
|
||||||
intent.putExtra(KEY_IS_MMS, isMms);
|
|
||||||
return intent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState, boolean ready) {
|
|
||||||
super.onCreate(savedInstanceState, ready);
|
|
||||||
setContentView(R.layout.longmessage_activity);
|
|
||||||
textBody = findViewById(R.id.longmessage_text);
|
|
||||||
|
|
||||||
initViewModel(getIntent().getLongExtra(KEY_MESSAGE_ID, -1), getIntent().getBooleanExtra(KEY_IS_MMS, false));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
|
||||||
super.onOptionsItemSelected(item);
|
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
|
||||||
case android.R.id.home:
|
|
||||||
finish();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initViewModel(long messageId, boolean isMms) {
|
|
||||||
viewModel = new ViewModelProvider(this, new LongMessageViewModel.Factory(getApplication(), new LongMessageRepository(this), messageId, isMms))
|
|
||||||
.get(LongMessageViewModel.class);
|
|
||||||
|
|
||||||
viewModel.getMessage().observe(this, message -> {
|
|
||||||
if (message == null) return;
|
|
||||||
|
|
||||||
if (!message.isPresent()) {
|
|
||||||
Toast.makeText(this, R.string.LongMessageActivity_unable_to_find_message, Toast.LENGTH_SHORT).show();
|
|
||||||
finish();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (message.get().getMessageRecord().isOutgoing()) {
|
|
||||||
getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_your_message));
|
|
||||||
} else {
|
|
||||||
Recipient recipient = message.get().getMessageRecord().getRecipient();
|
|
||||||
String name = Util.getFirstNonEmpty(recipient.getName(), recipient.getProfileName(), recipient.getAddress().serialize());
|
|
||||||
getSupportActionBar().setTitle(getString(R.string.LongMessageActivity_message_from_s, name));
|
|
||||||
}
|
|
||||||
Spannable bodySpans = VisibleMessageContentView.Companion.getBodySpans(this, message.get().getMessageRecord(), null);
|
|
||||||
textBody.setText(bodySpans);
|
|
||||||
textBody.setMovementMethod(LinkMovementMethod.getInstance());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,102 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.longmessage;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.WorkerThread;
|
|
||||||
|
|
||||||
import org.session.libsession.utilities.Util;
|
|
||||||
import org.session.libsession.utilities.concurrent.SignalExecutors;
|
|
||||||
import org.session.libsignal.utilities.Log;
|
|
||||||
import org.session.libsignal.utilities.guava.Optional;
|
|
||||||
import org.thoughtcrime.securesms.database.MmsDatabase;
|
|
||||||
import org.thoughtcrime.securesms.database.SmsDatabase;
|
|
||||||
import org.thoughtcrime.securesms.database.model.MessageRecord;
|
|
||||||
import org.thoughtcrime.securesms.database.model.MmsMessageRecord;
|
|
||||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
|
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
|
||||||
import org.thoughtcrime.securesms.mms.TextSlide;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
class LongMessageRepository {
|
|
||||||
|
|
||||||
private final static String TAG = LongMessageRepository.class.getSimpleName();
|
|
||||||
|
|
||||||
private final MmsDatabase mmsDatabase;
|
|
||||||
private final SmsDatabase smsDatabase;
|
|
||||||
|
|
||||||
LongMessageRepository(@NonNull Context context) {
|
|
||||||
this.mmsDatabase = DatabaseComponent.get(context).mmsDatabase();
|
|
||||||
this.smsDatabase = DatabaseComponent.get(context).smsDatabase();
|
|
||||||
}
|
|
||||||
|
|
||||||
void getMessage(@NonNull Context context, long messageId, boolean isMms, @NonNull Callback<Optional<LongMessage>> callback) {
|
|
||||||
SignalExecutors.BOUNDED.execute(() -> {
|
|
||||||
if (isMms) {
|
|
||||||
callback.onComplete(getMmsLongMessage(context, mmsDatabase, messageId));
|
|
||||||
} else {
|
|
||||||
callback.onComplete(getSmsLongMessage(smsDatabase, messageId));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private Optional<LongMessage> getMmsLongMessage(@NonNull Context context, @NonNull MmsDatabase mmsDatabase, long messageId) {
|
|
||||||
Optional<MmsMessageRecord> record = getMmsMessage(mmsDatabase, messageId);
|
|
||||||
|
|
||||||
if (record.isPresent()) {
|
|
||||||
TextSlide textSlide = record.get().getSlideDeck().getTextSlide();
|
|
||||||
|
|
||||||
if (textSlide != null && textSlide.getUri() != null) {
|
|
||||||
return Optional.of(new LongMessage(record.get(), readFullBody(context, textSlide.getUri())));
|
|
||||||
} else {
|
|
||||||
return Optional.of(new LongMessage(record.get(), ""));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return Optional.absent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private Optional<LongMessage> getSmsLongMessage(@NonNull SmsDatabase smsDatabase, long messageId) {
|
|
||||||
Optional<MessageRecord> record = getSmsMessage(smsDatabase, messageId);
|
|
||||||
|
|
||||||
if (record.isPresent()) {
|
|
||||||
return Optional.of(new LongMessage(record.get(), ""));
|
|
||||||
} else {
|
|
||||||
return Optional.absent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private Optional<MmsMessageRecord> getMmsMessage(@NonNull MmsDatabase mmsDatabase, long messageId) {
|
|
||||||
try (Cursor cursor = mmsDatabase.getMessage(messageId)) {
|
|
||||||
return Optional.fromNullable((MmsMessageRecord) mmsDatabase.readerFor(cursor).getNext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@WorkerThread
|
|
||||||
private Optional<MessageRecord> getSmsMessage(@NonNull SmsDatabase smsDatabase, long messageId) {
|
|
||||||
try (Cursor cursor = smsDatabase.getMessageCursor(messageId)) {
|
|
||||||
return Optional.fromNullable(smsDatabase.readerFor(cursor).getNext());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String readFullBody(@NonNull Context context, @NonNull Uri uri) {
|
|
||||||
try (InputStream stream = PartAuthority.getAttachmentStream(context, uri)) {
|
|
||||||
return Util.readFullyAsString(stream);
|
|
||||||
} catch (IOException e) {
|
|
||||||
Log.w(TAG, "Failed to read full text body.", e);
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback<T> {
|
|
||||||
void onComplete(T result);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,84 +0,0 @@
|
|||||||
package org.thoughtcrime.securesms.longmessage;
|
|
||||||
|
|
||||||
import android.app.Application;
|
|
||||||
import androidx.lifecycle.LiveData;
|
|
||||||
import androidx.lifecycle.MutableLiveData;
|
|
||||||
import androidx.lifecycle.ViewModel;
|
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
|
||||||
|
|
||||||
import android.database.ContentObserver;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Handler;
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.database.DatabaseContentProviders;
|
|
||||||
import org.session.libsignal.utilities.guava.Optional;
|
|
||||||
|
|
||||||
class LongMessageViewModel extends ViewModel {
|
|
||||||
|
|
||||||
private final Application application;
|
|
||||||
private final LongMessageRepository repository;
|
|
||||||
private final long messageId;
|
|
||||||
private final boolean isMms;
|
|
||||||
|
|
||||||
private final MutableLiveData<Optional<LongMessage>> message;
|
|
||||||
private final MessageObserver messageObserver;
|
|
||||||
|
|
||||||
private LongMessageViewModel(@NonNull Application application, @NonNull LongMessageRepository repository, long messageId, boolean isMms) {
|
|
||||||
this.application = application;
|
|
||||||
this.repository = repository;
|
|
||||||
this.messageId = messageId;
|
|
||||||
this.isMms = isMms;
|
|
||||||
this.message = new MutableLiveData<>();
|
|
||||||
this.messageObserver = new MessageObserver(new Handler());
|
|
||||||
|
|
||||||
repository.getMessage(application, messageId, isMms, longMessage -> {
|
|
||||||
if (longMessage.isPresent()) {
|
|
||||||
Uri uri = DatabaseContentProviders.Conversation.getUriForThread(longMessage.get().getMessageRecord().getThreadId());
|
|
||||||
application.getContentResolver().registerContentObserver(uri, true, messageObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
message.postValue(longMessage);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
LiveData<Optional<LongMessage>> getMessage() {
|
|
||||||
return message;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCleared() {
|
|
||||||
application.getContentResolver().unregisterContentObserver(messageObserver);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class MessageObserver extends ContentObserver {
|
|
||||||
MessageObserver(Handler handler) {
|
|
||||||
super(handler);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onChange(boolean selfChange) {
|
|
||||||
repository.getMessage(application, messageId, isMms, message::postValue);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static class Factory extends ViewModelProvider.NewInstanceFactory {
|
|
||||||
|
|
||||||
private final Application context;
|
|
||||||
private final LongMessageRepository repository;
|
|
||||||
private final long messageId;
|
|
||||||
private final boolean isMms;
|
|
||||||
|
|
||||||
public Factory(@NonNull Application application, @NonNull LongMessageRepository repository, long messageId, boolean isMms) {
|
|
||||||
this.context = application;
|
|
||||||
this.repository = repository;
|
|
||||||
this.messageId = messageId;
|
|
||||||
this.isMms = isMms;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @NonNull<T extends ViewModel> T create(@NonNull Class<T> modelClass) {
|
|
||||||
return modelClass.cast(new LongMessageViewModel(context, repository, messageId, isMms));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<ScrollView
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="match_parent">
|
|
||||||
|
|
||||||
<LinearLayout
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:orientation="vertical"
|
|
||||||
android:padding="16dp">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:textSize="@dimen/text_size"
|
|
||||||
android:focusable="true"
|
|
||||||
android:textColorLink="?android:textColorPrimary"
|
|
||||||
android:id="@+id/longmessage_text"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</ScrollView>
|
|
Loading…
x
Reference in New Issue
Block a user