Routine adapter RxJava2

A routine adapter for RxJava2.

License

License

Categories

Categories

RxJava Container Microservices Reactive libraries
GroupId

GroupId

com.anbillon.routine
ArtifactId

ArtifactId

adapter-rxjava2
Last Version

Last Version

1.1.1
Release Date

Release Date

Type

Type

aar
Description

Description

Routine adapter RxJava2
A routine adapter for RxJava2.
Project URL

Project URL

https://github.com/Tourbillon/Android-Routine.git
Source Code Management

Source Code Management

http://github.com/Tourbillon/Android-Routine

Download adapter-rxjava2

How to add to project

<!-- https://jarcasting.com/artifacts/com.anbillon.routine/adapter-rxjava2/ -->
<dependency>
    <groupId>com.anbillon.routine</groupId>
    <artifactId>adapter-rxjava2</artifactId>
    <version>1.1.1</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.anbillon.routine/adapter-rxjava2/
implementation 'com.anbillon.routine:adapter-rxjava2:1.1.1'
// https://jarcasting.com/artifacts/com.anbillon.routine/adapter-rxjava2/
implementation ("com.anbillon.routine:adapter-rxjava2:1.1.1")
'com.anbillon.routine:adapter-rxjava2:aar:1.1.1'
<dependency org="com.anbillon.routine" name="adapter-rxjava2" rev="1.1.1">
  <artifact name="adapter-rxjava2" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.anbillon.routine', module='adapter-rxjava2', version='1.1.1')
)
libraryDependencies += "com.anbillon.routine" % "adapter-rxjava2" % "1.1.1"
[com.anbillon.routine/adapter-rxjava2 "1.1.1"]

Dependencies

There are no dependencies for this project. It is a standalone project that does not depend on any other jars.

Project Modules

There are no modules declared in this project.

Routine

An android router which can support scheme url and native page.

Usage

  • Create your own navigator:
public interface Navigator {
  String EXTRA_ID = "com.andbillon.EXTRA_ID";
  /**
     * Navigate to {@link DemoActivity} with scheme url.
     *
     * @param context context to use
     */
    @SchemeUrl("demo://test/login?id=2") 
    void navigateToDemoWithSchemeUrl(@Caller Context context);

    /**
     * Navigate to {@link DemoActivity} with activity page value.
     *
     * @param context context to use
     */
    @PageName("com.anbillon.routine.sample.ui.DemoActivity")
    @Flags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
    void navigateToDemoWithPageName(@Caller Context context, @Extra(EXTRA_ID) String id,
        @RequestCode int requestCode);

    /**
     * Navigate to {@link DemoActivity} with activity page.
     *
     * @param context context to use
     */
    @Page(DemoActivity.class) 
    void navigateToDemoWithPage(@Caller Context context);
}
  • Routine supports three navigation method: @SchemeUrl, @PageName and @Page. If you want to use dynamic shceme url, then you can create like this:
/**
  * Navigate with dynamic scheme url.
  *
  * @param context context to use
  * @param url dynamic shceme url
  */
void navigateWithDynamicSchemeUrl(@Caller Context context, @SchemeUrl String url);
  • Then create Routine in application or somewhere:
Routine routine = new Routine.Builder().addInterceptor(new RoutineAuthInterceptor())
        .addInterceptor(
            new RoutineLoggingInterceptor().setLevel(RoutineLoggingInterceptor.Level.ALL))
        .build();
Navigator navigator = routine.create(Navigator.class);
  • And then you can use navigator to navigate to the target page:
navigator.navigateToDemoWithSchemeUrl(this);
navigator.navigateToDemoWithPageName(this, "3", REQUEST_CODE);
navigator.navigateToDemoWithPage(this);
  • If you want to navigation with @SchemeUrl, you need to add some extra properties in AndroidManifest.xml:
<activity android:name=".ui.DemoActivity">
      <intent-filter>
        <action android:name="android.intent.action.VIEW"/>

        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>

        <data
            android:scheme="demo"
            android:host="test"
            android:path="/login"
            />
      </intent-filter>
</activity>
  • However, it's not safe to add scheme in AndroidManifest.xml. Maybe you only want to make navigation just inside in your app , then you can add Filter to routine, one scheme url can map to many page, one page can map to many scheme urls too. The routine will open the first page which is available:
public final class SchemeFilter implements Filter {

  @Override public Matcher filter(Chain chain) {
    Matcher matcher = chain.matcher();
    Matcher.Builder builder = matcher.newBuilder();
    builder.addPage("demo://test/check", FilterActivity.class)
        .addPageName("demo://test/check", "com.anbillon.routine.sample.ui.FilterActivity");

    return chain.proceed(builder.build());
  }
  
/* add in routine */
Routine routine = new Routine.Builder().addFilter(new SchemeFilter()).build()
  • If you want navigate to a page with shceme url in webview of your app, then you need to replace the default method to handle scheme url with routine:
@SuppressWarnings("deprecation") private class HtmlClient extends WebViewClient {
  @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override
  public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
    if (navigator.navigateWithDynamicSchemeUrl(context, request.getUrl().toString())) {
      return true;
    } else {
      return super.shouldOverrideUrlLoading(view, request);
    }
  }

  @Override public boolean shouldOverrideUrlLoading(WebView view, String url) {
    if (navigator.navigateWithDynamicSchemeUrl(context, url)) {
      return true;
    } else {
      return super.shouldOverrideUrlLoading(view, url);
    }
  }
}
  • You can also use interceptor to get data or transform Intent:
public final class RoutineAuthInterceptor implements Interceptor {

  @Override public Router intercept(Chain chain) throws RoutineException {
    Router router = chain.router();
    Router.Builder builder = router.newBuilder();
    /* your authentication logic here */
    if (random(3) == 0) {
    Intent intent = new Intent(call.context(), LoginActivity.class);
    builder.intent(intent).requestCode(-1);
    }

    return chain.proceed(builder.build());
  }
}
  • Enjoy it.

Snapshots of the development version are available in Sonatype's snapshots repository.

Download

Add in your gradle.build:

compile 'com.anbillon.routine:routine:1.1.1'

Credits

  • Retrofit - Type-safe HTTP client for Android and Java by Square, Inc

License

Copyright (C) 2017 Tourbillon Group

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

     http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Versions

Version
1.1.1