Skip to content

Instantly share code, notes, and snippets.

testLoginError()
testLoginSuccess()
testLoginWithoutStudentNameAndPassword()
@selmanon
selmanon / gist:ec3f18e31618c8648077fb224416521a
Created August 30, 2017 20:15
Simplifying the startActivity function on Android using reified type parameter
inline fun<reified T:Activity>Context.startActivity() {
val intent = Intent(this, T:: class.java)
startActivity(intent)
}
startActivity<DetailActivity>()
## Note :
We will use MVP as default architecture cause it's easy to implement comparing to MVVM.
Instead we will implement some features with MVVM architecture.
## Why we need an Architecture ?
1. The Android API is tightly coupled.
2. Make the app easy to test (the must important part).
3. Make the app modular.
4. Make app change/fix easy.
# Package by features
The directory structure is the very first thing encountered by a programmer when browsing source code. Everything flows from it. Everything depends on it. It is clearly one of the most important aspects of your source code.
### Gains and Benefits
* By looking at the structure you can already tell what the app is all about (figure 1);
* Higher modularity;
* Easier code navigation;
* Higher level of abstraction;
mkdir alpha
cd alpha
mkdir data
printf 'a' > data/letter.txt
git init
git add data/letter.txt
printf '1234' > data/number.txt
git add data
printf '1' > data/number.txt
git add data
@selmanon
selmanon / onError
Created February 1, 2017 22:33
onError
@Override
public void onError(Throwable e) {
getMvpView().hideProgressIndicator();
if (e instanceof IOException || e instanceof HttpException) {
mDataManager.getProfiles().subscribe(new Action1<List<Profile>>() {
@Override
public void call(List<Profile> profiles) {
renderProfilesUi(profiles);
@selmanon
selmanon / Lifecycle change
Last active February 1, 2017 22:27
An organised draft of my time investment learning RxJava
@Override
protected void onDestroy() {
super.onDestroy();
if (mSubscription != null) mSubscription.unsubscribe();
}
@selmanon
selmanon / Caching
Last active February 1, 2017 23:12
An organised draft of my time investment learning RxJava
public Observable<List<Profile>> reloadProfiles() {
return mJobAppApiService.getAllProfiles().subscribeOn(Schedulers.io())
.concatMap(new Func1<List<Profile>, Observable<List<Profile>>>() {
@Override
public Observable<List<Profile>> call(List<Profile> profiles) {
return mRealmProfileRepo.setProfiles(profiles);
}
});
}
@selmanon
selmanon / mvp.java
Created November 3, 2016 22:00 — forked from deveshmittal/mvp.java
Clean Architecture
//BasePresenter.java
public interface BasePresenter<V extends BaseView> {
/**
* Set or attach the view to this presenter
*/
public void attachView(V view);
/**
* Will be called if the view has been destroyed. Typically this method will