Skip to content

Commit

Permalink
enrich samples
Browse files Browse the repository at this point in the history
  • Loading branch information
mrhabibi committed Jul 14, 2017
1 parent 97a4dd5 commit a441268
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Router.getInstance().map("/promo/*/discounted", (ctx, result) -> {
/* Get value from parsed queries */
Router.getInstance().map("/login", (ctx, result) -> {
Router.getInstance().map("/register", (ctx, result) -> {
String referrer = result.queries.get("referrer")
...
});
Expand Down
15 changes: 15 additions & 0 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
classpath 'me.tatarka:gradle-retrolambda:3.4.0'
}
}

repositories {
mavenCentral()
}

android {
compileSdkVersion 26
buildToolsVersion "26.0.0"
Expand All @@ -28,10 +33,20 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:26.+'
compile project(':url-router')
}

apply plugin: 'me.tatarka.retrolambda'

retrolambda {
jvmArgs '-noverify'
}
7 changes: 6 additions & 1 deletion sample/sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
Expand Down Expand Up @@ -76,14 +76,19 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental-safeguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,84 @@
package com.bukalapak.urlrouter.sample;

import android.net.Uri;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.bukalapak.urlrouter.Router;

public class MainActivity extends AppCompatActivity {

EditText editTextUrl;
Button buttonRoute;
TextView textViewResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

editTextUrl = (EditText) findViewById(R.id.edittext_url);
buttonRoute = (Button) findViewById(R.id.button_route);
textViewResult = (TextView) findViewById(R.id.textview_result);

buttonRoute.setOnClickListener(view -> {
Router.getInstance().route(this, editTextUrl.getText().toString(), null);
});

setMapping();
}

private void setMapping() {
Router router = Router.getInstance();

router.preMap("*://<subdomain:[a-z]+>.mysite.com/*", (ctx, result) -> {
String subdomain = result.variables.get("subdomain");
if (subdomain.equals("blog")) {
displayResult("Launch intent: " + result.url);
return null; // Don't continue routing
} else {
return Uri.parse(result.url).getPath(); // Continue routing
}
});

// https://www.mysite.com/about
router.map("/about", (ctx, result) -> {
displayResult("Open about page");
});

// https://www.mysite.com/promo/tas-keren-pria
router.map("/promo/*", (ctx, result) -> {
displayResult("Open promo page");
});

// https://www.mysite.com/promo/tas-keren-pria/discounted
router.map("/promo/*/discounted", (ctx, result) -> {
displayResult("Open discounted promo page");
});

// https://www.mysite.com/register?referrer=anonymous
router.map("/register", (ctx, result) -> {
String referrer = result.queries.get("referrer");
displayResult("Open registration page with referrer " + referrer);
});

// https://www.mysite.com/register?referrer=anonymous
router.map("/transaction/<transaction_id>/view", (ctx, result) -> {
String transactionId = result.variables.get("transaction_id");
displayResult("Open transaction detail page " + transactionId);
});

// https://www.mysite.com/product/kj9fd8-tas-paling-keren-masa-kini
router.map("/product/<product_id:[a-z0-9]+>-*", (ctx, result) -> {
String productId = result.variables.get("product_id");
displayResult("Open product detail page " + productId);
});
}

private void displayResult(String result) {
textViewResult.setText(result);
}
}
23 changes: 20 additions & 3 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:orientation="vertical">

<EditText
android:id="@+id/edittext_url"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="https://www.mysite/register?referrer=abc123" />

<Button
android:id="@+id/button_route"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Route" />

<TextView
android:id="@+id/textview_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter URL then Press Route" />

</LinearLayout>

0 comments on commit a441268

Please sign in to comment.