Add maven jitpack.io
and dependencies
in build.gradle (Project)
:
// build.gradle project
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
// build.gradle app/module
dependencies {
...
implementation 'com.google.android.material:material:1.2.1'
implementation 'com.github.gzeinnumer:EasyOptionMenu:version'
implementation 'com.github.gzeinnumer:SimpleMaterialStyle:last-vesion'
//check on https://github.com/gzeinnumer/SimpleMaterialStyle
implementation 'com.github.gzeinnumer:EasyDialogFragment:last-vesion'
//check on https://github.com/gzeinnumer/EasyDialogFragment
}
- Material.io (docs)
- Multi and Single Selection in Recyclerview (docs) (example)
- Android Slidr (docs) Spesial Thanks.
First Step. Use MaterialComponents
in your style :
<style name="AppTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<!-- Customize your theme here. -->
</style>
<style name="DynamicOptionMenuDefault" parent="Theme.MaterialComponents.Light.Dialog">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowMinWidthMajor">80%</item>
<item name="android:windowMinWidthMinor">80%</item>
<item name="android:windowEnterAnimation">@anim/anim_in</item>
<item name="android:windowExitAnimation">@anim/anim_out</item>
</style>
Add This Line to res/color.xml
. Important
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#FF6200EE</color>
<color name="colorPrimaryDark">#FF3700B3</color>
<color name="colorAccent">#FF03DAC5</color>
</resources>
- Content Item there is 2 types data that you can sent to this dialog.
Type 1
ArrayList<String> level1 = new ArrayList<>();
level1.add("Lorem ipsum dolor");
new DynamicOptionMenuBuilder<String>(getSupportFragmentManager())
.builder(level1)
.setTitle("Choise Brand")
...
Type 3 for this type you should override function toString()
in your model pojo
public class ExampleModel {
private int id;
private String name;
private String address;
//constructor
//getter
//setter
@Override
public String toString() {
return name+"."+address;
}
}
And dont forget to declare your model pojo
after DynamicOptionMenuBuilder<ModelPojo>
ArrayList<ExampleModel> level1 = new ArrayList<>();
level1.add(new ExampleModel(1, "Zein", "Balbar"));
new DynamicOptionMenuBuilder<ExampleModel>(getSupportFragmentManager())
.builder(level1)
.setTitle("Choise Brand")
...
Use only finalCallBack(...)
List<ExampleModel> level1 = new ArrayList<>();
level1.add(new ExampleModel(1, "Title 1", "Address 1"));
level1.add(new ExampleModel(2, "Title 2", "Address 2"));
level1.add(new ExampleModel(3, "Title 3", "Address 3"));
level1.add(new ExampleModel(4, "Title 4", "Address 4"));
level1.add(new ExampleModel(5, "Title 5", "Address 5"));
new DynamicOptionMenuBuilder<ExampleModel>(getSupportFragmentManager())
.builder(level1)
.setTitle("Choise Brand")
.finalCallBack(new DynamicOptionMenu.CallBackFinal<ExampleModel>() {
@Override
public void positionItem(ExampleModel data) {
appent("Level 1_" + data);
}
})
.show();
- 2 Level Menu
Use
addSub(...)
andfinalCallBack(...)
.
Use addSub(CallBack)
and return you next level menu with same ModelPojo
. example
.addSub(new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 1_" + data);
return level2;
}
})
Full code. Just Copy and Paste it
List<ExampleModel> level1 = new ArrayList<>();
List<ExampleModel> level2 = new ArrayList<>();
level1.add(new ExampleModel(1, "Title 1", "Address 1"));
level1.add(new ExampleModel(2, "Title 2", "Address 2"));
level1.add(new ExampleModel(3, "Title 3", "Address 3"));
level1.add(new ExampleModel(4, "Title 4", "Address 4"));
level1.add(new ExampleModel(5, "Title 5", "Address 5"));
level2.add(new ExampleModel(6, "Title 1.1", "Address 6"));
level2.add(new ExampleModel(7, "Title 1.2", "Address 7"));
level2.add(new ExampleModel(8, "Title 1.3", "Address 8"));
level2.add(new ExampleModel(9, "Title 1.4", "Address 9"));
level2.add(new ExampleModel(10, "Title 1.5", "Address 10"));
new DynamicOptionMenuBuilder<ExampleModel>(getSupportFragmentManager())
.builder(level1)
.setTitle("Choise Brand")
.addSub(new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 1_" + data);
return level2;
}
})
.finalCallBack(new DynamicOptionMenu.CallBackFinal<ExampleModel>() {
@Override
public void positionItem(ExampleModel data) {
appent("Level 2_" + data);
}
})
.show();
- More Than 2 Level Menu
Use
addSub(CallBack[])
andfinalCallBack(...)
.
Use addSub(CallBack[])
and return you next level menu with same ModelPojo
, and do it again in next pojo. example
.addSub(
new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 1_" + data);
return level2; //return level 2 menus
}
},
new DynamicOptionMenu.CallBack<ExampleModel>() {...},
new DynamicOptionMenu.CallBack<ExampleModel>() {...}
)
Full code. Just Copy and Paste it
List<ExampleModel> level1 = new ArrayList<>();
List<ExampleModel> level2 = new ArrayList<>();
List<ExampleModel> level3 = new ArrayList<>();
List<ExampleModel> level4 = new ArrayList<>();
level1.add(new ExampleModel(1, "Title 1", "Address 1"));
level1.add(new ExampleModel(2, "Title 2", "Address 2"));
level1.add(new ExampleModel(3, "Title 3", "Address 3"));
level1.add(new ExampleModel(4, "Title 4", "Address 4"));
level1.add(new ExampleModel(5, "Title 5", "Address 5"));
level2.add(new ExampleModel(6, "Title 1.1", "Address 6"));
level2.add(new ExampleModel(7, "Title 1.2", "Address 7"));
level2.add(new ExampleModel(8, "Title 1.3", "Address 8"));
level2.add(new ExampleModel(9, "Title 1.4", "Address 9"));
level2.add(new ExampleModel(10, "Title 1.5", "Address 10"));
level3.add(new ExampleModel(11, "Title 1.1.1", "Address 11"));
level3.add(new ExampleModel(12, "Title 1.1.2", "Address 12"));
level3.add(new ExampleModel(13, "Title 1.1.3", "Address 13"));
level4.add(new ExampleModel(14, "Title 1.1.1.1", "Address 14"));
level4.add(new ExampleModel(15, "Title 1.1.1.2", "Address 15"));
new DynamicOptionMenuBuilder<ExampleModel>(getSupportFragmentManager())
.builder(level1)
.setTitle("Choise Brand")
//ignore if your menu only have 1 level
.addSub(
new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 1_" + data);
return level2;
}
}, new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 2_" + data);
return level3;
}
}, new DynamicOptionMenu.CallBack<ExampleModel>() {
@Override
public List<ExampleModel> positionItem(ExampleModel data) {
appent("Level 3_" + data);
return level4;
}
}
)
//add this callback. important line
.finalCallBack(new DynamicOptionMenu.CallBackFinal<ExampleModel>() {
@Override
public void positionItem(ExampleModel data) {
appent("Level 4_" + data);
}
})
.show();
- Disable Filter
new DynamicOptionMenuBuilder<ExampleModel>(getSupportFragmentManager())
...
.setEnableFilter(false)
...
Preview :
FullCode MainActivity
- 1.0.0
- First Release
- 1.0.1
- New Filter Style
- 1.1.0
- Enable Filter
- 1.1.1
- Enablebackbutton true
You can sent your constibution to branch
open-pull
.
Copyright 2021 M. Fadli Zein