This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Oz Nusem on 5/19/14. | |
*/ | |
public class SafeFiledNamingStrategy implements FieldNamingStrategy { | |
/** | |
* @return Gson object with this safe strategy | |
*/ | |
public static Gson getGsonWithSafeNamingStrategy() { | |
return new GsonBuilder().setDateFormat("yyyy-MM-dd").setFieldNamingStrategy(new SafeFiledNamingStrategy()). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Created by Oz Nusem | |
* <p/> | |
* Picking image or capturing image in the same intent chooser | |
*/ | |
public class ImagePickerManager extends BaseAdapter { | |
private List<ResolveInfo> mApplications; | |
private TreeSet<Integer> mImageCaptureIntents; | |
private TreeSet<Integer> mImagePickerIntents; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public void initDB(Context context) { | |
try { | |
Manager manager = new Manager(new AndroidContext(context), Manager.DEFAULT_OPTIONS); | |
if (!Manager.isValidDatabaseName(DBName)) { | |
throw new RuntimeException("Bad database name"); | |
} | |
database = manager.getDatabase(DBName); | |
} catch (IOException e) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Document userDocument = database.createDocument(); | |
List<String> emails = new ArrayList<String>() {{ | |
add("[email protected]"); | |
add("[email protected]"); | |
} | |
}; | |
Map<String, Object> userMapper = new HashMap<>(); | |
userMapper.put("name", "Justin"); | |
userMapper.put("sureName", "Timberlake"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String documentId = userDocument.getId(); | |
Document document = database.getDocument(documentId); | |
List<String> emails = (List<String>) document.getProperty("emails"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
@PrimaryKey | |
private int userId; | |
private String description; | |
private String sureName; | |
private String name; | |
public String getDescription() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User user = new User(); | |
user.setName("Justin"); | |
user.setSurname("Timberlake"); | |
Realm realm = Realm.getInstance(getActivity()); | |
realm.beginTransaction(); | |
realm.copyToRealm(user); | |
realm.commitTransaction(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
@PrimaryKey | |
private int userId; | |
private String description; | |
private String sureName; | |
private String name; | |
private RealmList<Address> addresses; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class User extends RealmObject { | |
private String userName; | |
private String imageUrl; | |
private String status; | |
private RealmList<Email> emailList; | |
//getters and setter | |
..... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Realm realm = Realm.getInstance(context); | |
realm.beginTransaction(); | |
realm.copyToRealmOrUpdate(user); | |
realm.commitTransaction(); |
OlderNewer