Summary 5
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index 21b86d3..a0f719d 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -8,6 +8,8 @@
android:minSdkVersion="14"
android:targetSdkVersion="17" />
+ <uses-permission android:name="android.permission.INTERNET"/>
+
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
diff --git a/src/org/climbingguide/gui/FragmentCreateArea.java b/src/org/climbingguide/gui/FragmentCreateArea.java
index 3e753c5..b8b12d0 100644
--- a/src/org/climbingguide/gui/FragmentCreateArea.java
+++ b/src/org/climbingguide/gui/FragmentCreateArea.java
@@ -1,10 +1,49 @@
package org.climbingguide.gui;
+
+import org.climbingguide.main.R;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.annotation.SuppressLint;
import android.app.Fragment;
+import android.os.Bundle;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
@SuppressLint("ValidFragment")
public class FragmentCreateArea extends Fragment{
+
+ JSONObject json = new JSONObject();
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ getActivity().setTitle("CreateArea");
+ View view = inflater.inflate(R.layout.create_area,container, false);
+ Button b1 = (Button) view.findViewById(R.id.button1);
+
+ b1.setOnClickListener(onClickListener);
+ return view;
+ }
+ private OnClickListener onClickListener = new OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ EditText e1 = (EditText)v.findViewById(R.id.editText1);
+ try {
+ json.put("area_name", e1.getText().toString());
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ };
+
}
diff --git a/src/org/climbingguide/gui/FragmentCreateRoute.java b/src/org/climbingguide/gui/FragmentCreateRoute.java
index 6c0a1cd..ecee434 100644
--- a/src/org/climbingguide/gui/FragmentCreateRoute.java
+++ b/src/org/climbingguide/gui/FragmentCreateRoute.java
@@ -1,36 +1,72 @@
package org.climbingguide.gui;
-import java.util.ArrayList;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
import java.util.List;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
import org.climbingguide.dao.SectorDao;
import org.climbingguide.main.R;
import org.climbingguide.model.Sector;
+import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
-import android.annotation.SuppressLint;
import android.app.Fragment;
import android.os.Bundle;
+import android.os.StrictMode;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.view.View.OnClickListener;
+import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class FragmentCreateRoute extends Fragment{
public int id;
+ EditText e1;
+ EditText e2;
+ EditText e3;
+ EditText e4;
+ EditText e5;
+ TextView v1;
+ TextView v2;
+ TextView v3;
+ TextView v4;
+ TextView v5;
+ TextView v6;
+ int i;
+
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
+
getActivity().setTitle("CreateRoute");
View view = inflater.inflate(R.layout.create_route,container, false);
- int i = getArguments().getInt("idOfSector");
Button b1 = (Button) view.findViewById(R.id.button1);
+ i = getArguments().getInt("idOfSector");
+
+ e1 = (EditText)view.findViewById(R.id.editText1);
+ e2 = (EditText)view.findViewById(R.id.editText2);
+ e3 = (EditText)view.findViewById(R.id.editText3);
+ e4 = (EditText)view.findViewById(R.id.editText4);
+ e5 = (EditText)view.findViewById(R.id.editText5);
+ v1 = (TextView)view.findViewById(R.id.textView1);
+ v2 = (TextView)view.findViewById(R.id.textView2);
+ v3 = (TextView)view.findViewById(R.id.textView3);
+ v4 = (TextView)view.findViewById(R.id.textView4);
+ v5 = (TextView)view.findViewById(R.id.textView5);
+ v6 = (TextView)view.findViewById(R.id.textView6);
SectorDao dao = new SectorDao(getActivity());
dao.open();
@@ -39,48 +75,60 @@
b1.setOnClickListener(onClickListener);
EditText e2 = (EditText)view.findViewById(R.id.editText2);
- e2.setText(sectorList.get(i).getName());
- e2.setClickable(false);
+ e2.setText(sectorList.get(i-1).getName());
+ e2.setEnabled(false);
return view;
}
private OnClickListener onClickListener = new OnClickListener() {
@Override
public void onClick(final View v) {
- EditText e1 = (EditText)v.findViewById(R.id.editText1);
-
-// e2.setText(text);
- EditText e3 = (EditText)v.findViewById(R.id.editText3);
- EditText e4 = (EditText)v.findViewById(R.id.editText4);
- EditText e5 = (EditText)v.findViewById(R.id.editText5);
- TextView v1 = (TextView)v.findViewById(R.id.textView1);
- TextView v2 = (TextView)v.findViewById(R.id.textView2);
- TextView v3 = (TextView)v.findViewById(R.id.textView3);
- TextView v4 = (TextView)v.findViewById(R.id.textView4);
- TextView v5 = (TextView)v.findViewById(R.id.textView5);
- TextView v6 = (TextView)v.findViewById(R.id.textView6);
-
+
+ StrictMode.setThreadPolicy(policy);
JSONObject json = new JSONObject();
+ JSONArray array = new JSONArray();
try {
- json.put("route_name", e1.getText().toString());
- //json.put("sector", e2.getText().toString());
- json.put("difficulty", e3.getText().toString());
- json.put("bolts", e4.getText().toString());
- json.put("length", e5.getText().toString());
+ json.put("route_name", e1.getText());
+ json.put("id_of_sector", (i-1));
+ json.put("difficulty", e3.getText());
+ json.put("bolts", e4.getText());
+ json.put("length", e5.getText());
+
} catch (JSONException e) {
- e.printStackTrace();
+ e.printStackTrace();
}
+ array.put(json);
+ JSONObject json2 = new JSONObject();
try {
- v1.setText( id);
- v3.setText((CharSequence) json.get("difficulty"));
- v4.setText((CharSequence) json.get("bolts"));
- v5.setText((CharSequence) json.get("length"));
+ json2.put("routes", array);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
+ v6.setText(json2.toString());
+
+ final String CODEPAGE = "UTF-8";
+ HttpPost post = new HttpPost("http://climbingguide.madzik.sk/route.php");
+ try {
+ post.setEntity(new StringEntity(json2.toString(), CODEPAGE));
+ } catch (UnsupportedEncodingException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ HttpResponse resp = null;
+ HttpClient httpclient = new DefaultHttpClient();
+ try {
+ resp = httpclient.execute(post);
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ v6.setText(resp.toString());
}
};
diff --git a/src/org/climbingguide/gui/FragmentCreateSector.java b/src/org/climbingguide/gui/FragmentCreateSector.java
index b5c1826..3b7644e 100644
--- a/src/org/climbingguide/gui/FragmentCreateSector.java
+++ b/src/org/climbingguide/gui/FragmentCreateSector.java
@@ -1,9 +1,123 @@
package org.climbingguide.gui;
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.util.List;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.entity.StringEntity;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.climbingguide.dao.AreaDao;
+import org.climbingguide.dao.SectorDao;
+import org.climbingguide.main.R;
+import org.climbingguide.model.Area;
+import org.climbingguide.model.Sector;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.annotation.SuppressLint;
import android.app.Fragment;
+import android.os.Bundle;
+import android.os.StrictMode;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.View.OnClickListener;
+import android.widget.Button;
+import android.widget.EditText;
+import android.widget.TextView;
@SuppressLint("ValidFragment")
public class FragmentCreateSector extends Fragment{
+ EditText e1;
+ EditText e2;
+ TextView t1;
+ int i;
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+
+
+ JSONObject json = new JSONObject();
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container,
+ Bundle savedInstanceState) {
+
+ getActivity().setTitle("CreateSector");
+ View view = inflater.inflate(R.layout.create_sector,container, false);
+ i = getArguments().getInt("idOfArea");
+ Button b1 = (Button) view.findViewById(R.id.button1);
+
+ AreaDao dao = new AreaDao(getActivity());
+ dao.open();
+ List<Area> areaList = dao.getAllAreas();
+ dao.close();
+
+ b1.setOnClickListener(onClickListener);
+ e1 = (EditText)view.findViewById(R.id.editText1);
+ e2 = (EditText)view.findViewById(R.id.editText2);
+ t1 = (TextView)view.findViewById(R.id.textView1);
+ e2.setText(areaList.get(i-1).getName());
+ e2.setEnabled(false);
+ try {
+ json.put("id_area", (i-1));
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return view;
+ }
+
+ private OnClickListener onClickListener = new OnClickListener() {
+ @Override
+ public void onClick(final View v) {
+ StrictMode.setThreadPolicy(policy);
+ JSONObject json = new JSONObject();
+
+ try {
+ json.put("sector_name", e1.getText());
+ json.put("id_of_area", (i-1));
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ JSONObject json2 = new JSONObject();
+ JSONArray array = new JSONArray();
+ array.put(json);
+
+ try {
+ json2.put("sectors", array);
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+ final String CODEPAGE = "UTF-8";
+ HttpPost post = new HttpPost("http://climbingguide.madzik.sk/sector.php");
+ try {
+ post.setEntity(new StringEntity(json2.toString(), CODEPAGE));
+ } catch (UnsupportedEncodingException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+ HttpResponse resp = null;
+ HttpClient httpclient = new DefaultHttpClient();
+ try {
+ resp = httpclient.execute(post);
+ } catch (ClientProtocolException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+ }
+ };
}
+
+
diff --git a/src/org/climbingguide/gui/FragmentRoutes.java b/src/org/climbingguide/gui/FragmentRoutes.java
index 20738c1..74dc4a9 100644
--- a/src/org/climbingguide/gui/FragmentRoutes.java
+++ b/src/org/climbingguide/gui/FragmentRoutes.java
@@ -23,14 +23,14 @@
private RouteDao getRoutes;
private List<Route> routeList = new ArrayList<Route>();
private Route route = new Route();
-
+ private int idOfSector;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().setTitle("Routes");
getRoutes = new RouteDao(getActivity());
- int idOfSector = getArguments().getInt("idOfSector");
+ idOfSector = getArguments().getInt("idOfSector");
@@ -78,16 +78,16 @@
public int getIdOfSector()
{
- int i;
- if(routeList.isEmpty())
- {
- i = -1;
- }
- else
- {
- route = routeList.get(0);
- i = route.getIdOfSector();
- }
- return i;
+// int i;
+// if(routeList.isEmpty())
+// {
+// i = -1;
+// }
+// else
+// {
+// route = routeList.get(0);
+// i = route.getIdOfSector();
+// }
+ return idOfSector;
}
}
diff --git a/src/org/climbingguide/gui/FragmentSectors.java b/src/org/climbingguide/gui/FragmentSectors.java
index bb96fd0..23a9922 100644
--- a/src/org/climbingguide/gui/FragmentSectors.java
+++ b/src/org/climbingguide/gui/FragmentSectors.java
@@ -19,16 +19,15 @@
private SectorDao getSectors;
private List<Sector> sectorList = new ArrayList<Sector>();
private Sector sector = new Sector();
+ private int idOfArea;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
getActivity().setTitle("Sectors");
getSectors = new SectorDao(getActivity());
- int idOfArea = getArguments().getInt("idOfArea");
+ idOfArea = getArguments().getInt("idOfArea");
-
-
getSectors.open();
sectorList = getSectors.getSector(idOfArea); //get by area
@@ -64,17 +63,17 @@
public int getIdOfArea()
{
- int i;
- if(sectorList.isEmpty())
- {
- i = -1;
- }
- else{
- sector = sectorList.get(0);
-
- i = sector.getIdOfArea();
- }
- return i;
+// int i;
+// if(sectorList.isEmpty())
+// {
+// i = -1;
+// }
+// else{
+// sector = sectorList.get(0);
+//
+// i = sector.getIdOfArea();
+// }
+ return idOfArea;
}
}
diff --git a/src/org/climbingguide/gui/SearchRoutes.java b/src/org/climbingguide/gui/SearchRoutes.java
index 8f795f4..75e437a 100644
--- a/src/org/climbingguide/gui/SearchRoutes.java
+++ b/src/org/climbingguide/gui/SearchRoutes.java
@@ -19,6 +19,7 @@
private RouteDao getRoutes;
private List<Route> routeList = new ArrayList<Route>();
private Route route = new Route();
+ int idOfSector;
@Override
public void onActivityCreated(Bundle savedInstanceState) {
@@ -27,7 +28,7 @@
getRoutes = new RouteDao(getActivity());
String query = getArguments().getString("query");
- int idOfSector = getArguments().getInt("idOfSector");
+ idOfSector = getArguments().getInt("idOfSector");
getRoutes.open();
if(idOfSector >= 0)
@@ -78,14 +79,20 @@
public int getIdOfSector()
{
int i;
- if(routeList.isEmpty())
+ if(idOfSector >= 0)
{
- i = -1;
+ i = idOfSector;
}
else
{
- route = routeList.get(0);
- i = route.getIdOfSector();
+ if(routeList.isEmpty())
+ {
+ i = -1;
+ }
+ else{
+ route = routeList.get(0);
+ i = route.getIdOfSector();
+ }
}
return i;
}
diff --git a/src/org/climbingguide/gui/SearchSectors.java b/src/org/climbingguide/gui/SearchSectors.java
index 885eb3d..49a82a4 100644
--- a/src/org/climbingguide/gui/SearchSectors.java
+++ b/src/org/climbingguide/gui/SearchSectors.java
@@ -19,6 +19,8 @@
private SectorDao getSectors;
private List<Sector> sectorList = new ArrayList<Sector>();
private Sector sector = new Sector();
+ private int idOfArea;
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
@@ -26,7 +28,7 @@
getSectors = new SectorDao(getActivity());
String query = getArguments().getString("query");
- int idOfArea = getArguments().getInt("idOfArea");
+ idOfArea = getArguments().getInt("idOfArea");
getSectors.open();
if(idOfArea >= 0)
@@ -69,14 +71,19 @@
public int getIdOfArea()
{
int i;
- if(sectorList.isEmpty())
+ if(idOfArea >= 0)
{
- i = -1;
+ i = idOfArea;
}
else{
- sector = sectorList.get(0);
-
- i = sector.getIdOfArea();
+ if(sectorList.isEmpty())
+ {
+ i = -1;
+ }else{
+
+ sector = sectorList.get(0);
+ i = sector.getIdOfArea();
+ }
}
return i;
}
diff --git a/src/org/climbingguide/main/MainActivity.java b/src/org/climbingguide/main/MainActivity.java
index 4796c72..65416ca 100644
--- a/src/org/climbingguide/main/MainActivity.java
+++ b/src/org/climbingguide/main/MainActivity.java
@@ -226,6 +226,7 @@
if(areaAll != null && areaAll.isVisible()){
SearchAreas fragment = new SearchAreas();
+ fragment.setArguments(bundle);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
tagFragment = "AreasSearch";
transaction.replace(R.id.frame_container, fragment,tagFragment);
@@ -240,6 +241,8 @@
if(sectorAll != null && sectorAll.isVisible()){
SearchSectors fragment = new SearchSectors();
+ fragment.setArguments(bundle);
+ bundle.putInt("idOfArea",-1);
tagFragment="SectorsSearch";
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_container, fragment,tagFragment);
@@ -253,6 +256,8 @@
if(routeAll != null && routeAll.isVisible()){
SearchRoutes fragment = new SearchRoutes();
+ fragment.setArguments(bundle);
+ bundle.putInt("idOfSector",-1);
FragmentTransaction transaction = getFragmentManager().beginTransaction();
tagFragment="RoutesSearch";
transaction.replace(R.id.frame_container, fragment,tagFragment);
@@ -266,6 +271,8 @@
if(sector != null && sector.isVisible()){
SearchSectors fragment = new SearchSectors();
+ fragment.setArguments(bundle);
+ bundle.putInt("idOfArea",sector.getIdOfArea());
tagFragment = "SectorsSearch";
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_container, fragment,tagFragment);
@@ -279,6 +286,8 @@
if(route != null && route.isVisible() ){
SearchRoutes fragment = new SearchRoutes();
+ fragment.setArguments(bundle);
+ bundle.putInt("idOfSector",route.getIdOfSector());
tagFragment = "RoutesSearch";
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.frame_container, fragment,tagFragment);
@@ -324,6 +333,7 @@
switch (position) {
case 0:
fragment = new FragmentAreasAll();
+
tagFragment = "AreasAll";
break;
case 1:
@@ -375,15 +385,15 @@
fragment = new FragmentCreateRoute();
bundle.putInt("idOfSector", route.getIdOfSector());
fragment.setArguments(bundle);
- tagFragment = "CreateSector";
+ tagFragment = "CreateRoute";
break;
}
-// fragment = new FragmentCreateRoute();
-// tagFragment = "Create";
-// break;
-// case 4:
-// fragment = new ();
-// break;
+ case 4:
+ Update update = new Update();
+ update.updateA(getApplicationContext());
+ update.updateS(getApplicationContext());
+ update.updateR(getApplicationContext());
+ break;
// case 5:
// fragment = new ();
// break;
diff --git a/src/org/climbingguide/update/Update.java b/src/org/climbingguide/update/Update.java
index aca88e3..75eff4f 100644
--- a/src/org/climbingguide/update/Update.java
+++ b/src/org/climbingguide/update/Update.java
@@ -1,18 +1,103 @@
package org.climbingguide.update;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.List;
+
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.ClientProtocolException;
+import org.apache.http.client.HttpClient;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.climbingguide.dao.AreaDao;
+import org.climbingguide.dao.RouteDao;
+import org.climbingguide.dao.SectorDao;
+import org.climbingguide.model.Area;
+import org.climbingguide.model.Route;
+import org.climbingguide.model.Sector;
+import org.json.JSONArray;
+import org.json.JSONException;
+import org.json.JSONObject;
+
import android.content.Context;
+import android.os.StrictMode;
+import android.util.Log;
+import android.widget.Toast;
public class Update {
+
+ StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
+
+ public String readFeedFrom(String http){
+ StrictMode.setThreadPolicy(policy);
+ StringBuilder builder = new StringBuilder();
+ HttpClient client = new DefaultHttpClient();
+ HttpGet httpGet = new HttpGet(http);
+ try {
+ HttpResponse response = client.execute(httpGet);
+ StatusLine statusLine = response.getStatusLine();
+ int statusCode = statusLine.getStatusCode();
+ if (statusCode == 200) {
+ HttpEntity entity = response.getEntity();
+ InputStream content = entity.getContent();
+ BufferedReader reader = new BufferedReader(new InputStreamReader(content));
+ String line;
+ while ((line = reader.readLine()) != null) {
+ builder.append(line);
+ }
+ }
+ } catch (ClientProtocolException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ return builder.toString();
+
+ }
//----------------------------------------------------------
public void updateA(Context context)
{
UpdateArea area = new UpdateArea();
+ AreaDao daoa = new AreaDao(context);
+ daoa.open();
+ List <Area> listOfAreas = daoa.getAllAreas();
+ daoa.close();
+
+ String primeAreas = readFeedFrom("http://climbingguide.madzik.sk/areas.php");
- area.updateArea(1, "Drevenik",context);
- area.updateArea(2, "Turniska",context);
- area.updateArea(3, "Zamutov",context);
- area.updateArea(4, "Zadiel",context);
+ try {
+ JSONObject areas = new JSONObject(primeAreas);
+ JSONArray arrayAreas = new JSONArray();
+ arrayAreas = areas.getJSONArray("areas");
+ int i =0;
+ if(listOfAreas.size()<arrayAreas.length()){
+ for(i=listOfAreas.size();i<arrayAreas.length();i++){
+
+ JSONObject HTTPArea = new JSONObject();
+ HTTPArea = arrayAreas.getJSONObject(i);
+ area.updateArea(HTTPArea.getInt("id_area"), HTTPArea.getString("area_name"), context);
+ }
+ }
+ else{
+ Toast.makeText(context, "Your areas are up to date", Toast.LENGTH_LONG).show();
+
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+
+
+// area.updateArea(1, "Drevenik",context);
+// area.updateArea(2, "Turniska",context);
+// area.updateArea(3, "Zamutov",context);
+// area.updateArea(4, "Zadiel",context);
}
@@ -21,18 +106,47 @@
{
UpdateSector sector = new UpdateSector();
- sector.updateSector(1,"Peklo",1,context);
- sector.updateSector(2,"Raj",1,context);
- sector.updateSector(3,"Najvyssia turna",2,context);
- sector.updateSector(4,"Velkonocna turna",2,context);
- sector.updateSector(5,"Zarastena turna",2,context);
- sector.updateSector(6,"Mur",2,context);
- sector.updateSector(7,"Klemba",2,context);
- sector.updateSector(8,"Najnisia turna",2,context);
- sector.updateSector(9,"Cervene previsy",1,context);
- sector.updateSector(10,"Marta",1,context);
- sector.updateSector(11,"Amerika",1,context);
- sector.updateSector(12,"Previsy",3,context);
+ SectorDao daoa = new SectorDao(context);
+ daoa.open();
+ List <Sector> listOfSectors = daoa.getAllSectors();
+ daoa.close();
+
+ String primeSectors = readFeedFrom("http://climbingguide.madzik.sk/sectors.php");
+
+ try {
+ JSONObject sectors = new JSONObject(primeSectors);
+ JSONArray arraySectors = new JSONArray();
+ arraySectors = sectors.getJSONArray("sectors");
+ int i =0;
+ if(listOfSectors.size()<arraySectors.length()){
+ for(i=listOfSectors.size();i<arraySectors.length();i++){
+
+ JSONObject HTTPSector = new JSONObject();
+ HTTPSector = arraySectors.getJSONObject(i);
+ sector.updateSector(HTTPSector.getInt("id_sector"), HTTPSector.getString("sector_name"), HTTPSector.getInt("id_of_area"), context);
+ }
+ }
+ else{
+ Toast.makeText(context, "Your sectors are up to date", Toast.LENGTH_LONG).show();
+
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+// sector.updateSector(1,"Peklo",1,context);
+// sector.updateSector(2,"Raj",1,context);
+// sector.updateSector(3,"Najvyssia turna",2,context);
+// sector.updateSector(4,"Velkonocna turna",2,context);
+// sector.updateSector(5,"Zarastena turna",2,context);
+// sector.updateSector(6,"Mur",2,context);
+// sector.updateSector(7,"Klemba",2,context);
+// sector.updateSector(8,"Najnisia turna",2,context);
+// sector.updateSector(9,"Cervene previsy",1,context);
+// sector.updateSector(10,"Marta",1,context);
+// sector.updateSector(11,"Amerika",1,context);
+// sector.updateSector(12,"Previsy",3,context);
}
//---------------------------------------------------------------
@@ -40,10 +154,39 @@
{
UpdateRoute route = new UpdateRoute();
- route.updateRoute(1, "Moreplavec", 12, "7", 6, 10, 48.9947059,21.2347516, context);
- route.updateRoute(2, "Vecko", 12, "7-", 8, 15, 48.9947059,21.2347516, context);
- route.updateRoute(3, "Flora",3,"9/9+",6, 10, 48.9947059,21.2347516, context);
- route.updateRoute(4, "Vanicky",3, "8+",10, 17, 48.9947059,21.2347516, context);
+ RouteDao daoa = new RouteDao(context);
+ daoa.open();
+ List <Route> listOfRoutes = daoa.getAllRoutes();
+ daoa.close();
+
+ String primeRoutes = readFeedFrom("http://climbingguide.madzik.sk/routes.php");
+
+ try {
+ JSONObject routes = new JSONObject(primeRoutes);
+ JSONArray arrayRoutes = new JSONArray();
+ arrayRoutes = routes.getJSONArray("routes");
+ int i =0;
+ if(listOfRoutes.size()<arrayRoutes.length()){
+ for(i=listOfRoutes.size();i<arrayRoutes.length();i++){
+
+ JSONObject HTTPRoute = new JSONObject();
+ HTTPRoute = arrayRoutes.getJSONObject(i);
+ route.updateRoute(HTTPRoute.getInt("id_route"), HTTPRoute.getString("route_name"), HTTPRoute.getInt("id_of_sector"), HTTPRoute.getString("difficulty"), HTTPRoute.getInt("bolts"), HTTPRoute.getInt("length"), 48.9947059, 21.2347516, context);
+ }
+ }
+ else{
+ Toast.makeText(context, "Your routes are up to date", Toast.LENGTH_LONG).show();
+
+ }
+ } catch (JSONException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+
+// route.updateRoute(1, "Moreplavec", 12, "7", 6, 10, 48.9947059,21.2347516, context);
+// route.updateRoute(2, "Vecko", 12, "7-", 8, 15, 48.9947059,21.2347516, context);
+// route.updateRoute(3, "Flora",3,"9/9+",6, 10, 48.9947059,21.2347516, context);
+// route.updateRoute(4, "Vanicky",3, "8+",10, 17, 48.9947059,21.2347516, context);
}
}