Skip to content

Commit

Permalink
Merge pull request #1504 from oxen-io/release-1.18.4
Browse files Browse the repository at this point in the history
Merge release-1.18.4 to master
  • Loading branch information
bemusementpark authored May 31, 2024
2 parents 455a1ed + 9b6fa0d commit b544961
Show file tree
Hide file tree
Showing 32 changed files with 632 additions and 406 deletions.
16 changes: 14 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ configurations.all {
exclude module: "commons-logging"
}

def canonicalVersionCode = 372
def canonicalVersionName = "1.18.3"
def canonicalVersionCode = 373
def canonicalVersionName = "1.18.4"

def postFixSize = 10
def abiPostFix = ['armeabi-v7a' : 1,
Expand All @@ -41,6 +41,17 @@ def abiPostFix = ['armeabi-v7a' : 1,
'x86_64' : 4,
'universal' : 5]

// Function to get the current git commit hash so we can embed it along w/ the build version.
// Note: This is visible in the SettingsActivity, right at the bottom (R.id.versionTextView).
def getGitHash = { ->
def stdout = new ByteArrayOutputStream()
exec {
commandLine "git", "rev-parse", "--short", "HEAD"
standardOutput = stdout
}
return stdout.toString().trim()
}

android {
compileSdkVersion androidCompileSdkVersion
namespace 'network.loki.messenger'
Expand Down Expand Up @@ -94,6 +105,7 @@ android {
project.ext.set("archivesBaseName", "session")

buildConfigField "long", "BUILD_TIMESTAMP", getLastCommitTimestamp() + "L"
buildConfigField "String", "GIT_HASH", "\"$getGitHash\""
buildConfigField "String", "CONTENT_PROXY_HOST", "\"contentproxy.signal.org\""
buildConfigField "int", "CONTENT_PROXY_PORT", "443"
buildConfigField "String", "USER_AGENT", "\"OWA\""
Expand Down
104 changes: 45 additions & 59 deletions app/src/main/java/org/thoughtcrime/securesms/MediaPreviewActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.CursorIndexOutOfBoundsException;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
Expand Down Expand Up @@ -145,6 +146,7 @@ public class MediaPreviewActivity extends PassphraseRequiredActionBarActivity im
View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
}
};
private MediaItemAdapter adapter;

public static Intent getPreviewIntent(Context context, MediaPreviewArgs args) {
return getPreviewIntent(context, args.getSlide(), args.getMmsRecord(), args.getThread());
Expand Down Expand Up @@ -217,13 +219,6 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
Permissions.onRequestPermissionsResult(this, requestCode, permissions, grantResults);
}

@TargetApi(VERSION_CODES.JELLY_BEAN)
private void setFullscreenIfPossible() {
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}

@Override
public void onModified(Recipient recipient) {
Util.runOnMain(this::updateActionBar);
Expand Down Expand Up @@ -285,9 +280,6 @@ private void initializeViews() {
mediaPager = findViewById(R.id.media_pager);
mediaPager.setOffscreenPageLimit(1);

viewPagerListener = new ViewPagerListener();
mediaPager.addOnPageChangeListener(viewPagerListener);

albumRail = findViewById(R.id.media_preview_album_rail);
albumRailAdapter = new MediaRailAdapter(GlideApp.with(this), this, false);

Expand Down Expand Up @@ -378,7 +370,8 @@ private void initializeMedia() {
if (conversationRecipient != null) {
getSupportLoaderManager().restartLoader(0, null, this);
} else {
mediaPager.setAdapter(new SingleItemPagerAdapter(this, GlideApp.with(this), getWindow(), initialMediaUri, initialMediaType, initialMediaSize));
adapter = new SingleItemPagerAdapter(this, GlideApp.with(this), getWindow(), initialMediaUri, initialMediaType, initialMediaSize);
mediaPager.setAdapter(adapter);

if (initialCaption != null) {
detailsContainer.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -506,13 +499,8 @@ private boolean isMediaInDb() {
}

private @Nullable MediaItem getCurrentMediaItem() {
MediaItemAdapter adapter = (MediaItemAdapter)mediaPager.getAdapter();

if (adapter != null) {
return adapter.getMediaItemFor(mediaPager.getCurrentItem());
} else {
return null;
}
if (adapter == null) return null;
return adapter.getMediaItemFor(mediaPager.getCurrentItem());
}

public static boolean isContentTypeSupported(final String contentType) {
Expand All @@ -526,23 +514,28 @@ public static boolean isContentTypeSupported(final String contentType) {

@Override
public void onLoadFinished(@NonNull Loader<Pair<Cursor, Integer>> loader, @Nullable Pair<Cursor, Integer> data) {
if (data != null) {
CursorPagerAdapter adapter = new CursorPagerAdapter(this, GlideApp.with(this), getWindow(), data.first, data.second, leftIsRecent);
mediaPager.setAdapter(adapter);
adapter.setActive(true);
if (data == null) return;

viewModel.setCursor(this, data.first, leftIsRecent);
mediaPager.removeOnPageChangeListener(viewPagerListener);

if (restartItem >= 0 || data.second >= 0) {
int item = restartItem >= 0 ? restartItem : data.second;
mediaPager.setCurrentItem(item);
adapter = new CursorPagerAdapter(this, GlideApp.with(this), getWindow(), data.first, data.second, leftIsRecent);
mediaPager.setAdapter(adapter);

if (item == 0) {
viewPagerListener.onPageSelected(0);
}
} else {
Log.w(TAG, "one of restartItem "+restartItem+" and data.second "+data.second+" would cause OOB exception");
}
viewModel.setCursor(this, data.first, leftIsRecent);

int item = restartItem >= 0 && restartItem < adapter.getCount() ? restartItem : Math.max(Math.min(data.second, adapter.getCount() - 1), 0);

viewPagerListener = new ViewPagerListener();
mediaPager.addOnPageChangeListener(viewPagerListener);

try {
mediaPager.setCurrentItem(item);
} catch (CursorIndexOutOfBoundsException e) {
throw new RuntimeException("restartItem = " + restartItem + ", data.second = " + data.second + " leftIsRecent = " + leftIsRecent, e);
}

if (item == 0) {
viewPagerListener.onPageSelected(0);
}
}

Expand All @@ -560,26 +553,26 @@ public void onPageSelected(int position) {
if (currentPage != -1 && currentPage != position) onPageUnselected(currentPage);
currentPage = position;

MediaItemAdapter adapter = (MediaItemAdapter)mediaPager.getAdapter();
if (adapter == null) return;

if (adapter != null) {
MediaItem item = adapter.getMediaItemFor(position);
if (item.recipient != null) item.recipient.addListener(MediaPreviewActivity.this);
viewModel.setActiveAlbumRailItem(MediaPreviewActivity.this, position);
updateActionBar();
}
MediaItem item = adapter.getMediaItemFor(position);
if (item.recipient != null) item.recipient.addListener(MediaPreviewActivity.this);
viewModel.setActiveAlbumRailItem(MediaPreviewActivity.this, position);
updateActionBar();
}


public void onPageUnselected(int position) {
MediaItemAdapter adapter = (MediaItemAdapter)mediaPager.getAdapter();
if (adapter == null) return;

if (adapter != null) {
try {
MediaItem item = adapter.getMediaItemFor(position);
if (item.recipient != null) item.recipient.removeListener(MediaPreviewActivity.this);

adapter.pause(position);
} catch (CursorIndexOutOfBoundsException e) {
throw new RuntimeException("position = " + position + " leftIsRecent = " + leftIsRecent, e);
}

adapter.pause(position);
}

@Override
Expand All @@ -593,7 +586,7 @@ public void onPageScrollStateChanged(int state) {
}
}

private static class SingleItemPagerAdapter extends PagerAdapter implements MediaItemAdapter {
private static class SingleItemPagerAdapter extends MediaItemAdapter {

private final GlideRequests glideRequests;
private final Window window;
Expand Down Expand Up @@ -665,7 +658,7 @@ public void pause(int position) {
}
}

private static class CursorPagerAdapter extends PagerAdapter implements MediaItemAdapter {
private static class CursorPagerAdapter extends MediaItemAdapter {

private final WeakHashMap<Integer, MediaView> mediaViews = new WeakHashMap<>();

Expand All @@ -675,7 +668,6 @@ private static class CursorPagerAdapter extends PagerAdapter implements MediaIte
private final Cursor cursor;
private final boolean leftIsRecent;

private boolean active;
private int autoPlayPosition;

CursorPagerAdapter(@NonNull Context context, @NonNull GlideRequests glideRequests,
Expand All @@ -690,15 +682,9 @@ private static class CursorPagerAdapter extends PagerAdapter implements MediaIte
this.leftIsRecent = leftIsRecent;
}

public void setActive(boolean active) {
this.active = active;
notifyDataSetChanged();
}

@Override
public int getCount() {
if (!active) return 0;
else return cursor.getCount();
return cursor.getCount();
}

@Override
Expand Down Expand Up @@ -771,8 +757,8 @@ public void pause(int position) {
}

private int getCursorPosition(int position) {
if (leftIsRecent) return position;
else return cursor.getCount() - 1 - position;
int unclamped = leftIsRecent ? position : cursor.getCount() - 1 - position;
return Math.max(Math.min(unclamped, cursor.getCount() - 1), 0);
}
}

Expand Down Expand Up @@ -800,9 +786,9 @@ private MediaItem(@Nullable Recipient recipient,
}
}

interface MediaItemAdapter {
MediaItem getMediaItemFor(int position);
void pause(int position);
@Nullable View getPlaybackControls(int position);
abstract static class MediaItemAdapter extends PagerAdapter {
abstract MediaItem getMediaItemFor(int position);
abstract void pause(int position);
@Nullable abstract View getPlaybackControls(int position);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public AttachmentServer(Context context, Attachment attachment)
throws IOException
{
try {
this.context = context;
this.context = context.getApplicationContext();
this.attachment = attachment;
this.socket = new ServerSocket(0, 0, InetAddress.getByAddress(new byte[]{127, 0, 0, 1}));
this.port = socket.getLocalPort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ class DatabaseAttachmentProvider(context: Context, helper: SQLCipherOpenHelper)
override fun deleteMessage(messageID: Long, isSms: Boolean) {
val messagingDatabase: MessagingDatabase = if (isSms) DatabaseComponent.get(context).smsDatabase()
else DatabaseComponent.get(context).mmsDatabase()

val (threadId, timestamp) = runCatching { messagingDatabase.getMessageRecord(messageID).run { threadId to timestamp } }.getOrNull() ?: (null to null)

messagingDatabase.deleteMessage(messageID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ public void startRecording() {
Log.i(TAG, "Running startRecording() + " + Thread.currentThread().getId());
try {
if (audioCodec != null) {
throw new AssertionError("We can only record once at a time.");
Log.e(TAG, "Trying to start recording while another recording is in progress, exiting...");
return;
}

ParcelFileDescriptor fds[] = ParcelFileDescriptor.createPipe();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ class ProfilePictureView @JvmOverloads constructor(

glide.clear(imageView)

val placeholder = PlaceholderAvatarPhoto(context, publicKey, displayName ?: "${publicKey.take(4)}...${publicKey.takeLast(4)}")
val placeholder = PlaceholderAvatarPhoto(publicKey, displayName ?: "${publicKey.take(4)}...${publicKey.takeLast(4)}")

if (signalProfilePicture != null && avatar != "0" && avatar != "") {
glide.load(signalProfilePicture)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,10 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
if (hexEncodedSeed == null) {
hexEncodedSeed = IdentityKeyUtil.getIdentityKeyPair(this).hexEncodedPrivateKey // Legacy account
}

val appContext = applicationContext
val loadFileContents: (String) -> String = { fileName ->
MnemonicUtilities.loadFileContents(this, fileName)
MnemonicUtilities.loadFileContents(appContext, fileName)
}
MnemonicCodec(loadFileContents).encode(hexEncodedSeed!!, MnemonicCodec.Language.Configuration.english)
}
Expand Down Expand Up @@ -359,7 +361,6 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
private var currentLastVisibleRecyclerViewIndex: Int = RecyclerView.NO_POSITION
private var recyclerScrollState: Int = RecyclerView.SCROLL_STATE_IDLE


// region Settings
companion object {
// Extras
Expand Down Expand Up @@ -571,7 +572,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
binding!!.conversationRecyclerView.layoutManager = layoutManager
// Workaround for the fact that CursorRecyclerViewAdapter doesn't auto-update automatically (even though it says it will)
LoaderManager.getInstance(this).restartLoader(0, null, this)
binding!!.conversationRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {
binding!!.conversationRecyclerView.addOnScrollListener(object : RecyclerView.OnScrollListener() {

override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) {
// The unreadCount check is to prevent us scrolling to the bottom when we first enter a conversation
Expand Down Expand Up @@ -832,6 +833,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe

override fun onDestroy() {
viewModel.saveDraft(binding?.inputBar?.text?.trim() ?: "")
cancelVoiceMessage()
tearDownRecipientObserver()
super.onDestroy()
binding = null
Expand Down Expand Up @@ -1020,7 +1022,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
}

override fun showVoiceMessageUI() {
binding?.inputBarRecordingView?.show()
binding?.inputBarRecordingView?.show(lifecycleScope)
binding?.inputBar?.alpha = 0.0f
val animation = ValueAnimator.ofObject(FloatEvaluator(), 1.0f, 0.0f)
animation.duration = 250L
Expand Down Expand Up @@ -1884,7 +1886,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity(), InputBarDe
Log.w("ConversationActivityV2", "Asked to delete messages but could not obtain viewModel recipient - aborting.")
return
}

val allSentByCurrentUser = messages.all { it.isOutgoing }
val allHasHash = messages.all { lokiMessageDb.getMessageServerHash(it.id, it.isMms) != null }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ import kotlinx.coroutines.launch
import network.loki.messenger.R
import network.loki.messenger.databinding.ViewVisibleMessageBinding
import org.session.libsession.messaging.contacts.Contact
import org.session.libsession.utilities.TextSecurePreferences
import org.thoughtcrime.securesms.conversation.v2.messages.ControlMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageView
import org.thoughtcrime.securesms.conversation.v2.messages.VisibleMessageViewDelegate
import org.thoughtcrime.securesms.database.CursorRecyclerViewAdapter
import org.thoughtcrime.securesms.database.MmsSmsColumns
import org.thoughtcrime.securesms.database.model.MessageRecord
import org.thoughtcrime.securesms.dependencies.DatabaseComponent
import org.thoughtcrime.securesms.mms.GlideRequests
Expand Down Expand Up @@ -57,6 +59,7 @@ class ConversationAdapter(
private val contactCache = SparseArray<Contact>(100)
private val contactLoadedCache = SparseBooleanArray(100)
private val lastSeen = AtomicLong(originalLastSeen)
private var lastSentMessageId: Long = -1L

init {
lifecycleCoroutineScope.launch(IO) {
Expand Down Expand Up @@ -136,7 +139,8 @@ class ConversationAdapter(
senderId,
lastSeen.get(),
visibleMessageViewDelegate,
onAttachmentNeedsDownload
onAttachmentNeedsDownload,
lastSentMessageId
)

if (!message.isDeleted) {
Expand Down
Loading

0 comments on commit b544961

Please sign in to comment.