diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-10-26 14:52:38 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-10-26 14:52:38 +0200 |
| commit | e054988257da663b6c998cc2c0da84cf264bc23b (patch) | |
| tree | 97d9aba71e004ad590b9519d50e5c715c7f8d6b2 /main/src/cgeo/geocaching/PocketQueryList.java | |
| parent | 88d07a7a59fa7e8ceb93d2b219fd8e2c593caecd (diff) | |
| parent | bd09f1887a8e6a8e9b919d4605c04155a3e73760 (diff) | |
| download | cgeo-e054988257da663b6c998cc2c0da84cf264bc23b.zip cgeo-e054988257da663b6c998cc2c0da84cf264bc23b.tar.gz cgeo-e054988257da663b6c998cc2c0da84cf264bc23b.tar.bz2 | |
Merge remote-tracking branch 'mucek4/fix2830'
* fix HTML parsing
* simplify activity API
* disable the action for non premium members
Diffstat (limited to 'main/src/cgeo/geocaching/PocketQueryList.java')
| -rw-r--r-- | main/src/cgeo/geocaching/PocketQueryList.java | 125 |
1 files changed, 125 insertions, 0 deletions
diff --git a/main/src/cgeo/geocaching/PocketQueryList.java b/main/src/cgeo/geocaching/PocketQueryList.java new file mode 100644 index 0000000..e1a921c --- /dev/null +++ b/main/src/cgeo/geocaching/PocketQueryList.java @@ -0,0 +1,125 @@ +package cgeo.geocaching; + +import cgeo.geocaching.activity.ActivityMixin; +import cgeo.geocaching.connector.gc.GCParser; +import cgeo.geocaching.utils.RunnableWithArgument; + +import android.app.Activity; +import android.app.AlertDialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.res.Resources; +import android.os.Handler; +import android.os.Message; + +import java.util.List; + +public final class PocketQueryList { + + private final String guid; + private final int maxCaches; + private final String name; + + public PocketQueryList(String guid, String name, int maxCaches) { + this.guid = guid; + this.name = name; + this.maxCaches = maxCaches; + } + + public static class UserInterface { + + List<PocketQueryList> pocketQueryList = null; + RunnableWithArgument<PocketQueryList> runAfterwards; + + private Handler loadPocketQueryHandler = new Handler() { + + @Override + public void handleMessage(Message msg) { + if ((pocketQueryList == null) || (pocketQueryList.size() == 0)) { + if (waitDialog != null) { + waitDialog.dismiss(); + } + + ActivityMixin.showToast(activity, res.getString(R.string.warn_no_pocket_query_found)); + + return; + } + + if (waitDialog != null) { + waitDialog.dismiss(); + } + + final CharSequence[] items = new CharSequence[pocketQueryList.size()]; + + for (int i = 0; i < pocketQueryList.size(); i++) { + PocketQueryList pq = pocketQueryList.get(i); + + items[i] = pq.name + " (" + pq.maxCaches + ")"; + } + + AlertDialog.Builder builder = new AlertDialog.Builder(activity); + builder.setTitle(res.getString(R.string.search_pocket_select)); + builder.setItems(items, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialogInterface, int itemId) { + final PocketQueryList query = pocketQueryList.get(itemId); + dialogInterface.dismiss(); + runAfterwards.run(query); + } + }); + builder.create().show(); + + } + }; + + private class LoadPocketQueryListThread extends Thread { + final private Handler handler; + + public LoadPocketQueryListThread(Handler handlerIn) { + handler = handlerIn; + } + + @Override + public void run() { + pocketQueryList = GCParser.searchPocketQueryList(); + handler.sendMessage(Message.obtain()); + } + } + + private final Activity activity; + private final CgeoApplication app; + private final Resources res; + private ProgressDialog waitDialog = null; + + public UserInterface(final Activity activity) { + this.activity = activity; + app = CgeoApplication.getInstance(); + res = app.getResources(); + } + + public void promptForListSelection(final RunnableWithArgument<PocketQueryList> runAfterwards) { + + this.runAfterwards = runAfterwards; + + waitDialog = ProgressDialog.show(activity, res.getString(R.string.search_pocket_title), res.getString(R.string.search_pocket_loading), true, true); + + LoadPocketQueryListThread thread = new LoadPocketQueryListThread(loadPocketQueryHandler); + thread.start(); + } + + + } + + public String getGuid() { + return guid; + } + + public int getMaxCaches() { + return maxCaches; + } + + public String getName() { + return name; + } + +} |
