SlideShare a Scribd company logo
Don’t reinvent the wheel
Modern Android Stack
Paweł Junak
Libs:
● Timber
● Butterknife
● Picasso
● RoboSpice
+ Retrofit
● ORMLite
● Lombok
● Parceler
● Dagger2
Open Source Bar
Timber
never again:
deleting logs from
production app
Timber
if (BuildConfig.DEBUG) {
Timber.plant(new Timber.
DebugTree());
}
Timber
Timber.d("Downloading URL: %s", url);
Butterknife
never again:
findViewById()
Butterknife
EditText email = (EditText)
findViewById(R.id.email)
Butterknife
@Bind(R.id.email)
EditText email;
Butterknife
never again:
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
doStuff()
}
});
Butterknife
@onClick(R.id.button)
public void doStuff(View v)
Butterknife
@onClick(R.id.button)
public void doStuff()
Butterknife
@onClick(R.id.button)
public void doStuff(Button b) {
button.setText(); }
Butterknife
ButterKnife.bind(this);
● OnCreate
ButterKnife.bind(this, view);
● onViewCreated(View v, Bundle b),
● ViewHolder(View v):
Picasso
never again:
AsyncTask with HttpConnection
downloading image
Picasso
Picasso
.with(context)
.load(url)
.into(imageView);
Picasso
Picasso.with(context)
.load(url)
.placeholder(R.drawable.placeholder)
.error(R.drawable.placeholder_error)
.into(imageView);
Picasso
Picasso.with(context)
.load(url)
.resize(50, 50)
.centerCrop()
.into(imageView);
RoboSpice + Retrofit
never again:
AsyncTask with HttpConnection
RoboSpice
never again:
AsyncTask
RoboSpice
RoboSpice
Retrofit
never again:
HttpConnection
Retrofit
public interface GitHubService {
@GET("/users/{user}/repos")
List<Repo> listRep(@Path("user") String u);
}
Retrofit
@Headers("Cache-Control: max-age=640000")
@Headers({
"Accept: application/vnd.github.v3.full+json",
"User-Agent: Retrofit-Sample-App"
})
Retrofit
@GET(/users)
void getUser(@Header("Auth") String auth);
Retrofit
@GET("/group/{id}/users")
List<User> groupList(@Path("id") int groupId,
@Query("sort") String sort);
Retrofit
RestAdapter restAdapter = new RestAdapter.Builder()
.setEndpoint("https://api.github.com")
.build();
Retrofit
GitHubService serv =
RestAdapter.create(GitHubService.class);
List<Repo> repos = service.listRepos("octocat");
Retrofit
POJO
public class Repo {
int id;
String name;
}
RoboSpice + Retrofit
@Override
public void onRequestSuccess(Repo repo) {
// TODO forkAll
}
@Override
public void onRequestFailure(SpiceException ex) {
// TODO fail
}
Mention
Retrofit 2 coming
ORMLite
never again:
SQL
ORMLite
@DatabaseTable(tableName = "repo")
public class Repo {
@DatabaseField(id = true)
int id;
@DatabaseField(canBeNull = false)
String name;
}
ORMLite
No Args Constructor needed
public Repo() {};
ORMLite
class DbHelper extends OrmLiteSqliteOpenHelper
onCreate(SQLiteDatabase db, ConnectionSource cS) {
TableUtils.createTable(cS, Repo.class);
}
ORMLite
class DbHelper extends OrmLiteSqliteOpenHelper
Dao<Repo,Integer> getDao() {
return getDao(Repo.class)
}
ORMLite
class MainAct extends OrmLiteBaseActivity<DbHelper>
Dao<Repo,Integer> repoDao = getHelper.getDao();
ORMLite
Repo repo = new Repo(id, name);
repoDao.create(repo);
ORMLite
Repo repo = repoDao.queryForId(id);
ORMLite
module in RoboSpice :)
Mention
yahoo - squidb
square - sqlbrite
Lombok
never again:
boilerplate getters,
setters, constructors
Lombok
@Getter
@Setter
public class Repo {
int id;
String name;
}
Lombok
public class Repo {
@Getter
int id;
@Setter
String name;
}
Lombok
@NoArgsConstructor
public class Repo {
int id;
String name;
}
Lombok
@Data
public class Repo {
int id;
String name;
}
Parceler
never again:
public static final Creator<Repo> CREATOR =
new Creator<Repo> {
public Repo createFromParcel(Parcel source);
public Repo[] newArray(int size);
}
public void writeToParcel(Parcel dest, int flags);
Parceler
@Parcel
public class Repo
Parceler
Parcelable pr = Parcel.wrap(new Repo())
Repo repo = Parcel.unwrap(pr)
Lombok
@Getter
@Setter
@NoArgsConstructor
@Parcel
@DatabaseTable(tableName = "repo")
public class Repo {
@DatabaseField(id = true)
int id;
@DatabaseField(canBeNull = false)
String name;
}
Dagger2
never again:
init SharedPreferences
Dagger2
@Inject
SharedPreferences prefs;
Dagger2
@Module
class Utils
@Provides
SharedPreferences provideSharedPreferences(){
return context.getSharedPreferences("pref",
Context.MODE_PRIVATE);
}
Dagger2
tools.saveMail(mail);
tools.getMail();
tools.saveToken(token);
tools.getToken();
Dagger2
@Provides
Tools provideTools(){
return new Tools();
}
Dagger2
@Inject
Tools tools;
Summary:
● Butterknife
● Picasso
● RoboSpice
+ Retrofit
● ORMLite
● Lombok
● Parceler
● Dagger2
● Timber
github.com/Polidea/OpenSourceBar-Android
Q&A
Thanks

More Related Content

Viewers also liked

ButterKnife
ButterKnifeButterKnife
ButterKnife
Himanshu Dudhat
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
Felipe Theodoro
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
Benjamin Cheng
 
Annotation Processing in Android
Annotation Processing in AndroidAnnotation Processing in Android
Annotation Processing in Android
emanuelez
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
Mahfuz Islam Bhuiyan
 
Annotation processing in android
Annotation processing in androidAnnotation processing in android
Annotation processing in android
Zhe-Hao Hu
 

Viewers also liked (6)

ButterKnife
ButterKnifeButterKnife
ButterKnife
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
 
Annotation processing
Annotation processingAnnotation processing
Annotation processing
 
Annotation Processing in Android
Annotation Processing in AndroidAnnotation Processing in Android
Annotation Processing in Android
 
Java Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner WalkthroughJava Annotation Processing: A Beginner Walkthrough
Java Annotation Processing: A Beginner Walkthrough
 
Annotation processing in android
Annotation processing in androidAnnotation processing in android
Annotation processing in android
 

Similar to Don't reinvent the wheel, use libraries

Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Yuren Ju
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
Python-GTK
Python-GTKPython-GTK
Python-GTKYuren Ju
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
Garth Gilmour
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
James Aylett
 
Git使用
Git使用Git使用
Git使用
David Xie
 
Android game development
Android game developmentAndroid game development
Android game development
dmontagni
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
Garth Gilmour
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
Murat Yener
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
James Williams
 
Pioc
PiocPioc
Pioc
Tom Sun
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
Johan Thelin
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
Giovanni Bassi
 
Advanced Swift Generics
Advanced Swift GenericsAdvanced Swift Generics
Advanced Swift Generics
Max Sokolov
 
Kotlin a problem solver - gdd extended pune
Kotlin   a problem solver - gdd extended puneKotlin   a problem solver - gdd extended pune
Kotlin a problem solver - gdd extended pune
Hardik Trivedi
 
Working with Git
Working with GitWorking with Git
Working with Git
Pete Nicholls
 
There's more than web
There's more than webThere's more than web
There's more than webMatt Evans
 
Bitbucket
BitbucketBitbucket
Bitbucket
hariprasad1035
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension Yuren Ju
 

Similar to Don't reinvent the wheel, use libraries (20)

Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 
Survey_Paper
Survey_PaperSurvey_Paper
Survey_Paper
 
Kotlin / Android Update
Kotlin / Android UpdateKotlin / Android Update
Kotlin / Android Update
 
Git, from the beginning
Git, from the beginningGit, from the beginning
Git, from the beginning
 
Git使用
Git使用Git使用
Git使用
 
Android game development
Android game developmentAndroid game development
Android game development
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15Android and the Seven Dwarfs from Devox'15
Android and the Seven Dwarfs from Devox'15
 
Introduction to Griffon
Introduction to GriffonIntroduction to Griffon
Introduction to Griffon
 
Pioc
PiocPioc
Pioc
 
Qt Workshop
Qt WorkshopQt Workshop
Qt Workshop
 
Novidades do c# 7 e 8
Novidades do c# 7 e 8Novidades do c# 7 e 8
Novidades do c# 7 e 8
 
Advanced Swift Generics
Advanced Swift GenericsAdvanced Swift Generics
Advanced Swift Generics
 
Kotlin a problem solver - gdd extended pune
Kotlin   a problem solver - gdd extended puneKotlin   a problem solver - gdd extended pune
Kotlin a problem solver - gdd extended pune
 
Working with Git
Working with GitWorking with Git
Working with Git
 
There's more than web
There's more than webThere's more than web
There's more than web
 
Bitbucket
BitbucketBitbucket
Bitbucket
 
step by step to write a gnome-shell extension
step by step to write a gnome-shell extension step by step to write a gnome-shell extension
step by step to write a gnome-shell extension
 

Don't reinvent the wheel, use libraries