Extras binding and builder for Android activities and fragments which uses annotation processing to generate boilerplate code for you.
- Eliminate
Activity.getIntent().getExtra()
orFragment.getArguments().getStringExtra()
calls by using@BindExtra
on fields. - Generates elegant IntentBuilder/FragmentBuilder with appropriate arguments.
class ExampleActivity extends Activity {
@BindExtra String name;
@BindExtra int age;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intents.bind(this);
// TODO Use fields...
}
}
public class ExampleFragment extends Fragment {
@BindExtra int height;
@BindExtra int weight;
@Override public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intents.bind(this);
// TODO Use fields...
}
}
class CallerActivity extends Activity {
public void addExampleFragent() {
getSupportFragmentManager().beginTransaction()
.add(R.id.fragmentContainer, Intents.exampleFragment() // Generated by the library
.height(170)
.weight(60)
.make())
.commit();
}
public void openExampleActivity() {
final Intent intent = Intents.exampleActivity(this) // Generated by the library
.name("Giang")
.age(29)
.make();
startActivity(intent);
}
}
For example and additional information see sample.
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
compile 'com.github.tikivn.android-template:intents:-SNAPSHOT'
annotationProcessor 'com.github.tikivn.android-template:intents-compiler:-SNAPSHOT'
}
Copyright 2017 Tiki Corp
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.