Skip to content

Commit

Permalink
use material theme everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
aggarwalpulkit596 committed Aug 6, 2019
1 parent 2ca8a71 commit 02bee33
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.codingblocks.cbonlineapp.extensions

import android.content.Context
import android.graphics.drawable.Drawable
import android.graphics.drawable.PictureDrawable
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.core.view.ViewCompat
import com.caverock.androidsvg.SVG
import com.codingblocks.cbonlineapp.R
import com.codingblocks.cbonlineapp.util.NetworkUtils.okHttpClient
import com.google.android.material.snackbar.Snackbar
import com.squareup.picasso.Picasso
Expand Down Expand Up @@ -42,8 +46,14 @@ fun ImageView.loadImage(imgUrl: String) {
}
}

fun Snackbar.withColor(@ColorInt backgroundColor: Int, @ColorInt textColor: Int): Snackbar {
fun Snackbar.config(context: Context, @ColorInt backgroundColor: Int, @ColorInt textColor: Int) {
val params = this.view.layoutParams as ViewGroup.MarginLayoutParams
params.setMargins(12, 12, 12, 12)
this.view.layoutParams = params
this.view.background = context.getDrawable(R.drawable.bg_snackbar)

this.view.setBackgroundColor(backgroundColor)
this.view.findViewById<TextView>(com.google.android.material.R.id.snackbar_text).setTextColor(textColor)
return this

ViewCompat.setElevation(this.view, 6f)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.codingblocks.cbonlineapp.fragments

import android.graphics.Color
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -10,14 +9,12 @@ import com.codingblocks.cbonlineapp.R
import com.codingblocks.cbonlineapp.extensions.getPrefs
import com.codingblocks.cbonlineapp.extensions.observer
import com.codingblocks.cbonlineapp.extensions.retrofitCallback
import com.codingblocks.cbonlineapp.extensions.withColor
import com.codingblocks.cbonlineapp.viewmodels.MyCourseViewModel
import com.codingblocks.onlineapi.Clients
import com.google.android.material.snackbar.Snackbar
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.android.synthetic.main.fragment_overview.completetionBtn
import kotlinx.android.synthetic.main.fragment_overview.requestBtn
import kotlinx.android.synthetic.main.fragment_overview.view.overviewFragment
import org.jetbrains.anko.AnkoLogger
import org.koin.androidx.viewmodel.ext.android.sharedViewModel

Expand Down Expand Up @@ -48,14 +45,14 @@ class OverviewFragment : Fragment(), AnkoLogger {
setOnClickListener {
Clients.api.requestApproval(viewModel.attemptId).enqueue(retrofitCallback { throwable, response ->
response.let {
if (it?.code() == 500) {
Snackbar.make(overviewFragment, "Could not send the request", Snackbar.LENGTH_LONG).show()
} else if (it?.code() == 200) {
Snackbar.make(overviewFragment, "Request Successful", Snackbar.LENGTH_LONG).show()
if (it?.isSuccessful == true) {
it.body()?.let { it1 -> Snackbar.make(view.rootView, it1.string(), Snackbar.LENGTH_LONG).show() }
} else {
it?.errorBody()?.let { it1 -> Snackbar.make(view.rootView, it1.string(), Snackbar.LENGTH_LONG).show() }
}
}
throwable.let {
Snackbar.make(view.rootView, it?.message.toString(), Snackbar.LENGTH_LONG).withColor(Color.WHITE, Color.BLACK).show()
it?.message?.let { it1 -> Snackbar.make(view.rootView, it1, Snackbar.LENGTH_LONG).show() }
}
})
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_snackbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ffffff" />
<corners android:radius="4dp" />
</shape>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_my_course.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
android:textColor="@color/salmon"
android:textSize="16sp" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/resumeBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/layout/doubt_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:hint="@string/hint_title"
android:theme="@style/TextInputLayoutAppearance"
app:errorEnabled="true"
Expand All @@ -56,6 +57,7 @@
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/descriptionLayout"
android:layout_width="match_parent"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
Expand All @@ -76,7 +78,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="20dp">

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/cancelBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand All @@ -96,7 +98,7 @@
android:textColor="#ced0d2"
android:textSize="16sp" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/okBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_carousel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
android:textAlignment="viewStart"
android:textColor="@color/grey850" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/my_course_card_horizontal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
app:layout_constraintTop_toBottomOf="@+id/courseInstructors" />


<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/courseBtn1"
android:layout_width="0dp"
android:layout_height="40dp"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/nav_header_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
app:layout_constraintStart_toEndOf="@+id/nav_header_imageView"
app:layout_constraintTop_toBottomOf="@+id/nav_header_username_textView" />

<Button
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/login_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down

0 comments on commit 02bee33

Please sign in to comment.