@@ -0,0 +1,3229 @@
+package com.example.habitrack;%0A%0Aimport android.content.Context;%0A%0Aimport com.google.gson.Gson;%0Aimport com.google.gson.reflect.TypeToken;%0A%0Aimport java.io.BufferedReader;%0Aimport java.io.FileInputStream;%0Aimport java.io.FileNotFoundException;%0Aimport java.io.FileOutputStream;%0Aimport java.io.IOException;%0Aimport java.io.InputStreamReader;%0Aimport java.io.OutputStreamWriter;%0Aimport java.lang.reflect.Type;%0Aimport java.util.ArrayList;%0Aimport java.util.Calendar;%0A%0A/**%0A * Created by sshussai on 11/29/17.%0A */%0A%0A/**%0A * Steps to add a new object:%0A * 1. Declare a base object%0A * 2. Declare a public final MODE value%0A * 2. Declare a private final FILENAME value%0A * 3. Add the if case to the save function. Modify as needed%0A * 4. Add the if case to the load function. Modify as needed%0A */%0A%0Apublic class FileManager %7B%0A%0A    private Context ctx;%0A%0A    // 1. Base objects%0A    private ArrayList%3CHabitTypeMetadata%3E habitTypeMetadata;%0A%0A    // 2. MODES%0A    public final Integer HT_METADATA_MODE = 100;%0A%0A    // 3. FILENAMES%0A    private String filename;%0A    private final String HT_METADATA_FILE = %22htmetadata.sav%22;%0A%0A    // Constructor%0A    public FileManager(Context context) %7B%0A        this.ctx = context;%0A    %7D%0A%0A    public void save(Integer mode)%7B%0A        // 4. If cases for the save function%0A        if(mode == HT_METADATA_MODE)%7B%0A            habitTypeMetadata = HabitTypeStateManager.getHTStateManager().getHtMetadata();%0A            filename = HT_METADATA_FILE;%0A        %7D%0A        try %7B%0A            FileOutputStream fos = ctx.openFileOutput(filename,0);%0A            OutputStreamWriter writer = new OutputStreamWriter(fos);%0A            Gson gson = new Gson();%0A            if(mode == HT_METADATA_MODE) %7B%0A                gson.toJson(habitTypeMetadata, writer);%0A            %7D%0A            writer.flush();%0A        %7D catch (FileNotFoundException e) %7B%0A            // TODO Auto-generated catch block%0A            throw new RuntimeException();%0A        %7D catch (IOException e) %7B%0A            // TODO Auto-generated catch block%0A            throw new RuntimeException();%0A        %7D%0A    %7D%0A%0A    public void load(Integer mode) %7B%0A        // 5. If cases for load function%0A        if(mode == HT_METADATA_MODE)%7B%0A            filename = HT_METADATA_FILE;%0A        %7D%0A        try %7B%0A            FileInputStream fis = ctx.openFileInput(filename);%0A            BufferedReader in = new BufferedReader(new InputStreamReader(fis));%0A            Gson gson = new Gson();%0A            //Code taken from http://stackoverflow.com/questions/12384064/gson-convert-from-json-to-a-typed-arraylistt Sept.22,2016%0A            if(mode == HT_METADATA_MODE) %7B%0A                Type calType = new TypeToken%3CArrayList%3CHabitTypeMetadata%3E%3E() %7B%7D.getType();%0A                habitTypeMetadata = gson.fromJson(in, calType);%0A            %7D%0A        %7D catch (FileNotFoundException e) %7B%0A            // TODO Auto-generated catch block%0A            if(mode == HT_METADATA_MODE)%7B%0A                habitTypeMetadata = new ArrayList%3CHabitTypeMetadata%3E();%0A            %7D%0A        %7D catch (IOException e) %7B%0A            // TODO Auto-generated catch block%0A            throw new RuntimeException();%0A        %7D%0A        if(mode == HT_METADATA_MODE)%7B%0A            HabitTypeStateManager.setHtMetadata(habitTypeMetadata);%0A        %7D%0A    %7D%0A%0A%7D%0A%0A

add new filemanager class to refactor load/save methods