// Path: app/src/main/java/jaakko/jaaska/apptycoon/AppTycoonApp.java
// public class AppTycoonApp extends Application {
// 
//     private static AppTycoonApp sInstance;
// 
//     public static Context getContext() {
//         return sInstance;
//     }
// 
//     @Override
//     public void onCreate() {
//         sInstance = this;
//         super.onCreate();
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/core/GameState.java
// public class GameState {
// 
//     private int mTimeFactor;
//     private Company mCompany;
// 
//     public GameState() {
//         mTimeFactor = 1;
//     }
// 
//     public void setTimeFactor(int timeFactor) {
//         this.mTimeFactor = timeFactor;
//     }
// 
//     public int getTimeFactor() {
//         return mTimeFactor;
//     }
// 
//     public Company getCompany() {
//         return mCompany;
//     }
// 
//     public void setCompany(Company company) {
//         mCompany = company;
//     }
// }


import android.util.Log;
import jaakko.jaaska.apptycoon.AppTycoonApp;
import jaakko.jaaska.apptycoon.engine.core.GameState;
package jaakko.jaaska.apptycoon.storage;



/**
 * Class for accessing local (and cloud) storage of game data.
 *
 * All storage actions outside from .storage package should go through this class.
 */

public class StorageManager {

    private static final String TAG = "StorageManager";

    private static StorageManager mInstance;
    private LocalDatabaseHelper mDbHelper;

    private StorageManager() {
        mDbHelper = new LocalDatabaseHelper(AppTycoonApp.getContext());
    }

    public static StorageManager getInstance() {
        if (mInstance == null) {
            Log.d(TAG, "getInstance() - new instance created");
            mInstance = new StorageManager();
        }

        return mInstance;
    }

    /**
     * Checks if a saved game exists in local storage.
     *
     * @return True if there is an existing game progress in local storage.
     */
    public boolean localSaveGameExists() {
        mDbHelper.openReadable();
        boolean ret = mDbHelper.storedGameStateExists();
        mDbHelper.close();
        Log.d(TAG, "localSaveGameExists() - " + ret);
        return ret;
    }


    /**
     * Load the GameState from local database.
     *
     * @return GameState object with loaded data.
     */
// Path: app/src/main/java/jaakko/jaaska/apptycoon/AppTycoonApp.java
// public class AppTycoonApp extends Application {
// 
//     private static AppTycoonApp sInstance;
// 
//     public static Context getContext() {
//         return sInstance;
//     }
// 
//     @Override
//     public void onCreate() {
//         sInstance = this;
//         super.onCreate();
//     }
// }
// 
// Path: app/src/main/java/jaakko/jaaska/apptycoon/engine/core/GameState.java
// public class GameState {
// 
//     private int mTimeFactor;
//     private Company mCompany;
// 
//     public GameState() {
//         mTimeFactor = 1;
//     }
// 
//     public void setTimeFactor(int timeFactor) {
//         this.mTimeFactor = timeFactor;
//     }
// 
//     public int getTimeFactor() {
//         return mTimeFactor;
//     }
// 
//     public Company getCompany() {
//         return mCompany;
//     }
// 
//     public void setCompany(Company company) {
//         mCompany = company;
//     }
// }


// Path: app/src/main/java/jaakko/jaaska/apptycoon/storage/StorageManager.java
import android.util.Log;
import jaakko.jaaska.apptycoon.AppTycoonApp;
import jaakko.jaaska.apptycoon.engine.core.GameState;

package jaakko.jaaska.apptycoon.storage;



/**
 * Class for accessing local (and cloud) storage of game data.
 *
 * All storage actions outside from .storage package should go through this class.
 */

public class StorageManager {

    private static final String TAG = "StorageManager";

    private static StorageManager mInstance;
    private LocalDatabaseHelper mDbHelper;

    private StorageManager() {
        mDbHelper = new LocalDatabaseHelper(AppTycoonApp.getContext());
    }

    public static StorageManager getInstance() {
        if (mInstance == null) {
            Log.d(TAG, "getInstance() - new instance created");
            mInstance = new StorageManager();
        }

        return mInstance;
    }

    /**
     * Checks if a saved game exists in local storage.
     *
     * @return True if there is an existing game progress in local storage.
     */
    public boolean localSaveGameExists() {
        mDbHelper.openReadable();
        boolean ret = mDbHelper.storedGameStateExists();
        mDbHelper.close();
        Log.d(TAG, "localSaveGameExists() - " + ret);
        return ret;
    }


    /**
     * Load the GameState from local database.
     *
     * @return GameState object with loaded data.
     */
    public GameState loadFromDb() {