Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code review #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

104 changes: 0 additions & 104 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
//apply from: "$rootDir/jacoco.gradle"
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 29
buildToolsVersion "29.0.0"
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "ru.whalemare.bottomsheet"
minSdkVersion 16
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionCode 2
versionName app_version
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
Expand Down
62 changes: 28 additions & 34 deletions app/src/main/java/ru/whalemare/bottomsheet/MainActivityKotlin.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,56 @@ package ru.whalemare.bottomsheet

import android.graphics.drawable.Drawable
import android.os.Bundle
import android.view.View
import android.widget.CheckBox
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import kotlinx.android.synthetic.main.activity_main.*
import ru.whalemare.sheetmenu.ActionItem
import ru.whalemare.sheetmenu.SheetMenu
import ru.whalemare.sheetmenu.layout.GridLayoutProvider

open class MainActivityKotlin : AppCompatActivity() {
var needTitle = false
private var needTitle = false

var needIcons = true
private var needIcons = true

var needLong = true
private var needLong = true

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val textMenu = findViewById<TextView>(R.id.textMenu)

(findViewById<CheckBox>(R.id.checkbox_title))
.setOnCheckedChangeListener { _, isChecked -> needTitle = isChecked }

(findViewById<CheckBox>(R.id.checkbox_icons))
.setOnCheckedChangeListener { _, isChecked ->
needIcons = isChecked
textMenu.text = when {
needIcons -> "R.layout.menu_icons"
!needIcons -> "R.layout.menu"
else -> "null"
}

checkbox_title.setOnCheckedChangeListener { _, isChecked -> needTitle = isChecked }

checkbox_icons.setOnCheckedChangeListener { _, isChecked ->
needIcons = isChecked
textMenu.text = when {
isChecked -> "R.layout.menu_icons"
!isChecked -> "R.layout.menu"
else -> "null"
}
}

(findViewById<CheckBox>(R.id.checkbox_long))
.setOnCheckedChangeListener { _, isChecked -> needLong = isChecked }
checkbox_long.setOnCheckedChangeListener { _, isChecked -> needLong = isChecked }

findViewById<View>(R.id.button_linear).setOnClickListener {
button_linear.setOnClickListener {
setupLinear()
}

findViewById<View>(R.id.button_grid).setOnClickListener {
button_grid.setOnClickListener {
setupGrid()
}

findViewById<View>(R.id.button_menu).setOnClickListener {
button_menu.setOnClickListener {
setupMenuRes()
}
}

fun setupLinear() {
private fun setupLinear() {
SheetMenu(getSheetTitle(), getSheetItems()).show(this)
}

fun setupGrid() {
private fun setupGrid() {
SheetMenu(
title = getSheetTitle(),
actions = getSheetItems(),
Expand All @@ -65,35 +60,34 @@ open class MainActivityKotlin : AppCompatActivity() {
).show(this)
}

fun toast(text: CharSequence) {
private fun toast(text: CharSequence) {
Toast.makeText(this, text, Toast.LENGTH_SHORT).show()
}

fun setupMenuRes() {
private fun setupMenuRes() {
SheetMenu(
context = this,
title = getSheetTitle(),
menu = if (needIcons) R.menu.menu_icons else R.menu.menu
).show(this)
}

fun setupJustTitles() {
private fun setupJustTitles() {
SheetMenu("Post", listOf("Send mail", "Send telegram", "Receive parcel")).show(this)
}

fun getSheetTitle() = if (needTitle) "Title" else null
private fun getSheetTitle() = if (needTitle) "Title" else null

fun getSheetItems(): List<ActionItem> {
private fun getSheetItems(): List<ActionItem> {
val size = if (needLong) 20 else 5
return (0..size).map { index ->
val image = if (needIcons) getRandomIcon() else null
return@map ActionItem(index, "Title $index", image)
}
}

fun getRandomIcon(): Drawable {
private fun getRandomIcon(): Drawable? {
val icons = listOf(R.drawable.ic_atom, R.drawable.ic_disco)
return resources.getDrawable(icons.random())
return ContextCompat.getDrawable(this, icons.random())
}

}