Skip to content
GitLab
Explore
Projects
Groups
Snippets
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
horanvo
take-your-pill
Commits
eea47c2e
Commit
eea47c2e
authored
4 years ago
by
Vojtěch Hořánek
Browse files
Options
Download
Email Patches
Plain Diff
refactor RoundedDialogFragment.kt to be more kotlin :)
parent
720a43e0
master
develop
history_charts
plan_reminder_overhaul
v1.5
v1.5.rc3
v1.5.rc2
v1.5.rc1
1 merge request
!22
Develop
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
app/src/main/java/eu/vojtechh/takeyourpill/fragment/dialog/RoundedDialogFragment.kt
+32
-30
...chh/takeyourpill/fragment/dialog/RoundedDialogFragment.kt
imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/DialogHelper.kt
+29
-29
...in/com/github/dhaval2404/imagepicker/util/DialogHelper.kt
with
61 additions
and
59 deletions
+61
-59
app/src/main/java/eu/vojtechh/takeyourpill/fragment/dialog/RoundedDialogFragment.kt
+
32
-
30
View file @
eea47c2e
...
...
@@ -4,52 +4,54 @@ import android.app.Dialog
import
android.os.Bundle
import
android.view.View
import
androidx.core.view.ViewCompat
import
com.github.dhaval2404.imagepicker.R
import
com.google.android.material.bottomsheet.BottomSheetBehavior
import
com.google.android.material.bottomsheet.BottomSheetDialog
import
com.google.android.material.bottomsheet.BottomSheetDialogFragment
import
com.google.android.material.shape.MaterialShapeDrawable
import
com.google.android.material.shape.ShapeAppearanceModel
import
eu.vojtechh.takeyourpill.R
open
class
RoundedDialogFragment
:
BottomSheetDialogFragment
()
{
override
fun
onCreateDialog
(
savedInstanceState
:
Bundle
?):
Dialog
{
val
dialog
:
BottomSheetDialog
=
super
.
onCreateDialog
(
savedInstanceState
)
as
BottomSheetDialog
dialog
.
behavior
.
addBottomSheetCallback
(
object
:
BottomSheetBehavior
.
BottomSheetCallback
()
{
override
fun
onStateChanged
(
bottomSheet
:
View
,
newState
:
Int
)
{
return
(
super
.
onCreateDialog
(
savedInstanceState
)
as
BottomSheetDialog
).
apply
{
setBottomSheetCallback
({
bottomSheet
,
newState
->
if
(
newState
==
BottomSheetBehavior
.
STATE_EXPANDED
)
{
//In the EXPANDED STATE apply a new MaterialShapeDrawable with rounded corners
val
newMaterialShapeDrawable
:
MaterialShapeDrawable
=
createMaterialShapeDrawable
(
bottomSheet
)
ViewCompat
.
setBackground
(
bottomSheet
,
newMaterialShapeDrawable
)
ViewCompat
.
setBackground
(
bottomSheet
,
createRoundDrawable
(
bottomSheet
))
}
}
override
fun
onSlide
(
bottomSheet
:
View
,
slideOffset
:
Float
)
{}
})
return
dialog
},
{
_
,
_
->
})
}
}
private
fun
createMaterialShapeDrawable
(
bottomSheet
:
View
):
MaterialShapeDrawable
{
private
fun
createRoundDrawable
(
bottomSheet
:
View
):
MaterialShapeDrawable
{
val
shapeAppearanceModel
=
//Create a ShapeAppearanceModel with the same shapeAppearanceOverlay used in the style
ShapeAppearanceModel
.
builder
(
context
,
bottomSheet
.
context
,
0
,
R
.
style
.
AppTheme_Theme_CustomShapeAppearanceBottomSheetDialog
)
.
build
()
).
build
()
val
currentDrawable
=
bottomSheet
.
background
as
MaterialShapeDrawable
return
MaterialShapeDrawable
(
shapeAppearanceModel
).
apply
{
initializeElevationOverlay
(
bottomSheet
.
context
)
fillColor
=
currentDrawable
.
fillColor
tintList
=
currentDrawable
.
tintList
elevation
=
currentDrawable
.
elevation
strokeWidth
=
currentDrawable
.
strokeWidth
strokeColor
=
currentDrawable
.
strokeColor
}
}
private
fun
setBottomSheetCallback
(
onStateChanged
:
(
View
,
Int
)
->
Unit
,
onSlide
:
(
View
,
Float
)
->
Unit
)
{
object
:
BottomSheetBehavior
.
BottomSheetCallback
()
{
override
fun
onStateChanged
(
bottomSheet
:
View
,
newState
:
Int
)
=
onStateChanged
(
bottomSheet
,
newState
)
//Create a new MaterialShapeDrawable (you can't use the original MaterialShapeDrawable in the BottomSheet)
val
currentMaterialShapeDrawable
=
bottomSheet
.
background
as
MaterialShapeDrawable
val
newMaterialShapeDrawable
=
MaterialShapeDrawable
(
shapeAppearanceModel
)
//Copy the attributes in the new MaterialShapeDrawable
newMaterialShapeDrawable
.
initializeElevationOverlay
(
context
)
newMaterialShapeDrawable
.
fillColor
=
currentMaterialShapeDrawable
.
fillColor
newMaterialShapeDrawable
.
tintList
=
currentMaterialShapeDrawable
.
tintList
newMaterialShapeDrawable
.
elevation
=
currentMaterialShapeDrawable
.
elevation
newMaterialShapeDrawable
.
strokeWidth
=
currentMaterialShapeDrawable
.
strokeWidth
newMaterialShapeDrawable
.
strokeColor
=
currentMaterialShapeDrawable
.
strokeColor
return
newMaterialShapeDrawable
override
fun
onSlide
(
bottomSheet
:
View
,
slideOffset
:
Float
)
=
onSlide
(
bottomSheet
,
slideOffset
)
}
}
}
This diff is collapsed.
Click to expand it.
imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/DialogHelper.kt
+
29
-
29
View file @
eea47c2e
...
...
@@ -43,18 +43,11 @@ internal object DialogHelper {
setOnCancelListener
{
listener
.
onResult
(
null
)
}
behavior
.
addBottomSheetCallback
(
object
:
BottomSheetBehavior
.
BottomSheetCallback
()
{
override
fun
onStateChanged
(
bottomSheet
:
View
,
newState
:
Int
)
{
if
(
newState
==
BottomSheetBehavior
.
STATE_EXPANDED
)
{
//In the EXPANDED STATE apply a new MaterialShapeDrawable with rounded corners
val
newMaterialShapeDrawable
:
MaterialShapeDrawable
=
createMaterialShapeDrawable
(
bottomSheet
,
context
)
ViewCompat
.
setBackground
(
bottomSheet
,
newMaterialShapeDrawable
)
}
setBottomSheetCallback
({
bottomSheet
,
newState
->
if
(
newState
==
BottomSheetBehavior
.
STATE_EXPANDED
)
{
ViewCompat
.
setBackground
(
bottomSheet
,
createRoundDrawable
(
bottomSheet
))
}
override
fun
onSlide
(
bottomSheet
:
View
,
slideOffset
:
Float
)
{}
})
},
{
_
,
_
->
})
}
dialog
.
show
()
...
...
@@ -71,29 +64,36 @@ internal object DialogHelper {
}
}
private
fun
createMaterialShapeDrawable
(
bottomSheet
:
View
,
context
:
Context
private
fun
createRoundDrawable
(
bottomSheet
:
View
):
MaterialShapeDrawable
{
val
shapeAppearanceModel
=
//Create a ShapeAppearanceModel with the same shapeAppearanceOverlay used in the style
ShapeAppearanceModel
.
builder
(
context
,
bottomSheet
.
context
,
0
,
R
.
style
.
AppTheme_Theme_CustomShapeAppearanceBottomSheetDialog
)
.
build
()
).
build
()
val
currentDrawable
=
bottomSheet
.
background
as
MaterialShapeDrawable
return
MaterialShapeDrawable
(
shapeAppearanceModel
).
apply
{
initializeElevationOverlay
(
bottomSheet
.
context
)
fillColor
=
currentDrawable
.
fillColor
tintList
=
currentDrawable
.
tintList
elevation
=
currentDrawable
.
elevation
strokeWidth
=
currentDrawable
.
strokeWidth
strokeColor
=
currentDrawable
.
strokeColor
}
}
//Create a new MaterialShapeDrawable (you can't use the original MaterialShapeDrawable in the BottomSheet)
val
currentMaterialShapeDrawable
=
bottomSheet
.
background
as
MaterialShapeDrawable
val
newMaterialShapeDrawable
=
MaterialShapeDrawable
(
shapeAppearanceModel
)
//Copy the attributes in the new MaterialShapeDrawable
newMaterialShapeDrawable
.
initializeElevationOverlay
(
context
)
newMaterialShapeDrawable
.
fillColor
=
currentMaterialShapeDrawable
.
fillColor
newMaterialShapeDrawable
.
tintList
=
currentMaterialShapeDrawable
.
tintList
newMaterialShapeDrawable
.
elevation
=
currentMaterialShapeDrawable
.
elevation
newMaterialShapeDrawable
.
strokeWidth
=
currentMaterialShapeDrawable
.
strokeWidth
newMaterialShapeDrawable
.
strokeColor
=
currentMaterialShapeDrawable
.
strokeColor
return
newMaterialShapeDrawable
private
fun
setBottomSheetCallback
(
onStateChanged
:
(
View
,
Int
)
->
Unit
,
onSlide
:
(
View
,
Float
)
->
Unit
)
{
object
:
BottomSheetBehavior
.
BottomSheetCallback
()
{
override
fun
onStateChanged
(
bottomSheet
:
View
,
newState
:
Int
)
=
onStateChanged
(
bottomSheet
,
newState
)
override
fun
onSlide
(
bottomSheet
:
View
,
slideOffset
:
Float
)
=
onSlide
(
bottomSheet
,
slideOffset
)
}
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Explore
Projects
Groups
Snippets