Skip to content

Commit 5021e08

Browse files
author
Mohit Pandey
committed
log/comment removal
1 parent 97e1e9d commit 5021e08

File tree

3 files changed

+18
-69
lines changed

3 files changed

+18
-69
lines changed

ReactiveAndroid/src/main/java/com/mohit/reactiveandroid/GridAdapter.java

+9-35
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,15 @@
22

33

44
import android.content.Context;
5-
import android.util.Log;
65
import android.view.LayoutInflater;
76
import android.view.View;
87
import android.view.ViewGroup;
98
import android.widget.BaseAdapter;
109
import android.widget.ImageView;
1110
import android.widget.TextView;
12-
import android.widget.Toast;
1311
import com.squareup.picasso.Picasso;
1412
import rx.Observable;
1513
import rx.android.schedulers.AndroidSchedulers;
16-
import rx.functions.Action1;
17-
import rx.functions.Func1;
1814

1915
import java.util.ArrayList;
2016
import java.util.List;
@@ -23,43 +19,21 @@ public class GridAdapter extends BaseAdapter {
2319

2420
private Context context;
2521
private static final NetworkManager networkManager = new NetworkManager();
26-
private static final String TAG = "r3ader";
27-
2822
private List<Movie> movies = new ArrayList<Movie>();
2923

30-
public GridAdapter(Context context,String source) {
24+
public GridAdapter(Context context, String source) {
3125
this.context = context;
3226
networkManager.getData(source)
33-
.flatMap(data -> new FeedParser().getMovies(data))
34-
.observeOn(AndroidSchedulers.mainThread())
35-
.onErrorFlatMap(e->Observable.empty())
36-
.subscribe((Movies m) -> {
37-
movies.clear();
38-
movies.addAll(m.movies);
39-
notifyDataSetChanged();
40-
});
27+
.flatMap(data -> new FeedParser().getMovies(data))
28+
.observeOn(AndroidSchedulers.mainThread())
29+
.onErrorFlatMap(e -> Observable.empty())
30+
.subscribe((Movies m) -> {
31+
movies.clear();
32+
movies.addAll(m.movies);
33+
notifyDataSetChanged();
34+
});
4135
}
4236

43-
/*
44-
.flatMap(new Func1<String, Observable<Movies>>() {
45-
@Override
46-
public Observable<Movies> call(String data) {
47-
return new FeedParser().getMovies(data);
48-
}
49-
})
50-
*/
51-
// public void setAdapterSource(String url) {
52-
// Log.e(TAG,"Why is this getting called");
53-
// networkManager.getData(url)
54-
// .flatMap(data -> new FeedParser().getMovies(data))
55-
// .observeOn(AndroidSchedulers.mainThread())
56-
// .subscribe((Movies m) -> {
57-
// movies.clear();
58-
// movies.addAll(m.movies);
59-
// notifyDataSetChanged();
60-
// });
61-
// }
62-
6337
public int getCount() {
6438
return movies.size();
6539
}

ReactiveAndroid/src/main/java/com/mohit/reactiveandroid/MainActivity.java

+8-11
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,9 @@
55
import android.os.Bundle;
66
import android.support.v13.app.FragmentPagerAdapter;
77
import android.support.v4.view.ViewPager;
8-
import android.util.Log;
98
import android.view.*;
109
import android.widget.GridView;
1110

12-
import java.util.Locale;
13-
1411
public class MainActivity extends Activity implements ActionBar.TabListener {
1512

1613
/**
@@ -42,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {
4239
int sections = 4;
4340
// Create the adapter that will return a fragment for each of the three
4441
// primary sections of the activity.
45-
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this,sections);
42+
mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager(), this, sections);
4643

4744
// Set up the ViewPager with the sections adapter.
4845
mViewPager = (ViewPager) findViewById(R.id.pager);
@@ -57,8 +54,8 @@ public void onPageSelected(int position) {
5754
actionBar.setSelectedNavigationItem(position);
5855
}
5956
});
60-
String [] sectionNames = {"In Theaters","DVD Releases","Opening","Box Office"};
61-
for(int i=0;i<sections;i++) {
57+
String[] sectionNames = {"In Theaters", "DVD Releases", "Opening", "Box Office"};
58+
for (int i = 0; i < sections; i++) {
6259
actionBar.addTab(actionBar.newTab().setText(sectionNames[i]).setTabListener(this));
6360
}
6461
}
@@ -114,7 +111,7 @@ public class SectionsPagerAdapter extends FragmentPagerAdapter {
114111
"http://api.rottentomatoes.com/api/public/v1.0/lists/movies/box_office.json?page_limit=24&page=1&country=us&apikey="
115112
};
116113

117-
public SectionsPagerAdapter(FragmentManager fm, Context context,int sections) {
114+
public SectionsPagerAdapter(FragmentManager fm, Context context, int sections) {
118115
super(fm);
119116
this.context = context;
120117
this.sections = sections;
@@ -124,8 +121,8 @@ public SectionsPagerAdapter(FragmentManager fm, Context context,int sections) {
124121
public Fragment getItem(int position) {
125122
// getItem is called to instantiate the fragment for the given page.
126123
// Return a PlaceholderFragment (defined as a static inner class below).
127-
GridAdapter gridAdapter = new GridAdapter(this.context,LIST[position]);
128-
return PlaceholderFragment.newInstance(position, context,gridAdapter);
124+
GridAdapter gridAdapter = new GridAdapter(this.context, LIST[position]);
125+
return PlaceholderFragment.newInstance(position, context, gridAdapter);
129126
}
130127

131128
@Override
@@ -147,11 +144,12 @@ public static class PlaceholderFragment extends Fragment {
147144

148145
private int position;
149146
private GridAdapter gridAdapter;
147+
150148
/**
151149
* Returns a new instance of this fragment for the given section
152150
* number.
153151
*/
154-
public static PlaceholderFragment newInstance(int sectionNumber, Context context,GridAdapter gridAdapter) {
152+
public static PlaceholderFragment newInstance(int sectionNumber, Context context, GridAdapter gridAdapter) {
155153
PlaceholderFragment fragment = new PlaceholderFragment();
156154
Bundle args = new Bundle();
157155
args.putInt(ARG_SECTION_NUMBER, sectionNumber);
@@ -168,7 +166,6 @@ public PlaceholderFragment() {
168166
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
169167
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
170168
GridView gridview = (GridView) rootView.findViewById(R.id.gridView);
171-
Log.e(TAG,"Create view" + position);
172169
gridview.setAdapter(gridAdapter);
173170
return rootView;
174171
}

ReactiveAndroid/src/main/java/com/mohit/reactiveandroid/NetworkManager.java

+1-23
Original file line numberDiff line numberDiff line change
@@ -28,37 +28,16 @@ public class NetworkManager {
2828

2929
private OkHttpClient client = new OkHttpClient();
3030

31-
private static final String TAG = "r3ader";
31+
private static final String TAG = "reactive";
3232

3333
public NetworkManager() {
3434
}
3535

3636
public Observable<String> getData(final String url) {
37-
38-
/*
39-
.onErrorReturn(e->{
40-
return "{movies:[]}";
41-
});
42-
*/
4337
return Async.start(()->getContent(url),Schedulers.io());
44-
// return Observable.create((Observer<? super String> observer) ->{
45-
// try {
46-
// Log.d("r3ader", "downloading on "+Thread.currentThread().toString());
47-
// String data = getContent(url);
48-
// Log.d("r3ader", "done downloading on "+Thread.currentThread().toString());
49-
// observer.onNext(data);
50-
// observer.onCompleted();
51-
// } catch (Exception e) {
52-
// observer.onError(e);
53-
// }
54-
//
55-
// return Subscriptions.empty();
56-
// })
57-
// .subscribeOn(Schedulers.io());
5838
}
5939

6040
public String getContent(String urlString) {
61-
Log.e(TAG,"calling "+urlString);
6241
try {
6342
HttpURLConnection connection = client.open(new URL(urlString));
6443
byte [] bytes = readData(connection.getInputStream(), connection);
@@ -76,7 +55,6 @@ private byte[] readData(InputStream inputStream, HttpURLConnection connection) t
7655
byte[] data = new byte[0];
7756
final int contentLength = connection.getContentLength();
7857
if (contentLength > 0) {
79-
Log.d(TAG,"length "+contentLength);
8058
outputStream = new ByteArrayOutputStream(contentLength);
8159
} else {
8260
outputStream = new ByteArrayOutputStream();

0 commit comments

Comments
 (0)