-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
919 additions
and
18 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
76 changes: 76 additions & 0 deletions
76
app/src/main/java/com/daviancorp/android/data/classes/Habitat.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
82 changes: 82 additions & 0 deletions
82
app/src/main/java/com/daviancorp/android/data/database/MonsterHabitatCursor.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} |
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
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
45 changes: 45 additions & 0 deletions
45
app/src/main/java/com/daviancorp/android/loader/MonsterHabitatListCursorLoader.java
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 |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.