forked from zxing/zxing
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Preload bookmarks instead of holding open cursor to avoid concurrent …
…modification; no longer that slow that it must be avoided on the UI thread
- Loading branch information
Showing
2 changed files
with
30 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,10 +16,11 @@ | |
|
||
package com.google.zxing.client.android.share; | ||
|
||
import java.util.List; | ||
|
||
import com.google.zxing.client.android.R; | ||
|
||
import android.content.Context; | ||
import android.database.Cursor; | ||
import android.view.LayoutInflater; | ||
import android.view.View; | ||
import android.view.ViewGroup; | ||
|
@@ -36,23 +37,23 @@ | |
* @author [email protected] (Daniel Switkin) | ||
*/ | ||
final class BookmarkAdapter extends BaseAdapter { | ||
|
||
private final Context context; | ||
private final Cursor cursor; | ||
private final List<String[]> titleURLs; | ||
|
||
BookmarkAdapter(Context context, Cursor cursor) { | ||
BookmarkAdapter(Context context, List<String[]> titleURLs) { | ||
this.context = context; | ||
this.cursor = cursor; | ||
this.titleURLs = titleURLs; | ||
} | ||
|
||
@Override | ||
public int getCount() { | ||
return cursor.isClosed() ? 0 : cursor.getCount(); | ||
return titleURLs.size(); | ||
} | ||
|
||
@Override | ||
public Object getItem(int index) { | ||
// Not used, so no point in retrieving it. | ||
return null; | ||
return titleURLs.get(index); | ||
} | ||
|
||
@Override | ||
|
@@ -69,14 +70,9 @@ public View getView(int index, View view, ViewGroup viewGroup) { | |
LayoutInflater factory = LayoutInflater.from(context); | ||
layout = factory.inflate(R.layout.bookmark_picker_list_item, viewGroup, false); | ||
} | ||
|
||
if (!cursor.isClosed()) { | ||
cursor.moveToPosition(index); | ||
CharSequence title = cursor.getString(BookmarkPickerActivity.TITLE_COLUMN); | ||
((TextView) layout.findViewById(R.id.bookmark_title)).setText(title); | ||
CharSequence url = cursor.getString(BookmarkPickerActivity.URL_COLUMN); | ||
((TextView) layout.findViewById(R.id.bookmark_url)).setText(url); | ||
} // Otherwise... just don't update as the object is shutting down | ||
String[] titleURL = titleURLs.get(index); | ||
((TextView) layout.findViewById(R.id.bookmark_title)).setText(titleURL[0]); | ||
((TextView) layout.findViewById(R.id.bookmark_url)).setText(titleURL[1]); | ||
return layout; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters