Permalink
Browse files

Something wasn't quite right, attempting something of a remerge

  • Loading branch information...
1 parent b8374f0 commit c8581c959f2f58d9068a69b3f31d5243e5450b33 U-Poseidon\Devon committed Mar 19, 2012
@@ -3,6 +3,7 @@
import org.evilsoft.pathfinder.reference.db.psrd.CharacterAdapter;
import org.evilsoft.pathfinder.reference.db.psrd.PsrdDbAdapter;
import org.evilsoft.pathfinder.reference.db.user.PsrdUserDbAdapter;
+
import android.app.ActionBar;
import android.app.SearchManager;
import android.content.Context;
@@ -11,12 +12,11 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
-import android.util.Log;
+import android.support.v4.widget.SimpleCursorAdapter;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.SearchView;
-import android.widget.SimpleCursorAdapter;
public class DetailsActivity extends FragmentActivity {
private PsrdDbAdapter dbAdapter;
@@ -30,9 +30,10 @@ public void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.details);
Intent launchingIntent = getIntent();
- final DetailsViewFragment viewer = (DetailsViewFragment) getSupportFragmentManager().findFragmentById(
- R.id.details_view_fragment);
- DetailsListFragment list = (DetailsListFragment) getSupportFragmentManager().findFragmentById(R.id.details_list_fragment);
+ final DetailsViewFragment viewer = (DetailsViewFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.details_view_fragment);
+ DetailsListFragment list = (DetailsListFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.details_list_fragment);
String newUri;
if (Intent.ACTION_SEARCH.equals(launchingIntent.getAction())) {
String query = launchingIntent.getStringExtra(SearchManager.QUERY);
@@ -55,12 +56,12 @@ public void onCreate(Bundle savedInstanceState) {
action.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
CharacterAdapter ca = new CharacterAdapter(new PsrdUserDbAdapter(this));
SimpleCursorAdapter sca = new SimpleCursorAdapter(
- this,
- android.R.layout.simple_spinner_dropdown_item,
- ca.fetchCharacterList(), // this returns a cursor and won't be requeried automatically!
- new String[] { "name" },
- new int[] { android.R.id.text1 },
- 0);
+ this,
+ android.R.layout.simple_spinner_dropdown_item,
+ ca.fetchCharacterList(), // this returns a cursor and won't be required automatically!
+ new String[] { "name" },
+ new int[] { android.R.id.text1 },
+ 0);
action.setListNavigationCallbacks(sca, new ActionBar.OnNavigationListener() {
public boolean onNavigationItemSelected(int itemPosition, long itemId) {
viewer.setCharacter(itemId);
@@ -124,6 +125,8 @@ public String buildSearchUrl(String searchText) {
return sb.toString();
}
+
+
public static String buildDetailsListUri(String uri) {
String[] parts = uri.split("\\/");
if (parts[2].equals("Search")) {
@@ -150,19 +153,19 @@ protected void onDestroy() {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
- case R.id.menu_ogl:
- Intent showContent = new Intent(getApplicationContext(), DetailsActivity.class);
- showContent.setData(Uri.parse("pfsrd://Ogl"));
- startActivity(showContent);
- return true;
- case android.R.id.home:
- // app icon in action bar clicked; go home
- Intent intent = new Intent(this, PathfinderOpenReferenceActivity.class);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- startActivity(intent);
- return true;
- default:
- return super.onOptionsItemSelected(item);
+ case R.id.menu_ogl:
+ Intent showContent = new Intent(getApplicationContext(), DetailsActivity.class);
+ showContent.setData(Uri.parse("pfsrd://Ogl"));
+ startActivity(showContent);
+ return true;
+ case android.R.id.home:
+ // app icon in action bar clicked; go home
+ Intent intent = new Intent(this, PathfinderOpenReferenceActivity.class);
+ intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
+ startActivity(intent);
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
}
}
-}
+}
@@ -41,7 +41,7 @@ public void onDestroy() {
client.onDestroy();
}
- public void setCharacter(long itemId) {
- client.setCharacter(itemId);
- }
+ public void setCharacter(long itemId) {
+ client.setCharacter(itemId);
+ }
}
@@ -2,12 +2,12 @@
import java.util.ArrayList;
import java.util.HashMap;
+
import org.evilsoft.pathfinder.reference.db.psrd.CharacterAdapter;
import org.evilsoft.pathfinder.reference.db.psrd.PsrdDbAdapter;
-import org.evilsoft.pathfinder.reference.render.SectionRenderer;
+
import android.app.Activity;
import android.content.res.AssetManager;
-import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.util.Log;
import android.view.View;
@@ -87,11 +87,11 @@ public boolean shouldOverrideUrlLoading(WebView view, String newUrl) {
public void reloadList(String newUrl) {
// [{id=10751, name=Ability Scores}, {id=10701, name=Getting Started},
// {id=10700, name=Rules: Core Rulebook}, {id=1, name=PFSRD}]
- Log.e("url", newUrl);
+ Log.e(TAG, newUrl);
String[] parts = newUrl.split("\\/");
if (parts[2].startsWith("Rules")) {
DetailsListFragment list = (DetailsListFragment) act.getSupportFragmentManager().findFragmentById(
- R.id.details_list_fragment);
+ R.id.details_list_fragment);
HashMap<String, String> parent = path.get(1);
String updateUrl = RenderFarm.swapUrl(this.url, parent.get("name"), parent.get("id"));
list.updateUrl(updateUrl);
@@ -123,16 +123,9 @@ public boolean renderPfsrd(WebView view, String newUrl) {
} else {
html = "<H1>" + newUrl + "</H1>";
}
- // if (Build.VERSION.SDK_INT <= 10) {
view.loadDataWithBaseURL(newUrl, html, "text/html", "UTF-8", this.oldUrl);
view.setWebViewClient(this);
view.scrollTo(0, 0);
- // } else {
- // view.loadData(html, "text/html", "UTF-8");
- // view.scrollTo(0, 0);
- // view.reload();
- // view.scrollTo(0, 0);
- // }
refreshStarButtonState();
star.setOnClickListener(new View.OnClickListener() {
@@ -142,7 +135,6 @@ public void onClick(View v) {
refreshStarButtonState();
}
});
-
this.oldUrl = newUrl;
return true;
}
@@ -43,9 +43,9 @@
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- userDbAdapter = new PsrdUserDbAdapter(getApplicationContext());
+ userDbAdapter = new PsrdUserDbAdapter(this.getApplicationContext());
userDbAdapter.open();
- PsrdDbHelper dbh = new PsrdDbHelper(getApplicationContext());
+ PsrdDbHelper dbh = new PsrdDbHelper(this.getApplicationContext());
try {
dbh.createDataBase(userDbAdapter);
} catch (IOException e) {
@@ -144,7 +144,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
result.add(charList);
} else {
-
+ result.add(new ArrayList<HashMap<String, Object>>());
}
}
this.children = result;
@@ -108,17 +108,17 @@ public void updateUrl(String newUrl) {
currentListAdapter = new MonsterListAdapter(getActivity().getApplicationContext(), curs, true);
}
} else if (parts[2].equals("Characters")) {
- if (parts.length > 4) {
- // I believe it's safe to test against the name because the keyboard doesn't allow typing an ellipsis character
- if (parts[parts.length - 1].equals(getString(R.string.add_character))) {
- showNewCharacterDialog();
- } else {
- // We have a character name and can search on it
- CharacterAdapter ca = new CharacterAdapter(userDbAdapter);
- Cursor curs = ca.fetchCharacterEntries(parts[parts.length - 1]);
- currentListAdapter = new CharacterListAdapter(getActivity(), curs, parts[3]);
- }
- }
+ if (parts.length > 4) {
+ // I believe it's safe to test against the name because the keyboard doesn't allow typing an ellipsis character
+ if (parts[parts.length - 1].equals(getString(R.string.add_character))) {
+ showNewCharacterDialog();
+ } else {
+ // We have a character name and can search on it
+ CharacterAdapter ca = new CharacterAdapter(userDbAdapter);
+ Cursor curs = ca.fetchCharacterEntries(parts[parts.length - 1]);
+ currentListAdapter = new CharacterListAdapter(getActivity(), curs, parts[3]);
+ }
+ }
} else {
ArrayList<String> list = new ArrayList<String>();
for (int i = 0; i < 6; i++) {
@@ -131,48 +131,45 @@ public void updateUrl(String newUrl) {
}
private void showNewCharacterDialog() {
- AlertDialog.Builder alert =
- Integer.parseInt(android.os.Build.VERSION.SDK) < 11 ?
- new AlertDialog.Builder(getActivity()) :
- new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
+ AlertDialog.Builder alert =
+ Integer.parseInt(android.os.Build.VERSION.SDK) < 11 ?
+ new AlertDialog.Builder(getActivity()) :
+ new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_LIGHT);
- final EditText edit = new EditText(alert.getContext());
- edit.setSingleLine(true);
+ final EditText edit = new EditText(alert.getContext());
+ edit.setSingleLine(true);
- alert.setTitle(R.string.character_entry_title)
- .setMessage(R.string.character_entry_text)
- .setView(edit)
- .setPositiveButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- PsrdUserDbAdapter db = new PsrdUserDbAdapter(getActivity());
+ alert.setTitle(R.string.character_entry_title)
+ .setMessage(R.string.character_entry_text)
+ .setView(edit)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ PsrdUserDbAdapter db = new PsrdUserDbAdapter(getActivity());
- try {
- db.open();
- if (db.addCharacter(edit.getText().toString())) {
- Toast.makeText(getActivity(), R.string.character_entry_success, Toast.LENGTH_SHORT).show();
- // TODO: Figure out a way to make this refresh the list!
- } else {
- Toast.makeText(getActivity(), R.string.character_entry_failure, Toast.LENGTH_SHORT).show();
- }
- } finally {
- db.close();
- }
- }
- })
- .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {}
- })
- .show();
- }
+ try {
+ db.open();
+ if (db.addCharacter(edit.getText().toString())) {
+ Toast.makeText(getActivity(), R.string.character_entry_success, Toast.LENGTH_SHORT).show();
+ // TODO: Figure out a way to make this refresh the list!
+ } else {
+ Toast.makeText(getActivity(), R.string.character_entry_failure, Toast.LENGTH_SHORT).show();
+ }
+ } finally {
+ db.close();
+ }
+ }
+ }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {}
+ }).show();
+ }
- @Override
+ @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setListAdapter(ArrayAdapter.createFromResource(getActivity().getApplicationContext(), R.array.top_titles,
R.layout.list_item));
dbAdapter = new PsrdDbAdapter(getActivity().getApplicationContext());
dbAdapter.open();
-
userDbAdapter = new PsrdUserDbAdapter(getActivity());
userDbAdapter.open();
}
@@ -184,22 +181,20 @@ public void onDestroy() {
dbAdapter.close();
}
if (userDbAdapter != null) {
- userDbAdapter.close();
+ userDbAdapter.close();
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
- Intent showContent = new Intent(getActivity().getApplicationContext(), DetailsActivity.class);
-
- String uri = currentUrl + "/" + currentListAdapter.getItemId(position);
+ Intent showContent = new Intent(getActivity().getApplicationContext(), DetailsActivity.class);
+ String uri = currentUrl + "/" + currentListAdapter.getItemId(position);
DisplayListAdapter a = (DisplayListAdapter) parent.getAdapter();
if (a.getClass().equals(CharacterListAdapter.class)) {
- CharacterListItem item = (CharacterListItem) a.getItem(position);
- uri = item.getUrl();
- showContent.putExtra("currentCharacter", item.getCharacterId());
+ CharacterListItem item = (CharacterListItem) a.getItem(position);
+ uri = item.getUrl();
+ showContent.putExtra("currentCharacter", item.getCharacterId());
}
-
Log.e(TAG, uri);
showContent.setData(Uri.parse(uri));
startActivity(showContent);

0 comments on commit c8581c9

Please sign in to comment.