Easy to putExtra in Activity. Support multi module. 😏
Java
Switch branches/tags
Clone or download
Latest commit e456219 Jan 4, 2018
Permalink
Failed to load latest commit information.
annotation split path and instance Dec 1, 2017
compiler split path and instance Dec 1, 2017
core mix module Nov 25, 2017
gradle/wrapper support multi module Nov 23, 2017
path split path and instance Dec 1, 2017
.gitattributes add gitattributes Aug 25, 2017
.gitignore update readme Nov 26, 2017
README.md Update README.md Jan 4, 2018
build.gradle optimize Dec 1, 2017
gradle.properties init Feb 16, 2017
gradlew init Feb 16, 2017
gradlew.bat init Feb 16, 2017
settings.gradle filter illegal chars in module name Nov 26, 2017

README.md

SmartGo

简化Activity传值,跨模块跳转、获取实例

Gradle配置

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Java

android {
    defaultConfig {
        ...
        javaCompileOptions {
            annotationProcessorOptions {
                arguments = [ module : project.name ]
            }
        }
    }
}

dependencies {
    implementation 'com.github.VictorChow.SmartGo:core:2.0.0-rc3'
    annotationProcessor 'com.github.VictorChow.SmartGo:compiler:2.0.0-rc3'
}

Kotlin

apply plugin: 'kotlin-kapt'

dependencies {
    implementation 'com.github.VictorChow.SmartGo:core:2.0.0-rc3'
    kapt 'com.github.VictorChow.SmartGo:compiler:2.0.0-rc3'
}

kapt {
    arguments {
        arg("module", project.name)
    }
}

混淆

-keep class * implements pers.victor.smartgo.SmartGoInjector
-keep class * implements pers.victor.smartgo.SmartPathInjector
-keep class * implements pers.victor.smartgo.InstanceInjector

同模块

目标Activity

  • 属性添加@IntentExtra后需要Make Project生成SmartGo类
  • 不支持Serializable

Java

public class TargetActivity extends Activity {
    @IntentExtra("name")
    String myName; 
    @IntentExtra //不加value时默认为属性名
    int age;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        SmartGo.inject(this); //注入
    }

    //若需要在onNewIntent里调用时
    @Override
    protected void onNewIntent(Intent intent) {
        SmartGo.inject(this, intent); //注入
    }
}

Kotlin

类似Java,lateinit属性需要添加@JvmField注解

跳转

自动生成ToXXXActivity()、setXXX()
SmartGo.from(context)
       .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)    //需要时使用,非必需
       .setAnim(R.anim.enterAnim, R.anim.exitAnim) //需要时使用,非必需
       .toTargetActivity()
       .setName("Victor")
       .setAge(23)
       .go(); //可填入requestCode

跨模块跳转

module1

@Path("module1_activity")
public class Module1Activity extends Activity {
    //内部配置类似单模块
}

module2

SmartPath.from(context)
         .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)    //需要时使用,非必需
         .setAnim(R.anim.enterAnim, R.anim.exitAnim) //需要时使用,非必需
         .toPath("module1_activity")
         .putString("name", "victor")
         .putInt("age", 23)
         .go(); //可填入requestCode

跨模块获取实例

module1

@Instance("test_fragment")
public class TestFragment extends Fragment {
}

@Instance("test_invoke")
public class TestInvokable implements Invokable {
    @Override
    public Object invoke(Object... key) {
        return "TestInvokable";
    }
}

module2

 Fragment fragment = SmartPath.createInstance("test_fragment");
 Invokable invokable = SmartPath.createInstance("test_invoke");