소스 검색

API v1 Sync implemented, with collateral errors.

The app syncing is now done against the Sync API v1. All tables are perfectly synced and the app can handle the new data. However, some errors have arisen with this change:
* Some characters need reencoding, specially spanish characters. For example, "ñ" is displayed as "\u00f1". This is how the data is received from the API. The reencoding can de applied at database level.
*The transition is not, as of now, possible from installed apps previously using the old syncing mechanism, due to changes on the database structure. This can be fixed by recreating the tables while syncing.
seavenois 10 년 전
부모
커밋
7b336da16e

+ 1 - 1
app/src/main/java/com/ivalentin/margolariak/GalleryLayout.java

@@ -76,7 +76,7 @@ public class GalleryLayout extends Fragment{
 		String lang = GM.getLang();
 
         //Get data from the database
-        cursor = db.rawQuery("SELECT DISTINCT album.id AS id, album.name_" + lang + " AS name FROM photo, album, photo_album WHERE photo.id = photo AND album.id = album ORDER BY uploaded DESC;", null);
+        cursor = db.rawQuery("SELECT DISTINCT album.id AS id, album.title_" + lang + " AS name FROM photo, album, photo_album WHERE photo.id = photo AND album.id = album ORDER BY uploaded DESC;", null);
 
         //Loop
         while (cursor.moveToNext()){

+ 2 - 2
app/src/main/java/com/ivalentin/margolariak/MainActivity.java

@@ -568,8 +568,8 @@ public class MainActivity extends Activity{
 			db.execSQL("CREATE TABLE IF NOT EXISTS activity_image (id INT, activity INT, image VARCHAR, idx INT);");
 			db.execSQL("CREATE TABLE IF NOT EXISTS activity_itinerary (id INT, activity INT, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, start DATETIME, end DATETIME, place INT);");
 			db.execSQL("CREATE TABLE IF NOT EXISTS activity_tag (activity INT, tag VARCHAR);");
-			db.execSQL("CREATE TABLE IF NOT EXISTS album (id INT, permalink VARCHAR, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, open INT, time DATETIME);");
-			db.execSQL("CREATE TABLE IF NOT EXISTS festival (id INT, year INT, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, img VARCHAR);");
+			db.execSQL("CREATE TABLE IF NOT EXISTS album (id INT, permalink VARCHAR, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, open INT, time DATETIME);");
+			db.execSQL("CREATE TABLE IF NOT EXISTS festival (id INT, year INT, text_es VARCHAR, text_en VARCHAR, text_eu VARCHAR, summary_es VARCHAR, summary_en VARCHAR, summary_eu VARCHAR, img VARCHAR);");
 			db.execSQL("CREATE TABLE IF NOT EXISTS festival_day (id INT, date DATETIME, name_es VARCHAR, name_en VARCHAR, name_eu VARCHAR, price INT);");
 			db.execSQL("CREATE TABLE IF NOT EXISTS festival_event (id INT, gm INT, title_es VARCHAR, title_en VARCHAR, title_eu VARCHAR, description_es VARCHAR, description_en VARCHAR, description_eu VARCHAR, host INT, place INT, start DATETIME, end DATETIME);");
 			db.execSQL("CREATE TABLE IF NOT EXISTS festival_event_image (id INT, event INT, image VARCHAR, idx INT);");

+ 11 - 3
app/src/main/java/com/ivalentin/margolariak/Sync.java

@@ -297,7 +297,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 		boolean result = true;
 		//try{
 			str = data.substring(data.indexOf("[") + 1, data.lastIndexOf("]"));
-			while (str.indexOf("]") > 0){
+			while (str.indexOf("}") > 0){
 				try {
 					key = str.substring(str.indexOf("\"") + 1, str.indexOf("\"", str.indexOf("\"") + 1));
 					value = str.substring(str.indexOf("["), str.indexOf("]"));
@@ -307,7 +307,7 @@ class Sync extends AsyncTask<Void, Void, Void> {
 						return false;
 					}
 
-					str = str.substring(str.indexOf("]") + 1);
+					str = str.substring(str.indexOf("}") + 1);
 				}
 				catch (Exception ex){
 					//End of string
@@ -349,8 +349,9 @@ class Sync extends AsyncTask<Void, Void, Void> {
 
 		int i = 0;
 		try {
+			String row;
 			while (str.indexOf("{") > 0) {
-				String row = str.substring(str.indexOf("{"), str.indexOf("}") + 1);
+				row = str.substring(str.indexOf("{"), str.indexOf("}") + 1);
 				totalFields = 0;
 				values = new String[99];
 				keys = new String[99];
@@ -365,6 +366,13 @@ class Sync extends AsyncTask<Void, Void, Void> {
 
 					row = row.substring(row.indexOf(value) + value.length() + 1);
 				}
+				//TODO: Last column
+				row = row.substring(row.indexOf("\"") + 1, row.indexOf("}"));
+				key = row.substring(0, row.indexOf("\""));
+				value = row.substring(row.indexOf(":") + 1);
+				keys[totalFields] = key;
+				values[totalFields] = value;
+				totalFields++;
 
 				//With all the keys and the values, create an INSERT query and add to queries
 				fields = "(";