Code Monkey home page Code Monkey logo

barber's Introduction

Currently working on Slack. Read my blog or follow me on places @ZacSweers.

GitHub Activity

2024-06-26 — commented on #8 in ZacSweers/FieldSpottr

2024-06-26 — closed issue #8 on ZacSweers/FieldSpottr: "Show current time with red line"

2024-06-25 — closed issue #10 on ZacSweers/FieldSpottr: "Red-out permit blocks"

2024-06-25 — deleted branch z/errorBlocks on ZacSweers/FieldSpottr

2024-06-25 — merged PR #11 to ZacSweers/FieldSpottr: "Mark permit blocks in red"

2024-06-25 — opened PR #11 to ZacSweers/FieldSpottr: "Mark permit blocks in red"

2024-06-25 — created branch z/errorBlocks on ZacSweers/FieldSpottr

2024-06-25 — deleted branch renovate/ktor-monorepo on ZacSweers/FieldSpottr

2024-06-25 — merged PR #7 to ZacSweers/FieldSpottr: "Update ktor monorepo to v2.3.12"

2024-06-25 — opened issue #10 on ZacSweers/FieldSpottr: "Red-out permit blocks"

On My Blog

2024-05-06Preparing for K2

2024-01-03Life in 2024

2023-07-09Catching Up on CatchUp: 2023

2023-01-10Keeping Android and Kotlin Healthy in a Post-Twitter World

2022-12-19Improving Your Gradle Workflow by Not Auto-reloading Build Files

2022-11-30Android Studio's "I'm Feeling Lucky" Button

2022-11-22Network Calls in Lint: Best Practices

2022-10-17Is ViewPump A Security Risk?

2022-05-23You Are Not Blocked

2021-07-23Optimizing Your Kotlin Build

More on zacsweers.dev

Inspired by Simon Willison's auto-updating profile README.

barber's People

Contributors

achuinard avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

barber's Issues

Explore possibly lower minSdkVersion

Right now the minSdkVersion is 14, but it could possibly support lower. I don't know for sure if I want to support lower versions, but something to look in to.

Publish to Maven Central

Pretty straightforward, Bintray makes it easy to sync. Issue is the bintray-release plugin currently doesn't generate some required portions of the pom.xml (tracked in this issue. Once that's resolved, should be quick to make them available on both.

Barber is incompatible with Dagger code generation

Hi -

Tracking this, so I wanted to put in an issue. When adding Barber to a project that already uses Dagger (and dagger-compiler) for injection, dagger code generation fails to run.

My setup is as such;

apt 'io.sweers.barber:barber-compiler:1.0.1'
compile 'io.sweers.barber:barber-api:1.0.1'
compile 'com.squareup.dagger:dagger:1.2.2'
provided 'com.squareup.dagger:dagger-compiler:1.2.2'

Default values

Just an idea, but I think this could work. It's not the prettiest solution, but it would at least give users and avenue to handle dynamic defaults.

public class MyView extends View {

  @StyledAttr(R.styleable.MyView_my_attr)
  int myAttr;

  public MyView(Context context, AttributeSet set) {
      Barber.style(this, R.style.MyView, set);
  }

  // Annotate a method that resolves the default value
  @AttrDefault(R.styleable.MyView_myattr)
  public int getMyAttrDefault() {
      return 4;
  }

  // Alternatively could have a "catchAll = true" value that tells Barber 
  // that this method will handle ALL default value resolution. Need to be 
  // careful here though, as things could get sticky really fast.
  @AttrDefault(catchAll = true)
  public Object resolveDefault(int styleable) {
    switch (styleable) {
      case R.styleable.MyView_my_attr:
        return 4;
    }
  }

  // Generated code would look like this
  target.myAttr = a.getInt(0, target.getMyAttrDefault();
}

Add support for retrieving android namespace values

For example:

String textAllCapsSet = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "textAllCaps");

Not sure how best to approach this. Simple quick and dirty would be to just get the string and use that, but ideally it would be nice to take care of converting it to whatever type the user needs as well.

// In code
@StyledAttr(androidAttr="textAllCaps")
boolean textAllCaps = false;

// Under the hood
String textAllCapsSet = attrs.getAttributeValue("http://schemas.android.com/apk/res/android", "textAllCaps");
target.textAllCaps = Boolean.parseBoolean(textAllCapsSet); 

Travis CI

Few requirements:

  • Basic smoke test (make sure it builds)

./gradlew clean build

  • Run instrumentation tests
$ ./gradlew clean :sample:installDebug
$ adb shell am instrument -w io.sweers.barber.sample.test/android.test.InstrumentationTestRunner

Add support for context.getTheme().resolveAttribute(...)

Not high on my priority list right now, but will consider adding if people express an interest.


TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, outValue, true);
int primaryTextColor = outValue.data;

Have access to TypedValue means this could support a full range of checks to figure out its type. Doing so automatically might come at the expense of flexibility (e.g. user might want to force a particular type).

@ResolvedAttr(android.R.attr.textColorPrimary)
int primaryTextColor;

The default could be to resolve the attribute based on TypedValue's type, with an optional specifier.

Alternative approach.

Simpler for code generation, but more work for the user as they would have to figure out how to mix their desired attrs with these. Would need another overload for Style, and remove the hard requirement for attributeset not to be null in the generated Barbershop#style(...) method.

private static final int[] ATTRS = new int[]{
        android.R.attr.listDivider
};

// Want to do this boilerplate
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();

// Probable method signature
style(Object target, int[] attrs);

Inheritance support

Currently, we can only annotate/style a class that is directly instantiated. It would useful to be able to maintain the extendability of custom View types.

The problem is that a class' generated Barbershop is not invoked by subclasses. When the parent class calls Barber.style it will find the subclass' Barbershop instead of its own, because target.getClass does not refer to its own class.

I don't see any clean fix for this, unfortunately. So perhaps it's something to discuss for now rather than fix immediately. It would probably require some change to the API, such as passing the Class as a parameter in the Barber.style method. We can't simply have a Barbershop look for its parent class' Barbershop because it won't know the correct styleable resource to pass.

Automated versioning

Just something standard to consolidate the version across modules and make it easy to update

Sample for String attribute

How to use the attribute of string value(both hard coded and string ref), not able to find any samples on that

Support for retrieving attributes just from context

Would need another overload for Style, and remove the hard requirement for attributeset not to be null in the generated Barbershop#style(...) method.

private static final int[] ATTRS = new int[]{
        android.R.attr.listDivider
};

// Want to do this boilerplate
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
a.recycle();

// Probable method signature
style(Object target, int[] attrs);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.