Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
aartikov committed Jan 9, 2024
2 parents a66bd3e + 94ccecf commit 9637eb9
Show file tree
Hide file tree
Showing 170 changed files with 3,779 additions and 4,439 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ captures/
/.idea/gradle.xml
/.idea/compiler.xml
/.idea/jarRepositories.xml
/.idea/kotlinc.xml

# Keystore files
*.jks
52 changes: 26 additions & 26 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion alligator-compiler/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apply plugin: 'java'
apply plugin: 'maven-publish'

group = 'com.github.aartikov'
version = '4.3.0'
version = '4.4.0'

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class NavigationFactoryGenerator {
private static final String CLASS_NAME = "GeneratedNavigationFactory";
private static final String SUPERCLASS_NAME = "RegistryNavigationFactory";

private ProcessingUtils utils;
private final ProcessingUtils utils;

public NavigationFactoryGenerator(ProcessingUtils utils) {
this.utils = utils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import javax.lang.model.element.Element;

public class ProcessingException extends Exception {
private Element element;
private final Element element;

public ProcessingException(Element element, String message, Object... args) {
super(String.format(message, args));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import javax.lang.model.util.Types;

public class ProcessingUtils {
private Types typeUtils;
private final Types typeUtils;

public ProcessingUtils(ProcessingEnvironment processingEnv) {
typeUtils = processingEnv.getTypeUtils();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
import javax.lang.model.element.TypeElement;

public class RegistrationAnnotatedClass {
private TypeElement classElement;
private ScreenType screenType;
private String screenClassName;
private String screenResultClassName;
private final TypeElement classElement;
private final ScreenType screenType;
private final String screenClassName;
private final String screenResultClassName;

public RegistrationAnnotatedClass(TypeElement classElement, ScreenType screenType, String screenClassName, String screenResultClassName) {
this.classElement = classElement;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import me.aartikov.alligator.annotations.RegisterScreen;

public class RegistrationAnnotatedClassCreator {
private ProcessingUtils utils;
private final ProcessingUtils utils;

public RegistrationAnnotatedClassCreator(ProcessingUtils utils) {
this.utils = utils;
Expand Down
11 changes: 8 additions & 3 deletions alligator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
apply plugin: 'com.android.library'
apply plugin: 'maven-publish'
apply plugin: 'kotlin-android'

group = 'com.github.aartikov'
version = '4.3.0'
version = '4.4.0'

android {
compileSdk 34
Expand All @@ -14,8 +15,11 @@ android {
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
}

publishing {
Expand All @@ -29,6 +33,7 @@ android {
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.21"
}

afterEvaluate {
Expand Down
44 changes: 0 additions & 44 deletions alligator/src/main/java/me/aartikov/alligator/ActivityResult.java

This file was deleted.

20 changes: 20 additions & 0 deletions alligator/src/main/java/me/aartikov/alligator/ActivityResult.kt
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
}

This file was deleted.

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?
)
}
Loading

0 comments on commit 9637eb9

Please sign in to comment.