-
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.
- Loading branch information
Showing
9 changed files
with
232 additions
and
2 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
116 changes: 116 additions & 0 deletions
116
app/src/main/java/it/tiwiz/rxjavacrunch/part6/Part6Activity.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,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); | ||
} | ||
|
||
} |
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,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> |
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,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> |
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,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> |
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