Coder Social home page Coder Social logo

Comments (7)

andretietz avatar andretietz commented on May 21, 2024

I just tried this out! You're right, this is if course an issue. Any suggestions?

from retroauth.

leovanhaaren avatar leovanhaaren commented on May 21, 2024

When using the 2.0 version (before the switch from string to int) all works fine. Seems like Butterknife had the same problem before, but they never fixed it. (Library project resources are not defined as final static because of speed advantages)

JakeWharton/butterknife#45

from retroauth.

andretietz avatar andretietz commented on May 21, 2024

This is because of the "reindexing" of the resource ids on newer android build systems. On the build time of the library, the build system does not set the values to "constant" so, that on build time of the app, this value can be overridden.

So there are not that many options here.

  • Either you define the strings in your library already
  • You define your Retrofit interface in the app

A third, but a bit more complex method is to write your own AuthenticationHandler, create your own TokenStorage. To be able to ignore this annotations and create the TokenType differently

Like this:

public class MyAuthenticationHandler extends AuthenticationHandler<Account, AndroidTokenType, AndroidToken> {
    public MyAuthenticationHandler(Provider<Account, AndroidTokenType, AndroidToken> provider) {
        super(new AndroidMethodCache(), new AndroidOwnerManager(new AuthAccountManager()),
                new MyTokenStorage(), provider);
    }
}

Copy the AndroidTokenStorage from the retroauth-android project and and call it "MyTokenStorage" (may be for the future, I should make this class non-final, so you can extend it and override the interesting method "createType")

@Override
public AndroidTokenType createType(int[] annotationValues) {
    // create your tokentype however you want
    // ...
    return new AndroidTokenType(accountType, tokenType);
}

In this AndroidTokenStorage, is a method called "createType", in which you get the "int[]" from the annotations and form them into an AndroidTokenType Object.

In there you could do now your own Magic to create the tokentype (even with no annotation values available).

Since a couple of classes are package private, you propably have to put them into a "com.andretietz.retroauth" package.

Just did that, it's working.

It has one disadvantage though, your not easily able to handle multiple account and token types. For most projects this should still be fine

You can now i.e. hand the account and token type into the AuthenticationHandler i.e. and leave the annotations empty

Let me know, if you need help!

from retroauth.

andretietz avatar andretietz commented on May 21, 2024

Milestone for the non-final AndroidTokenStorage

from retroauth.

leovanhaaren avatar leovanhaaren commented on May 21, 2024

Thanks! This will do for now 👍

I'll keep a close eye watching the 2.1.1 version.

from retroauth.

andretietz avatar andretietz commented on May 21, 2024

I did't like the solution with making it non final. I found a nicer one. Since the TokenType creation shouldn't be part of the TokenStorage, I will create a TokenTypeFactory, which you then can easily override(optionally), when creating the AndroidAuthenticationHandler.

from retroauth.

andretietz avatar andretietz commented on May 21, 2024

It's done! New release version is 2.1.1

Use:

AndroidAuthenticationHandler.create(new MyProvider(), new MyTokenTypeFactory())

(second parameter is optional)

from retroauth.

Related Issues (20)

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.