Search in sources :

Example 1 with KaptLibraryDeepLinkModuleRegistry

use of com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry in project DeepLinkDispatch by airbnb.

the class TypeConversionErrorHandlerCustomTypeDeepLinkActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    typeConverters = new TypeConverters();
    typeConverters.put(ComparableColorDrawable.class, value -> {
        switch(value.toLowerCase()) {
            case "red":
                return new ComparableColorDrawable(0xff0000ff);
            case "green":
                return new ComparableColorDrawable(0x00ff00ff);
            case "blue":
                return new ComparableColorDrawable(0x000ffff);
            default:
                return new ComparableColorDrawable(0xffffffff);
        }
    });
    try {
        // Not very elegant reflection way to get the right type to add to the mapper.
        typeConverters.put(TypeConversionErrorHandlerCustomTypeDeepLinkActivity.class.getDeclaredField("stringList").getGenericType(), value -> Arrays.asList(value.split(",")));
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    }
    Function3<DeepLinkUri, Type, ? super String, Integer> typeConversionErrorNullable = (Function3<DeepLinkUri, Type, String, Integer>) (uriTemplate, type, s) -> {
        Log.e(TAG, "Unable to convert " + s + " used in urlTemplate " + uriTemplate + " to a " + type + ". Returning null.");
        throw new NumberFormatException("For input string: \"" + s + "\"");
    };
    Function3<DeepLinkUri, Type, ? super String, Integer> typeConversionErrorNonNullable = (Function3<DeepLinkUri, Type, String, Integer>) (uriTemplate, type, s) -> {
        Log.e(TAG, "Unable to convert " + s + " used in urlTemplate " + uriTemplate + " to a " + type + ". Returning 0.");
        throw new NumberFormatException("For input string: \"" + s + "\"");
    };
    Function0<TypeConverters> typeConvertersLambda = () -> typeConverters;
    super.onCreate(savedInstanceState);
    Map configurablePlaceholdersMap = new HashMap();
    configurablePlaceholdersMap.put("configPathOne", "somePathThree");
    configurablePlaceholdersMap.put("configurable-path-segment-one", "");
    configurablePlaceholdersMap.put("configurable-path-segment", "");
    configurablePlaceholdersMap.put("configurable-path-segment-two", "");
    configurablePlaceholdersMap.put("configPathOne", "somePathOne");
    DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(), new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), new KaptLibraryDeepLinkModuleRegistry(), configurablePlaceholdersMap, typeConvertersLambda, typeConversionErrorNullable, typeConversionErrorNonNullable);
    deepLinkDelegate.dispatchFrom(this);
    finish();
}
Also used : SampleModuleRegistry(com.airbnb.deeplinkdispatch.sample.SampleModuleRegistry) DeepLinkUri(com.airbnb.deeplinkdispatch.DeepLinkUri) HashMap(java.util.HashMap) Function3(kotlin.jvm.functions.Function3) BenchmarkDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry) TypeConverters(com.airbnb.deeplinkdispatch.handler.TypeConverters) Type(java.lang.reflect.Type) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) LibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with KaptLibraryDeepLinkModuleRegistry

use of com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry in project DeepLinkDispatch by airbnb.

the class MainActivityTest method testTwoConfigurablePathSegmentsMatch.

@Test
public void testTwoConfigurablePathSegmentsMatch() {
    Map<String, String> configurablePathSegmentReplacements = new HashMap<>();
    configurablePathSegmentReplacements.put("configurable-path-segment", "obamaOs");
    configurablePathSegmentReplacements.put("configurable-path-segment-one", "belong");
    configurablePathSegmentReplacements.put("configurable-path-segment-two", "anywhere");
    DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(), new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), new KaptLibraryDeepLinkModuleRegistry(), configurablePathSegmentReplacements);
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/anywhere/belong/foo"), equalTo(false));
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/belong/anywhere/foo"), equalTo(true));
}
Also used : HashMap(java.util.HashMap) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) LibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) BenchmarkDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry) Test(org.junit.Test)

Example 3 with KaptLibraryDeepLinkModuleRegistry

use of com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry in project DeepLinkDispatch by airbnb.

the class MainActivityTest method testPathSegmentUriNoMatch.

@Test
public void testPathSegmentUriNoMatch() {
    Map<String, String> configurablePathSegmentReplacements = new HashMap<>();
    configurablePathSegmentReplacements.put("configurable-path-segment", "obamaOs");
    configurablePathSegmentReplacements.put("configurable-path-segment-one", "belong");
    configurablePathSegmentReplacements.put("configurable-path-segment-two", "anywhere");
    DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(), new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), new KaptLibraryDeepLinkModuleRegistry(), configurablePathSegmentReplacements);
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/<capnMccains>/bar"), equalTo(false));
    assertThat(deepLinkDelegate.supportsUri("https://www.example.com/<obamaOs>/bar"), equalTo(false));
}
Also used : HashMap(java.util.HashMap) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) LibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) BenchmarkDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry) Test(org.junit.Test)

Example 4 with KaptLibraryDeepLinkModuleRegistry

use of com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry in project DeepLinkDispatch by airbnb.

the class MainActivityTest method testSupportsUri.

@Test
public void testSupportsUri() throws Exception {
    Map<String, String> configurablePathSegmentReplacements = new HashMap<>();
    configurablePathSegmentReplacements.put("configurable-path-segment", "obamaOs");
    configurablePathSegmentReplacements.put("configurable-path-segment-one", "belong");
    configurablePathSegmentReplacements.put("configurable-path-segment-two", "anywhere");
    DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(), new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), new KaptLibraryDeepLinkModuleRegistry(), configurablePathSegmentReplacements);
    assertThat(deepLinkDelegate.supportsUri("dld://classDeepLink"), equalTo(true));
    assertThat(deepLinkDelegate.supportsUri("some://weirdNonExistentUri"), equalTo(false));
}
Also used : HashMap(java.util.HashMap) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) LibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) BenchmarkDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry) Test(org.junit.Test)

Example 5 with KaptLibraryDeepLinkModuleRegistry

use of com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry in project DeepLinkDispatch by airbnb.

the class MainActivityTest method testMissingKeysThrowsIAException.

@Test
public void testMissingKeysThrowsIAException() {
    DeepLinkDispatch.setValidationExecutor(TestUtils.getImmediateExecutor());
    String message = "";
    try {
        Map<String, String> configurablePathSegmentReplacements = new HashMap<>();
        configurablePathSegmentReplacements.put("configurable-path-segment", "obamaOs");
        DeepLinkDelegate deepLinkDelegate = new DeepLinkDelegate(new SampleModuleRegistry(), new LibraryDeepLinkModuleRegistry(), new BenchmarkDeepLinkModuleRegistry(), new KaptLibraryDeepLinkModuleRegistry(), configurablePathSegmentReplacements);
    } catch (IllegalArgumentException e) {
        message = e.getMessage();
    }
    // Alternatively, we could have used @Test(expected = IllegalArgumentException.class), but I wanted to assert this message.
    assertEquals("Keys not found in BaseDeepLinkDelegate's mapping of PathVariableReplacementValues. Missing keys are:\n" + "configurable-path-segment-one,\n" + "configurable-path-segment-two.\n" + "Keys in mapping are:\n" + "configurable-path-segment.", message);
}
Also used : HashMap(java.util.HashMap) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) LibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry) KaptLibraryDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry) BenchmarkDeepLinkModuleRegistry(com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry) Test(org.junit.Test)

Aggregations

BenchmarkDeepLinkModuleRegistry (com.airbnb.deeplinkdispatch.sample.benchmarkable.BenchmarkDeepLinkModuleRegistry)8 KaptLibraryDeepLinkModuleRegistry (com.airbnb.deeplinkdispatch.sample.kaptlibrary.KaptLibraryDeepLinkModuleRegistry)8 LibraryDeepLinkModuleRegistry (com.airbnb.deeplinkdispatch.sample.library.LibraryDeepLinkModuleRegistry)8 HashMap (java.util.HashMap)8 Test (org.junit.Test)6 Map (java.util.Map)2 DeepLinkUri (com.airbnb.deeplinkdispatch.DeepLinkUri)1 TypeConverters (com.airbnb.deeplinkdispatch.handler.TypeConverters)1 SampleModuleRegistry (com.airbnb.deeplinkdispatch.sample.SampleModuleRegistry)1 Type (java.lang.reflect.Type)1 Function3 (kotlin.jvm.functions.Function3)1