Commit 509a100b authored by Adrien Oliva's avatar Adrien Oliva

feat(Character) Creation and retrieval of #1 character

Move database from internal storage to sdcard
Store character in database
Retrieve first character data (#1)

GTLAB #2Signed-off-by: Adrien Oliva's avatarAdrien Oliva <olivaa+gitlab@yapbreak.fr>
parent 4582db68
Pipeline #474 passed with stage
in 0 seconds
package fr.yapbreak.skyrimquest;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.Environment;
import android.support.annotation.NonNull;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
......@@ -11,12 +15,12 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import fr.yapbreak.skyrimquest.data.DataHelper;
import fr.yapbreak.skyrimquest.quests.Quest;
import fr.yapbreak.skyrimquest.quests.SkyrimCursorAdapter;
import fr.yapbreak.skyrimquest.character.Character;
......@@ -29,9 +33,13 @@ public class QuestList extends AppCompatActivity
private DataHelper quest_data;
private Character activeCharacter;
ImageView navigation_avatar;
TextView navigation_name;
TextView navigation_details;
private static final int EXTERNAL_CODE = 570;
private String[] permission = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
ListView mainListView;
NavigationView navigationView;
public static DataHelper getDataHandler()
{
......@@ -48,14 +56,18 @@ public class QuestList extends AppCompatActivity
******************************************************************************************/
activeCharacter = quest_data.getActiveCharacter();
if (activeCharacter != null) {
View header = navigationView.getHeaderView(0);
ImageView navigation_avatar = header.findViewById(R.id.navigation_avatar);
TextView navigation_name = header.findViewById(R.id.navigation_character_name);
TextView navigation_details = header.findViewById(R.id.navigation_character_details);
navigation_name.setText(activeCharacter.getName());
StringBuilder details = new StringBuilder();
details.append(activeCharacter.getRace());
details.append(" - ");
details.append(getString(R.string.level_label));
details.append(" ");
details.append(activeCharacter.getLevel());
navigation_details.setText(details.toString());
String details = activeCharacter.getRace()
+ " - "
+ getString(R.string.level_label)
+ " "
+ activeCharacter.getLevel();
navigation_details.setText(details);
}
}
......@@ -70,48 +82,67 @@ public class QuestList extends AppCompatActivity
super.onCreate(savedInstanceState);
QuestList.context = getApplicationContext();
// TODO: remove this line when database is ready
this.deleteDatabase("quest_database");
/*******************************************************************************************
Set up database
******************************************************************************************/
quest_data = new DataHelper(this);
quest_data.populate();
instance = quest_data;
/*******************************************************************************************
Retrieve active character
******************************************************************************************/
activeCharacter = quest_data.getActiveCharacter();
setContentView(R.layout.activity_quest_list);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
DrawerLayout drawer = findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) {
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
}
public void onDrawerOpened(View view) {
super.onDrawerOpened(view);
updateCharacterInfo();
}
};
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = findViewById(R.id.nav_view);
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
/**
* Set up navigation view
*/
navigation_avatar = navigationView.findViewById(R.id.navigation_avatar);
navigation_name = navigationView.findViewById(R.id.navigation_character_name);
navigation_details = navigationView.findViewById(R.id.navigation_character_details);
mainListView = findViewById(R.id.quests_listview);
/*******************************************************************************************
Set up database
******************************************************************************************/
if (checkSelfPermission(permission[0]) == PackageManager.PERMISSION_GRANTED
&& checkSelfPermission(permission[1]) == PackageManager.PERMISSION_GRANTED) {
quest_data = new DataHelper(this);
quest_data.populate();
instance = quest_data;
SkyrimCursorAdapter adapter = new SkyrimCursorAdapter(this, quest_data.getAllQuests());
mainListView.setAdapter(adapter);
} else {
requestPermissions(permission, EXTERNAL_CODE);
}
SkyrimCursorAdapter adapter = new SkyrimCursorAdapter(this, quest_data.getAllQuests());
ListView lv = findViewById(R.id.quests_listview);
lv.setAdapter(adapter);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case EXTERNAL_CODE:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED
&& grantResults[1] == PackageManager.PERMISSION_GRANTED) {
quest_data = new DataHelper(this);
quest_data.populate();
instance = quest_data;
SkyrimCursorAdapter adapter = new SkyrimCursorAdapter(this, quest_data.getAllQuests());
mainListView.setAdapter(adapter);
}
}
}
@Override
......
......@@ -21,9 +21,9 @@ public class Character {
}
public Character(String name,
String avatarFileName,
String raceId,
int level,
String raceId)
String avatarFileName)
{
this.name = name;
this.avatarFileName = avatarFileName;
......
......@@ -6,6 +6,7 @@ import android.database.Cursor;
import android.database.sqlite.SQLiteConstraintException;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.os.Environment;
import android.util.Log;
import fr.yapbreak.skyrimquest.character.Character;
......@@ -26,7 +27,7 @@ public class DataHelper extends SQLiteOpenHelper {
}
}
private final static String DATABASE_NAME = "quest_database";
private final static String DATABASE_NAME = Environment.getExternalStorageDirectory().getPath()+"/quest_database.db";
private final static int DATABASE_VERSION = 1;
private final static String QUEST_TABLE = "tbl_quest";
......@@ -89,6 +90,7 @@ public class DataHelper extends SQLiteOpenHelper {
public DataHelper(Context context)
{
super(context, DATABASE_NAME, null, DATABASE_VERSION);
SQLiteDatabase.openOrCreateDatabase(DATABASE_NAME, null);
}
@Override
......@@ -358,7 +360,7 @@ public class DataHelper extends SQLiteOpenHelper {
public Character getActiveCharacter()
{
try {
Character c = new Character(0);
Character c = new Character(1);
return c;
} catch (DataNotFound e) {
Log.i("SKYRIM", "No active character found");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment