This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun<reified T:Activity>Context.startActivity() { | |
val intent = Intent(this, T:: class.java) | |
startActivity(intent) | |
} | |
startActivity<DetailActivity>() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
testLoginError() | |
testLoginSuccess() | |
testLoginWithoutStudentNameAndPassword() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testSuccessfulLogin() { | |
// Aragnge | |
final LoginViewModel vm = new LoginViewModel(environment()); | |
final TestSubscriber<Void> loginSuccess = new TestSubscriber<>(); | |
vm.outputs.loginSuccess().subscribe(loginSuccess); | |
vm.inputs.email("hello@kickstarter.com"); | |
vm.inputs.password("danisawesome"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable | |
.just(1, 2, 3, 4, 5) | |
.filter(new Func1<Integer, Boolean>() { | |
@Override | |
public Boolean call(Integer integer) { | |
return integer % 2 != 0; | |
} | |
}).subscribe(new Observer<Integer>() { | |
@Override | |
public void onSubscribe(Disposable d) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Observable | |
.just(1, 2, 3, 4, 5) | |
.filter(integer -> integer % 2 != 0) | |
.subscribe( | |
integer -> Log.i(TAG, String.valueOf(integer)), | |
error -> Log.e(TAG, "Error"), | |
() -> Log.i(TAG, "No more results") | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (product.getType == productType.TYPE_A) { | |
// ... | |
} else if (product.getType == productType.TYPE_B) { | |
// ... | |
} else if (...) { | |
// ... | |
} | |
else { | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import kotlin.math.ceil | |
data class Cell(val i: Int, val j: Int, val isAlive: Boolean) { | |
operator fun get(i: Int, j: Int): Int { | |
if ((i < 0 || i >= 2) || (j < 0 || j >= 2)) return 0 | |
else | |
return 0 | |
} | |
} |