package com.example.silence.flyweather.util;

import android.text.TextUtils;

import com.example.silence.flyweather.db.FlyWeatherDB;
import com.example.silence.flyweather.model.City;
import com.example.silence.flyweather.model.Province;

/**
 * Created by Silence on 2016/3/29.
 */
public class Utility {
    /**
     * 解析和处理服务器返回的省级数据
     */
    public synchronized static boolean handleProvinceResponse(FlyWeatherDB flyWeatherDB, String response) {
        if (!TextUtils.isEmpty(response)){
            String[] allProvinces = response.split(",");
            if (allProvinces != null && allProvinces.length > 0){
                for (String p : allProvinces){
                    String[] array = p.split("\\|");
                    Province province = new Province();
                    province.setProvinceCode(array[0]);
                    province.setProvinceName(array[1]);
                    //将解析出来的数据存储到Province表
                    flyWeatherDB.saveProvince(province);
                }
                return true;
            }
        }
        return false;
    }

    /**
     * 解析和处理服务器返回的市级数据
     */
    public static boolean handleCitiesResponse(FlyWeatherDB flyWeatherDB, String response, int provinceID){
        if (!TextUtils.isEmpty(response)){
            String[] allCities = response.split(",");
            if (allCities != null && allCities.length > 0){
                for (String c : allCities){
                    String [] array =c.split("\\|");
                    City city = new City();
                    city.setCityCode(array[0]);
                    city.setCityName(array[1]);
                    city.setProvinceId(provinceID);
                    //将解析出来的数据储存到City表
                    flyWeatherDB.savedCity(city);
                }
                return true;
            }
        }
        return false;
    }


}

@@ -176,16 +176,68 @@
 l.City;%0A
+import com.example.silence.flyweather.model.County;%0A
 import c
@@ -282,16 +282,16 @@
 ovince;%0A
-
 %0A/**%0A * 
@@ -1516,16 +1516,17 @@
  array =
+ 
 c.split(
@@ -1914,11 +1914,812 @@
 %0A    %7D%0A%0A
+    /**%0A     * %E8%A7%A3%E6%9E%90%E5%92%8C%E5%A4%84%E7%90%86%E6%9C%8D%E5%8A%A1%E5%99%A8%E8%BF%94%E5%9B%9E%E7%9A%84%E5%8E%BF%E7%BA%A7%E6%95%B0%E6%8D%AE%0A     */%0A    public static boolean handleCountiesResponse(FlyWeatherDB flyWeatherDB, String response, int cityId)%7B%0A        if (!TextUtils.isEmpty(response))%7B%0A            String%5B%5D allCounties = response.split(%22,%22);%0A            if (allCounties != null && allCounties.length %3E 0)%7B%0A                for (String c : allCounties)%7B%0A                    String %5B%5D array = c.split(%22%5C%5C%7C%22);%0A                    County county = new County();%0A                    county.setCountyCode(array%5B0%5D);%0A                    county.setCountyName(array%5B1%5D);%0A                    county.setCityId(cityId);%0A                    //%E5%B0%86%E8%A7%A3%E6%9E%90%E5%87%BA%E6%9D%A5%E7%9A%84%E6%95%B0%E6%8D%AE%E5%82%A8%E5%AD%98%E5%88%B0County%E8%A1%A8%0A                    flyWeatherDB.savedCounty(county);%0A                %7D%0A                return true;%0A            %7D%0A        %7D%0A        return false;%0A    %7D
 %0A%7D%0A

解析服务器返回的数据 wangyufei 2016/3/29