-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/Part5' into develop
- Loading branch information
Showing
10 changed files
with
174 additions
and
20 deletions.
There are no files selected for viewing
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
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
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
61 changes: 61 additions & 0 deletions
61
app/src/main/java/it/tiwiz/rxjavacrunch/part5/Part5Activity.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package it.tiwiz.rxjavacrunch.part5; | ||
|
||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.widget.TextView; | ||
|
||
import com.trello.rxlifecycle.components.support.RxAppCompatActivity; | ||
|
||
import java.util.concurrent.TimeUnit; | ||
|
||
import it.tiwiz.rxjavacrunch.R; | ||
import rx.Observable; | ||
import rx.android.schedulers.AndroidSchedulers; | ||
import rx.functions.Action0; | ||
|
||
public class Part5Activity extends RxAppCompatActivity { | ||
|
||
private TextView textEmittedNumber; | ||
private static final String TAG = "NightObserver"; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_part5); | ||
wireUpActivity(); | ||
startEmitting(); | ||
} | ||
|
||
private void wireUpActivity() { | ||
textEmittedNumber = (TextView) findViewById(R.id.mainEmittedNumber); | ||
} | ||
|
||
|
||
private void startEmitting() { | ||
Log.d(TAG, "Night gathers, and now my watch begins"); | ||
Observable.interval(1, TimeUnit.SECONDS) | ||
.observeOn(AndroidSchedulers.mainThread()) | ||
.compose(bindToLifecycle()) | ||
.subscribe(this::logOnNext, this::logOnError, this::logOnCompleted); | ||
} | ||
|
||
private void logOnNext(Long time) { | ||
textEmittedNumber.setText(String.valueOf(time)); | ||
Log.d(TAG, "Nothing bad happened for " + time + " seconds"); | ||
} | ||
|
||
private void logOnError(Throwable throwable) { | ||
Log.e(TAG, "Something worse than White Walkers is approaching!\t" + throwable.getMessage()); | ||
} | ||
|
||
private void logOnCompleted() { | ||
Log.d(TAG, "The day has come, may my watch end!"); | ||
} | ||
|
||
@Override | ||
protected void onPause() { | ||
super.onPause(); | ||
Log.w(TAG, "The sun is rising!"); | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:fitsSystemWindows="true" | ||
android:orientation="vertical" | ||
android:layout_margin="16dp" | ||
tools:context="it.tiwiz.rxjavacrunch.part5.Part5Activity"> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="48dp" | ||
android:orientation="horizontal"> | ||
|
||
<TextView | ||
android:layout_width="0dp" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:gravity="center" | ||
android:text="Currently emitted number" | ||
android:textSize="14sp" /> | ||
|
||
<TextView | ||
android:id="@+id/mainEmittedNumber" | ||
android:layout_width="0dp" | ||
android:layout_height="match_parent" | ||
android:layout_weight="1" | ||
android:gravity="center" | ||
android:textSize="20sp" | ||
tools:text="12345678901234" /> | ||
</LinearLayout> | ||
|
||
|
||
</LinearLayout> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<resources>> | ||
|
||
<style name="AppTheme.NoActionBar"> | ||
<item name="windowActionBar">false</item> | ||
<item name="windowNoTitle">true</item> | ||
<item name="android:windowDrawsSystemBarBackgrounds">true</item> | ||
<item name="android:statusBarColor">@android:color/transparent</item> | ||
</style> | ||
</resources> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,9 @@ | ||
<resources> | ||
<string name="app_name">RxJava Crunch</string> | ||
|
||
<string name="hello_world">Hello world!</string> | ||
<string name="action_settings">Settings</string> | ||
<string name="title_activity_part1">Part1Activity</string> | ||
<string name="title_activity_part2">Part2Activity</string> | ||
<string name="title_activity_part3">Part3Activity</string> | ||
<string name="title_activity_main4">Retrofit test</string> | ||
<string name="title_activity_part4_detail">Part4DetailActivity</string> | ||
<string name="app_name">Crunching RxAndroid</string> | ||
<string name="title_activity_part1">Crunching RxAndroid - Part 1</string> | ||
<string name="title_activity_part2">Crunching RxAndroid - Part 2</string> | ||
<string name="title_activity_part3">Crunching RxAndroid - Part 3</string> | ||
<string name="title_activity_main4">Crunching RxAndroid - Retrofit</string> | ||
<string name="title_activity_part4_detail">Crunching RxAndroid - Retrofit Detail</string> | ||
<string name="title_activity_part5">Crunching RxAndroid - RxLifecycle</string> | ||
</resources> |
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