Skip to content

Commit

Permalink
Merge branch 'mmangliers-master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamegami committed Feb 22, 2015
2 parents 53e6860 + 05a264c commit ce500e3
Show file tree
Hide file tree
Showing 19 changed files with 919 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.daviancorp.android.mh4udatabase"
android:versionCode="1"
android:versionName="1.0" >
android:versionName="1.01" >

<uses-sdk
android:minSdkVersion="14"
Expand Down
76 changes: 76 additions & 0 deletions app/src/main/java/com/daviancorp/android/data/classes/Habitat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package com.daviancorp.android.data.classes;

/**
* Created by Mark on 2/22/2015.
* Describes a habitat for a monster
*/
public class Habitat {
private long id; //id of habitat entry
private Monster monster; //id of the monster
private Location location; //if of habitat location
private long start; //Starting area number
private long[] areas; //Array of areas
private long rest; //Rest area of the monster

/**
* Default constructor
* Initializes variables to defaults
*/
public Habitat()
{
this.monster = null;
this.location = null;
this.areas = null;
start = 0;
rest = 0;
id = -1;
}

public Monster getMonster() {
return monster;
}

public void setMonster(Monster monster) {
this.monster = monster;
}

public Location getLocation() {
return location;
}

public void setLocation(Location location) {
this.location = location;
}

public long getStart() {
return start;
}

public void setStart(long start) {
this.start = start;
}

public long[] getAreas() {
return areas;
}

public void setAreas(long[] areas) {
this.areas = areas;
}

public long getRest() {
return rest;
}

public void setRest(long rest) {
this.rest = rest;
}

public long getId() {
return id;
}

public void setId(long id) {
this.id = id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,17 @@ public ArrayList<MonsterToQuest> 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 */
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<String, String> projectionMap = new HashMap<String, String>();

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 ******************************************/

Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/daviancorp/android/data/database/S.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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:
Expand All @@ -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;
}

}
Loading

0 comments on commit ce500e3

Please sign in to comment.