mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-30 13:35:18 +00:00
Implement message status bar
This commit is contained in:
parent
eda21064a4
commit
f4360bddc7
@ -72,6 +72,19 @@
|
||||
android:orientation="vertical"
|
||||
android:paddingTop="?attr/actionBarSize">
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/messageStatusProgressBar"
|
||||
style="?android:attr/progressBarStyleHorizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/accent_line_thickness"
|
||||
android:paddingLeft="-2dp"
|
||||
android:paddingRight="-2dp"
|
||||
android:progressTint="@color/accent"
|
||||
android:progressBackgroundTint="@color/transparent"
|
||||
android:alpha="0"
|
||||
android:indeterminate="false"
|
||||
android:progress="80" />
|
||||
|
||||
<ViewStub
|
||||
android:id="@+id/group_share_profile_view_stub"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -3,7 +3,7 @@
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:background="@drawable/default_session_background"
|
||||
android:background="@color/transparent"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
tools:visibility="visible"
|
||||
android:text="@string/message_details_header__issues_need_your_attention"
|
||||
android:drawableStart="@drawable/ic_error"
|
||||
android:gravity="center_vertical" />
|
||||
android:layout_gravity="center_vertical" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/resend_button"
|
||||
|
@ -73,6 +73,7 @@ import org.thoughtcrime.securesms.loki.LokiRSSFeedPoller;
|
||||
import org.thoughtcrime.securesms.loki.LokiUserDatabase;
|
||||
import org.thoughtcrime.securesms.loki.MultiDeviceUtilities;
|
||||
import org.thoughtcrime.securesms.loki.redesign.activities.HomeActivity;
|
||||
import org.thoughtcrime.securesms.loki.redesign.utilities.Broadcaster;
|
||||
import org.thoughtcrime.securesms.notifications.MessageNotifier;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.providers.BlobProvider;
|
||||
@ -151,6 +152,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
private LokiRSSFeedPoller lokiMessengerUpdatesFeedPoller = null;
|
||||
private LokiPublicChatManager lokiPublicChatManager = null;
|
||||
private LokiPublicChatAPI lokiPublicChatAPI = null;
|
||||
public Broadcaster broadcaster = null;
|
||||
public SignalCommunicationModule communicationModule;
|
||||
public MixpanelAPI mixpanel;
|
||||
|
||||
@ -164,6 +166,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
Log.i(TAG, "onCreate()");
|
||||
broadcaster = new Broadcaster(this);
|
||||
checkNeedsDatabaseReset();
|
||||
startKovenant();
|
||||
initializeSecurityProvider();
|
||||
@ -504,7 +507,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
||||
if (userHexEncodedPublicKey == null) return;
|
||||
LokiAPIDatabase lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(this);
|
||||
Context context = this;
|
||||
lokiLongPoller = new LokiLongPoller(userHexEncodedPublicKey, lokiAPIDatabase, protos -> {
|
||||
lokiLongPoller = new LokiLongPoller(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster, protos -> {
|
||||
for (SignalServiceProtos.Envelope proto : protos) {
|
||||
new PushContentReceiveJob(context).processEnvelope(new SignalServiceEnvelope(proto));
|
||||
}
|
||||
|
@ -160,7 +160,7 @@ public class MessageDetailsActivity extends PassphraseRequiredActionBarActivity
|
||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(color.toStatusBarColor(this));
|
||||
// getWindow().setStatusBarColor(color.toStatusBarColor(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,11 +38,13 @@ import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Vibrator;
|
||||
import android.provider.Browser;
|
||||
import android.provider.Telephony;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v4.content.pm.ShortcutInfoCompat;
|
||||
import android.support.v4.content.pm.ShortcutManagerCompat;
|
||||
import android.support.v4.graphics.drawable.IconCompat;
|
||||
@ -68,6 +70,7 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@ -316,6 +319,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private MentionTextWatcher mentionTextWatcher;
|
||||
private ConversationSearchBottomBar searchNav;
|
||||
private MenuItem searchViewItem;
|
||||
private ProgressBar messageStatusProgressBar;
|
||||
private TextView actionBarSubtitleTextView;
|
||||
|
||||
private AttachmentTypeSelector attachmentTypeSelector;
|
||||
private AttachmentManager attachmentManager;
|
||||
@ -346,6 +351,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
private final DynamicNoActionBarTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
|
||||
|
||||
private ArrayList<BroadcastReceiver> broadcastReceivers = new ArrayList<>();
|
||||
private String messageStatus = null;
|
||||
|
||||
// Mentions
|
||||
private MentionCandidateSelectionView mentionCandidateSelectionView;
|
||||
private int currentMentionStartIndex = -1;
|
||||
@ -376,6 +384,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
fragment = initFragment(R.id.fragment_content, new ConversationFragment(), dynamicLanguage.getCurrentLocale());
|
||||
fragment.friendRequestViewDelegate = this;
|
||||
|
||||
registerMessageStatusObserver("calculatingPoW");
|
||||
registerMessageStatusObserver("contactingNetwork");
|
||||
registerMessageStatusObserver("sendingMessage");
|
||||
registerMessageStatusObserver("messageSent");
|
||||
registerMessageStatusObserver("messageFailed");
|
||||
|
||||
initializeReceivers();
|
||||
initializeActionBar();
|
||||
initializeViews();
|
||||
@ -438,6 +452,19 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void registerMessageStatusObserver(String status) {
|
||||
BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
long timestamp = intent.getLongExtra("long", 0);
|
||||
handleMessageStatusChanged(status, timestamp);
|
||||
}
|
||||
};
|
||||
broadcastReceivers.add(broadcastReceiver);
|
||||
LocalBroadcastManager.getInstance(this).registerReceiver(broadcastReceiver, new IntentFilter(status));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onNewIntent(Intent intent) {
|
||||
Log.i(TAG, "onNewIntent()");
|
||||
@ -533,6 +560,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
saveDraft();
|
||||
if (recipient != null) recipient.removeListener(this);
|
||||
if (securityUpdateReceiver != null) unregisterReceiver(securityUpdateReceiver);
|
||||
for (BroadcastReceiver broadcastReceiver : broadcastReceivers) {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@ -1588,6 +1618,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
inputPanel = ViewUtil.findById(this, R.id.bottom_panel);
|
||||
searchNav = ViewUtil.findById(this, R.id.conversation_search_nav);
|
||||
mentionCandidateSelectionView = ViewUtil.findById(this, R.id.userSelectionView);
|
||||
messageStatusProgressBar = ViewUtil.findById(this, R.id.messageStatusProgressBar);
|
||||
actionBarSubtitleTextView = ViewUtil.findById(this, R.id.subtitleTextView);
|
||||
|
||||
ImageButton quickCameraToggle = ViewUtil.findById(this, R.id.quick_camera_toggle);
|
||||
ImageButton inlineAttachmentButton = ViewUtil.findById(this, R.id.inline_attachment_button);
|
||||
@ -3049,11 +3081,92 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
}
|
||||
|
||||
// region Loki
|
||||
private void updateTitleTextView(GlideRequests glide, Recipient recipient) {
|
||||
|
||||
}
|
||||
|
||||
// region Loki
|
||||
private void updateSubtitleTextView() {
|
||||
if (messageStatus != null) {
|
||||
switch (messageStatus) {
|
||||
case "calculatingPoW": actionBarSubtitleTextView.setText("Encrypting message"); break;
|
||||
case "contactingNetwork": actionBarSubtitleTextView.setText("Tracing a path"); break;
|
||||
case "sendingMessage": actionBarSubtitleTextView.setText("Sending message"); break;
|
||||
case "messageSent": actionBarSubtitleTextView.setText("Message sent securely"); break;
|
||||
case "messageFailed": actionBarSubtitleTextView.setText("Message failed to send"); break;
|
||||
}
|
||||
} else {
|
||||
actionBarSubtitleTextView.setText("26 members");
|
||||
}
|
||||
}
|
||||
|
||||
private void setMessageStatusProgressAnimatedIfPossible(int progress) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
messageStatusProgressBar.setProgress(progress, true);
|
||||
} else {
|
||||
messageStatusProgressBar.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMessageStatusProgressBar() {
|
||||
if (messageStatus != null) {
|
||||
messageStatusProgressBar.setAlpha(1.0f);
|
||||
switch (messageStatus) {
|
||||
case "calculatingPoW": setMessageStatusProgressAnimatedIfPossible(25); break;
|
||||
case "contactingNetwork": setMessageStatusProgressAnimatedIfPossible(50); break;
|
||||
case "sendingMessage": setMessageStatusProgressAnimatedIfPossible(75); break;
|
||||
case "messageSent":
|
||||
setMessageStatusProgressAnimatedIfPossible(100);
|
||||
new Handler().postDelayed(() -> messageStatusProgressBar.animate().alpha(0).setDuration(250).start(), 250);
|
||||
new Handler().postDelayed(() -> messageStatusProgressBar.setProgress(0), 500);
|
||||
break;
|
||||
case "messageFailed":
|
||||
messageStatusProgressBar.animate().alpha(0).setDuration(250).start();
|
||||
new Handler().postDelayed(() -> messageStatusProgressBar.setProgress(0), 250);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void handleMessageStatusChanged(String newMessageStatus, long timestamp) {
|
||||
if (timestamp == 0) { return; }
|
||||
updateForNewMessageStatusIfNeeded(newMessageStatus, timestamp);
|
||||
if (newMessageStatus.equals("messageFailed") || newMessageStatus.equals("messageSent")) {
|
||||
new Handler().postDelayed(() -> clearMessageStatusIfNeeded(timestamp), 1000);
|
||||
}
|
||||
}
|
||||
|
||||
private int precedence(String messageStatus) {
|
||||
if (messageStatus != null) {
|
||||
switch (messageStatus) {
|
||||
case "calculatingPoW": return 0;
|
||||
case "contactingNetwork": return 1;
|
||||
case "sendingMessage": return 2;
|
||||
case "messageSent": return 3;
|
||||
case "messageFailed": return 4;
|
||||
default: return -1;
|
||||
}
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateForNewMessageStatusIfNeeded(String newMessageStatus, long timestamp) {
|
||||
if (!DatabaseFactory.getSmsDatabase(this).isOutgoingMessage(timestamp) && !DatabaseFactory.getMmsDatabase(this).isOutgoingMessage(timestamp)) { return; }
|
||||
if (precedence(newMessageStatus) > precedence(messageStatus)) {
|
||||
messageStatus = newMessageStatus;
|
||||
updateSubtitleTextView();
|
||||
updateMessageStatusProgressBar();
|
||||
}
|
||||
}
|
||||
|
||||
private void clearMessageStatusIfNeeded(long timestamp) {
|
||||
if (!DatabaseFactory.getSmsDatabase(this).isOutgoingMessage(timestamp) && !DatabaseFactory.getMmsDatabase(this).isOutgoingMessage(timestamp)) { return; }
|
||||
messageStatus = null;
|
||||
updateSubtitleTextView();
|
||||
updateMessageStatusProgressBar();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptFriendRequest(@NotNull MessageRecord friendRequest) {
|
||||
// Send the accept to the original friend request thread id
|
||||
|
@ -801,7 +801,7 @@ public class ConversationItem extends LinearLayout
|
||||
int groupThreadMargin = (int)(getResources().getDimension(R.dimen.large_spacing) + getResources().getDimension(R.dimen.small_profile_picture_size));
|
||||
int defaultMargin = 0;
|
||||
String threadName = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(messageRecord.getThreadId()).getName();
|
||||
boolean isRSSFeed = threadName.equals("Loki News") || threadName.equals("Loki Messenger Updates");
|
||||
boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Loki Messenger Updates"));
|
||||
layoutParams.setMarginStart((groupThread && !isRSSFeed) ? groupThreadMargin : defaultMargin);
|
||||
bodyBubble.setLayoutParams(layoutParams);
|
||||
if (profilePictureView == null) return;
|
||||
@ -983,7 +983,7 @@ public class ConversationItem extends LinearLayout
|
||||
|
||||
private void setAuthor(@NonNull MessageRecord current, @NonNull Optional<MessageRecord> previous, @NonNull Optional<MessageRecord> next, boolean isGroupThread) {
|
||||
String threadName = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(current.getThreadId()).getName();
|
||||
boolean isRSSFeed = threadName.equals("Loki News") || threadName.equals("Loki Messenger Updates");
|
||||
boolean isRSSFeed = threadName != null && (threadName.equals("Loki News") || threadName.equals("Loki Messenger Updates"));
|
||||
if (isGroupThread && !isRSSFeed && !current.isOutgoing()) {
|
||||
contactPhotoHolder.setVisibility(VISIBLE);
|
||||
|
||||
|
@ -236,6 +236,26 @@ public class MmsDatabase extends MessagingDatabase {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOutgoingMessage(long timestamp) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
boolean isOutgoing = false;
|
||||
|
||||
try {
|
||||
cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, MESSAGE_BOX, ADDRESS }, DATE_SENT + " = ?", new String[] { String.valueOf(timestamp) }, null, null, null, null);
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(MESSAGE_BOX)))) {
|
||||
isOutgoing = true;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null)
|
||||
cursor.close();
|
||||
}
|
||||
return isOutgoing;
|
||||
}
|
||||
|
||||
public void incrementReceiptCount(SyncMessageId messageId, long timestamp, boolean deliveryReceipt, boolean readReceipt) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
|
@ -330,6 +330,28 @@ public class SmsDatabase extends MessagingDatabase {
|
||||
database.update(TABLE_NAME, contentValues, ID_WHERE, new String[] {String.valueOf(id)});
|
||||
}
|
||||
|
||||
public boolean isOutgoingMessage(long timestamp) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
boolean isOutgoing = false;
|
||||
|
||||
try {
|
||||
cursor = database.query(TABLE_NAME, new String[] { ID, THREAD_ID, ADDRESS, TYPE },
|
||||
DATE_SENT + " = ?", new String[] { String.valueOf(timestamp) },
|
||||
null, null, null, null);
|
||||
|
||||
while (cursor.moveToNext()) {
|
||||
if (Types.isOutgoingMessageType(cursor.getLong(cursor.getColumnIndexOrThrow(TYPE)))) {
|
||||
isOutgoing = true;
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
if (cursor != null) cursor.close();
|
||||
}
|
||||
|
||||
return isOutgoing;
|
||||
}
|
||||
|
||||
public void incrementReceiptCount(SyncMessageId messageId, boolean deliveryReceipt, boolean readReceipt) {
|
||||
SQLiteDatabase database = databaseHelper.getWritableDatabase();
|
||||
Cursor cursor = null;
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.dependencies;
|
||||
import android.content.Context;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.thoughtcrime.securesms.ApplicationContext;
|
||||
import org.thoughtcrime.securesms.CreateProfileActivity;
|
||||
import org.thoughtcrime.securesms.DeviceListFragment;
|
||||
import org.thoughtcrime.securesms.crypto.storage.SignalProtocolStoreImpl;
|
||||
@ -160,7 +161,8 @@ public class SignalCommunicationModule {
|
||||
DatabaseFactory.getLokiMessageDatabase(context),
|
||||
DatabaseFactory.getLokiPreKeyBundleDatabase(context),
|
||||
new TextSecureSessionStore(context),
|
||||
DatabaseFactory.getLokiUserDatabase(context));
|
||||
DatabaseFactory.getLokiUserDatabase(context),
|
||||
((ApplicationContext)context.getApplicationContext()).broadcaster);
|
||||
} else {
|
||||
this.messageSender.setMessagePipe(IncomingMessageObserver.getPipe(), IncomingMessageObserver.getUnidentifiedPipe());
|
||||
this.messageSender.setIsMultiDevice(TextSecurePreferences.isMultiDevice(context));
|
||||
|
@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import nl.komponents.kovenant.functional.map
|
||||
import org.thoughtcrime.securesms.ApplicationContext
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory
|
||||
import org.thoughtcrime.securesms.jobs.PushContentReceiveJob
|
||||
import org.thoughtcrime.securesms.service.PersistentAlarmManagerListener
|
||||
@ -33,7 +34,7 @@ class BackgroundPollWorker : PersistentAlarmManagerListener() {
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
try {
|
||||
LokiAPI(userHexEncodedPublicKey, lokiAPIDatabase).getMessages().map { messages ->
|
||||
LokiAPI(userHexEncodedPublicKey, lokiAPIDatabase, (context.applicationContext as ApplicationContext).broadcaster).getMessages().map { messages ->
|
||||
messages.forEach {
|
||||
PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it))
|
||||
}
|
||||
|
@ -0,0 +1,14 @@
|
||||
package org.thoughtcrime.securesms.loki.redesign.utilities
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v4.content.LocalBroadcastManager
|
||||
|
||||
class Broadcaster(private val context: Context) : org.whispersystems.signalservice.loki.utilities.Broadcaster {
|
||||
|
||||
override fun broadcast(event: String, long: Long) {
|
||||
val intent = Intent(event)
|
||||
intent.putExtra("long", long)
|
||||
LocalBroadcastManager.getInstance(context).sendBroadcast(intent)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user