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

DOCX
Git setuplinux
PDF
Anaysing your logs with docker and elk
PDF
Git training cheat sheet
DOCX
Public class form1
PPTX
HItchhickers Guide to TypeScript
PDF
Latex with git
PPTX
1. hg init – a mercurial tutorial by tortoies hg ground up mercurial
PDF
Get on with git
Git setuplinux
Anaysing your logs with docker and elk
Git training cheat sheet
Public class form1
HItchhickers Guide to TypeScript
Latex with git
1. hg init – a mercurial tutorial by tortoies hg ground up mercurial
Get on with git

Viewers also liked (6)

PDF
ButterKnife
PDF
Annotation processing
PPTX
Annotation processing
PDF
Annotation Processing in Android
PDF
Java Annotation Processing: A Beginner Walkthrough
PDF
Annotation processing in android
ButterKnife
Annotation processing
Annotation processing
Annotation Processing in Android
Java Annotation Processing: A Beginner Walkthrough
Annotation processing in android
Ad

Recently uploaded (10)

PDF
Date Right Stuff - Invite only, conservative dating app
DOC
NIU毕业证学历认证,阿比林基督大学毕业证留学生学历
PDF
Best 4 Sites for Buy Verified Cash App Accounts – BTC Only.pdf
PPTX
ASMS Telecommunication company Profile
PDF
Kids, Screens & Emotional Development by Meenakshi Khakat
PDF
2025 Guide to Buy Verified Cash App Accounts You Can Trust.pdf
PDF
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
PPTX
Social Media People PowerPoint Templates.pptx
DOC
SIUE毕业证学历认证,阿祖萨太平洋大学毕业证学位证书复制
PPTX
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
Date Right Stuff - Invite only, conservative dating app
NIU毕业证学历认证,阿比林基督大学毕业证留学生学历
Best 4 Sites for Buy Verified Cash App Accounts – BTC Only.pdf
ASMS Telecommunication company Profile
Kids, Screens & Emotional Development by Meenakshi Khakat
2025 Guide to Buy Verified Cash App Accounts You Can Trust.pdf
Lesson 13- HEREDITY _ pedSAWEREGFVCXZDSASEWFigree.pdf
Social Media People PowerPoint Templates.pptx
SIUE毕业证学历认证,阿祖萨太平洋大学毕业证学位证书复制
Introduction to Packet Tracer Course Overview - Aug 21 (1).pptx
Ad

Don't reinvent the wheel, use libraries