Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ configurations.configureEach {
exclude(module = "commons-logging")
}

val canonicalVersionCode = 420
val canonicalVersionCode = 421
val canonicalVersionName = "1.28.0"

val postFixSize = 10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,23 +350,34 @@ public static void selectGallery(Activity activity, int requestCode, @NonNull Ad
}

public static boolean hasFullAccess(Activity activity) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
return Permissions.hasAll(activity,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO);
} else {
return Permissions.hasAll(activity, android.Manifest.permission.READ_EXTERNAL_STORAGE);
}
}

public static boolean hasPartialAccess(@NonNull Context c) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE &&
Permissions.hasAll(activity,
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO);
Permissions.hasAll(c, Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED);
}

public static void managePhotoAccess(@NonNull Activity activity, @Nullable Runnable onAnyResult) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) { // API 34+
Permissions.with(activity)
.request(
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED
).onAnyResult(() -> {
if (onAnyResult != null) onAnyResult.run();
})
.execute();
if (hasPartialAccess(activity)) {
Permissions.with(activity)
.request(
Manifest.permission.READ_MEDIA_IMAGES,
Manifest.permission.READ_MEDIA_VIDEO,
Manifest.permission.READ_MEDIA_VISUAL_USER_SELECTED
)
.onAnyResult(() -> {
if (onAnyResult != null) onAnyResult.run();
})
.execute();
}
} else {
// older Android: no partial selector, send to App settings
Intent i = new Intent(android.provider.Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
Expand All @@ -375,6 +386,15 @@ public static void managePhotoAccess(@NonNull Activity activity, @Nullable Runna
}
}

public static boolean shouldShowManagePhoto(@NonNull Activity activity){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE){
return !hasFullAccess(activity) && hasPartialAccess(activity);
}else{
// No partial access for <= API 33
return false;
}
}

public static void selectAudio(Activity activity, int requestCode) {
selectMediaType(activity, "audio/*", null, requestCode);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GroupLeavingWorker @AssistedInject constructor(

if (group != null && !group.kicked && !weAreTheOnlyAdmin) {
val address = Address.fromSerialized(groupId.hexString)
val statusChannel = Channel<kotlin.Result<Unit>>()

// Always send a "XXX left" message to the group if we can
MessageSender.send(
Expand All @@ -70,12 +71,12 @@ class GroupLeavingWorker @AssistedInject constructor(
.setMemberLeftNotificationMessage(DataMessage.GroupUpdateMemberLeftNotificationMessage.getDefaultInstance())
.build()
),
address
address,
statusCallback = statusChannel,
)

// If we are not the only admin, send a left message for other admin to handle the member removal
// We'll have to wait for this message to be sent before going ahead to delete the group
val statusChannel = Channel<kotlin.Result<Unit>>()
MessageSender.send(
GroupUpdated(
GroupUpdateMessage.newBuilder()
Expand All @@ -86,7 +87,10 @@ class GroupLeavingWorker @AssistedInject constructor(
statusCallback = statusChannel
)

statusChannel.receive().getOrThrow()
// Wait for both messages to be sent
repeat(2) {
statusChannel.receive().getOrThrow()
}
}

// If we are the only admin, leaving this group will destroy the group
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class MediaPickerFolderFragment extends Fragment implements MediaPickerFo

MediaPickerFolderAdapter adapter;

private MenuProvider manageMenuProvider;

public static @NonNull MediaPickerFolderFragment newInstance(@NonNull Recipient recipient) {
Bundle args = new Bundle();
Expand Down Expand Up @@ -133,9 +134,20 @@ private void initToolbar(Toolbar toolbar) {
toolbar.setNavigationOnClickListener(v -> requireActivity().onBackPressed());
}

if(!AttachmentManager.hasFullAccess(requireActivity())){
MenuHost menuHost = (MenuHost) requireActivity();
menuHost.addMenuProvider(new MenuProvider() {
initToolbarOptions();
}

private void initToolbarOptions() {
MenuHost menuHost = (MenuHost) requireActivity();

// Always remove current provider first (if any)
if (manageMenuProvider != null) {
menuHost.removeMenuProvider(manageMenuProvider);
manageMenuProvider = null;
}

if (AttachmentManager.shouldShowManagePhoto(requireActivity())) {
manageMenuProvider = new MenuProvider() {
@Override
public void onCreateMenu(@NonNull Menu menu, @NonNull MenuInflater inflater) {
inflater.inflate(R.menu.menu_media_add, menu);
Expand All @@ -146,14 +158,19 @@ public boolean onMenuItemSelected(@NonNull MenuItem item) {
if (item.getItemId() == R.id.mediapicker_menu_add) {
AttachmentManager.managePhotoAccess(requireActivity(), () -> {
if (!isAdded()) return;

viewModel.getFolders(requireContext())
.observe(getViewLifecycleOwner(), adapter::setFolders);

initToolbarOptions();
});
return true;
}
return false;
}
}, getViewLifecycleOwner(), Lifecycle.State.STARTED);
};

menuHost.addMenuProvider(manageMenuProvider, getViewLifecycleOwner(), Lifecycle.State.STARTED);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ class SettingsViewModel @Inject constructor(
}

viewModelScope.launch {
OnionRequestAPI.hasPath.collect {
_uiState.update { it.copy(hasPath = it.hasPath) }
OnionRequestAPI.hasPath.collect { data ->
_uiState.update { it.copy(hasPath = data) }
}
}

Expand Down