Skip to content
This repository has been archived by the owner on Dec 22, 2018. It is now read-only.

martyglaubitz/EnumResources

Repository files navigation

EnumRessources Build Status

I often found myself to have an enum for my apps UI state. For example you might a have a drop down which value controls the behaviour of the fragment/activity and also it's look (toolbar color for example).

You could store this meta-data in the enum values themselfes, but by doing so they can quickly become cluttered wioth all sorts of fields and methods. Also: enum constructors with 12 params don't look that nice.

enum FeedContentMode {
  GLOBAL,
  LOCAL,
  FRIENDS
}

final EnumResources enumResources = new EnumResources();

enumResources.get(FeedContentMode.GLOBAL)
  .assocColor(R.color.blue)
  .assocString(R.string.ttl_global);
  
enumResources.get(FeedContentMode.LOCAL)
  .assocColor(R.color.red)
  .assocString(R.string.ttl_local);
  
enumResources.get(FeedContentMode.FRIENDS)
  .assocColor(R.color.yellow)
  .assocString(R.string.ttl_friends);
  
void onFilterChanged(final FeedContentMode feedContentMode) {
  toolbar.setBackgroundDrawable(new ColorDrawable(enumResource.get(feedContentMode).getColor(getResources())));
  setTitle(enumResource.get(feedContentMode).getStringRes());
}

#Usage repositories { jcenter() }

compile 'de.mglaubitz:EnumResources:1.0.2'

About

Utility class to bind Android Ressources to Enum values

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages