package com.andela.currencycalculator.manager;

import android.content.Context;

import com.andela.currencycalculator.model.currency.Currency;
import com.andela.currencycalculator.model.dbparser.DbHandler;
import com.andela.currencycalculator.model.jsonparser.CurrencyJsonParser;

import java.util.ArrayList;

/**
 * Created by Spykins on 20/02/2016.
 */
public class ParserDbManager {
    private CurrencyJsonParser currencyJsonParser;
    private DbHandler dbHandler;
    private JsonParserInterface jsonParserInterface;
    private static ParserDbManager parserDbManager;
    private ArrayList<Currency> allCurrency;

    private ParserDbManager(Context context) {
        currencyJsonParser = new CurrencyJsonParser(this);
        jsonParserInterface = (JsonParserInterface) context;
        allCurrency = new ArrayList<>();
        dbHandler = new DbHandler(context, null, null, 1);
        getDataFromJson();
    }

    public static ParserDbManager getInstance(Context context) {
        if (parserDbManager == null) {
            parserDbManager = new ParserDbManager(context);
            return parserDbManager;
        }

        return parserDbManager;

    }

    private void getDataFromJson() {
        currencyJsonParser.loadRate();
    }

    public void addAllCurrencyDataToDb() {
        for (Currency currency : allCurrency) {
            dbHandler.insertCurrencyInDatabase(currency);
        }
        jsonParserInterface.notifyActivity();

    }

    public ArrayList<Currency> readAllCurrencyDataFromDb() {
        return dbHandler.readCurrencyFromDatabase();
    }

    public void parseDataFromJson(ArrayList<Currency> allData) {

        allCurrency = allData;
        addAllCurrencyDataToDb();
    }

    public interface JsonParserInterface {
        void notifyActivity();
    }
}

@@ -612,16 +612,37 @@
 urrency;
+%0A    Context context;
 %0A%0A    pr
@@ -674,32 +674,64 @@
 text context) %7B%0A
+        this.context = context;%0A
         currency
@@ -938,35 +938,8 @@
 1);%0A
-        getDataFromJson();%0A
     
@@ -1197,22 +1197,21 @@
 %7D%0A%0A    p
-rivate
+ublic
  void ge
@@ -1789,16 +1789,16 @@
 rface %7B%0A
-
         
@@ -1825,11 +1825,99 @@
 );%0A    %7D
+%0A%0A    public boolean hasDatabase()%7B%0A        return dbHandler.hasDataBase(context);%0A    %7D
 %0A%7D%0A

Implement if database exists and refactor the code