Skip to content

Commit

Permalink
Merge pull request #165 from chenenyu/dev
Browse files Browse the repository at this point in the history
release 1.7.6
  • Loading branch information
chenenyu authored Jul 13, 2021
2 parents b7c95f0 + 49ddba3 commit c65896c
Show file tree
Hide file tree
Showing 18 changed files with 123 additions and 117 deletions.
6 changes: 5 additions & 1 deletion Sample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ android {
versionName "1.0"
}

buildFeatures {
viewBinding true
}

buildTypes {
debug {
// 测试混淆
Expand All @@ -28,7 +32,7 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.2.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation project(':module1')
implementation project(':module2')
testImplementation 'junit:junit:4.12'
Expand Down
78 changes: 27 additions & 51 deletions Sample/app/src/main/java/com/chenenyu/router/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,26 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.chenenyu.router.RouteCallback;
import com.chenenyu.router.RouteStatus;
import com.chenenyu.router.Router;
import com.chenenyu.router.template.RouteTable;

import java.util.Map;
import com.chenenyu.router.app.databinding.ActivityMainBinding;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {
private ActivityMainBinding binding;
private String uri;
private Button btn0, btn1, btn2, btn3, btn4, btn5, btn6, btn7, btn8, btn9, btn10, btn11;

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

EditText editRoute = findViewById(R.id.edit_route);
btn0 = findViewById(R.id.btn0);
btn1 = findViewById(R.id.btn1);
btn2 = findViewById(R.id.btn2);
btn3 = findViewById(R.id.btn3);
btn4 = findViewById(R.id.btn4);
btn5 = findViewById(R.id.btn5);
btn6 = findViewById(R.id.btn6);
btn7 = findViewById(R.id.btn7);
btn8 = findViewById(R.id.btn8);
btn9 = findViewById(R.id.btn9);
btn10 = findViewById(R.id.btn10);
btn11 = findViewById(R.id.btn11);
binding = ActivityMainBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

editRoute.addTextChangedListener(new TextWatcher() {
binding.editRoute.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
Expand All @@ -54,19 +37,14 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
@Override
public void afterTextChanged(Editable s) {
uri = s.toString();
btn0.setText(getString(R.string.go_to, s));
binding.btn0.setText(getString(R.string.go_to, s));
}
});

Router.addGlobalInterceptor(new GlobalInterceptor());

// 动态添加路由
Router.handleRouteTable(new RouteTable() {
@Override
public void handle(Map<String, Class<?>> map) {
map.put("dynamic", DynamicActivity.class);
}
});
Router.handleRouteTable(map -> map.put("dynamic", DynamicActivity.class));

// Router.handleInterceptorTable(new InterceptorTable() {
// @Override
Expand All @@ -85,41 +63,39 @@ public void handle(Map<String, Class<?>> map) {

@Override
public void onClick(View v) {
if (v == btn0) {
Router.build(uri).callback(new RouteCallback() { // 添加结果回调
@Override
public void callback(RouteStatus status, Uri uri, String message) {
if (status == RouteStatus.SUCCEED) {
Toast.makeText(MainActivity.this, "succeed: " + uri.toString(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "error: " + uri + ", " + message, Toast.LENGTH_SHORT).show();
}
if (v == binding.btn0) {
// 添加结果回调
Router.build(uri).callback((RouteCallback) (status, uri, message) -> {
if (status == RouteStatus.SUCCEED) {
Toast.makeText(MainActivity.this, "succeed: " + uri.toString(), Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "error: " + uri + ", " + message, Toast.LENGTH_SHORT).show();
}
}).go(this);
} else if (v == btn1) {
Router.build(btn1.getText().toString()).go(this);
} else if (v == btn2) {
} else if (v == binding.btn1) {
Router.build(binding.btn1.getText().toString()).go(this);
} else if (v == binding.btn2) {
Router.build("dynamic").go(this);
} else if (v == btn3) {
} else if (v == binding.btn3) {
// Bundle bundle = new Bundle();
// bundle.putString("extra", "Bundle from MainActivity.");
// Router.build("result").requestCode(0).with(bundle).go(this);
Router.build("result").requestCode(0).with("extra", "Bundle from MainActivity.").go(this);
} else if (v == btn4) {
} else if (v == binding.btn4) {
startActivity(new Intent(this, WebActivity.class));
} else if (v == btn5) {
} else if (v == binding.btn5) {
Router.build(Uri.parse("router://implicit?id=9527&status=success")).go(this);
} else if (v == btn6) {
Router.build(btn6.getText().toString()).go(this);
} else if (v == btn7) {
} else if (v == binding.btn6) {
Router.build(binding.btn6.getText().toString()).go(this);
} else if (v == binding.btn7) {
Router.build("module1").go(this);
} else if (v == btn8) {
} else if (v == binding.btn8) {
Router.build("module2").go(this);
} else if (v == btn9) {
} else if (v == binding.btn9) {
Router.build("intercepted").go(this);
} else if (v == btn10) {
} else if (v == binding.btn10) {
Router.build("intercepted").skipInterceptors().go(this);
} else if (v == btn11) {
} else if (v == binding.btn11) {
Router.build("test").addInterceptors("AInterceptor").go(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.chenenyu.router.app;

import android.os.Bundle;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.chenenyu.router.Router;
import com.chenenyu.router.annotation.InjectParam;
import com.chenenyu.router.annotation.Route;
import com.chenenyu.router.app.databinding.ActivityTestBinding;

@Route({"test", "http://example.com/user", "router://filter/test"})
public class TestActivity extends AppCompatActivity {
Expand All @@ -25,17 +25,19 @@ public class TestActivity extends AppCompatActivity {
@InjectParam
Model test4;

private ActivityTestBinding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
binding = ActivityTestBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

Router.injectParams(this);

Bundle mExtras = getIntent().getExtras();
id = mExtras.getString("id", id);

TextView text = findViewById(R.id.text_test);
Bundle bundle = getIntent().getExtras();
if (bundle != null && !bundle.isEmpty()) {
StringBuilder sb = new StringBuilder();
Expand All @@ -44,7 +46,7 @@ protected void onCreate(Bundle savedInstanceState) {
.append("\n")
.append("status:")
.append(sts);
text.setText(sb.toString());
binding.textTest.setText(sb.toString());
}
}
}
7 changes: 5 additions & 2 deletions Sample/module1/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.chenenyu.router'

android {
Expand All @@ -13,6 +12,10 @@ android {
versionName "1.0"
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -32,6 +35,6 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
package com.chenenyu.router.module;


import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.chenenyu.router.Router;
import com.chenenyu.router.annotation.InjectParam;
import com.chenenyu.router.annotation.Route;
import com.chenenyu.router.module1.R;
import com.chenenyu.router.module1.databinding.FragmentModule1Binding;

import org.jetbrains.annotations.NotNull;

/**
* A simple {@link Fragment} subclass.
Expand All @@ -28,29 +27,34 @@ public class Module1Fragment extends Fragment {
@InjectParam(key = "test22")
char[] test2;

private FragmentModule1Binding binding;

public Module1Fragment() {
// Required empty public constructor
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_module1, container, false);
binding = FragmentModule1Binding.inflate(inflater, container, false);
return binding.getRoot();
}

@Override
public void onViewCreated(@NotNull View view, @Nullable Bundle savedInstanceState) {
getView().findViewById(R.id.btn_go).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Router.build("module1").go(Module1Fragment.this);
getActivity().finish();
}
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
binding.btnGo.setOnClickListener(v -> {
Router.build("module1").go(Module1Fragment.this);
requireActivity().finish();
});

Router.injectParams(Module1Fragment.this);

Log.d(Module1Fragment.class.getSimpleName(), "test1=" + test1);
}

@Override
public void onDestroyView() {
super.onDestroyView();
binding = null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.chenenyu.router.Router
import com.chenenyu.router.annotation.Route
import com.chenenyu.router.module1.R
import com.chenenyu.router.module1.databinding.ActivityModule1Binding

@Route("module1", "router://filter/module1")
class Module1Activity : AppCompatActivity() {

private lateinit var binding: ActivityModule1Binding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

setContentView(R.layout.activity_module1)

binding = ActivityModule1Binding.inflate(layoutInflater)
setContentView(binding.root)
val fragment = Router.build("fragment2").getFragment(this) as Fragment
supportFragmentManager.beginTransaction().add(R.id.activity_module1, fragment).commit()
supportFragmentManager.beginTransaction().add(binding.activityModule1.id, fragment).commit()
}
}
2 changes: 1 addition & 1 deletion Sample/module1/src/main/res/layout/fragment_module1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.chenenyu.router.module.Module1Activity">
tools:context="com.chenenyu.router.module.Module1Fragment">

<TextView
android:layout_width="wrap_content"
Expand Down
7 changes: 5 additions & 2 deletions Sample/module2/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'com.chenenyu.router'

android {
Expand All @@ -13,6 +12,10 @@ android {
versionName "1.0"
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
Expand All @@ -32,6 +35,6 @@ android {

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "androidx.appcompat:appcompat:1.1.0"
implementation "androidx.appcompat:appcompat:1.3.0"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,21 @@

import com.chenenyu.router.Router;
import com.chenenyu.router.annotation.Route;
import com.chenenyu.router.module2.R;
import com.chenenyu.router.module2.databinding.ActivityModule2Binding;

@Route("module2")
public class Module2Activity extends AppCompatActivity {
private ActivityModule2Binding binding;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_module2);
binding = ActivityModule2Binding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

Fragment fragment = Router.build("fragment1").getFragment(this);
if (fragment != null) {
getSupportFragmentManager().beginTransaction().add(R.id.activity_module2, fragment).commit();
getSupportFragmentManager().beginTransaction().add(binding.activityModule2.getId(), fragment).commit();
}
}
}
Loading

0 comments on commit c65896c

Please sign in to comment.