diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 651bc3fe..e88a5f8c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,7 +2,7 @@ + android:versionName="1.01" > queryMonsterToQuestArrayQuest(long id) { cursor.close(); return mtq; } - + +/********************************* MONSTER HABITAT QUERIES ******************************************/ + /* Get a Cursor that has a list of MonsterHabitats based on Monster */ + public MonsterHabitatCursor queryHabitatMonster(long id) { + return mHelper.queryHabitatMonster(id); + } + + /* Get a Cursor that has a list of MonsterHabitats based on Location */ + public MonsterHabitatCursor queryHabitatLocation(long id) { + return mHelper.queryHabitatLocation(id); + } /********************************* QUEST QUERIES ******************************************/ /* Get a Cursor that has a list of all Quests */ diff --git a/app/src/main/java/com/daviancorp/android/data/database/MonsterHabitatCursor.java b/app/src/main/java/com/daviancorp/android/data/database/MonsterHabitatCursor.java new file mode 100644 index 00000000..b9d5b6bd --- /dev/null +++ b/app/src/main/java/com/daviancorp/android/data/database/MonsterHabitatCursor.java @@ -0,0 +1,82 @@ +package com.daviancorp.android.data.database; + +import android.database.Cursor; +import android.database.CursorWrapper; + +import com.daviancorp.android.data.classes.Habitat; +import com.daviancorp.android.data.classes.Location; +import com.daviancorp.android.data.classes.Monster; + +/** + * Created by Mark on 2/22/2015. + */ +public class MonsterHabitatCursor extends CursorWrapper { + + /** + * Default constructor + * @param c + */ + public MonsterHabitatCursor(Cursor c) { + super(c); + } + + /** + * Generates a Habitat object after retrieving entries from the database + * @return The habitat object + */ + public Habitat getHabitat() + { + if (isBeforeFirst() || isAfterLast()) + return null; + + + //Get base habitat info + Habitat habitat = new Habitat(); + + long id = getLong(getColumnIndex(S.COLUMN_HABITAT_ID)); + long start = getLong(getColumnIndex(S.COLUMN_HABITAT_START)); + long rest = getLong(getColumnIndex(S.COLUMN_HABITAT_REST)); + + String areas = getString(getColumnIndex(S.COLUMN_HABITAT_AREAS)); + String[] allAreas = areas.split("/"); + + long[] areasInt = new long[allAreas.length]; + for (int i = 0; i < allAreas.length; i++) + { + areasInt[i] = Long.valueOf(allAreas[i]); + } + + habitat.setStart(start); + habitat.setRest(rest); + habitat.setAreas(areasInt); + habitat.setId(id); + + //Get Location + Location location = new Location(); + + long loc_id = getLong(getColumnIndex("l" + S.COLUMN_LOCATIONS_ID)); + String loc_name = getString(getColumnIndex("l" + S.COLUMN_LOCATIONS_NAME)); + + location.setId(loc_id); + location.setName(loc_name); + + habitat.setLocation(location); + + //Get Monster + Monster monster = new Monster(); + + long mon_id = getLong(getColumnIndex("m" + S.COLUMN_MONSTERS_ID)); + String mon_name = getString(getColumnIndex("m" + S.COLUMN_MONSTERS_NAME)); + String file = getString(getColumnIndex("m" + S.COLUMN_MONSTERS_FILE_LOCATION)); + String mon_class = getString(getColumnIndex("m" + S.COLUMN_MONSTERS_CLASS)); + + monster.setId(mon_id); + monster.setName(mon_name); + monster.setFileLocation(file); + monster.setMonsterClass(mon_class); + + habitat.setMonster(monster); + + return habitat; + } +} diff --git a/app/src/main/java/com/daviancorp/android/data/database/MonsterHunterDatabaseHelper.java b/app/src/main/java/com/daviancorp/android/data/database/MonsterHunterDatabaseHelper.java index 0e06f516..4dc492ac 100644 --- a/app/src/main/java/com/daviancorp/android/data/database/MonsterHunterDatabaseHelper.java +++ b/app/src/main/java/com/daviancorp/android/data/database/MonsterHunterDatabaseHelper.java @@ -8,6 +8,7 @@ import java.io.OutputStream; import java.util.HashMap; +import android.app.DownloadManager; import android.content.ContentValues; import android.content.Context; import android.database.Cursor; @@ -1716,6 +1717,87 @@ public MonsterCursor queryMonsterTrait(String name) { return new MonsterCursor(wrapHelper(qh)); } + +/********************************* MONSTER HABITAT QUERIES ******************************************/ + + /** + * Get a cursor with a query to grab all habitats of a monster + * @param id id of the monster to query + * @return A habitat cursor + */ + public MonsterHabitatCursor queryHabitatMonster(long id) + { + // Select * FROM monster_habitat WHERE monster_id = id + QueryHelper qh = new QueryHelper(); + qh.Distinct = true; + qh.Table = S.TABLE_HABITAT; + qh.Columns = null; + qh.Selection = S.COLUMN_HABITAT_MONSTER_ID + " = ?"; + qh.SelectionArgs = new String[]{ String.valueOf(id) }; + qh.GroupBy = null; + qh.Having = null; + qh.OrderBy = null; + qh.Limit = null; + + return new MonsterHabitatCursor(wrapJoinHelper(builderHabitat(qh.Distinct),qh)); + } + + /** + * Get a cursor with a query to grab all monsters by a location + * @param id id of the location to query + * @return A habitat cursor + */ + public MonsterHabitatCursor queryHabitatLocation(long id) + { + // Select * FROM monster_habitat WHERE location_id = id + QueryHelper qh = new QueryHelper(); + qh.Distinct = true; + qh.Table = S.TABLE_HABITAT; + qh.Columns = null; + qh.Selection = S.COLUMN_HABITAT_LOCATION_ID + " = ?"; + qh.SelectionArgs = new String[]{ String.valueOf(id) }; + qh.GroupBy = null; + qh.Having = null; + qh.OrderBy = null; + qh.Limit = null; + + return new MonsterHabitatCursor(wrapJoinHelper(builderHabitat(qh.Distinct),qh)); + } + + /* + * Helper method to query for Habitat/Monster/Location + */ + private SQLiteQueryBuilder builderHabitat(boolean Distinct) { + String h = "h"; + String m = "m"; + String l = "l"; + + HashMap projectionMap = new HashMap(); + + projectionMap.put("_id", h + "." + S.COLUMN_HABITAT_ID + " AS " + "_id"); + projectionMap.put("start_area", h + "." + S.COLUMN_HABITAT_START + " AS " + "start_area"); + projectionMap.put("move_area", h + "." + S.COLUMN_HABITAT_AREAS + " AS " + "move_area"); + projectionMap.put("rest_area", h + "." + S.COLUMN_HABITAT_REST + " AS " + "rest_area"); + + projectionMap.put(l + S.COLUMN_LOCATIONS_ID, l + "." + S.COLUMN_LOCATIONS_ID + " AS " + l + S.COLUMN_LOCATIONS_ID ); + projectionMap.put(l + S.COLUMN_LOCATIONS_NAME, l + "." + S.COLUMN_LOCATIONS_NAME + " AS " + l + S.COLUMN_LOCATIONS_NAME ); + + projectionMap.put(m + S.COLUMN_MONSTERS_ID, m+ "." + S.COLUMN_MONSTERS_ID + " AS " + m + S.COLUMN_MONSTERS_ID); + projectionMap.put(m + S.COLUMN_MONSTERS_NAME, m + "." + S.COLUMN_MONSTERS_NAME + " AS " + m + S.COLUMN_MONSTERS_NAME); + projectionMap.put(m + S.COLUMN_MONSTERS_CLASS, m + "." + S.COLUMN_MONSTERS_CLASS + " AS " + m + S.COLUMN_MONSTERS_CLASS ); + projectionMap.put(m + S.COLUMN_MONSTERS_FILE_LOCATION, m + "." + S.COLUMN_MONSTERS_FILE_LOCATION + " AS " + m + S.COLUMN_MONSTERS_FILE_LOCATION ); + + //Create new querybuilder + SQLiteQueryBuilder QB = new SQLiteQueryBuilder(); + + QB.setTables(S.TABLE_HABITAT + " AS h" + " LEFT OUTER JOIN " + S.TABLE_MONSTERS + " AS m" + " ON " + "h." + + S.COLUMN_HABITAT_MONSTER_ID + " = " + "m." + S.COLUMN_MONSTERS_ID + " LEFT OUTER JOIN " + S.TABLE_LOCATIONS + + " AS l " + " ON " + "h." + S.COLUMN_HABITAT_LOCATION_ID + " = " + "l." + S.COLUMN_LOCATIONS_ID); + + QB.setDistinct(Distinct); + QB.setProjectionMap(projectionMap); + return QB; + } /********************************* MONSTER DAMAGE QUERIES ******************************************/ diff --git a/app/src/main/java/com/daviancorp/android/data/database/S.java b/app/src/main/java/com/daviancorp/android/data/database/S.java index 39473df6..1a9c72f0 100644 --- a/app/src/main/java/com/daviancorp/android/data/database/S.java +++ b/app/src/main/java/com/daviancorp/android/data/database/S.java @@ -176,7 +176,16 @@ public class S { static final String COLUMN_MONSTERS_TRAIT = "trait"; static final String COLUMN_MONSTERS_FILE_LOCATION = "icon_name"; static final String COLUMN_MONSTERS_SORT_NAME = "sort_name"; - + + // Monster Habitat + static final String TABLE_HABITAT = "monster_habitat"; + static final String COLUMN_HABITAT_ID = "_id"; + static final String COLUMN_HABITAT_LOCATION_ID = "location_id"; + static final String COLUMN_HABITAT_MONSTER_ID = "monster_id"; + static final String COLUMN_HABITAT_START = "start_area"; + static final String COLUMN_HABITAT_AREAS = "move_area"; + static final String COLUMN_HABITAT_REST = "rest_area"; + // Monster Damage static final String TABLE_MONSTER_DAMAGE = "monster_damage"; static final String COLUMN_MONSTER_DAMAGE_ID = "_id"; diff --git a/app/src/main/java/com/daviancorp/android/loader/MonsterHabitatListCursorLoader.java b/app/src/main/java/com/daviancorp/android/loader/MonsterHabitatListCursorLoader.java new file mode 100644 index 00000000..8becee2b --- /dev/null +++ b/app/src/main/java/com/daviancorp/android/loader/MonsterHabitatListCursorLoader.java @@ -0,0 +1,45 @@ +package com.daviancorp.android.loader; + +import android.content.Context; +import android.database.Cursor; + +import com.daviancorp.android.data.database.DataManager; +/** + * Created by Mark on 2/22/2015. + * + */ +public class MonsterHabitatListCursorLoader extends SQLiteCursorLoader { + public static String FROM_MONSTER = "monster"; + public static String FROM_LOCATION = "location"; + + private String from; // "monster" or "location" + private long id; // Item or Location id + + /** + * Public constructor for the cursor loader + * @param context The context of the loader + * @param from String of "monster" or "location" + * @param id id of monster or location to query + */ + public MonsterHabitatListCursorLoader(Context context, String from, long id) { + super(context); + this.from = from; + this.id = id; + } + + @Override + /** + * Loads cursor based upon which query we're coming from + */ + protected Cursor loadCursor() { + if (from.equals(FROM_MONSTER)) { + return DataManager.get(getContext()).queryHabitatMonster(id); + } + else if(from.equals(FROM_LOCATION)) { + return DataManager.get(getContext()).queryHabitatLocation(id); + } + else { + return null; + } + } +} diff --git a/app/src/main/java/com/daviancorp/android/ui/adapter/LocationDetailPagerAdapter.java b/app/src/main/java/com/daviancorp/android/ui/adapter/LocationDetailPagerAdapter.java index 2c2e4e10..aed7da14 100644 --- a/app/src/main/java/com/daviancorp/android/ui/adapter/LocationDetailPagerAdapter.java +++ b/app/src/main/java/com/daviancorp/android/ui/adapter/LocationDetailPagerAdapter.java @@ -6,6 +6,7 @@ import com.daviancorp.android.loader.GatheringListCursorLoader; import com.daviancorp.android.ui.detail.LocationDetailFragment; +import com.daviancorp.android.ui.detail.LocationHabitatFragment; import com.daviancorp.android.ui.detail.LocationRankFragment; public class LocationDetailPagerAdapter extends FragmentPagerAdapter { @@ -24,13 +25,16 @@ public Fragment getItem(int index) { case 0: // Location detail return LocationDetailFragment.newInstance(locationId); - case 1: + case 1: + // Habitat detail + return LocationHabitatFragment.newInstance(locationId); + case 2: // Low-rank items return LocationRankFragment.newInstance(locationId, GatheringListCursorLoader.RANK_LR); - case 2: + case 3: // High-rank items return LocationRankFragment.newInstance(locationId, GatheringListCursorLoader.RANK_HR); - case 3: + case 4: // G-rank items return LocationRankFragment.newInstance(locationId, GatheringListCursorLoader.RANK_G); default: @@ -41,7 +45,7 @@ public Fragment getItem(int index) { @Override public int getCount() { // get item count - equal to number of tabs - return 4; + return 5; } } \ No newline at end of file diff --git a/app/src/main/java/com/daviancorp/android/ui/adapter/MonsterDetailPagerAdapter.java b/app/src/main/java/com/daviancorp/android/ui/adapter/MonsterDetailPagerAdapter.java index a4beffd7..c35cf90e 100644 --- a/app/src/main/java/com/daviancorp/android/ui/adapter/MonsterDetailPagerAdapter.java +++ b/app/src/main/java/com/daviancorp/android/ui/adapter/MonsterDetailPagerAdapter.java @@ -6,8 +6,10 @@ import com.daviancorp.android.loader.HuntingRewardListCursorLoader; import com.daviancorp.android.ui.detail.MonsterDetailFragment; +import com.daviancorp.android.ui.detail.MonsterHabitatFragment; import com.daviancorp.android.ui.detail.MonsterQuestFragment; import com.daviancorp.android.ui.detail.MonsterRewardFragment; +import com.daviancorp.android.ui.detail.MonsterHabitatFragment; public class MonsterDetailPagerAdapter extends FragmentPagerAdapter { @@ -25,16 +27,19 @@ public Fragment getItem(int index) { case 0: // Monster detail return MonsterDetailFragment.newInstance(monsterId); - case 1: + case 1: + // Monster Habitat + return MonsterHabitatFragment.newInstance(monsterId); + case 2: // Low-rank drops return MonsterRewardFragment.newInstance(monsterId, HuntingRewardListCursorLoader.RANK_LR); - case 2: + case 3: // High-rank drops return MonsterRewardFragment.newInstance(monsterId, HuntingRewardListCursorLoader.RANK_HR); - case 3: + case 4: // G-rank drops return MonsterRewardFragment.newInstance(monsterId, HuntingRewardListCursorLoader.RANK_G); - case 4: + case 5: // Quest appearance return MonsterQuestFragment.newInstance(monsterId); default: @@ -45,7 +50,7 @@ public Fragment getItem(int index) { @Override public int getCount() { // get item count - equal to number of tabs - return 5; + return 6; } } \ No newline at end of file diff --git a/app/src/main/java/com/daviancorp/android/ui/detail/LocationDetailActivity.java b/app/src/main/java/com/daviancorp/android/ui/detail/LocationDetailActivity.java index 73b1fcb9..08e36ab1 100644 --- a/app/src/main/java/com/daviancorp/android/ui/detail/LocationDetailActivity.java +++ b/app/src/main/java/com/daviancorp/android/ui/detail/LocationDetailActivity.java @@ -23,7 +23,7 @@ public class LocationDetailActivity extends GenericTabActivity implements private ActionBar actionBar; // Tab titles - private String[] tabs = { "Map" , "Low Rank" , "High Rank" , "G Rank" }; + private String[] tabs = { "Map" ,"Monsters", "Low Rank" , "High Rank" , "G Rank" }; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/daviancorp/android/ui/detail/LocationHabitatFragment.java b/app/src/main/java/com/daviancorp/android/ui/detail/LocationHabitatFragment.java new file mode 100644 index 00000000..46394005 --- /dev/null +++ b/app/src/main/java/com/daviancorp/android/ui/detail/LocationHabitatFragment.java @@ -0,0 +1,180 @@ +package com.daviancorp.android.ui.detail; + +import android.annotation.SuppressLint; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.v4.app.ListFragment; +import android.support.v4.app.LoaderManager.LoaderCallbacks; +import android.support.v4.content.Loader; +import android.support.v4.widget.CursorAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.TextView; + +import com.daviancorp.android.data.classes.Habitat; +import com.daviancorp.android.data.database.MonsterHabitatCursor; +import com.daviancorp.android.loader.MonsterHabitatListCursorLoader; +import com.daviancorp.android.mh4udatabase.R; + +import java.io.IOException; + +/** + * A simple {@link android.app.Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link com.daviancorp.android.ui.detail.LocationHabitatFragment.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link com.daviancorp.android.ui.detail.LocationHabitatFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class LocationHabitatFragment extends ListFragment implements + LoaderCallbacks { + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_LOCATION_ID = "LOCATION_ID"; + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param loc_id The id of the location for the fragment + * + * @return A new instance of fragment MonsterHabitatFragment. + */ + public static LocationHabitatFragment newInstance(long loc_id) { + LocationHabitatFragment fragment = new LocationHabitatFragment(); + Bundle args = new Bundle(); + args.putLong(ARG_LOCATION_ID, loc_id); + fragment.setArguments(args); + return fragment; + } + + public LocationHabitatFragment() { + // Required empty public constructor + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Initialize the loader to load the list of monsters + getLoaderManager().initLoader(0, getArguments(), this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_monster_habitat_list, container, false); + } + + @SuppressLint("NewApi") + @Override + public Loader onCreateLoader(int id, Bundle args) { + long itemId = args.getLong(ARG_LOCATION_ID, -1); + + return new MonsterHabitatListCursorLoader(getActivity(), + MonsterHabitatListCursorLoader.FROM_LOCATION, itemId); + } + + @Override + public void onLoadFinished(Loader loader, Cursor cursor) { + // Create an adapter to point at this cursor + + MonsterHabitatCursorAdapter adapter = new MonsterHabitatCursorAdapter( + getActivity(), (MonsterHabitatCursor) cursor); + setListAdapter(adapter); + + } + + @Override + public void onLoaderReset(Loader loader) { + // Stop using the cursor (via the adapter) + setListAdapter(null); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + // The id argument will be the Location ID set by adapter + + Intent i = new Intent(getActivity(), MonsterDetailActivity.class); + i.putExtra(MonsterDetailActivity.EXTRA_MONSTER_ID, (long) v.getTag()); + startActivity(i); + } + + private static class MonsterHabitatCursorAdapter extends CursorAdapter { + + private MonsterHabitatCursor mHabitatCursor; + + public MonsterHabitatCursorAdapter(Context context, + MonsterHabitatCursor cursor) { + super(context, cursor, 0); + mHabitatCursor = cursor; + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + // Use a layout inflater to get a row view + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + return inflater.inflate(R.layout.fragment_location_habitat_listitem, + parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + // Get the item for the current row + Habitat habitat = mHabitatCursor.getHabitat(); + + // Set up the text view + LinearLayout itemLayout = (LinearLayout) view + .findViewById(R.id.listitem); + + ImageView monsterImageView = (ImageView) view.findViewById(R.id.monster_image); + TextView monsterTextView = (TextView) view.findViewById(R.id.monster); + TextView startTextView = (TextView) view.findViewById(R.id.start); + TextView areaTextView = (TextView) view.findViewById(R.id.move); + TextView restTextView = (TextView) view.findViewById(R.id.rest); + + long start = habitat.getStart(); + long[] area = habitat.getAreas(); + long rest = habitat.getRest(); + + String areas = ""; + for(int i = 0; i < area.length; i++) + { + areas += Long.toString(area[i]); + if (i != area.length - 1) + { + areas += ", "; + } + } + + Drawable i = null; + String cellImage = "icons_monster/" + + habitat.getMonster().getFileLocation(); + try { + i = Drawable.createFromStream( + context.getAssets().open(cellImage), null); + } catch (IOException e) { + e.printStackTrace(); + } + + monsterImageView.setImageDrawable(i); + + monsterTextView.setText(habitat.getMonster().getName()); + startTextView.setText(Long.toString(start)); + areaTextView.setText(areas); + restTextView.setText(Long.toString(rest)); + + // Set id of layout to location so clicking gives us the location + itemLayout.setTag(habitat.getMonster().getId()); + } + } + +} diff --git a/app/src/main/java/com/daviancorp/android/ui/detail/MonsterDetailActivity.java b/app/src/main/java/com/daviancorp/android/ui/detail/MonsterDetailActivity.java index 87b545bc..40865b45 100644 --- a/app/src/main/java/com/daviancorp/android/ui/detail/MonsterDetailActivity.java +++ b/app/src/main/java/com/daviancorp/android/ui/detail/MonsterDetailActivity.java @@ -23,7 +23,7 @@ public class MonsterDetailActivity extends GenericTabActivity implements private ActionBar actionBar; // Tab titles - private String[] tabs = { "Detail", "Low-Rank", "High-Rank", "G-Rank", "Quest"}; + private String[] tabs = { "Detail", "Habitat","Low-Rank", "High-Rank", "G-Rank", "Quest"}; @Override public void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/daviancorp/android/ui/detail/MonsterHabitatFragment.java b/app/src/main/java/com/daviancorp/android/ui/detail/MonsterHabitatFragment.java new file mode 100644 index 00000000..c4670bb5 --- /dev/null +++ b/app/src/main/java/com/daviancorp/android/ui/detail/MonsterHabitatFragment.java @@ -0,0 +1,174 @@ +package com.daviancorp.android.ui.detail; + +import android.annotation.SuppressLint; +import android.app.Activity; +import android.support.v4.app.ListFragment; +import android.app.LoaderManager; +import android.support.v4.app.LoaderManager.LoaderCallbacks; +import android.content.Context; +import android.content.Intent; +import android.database.Cursor; +import android.net.Uri; +import android.os.Bundle; +import android.app.Fragment; +import android.support.v4.content.Loader; +import android.support.v4.widget.CursorAdapter; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.ListView; +import android.widget.TextView; + + +import com.daviancorp.android.data.classes.Gathering; +import com.daviancorp.android.data.classes.Habitat; +import com.daviancorp.android.data.classes.Monster; +import com.daviancorp.android.data.database.GatheringCursor; +import com.daviancorp.android.data.database.MonsterHabitatCursor; +import com.daviancorp.android.loader.GatheringListCursorLoader; +import com.daviancorp.android.loader.MonsterHabitatListCursorLoader; +import com.daviancorp.android.mh4udatabase.R; + +/** + * A simple {@link Fragment} subclass. + * Activities that contain this fragment must implement the + * {@link MonsterHabitatFragment.OnFragmentInteractionListener} interface + * to handle interaction events. + * Use the {@link MonsterHabitatFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class MonsterHabitatFragment extends ListFragment implements + LoaderCallbacks { + // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER + private static final String ARG_MONSTER_ID = "MONSTER_ID"; + + /** + * Use this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @param mon_id The id of the monster for the fragment + * + * @return A new instance of fragment MonsterHabitatFragment. + */ + public static MonsterHabitatFragment newInstance(long mon_id) { + MonsterHabitatFragment fragment = new MonsterHabitatFragment(); + Bundle args = new Bundle(); + args.putLong(ARG_MONSTER_ID, mon_id); + fragment.setArguments(args); + return fragment; + } + + public MonsterHabitatFragment() { + // Required empty public constructor + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + // Initialize the loader to load the list of monsters + getLoaderManager().initLoader(0, getArguments(), this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflate the layout for this fragment + return inflater.inflate(R.layout.fragment_monster_habitat_list, container, false); + } + + @SuppressLint("NewApi") + @Override + public Loader onCreateLoader(int id, Bundle args) { + long itemId = args.getLong(ARG_MONSTER_ID, -1); + + return new MonsterHabitatListCursorLoader(getActivity(), + MonsterHabitatListCursorLoader.FROM_MONSTER, itemId); + } + + @Override + public void onLoadFinished(Loader loader, Cursor cursor) { + // Create an adapter to point at this cursor + + MonsterHabitatCursorAdapter adapter = new MonsterHabitatCursorAdapter( + getActivity(), (MonsterHabitatCursor) cursor); + setListAdapter(adapter); + + } + + @Override + public void onLoaderReset(Loader loader) { + // Stop using the cursor (via the adapter) + setListAdapter(null); + } + + @Override + public void onListItemClick(ListView l, View v, int position, long id) { + // The id argument will be the Location ID set by adapter + + Intent i = new Intent(getActivity(), LocationDetailActivity.class); + i.putExtra(LocationDetailActivity.EXTRA_LOCATION_ID, (long) v.getTag()); + startActivity(i); + } + + private static class MonsterHabitatCursorAdapter extends CursorAdapter { + + private MonsterHabitatCursor mHabitatCursor; + + public MonsterHabitatCursorAdapter(Context context, + MonsterHabitatCursor cursor) { + super(context, cursor, 0); + mHabitatCursor = cursor; + } + + @Override + public View newView(Context context, Cursor cursor, ViewGroup parent) { + // Use a layout inflater to get a row view + LayoutInflater inflater = (LayoutInflater) context + .getSystemService(Context.LAYOUT_INFLATER_SERVICE); + return inflater.inflate(R.layout.fragment_monster_habitat_listitem, + parent, false); + } + + @Override + public void bindView(View view, Context context, Cursor cursor) { + // Get the item for the current row + Habitat habitat = mHabitatCursor.getHabitat(); + + // Set up the text view + LinearLayout itemLayout = (LinearLayout) view + .findViewById(R.id.listitem); + + TextView mapTextView = (TextView) view.findViewById(R.id.map); + TextView startTextView = (TextView) view.findViewById(R.id.start); + TextView areaTextView = (TextView) view.findViewById(R.id.move); + TextView restTextView = (TextView) view.findViewById(R.id.rest); + + + String mapName = habitat.getLocation().getName(); + long start = habitat.getStart(); + long[] area = habitat.getAreas(); + long rest = habitat.getRest(); + + String areas = ""; + for(int i = 0; i < area.length; i++) + { + areas += Long.toString(area[i]); + if (i != area.length - 1) + { + areas += ", "; + } + } + + mapTextView.setText(mapName); + startTextView.setText(Long.toString(start)); + areaTextView.setText(areas); + restTextView.setText(Long.toString(rest)); + + // Set id of layout to location so clicking gives us the location + itemLayout.setTag(habitat.getLocation().getId()); + } + } + +} diff --git a/app/src/main/res/layout/fragment_location_habitat_list.xml b/app/src/main/res/layout/fragment_location_habitat_list.xml new file mode 100644 index 00000000..9db4e5e3 --- /dev/null +++ b/app/src/main/res/layout/fragment_location_habitat_list.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_location_habitat_listitem.xml b/app/src/main/res/layout/fragment_location_habitat_listitem.xml new file mode 100644 index 00000000..ddc80905 --- /dev/null +++ b/app/src/main/res/layout/fragment_location_habitat_listitem.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_monster_habitat_list.xml b/app/src/main/res/layout/fragment_monster_habitat_list.xml new file mode 100644 index 00000000..d89ae129 --- /dev/null +++ b/app/src/main/res/layout/fragment_monster_habitat_list.xml @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/fragment_monster_habitat_listitem.xml b/app/src/main/res/layout/fragment_monster_habitat_listitem.xml new file mode 100644 index 00000000..f5e0f558 --- /dev/null +++ b/app/src/main/res/layout/fragment_monster_habitat_listitem.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index dff7d24c..4101c1cc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -4,15 +4,14 @@ MH4U Database About Settings - MH4U Database + MH4U Database v1.01 \n\n - Contribute at: - \n GitHub:\n + Contribute at:\n https://github.com/kamegami13/MonsterHunter4UDatabase \n\n Based on data from:\n Ping\'s Dex\n - monsterhunter.wikia.com/\n + monsterhunter.wikia.com\n kiranico.com\n wiki.mh4g.org\n aegil.net @@ -20,6 +19,7 @@ A Special Thanks to:\n Kiranico\n Kogath at Monster Hunter Wikia\n + kaiiboraka\n Ping\n Aegil \n\n @@ -29,6 +29,7 @@ Rate! Cancel Submit + "Monsters" "Weapons" @@ -43,6 +44,7 @@ "Arena Quests" "Wishlists" + List Grid Add wishlist @@ -68,5 +70,6 @@ Arena Quests Wishlists MH4U DB + Hello blank fragment \ No newline at end of file diff --git a/changelog.txt b/changelog.txt new file mode 100644 index 00000000..8b7856cc --- /dev/null +++ b/changelog.txt @@ -0,0 +1,16 @@ +Release Notes: +Version 1.01 + New Features: + - Monster Habitats now appear on the Monster Detail Page + - Monster Habitats are now listed on the Location Detail Page + + Bug Fixes: + - Fixed crash on dual element Dual Blades + - Fixed crash on Bows with less than three charges + - Fixed layout for skill descriptions; long descriptions will no longer be clipped. + - Added tabs for padding to the Bow/Bowgun weapon trees. + - Fixed small monster links being sent to wrong monster page + - Fixed icons for charge blade and insect glaive not appearing + +Version 1.0 + - Initial Release \ No newline at end of file