Skip to content

Commit

Permalink
Merge branch 'release/Part6'
Browse files Browse the repository at this point in the history
  • Loading branch information
tiwiz committed Jan 19, 2016
2 parents d15373e + 1a5c4a5 commit b5207b8
Show file tree
Hide file tree
Showing 9 changed files with 232 additions and 2 deletions.
7 changes: 5 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,16 @@ retrolambda {

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:23.1.0'
compile 'com.android.support:recyclerview-v7:23.1.0'
compile 'com.android.support:appcompat-v7:23.1.1'
compile 'com.android.support:recyclerview-v7:23.1.1'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'io.reactivex:rxandroid:1.0.1'
compile 'io.reactivex:rxjava:1.0.14'
compile 'com.android.support:design:23.1.0'
compile 'com.squareup.retrofit:retrofit:1.9.0'
compile 'com.trello:rxlifecycle:0.3.0'
compile 'com.trello:rxlifecycle-components:0.3.0'
compile 'com.jakewharton.rxbinding:rxbinding:0.3.0'
compile 'com.jakewharton.rxbinding:rxbinding-appcompat-v7:0.3.0'
compile 'com.jakewharton.rxbinding:rxbinding-design:0.3.0'
}
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@
android:name="android.support.PARENT_ACTIVITY"
android:value="it.tiwiz.rxjavacrunch.MainActivity" />
</activity>
<activity
android:name=".part6.Part6Activity"
android:label="@string/title_activity_part6"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="it.tiwiz.rxjavacrunch.MainActivity" />
</activity>
</application>

</manifest>
5 changes: 5 additions & 0 deletions app/src/main/java/it/tiwiz/rxjavacrunch/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import it.tiwiz.rxjavacrunch.part3.Part3Activity;
import it.tiwiz.rxjavacrunch.part4.Part4Activity;
import it.tiwiz.rxjavacrunch.part5.Part5Activity;
import it.tiwiz.rxjavacrunch.part6.Part6Activity;


public class MainActivity extends AppCompatActivity implements View.OnClickListener{
Expand All @@ -31,6 +32,7 @@ private void wireUi() {
setTapListener(R.id.btnPart3);
setTapListener(R.id.btnPart4);
setTapListener(R.id.btnPart5);
setTapListener(R.id.btnPart6);
}

private void setTapListener(int viewId) {
Expand Down Expand Up @@ -61,6 +63,9 @@ private Intent getLaunchIntentFor(int viewId) {
case R.id.btnPart5:
launchIntent = new Intent(this, Part5Activity.class);
break;
case R.id.btnPart6:
launchIntent = new Intent(this, Part6Activity.class);
break;
}

return launchIntent;
Expand Down
116 changes: 116 additions & 0 deletions app/src/main/java/it/tiwiz/rxjavacrunch/part6/Part6Activity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package it.tiwiz.rxjavacrunch.part6;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.jakewharton.rxbinding.support.design.widget.RxSnackbar;
import com.jakewharton.rxbinding.support.v7.widget.RxToolbar;
import com.jakewharton.rxbinding.view.RxView;
import com.jakewharton.rxbinding.widget.RxTextView;

import it.tiwiz.rxjavacrunch.R;

public class Part6Activity extends AppCompatActivity {
TextView responseTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_part6);
responseTextView = (TextView) findViewById(R.id.response);

manageToolbar();
manageFloatingActionButton();
manageEditTexts();
}

private void manageToolbar() {
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);

/**
* Here, we manage the two events of the toolbar
**/
RxToolbar.itemClicks(toolbar).subscribe(this::onToolbarItemClicked);
RxToolbar.navigationClicks(toolbar).subscribe(aVoid -> onToolbarNavigationClicked());
}

private void onToolbarItemClicked(MenuItem menuItem) {
String message = "Item \"" + menuItem.getTitle() + "\" clicked";
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
}

private void onToolbarNavigationClicked() {
Toast.makeText(this, "Navigation item clicked", Toast.LENGTH_SHORT).show();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.part6, menu);
return true;
}

private void manageFloatingActionButton() {
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
RxView.clicks(fab).subscribe(aVoid -> onFabClicked());
}

private void onFabClicked() {
Snackbar testSnackbar = Snackbar.make(findViewById(android.R.id.content), "Snackbar clicked", Snackbar.LENGTH_SHORT);
testSnackbar.show();
/**
* Managing the {@link Snackbar} is not that hard either
*/
RxSnackbar.dismisses(testSnackbar).subscribe(this::onSnackbarDismissed);
}

private void onSnackbarDismissed(Integer integer) {
String text = "Snackbar dismissed with code " + integer;
Toast.makeText(this, text, Toast.LENGTH_SHORT).show();
}

private void manageEditTexts() {
EditText usualApproachEditText, reactiveApproachEditText;

usualApproachEditText = (EditText) findViewById(R.id.editTextUsualApproach);

usualApproachEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {

}

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
onNewTextChanged(s);
}

@Override
public void afterTextChanged(Editable s) {

}
});

/**
* Here, we see how it can be easy to manage text changes with RxBindings
*/
reactiveApproachEditText = (EditText) findViewById(R.id.editTextReactiveApproach);
RxTextView.textChanges(reactiveApproachEditText).subscribe(this::onNewTextChanged);
}

private void onNewTextChanged(CharSequence text) {
responseTextView.setText(text);
}

}
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,10 @@
android:text="Part 5"
android:layout_below="@id/btnPart4"/>

<Button
style="@style/RxButton"
android:id="@+id/btnPart6"
android:text="Part 6"
android:layout_below="@id/btnPart5"/>

</RelativeLayout>
34 changes: 34 additions & 0 deletions app/src/main/res/layout/activity_part6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="it.tiwiz.rxjavacrunch.part6.Part6Activity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_part6" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>
41 changes: 41 additions & 0 deletions app/src/main/res/layout/content_part6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="it.tiwiz.rxjavacrunch.part6.Part6Activity"
tools:showIn="@layout/activity_part6">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Usual approach"/>

<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/editTextUsualApproach"/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Reactive approach"/>

<EditText
android:layout_width="match_parent"
android:layout_height="48dp"
android:id="@+id/editTextReactiveApproach"/>

<TextView
android:id="@+id/response"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

</LinearLayout>
15 changes: 15 additions & 0 deletions app/src/main/res/menu/part6.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<item android:icon="@android:drawable/ic_input_add"
android:id="@+id/menuInputAdd"
android:title="+"
app:showAsAction="always"/>

<item android:icon="@android:drawable/ic_input_delete"
android:id="@+id/menuInputDelete"
android:title="-"
app:showAsAction="always"/>

</menu>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<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>
<string name="title_activity_part6">Part6Activity</string>
</resources>

0 comments on commit b5207b8

Please sign in to comment.