Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit for the ViewPager Spike (includes a working ViewPager with Fragments) #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:theme="@android:style/Theme.Holo"
android:allowBackup="true">
<activity
android:name=".BookmarkListActivity"
android:name=".BookMarkMainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand All @@ -24,7 +24,7 @@
<activity
android:theme="@android:style/Animation"
android:name=".prefs.SettingsActivity"
android:parentActivityName=".BookmarkListActivity" >
android:parentActivityName=".BookMarkMainActivity" >
</activity>
<activity
android:name="NewBookmarkActivity">
Expand All @@ -35,7 +35,7 @@
</intent-filter>
</activity>
<activity android:name=".BookMarkDetailActivity"
android:parentActivityName=".BookmarkListActivity"/>
android:parentActivityName=".BookMarkMainActivity"/>
</application>

</manifest>
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@
<artifactId>okhttp</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.google.android</groupId>
<artifactId>support-v4</artifactId>
<version>r6</version>
</dependency>
</dependencies>

<build>
Expand Down
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions res/layout/book_mark_search_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
6 changes: 6 additions & 0 deletions res/layout/bookie_main_container_layout.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent" />
6 changes: 6 additions & 0 deletions res/layout/mybook_marks_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
9 changes: 9 additions & 0 deletions res/layout/mybookmarks_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/bookmarkListRow"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp" >

</TextView>
16 changes: 8 additions & 8 deletions res/menu/main_activity_actions.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>

<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/action_everyones_recent"
android:icon="@drawable/fa_tags"
android:title="@string/button_newest_global_text"
android:showAsAction="ifRoom"/>
<item android:id="@+id/action_recent"
android:icon="@drawable/fa_tag"
android:title="@string/button_newest_user_text"
android:showAsAction="ifRoom"/>
<!--<item android:id="@+id/action_everyones_recent"-->
<!--android:icon="@drawable/fa_tags"-->
<!--android:title="@string/button_newest_global_text"-->
<!--android:showAsAction="ifRoom"/>-->
<!--<item android:id="@+id/action_recent"-->
<!--android:icon="@drawable/fa_tag"-->
<!--android:title="@string/button_newest_user_text"-->
<!--android:showAsAction="ifRoom"/>-->
<item android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
android:title="@string/menu_search"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
package us.bmark.android;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

Expand All @@ -35,7 +28,6 @@
import retrofit.RestAdapter;
import retrofit.RetrofitError;
import retrofit.client.Response;
import us.bmark.android.prefs.SettingsActivity;
import us.bmark.android.prefs.SharedPrefsBackedUserSettings;
import us.bmark.android.utils.ErrorHandler;
import us.bmark.android.utils.IntentConstants;
Expand All @@ -49,9 +41,9 @@
import static java.net.URLEncoder.encode;
import static us.bmark.android.utils.Utils.isBlank;

public class BookmarkListActivity extends ListActivity {
public class AllBookMarksListFragment extends ListFragment {

private static final String TAG = BookmarkListActivity.class.getName();
private static final String TAG = AllBookMarksListFragment.class.getName();
private int countPP;
private BookieService service;
private UserSettings settings;
Expand All @@ -65,13 +57,14 @@ public class BookmarkListActivity extends ListActivity {
public static final int FORBIDDEN = 403;
private ErrorHandler errorHandler;

private View view;
private enum State {
ALL, MINE, SEARCH
ALL, SEARCH
}

private class BookmarkArrayAdapter extends ArrayAdapter<Bookmark> {

private static final int ROW_VIEW_ID = R.layout.list_item;
private static final int ROW_VIEW_ID = R.layout.allbookmarks_list_item;

BookmarkArrayAdapter(Context context, List<Bookmark> objects) {
super(context, ROW_VIEW_ID, objects);
Expand Down Expand Up @@ -125,7 +118,7 @@ private class ServiceCallback implements Callback<BookmarkList> {

@Override
public void success(BookmarkList bookmarkList, Response response) {
setProgressBarIndeterminateVisibility(false);
getActivity().setProgressBarIndeterminateVisibility(false);
bmarks.addAll(bookmarkList.bmarks);
Log.w(TAG, "on success for bookmark list, fetched " + bmarks.size());
adapter.notifyDataSetChanged();
Expand All @@ -134,34 +127,23 @@ public void success(BookmarkList bookmarkList, Response response) {

@Override
public void failure(RetrofitError error) {
setProgressBarIndeterminateVisibility(false);
getActivity().setProgressBarIndeterminateVisibility(false);
errorHandler.handleError(error);
}
}

@Override
public void onCreate(Bundle savedInstanceState) {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
settings = new SharedPrefsBackedUserSettings(this);
errorHandler = new JustDisplayToastErrorHandler(this,settings);
view = inflater.inflate(R.layout.allbook_marks_main, container, false);
settings = new SharedPrefsBackedUserSettings(getActivity());
errorHandler = new JustDisplayToastErrorHandler(getActivity(),settings);
countPP = getResources().getInteger(R.integer.default_number_of_bookmarks_to_get);
setUpService();
requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
setContentView(R.layout.main);
getActionBar().setDisplayHomeAsUpEnabled(false); // Hides the '<' button in the ActionBar
getActionBar().setHomeButtonEnabled(true); // Enables the 'B' icon to be tappable on the list Activity
adapter = new BookmarkArrayAdapter(this,bmarks);
adapter = new BookmarkArrayAdapter(getActivity(),bmarks);
setListAdapter(adapter);
setUpListView();
loadMoreData();
}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main_activity_actions, menu);
return super.onCreateOptionsMenu(menu);
return view;
}

private void setUpService() {
Expand All @@ -174,18 +156,14 @@ private void setUpService() {

private void refreshWithNewestGlobal() {
int nextPage = pagesLoaded;
setProgressBarIndeterminateVisibility(true);
getActivity().setProgressBarIndeterminateVisibility(true);
service.everyonesRecent(countPP, nextPage, new ServiceCallback());
}

private void refreshWithNewestUser() {
int nextPage = pagesLoaded;
setProgressBarIndeterminateVisibility(true);
service.recent(settings.getUsername(),
settings.getApiKey(),
countPP,
nextPage,
new ServiceCallback());
@Override
public void onStart() {
super.onStart();
setUpListView();
}

private void setUpListView() {
Expand Down Expand Up @@ -214,7 +192,7 @@ public boolean onItemLongClick(AdapterView<?> parent, View view,
final Bundle bundle = new Bundle();
String bmarkJson = (new Gson()).toJson(bmark);
bundle.putString(IntentConstants.EXTRAS_KEY_BMARK, bmarkJson);
final Intent intent = new Intent(BookmarkListActivity.this,
final Intent intent = new Intent(getActivity(),
BookMarkDetailActivity.class);
intent.putExtras(bundle);
startActivity(intent);
Expand All @@ -225,70 +203,6 @@ public boolean onItemLongClick(AdapterView<?> parent, View view,
lv.setOnScrollListener(new EndlessScrollListener());
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {

switch( item.getItemId() ) {
case android.R.id.home:
case R.id.action_everyones_recent:
Log.v(TAG, "global button clicked");
flipState(State.ALL);
return true;
case R.id.action_recent:
Log.v(TAG, "user button clicked");
flipState(State.MINE);
return true;
case R.id.action_settings:
Intent settingsIntent =
new Intent(BookmarkListActivity.this, SettingsActivity.class);
BookmarkListActivity.this.startActivity(settingsIntent);
return true;
case R.id.action_search:
displaySearchDialog();
default:
return super.onOptionsItemSelected(item);
}
}

private void flipState(State desiredState) {
this.state = desiredState;
bmarks = new ArrayList<Bookmark>(countPP);
adapter = new BookmarkArrayAdapter(this,bmarks);
setListAdapter(adapter);
pagesLoaded = 0;
getListView().setOnScrollListener(new EndlessScrollListener());

loadMoreData();
}

private void displaySearchDialog() {
AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle(R.string.search_dialog_title);
alert.setMessage(R.string.search_dialog_message);

final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton(R.string.search_dialog_positive_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
searchTerms = input.getText().toString();
flipState(State.SEARCH);
}
});

alert.setNegativeButton(R.string.search_dialog_cancel_button, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing
}
});

alert.show();
}

private void refreshWithSearch() {
String terms;
try {
Expand All @@ -297,7 +211,7 @@ private void refreshWithSearch() {
Log.e(TAG,"UTF-8 not supported?",e);
return;
}
setProgressBarIndeterminateVisibility(true);
getActivity().setProgressBarIndeterminateVisibility(true);
final int nextPage = pagesLoaded;
service.search(settings.getUsername(),settings.getApiKey(),
terms,countPP,nextPage,
Expand All @@ -311,12 +225,12 @@ public void success(SearchResult searchResult, Response response) {
adapter.notifyDataSetChanged();
pagesLoaded++;
}
setProgressBarIndeterminateVisibility(false);
getActivity().setProgressBarIndeterminateVisibility(false);
}

@Override
public void failure(RetrofitError error) {
setProgressBarIndeterminateVisibility(false);
getActivity().setProgressBarIndeterminateVisibility(false);
errorHandler.handleError(error);
}
});
Expand All @@ -325,8 +239,6 @@ public void failure(RetrofitError error) {
private void loadMoreData() {
switch(state) {
case ALL : refreshWithNewestGlobal(); break;
case MINE : refreshWithNewestUser(); break;
case SEARCH : refreshWithSearch(); break;
}
}

Expand Down
Loading