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

Supporting Material Library #124

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Supporting Material Library #124

wants to merge 7 commits into from

Conversation

Zoha131
Copy link

@Zoha131 Zoha131 commented Jan 22, 2020

Adding MaterialButtonProxy to support dynamic style for MaterialButton.

As stated in the issue: #91 I am submitting this PR for review.

The problems I am facing:

  1. Keeping the Material Theme Style
    For TextColor and TextAppearance when the user does not pass any value then by default it does not pick the material theme color
  2. Setting style using the style resources
    When I tried to add style using the style resource then I get some unexpected behavior. It does not work as intended.

Code Structure I have used:

  • I have created two modules: paris-material & sample-material . All of my codes are in these modules.
  • I have not written any test cases as I am not 100% sure if it is possible to style Material Library using Paris

Copy link
Collaborator

@ngsilverman ngsilverman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Zoha131, thank you for your contribution and sorry it took me a while to review it. I think you're on the right path here but I've got some comments. I think this can be simplified in a number of ways. If you can work on it some more I can take a closer look and try to see how to best address the textAppearance issue.

@@ -0,0 +1,119 @@
<component name="ProjectCodeStyleConfiguration">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't commit this file.

@@ -19,6 +19,7 @@ rootProject.ext {
MOCKITO_VERSION = '2.23.0'
ROBOLECTRIC_VERSION = '3.8'
TESTING_COMPILE_VERSION = '0.15'
MATERIAL_VERSION = '1.1.0-rc01'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we use a stable version instead?


private var mColors: ColorStateList? = null
private val defaultTextAppearance:Int = 16974317 //todo this might not be the default for every android version or phone
private var mTextAppearance = defaultTextAppearance
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This project doesn't follow the m prefix convention. You can call these colors and textAppearance.

}

@Attr(R2.styleable.Paris_MaterialButton_android_textColor)
fun setTextColor(colors: ColorStateList?) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MaterialButton extends from TextView so all the attributes supported by TextViewProxy and ViewProxy should already work. They don't need to be added again here.

/*
* Material component has default textAppearance.
* But if we do not pass any textAppearance then
* android default textAppearance is set. To keep the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the style doesn't define textAppearance and the theme does then the theme value will be used. That's probably what you're observing and it is the correct behavior. I don't think we should be trying to override it here.

if(mColors == null){
val typedValue = TypedValue()
view.context.theme.resolveAttribute(R.attr.colorOnPrimary, typedValue, true)
view.setTextColor(typedValue.data)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is using colorOnPrimary implemented in MaterialButton? This may be unnecessary.


object ViewUtils {

fun parseTintMode(value: Int, defaultMode: PorterDuff.Mode): PorterDuff.Mode {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reiterating a comment above: this is already implemented by ViewProxy and is not needed here.

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="Paris_MaterialButton">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should only include the XML attributes that are specifically owned by the MaterialButton class (see https://developer.android.com/reference/com/google/android/material/button/MaterialButton), not its parents.

@@ -0,0 +1,25 @@
apply plugin: 'com.android.application'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a sample app specifically for material, you can use the existing sample app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants