Commit 7bd2b50c authored by Adrien Oliva's avatar Adrien Oliva

feat(character) Allow switching between characters

Signed-off-by: Adrien Oliva's avatarAdrien Oliva <olivaa+gitlab@yapbreak.fr>
parent e3bba0fc
Pipeline #549 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>
......
......@@ -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;
......@@ -10,9 +11,6 @@ import fr.yapbreak.skyrimquest.data.DataHelper;
public class CharacterSwitch extends AppCompatActivity {
DataHelper data;
ListView mainListView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -20,10 +18,18 @@ public class CharacterSwitch extends AppCompatActivity {
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mainListView = findViewById(R.id.character_listview);
ListView mainListView = findViewById(R.id.character_listview);
data = new DataHelper(this);
CharacterCursorAdapter adapter = new CharacterCursorAdapter(this, data.getAllCharacters());
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,18 +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 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()
{
......@@ -62,7 +68,8 @@ public class QuestList extends AppCompatActivity
/* *****************************************************************************************
Retrieve active character
******************************************************************************************/
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);
......@@ -92,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);
......@@ -100,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();
......@@ -119,7 +124,7 @@ public class QuestList extends AppCompatActivity
* Set up navigation view
*/
mainListView = findViewById(R.id.quests_listview);
ListView mainListView = findViewById(R.id.quests_listview);
/* *****************************************************************************************
Set up database
......@@ -143,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.commit();
updateCharacterInfo();
}
break;
default:
super.onActivityResult(requestCode, resultCode, data);
}
}
@Override
public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout);
......@@ -170,8 +194,7 @@ public class QuestList extends AppCompatActivity
//noinspection SimplifiableIfStatement
if (id == R.id.action_character_switch) {
Intent i = new Intent(this, CharacterSwitch.class);
startActivity(i);
updateCharacterInfo();
startActivityForResult(i, CHARACTER_SWITCH);
return true;
} else if (id == R.id.action_character_create) {
Intent i = new Intent(this, CharacterCreation.class);
......@@ -189,7 +212,7 @@ public class QuestList extends AppCompatActivity
return super.onOptionsItemSelected(item);
}
void copyDatabaseOnExternalData()
private void copyDatabaseOnExternalData()
{
String path = quest_data.getFilename();
......
......@@ -12,19 +12,24 @@ 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;
}
public CharacterCursorAdapter(Context context, Cursor c) {
private final CharacterSwitch m_parent;
public CharacterCursorAdapter(Context context, Cursor c, CharacterSwitch parent) {
super(context, c, true);
m_parent = parent;
}
@Override
......@@ -44,7 +49,7 @@ public class CharacterCursorAdapter extends CursorAdapter {
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
public void bindView(View view, Context context, final Cursor cursor) {
ViewHolder viewHolder = (ViewHolder) view.getTag();
String character_name = cursor.getString(1);
......@@ -61,9 +66,18 @@ public class CharacterCursorAdapter extends CursorAdapter {
}
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)
{
......@@ -364,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;
......
......@@ -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