android - Best Architecture to implement different logic and UI, based on the user privileges -


i trying implement feature based flows, in android app:

some users able win points , spend them, others not. not able win points, should not see point related ui , logic should not triggered.

some users able see offers, other users not. same above....

so basically, each user have list of privileges, , views show/hide based on those, other logic should run user , not other (if user.haspointsfeature -> server call , update points, if not, show him message)

i looking @ best way implement architectural point of view, other developers working on project in future, , want make solid , clean possible.

here's i'm thinking of far:

for ui elements:

implement custom layout called: "featurewrapperlayout", have custom attributes app:features="points"for example. , in when initiating it, check it's feature user features , show/hide accordingly.

for code, can't settle on 1 approach need most

1. use if/else everywhere

this basic solution. everywhere logic might different, put

if(user.hasthisfeature()) {     //do logic } else {     //do else } 

problem: pain maintain, when more features added. trying avoid unless no other way plausible.

2. use annotations

this i'm trying achieve, if possible. use runtime annotations specify methods feature related. trying achieve this:

@feature("points") public void fetchuserpoints() {     //fetch points } 

and if call getuserpoints() anywhere, annotation processor check if user has feature, calls it, otherwise, ignores it.

problem: i'm stuck @ making work. trying follow this tutorial he's generating whole new file, , not i'm looking for.

3. use dagger 2

i have dagger 2 in app, implemented else. honnest, don't yet understand well, nor did work yet, know it's used dependency injection. can library helpful achieve want?

tldr

i'm trying find best architecture implement flows , multiple logics run based on privileges user has.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -