Skip to content

Commit 9310590

Browse files
committed
Add custom layout manager
1 parent fb69956 commit 9310590

File tree

5 files changed

+27
-4
lines changed

5 files changed

+27
-4
lines changed

app/build.gradle

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,18 @@ android {
1818
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
1919
}
2020
}
21+
compileOptions {
22+
sourceCompatibility JavaVersion.VERSION_1_7
23+
targetCompatibility JavaVersion.VERSION_1_7
24+
}
2125
}
2226

2327
dependencies {
2428
compile fileTree(dir: 'libs', include: ['*.jar'])
2529
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
2630
exclude group: 'com.android.support', module: 'support-annotations'
2731
})
28-
// compile project(path: ':sheetmenu')
29-
compile 'com.github.whalemare:sheetmenu:1.0'
32+
compile project(path: ':sheetmenu')
3033
compile 'com.android.support:appcompat-v7:25.3.1'
3134
compile 'com.android.support.constraint:constraint-layout:1.0.2'
3235
testCompile 'junit:junit:4.12'

app/src/main/java/ru/whalemare/bottomsheet/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ private void setup2() {
4141
R.string.title,
4242
null,
4343
R.menu.menu,
44+
null,
4445
new MenuItem.OnMenuItemClickListener() {
4546
@Override
4647
public boolean onMenuItemClick(MenuItem item) {

app/src/main/java/ru/whalemare/bottomsheet/MainActivityKotlin.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package ru.whalemare.bottomsheet
22

33
import android.os.Bundle
44
import android.support.v7.app.AppCompatActivity
5+
import android.support.v7.widget.GridLayoutManager
56
import android.view.MenuItem
67
import ru.whalemare.sheetmenu.SheetMenu
78

@@ -19,6 +20,7 @@ open class MainActivityKotlin : AppCompatActivity() {
1920
fun setup() {
2021
SheetMenu().apply {
2122
titleId = R.string.title
23+
layoutManager = GridLayoutManager(this@MainActivityKotlin, 3)
2224
click = MenuItem.OnMenuItemClickListener { true }
2325
menu = R.menu.menu
2426
}.show(this)

sheetmenu/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ android {
2323
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
2424
}
2525
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_7
28+
targetCompatibility JavaVersion.VERSION_1_7
29+
}
2630
}
2731

2832
dependencies {

sheetmenu/src/main/java/ru/whalemare/sheetmenu/SheetMenu.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ import ru.whalemare.sheetmenu.extension.inflate
1717
* @param titleId id from resources with text for title. it is more important than common <b>title</b> param
1818
* @param title string with text for title
1919
* @param menu id from resources for auto-inflate menu
20+
* @param layoutManager for RecyclerView. By default: vertical linear layout manager.
2021
* @param click listener for menu items
2122
*/
2223
open class SheetMenu(
2324
var titleId: Int = 0,
2425
var title: String? = "",
2526
var menu: Int = 0,
27+
var layoutManager: RecyclerView.LayoutManager? = null,
2628
var click: MenuItem.OnMenuItemClickListener = MenuItem.OnMenuItemClickListener { false }) {
2729

2830
fun show(context: Context) {
@@ -57,7 +59,9 @@ open class SheetMenu(
5759
adapter = ListAdapter.with(context.inflate(menu)).apply {
5860
callback = click
5961
}
60-
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
62+
if (layoutManager == null) {
63+
layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
64+
}
6165
}
6266
}
6367
}
@@ -74,10 +78,11 @@ open class SheetMenu(
7478

7579
private var title = ""
7680
private var menu: Int = 0
81+
private var layoutManager: RecyclerView.LayoutManager? = null
7782
private var click: MenuItem.OnMenuItemClickListener = MenuItem.OnMenuItemClickListener { false }
7883

7984
fun show() {
80-
SheetMenu(0, title, menu, click).show(context)
85+
SheetMenu(0, title, menu, layoutManager, click).show(context)
8186
}
8287

8388
/**
@@ -111,6 +116,14 @@ open class SheetMenu(
111116
this.click = click
112117
return this
113118
}
119+
120+
/**
121+
* @param layoutManager for RecyclerView. By default: vertical linear layout manager.
122+
*/
123+
fun setLayoutManager(layoutManager: RecyclerView.LayoutManager?): Builder {
124+
this.layoutManager = layoutManager
125+
return this
126+
}
114127
}
115128
//endregion
116129
}

0 commit comments

Comments
 (0)