package org.worshipsongs.utils;

import android.content.Context;
import android.text.Spannable;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.widget.TextView;

import org.apache.commons.io.FileUtils;
import org.worshipsongs.CommonConstants;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Created by Seenivasan on 10/26/2014.
 */
public final class PropertyUtils
{

    public static void setProperties(Map<String, String> propertiesMap, File propertiesFile)
    {
        Properties properties = new Properties();
        OutputStream outputStream = null;
        try {

            outputStream = new FileOutputStream(propertiesFile);
            for (String key : propertiesMap.keySet()) {
                properties.setProperty(key, propertiesMap.get(key));
            }
            properties.store(outputStream, "");
        } catch (Exception ex) {

        }
    }

    public static void setProperty(String key, String value, File propertiesFile)
    {
        Map<String, String> propertyMap = new HashMap<String, String>();
        propertyMap.put(key, value);
        setProperties(propertyMap, propertiesFile);
    }

    public static String getProperty(String key, File propertiesFile)
    {
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = new FileInputStream(propertiesFile);
            properties.load(inputStream);
            return properties.get(key).toString();
        } catch (Exception ex) {
            return "";
        }
    }

    public static File getCommonPropertyFile(Context context)
    {
        File commonPropertyFile = null;
        try {
            String configDirPath = "/data/data/config/" + context.getApplicationContext().getPackageName();
            File configDir = new File(configDirPath);
            commonPropertyFile = new File(configDir, CommonConstants.COMMON_PROPERTY_TEMP_FILENAME);
            Log.d("PropertyUtils", "Absolute path " + commonPropertyFile.getAbsolutePath());
            if (!commonPropertyFile.exists()) {
                Log.d("PropertyUtils", "Common property files " + commonPropertyFile + " is not  exists");
                FileUtils.touch(commonPropertyFile);
            } else {
                Log.d("PropertyUtils", "Common property files " + commonPropertyFile + " is  exists");
            }
        } catch (Exception ex) {
            Log.e("PropertyUtils", "Error" + ex);
        }
        return commonPropertyFile;
    }

    public static void appendColoredText(TextView tv, String text, int color)
    {
        Log.d(PropertyUtils.class.getName(), "Lines" + text);
        Log.d(PropertyUtils.class.getName(), "color" + color);
        int start = tv.getText().length();

        tv.append(text);
        tv.append("\n");
        int end = tv.getText().length();

        Spannable spannableText = (Spannable) tv.getText();
        spannableText.setSpan(new ForegroundColorSpan(color), start, end, 0);
    }
}

@@ -1929,15 +1929,8 @@
 ata/
-config/
 %22 + 
@@ -1977,16 +1977,38 @@
 geName()
+ + %22/databases/config%22
 ;%0A      
@@ -2293,24 +2293,77 @@
 exists()) %7B%0A
+                FileUtils.touch(commonPropertyFile);%0A
             
@@ -2457,62 +2457,21 @@
 ists
-%22);%0A                FileUtils.touch(commonPropertyFile
+ and created%22
 );%0A 

Save property file in appropriate location