Commit f672ee89 authored by Adrien Oliva's avatar Adrien Oliva

Merge branch '4-character-switch' into 'master'

Resolve "Character switch"

Closes #4

See merge request !3
parents 1f5ee615 1d0be0c4
Pipeline #552 passed with stage
in 0 seconds
*.iml
.gradle
/local.properties
/.idea/caches/build_file_checksums.ser
/.idea/caches/
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
......
......@@ -3,6 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
......
......@@ -5,7 +5,7 @@
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
<option name="myNullables">
<value>
<list size="7">
<list size="10">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
......@@ -13,18 +13,24 @@
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.Nullable" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableDecl" />
<item index="9" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NullableType" />
</list>
</value>
</option>
<option name="myNotNulls">
<value>
<list size="6">
<list size="9">
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
<item index="6" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.qual.NonNull" />
<item index="7" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullDecl" />
<item index="8" class="java.lang.String" itemvalue="org.checkerframework.checker.nullness.compatqual.NonNullType" />
</list>
</value>
</option>
......
......@@ -28,9 +28,14 @@
android:label="@string/title_activity_character_creation"
android:theme="@style/AppTheme.NoActionBar" />
<activity android:name=".CharacterSwitch"
android:label="@string/title_activity_character_switch"
android:theme="@style/AppTheme.NoActionBar" />
<meta-data
android:name="com.google.android.actions"
android:resource="@xml/backup_rules" />
</application>
</manifest>
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class CharacterCreation extends AppCompatActivity {
private EditText levelView;
ArrayList<String> raceIdArray;
private ArrayList<String> raceIdArray;
private final static int LOAD_AVATAR = 1;
......
package fr.yapbreak.skyrimquest;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.ListView;
import fr.yapbreak.skyrimquest.character.CharacterCursorAdapter;
import fr.yapbreak.skyrimquest.data.DataHelper;
public class CharacterSwitch extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_character_switch);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
ListView mainListView = findViewById(R.id.character_listview);
DataHelper data = new DataHelper(this);
CharacterCursorAdapter adapter = new CharacterCursorAdapter(this, data.getAllCharacters(), this);
mainListView.setAdapter(adapter);
}
public void setSelectedCharacter(int character_id) {
Intent intent = new Intent();
intent.putExtra(QuestList.activeCharacter, character_id);
setResult(RESULT_OK, intent);
finish();
}
}
......@@ -3,6 +3,7 @@ package fr.yapbreak.skyrimquest;
import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.graphics.BitmapFactory;
import android.os.Bundle;
......@@ -36,19 +37,23 @@ import fr.yapbreak.skyrimquest.character.Character;
public class QuestList extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {
protected static DataHelper instance;
protected static Context context;
private static final String myPreferences = "SkyrimPreference";
public static final String activeCharacter = "active_character";
private static final int CHARACTER_SWITCH = 1;
private static DataHelper instance;
private static Context context;
private DataHelper quest_data;
private Character activeCharacter;
private static final int EXTERNAL_CODE = 570;
private String[] permission = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
private final String[] permission = {Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE};
ListView mainListView;
NavigationView navigationView;
private NavigationView navigationView;
private SharedPreferences sharedPreferences;
public static DataHelper getDataHandler()
{
......@@ -60,10 +65,11 @@ public class QuestList extends AppCompatActivity
private void updateCharacterInfo()
{
/*******************************************************************************************
/* *****************************************************************************************
Retrieve active character
******************************************************************************************/
activeCharacter = quest_data.getActiveCharacter();
int character_id = sharedPreferences.getInt(activeCharacter, 0);
Character activeCharacter = quest_data.getActiveCharacter(character_id);
if (activeCharacter != null) {
View header = navigationView.getHeaderView(0);
ImageView navigation_avatar = header.findViewById(R.id.navigation_avatar);
......@@ -93,6 +99,8 @@ public class QuestList extends AppCompatActivity
super.onCreate(savedInstanceState);
QuestList.context = getApplicationContext();
sharedPreferences = getSharedPreferences(myPreferences, Context.MODE_PRIVATE);
setContentView(R.layout.activity_quest_list);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
......@@ -101,10 +109,6 @@ public class QuestList extends AppCompatActivity
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
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();
......@@ -116,13 +120,13 @@ public class QuestList extends AppCompatActivity
navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
/**
/*
* Set up navigation view
*/
mainListView = findViewById(R.id.quests_listview);
ListView mainListView = findViewById(R.id.quests_listview);
/*******************************************************************************************
/* *****************************************************************************************
Set up database
******************************************************************************************/
quest_data = new DataHelper(this);
......@@ -144,6 +148,25 @@ public class QuestList extends AppCompatActivity
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case CHARACTER_SWITCH:
if (resultCode == RESULT_OK) {
int selected_character = data.getIntExtra(activeCharacter, 0);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(activeCharacter, selected_character);
editor.apply();
updateCharacterInfo();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
......@@ -170,6 +193,8 @@ public class QuestList extends AppCompatActivity
//noinspection SimplifiableIfStatement
if (id == R.id.action_character_switch) {
Intent i = new Intent(this, CharacterSwitch.class);
startActivityForResult(i, CHARACTER_SWITCH);
return true;
} else if (id == R.id.action_character_create) {
Intent i = new Intent(this, CharacterCreation.class);
......@@ -187,7 +212,7 @@ public class QuestList extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
void copyDatabaseOnExternalData()
private void copyDatabaseOnExternalData()
{
String path = quest_data.getFilename();
......@@ -234,7 +259,7 @@ public class QuestList extends AppCompatActivity
@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
// Handle navigation view item clicks here.
int id = item.getItemId();
......
package fr.yapbreak.skyrimquest.character;
import android.content.Context;
import android.database.Cursor;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import java.lang.reflect.Field;
import fr.yapbreak.skyrimquest.CharacterSwitch;
import fr.yapbreak.skyrimquest.R;
public class CharacterCursorAdapter extends CursorAdapter {
private static class ViewHolder {
int id;
ImageView avatar;
TextView name;
TextView race;
TextView level;
}
private final CharacterSwitch m_parent;
public CharacterCursorAdapter(Context context, Cursor c, CharacterSwitch parent) {
super(context, c, true);
m_parent = parent;
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup viewGroup) {
LayoutInflater inflater = LayoutInflater.from(context);
View myView = inflater.inflate(R.layout.character_fragment, viewGroup, false);
ViewHolder viewHolder = new ViewHolder();
viewHolder.avatar = myView.findViewById(R.id.character_avatar);
viewHolder.name = myView.findViewById(R.id.character_name_label);
viewHolder.race = myView.findViewById(R.id.character_race_label);
viewHolder.level = myView.findViewById(R.id.character_level_label);
myView.setTag(viewHolder);
return myView;
}
@Override
public void bindView(View view, Context context, final Cursor cursor) {
ViewHolder viewHolder = (ViewHolder) view.getTag();
String character_name = cursor.getString(1);
String character_avatar_path = cursor.getString(2);
String character_race_res_id = cursor.getString(3);
Integer character_level = cursor.getInt(4);
String race_label;
try {
Field translatedRace = R.string.class.getDeclaredField(character_race_res_id);
race_label = context.getString(translatedRace.getInt(translatedRace));
} catch (Exception e) {
race_label = character_race_res_id;
}
String character_level_label = context.getString(R.string.character_level_default) + " " + character_level.toString();
viewHolder.id = cursor.getInt(0);
viewHolder.name.setText(character_name);
viewHolder.level.setText(character_level_label);
viewHolder.race.setText(race_label);
viewHolder.avatar.setImageBitmap(BitmapFactory.decodeFile(character_avatar_path));
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
ViewHolder vh = (ViewHolder) view.getTag();
m_parent.setSelectedCharacter(vh.id);
}
});
}
}
......@@ -12,7 +12,7 @@ import java.util.UUID;
import fr.yapbreak.skyrimquest.CharacterCreation;
public class CharacterSaver implements View.OnClickListener {
private CharacterCreation activity;
private final CharacterCreation activity;
public CharacterSaver(CharacterCreation activity) {
this.activity = activity;
......
......@@ -6,7 +6,6 @@ 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;
......@@ -14,7 +13,7 @@ import fr.yapbreak.skyrimquest.character.Character;
public class DataHelper extends SQLiteOpenHelper {
public class DataNotFound extends Exception {
private String msg;
private final String msg;
private DataNotFound(String message)
{
......@@ -288,6 +287,13 @@ public class DataHelper extends SQLiteOpenHelper {
return db.rawQuery("SELECT " + PK_RACE_ID + " AS _id, " + RESOURCE_ID_STRING + " FROM " + RACE_TABLE + " ORDER BY _id", null);
}
public Cursor getAllCharacters()
{
SQLiteDatabase db = getReadableDatabase();
Log.d("SKYRIM", "SELECT " + PK_CHARACTER_ID + " AS _id, " + NAME + ", " + AVATAR_FILENAME + ", R." + RESOURCE_ID_STRING + ", " + LEVEL + " FROM " + CHARACTER_TABLE + ", " + RACE_TABLE + " AS R");
return db.rawQuery("SELECT " + PK_CHARACTER_ID + " AS _id, " + NAME + ", " + AVATAR_FILENAME + ", R." + RESOURCE_ID_STRING + ", " + LEVEL + " FROM " + CHARACTER_TABLE + ", " + RACE_TABLE + " AS R WHERE " + FK_RACE_ID + " = R." + PK_RACE_ID, null);
}
public int getCharacterId(Character c)
{
SQLiteDatabase db = getReadableDatabase();
......@@ -357,11 +363,14 @@ public class DataHelper extends SQLiteOpenHelper {
return getCharacterId(c);
}
public Character getActiveCharacter()
/*public Character getActiveCharacter() {
return getActiveCharacter(0);
}*/
public Character getActiveCharacter(int active)
{
try {
Character c = new Character(1);
return c;
return new Character(active);
} catch (DataNotFound e) {
Log.i("SKYRIM", "No active character found");
return null;
......
......@@ -3,8 +3,8 @@ package fr.yapbreak.skyrimquest.quests;
import android.view.View;
import android.widget.ImageView;
public class LongChangeStatusListener implements View.OnLongClickListener {
private Quest quest;
class LongChangeStatusListener implements View.OnLongClickListener {
private final Quest quest;
LongChangeStatusListener(Quest q)
{
......
package fr.yapbreak.skyrimquest.quests;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
public class QuickChangeStatusListener implements View.OnClickListener {
class QuickChangeStatusListener implements View.OnClickListener {
private Quest myQuest;
private final Quest myQuest;
public QuickChangeStatusListener(Quest quest) {
myQuest = quest;
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CharacterSwitch">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_character_switch" />
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="@+id/character_avatar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:contentDescription="@string/character_avatar_alt"
android:minWidth="50dip"
android:src="@mipmap/ic_default_avatar"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/character_race_label"/>
<TextView
android:id="@+id/character_name_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/character_name_default"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/character_avatar"
/>
<TextView
android:id="@+id/character_race_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/character_race_default"
android:textStyle="italic"
app:layout_constraintLeft_toRightOf="@id/character_avatar"
app:layout_constraintTop_toBottomOf="@id/character_name_label"/>
<TextView
android:id="@+id/character_level_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/character_level_default"
app:layout_constraintTop_toBottomOf="@id/character_name_label"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
......@@ -16,7 +16,8 @@
android:padding="20dp"
android:src="@mipmap/ic_default_avatar"
android:contentDescription="@string/avatar_description"
app:layout_constraintBottom_toBottomOf="@id/sp_race"/>
app:layout_constraintBottom_toBottomOf="@id/sp_race"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:id="@+id/et_name"
......@@ -52,7 +53,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/minus"
app:layout_constraintTop_toBottomOf="@id/tv_level_label" />
app:layout_constraintTop_toBottomOf="@id/tv_level_label"
app:layout_constraintLeft_toLeftOf="parent" />
<EditText
android:id="@+id/et_level"
......
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/activity_character_switch"
tools:context=".CharacterSwitch"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/activity_character_switch" >
<ListView
android:id="@+id/character_listview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</android.support.constraint.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
......@@ -14,6 +13,7 @@
android:contentDescription="@string/quest_img_alt"
android:minWidth="50dip"
android:src="@drawable/ic_success"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="@id/quest_summary"/>
......@@ -24,6 +24,7 @@
android:text="@string/quest_title_default"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@id/quest_img" />
<TextView
......
......@@ -60,4 +60,9 @@
<string name="avatar_description">Avatar</string>
<string name="action_debug_grab_database">Copie base de données</string>
<string name="action_debug_grab_database_result">"Base de données disponnible sous "</string>
<string name="title_activity_character_switch">Changement de personnage</string>
<string name="character_avatar_alt">Avatar du personnage</string>
<string name="character_name_default">Nom du personnage</string>
<string name="character_race_default">Race du personnage</string>
<string name="character_level_default">Niveau</string>
</resources>
\ No newline at end of file
......@@ -4,6 +4,9 @@
<string name="navigation_drawer_close" translatable="false">Close navigation drawer</string>
<string name="nav_header_desc" translatable="false">Navigation header</string>
<string name="action_character_switch">Switch</string>
<string name="action_character_create">Create new…</string>
<string name="action_debug_grab_database">Copy database</string>
<string name="action_debug_grab_database_result">Database available at </string>
<!-- Strings from quest fragment -->
<string name="quest_img_alt">Image related to current quest</string>
......@@ -15,11 +18,15 @@
<string name="character_name_label">Name</string>
<string name="level_label">Level</string>
<string name="character_create">Create</string>
<string name="action_character_create">Create new…</string>
<string name="avatar_description">Avatar picture</string>
<string name="plus" translatable="false">+</string>
<string name="minus" translatable="false">-</string>
<string name="action_debug_grab_database">Copy database</string>
<string name="action_debug_grab_database_result">Database available at </string>
<!-- Strings from Character switch activity -->
<string name="title_activity_character_switch">Character Switch</string>
<string name="character_avatar_alt">Avatar image of current character</string>
<string name="character_name_default">Character name</string>
<string name="character_race_default">Character race default</string>
<string name="character_level_default">Level</string>
</resources>
......@@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
......
#Wed Feb 06 13:51:24 CET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
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