We're sorry but this page doesn't work properly without JavaScript enabled. Please enable it to continue.
Feedback

Don't reinvent the wheel, use libraries: Modern Android Stack

00:00

Formal Metadata

Title
Don't reinvent the wheel, use libraries: Modern Android Stack
Title of Series
Number of Parts
46
Author
License
CC Attribution 3.0 Unported:
You are free to use, adapt and copy, distribute and transmit the work or content in adapted or unchanged form for any legal purpose as long as the work is attributed to the author in the manner specified by the author or licensor.
Identifiers
Publisher
Release Date
Language

Content Metadata

Subject Area
Genre
Abstract
Use of libraries gives you speed and smaller error rate than writing everything by yourself. In this talk you gonna learn about how to use modern libraries that make your developer life easier. From Timber through Picasso, ButterKnife to RoboSpice, Dagger2 and few other libs you gonna learn about modern approach to build Android apps that make your customers happy.
18
Stack (abstract data type)Android (robot)Android (robot)outputMobile appStack (abstract data type)Lecture/Conference
Object-relational mappingLipschitz-StetigkeitLecture/ConferenceComputer animation
Object-relational mappingOpen setOpen sourceOpen sourceLibrary (computing)Video gameGoodness of fitEvent horizonLecture/Conference
Open sourceoutputStaff (military)Software developerMultiplication signSoftware bugLibrary (computing)Task (computing)SynchronizationConnected spaceAndroid (robot)Goodness of fitMeeting/Interview
BlogLibrary (computing)Computer fontProduct (business)Mobile appLecture/ConferenceXMLComputer animation
Library (computing)Product (business)PasswordMobile appLecture/Conference
Uniform resource locatorRevision controlNetwork topologyBuildingConfiguration spaceError messageSocial classMultiplication signFile formatCartesian coordinate systemLecture/ConferenceComputer animation
View (database)Standard deviationLecture/ConferenceJSONXMLUML
EmailView (database)OvalInjektivitätView (database)Dependent and independent variablesLine (geometry)WritingPositional notationTouchscreenEvent horizonSocial classEmailXMLUML
Fiber bundleView (database)Parameter (computer programming)Lecture/ConferenceComputer animation
Computer-generated imageryFree variables and bound variablesError messageConnected spaceLibrary (computing)Medical imagingAndroid (robot)View (database)Multiplication signInternetworkingUniform resource locatorFree variables and bound variablesContext awarenessError messageSoftware bugComputer animationLecture/Conference
Line (geometry)Software bugDisk read-and-write headPower (physics)MereologyRoboticsTask (computing)SynchronizationConnected spaceRobotComputer animationLecture/ConferenceMeeting/InterviewXMLUML
Task (computing)Configuration spaceSoftware testingACID
Intelligent NetworkResultantService (economics)Task (computing)MereologyConnected spaceRobot
Interface (computing)Beer steinString (computer science)Control flowEmailAuthorizationLocal GroupBuildingSoftware repositoryMereologyConnected spaceInterface (computing)EmailUniform resource locatorSoftware repositoryCache (computing)Electronic mailing listObject (grammar)Point (geometry)Service (economics)Positional notationEndliche ModelltheorieDependent and independent variablesMathematicsProcess (computing)LoginCoprocessorComputer fileSet (mathematics)Interior (topology)Game controllerLibrary (computing)String (computer science)Multiplication signInternetworkingGoogolRun time (program lifecycle phase)Level (video gaming)Projective planeQuery languageField (computer science)Different (Kate Ryan album)Form (programming)Type theory2 (number)Lecture/ConferenceMeeting/InterviewComputer animation
Software repositoryOvalMathematicsCase moddingRoboticsModule (mathematics)Social classInternetworkingException handlingObject (grammar)System callKeyboard shortcutNP-hardLecture/ConferenceComputer animation
Video gameObject (grammar)ArmObject modelObject-relational mappingWritingXML
Software repositoryString (computer science)Constructor (object-oriented programming)Social classIntegerArmMultiplication signSocial classString (computer science)Module (mathematics)Key (cryptography)Data structureFilm editingUtility softwareTable (information)Normal (geometry)DatabaseJava appletTask (computing)2 (number)Computer fileObject (grammar)Query languageBitOpen setVideo gameScaling (geometry)Software repositorySynchronizationField (computer science)PiMeeting/InterviewComputer animation
Boilerplate (text)Constructor (object-oriented programming)Software repositoryString (computer science)Fluid staticsSource codeFlagOvalBoilerplate (text)Constructor (object-oriented programming)Level (video gaming)CodeHash functionField (computer science)Standard deviationSocial classAndroid (robot)Positional notationArc (geometry)Lecture/ConferenceComputer animation
Software repositorySystem callCASE <Informatik>CodeSocial classDrop (liquid)BitNormal (geometry)XMLComputer animationMeeting/Interview
CodeSquare numberGoogolLibrary (computing)Reflection (mathematics)XML
DebuggerSquare numberInjektivitätCodeLibrary (computing)Lecture/Conference
WritingModule (mathematics)Multiplication signXMLComputer animationLecture/Conference
Module (mathematics)Context awarenessAndroid (robot)CodeRoundness (object)Multiplication signoutputLibrary (computing)Computer animation
Android (robot)Open sourceLibrary (computing)Lambda calculusJava appletInjektivitätView (database)Connected spaceStructural loadTask (computing)Boilerplate (text)Lecture/ConferenceComputer animation
RepetitionOpen setSoftware frameworkRadon transformCodeError messageFirmwareRouter (computing)Lecture/Conference
Connected spaceInternetworkingLecture/Conference
InternetworkingNeuroinformatikRouter (computing)FacebookLibrary (computing)Lecture/ConferenceMeeting/Interview
Radon transformOpen setComputer simulationMeeting/Interview
Cellular automatonComputer networkSimulationElectric currentUser profileConnected spaceLevel (video gaming)WeightDemo (music)NeuroinformatikComputer animation
Electronic mailing listLibrary (computing)Shape (magazine)Limit (category theory)FacebookMultiplication signRouter (computing)Lattice (order)Meeting/Interview
CodeInternetworkingSoftware testingMobile appConnected spacePoint cloudLevel (video gaming)CuboidXMLComputer animation
SimulationCellular automatonComputer networkXMLUMLMeeting/Interview
Transcript: English(auto-generated)
Hi everyone, Dondrej Invel, The Wheel, another Android stack. My name is Paweł Junak, I work at Polydia in Warsaw, in Poland, we do the mobile apps for iOS and Android.
Quick introduction, what we're gonna talk about, the talk is introductionary, I went through all these lips, show you what you can do it, but I don't tell you every detail, how to configure it, just to show you possibilities, you have it, and stuff like that.
So let's do a quick poll, how many of you knows all of them, or like most of them? Good, I was like afraid that's, everyone gonna know everything, so I'm gonna quit.
I like about a half of them, like three or four, three or two, good audience, thanks. Okay, so quick history about why this talk came to life. Our company organized the MC, Mobile Central Europe,
in Warsaw, it's an event, a quite big conference, we had the thing what's called open source bar, and we were talking about these libraries, we use at work, we contribute to some of our stuff,
it was for Android and iOS, and the conclusion was that a lot of developers don't know about really neat and useful libraries that speed up your development is outed, and they also are like new developers when they start doing stuff with the documentation
from developer Android and so on, there's no mentions about the libraries that help you out, so if a new developer comes to our place and you're like oh I didn't know I can do that, and I can do that, so he does like as in task, it's deep connection, and so on,
the basics are important, but if you can avoid them, like you have everything written out, tested, you save your time, time for fixing bugs, and yeah, everything works good. Never again, the outline for every library is like what we can avoid using this library,
the first one is timber, never again deleting logs from your production app, so this is actually a really simple library, but it gives you one neat thing, like you don't have to remember if you deleted your logs or not,
sometimes like you log whatever, foo, foobar, password, whatever, and then it stays on the production app, and if you want to delete it, you have to search for it, or you forgot something, and this little library wrote by Jack Wharton, it's like famous everywhere, saves you from that,
and if you remember anything from this talk, just remember this library, how does it work? Yeah, with timber, we plant, we plant tree, the debug tree, so if we have a build config debug in our initialization class for application,
it plants tree, we have a tree, we have a logs, we don't have a tree, we don't have a logs, and it's that simple. Logs are made after the native log class, so we have different verbosity, the error and stuff on,
we can use printf format, and one thing that I know if you notice, there's no tag, so you don't have to, in every class, put the tag and build cleaner, because timber, it's detecting which class is calling it, and in the log, it shows which class it was called from.
So yeah, really simple thing, but saves you a lot of time and a lot of thinking about deleted my logs. Okay, butter knife, one of the most known, but yeah, that's good. It's again, Jack Wharton, it was, I guess,
the talk before, they also talked about it, how it was made inside. Never again find view by ID, what's the deal? It's the standard line, but we have this, we have edit text with email, we do find view by ID, we cast it to have it, to use it, and yeah, you have few views, few screens,
and you write find view by ID like 100 times, and yeah, save our keystrokes. What we do, we inject it. We have the annotation, inject view, inject view, and ID of the view we want to inject into,
in which variable, and it's already casted, so yeah, these two lines, it looks like small, but you are getting used to it really fast, and you're like never wanting again, write find view by ID. Okay, we're still with butter knife, never again set on click listener, anonymous class,
on click and stuff, a lot of writing. What we do, we have another annotation on click. We annotate the view, we want to have the response to on click event, we have a method. One thing is also we don't have to initialize this view,
so it's just this line without the inject view, as we would do with butter knife, and yeah, a lot less of writing, and it's quicker, and even if you want to write even less, you can omit the view, but what if you want to
use the view we clicked on? We add it as a variable, as argument, it's already casted, and we can work on it, so yeah, we are way ahead with our keystrokes. That's the basic inject we have to do on create in activities and in fragment, and you can also use it
in RecyclerView or ViewHolder stuff. Okay, that was the views, what's next? Picasso, I guess second well known library, AsyncTest with HTTP connection, the learning image,
it's like probably most known one-liner in Android. Yeah, that's it, we have it here, we have a Picasso, we give it context, we give it a URL to our image, and the view we want to put the image into, and it's done by us, we don't think about caching, about internet connection, about a lot of stuff
that makes bugs, and yeah, you have to write it. It's simple, but you can do a lot more, you can have placeholders for the time when the image is downloading, or for the, when there is some error, no internet, or 404,
whatever you need, yeah, you can even resize it, crop it, everything in one line using Picasso. Again, a lot less keystrokes, a lot of less bugs, quicker development, and yeah, safer, like sane, sane head.
Okay, that's one powerful tandem, RoboSpice with retrofit, so we were with the background text with downloading stuff, so we have AsyncTask with HTTP connection, never again, why?
RoboSpice, it's the AsyncTask part. What's the deal with the RoboSpice? What's wrong with AsyncTask, the first thing is, if we run AsyncTask from our activity, it's run in the background, but if we rotate the phone, or do anything that changed configuration,
the activity is recreated, so AsyncTask has a reference to our old activity, we have a new activity after rotating phone, so that's the two really bad things happening, the old activity can be garbage collected
because there's reference from AsyncTask to it, and the second bad thing is that the, everything that was doing an AsyncTask in background, it's never delivered to your activity which is on, because it's a new activity, and the old AsyncTask doesn't have the reference to it.
So, how RoboSpice solves it. The main philosophy about RoboSpice is that everything works in service. You run service, it does the stuff you need to do, and it returns the result to your activity,
but through listeners, so you can rotate your phone, click back button and stuff, and it always return to the listener from the active activity, which is right now on the phone,
you can do caching, stuff like that. So that was the AsyncTask part, we have the HTP connection part. Retrofit, I guess it's square, so again, Jack Wharton involved. What does Retrofit do?
It creates interfaces from your API endpoints. You model your API endpoints as interfaces, which gives you a little nice time to modeling,
I don't know, oh, there's nothing to see. So yeah, here we have like endpoint for users, we have the rest method, get, we have a variable path we can dynamically on the runtime set, and we get the repo file or repo object,
we will talk what this object comes from in a second. So yeah, that's the Retrofit. Model your API endpoints with interfaces. What can you do also? You can put headers with a cache control,
like list of headers, form encoded, multi-part, whatever you need for your API. You can set headers on runtime, using headers annotation, and yeah, have a query to add it to your API,
again, path, and yeah, looks nice. We have interfaces, how to use it. We make a rest adapter. And this actually, one of the downsides of Retrofit is it's one purpose only, you can say it
because it's like to use with your API from one URL, you set the URL, and then every interface, it's endpoint from this URL. So if you have multiple places you have to touch with your internet, like calls, for example,
download stuff, there's a few other libraries, there is Volley from Google, they use it in Google Play, or they used it before. I have it in here, but if you wanna do things like downloading stuff from the URL you get on the runtime,
that's the place you can go. This builder is quite flexible. You can add different level of logins, you can change the JSON processor, if you wanna use Jackson instead of Json, this Json is the standard one.
Like change the HTTP processor and stuff like that. How to use it? We have a rest adapter and we create object service from our interface, and we call the method that was defined in this interface
and we get the object. And we now get to the point where we get the object from. It's all good POJO. So we model our response in Json against the POJO, or the way around. We model our POJO against the Json.
So if we have ID field in our Json, it's mapped to the ID. If we have a string, it's mapped to the string. If we have like 100 more, they are ignored. You don't have to think about it. We have type safety, so we have to watch out if you have ID, which it's not int,
it's gonna crush you up. So it's really tricky to use APIs that can change. And yeah, if we connect it together, we get the tandem.
The RoboSpice is like the main thing and the Retrofit is module for the RoboSpice. You extend a few classes, set up stuff. As I told, it's like, I just wanna go through the libraries and show you shortcuts you can get and I leave the rest for you to figure out stuff.
It's not that hard. But that's the essential from it. When you use Retrofit with RoboSpice, you get two calls. They are quite self explanatory, yeah, sorry. Success and failure. And success, we get our object we defined
and we do whatever we need to do with it. And failure, which is like no internet, 404, whatever happens. We have a spice exception we can use. Okay, so that's like a lot. Arm light, never again SQL.
Arm light is object model, oh shit, sorry guys. I'm a little nervous. Object relation mapper for SQLite. So you don't wanna write SQL.
It's not bad, but if you have to write select 100 times, it's gotta be annoying. So how to do it with arm light? Again, annotation. Like half of all we're cutting is right now annotation stuff.
So yeah, here we have annotation about the table which gonna keep our REPL stuffs. We have a field, column. We can add the arguments like if the ID should be a primary key or the string should be like not null.
The one thing you have to remember, you have to have no IEX structure all the time. We also will back to it. And yeah, that's the piping. You create DB helper, extending arm light,
SQLite open helper. Lovely long name. And you do it like the normal database helper. You have on create, you use table utils to create tables using your class. You also have like on update and some stuff
you do in your database helper. And how to get the stuff into or from database. You use Java DAO file class. Here we're like again in DB helper, we create a getter to have it.
We have DAO class which is the first one is our object and the second is the primary key which is in this table. And we get the DAO from our REPL class. And in main activity or whatever you need,
we need to extend the arm light base activity to use it. We get our DAO, we create object, use the create method and all the SQL is there. How to get anything from SQLite? We have query for ID which we use with primary key.
We also have query builders. If you need anything more complex or the searches, you can do a lot of complicated stuff but then you will need to go back to SQL for joins and stuff like that.
And yeah, awesome module in RoboSpice. So we also again have a async task or do background task done by RoboSpice. Bombok, never again boilerplate.
What we do here? Again, we add notate. That's like half of the stuff we do. We have annotations that add the getters and setters. In this example, it makes getters and setters
for every class member. It's smart enough to not make setters for final. We can do it on per member level. We have our no-arcs constructor.
And you can ask, wow, but I have command N in Android Studio, create constructor and co-create getters, setters, et cetera. One plus for this is you have a cleaner code. It's like if you have like 10 members
and you have like 20 getters, setters and stuff like that, it's gonna be confusing. And this is like one powerful annotation. It makes everything. It makes getters, setters, constructors with the finals, a hash code equals to and to string
from every field you have parcellar. Never again our standard code with parcel. What we do? You should know it. We add notate, yeah. We add notate one annotation, the class is parcellable.
It works in like 90% cases. There's some edge cases like cyclics and stuff like that. You can then have your own code you can add. So if you have like 90% normal classes
and just one you have to write the code for, so yeah, still save this stuff. And you use parcel wrap and unwrap method to have it. So yeah, again, one annotation and a lot of saved code. Dogger too. Yeah, that's again really known and powerful library.
As I told in the beginning, all of the stuff could be like, could have separate talks. This one definitely have a lot of talks, a lot of log posts you can read about it. I would just show really simple example.
Quick history. It was again, the Dogger one was made by Square because they were not satisfied with rubber juice. Then they had a problems because it was a little slow and guys from Google were using it in it. And they like those reflections,
they were like debugging problems. There was like not clear code for debugger and stuff like that. So they made Dogger too with the guys from Square. And yeah, the one thing I didn't tell you like what's the Dogger too? It's a dependency injection library. So what we do when we wanna do short preferences?
Guys, yes, awesome. Yeah, we inject short preferences but how do we get it from? Yeah, we have to do a little writing like ahead but we do it once and don't have like,
get it all the time. So we create module which provides short preferences we do our stuff here and it's in every places you need short preference, you just inject it. Good like way to do it's just like have a tool which abstract stuff with it
and you can provide it, provide the tool. Inside you have a provided short preferences. So you inject your tools and you have inside injected short preferences and stuff like that. It's simple to go. And in this quick round we went through all of them.
I don't know how we spend with time, not bad. Again, a little summary. We have these libraries. I have flyers here with all these libraries and some libraries for iOS and stuff from our company
that are still from the open source bar. There's the GitHub when you have example of every of this library in use and also like RxJava, RetroLambda, they're also there. And yeah, quick summary, butter knife and to inject the views and set on click listeners,
Picasa to download your pictures in background, RoboSpice and RetroFit don't do how to HTTP connection in AsyncTask. So you have your API solved on light for SQL, Lombok for boilerplate, Parcelar for Parcelar,
Dogger too for dependency injection in timber. Remember, at least timber and also remember the flyers. So yeah, that quick overview of the stuff you should know and will ease your code
and make you less error prone and stuff like that. Good to use it. I have ad bonus here. I need a second to set up. I'll talk about. Also in Polydia, we made an add-on to OpenWrt
which is an open firmware for routers. Can be easier like that.
One thing is I couldn't get the internet connection here
so it's a little faked because I'm like sharing the internet from my computer to the router so I can show you like all the stuff. What's it is about? Do you know the library, the Facebook showed
like few other weeks or months ago about shaping a traffic, like simulating like villages in India with your Wi-Fi?
That's kind of stuff. One thing that's in their setup, it's you have to have like MongoDB, Django and stuff like that just like simulate stuff on Wi-Fi. We have the add-on to OpenWrt. You just install inside with a packet manager
from OpenWrt and you have the shaper by yourself. It looks like that. I can show you like live demo because the way around it works, I can connect on my computer to show it. I have it on my phone.
You have for the beginning like few levels defined by us but it's all configurable like you can do whatever you want. It uses Linux net I guess, I don't remember, sorry,
inside and the really nice thing is, don't mind my host name, you can, one of the biggest limitation for us with Facebook lib is that you only like turn the Wi-Fi
to the one shape and that's all. You have like all the time India village in your router. On our solution, you have a list of devices you can, each of them change the speed,
whatever you need and one also neat thing is which I can show you and you can capture stuff with a sniffer so you want to debug some HDP connections or whatever you need and it do the wire shark
and it sends the cloud wire shark. So one thing you have to remember, never debug stuff, you don't want to have it in internet like everything you put in internet, it will come up somewhere unexpectedly and it's also in our flyer if you want to get it. Really simple tool but gives you a lot of possibilities
to like test your apps with low level of reception. So that's all with our ad bonus. Yeah, that's name.
Yeah, that's thanks.