Skip to content

Commit c348105

Browse files
author
Arnav Gupta
committed
add next and previous buttons on InstaPaper Viewer
1 parent 63dadc1 commit c348105

File tree

4 files changed

+60
-17
lines changed

4 files changed

+60
-17
lines changed

App/src/main/java/in/ac/dtu/subtlenews/InstapaperViewer.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import android.annotation.TargetApi;
66
import android.app.Activity;
7+
import android.content.DialogInterface;
78
import android.content.Intent;
89
import android.os.Build;
910
import android.os.Bundle;
@@ -13,9 +14,15 @@
1314
import android.view.MenuItem;
1415
import android.support.v4.app.NavUtils;
1516
import android.webkit.WebView;
17+
import android.widget.Button;
1618
import android.widget.FrameLayout;
1719
import android.widget.LinearLayout;
1820

21+
import org.json.JSONException;
22+
import org.json.JSONObject;
23+
24+
import java.util.ArrayList;
25+
1926
/**
2027
* An example full-screen activity that shows and hides the system UI (i.e.
2128
* status bar and navigation/system bar) with user interaction.
@@ -24,6 +31,9 @@
2431
*/
2532
public class InstapaperViewer extends Activity {
2633
public String summaryUrl = "http://google.com";
34+
public Integer urlId = 0;
35+
public ArrayList<String> urlList;
36+
2737

2838
/**
2939
* Whether or not the system UI should be auto-hidden after
@@ -62,13 +72,18 @@ protected void onCreate(Bundle savedInstanceState) {
6272

6373
Bundle extras = getIntent().getExtras();
6474
if (extras != null) {
65-
summaryUrl = extras.getString("URL");
75+
urlId = extras.getInt("URLID");
76+
urlList = extras.getStringArrayList("URLList");
77+
6678
}
6779
final WebView instapaperView = (WebView) findViewById(R.id.instapaper_viewer);
6880

6981
final View controlsView = findViewById(R.id.fullscreen_content_controls);
7082
final View contentView = findViewById(R.id.instapaper_viewer);
7183

84+
final Button prevButton = (Button) findViewById(R.id.summary_prev_button);
85+
final Button nextButton = (Button) findViewById(R.id.summary_next_button);
86+
7287
// Set up an instance of SystemUiHider to control the system UI for
7388
// this activity.
7489
mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
@@ -135,10 +150,38 @@ public void onClick(View view) {
135150
// Upon interacting with UI controls, delay any scheduled hide()
136151
// operations to prevent the jarring behavior of controls going away
137152
// while interacting with the UI.
138-
findViewById(R.id.summary_back_button).setOnTouchListener(mDelayHideTouchListener);
139-
153+
prevButton.setOnTouchListener(mDelayHideTouchListener);
154+
nextButton.setOnTouchListener(mDelayHideTouchListener);
140155

156+
try {
157+
summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(urlId);
158+
} catch (Exception e) {
159+
e.printStackTrace();
160+
}
141161
instapaperView.loadUrl(summaryUrl);
162+
prevButton.setOnClickListener(new View.OnClickListener() {
163+
@Override
164+
public void onClick(View view) {
165+
try {
166+
summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(--urlId);
167+
} catch (Exception e) {
168+
e.printStackTrace();
169+
}
170+
instapaperView.loadUrl(summaryUrl);
171+
}
172+
});
173+
nextButton.setOnClickListener(new View.OnClickListener() {
174+
@Override
175+
public void onClick(View view) {
176+
try {
177+
summaryUrl = "http://www.instapaper.com/text?u=" + urlList.get(++urlId);
178+
} catch (Exception e) {
179+
e.printStackTrace();
180+
}
181+
instapaperView.loadUrl(summaryUrl);
182+
}
183+
});
184+
142185
}
143186

144187
@Override

App/src/main/java/in/ac/dtu/subtlenews/MainFragment.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public class MainFragment extends Fragment {
4848
private static final String TAG = "MAIN_FRAGMENT";
4949

5050
private int sNumber ;
51+
public ArrayList<String> urlArray = new ArrayList<String>();
5152

5253
View rootView;
5354

@@ -130,6 +131,7 @@ protected ArrayList<JSONObject> doInBackground(Void... v) {
130131

131132
if(obj.getString("category").equals(Utils.categoryMap[sNumber - 1])){
132133
selectedCategoryList.add(obj);
134+
urlArray.add(obj.getString(TAG_LINK));
133135
}
134136

135137
}
@@ -169,22 +171,12 @@ public void onItemClick(AdapterView<?> adapterView, View view, final int i, long
169171
.setMessage(fArrayList.get(i).getString(TAG_SUMMARY))
170172
.setPositiveButton("Instapaper", new DialogInterface.OnClickListener() {
171173
public void onClick(DialogInterface dialog, int id) {
172-
/* TODO :
173-
USE webview to implement in-app browser instead of this
174174

175175

176-
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
177-
startActivity(browserIntent);
178-
*/
179-
String url = "http://www.google.com";
180-
try {
181-
url = "http://www.instapaper.com/text?u=" + fArrayList.get(i).getString(TAG_LINK);
182-
} catch (JSONException e) {
183-
e.printStackTrace();
184-
}
185176

186177
Intent instapaper = new Intent(getActivity(), InstapaperViewer.class);
187-
instapaper.putExtra("URL", url);
178+
instapaper.putExtra("URLID", i);
179+
instapaper.putExtra("URLList", urlArray);
188180
startActivity(instapaper);
189181

190182

App/src/main/res/layout/activity_instapaper_viewer.xml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,18 @@
2929
android:orientation="horizontal"
3030
tools:ignore="UselessParent">
3131

32-
<Button android:id="@+id/summary_back_button"
32+
<Button android:id="@+id/summary_prev_button"
3333
style="?metaButtonBarButtonStyle"
3434
android:layout_width="0dp"
3535
android:layout_height="wrap_content"
3636
android:layout_weight="1"
37-
android:text="@string/summary_back_button" />
37+
android:text="@string/summary_prev_button" />
38+
<Button android:id="@+id/summary_next_button"
39+
style="?metaButtonBarButtonStyle"
40+
android:layout_width="0dp"
41+
android:layout_height="wrap_content"
42+
android:layout_weight="1"
43+
android:text="@string/summary_next_button" />
3844

3945
</LinearLayout>
4046
</FrameLayout>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,7 @@
1414
<string name="title_activity_instapaper_viewer">InstapaperViewer</string>
1515
<string name="summary_back_button">Back</string>
1616
<string name="dummy_content">DUMMY\nCONTENT</string>
17+
<string name="summary_next_button">Next</string>
18+
<string name="summary_prev_button">Prev</string>
1719

1820
</resources>

0 commit comments

Comments
 (0)