Skip to content

Commit

Permalink
Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
DerekV committed Nov 3, 2013
1 parent 48241ee commit c6a5f7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
5 changes: 5 additions & 0 deletions android/util/annotations.xml
@@ -0,0 +1,5 @@
<root>
<item name='android.util.Log'>
<annotation name='org.jetbrains.annotations.NonNls' />
</item>
</root>
49 changes: 22 additions & 27 deletions src/main/java/us/bmark/android/BookmarkListActivity.java
Expand Up @@ -47,26 +47,27 @@

public class BookmarkListActivity extends ListActivity {

private static final String TAG = BookmarkListActivity.class.getName();
private int countPP;
private BookieService service;
private UserSettings settings;
private List<Bookmark> bmarks =
new ArrayList<Bookmark>();
private String searchTerms;
private int pagesLoaded = 0;
private int pagesLoaded;
private State state = State.ALL;
private BookmarkArrayAdapter adapter;

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


private class BookmarkArrayAdapter extends ArrayAdapter<Bookmark> {

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

public BookmarkArrayAdapter(Context context, List<Bookmark> objects) {
BookmarkArrayAdapter(Context context, List<Bookmark> objects) {
super(context, ROW_VIEW_ID, objects);
}

Expand All @@ -91,17 +92,10 @@ public View getView(int position, View convertView, ViewGroup parent) {


private class EndlessScrollListener implements AbsListView.OnScrollListener {

private int visibleThreshold = 5;
private static final int THRESH = 0;
private int previousTotal = 0;
private boolean loading = true;

public EndlessScrollListener() {
}
public EndlessScrollListener(int visibleThreshold) {
this.visibleThreshold = visibleThreshold;
}

@Override
public void onScroll(AbsListView view, int firstVisibleItem,
int visibleItemCount, int totalItemCount) {
Expand All @@ -111,9 +105,7 @@ public void onScroll(AbsListView view, int firstVisibleItem,
previousTotal = totalItemCount;
}
}
if (!loading && ((totalItemCount - visibleItemCount) <= (firstVisibleItem + visibleThreshold))) {
// I load the next page of gigs using a background task,
// but you can call any function here.
if (!loading && ((totalItemCount - visibleItemCount) <= (firstVisibleItem + THRESH))) {
loadMoreData();
loading = true;
}
Expand All @@ -129,14 +121,14 @@ private class ServiceCallback implements Callback<BookmarkList> {
@Override
public void success(BookmarkList bookmarkList, Response response) {
bmarks.addAll(bookmarkList.bmarks);
Log.w("bmark", "on success for bookmark list, fetched " + bmarks.size());
Log.w(TAG, "on success for bookmark list, fetched " + bmarks.size());
adapter.notifyDataSetChanged();
pagesLoaded++;
}

@Override
public void failure(RetrofitError error) {
Log.w("bmark", error.getMessage());
Log.w(TAG, error.getMessage());
// TODO
}
}
Expand Down Expand Up @@ -164,10 +156,10 @@ public boolean onCreateOptionsMenu(Menu menu) {

private void setUpService() {
String serverUrl = settings.getBaseUrl();
RestAdapter adapter = new RestAdapter.Builder()
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(serverUrl).build();
adapter.setLogLevel(RestAdapter.LogLevel.FULL);
service = adapter.create(BookieService.class);
restAdapter.setLogLevel(RestAdapter.LogLevel.FULL);
service = restAdapter.create(BookieService.class);
}

private void refreshWithNewestGlobal() {
Expand All @@ -190,9 +182,9 @@ private void setUpListView() {
lv.setTextFilterEnabled(true);

lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// open link in browser
final Bookmark bmark = ((Bookmark) parent.getAdapter().getItem(position));

final Uri uri = Uri.parse(BookieServiceUtils.urlForRedirect(bmark,
Expand All @@ -203,12 +195,13 @@ public void onItemClick(AdapterView<?> parent, View view,
});

lv.setOnItemLongClickListener(new OnItemLongClickListener() {
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view,
int position, long id) {
final Bookmark bmark = ((Bookmark) parent.getAdapter().getItem(position));
final Bundle bundle = new Bundle();
String bmarkJson = (new Gson()).toJson(bmark);
bundle.putString("bmark", bmarkJson);
bundle.putString(TAG, bmarkJson);
final Intent intent = new Intent(BookmarkListActivity.this,
BookMarkDetailActivity.class);
intent.putExtras(bundle);
Expand All @@ -226,11 +219,11 @@ public boolean onOptionsItemSelected(MenuItem item) {

switch( item.getItemId() ) {
case R.id.action_everyones_recent:
Log.v("bmark", "glabal bttn clicked");
Log.v(TAG, "global button clicked");
flipState(State.ALL);
return true;
case R.id.action_recent:
Log.v("bmark", "user bttn clicked");
Log.v(TAG, "user button clicked");
flipState(State.MINE);
return true;
case R.id.action_settings:
Expand Down Expand Up @@ -266,13 +259,15 @@ private void displaySearchDialog() {
alert.setView(input);

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

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int whichButton) {
// Do nothing
}
Expand All @@ -282,7 +277,7 @@ public void onClick(DialogInterface dialog, int whichButton) {
}

private void refreshWithSearch() {
String terms = null;
String terms;
try {
terms = encode(searchTerms, "UTF-8");
} catch (UnsupportedEncodingException e) {
Expand All @@ -297,14 +292,14 @@ private void refreshWithSearch() {
public void success(SearchResult searchResult, Response response) {
bmarks.addAll(searchResult.search_results);

Log.w("bmark", "on success search :" + bmarks.size());
Log.w(TAG, "on success search :" + bmarks.size());
adapter.notifyDataSetChanged();
pagesLoaded=nextPage;
}

@Override
public void failure(RetrofitError error) {
Log.w("bmark", error.getMessage());
Log.w(TAG, error.getMessage());
// TODO
}
});
Expand Down

0 comments on commit c6a5f7b

Please sign in to comment.