Timber
Butterknife
GSON
Universal Image Loader
OkHttp
RxJava
Mosby MVP
Dagger 2
Timber.d("There are %s apples", x);
Log.d(TAG, "There are " + x + " apples);
Timber.w(e, "Reason for the error");
Log.w("Reason for the error"); e.printStackTrace();
private TextView mTextView;
private ImageView mImageView;
private RelativeLayout mContainerView;
public void onCreate(Bundle savedInstanceState) {
mTextView = (TextView) this.findViewById(R.id.textView);
mImageView = (ImageView) this.findViewById(R.id.imageView);
mContainerView = (RelativeLayout) this.findViewById(R.id.container);
}
@Bind(R.id.textView) TextView mTextView;
@Bind(R.id.imageView) ImageView mImageView;
@Bind(R.id.container) RelativeLayout mContainerView;
private TextView mTextView;
public void onCreate(Bundle savedInstanceState) {
mTextView = (TextView) this.findViewById(R.id.textView);
mTextView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
((TextView) v).setText("Hello World!");
}
});
}
@OnClick(R.id.textview)
public void textViewClicked(TextView tv) {
tv.setText("Hello World!");
}
{
"page_preview": {
"href": "https://static.blendle.nl/...6b831ee.jpg",
"width": 412,
"height": 550
},
"id": "bnl-soigneur-20150601",
"initial_publication_time": "2015-06-01T00:00:00+00:00"
}
public class Issue {
@SerializedName("page_preview")
PagePreview pagePreview;
@SerializedName("inital_publication_date")
Date publicationDate;
String id;
public static class PagePreview {
String href;
int width;
int height;
}
}
Issue i = new Gson().fromJson(jsonString, Issue.class);
Asynchronous
Memory management
Disk caching
Request request = new Request.Builder()
.url(url)
.build();
Response response = new OkHttpClient().newCall(request).execute();
String body = response.body().string();
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
String body = EntityUtils.toString(response.getEntity());
Sharing sockets
Connection pooling
Transparent GZIP
Caching for repeated requests
Silent recovery
Observable<List<Issue>> myObservable = mDataManager
.getUserFavourites()
.flatMap(Observable::from)
.map(UserFavourite::getLatestIssueLink)
.concatMap(this::getIssue)
.toList();
myObservable.subscribe(
this::showIssues,
this::showError);
public interface LoginView extends MvpView {
void showLoginLoading();
void loginSucceeded();
void loginFailed();
}
public class LoginPresenter implements MvpPresenter<LoginView> {
public void cancel() {}
public void forgotPassword() {}
public void login(String username, String password) {}
}
In software engineering, dependency injection
is a software design pattern that implements
inversion of control for resolving dependencies.
Dependency injection means giving an object
its instance variables. Really. That's it.
~ Wikipedia
DataManager mDataManager;
Analytics mAnalytics;
Session mSessionl
KioskService mKioskService;
public KioskPresenter(DataManager dataManager,
Analytics analytics, Session session,
KioskService kioskService) {
mDataManager = dataManager;
mAnalytics = analytics;
mSession = session;
mKioskService = kioskService;
}
@Inject DataManager mDataManager;
@Inject Analytics mAnalytics;
@Inject Session mSession;
@Inject KioskService mKioskService;
public KioskPresenter(Context context) {
MyApp.get(context).getSessionComponent().inject(this);
}
@Module
public class SessionModule {
@Provides
public OkHttpClient provideHttpClient() {
return new OkHttpClient();
}
@Provides
public DataManager provideDataManager(client) {
return new DataManager(client);
}
DataManager mDataManager;
Analytics mAnalytics;
Session mSessionl
KioskService mKioskService;
public KioskPresenter(Context context) {
mDataManager = DataManager.getInstance();
mAnalytics = new Analytics(context);
mSession = Session.retrieveSession();
mKioskService = new KioskService(context);
}
Timber
Butterknife
GSON
Universal Image Loader
OkHttp
RxJava
Mosby MVP
Dagger 2