-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
170 changed files
with
3,779 additions
and
4,439 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
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
44 changes: 0 additions & 44 deletions
44
alligator/src/main/java/me/aartikov/alligator/ActivityResult.java
This file was deleted.
Oops, something went wrong.
20 changes: 20 additions & 0 deletions
20
alligator/src/main/java/me/aartikov/alligator/ActivityResult.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,20 @@ | ||
package me.aartikov.alligator | ||
|
||
import android.app.Activity | ||
import android.content.Intent | ||
import android.net.Uri | ||
|
||
/** | ||
* Wrapper for an activity result. It contains a result code and an intent. | ||
*/ | ||
class ActivityResult(val resultCode: Int, val intent: Intent?) { | ||
|
||
val dataUri: Uri? | ||
get() = intent?.data | ||
|
||
val isOk: Boolean | ||
get() = resultCode == Activity.RESULT_OK | ||
|
||
val isCanceled: Boolean | ||
get() = resultCode == Activity.RESULT_CANCELED | ||
} |
86 changes: 0 additions & 86 deletions
86
alligator/src/main/java/me/aartikov/alligator/ActivityResultHandler.java
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
alligator/src/main/java/me/aartikov/alligator/ActivityResultHandler.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,74 @@ | ||
package me.aartikov.alligator | ||
|
||
import android.content.Intent | ||
import me.aartikov.alligator.destinations.ActivityDestination | ||
import me.aartikov.alligator.helpers.ScreenResultHelper | ||
import me.aartikov.alligator.listeners.ScreenResultListener | ||
import me.aartikov.alligator.navigationfactories.NavigationFactory | ||
|
||
/** | ||
* Helper class for handling a screen result. | ||
*/ | ||
class ActivityResultHandler internal constructor(private val mNavigationFactory: NavigationFactory) { | ||
|
||
private var mScreenResultListener: ScreenResultListener? = null | ||
private var mPendingScreenResultPair: ScreenResultPair? = null | ||
|
||
fun setScreenResultListener(screenResultListener: ScreenResultListener) { | ||
mScreenResultListener = screenResultListener | ||
handlePendingScreenResult() | ||
} | ||
|
||
fun resetScreenResultListener() { | ||
mScreenResultListener = null | ||
} | ||
|
||
/** | ||
* Handles activity result. This method should be called from `onActivityResult` of an activity. | ||
* | ||
* @param requestCode requestCode passed to `onActivityResult` | ||
* @param resultCode resultCode passed to `onActivityResult` | ||
* @param data intent passed to `onActivityResult` | ||
*/ | ||
fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | ||
val screenClass = mNavigationFactory.getScreenClass(requestCode) | ||
if (screenClass != null) { | ||
val destination = mNavigationFactory.getDestination(screenClass) | ||
if (destination is ActivityDestination) { | ||
val screenResult = destination.getScreenResult(ActivityResult(resultCode, data)) | ||
if (mPendingScreenResultPair == null || mPendingScreenResultPair!!.mScreenResult == null) { | ||
mPendingScreenResultPair = ScreenResultPair(screenClass, screenResult) | ||
} | ||
handlePendingScreenResult() | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Handles activity result. This method should be called from `onNewIntent` of an activity. | ||
* | ||
* @param intent intent passed to `onNewIntent` | ||
*/ | ||
fun onNewIntent(intent: Intent) { | ||
val requestCode = intent.getIntExtra(ScreenResultHelper.KEY_REQUEST_CODE, -1) | ||
if (requestCode != -1) { | ||
val resultCode = intent.getIntExtra(ScreenResultHelper.KEY_RESULT_CODE, 0) | ||
onActivityResult(requestCode, resultCode, intent) | ||
} | ||
} | ||
|
||
private fun handlePendingScreenResult() { | ||
if (mScreenResultListener != null && mPendingScreenResultPair != null) { | ||
mScreenResultListener!!.onScreenResult( | ||
mPendingScreenResultPair!!.mScreenClass, | ||
mPendingScreenResultPair!!.mScreenResult | ||
) | ||
mPendingScreenResultPair = null | ||
} | ||
} | ||
|
||
private inner class ScreenResultPair( | ||
val mScreenClass: Class<out Screen>, | ||
val mScreenResult: ScreenResult? | ||
) | ||
} |
Oops, something went wrong.