Skip to content

Commit fb50334

Browse files
author
Kaushik Gopal
committed
feat: wip: add wiring for Timing demo
1 parent c7247cf commit fb50334

File tree

5 files changed

+90
-4
lines changed

5 files changed

+90
-4
lines changed

app/src/main/java/com/morihacky/android/rxjava/MainFragment.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,14 @@ public void pseudoCacheDemo() {
116116
.replace(R.id.activity_main, new PseudoCacheConcatFragment(), this.toString())
117117
.commit();
118118
}
119+
120+
@OnClick(R.id.btn_demo_timing)
121+
public void demoTimerIntervalDelays() {
122+
getActivity().getSupportFragmentManager()
123+
.beginTransaction()
124+
.addToBackStack(this.toString())
125+
.replace(R.id.activity_main, new TimingDemoFragment(), this.toString())
126+
.commit();
127+
}
128+
119129
}

app/src/main/java/com/morihacky/android/rxjava/TimingDemoFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class TimingDemoFragment
2222
public View onCreateView(LayoutInflater inflater,
2323
@Nullable ViewGroup container,
2424
@Nullable Bundle savedInstanceState) {
25-
View layout = inflater.inflate(R.layout.fragment_timing_demo, container, false);
25+
View layout = inflater.inflate(R.layout.fragment_demo_timing, container, false);
2626
ButterKnife.inject(this, layout);
2727
return layout;
2828
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
3+
<LinearLayout
4+
android:orientation="vertical"
5+
android:layout_height="match_parent"
6+
android:layout_width="match_parent"
7+
xmlns:android="http://schemas.android.com/apk/res/android"
8+
>
9+
10+
<TableLayout
11+
android:layout_height="wrap_content"
12+
android:layout_width="match_parent"
13+
>
14+
15+
<TableRow
16+
android:layout_height="wrap_content"
17+
android:layout_width="match_parent"
18+
>
19+
20+
<Button
21+
android:id="@+id/btn_demo_timing_1"
22+
android:layout_weight="1"
23+
android:layout_height="wrap_content"
24+
android:layout_width="wrap_content"
25+
android:text="run once after a delay"
26+
/>
27+
28+
<Button
29+
android:id="@+id/btn_demo_timing_3"
30+
android:layout_weight="1"
31+
android:layout_height="wrap_content"
32+
android:layout_width="wrap_content"
33+
android:text="run at intervals (start with delay)"
34+
/>
35+
</TableRow>
36+
37+
<TableRow
38+
android:layout_height="wrap_content"
39+
android:layout_width="match_parent"
40+
>
41+
42+
<Button
43+
android:id="@+id/btn_demo_timing_2"
44+
android:layout_weight="1"
45+
android:layout_height="wrap_content"
46+
android:layout_width="wrap_content"
47+
android:text="run 5 times at specific intervals"
48+
/>
49+
50+
<Button
51+
android:id="@+id/btn_demo_timing_4"
52+
android:layout_weight="1"
53+
android:layout_height="wrap_content"
54+
android:layout_width="wrap_content"
55+
android:text="intervals (but start immediately)"
56+
/>
57+
</TableRow>
58+
</TableLayout>
59+
60+
61+
<ListView
62+
android:id="@+id/list_threading_log"
63+
android:layout_height="match_parent"
64+
android:layout_width="match_parent"
65+
/>
66+
67+
</LinearLayout>

app/src/main/res/layout/fragment_main.xml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<LinearLayout
88
android:orientation="vertical"
9-
android:layout_height="match_parent"
9+
android:layout_height="wrap_content"
1010
android:layout_width="match_parent"
1111
android:paddingTop="@dimen/activity_vertical_margin"
1212
android:paddingBottom="@dimen/activity_vertical_margin"
@@ -77,7 +77,14 @@
7777
android:id="@+id/btn_demo_pseudo_cache"
7878
android:layout_height="wrap_content"
7979
android:layout_width="match_parent"
80-
android:text="@string/btn_demo_pseudo_cache"
80+
android:text="@string/btn_demo_pseudocache"
81+
/>
82+
83+
<Button
84+
android:id="@+id/btn_demo_timing"
85+
android:layout_height="wrap_content"
86+
android:layout_width="match_parent"
87+
android:text="@string/btn_demo_timing"
8188
/>
8289
</LinearLayout>
8390
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
<string name="btn_demo_polling">Polling with RxJava</string>
1616
<string name="btn_demo_rxbus">Event Bus with RxJava</string>
1717
<string name="btn_demo_form_validation_combinel">Form Validation with CombineLatest</string>
18-
<string name="btn_demo_pseudo_cache">Pseudo cache using concat</string>
18+
<string name="btn_demo_pseudocache">Pseudo cache using concat</string>
19+
<string name="btn_demo_timing">Variations of timing/intervals/delays</string>
1920

2021
<string name="msg_demo_concurrency_schedulers">This is a demo of how long running operations can be offloaded to a background thread. After the operation is done, we resume back on the main thread. All using RxJava! \n\n To really see this shine. Hit the button multiple times and see how the button click which is a ui operation is never blocked because the long operation only runs in the background</string>
2122
<string name="msg_demo_buffer">This is a demo of how events can be accumulated using the "buffer" operation. Tap the button below repetitively and you will notice in the logs that button taps are collected over a span of 2s and printed below.</string>
@@ -26,4 +27,5 @@
2627
<string name="msg_demo_polling">This is demo of polling or making a call repeatedly with RxJava. \n\nSimple polling: Notice in the logs how a network call (simulated) is repeatedly made in the background.</string>
2728
<string name="msg_demo_rxbus_1">Tap on the below button and RxBus will listen to the events</string>
2829
<string name="msg_demo_form_comb_latest">Monitor the state of multiple observables with the combineLatest operator. The submit button uses combineLatest to monitor validity of each of the 3 inputs. Only after the 3 inputs contain valid inputs will the submit button be enabled</string>
30+
<string name="msg_demo_timing">Demo of how you can use timing/interval/delay and play with the timings of when your events are emitted</string>
2931
</resources>

0 commit comments

Comments
 (0)