-
Notifications
You must be signed in to change notification settings - Fork 344
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace InlineActivityResult with ActivityResultContract
- Loading branch information
1 parent
2a558b3
commit 071dccf
Showing
5 changed files
with
63 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/InlineActivityResult.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.github.dhaval2404.imagepicker.util | ||
|
||
import android.content.Intent | ||
import androidx.activity.result.ActivityResult | ||
import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.fragment.app.Fragment | ||
|
||
/** | ||
* Inline Activity Result | ||
* | ||
* @author Dhaval Patel | ||
* @version 2.0 | ||
* @since 29 April 2020 | ||
*/ | ||
fun AppCompatActivity.startActivityForResult( | ||
intent: Intent, | ||
listener: (Int, Intent?) -> Unit? | ||
) { | ||
registerForActivityResult(StartActivityForResult()) { result: ActivityResult -> | ||
listener.invoke(result.resultCode, result.data) | ||
}.launch(intent) | ||
} | ||
|
||
fun Fragment.startActivityForResult(intent: Intent, listener: (Int, Intent?) -> Unit?) { | ||
registerForActivityResult(StartActivityForResult()) { result: ActivityResult -> | ||
listener.invoke(result.resultCode, result.data) | ||
}.launch(intent) | ||
} |