use of com.baker.abaker.model.Magazine in project baker-android by bakerframework.
the class GindActivity method readStandaloneIssues.
private void readStandaloneIssues(final ArrayList<String> issues) {
Log.d(this.getClass().getName(), "Found " + issues.size() + " issues.");
if (issues.size() == 1) {
RETURN_TO_SHELF = false;
Magazine magazine = new Magazine();
magazine.setName(issues.get(0));
magazine.setStandalone(STANDALONE_MODE);
boolean fromAssets = !this.getResources().getBoolean(R.bool.sa_read_from_custom_directory);
bookJsonParserTask = new BookJsonParserTask(this, magazine, this, BOOK_JSON_PARSE_TASK);
bookJsonParserTask.setFromAssets(fromAssets);
bookJsonParserTask.execute("STANDALONE");
} else if (issues.size() > 1) {
JSONArray jsonArray = new JSONArray();
for (String issue : issues) {
Log.d(this.getClass().getName(), "The file is: " + issue);
jsonArray.put(this.getIssueData(issue));
}
this.createThumbnails(jsonArray);
} else {
Log.e(this.getClass().getName(), "Running standalone but no issues were found.");
Toast.makeText(this, getString(R.string.sa_no_issues), Toast.LENGTH_LONG).show();
this.finish();
}
}
use of com.baker.abaker.model.Magazine in project baker-android by bakerframework.
the class GindActivity method createThumbnails.
public void createThumbnails(final JSONArray jsonArray) {
Log.d(this.getClass().getName(), "Shelf json contains " + jsonArray.length() + " elements.");
JSONObject json;
try {
this.setContentView(R.layout.activity_gind);
loadHeader();
loadBackground();
if (this.getActionBar() != null) {
this.getActionBar().show();
// Modify the action bar to use a custom layout to center the title.
this.getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
this.getActionBar().setCustomView(R.layout.custom_actionbar);
}
flowLayout = (FlowLayout) findViewById(R.id.thumbsContainer);
int length = jsonArray.length();
for (int i = 0; i < length; i++) {
json = new JSONObject(jsonArray.getString(i));
Log.i(this.getClass().getName(), "Parsing JSON object " + json);
LinearLayout inner = new LinearLayout(this);
inner.setLayoutParams(new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1));
inner.setGravity(Gravity.CENTER_HORIZONTAL);
// Building magazine data
Date date = sdfInput.parse(json.getString("date"));
String dateString = sdfOutput.format(date);
int size = 0;
if (json.has("size"))
size = json.getInt("size");
String encoding = "UTF-8";
Magazine magazine = new Magazine();
magazine.setName(new String(json.getString("name").getBytes(encoding), encoding));
magazine.setTitle(new String(json.getString("title").getBytes(encoding), encoding));
magazine.setInfo(new String(json.getString("info").getBytes(encoding), encoding));
magazine.setDate(dateString);
magazine.setSize(size);
magazine.setCover(new String(json.getString("cover").getBytes(encoding), encoding));
magazine.setUrl(new String(json.getString("url").getBytes(encoding), encoding));
magazine.setStandalone(STANDALONE_MODE);
if (json.has("liveUrl")) {
String liveUrl = new String(json.getString("liveUrl").getBytes(encoding), encoding);
liveUrl = liveUrl.replace("/" + this.getString(R.string.book), "");
while (liveUrl.endsWith("/")) {
liveUrl = liveUrl.substring(0, liveUrl.length() - 1);
}
magazine.setLiveUrl(liveUrl);
Log.d(this.getClass().toString(), "The liveUrl for the magazine " + magazine.getName() + " will be " + liveUrl);
}
// Starting the ThumbLayout
MagazineThumb thumb = new MagazineThumb(this, magazine, thumbnailDownloaderHandler);
thumb.setId(i + i);
thumb.init(this, null);
thumbnailIds.add(thumb.getId());
if (this.magazineExists(magazine.getName())) {
thumb.enableReadArchiveActions();
} else if (STANDALONE_MODE) {
thumb.enableReadButton();
}
// Add layout
flowLayout.addView(thumb);
}
// Start downloading the thumbnails.
this.downloadNextThumbnail();
isLoading = false;
} catch (Exception e) {
Log.e(this.getClass().getName(), "Error loading the shelf elements.", e);
//TODO: Notify the user about the issue.
e.printStackTrace();
}
}
Aggregations