Commit ea812326 authored by Adrien Oliva's avatar Adrien Oliva

WIP feat(character): Retrieve current character

GTLAB #2Signed-off-by: Adrien Oliva's avatarAdrien Oliva <olivaa+gitlab@yapbreak.fr>
parent 495fe7bb
Pipeline #467 passed with stage
in 0 seconds
......@@ -10,10 +10,13 @@ import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import fr.yapbreak.skyrimquest.data.DataHelper;
import fr.yapbreak.skyrimquest.quests.SkyrimCursorAdapter;
import fr.yapbreak.skyrimquest.character.Character;
public class QuestList extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
......@@ -21,12 +24,41 @@ public class QuestList extends AppCompatActivity
protected static QuestList instance;
private DataHelper quest_data;
private Character activeCharacter;
ImageView navigation_avatar;
TextView navigation_name;
TextView navigation_details;
public static QuestList getInstance()
{
return instance;
}
private void updateCharacterInfo()
{
/*******************************************************************************************
Retrieve active character
******************************************************************************************/
activeCharacter = quest_data.getActiveCharacter();
if (activeCharacter != null) {
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());
}
}
@Override
protected void onResume() {
super.onResume();
updateCharacterInfo();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -35,9 +67,18 @@ public class QuestList extends AppCompatActivity
// TODO: remove this line when database is ready
this.deleteDatabase("quest_database");
/*******************************************************************************************
Set up database
******************************************************************************************/
quest_data = new DataHelper(this);
quest_data.populate();
/*******************************************************************************************
Retrieve active character
******************************************************************************************/
activeCharacter = quest_data.getActiveCharacter();
setContentView(R.layout.activity_quest_list);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
......@@ -51,6 +92,15 @@ public class QuestList extends AppCompatActivity
NavigationView 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);
SkyrimCursorAdapter adapter = new SkyrimCursorAdapter(this, quest_data.getAllQuests());
ListView lv = findViewById(R.id.quests_listview);
......@@ -115,6 +165,8 @@ public class QuestList extends AppCompatActivity
DrawerLayout drawer = findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
updateCharacterInfo();
return true;
}
......
......@@ -354,4 +354,15 @@ public class DataHelper extends SQLiteOpenHelper {
return getCharacterId(c);
}
public Character getActiveCharacter()
{
try {
Character c = new Character(0);
return c;
} catch (DataNotFound e) {
Log.i("SKYRIM", "No active character found");
return null;
}
}
}
......@@ -13,7 +13,7 @@
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView"
android:id="@+id/navigation_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc"
......@@ -21,16 +21,15 @@
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:id="@+id/navigation_character_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:id="@+id/navigation_character_details"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />
android:layout_height="wrap_content" />
</LinearLayout>
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