Skip to content
This repository was archived by the owner on Aug 22, 2024. It is now read-only.

Commit be4efea

Browse files
authored
Merge pull request #91 from amardeshbd/material-theme-and-remove-flashbar
Material theme and remove flashbar
2 parents ff6a0a2 + ad27081 commit be4efea

File tree

8 files changed

+211
-56
lines changed

8 files changed

+211
-56
lines changed

app/build.gradle

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,6 @@ dependencies {
8181
//implementation "com.google.dagger:dagger-android-support:$rootProject.daggerVersion"
8282
kapt "com.google.dagger:dagger-android-processor:$rootProject.daggerVersion"
8383

84-
// A highly customizable, powerful and easy-to-use alerting library for Android.
85-
// https://github.com/aritraroy/Flashbar
86-
implementation "com.andrognito.flashbar:flashbar:$rootProject.flashBarVersion"
87-
8884
// ----------------------------------------------------------------
8985
// Android Unit and Instrumentation test
9086
// ----------------------------------------------------------------
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/*
2+
* Copyright (c) 2019 Hossain Khan
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.hossainkhan.android.demo.ui.dialog
18+
19+
import android.os.Bundle
20+
import android.view.LayoutInflater
21+
import android.view.View
22+
import android.view.ViewGroup
23+
import android.widget.FrameLayout
24+
import android.widget.TextView
25+
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
26+
import com.google.android.material.button.MaterialButton
27+
import com.google.android.material.bottomsheet.BottomSheetBehavior
28+
import com.google.android.material.bottomsheet.BottomSheetDialog
29+
import com.hossainkhan.android.demo.R
30+
31+
32+
/**
33+
* Bottom sheet dialog to show layout information.
34+
*/
35+
class LayoutInfoDialog : BottomSheetDialogFragment() {
36+
companion object {
37+
private const val BUNDLE_ARG_KEY_TITLE = "BUNDLE_TITLE"
38+
private const val BUNDLE_ARG_KEY_DESC = "BUNDLE_DESCRIPTION"
39+
40+
fun newInstance(title: String, description: String): LayoutInfoDialog {
41+
val args = Bundle()
42+
args.putString(BUNDLE_ARG_KEY_TITLE, title)
43+
args.putString(BUNDLE_ARG_KEY_DESC, description)
44+
45+
val dialog = LayoutInfoDialog()
46+
47+
dialog.arguments = args
48+
49+
return dialog
50+
}
51+
}
52+
53+
54+
lateinit var infoTitle: TextView
55+
lateinit var infoDescription: TextView
56+
lateinit var okButton: MaterialButton
57+
lateinit var previewXml: MaterialButton
58+
var previewXmlListener: (() -> Unit)? = null
59+
60+
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
61+
val view = inflater.inflate(com.hossainkhan.android.demo.R.layout.dialog_layout_info_sheet, container, false)
62+
infoTitle = view.findViewById(R.id.layout_info_title)
63+
infoDescription = view.findViewById(R.id.layout_info_description)
64+
okButton = view.findViewById(R.id.layout_info_ok)
65+
previewXml = view.findViewById(R.id.layout_info_preview_xml)
66+
return view
67+
}
68+
69+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
70+
super.onViewCreated(view, savedInstanceState)
71+
72+
// Make the bottom sheet dialog expand to full height
73+
// Source: https://medium.com/@OguzhanAlpayli/bottom-sheet-dialog-fragment-expanded-full-height-65b725c8309
74+
view.viewTreeObserver.addOnGlobalLayoutListener {
75+
val dialog = dialog as BottomSheetDialog
76+
val bottomSheet = dialog.findViewById<FrameLayout>(com.google.android.material.R.id.design_bottom_sheet)
77+
val behavior = BottomSheetBehavior.from<View>(bottomSheet)
78+
behavior.state = BottomSheetBehavior.STATE_EXPANDED
79+
behavior.peekHeight = 0
80+
}
81+
82+
bindView(
83+
arguments!!.getString(BUNDLE_ARG_KEY_TITLE, ""),
84+
arguments!!.getString(BUNDLE_ARG_KEY_DESC, "")
85+
)
86+
}
87+
88+
override fun onPause() {
89+
super.onPause()
90+
dismiss()
91+
}
92+
93+
94+
private fun bindView(title: String, description: String) {
95+
infoTitle.text = title
96+
infoDescription.text = description
97+
98+
okButton.setOnClickListener { dismiss() }
99+
previewXml.setOnClickListener {
100+
dismiss()
101+
previewXmlListener?.invoke()
102+
}
103+
}
104+
}

app/src/main/java/com/hossainkhan/android/demo/ui/functionaldemo/MovieDetailsPreviewActivity.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class MovieDetailsPreviewActivity : LayoutPreviewBaseActivity() {
4545
// Some custom logic to make the UI alive!
4646
when (view.id) {
4747
R.id.rating_thumbs_up, R.id.rating_thumbs_down -> {
48-
applyColorTint((view as ImageButton), R.color.white)
48+
applyColorTint((view as ImageButton), android.R.color.white)
4949
}
5050
}
5151
}

app/src/main/java/com/hossainkhan/android/demo/ui/layoutpreview/LayoutPreviewBaseActivity.kt

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ import androidx.core.app.NavUtils
2828
import androidx.appcompat.app.AppCompatActivity
2929
import android.view.Menu
3030
import android.view.MenuItem
31-
import com.andrognito.flashbar.Flashbar
3231
import com.hossainkhan.android.demo.R
3332
import com.hossainkhan.android.demo.data.LayoutInformation
33+
import com.hossainkhan.android.demo.ui.dialog.LayoutInfoDialog
3434
import com.hossainkhan.android.demo.viewmodel.LayoutPreviewViewModelFactory
3535
import dagger.android.AndroidInjection
3636
import timber.log.Timber
@@ -81,7 +81,7 @@ open class LayoutPreviewBaseActivity : AppCompatActivity() {
8181

8282
private lateinit var viewModel: LayoutInfoViewModel
8383

84-
internal var flashbar: Flashbar? = null
84+
internal var infoDialog: LayoutInfoDialog? = null
8585

8686
override fun onCreate(savedInstanceState: Bundle?) {
8787
AndroidInjection.inject(this)
@@ -104,12 +104,6 @@ open class LayoutPreviewBaseActivity : AppCompatActivity() {
104104
})
105105
}
106106

107-
override fun onStop() {
108-
super.onStop()
109-
flashbar?.dismiss()
110-
flashbar = null
111-
}
112-
113107
private fun updateActionBar(layoutInformation: LayoutInformation) {
114108
supportActionBar?.title = layoutInformation.title
115109
}
@@ -118,39 +112,21 @@ open class LayoutPreviewBaseActivity : AppCompatActivity() {
118112
* Loads layout information and previews in a snackbar.
119113
*/
120114
private fun showLayoutInfo(layoutInformation: LayoutInformation, fromUser: Boolean = false) {
121-
if (flashbar == null) {
122-
flashbar = Flashbar.Builder(this)
123-
.gravity(Flashbar.Gravity.BOTTOM)
124-
.title(layoutInformation.title.toString())
125-
.message(layoutInformation.description.toString())
126-
.backgroundColorRes(R.color.colorPrimaryDark)
127-
.positiveActionText(R.string.btn_cta_preview_layout_xml)
128-
.negativeActionText(R.string.btn_cta_okay)
129-
.positiveActionTextColorRes(R.color.colorAccent)
130-
.negativeActionTextColorRes(R.color.colorAccent)
131-
.positiveActionTapListener(object : Flashbar.OnActionTapListener {
132-
override fun onActionTapped(bar: Flashbar) {
133-
Timber.d("Loading the XML for ")
134-
bar.dismiss()
135-
loadLayoutUrl()
136-
}
137-
})
138-
.negativeActionTapListener(object : Flashbar.OnActionTapListener {
139-
override fun onActionTapped(bar: Flashbar) {
140-
Timber.d("Closing dialog.")
141-
bar.dismiss()
142-
}
143-
})
144-
.build()
145-
}
146-
147-
Timber.d("Flash bar showing: %s", flashbar?.isShown())
148-
if (flashbar?.isShown() == false) {
115+
infoDialog = LayoutInfoDialog.newInstance(
116+
layoutInformation.title.toString(),
117+
layoutInformation.description.toString()
118+
)
119+
infoDialog?.previewXmlListener = { loadLayoutUrl() }
120+
121+
Timber.d("Layout info showing: %s", infoDialog?.isVisible)
122+
if (infoDialog?.isVisible == false) {
149123
if (fromUser || viewModel.isFirstTime) {
150-
flashbar?.show()
124+
infoDialog?.let {
125+
it.show(supportFragmentManager, "dialog")
126+
}
151127
}
152128
} else {
153-
flashbar?.dismiss()
129+
infoDialog?.dismiss()
154130
}
155131
}
156132

app/src/main/res/layout/demo_movie_details.xml

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@
6363
app:layout_constraintStart_toStartOf="parent"
6464
app:layout_constraintTop_toTopOf="parent" />
6565

66-
<Button
66+
<com.google.android.material.button.MaterialButton
6767
android:id="@+id/movie_trailer"
68-
style="@style/Widget.AppCompat.Button.Borderless"
68+
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
6969
android:layout_width="wrap_content"
7070
android:layout_height="wrap_content"
7171
android:layout_marginTop="8dp"
72-
android:drawableStart="@drawable/ic_play_circle_outline_black_24dp"
73-
android:drawablePadding="5dp"
74-
android:drawableTint="@color/md_pink_300"
7572
android:text="Trailer"
7673
android:textColor="@color/md_grey_400"
74+
app:icon="@drawable/ic_play_circle_outline_black_24dp"
75+
app:iconPadding="5dp"
76+
app:iconTint="@color/md_pink_300"
7777
app:layout_constraintEnd_toEndOf="parent"
7878
app:layout_constraintStart_toStartOf="parent"
7979
app:layout_constraintTop_toTopOf="parent" />
@@ -128,8 +128,8 @@
128128
android:layout_gravity="center"
129129
android:layout_marginStart="16dp"
130130
android:drawableStart="@drawable/ic_people_black_18dp"
131-
android:drawablePadding="5dp"
132131
android:drawableEnd="@drawable/ic_baseline_4k_18dp"
132+
android:drawablePadding="5dp"
133133
android:drawableTint="@android:color/white"
134134
android:text="93%"
135135
app:layout_constraintLeft_toRightOf="@+id/user_rating"
@@ -187,21 +187,22 @@
187187
app:layout_constraintTop_toBottomOf="@+id/rating_thumbs_down" />
188188

189189
<!-- =========================== Begin Chained Button =========================== -->
190-
<Button
190+
<com.google.android.material.button.MaterialButton
191191
android:id="@+id/button_rent"
192-
style="@style/Widget.AppCompat.Button.Colored"
192+
style="@style/Widget.MaterialComponents.Button"
193193
android:layout_width="0dp"
194194
android:layout_height="wrap_content"
195195
android:layout_marginTop="16dp"
196+
android:layout_marginEnd="16dp"
196197
android:text="Rent from $4.99"
197198
app:layout_constraintEnd_toStartOf="@+id/button_buy"
198199
app:layout_constraintHorizontal_chainStyle="spread"
199200
app:layout_constraintStart_toStartOf="@+id/guideline_vertical_start"
200201
app:layout_constraintTop_toBottomOf="@+id/movie_storyline" />
201202

202-
<Button
203+
<com.google.android.material.button.MaterialButton
203204
android:id="@+id/button_buy"
204-
style="@style/Widget.AppCompat.Button.Colored"
205+
style="@style/Widget.MaterialComponents.Button"
205206
android:layout_width="0dp"
206207
android:layout_height="wrap_content"
207208
android:text="Buy from $19.99"
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<!--
4+
~ Copyright (c) 2019 Hossain Khan
5+
~
6+
~ Licensed under the Apache License, Version 2.0 (the "License");
7+
~ you may not use this file except in compliance with the License.
8+
~ You may obtain a copy of the License at
9+
~
10+
~ http://www.apache.org/licenses/LICENSE-2.0
11+
~
12+
~ Unless required by applicable law or agreed to in writing, software
13+
~ distributed under the License is distributed on an "AS IS" BASIS,
14+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
~ See the License for the specific language governing permissions and
16+
~ limitations under the License.
17+
-->
18+
19+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
xmlns:app="http://schemas.android.com/apk/res-auto"
21+
xmlns:tools="http://schemas.android.com/tools"
22+
android:layout_width="match_parent"
23+
android:layout_height="wrap_content"
24+
android:background="@color/colorPrimary"
25+
android:padding="16dp">
26+
27+
<TextView
28+
android:id="@+id/layout_info_title"
29+
style="@style/TextAppearance.AppCompat.Title.Inverse"
30+
android:layout_width="0dp"
31+
android:layout_height="wrap_content"
32+
app:layout_constraintEnd_toEndOf="parent"
33+
app:layout_constraintStart_toStartOf="parent"
34+
app:layout_constraintTop_toTopOf="parent"
35+
tools:text="Layout info title" />
36+
37+
<TextView
38+
android:id="@+id/layout_info_description"
39+
style="@style/TextAppearance.AppCompat.Medium.Inverse"
40+
android:layout_width="0dp"
41+
android:layout_height="wrap_content"
42+
android:layout_marginTop="8dp"
43+
app:layout_constraintEnd_toEndOf="parent"
44+
app:layout_constraintStart_toStartOf="parent"
45+
app:layout_constraintTop_toBottomOf="@+id/layout_info_title"
46+
tools:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry.\n\n
47+
Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an
48+
unknown printer took a galley of type and scrambled it to make a type specimen book." />
49+
50+
<com.google.android.material.button.MaterialButton
51+
android:id="@+id/layout_info_preview_xml"
52+
style="@style/Widget.MaterialComponents.Button"
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:layout_marginTop="16dp"
56+
android:layout_marginEnd="8dp"
57+
android:text="@string/btn_cta_preview_layout_xml"
58+
app:layout_constraintEnd_toStartOf="@+id/layout_info_ok"
59+
app:layout_constraintTop_toBottomOf="@+id/layout_info_description" />
60+
61+
<com.google.android.material.button.MaterialButton
62+
android:id="@+id/layout_info_ok"
63+
style="@style/Widget.MaterialComponents.Button"
64+
android:layout_width="wrap_content"
65+
android:layout_height="wrap_content"
66+
android:layout_marginTop="16dp"
67+
android:layout_marginEnd="8dp"
68+
android:text="@string/btn_cta_okay"
69+
app:layout_constraintEnd_toEndOf="parent"
70+
app:layout_constraintTop_toBottomOf="@+id/layout_info_description" />
71+
72+
73+
</androidx.constraintlayout.widget.ConstraintLayout>

app/src/main/res/values/styles.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
<resources>
22

3-
<!-- Base application theme. -->
4-
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
3+
<!--
4+
Base application theme.
5+
Use material theme for clean look.
6+
See
7+
- https://material.io/develop/android/docs/getting-started/
8+
- https://material.io/develop/android/components/
9+
-->
10+
<style name="AppTheme" parent="Theme.MaterialComponents.Light.DarkActionBar">
511
<!-- Customize your theme here. -->
612
<item name="colorPrimary">@color/colorPrimary</item>
713
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>

build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ ext {
107107
daggerVersion = '2.15' // https://github.com/google/dagger
108108
timberLibraryVersion = '4.7.1' // https://github.com/JakeWharton/timber
109109
leakcanaryLibraryVersion = '1.6.3' // https://github.com/square/leakcanary/releases
110-
flashBarVersion = '1.0.3' // https://github.com/aritraroy/Flashbar/releases
111110
}
112111

113112
//

0 commit comments

Comments
 (0)