android10 / Android-CleanArchitecture

This is a sample app that is part of a series of blog posts I have written about how to architect an android application using Uncle Bob's clean architecture approach.
Apache License 2.0
15.49k stars 3.33k forks source link

New http request on conf changes #57

Closed feresr closed 8 years ago

feresr commented 8 years ago

I like how you architectured your application but, in a real android app. you would't want to waste resources and make new network request every time the user does something as simple as rotating their phone.

xilosada commented 8 years ago

This application is an approach of how to implement an android app based on the Uncle Bob's Clean Code architecture. The synchronization depends of the app and is not standard. The example you have exposed, can be done with a few lines of code. IMO this isn't an issue,

feresr commented 8 years ago

Perhaps you are right and this is not an issue. But could someone provide references to articles explaining how to integrate this architure without this small setback. I mean, using this 'as is' on a real application wouldn't be optimal. Again. I love how this is structured. but this small flaw prevents me from using it in my app.

spirosoik commented 8 years ago

@feresr Of course, It's not an issue because if you check the code there is the cache store also (you can use whatever you want there like a Database instead of files) in order to store/cache a few things and invalidate them after mins/hours whatever anyway.

feresr commented 8 years ago

@spirosoik thanks!. I took another quick look at the code and noticed I had skipped these key lines:

    UserDataStore userDataStore;

if (!this.userCache.isExpired() && this.userCache.isCached(userId)) { userDataStore = new DiskUserDataStore(this.userCache); } else { userDataStore = createCloudDataStore(); }```



Now everything falls into place :)
Will close this issue now.
spirosoik commented 8 years ago

@feresr the only thing which must change is that this demo uses a multiple activity architecture. it will be good to use a single activity architecture with fragments. I mentioned it here https://github.com/android10/Android-CleanArchitecture/issues/32#issuecomment-139189160 and another guy send a detailed pull request for this kind of implementation. check here https://github.com/android10/Android-CleanArchitecture/pull/53

Read carefully the post of @android10 , he mentioned a few things which must be done a little bit different. One of them is the packaging of application's features. @android10 suggests and actually, it's a good idea to use 'Packages by feature', especially if you are in a big team and you want to keep the ownership as a smaller team

android10 commented 8 years ago

Guys, nice discussion. Sorry I was on vacations. As you have figured out, one of the approach is to use a cache, that's the main value of it, isn't it? We want to avoid connections as much as we can, specially when no data is changed on the server.

On the other hand, another simple approach I used is to retain fragment instances. Although this is not the most effective solution, it is pretty much we need in order to not either hit the api or query the cache.

spirosoik commented 8 years ago

@android10 :+1: cool