use of forpdateam.ru.forpda.data.models.notes.NoteItem in project ForPDA by RadiationX.
the class NotesFragment method exportNotes.
private void exportNotes() {
if (realm.isClosed())
return;
RealmResults<NoteItemBd> results = realm.where(NoteItemBd.class).findAllSorted("id", Sort.DESCENDING);
ArrayList<NoteItem> noteItems = new ArrayList<>();
for (NoteItemBd item : results) {
noteItems.add(new NoteItem(item));
}
final JSONArray jsonBody = new JSONArray();
for (NoteItem item : noteItems) {
try {
JSONObject jsonItem = new JSONObject();
jsonItem.put("id", item.getId());
jsonItem.put("title", item.getTitle());
jsonItem.put("link", item.getLink());
jsonItem.put("content", item.getContent());
jsonBody.put(jsonItem);
} catch (JSONException e) {
e.printStackTrace();
}
}
saveImageToExternalStorage(jsonBody.toString());
}
use of forpdateam.ru.forpda.data.models.notes.NoteItem in project ForPDA by RadiationX.
the class NotesFragment method importNotes.
private void importNotes(String jsonSource) {
ArrayList<NoteItem> noteItems = new ArrayList<>();
try {
final JSONArray jsonBody = new JSONArray(jsonSource);
for (int i = 0; i < jsonBody.length(); i++) {
try {
JSONObject jsonItem = jsonBody.getJSONObject(i);
NoteItem item = new NoteItem();
item.setId(jsonItem.getLong("id"));
item.setTitle(jsonItem.getString("title"));
item.setLink(jsonItem.getString("link"));
item.setContent(jsonItem.getString("content"));
noteItems.add(item);
} catch (JSONException e) {
e.printStackTrace();
}
}
} catch (JSONException e) {
e.printStackTrace();
Toast.makeText(getContext(), "Ошибка разбора файла: " + e.getMessage(), Toast.LENGTH_SHORT).show();
}
Toast.makeText(getContext(), "Заметки успешно импортированы", Toast.LENGTH_SHORT).show();
if (realm.isClosed())
return;
realm.executeTransactionAsync(realm1 -> {
for (NoteItem item : noteItems) {
realm1.insertOrUpdate(new NoteItemBd(item));
}
}, this::loadCacheData);
}
use of forpdateam.ru.forpda.data.models.notes.NoteItem in project ForPDA by RadiationX.
the class NotesFragment method loadCacheData.
@Override
public void loadCacheData() {
super.loadCacheData();
if (!realm.isClosed()) {
setRefreshing(true);
RealmResults<NoteItemBd> results = realm.where(NoteItemBd.class).findAllSorted("id", Sort.DESCENDING);
if (results.isEmpty()) {
if (!contentController.contains(ContentController.TAG_NO_DATA)) {
FunnyContent funnyContent = new FunnyContent(getContext()).setImage(R.drawable.ic_bookmark).setTitle(R.string.funny_notes_nodata_title);
contentController.addContent(funnyContent, ContentController.TAG_NO_DATA);
}
contentController.showContent(ContentController.TAG_NO_DATA);
} else {
contentController.hideContent(ContentController.TAG_NO_DATA);
}
ArrayList<NoteItem> nonBdResult = new ArrayList<>();
for (NoteItemBd item : results) {
nonBdResult.add(new NoteItem(item));
}
adapter.addAll(nonBdResult);
}
setRefreshing(false);
}
Aggregations