Skip to content

Commit 3c73ef5

Browse files
committed
Merge branch 'develop'
2 parents d1cbcdf + 5f15504 commit 3c73ef5

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

app/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ android {
5252
applicationId "me.tagavari.airmessage"
5353
minSdkVersion 23
5454
targetSdkVersion 31
55-
versionName "3.4.0"
56-
versionCode 133
55+
versionName "3.4.1"
56+
versionCode 134
5757

5858
resConfigs "en", "fr", "ja"
5959

app/src/main/java/me/tagavari/airmessage/fragment/FragmentMessagingAttachments.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import android.content.ContentUris;
1212
import android.content.Context;
1313
import android.content.Intent;
14-
import android.content.IntentSender;
1514
import android.content.pm.PackageManager;
1615
import android.database.Cursor;
1716
import android.database.sqlite.SQLiteException;
@@ -38,6 +37,7 @@
3837
import androidx.annotation.NonNull;
3938
import androidx.annotation.Nullable;
4039
import androidx.cardview.widget.CardView;
40+
import androidx.core.content.ContextCompat;
4141
import androidx.core.content.FileProvider;
4242
import androidx.lifecycle.AndroidViewModel;
4343
import androidx.lifecycle.MutableLiveData;
@@ -172,6 +172,14 @@ public Intent createIntent(@NonNull Context context, @NonNull Uri input) {
172172
.putExtra(MediaStore.EXTRA_VIDEO_QUALITY, 0);
173173
}
174174
}, cameraResultCallback);
175+
176+
private Runnable cameraPermissionsCallback = null;
177+
private final ActivityResultLauncher<String> requestCameraPermissionLauncher = registerForActivityResult(new ActivityResultContracts.RequestPermission(), granted -> {
178+
if(granted && cameraPermissionsCallback != null) {
179+
cameraPermissionsCallback.run();
180+
}
181+
});
182+
175183
private final ActivityResultLauncher<Intent> mediaSelectorLauncher = registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
176184
if(result.getResultCode() != Activity.RESULT_OK) return;
177185

@@ -688,6 +696,13 @@ private void setSystemPickerBubbleState(CardView view, boolean bubble, int tileS
688696
* @param video Whether to capture a video instead of a picture
689697
*/
690698
private void requestCamera(boolean video) {
699+
//Check if we need permission
700+
if(ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.CAMERA) != PackageManager.PERMISSION_GRANTED) {
701+
cameraPermissionsCallback = () -> requestCamera(video);
702+
requestCameraPermissionLauncher.launch(Manifest.permission.CAMERA);
703+
return;
704+
}
705+
691706
//Finding a free file
692707
File targetFile = AttachmentStorageHelper.prepareContentFile(requireContext(), AttachmentStorageHelper.dirNameDraftPrepare, video ? FileNameConstants.videoName : FileNameConstants.pictureName);
693708
viewModel.targetFileIntent = targetFile;

app/src/main/java/me/tagavari/airmessage/util/TaskManagerLongBehavior.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import io.reactivex.rxjava3.subjects.BehaviorSubject
1010
* A helper class that manages [Observable] running tasks and caching their results in the form of a [BehaviorSubject<T>]
1111
* @param <T> The result type of this manager's tasks
1212
*/
13-
class TaskManagerLongBehavior<T> {
13+
class TaskManagerLongBehavior<T : Any> {
1414
private val requestMap = LongSparseArray<BehaviorSubject<T>>()
1515

1616
/**
@@ -22,11 +22,14 @@ class TaskManagerLongBehavior<T> {
2222
@CheckReturnValue
2323
fun run(id: Long, taskSupplier: Supplier<Observable<T>>): BehaviorSubject<T> {
2424
//If we already have a request with a matching key, return that
25-
var subject = requestMap[id]
26-
if(subject != null && subject.throwable == null) return subject
25+
requestMap[id]?.let { subject ->
26+
if(subject.throwable != null) {
27+
return subject
28+
}
29+
}
2730

2831
//Otherwise, create a new request
29-
subject = BehaviorSubject.create()
32+
val subject = BehaviorSubject.create<T>()
3033
requestMap.put(id, subject)
3134
taskSupplier.get().subscribe(subject)
3235
return subject

0 commit comments

Comments
 (0)