Skip to content

Commit

Permalink
Fixed import/export to XML.
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristi Libotean committed Mar 5, 2019
1 parent 8ac6f62 commit bf11d01
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 27 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ android {
storePassword keystoreProperties['KeyPassword']
}
}
compileSdkVersion 27
buildToolsVersion '27.0.3'
compileSdkVersion 28
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.eblis.whenwasit"
minSdkVersion 16
targetSdkVersion 27
targetSdkVersion 28
versionCode 36
versionName "1.0.${versionCode}"
resConfigs "auto"
resConfigs "en", "be", "de", "el", "es", "fil", "fr", "hu", "in", "it", "ja", "kab", "kk", "nb", "nl", "pt", "ro", "ru", "tr", "uk", "zh"
vectorDrawables.useSupportLibrary = true
resValue "string", "version_name", versionName
manifestPlaceholders = [fabric_api_key: keystoreProperties['FabricApiKey']]
Expand Down
37 changes: 20 additions & 17 deletions app/src/main/java/com/eblis/whenwasit/backup/ExportHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ public class ExportHelper {
private static final String EMAIL = "email";
private static final String BACKUP = "backup";
private static final String UTF_8 = "UTF-8";
private static final String CATEGORY = "category";
private static final String ANNIVERSARY_LABEL = "anniversary_label";
private static final String ANNIVERSARY_TYPE = "anniversary_type";

// Exceptions constants
private static final String ILLEGAL_ARGUMENT_EXCEPTION = "IllegalArgumentException";
Expand Down Expand Up @@ -81,6 +84,12 @@ private String getBackupFileName() {
return BACKUP + "_" + Utils.getDate(now) + "_" + String.valueOf(now) + ".xml";
}

private void writeTag(String tag, String value, XmlSerializer xmlSerializer) throws IOException {
xmlSerializer.startTag(null, tag);
xmlSerializer.text(value);
xmlSerializer.endTag(null, tag);
}

private String writeXml(List<Person> persons) {
XmlSerializer xmlSerializer = Xml.newSerializer();
StringWriter stringWriter = new StringWriter();
Expand All @@ -91,27 +100,21 @@ private String writeXml(List<Person> persons) {
for (Person person : persons) {
xmlSerializer.startTag(null, PERSON);
// name
xmlSerializer.startTag(null, NAME);
xmlSerializer.text(person.getName());
xmlSerializer.endTag(null, NAME);
writeTag(NAME, person.getName(), xmlSerializer);
// date
xmlSerializer.startTag(null, DATE);
xmlSerializer.text(String.valueOf(person.getDate()));
xmlSerializer.endTag(null, DATE);
writeTag(DATE, String.valueOf(person.getDate()), xmlSerializer);
// year unknown
xmlSerializer.startTag(null, YEAR_UNKNOWN);
xmlSerializer.text(String.valueOf(person.isYearUnknown()));
xmlSerializer.endTag(null, YEAR_UNKNOWN);
writeTag(YEAR_UNKNOWN, String.valueOf(person.isYearUnknown()), xmlSerializer);
// phone number
xmlSerializer.startTag(null, PHONE_NUMBER);
String phoneNumber = person.getPhoneNumber() == null ? "" : person.getPhoneNumber();
xmlSerializer.text(phoneNumber);
xmlSerializer.endTag(null, PHONE_NUMBER);
writeTag(PHONE_NUMBER, person.getPhoneNumber() == null ? "" : person.getPhoneNumber(), xmlSerializer);
// email
xmlSerializer.startTag(null, EMAIL);
String email = person.getEmail() == null ? "" : person.getEmail();
xmlSerializer.text(email);
xmlSerializer.endTag(null, EMAIL);
writeTag(EMAIL, person.getEmail() == null ? "" : person.getEmail(), xmlSerializer);
//category
writeTag(CATEGORY, person.getContactCategory(), xmlSerializer);
//label
writeTag(ANNIVERSARY_LABEL, person.getAnniversaryLabel(), xmlSerializer);
//type
writeTag(ANNIVERSARY_TYPE, person.getAnniversaryType().toString(), xmlSerializer);
xmlSerializer.endTag(null, PERSON);
}
xmlSerializer.endTag(null, RECORDS);
Expand Down
15 changes: 14 additions & 1 deletion app/src/main/java/com/eblis/whenwasit/backup/RecoverHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.eblis.whenwasit.R;
import com.eblis.whenwasit.alarm.AlarmHelper;
import com.eblis.whenwasit.database.DbHelper;
import com.eblis.whenwasit.models.AnniversaryType;
import com.eblis.whenwasit.models.Person;
import com.eblis.whenwasit.utils.Utils;

Expand All @@ -51,6 +52,9 @@ public class RecoverHelper {
private static final String YEAR_UNKNOWN = "year_unknown";
private static final String PHONE_NUMBER = "phone_number";
private static final String EMAIL = "email";
private static final String CATEGORY = "category";
private static final String ANNIVERSARY_LABEL = "anniversary_label";
private static final String ANNIVERSARY_TYPE = "anniversary_type";

// Exceptions constants
private static final String XML_PULL_PARSER_EXCEPTION = "XmlPullParserException";
Expand Down Expand Up @@ -114,7 +118,7 @@ private void parseXml(XmlPullParser parser) {
person.setName(parser.nextText());
break;
case DATE:
person.setDate(new LocalDate(Long.valueOf(parser.nextText())));
person.setDate(new LocalDate(parser.nextText()));
break;
case YEAR_UNKNOWN:
person.setYearUnknown(Boolean.valueOf(parser.nextText()));
Expand All @@ -125,6 +129,15 @@ private void parseXml(XmlPullParser parser) {
case EMAIL:
person.setEmail(parser.nextText());
break;
case CATEGORY:
person.setContactCategory(parser.nextText());
break;
case ANNIVERSARY_LABEL:
person.setAnniversaryLabel(parser.nextText());
break;
case ANNIVERSARY_TYPE:
person.setAnniversaryType(AnniversaryType.valueOf(parser.nextText()));
break;
}
}
break;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
<string name="about_ad_title">Pourquoi est-ce que je vois des annonces?</string>
<string name="about_ad_summary">Les revenus tirés de la publicité vont à l’élaboration du projet et à la traduction dans d’autres langues. Vous pouvez supprimer les annonces gratuitement.</string>
<string name="ad_interstitial_title">Annonce interstitielle</string>
<string name="ad_interstitial_summary">Ce type de publicité n\'est affiché qu\'une seule fois par jour. Cela soutient le projet et ce n'est pas si fréquent, non ?</string>
<string name="ad_interstitial_summary">Ce type de publicité n\'est affiché qu\'une seule fois par jour. Cela soutient le projet et ce n\'est pas si fréquent, non ?</string>
<string name="ad_banner">Bannière</string>
<!-- About app -->
<string name="about_app">À propos de l\'app</string>
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ buildscript {
}

dependencies {
classpath 'com.android.tools.build:gradle:3.1.4'
classpath 'com.android.tools.build:gradle:3.3.1'
classpath 'com.google.gms:google-services:3.1.1'
classpath 'com.google.firebase:firebase-plugins:1.1.1'
classpath 'io.fabric.tools:gradle:1.24.1'
classpath 'io.fabric.tools:gradle:1.25.4'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sun Apr 08 23:10:37 EEST 2018
#Sun Feb 10 23:37:14 EET 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip

0 comments on commit bf11d01

Please sign in to comment.