Skip to content

Commit

Permalink
Merge branch 'fix/3.1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tagavari committed Feb 16, 2021
2 parents e51ec94 + ba4f74f commit 0302679
Show file tree
Hide file tree
Showing 14 changed files with 110 additions and 82 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ android {
applicationId "me.tagavari.airmessage"
minSdkVersion 23
targetSdkVersion 30
versionName "3.1.1b"
versionCode 107
versionName "3.1.2"
versionCode 108

resConfigs "en", "fr", "ja"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

Expand Down Expand Up @@ -1094,7 +1093,7 @@ private void updateMessageListConversationUpdate(ReduxEventMessaging.Conversatio

//Getting and updating the conversation's preview
ConversationPreview conversationPreview = ConversationPreviewHelper.latestItemToPreview(entry.getValue());
conversationInfo.setMessagePreview(conversationPreview);
if(conversationPreview != null) conversationInfo.setMessagePreview(conversationPreview);
conversationInfo.setUnreadMessageCount(entry.getValue().size());

//Finding the index to insert the conversation
Expand Down
98 changes: 55 additions & 43 deletions app/src/main/java/me/tagavari/airmessage/activity/Messaging.java
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,6 @@ public void onCreate(Bundle savedInstanceState) {
//Setting the status bar color
PlatformHelper.updateChromeOSStatusBar(this);

//Creating the filler values
String fillerText = null;
Uri[] fillerFiles = null;

//Checking if the request is a send intent
if(Intent.ACTION_SEND.equals(getIntent().getAction()) || Intent.ACTION_SENDTO.equals(getIntent().getAction())) {
long conversationID = -1;
Expand All @@ -568,25 +564,6 @@ else if(getIntent().getDataString() != null) {
AddressHelper.normalizeAddresses(recipients);
}

//Getting the message
String message;
if(getIntent().hasExtra(Intent.EXTRA_TEXT)) message = getIntent().getStringExtra(Intent.EXTRA_TEXT);
else if(getIntent().hasExtra("sms_body")) message = getIntent().getStringExtra("sms_body");
else message = null;
fillerText = message;

//Getting the extra files
List<Uri> sendFiles = new ArrayList<>();
{
Uri data = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if(data != null) sendFiles.add(data);
else {
List<Uri> dataList = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if(dataList != null) sendFiles.addAll(dataList);
}
}
fillerFiles = sendFiles.toArray(new Uri[0]);

//Getting the view model
final long finalConversationID = conversationID;
final String[] finalRecipients = recipients;
Expand All @@ -599,6 +576,24 @@ public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
else return (T) new ActivityViewModel(getApplication(), -1);
}
}).get(ActivityViewModel.class);

if(!viewModel.fillerAssigned) {
//Getting the message
if(getIntent().hasExtra(Intent.EXTRA_TEXT)) viewModel.fillerText = getIntent().getStringExtra(Intent.EXTRA_TEXT);
else if(getIntent().hasExtra("sms_body")) viewModel.fillerText = getIntent().getStringExtra("sms_body");

//Getting the extra files
List<Uri> sendFiles = new ArrayList<>();
Uri data = getIntent().getParcelableExtra(Intent.EXTRA_STREAM);
if(data != null) sendFiles.add(data);
else {
List<Uri> dataList = getIntent().getParcelableArrayListExtra(Intent.EXTRA_STREAM);
if(dataList != null) sendFiles.addAll(dataList);
}
if(!sendFiles.isEmpty()) viewModel.fillerFiles = sendFiles.toArray(new Uri[0]);

viewModel.fillerAssigned = true;
}
} else {
//Getting the conversation ID
long conversationID = getIntent().getLongExtra(intentParamTargetID, -1);
Expand All @@ -613,13 +608,17 @@ public <T extends ViewModel> T create(@NonNull Class<T> modelClass) {
}).get(ActivityViewModel.class);

//Getting the filler data
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && getIntent().hasExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT)) fillerText = getIntent().getStringExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT); //Notification inline reply text (only supported on Android P and above)
else if(getIntent().hasExtra(intentParamDataText)) fillerText = getIntent().getStringExtra(intentParamDataText); //Shared text from activity

if(getIntent().getBooleanExtra(intentParamDataFile, false)) {
ClipData clipData = getIntent().getClipData();
fillerFiles = new Uri[clipData.getItemCount()];
for(int i = 0; i < clipData.getItemCount(); i++) fillerFiles[i] = clipData.getItemAt(i).getUri();
if(!viewModel.fillerAssigned) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && getIntent().hasExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT)) viewModel.fillerText = getIntent().getStringExtra(Notification.EXTRA_REMOTE_INPUT_DRAFT); //Notification inline reply text (only supported on Android P and above)
else if(getIntent().hasExtra(intentParamDataText)) viewModel.fillerText = getIntent().getStringExtra(intentParamDataText); //Shared text from activity

if(getIntent().getBooleanExtra(intentParamDataFile, false)) {
ClipData clipData = getIntent().getClipData();
viewModel.fillerFiles = new Uri[clipData.getItemCount()];
for(int i = 0; i < clipData.getItemCount(); i++) viewModel.fillerFiles[i] = clipData.getItemAt(i).getUri();
}

viewModel.fillerAssigned = true;
}
}

Expand Down Expand Up @@ -692,10 +691,6 @@ public void getOutline(View view, Outline outline) {
listAttachmentQueue.setClipToOutline(true);
}

//Setting the filler data
if(fillerText != null) messageInputField.setText(fillerText);
if(fillerFiles != null) queueURIs(fillerFiles);

//Creating the info bars
infoBarConnection = pluginMessageBar.create(R.drawable.disconnection, null);

Expand Down Expand Up @@ -842,20 +837,31 @@ private void updateUI(int state) {
//Setting the message input field hint
messageInputField.setHint(getMessageFieldPlaceholder());

//Checking if there are drafts files saved in the conversation
if(!viewModel.conversationInfo.getDraftFiles().isEmpty()) {
if(!viewModel.inputDataRestored) {
//Applying filler data
if(viewModel.fillerText != null) {
messageInputField.setText(viewModel.fillerText);
viewModel.fillerText = null;
} else {
messageInputField.setText(viewModel.conversationInfo.getDraftMessage());
}
if(viewModel.fillerFiles != null) {
queueURIs(viewModel.fillerFiles);
viewModel.fillerFiles = null;
}

viewModel.inputDataRestored = true;
}

//Checking if there are queued files
if(!viewModel.queueList.isEmpty()) {
//Showing the file queue
showFileQueue(false);

//Updating the send button
updateSendButton(false);
}

//Restoring the draft message
if(messageInputField.getText().length() == 0) {
messageInputField.setText(viewModel.conversationInfo.getDraftMessage());
}

//Setting the last message count
viewModel.lastUnreadCount = viewModel.conversationInfo.getUnreadMessageCount();

Expand Down Expand Up @@ -2333,7 +2339,6 @@ public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int
View view = getLayoutInflater().inflate(R.layout.listitem_loading, parent, false);
CircularProgressIndicator progressIndicator = view.findViewById(R.id.progressbar);
progressIndicator.setIndicatorColor(getUIColor());
progressIndicator.setTrackColor(getUIColor());
return new LoadingViewHolder(view);
}
case itemTypeConversationActions: {
Expand Down Expand Up @@ -3199,6 +3204,7 @@ private void bindMessageAttachmentCommon(VHMessageStructure viewHolderStructure,
//Showing the open view
setAttachmentView(viewHolder, viewHolder.groupOpen);
viewHolder.labelOpen.setText(component.getFileName());
viewHolder.labelOpen.setMaxWidth(WindowHelper.getMaxMessageWidth(getResources()));
viewHolder.itemView.setOnClickListener(view -> IntentHelper.openAttachmentFile(Messaging.this, component.getFile(), component.getContentType()));

//Setting up the content view
Expand Down Expand Up @@ -3518,7 +3524,7 @@ private void bindMessagePreviewLink(VHMessageComponentText componentViewHolder,
viewHolder.imageHeader.setVisibility(View.GONE);
} else {
viewHolder.imageHeader.setVisibility(View.VISIBLE);
Glide.with(Messaging.this).load(data).into(viewHolder.imageHeader);
if(!isDestroyed()) Glide.with(Messaging.this).load(data).into(viewHolder.imageHeader);
}

//Setting the title
Expand Down Expand Up @@ -4492,6 +4498,12 @@ private static class ActivityViewModel extends AndroidViewModel {
MessageInfo latestMessageRead, latestMessageDelivered;
private long lastConversationActionTarget = -1;

//Creating the filler values
boolean inputDataRestored = false;
boolean fillerAssigned = false;
String fillerText = null;
Uri[] fillerFiles = null;

//Creating the sound values
private final SoundPool soundPool = SoundHelper.getSoundPool();
private final int soundIDMessageIncoming = soundPool.load(getApplication(), R.raw.message_in, 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1082,8 +1082,11 @@ private void requestSyncMessages(MassRetrievalParams params) {
})
.subscribe(success -> {
//Displaying a snackbar
if(success) Snackbar.make(getView(), R.string.message_confirm_resyncmessages_started, Snackbar.LENGTH_SHORT).show();
else Snackbar.make(getView(), R.string.message_serverstatus_noconnection, Snackbar.LENGTH_LONG).show();
View view = getView();
if(view != null) {
if(success) Snackbar.make(view, R.string.message_confirm_resyncmessages_started, Snackbar.LENGTH_SHORT).show();
else Snackbar.make(view, R.string.message_serverstatus_noconnection, Snackbar.LENGTH_LONG).show();
}
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -674,14 +674,22 @@ public void onFileRequestData(short requestID, int responseIndex, byte[] data) {
FileFetchRequest fileFetchRequest = subject.getRequestData();
compositeDisposable.add(
fileFetchRequest.writeChunk(responseIndex, data).subscribe((writtenLength) -> {
subject.get().onNext(new ReduxEventAttachmentDownload.Progress(writtenLength, fileFetchRequest.getTotalLength()));
//Getting the request
RequestSubject.Publish<ReduxEventAttachmentDownload> localSubject = (RequestSubject.Publish<ReduxEventAttachmentDownload>) idRequestSubjectMap.get(requestID);
if(localSubject == null) return;

localSubject.get().onNext(new ReduxEventAttachmentDownload.Progress(writtenLength, fileFetchRequest.getTotalLength()));
}, (error) -> {
//Getting the request
RequestSubject.Publish<ReduxEventAttachmentDownload> localSubject = (RequestSubject.Publish<ReduxEventAttachmentDownload>) idRequestSubjectMap.get(requestID);
if(localSubject == null) return;

if(error instanceof IOException) {
subject.onError(new AMRequestException(AttachmentReqErrorCode.localIO));
localSubject.onError(new AMRequestException(AttachmentReqErrorCode.localIO, error));
} else if(error instanceof IllegalArgumentException) {
subject.onError(new AMRequestException(AttachmentReqErrorCode.localBadResponse));
localSubject.onError(new AMRequestException(AttachmentReqErrorCode.localBadResponse, error));
} else {
subject.onError(new AMRequestException(AttachmentReqErrorCode.unknown));
localSubject.onError(new AMRequestException(AttachmentReqErrorCode.unknown, error));
}
idRequestSubjectMap.remove(requestID);
})
Expand All @@ -698,11 +706,19 @@ public void onFileRequestComplete(short requestID) {
FileFetchRequest fileFetchRequest = subject.getRequestData();
compositeDisposable.add(
fileFetchRequest.complete(getContext()).subscribe((attachmentFile) -> {
subject.get().onNext(new ReduxEventAttachmentDownload.Complete(attachmentFile));
subject.onComplete();
//Getting the request
RequestSubject.Publish<ReduxEventAttachmentDownload> localSubject = (RequestSubject.Publish<ReduxEventAttachmentDownload>) idRequestSubjectMap.get(requestID);
if(localSubject == null) return;

localSubject.get().onNext(new ReduxEventAttachmentDownload.Complete(attachmentFile));
localSubject.onComplete();
ReduxEmitterNetwork.getMessageUpdateSubject().onNext(new ReduxEventMessaging.AttachmentFile(fileFetchRequest.getMessageID(), fileFetchRequest.getAttachmentID(), attachmentFile));
}, (error) -> {
subject.onError(new AMRequestException(AttachmentReqErrorCode.localIO));
//Getting the request
RequestSubject.Publish<ReduxEventAttachmentDownload> localSubject = (RequestSubject.Publish<ReduxEventAttachmentDownload>) idRequestSubjectMap.get(requestID);
if(localSubject == null) return;

localSubject.onError(new AMRequestException(AttachmentReqErrorCode.localIO));
idRequestSubjectMap.remove(requestID);
})
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public Single<List<ConversationInfo>> handleInitialInfo(Collection<Blocks.Conver
}
this.conversationList = conversationInfoList;
return conversationInfoList;
}).subscribeOn(requestScheduler);
}).subscribeOn(requestScheduler).observeOn(AndroidSchedulers.mainThread());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2301,6 +2301,7 @@ public <A> GhostMergeResult<A> tryMergeMessageIntoGhost(long conversationID, Lis
* @param conversationItem The conversation item to add
* @return A result containing created, updated and deleted messages
*/
@Nullable
public ReplaceInsertResult mergeOrWriteConversationItem(Context context, long conversationID, Blocks.ConversationItem conversationItem) {
//Getting the database
SQLiteDatabase database = getWritableDatabase();
Expand Down Expand Up @@ -2419,6 +2420,7 @@ public ReplaceInsertResult mergeOrWriteConversationItem(Context context, long co

//Adding the conversation item normally
ConversationItem addedItem = addConversationStruct(context, conversationID, conversationItem);
if(addedItem == null) return null;
return new ReplaceInsertResult(addedItem, Collections.singletonList(addedItem), Collections.emptyList(), Collections.emptyList());
}

Expand Down Expand Up @@ -2637,6 +2639,7 @@ public List<A> getNewAttachments() {
* @param conversationItem The message to add
* @return A completed conversation item
*/
@Nullable
public ConversationItem addConversationStruct(Context context, long conversationID, Blocks.ConversationItem conversationItem) {
//Getting the database
SQLiteDatabase database = getWritableDatabase();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,6 @@ public static Single<String> buildMemberTitle(Context context, List<MemberInfo>
*/
@CheckReturnValue
public static Single<Bitmap> generateShortcutIcon(Context context, ConversationInfo conversationInfo) {
//Returning if the conversation has no members
if(conversationInfo.getMembers().isEmpty()) {
return Single.error(new Throwable("No members available"));
}

//if(true) return MainApplication.getInstance().getUserCacheHelper().getUserInfo(context, conversationInfo.getMembers().get(0).getAddress()).flatMap(user -> BitmapHelper.loadBitmap(context, ContactHelper.getContactImageURI(user.getContactID())));

//Rendering and returning the view
ArrayList<MemberInfo> memberInfos = new ArrayList<>(conversationInfo.getMembers());
return Observable.fromIterable(memberInfos)
Expand All @@ -112,7 +105,7 @@ public static Single<Bitmap> generateShortcutIcon(Context context, ConversationI
.flatMap(userInfo -> BitmapHelper.loadBitmap(context, ContactHelper.getContactImageURI(userInfo.getContactID()), true).map(Union::<Integer, Bitmap>ofB))
.onErrorReturnItem(Union.<Integer, Bitmap>ofA(member.getColor()))
)
.toList()
.toList(memberInfos.size())
.map(contactDataList -> {
//Calculating layer sizes
int layerSizeOuter = ResourceHelper.dpToPx(108);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,7 @@ public static Single<Pair<ConversationInfo, MessageInfo>> updateTextConversation
* @return A single for a pair of the new conversation and message
*/
private static Single<MessageInfo> updateTextConversationMessage(ConversationInfo conversationInfo, boolean conversationIsNew, MessageInfo newMessage) {
//Triplet<Boolean: whether the conversation is freshly created, ConversationInfo: the conversation for the message, List<ConversationItem>: a list of newly added messages>
return Single.create((SingleEmitter<MessageInfo> emitter) -> {
return Single.fromCallable(() -> {
//Writing the message to the database
long messageID = DatabaseManager.getInstance().addConversationItem(conversationInfo.getLocalID(), newMessage, conversationInfo.getServiceHandler() == ServiceHandler.appleBridge);
if(messageID == -1) throw new Exception("Failed to add message to database");
Expand All @@ -241,7 +240,7 @@ private static Single<MessageInfo> updateTextConversationMessage(ConversationInf
MessageInfo localMessage = newMessage.clone();
localMessage.setLocalID(messageID);

emitter.onSuccess(localMessage);
return localMessage;
}).subscribeOn(Schedulers.single()).observeOn(AndroidSchedulers.mainThread()).flatMap(messageInfo -> {
//Getting the values
if(conversationIsNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.SingleEmitter;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.schedulers.Schedulers;
import me.tagavari.airmessage.activity.Messaging;
import me.tagavari.airmessage.connection.ConnectionManager;
import me.tagavari.airmessage.connection.exception.AMRequestException;
import me.tagavari.airmessage.constants.RegexConstants;
Expand Down Expand Up @@ -178,7 +175,13 @@ public static Completable sendMessage(Context context, ConversationInfo conversa
if(connectionManager != null) {
//Send the messages over the connection
return sendMessageAMBridge(conversationInfo, message, connectionManager)
.onErrorReturn(error -> new Pair<>(message, (AMRequestException) error));
.onErrorReturn(error -> {
if(error instanceof AMRequestException) {
return new Pair<>(message, (AMRequestException) error);
} else {
return new Pair<>(message, new AMRequestException(MessageSendErrorCode.localUnknown, error));
}
});
} else {
//Fail immediately
return Maybe.just(new Pair<>(message, new AMRequestException(MessageSendErrorCode.localNetwork)));
Expand All @@ -200,7 +203,7 @@ public static Completable sendMessage(Context context, ConversationInfo conversa
* @param conversationInfo The message's conversation
* @param messageInfo The message to send
* @param connectionManager The connection manager to use (or NULL if unavailable)
* @return A compleatble to represent this request
* @return A completable to represent this request
*/
@CheckReturnValue
public static Completable sendMessageAMBridge(ConversationInfo conversationInfo, MessageInfo messageInfo, ConnectionManager connectionManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public ConversationPreview getDynamicPreview() {
return draftPreview;
} else if(draftPreview == null) {
return messagePreview;
} if(messagePreview.getDate() > draftPreview.getDate()) {
} else if(messagePreview.getDate() > draftPreview.getDate()) {
return messagePreview;
} else {
return draftPreview;
Expand Down
Loading

0 comments on commit 0302679

Please sign in to comment.