package gr.efrag.timeseriesdata.activities;

import android.app.Activity;
import android.content.Intent;

import java.text.SimpleDateFormat;
import java.util.Locale;

/**
 * This class will be extended by the AddRecord and EditRecord activities so that they
 * can share the code about updating a record if a duplicate record has been found.
 */
public abstract class ManageRecordActivity extends BaseActivity {
    protected SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.US);

    /**
     * Helper method that allows us to update the value of a record
     * @param updateRecordId
     * @param value
     */
    public void doUpdateRecord(int updateRecordId, double value, int deleteRecordId) {
        dbHelper.updateRecord(updateRecordId, value);

        if (deleteRecordId != 0) {
            dbHelper.deleteRecord(deleteRecordId);
        }

        Intent returnIntent = new Intent();
        setResult(Activity.RESULT_OK, returnIntent);
        finish();
    }
}
