use of scal.io.liger.model.sqlbrite.BaseIndexItem in project storymaker by StoryMaker.
the class InstanceIndexItemAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
Context context = holder.card.getContext();
final BaseIndexItem baseItem = mDataset.get(position);
String description = baseItem.getDescription();
if (baseItem instanceof InstanceIndexItem) {
final InstanceIndexItem instanceItem = (InstanceIndexItem) baseItem;
holder.title.setText(String.format("%s %s", !TextUtils.isEmpty(instanceItem.getTitle()) ? instanceItem.getTitle() : context.getString(R.string.no_title), instanceItem.getStoryCreationDate() == 0 ? "" : sdf.format(new Date(instanceItem.getStoryCreationDate()))));
int mediumStringResId;
String storyType = TextUtils.isEmpty(instanceItem.getStoryType()) ? "?" : instanceItem.getStoryType();
switch(storyType) {
case "video":
mediumStringResId = R.string.lbl_video;
break;
case "audio":
mediumStringResId = R.string.lbl_audio;
break;
case "photo":
mediumStringResId = R.string.lbl_photo;
break;
default:
mediumStringResId = R.string.no_medium;
break;
}
description = context.getString(mediumStringResId) + ". " + context.getString(org.storymaker.app.R.string.last_modified) + ": ";
if (!TextUtils.isEmpty(instanceItem.getInstanceFilePath())) {
description += sdf.format(new Date(new File(instanceItem.getInstanceFilePath()).lastModified()));
}
/*
holder.card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onStorySelected(instanceItem);
}
}
});
*/
String thumbnailPath = baseItem.getThumbnailPath();
if (!TextUtils.isEmpty(thumbnailPath)) {
if (thumbnailPath.startsWith("http")) {
Picasso.with(context).load(thumbnailPath).into(holder.thumb);
} else {
Picasso.with(context).load(// FIXME leaving for now, but doesnt picasso handle making teh File object iteself?
new File(thumbnailPath)).into(holder.thumb);
}
} else {
Picasso.with(context).load(R.drawable.no_thumbnail).into(holder.thumb);
}
} else {
ExpansionIndexItem expansionIndexItem = (ExpansionIndexItem) baseItem;
// check if this is already installed or waiting to be downloaded to change which picture we show
HashMap<String, ExpansionIndexItem> installedIds = StorymakerIndexManager.loadInstalledIdIndex(context, installedDao);
holder.title.setText(baseItem.getTitle());
// show the content pack version info for help debugging upgrade issues
if (BuildConfig.DEBUG) {
int patchVer = !TextUtils.isEmpty(expansionIndexItem.getPatchFileVersion()) ? Integer.parseInt(expansionIndexItem.getPatchFileVersion()) : 0;
String ver = expansionIndexItem.getExpansionFileVersion() + ((patchVer > 0) ? ("." + patchVer) : "");
description = "v" + ver + ": " + description;
}
// need to verify that content pack containing thumbnail actually exists
File contentCheck = new File(StorymakerIndexManager.buildFilePath(expansionIndexItem, context), StorymakerIndexManager.buildFileName(expansionIndexItem, Constants.MAIN));
// need to verify that index item has been updated with content pack thumbnail path
String contentPath = expansionIndexItem.getPackageName() + File.separator + expansionIndexItem.getExpansionId();
if (installedIds.containsKey(expansionIndexItem.getExpansionId()) && contentCheck.exists() && baseItem.getThumbnailPath().startsWith(contentPath)) {
// ZipHelper.getTempFile((baseItem.getThumbnailPath(), "/sdcard/"
holder.thumb.setImageBitmap(BitmapFactory.decodeStream(ZipHelper.getFileInputStream(baseItem.getThumbnailPath(), context)));
} else {
String thumbnailPath = baseItem.getThumbnailPath();
if (!TextUtils.isEmpty(thumbnailPath)) {
if (thumbnailPath.startsWith("http")) {
Picasso.with(context).load(thumbnailPath).into(holder.thumb);
} else {
File file = StorymakerIndexManager.copyThumbnail(context, expansionIndexItem.getThumbnailPath());
Picasso.with(context).load(file).into(holder.thumb);
}
} else {
Picasso.with(context).load(R.drawable.no_thumbnail).into(holder.thumb);
}
// FIXME desaturate image and overlay the downarrow
}
}
holder.card.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mListener != null) {
mListener.onStorySelected(baseItem);
}
}
});
holder.card.setOnLongClickListener(new DeleteListener(context, baseItem));
holder.description.setText(description);
}
use of scal.io.liger.model.sqlbrite.BaseIndexItem in project storymaker by StoryMaker.
the class HomeActivity method initActivityList.
public void initActivityList() {
// menu items now locked during downloads, i think this can be removed
/*
if (!DownloadHelper.checkAllFiles(this)) { // FIXME the app should define these, not the library
Toast.makeText(this, "Please wait for the content pack to finish downloading and reload the app", Toast.LENGTH_LONG).show(); // FIXME move to strings.xml
return;
}
*/
JsonHelper.setupFileStructure(this);
// NEW: load instance index
String lang = StoryMakerApp.getCurrentLocale().getLanguage();
Timber.d("lang returned from getCurrentLocale: " + lang);
HashMap<String, InstanceIndexItem> instanceIndex = StorymakerIndexManager.fillInstanceIndex(HomeActivity.this, StorymakerIndexManager.loadInstanceIndex(HomeActivity.this, instanceIndexItemDao), lang, instanceIndexItemDao);
boolean fileAddedFlag = StorymakerIndexManager.fillInstalledIndex(HomeActivity.this, StorymakerIndexManager.loadInstalledFileIndex(HomeActivity.this, installedIndexItemDao), StorymakerIndexManager.loadAvailableFileIndex(HomeActivity.this, availableIndexItemDao), lang, installedIndexItemDao);
if (fileAddedFlag) {
Timber.d("HomeActivity", "file added");
}
// FIXME --- this should only happen on app updates in a migration
if (instanceIndex.size() > 0) {
Timber.d("INITACTIVITYLIST - FOUND INSTANCE INDEX WITH " + instanceIndex.size() + " ITEMS");
// dumb test
// put in values
/*
for (InstanceIndexItem item : instanceIndex.values()) {
instanceIndexItemDao.addInstanceIndexItem(item);
}
// read out values
instanceIndexItemDao.getInstanceIndexItems().subscribe(new Action1<List<org.storymaker.app.db.InstanceIndexItem>>() {
@Override
public void call(List<org.storymaker.app.db.InstanceIndexItem> instanceIndexItems) {
// just process the list
for (org.storymaker.app.db.InstanceIndexItem item : instanceIndexItems) {
Timber.d("GOT ITEM " + item.getId() + ", TITLE: " + item.getTitle());
}
}
});
*/
} else {
Timber.d("INITACTIVITYLIST - FOUND INSTANCE INDEX WITH NO ITEMS");
}
ArrayList<BaseIndexItem> instances = new ArrayList<BaseIndexItem>(instanceIndex.values());
ArrayList<BaseIndexItem> installations = new ArrayList<BaseIndexItem>();
ArrayList<BaseIndexItem> guides = new ArrayList<BaseIndexItem>();
ArrayList<BaseIndexItem> lessons = new ArrayList<BaseIndexItem>();
ArrayList<BaseIndexItem> templates = new ArrayList<BaseIndexItem>();
ArrayList<BaseIndexItem> homeitems = new ArrayList<BaseIndexItem>();
//HashMap<String, ExpansionIndexItem> availableIds = StorymakerIndexManager.loadAvailableIdIndex(this, availableIndexItemDao);
//ArrayList<String> availableGuideIds = getIndexItemIdsByType(availableIndexItemDao, "guide");
//ArrayList<String> availableLessonIds = getIndexItemIdsByType(availableIndexItemDao, "lesson");
//ArrayList<String> availableTemplateIds = getIndexItemIdsByType(availableIndexItemDao, "template");
//HashMap<String, ExpansionIndexItem> installedIds = StorymakerIndexManager.loadInstalledIdIndex(this, installedIndexItemDao);
//ArrayList<String> installedIdList = StorymakerIndexManager.loadInstalledIdIndexList(this, installedIndexItemDao);
StorymakerIndexManager.IndexKeyMap installedIndexKeyMap = StorymakerIndexManager.loadInstalledIdIndexKeyMap(this, installedIndexItemDao);
HashMap<String, scal.io.liger.model.sqlbrite.ExpansionIndexItem> installedIds = installedIndexKeyMap.getIndexMap();
ArrayList<String> installedKeys = installedIndexKeyMap.getIndexKeys();
ArrayList<String> installedGuideIds = getIndexItemIdsByType(installedIds, "guide");
ArrayList<String> installedLessonIds = getIndexItemIdsByType(installedIds, "lesson");
ArrayList<String> installedTemplateIds = getIndexItemIdsByType(installedIds, "template");
for (String id : installedKeys) {
// we don't want to populate the home screen with anything that hasn't finished downloading
InstalledIndexItem checkItem = (InstalledIndexItem) installedIds.get(id);
if (checkItem.isInstalled()) {
// if the available item has been installed, add the corresponding item from the installed index
installations.add(installedIds.get(id));
if (installedGuideIds.contains(id)) {
guides.add(checkItem);
} else if (installedLessonIds.contains(id)) {
lessons.add(checkItem);
} else if (installedTemplateIds.contains(id)) {
templates.add(checkItem);
}
} else {
Timber.d("HomeActivity - " + checkItem.getExpansionId() + " has not finished downloading, it will be skipped");
}
}
// FIXME we should sort this down a layer, perhaps in loadInstanceIndexAsList
Collections.sort(instances, Collections.reverseOrder());
// FIXME we should sort this down a layer, perhaps in loadInstanceIndexAsList
Collections.sort(lessons, Collections.reverseOrder());
// FIXME we should sort this down a layer, perhaps in loadInstanceIndexAsList
Collections.sort(guides, Collections.reverseOrder());
// FIXME we should sort this down a layer, perhaps in loadInstanceIndexAsList
Collections.sort(templates, Collections.reverseOrder());
// FIXME we should sort this down a layer, perhaps in loadInstanceIndexAsList
Collections.sort(installations, Collections.reverseOrder());
mHomeTabInstanceCount = 0;
mHomeTabInstallationCount = 0;
for (int i = 0; i < instances.size(); i++) {
//System.out.println(list.get(i));
homeitems.add(instances.get(i));
mHomeTabInstanceCount++;
if (i == 1) {
break;
}
}
if (installations.size() > 0) {
homeitems.add(installations.get(0));
mHomeTabInstallationCount++;
}
//mRecyclerView.setAdapter(new InstanceIndexItemAdapter(instances, new InstanceIndexItemAdapter.BaseIndexItemSelectedListener() {
InstanceIndexItemAdapter.BaseIndexItemSelectedListener myBaseIndexItemSelectedListener = new InstanceIndexItemAdapter.BaseIndexItemSelectedListener() {
@Override
public void onStorySelected(BaseIndexItem selectedItem) {
if (selectedItem instanceof InstanceIndexItem) {
updateInstanceIndexItemLastOpenedDate((InstanceIndexItem) selectedItem);
launchLiger(HomeActivity.this, null, ((InstanceIndexItem) selectedItem).getInstanceFilePath(), null);
} else {
// get clicked item
final ExpansionIndexItem eItem = ((ExpansionIndexItem) selectedItem);
Timber.d("HomeActivity - clicked an item: " + eItem.getExpansionId());
// get installed items
final HashMap<String, ExpansionIndexItem> installedIds = StorymakerIndexManager.loadInstalledIdIndex(HomeActivity.this, installedIndexItemDao);
if (!installedIds.containsKey(eItem.getExpansionId())) {
// this state should be unreachable, not sure what to do here
Timber.e("HomeActivity - " + eItem.getExpansionId() + " was not found in the installed index, something went wrong");
} else {
// proceed as usual
Timber.d("HomeActivity - handle click for item: " + eItem.getExpansionId());
handleClick(eItem, installedIds, true);
}
}
}
};
myHomeItemsInstanceIndexItemAdapter = new InstanceIndexItemAdapter(homeitems, myBaseIndexItemSelectedListener, installedIndexItemDao, instanceIndexItemDao);
myInstancesInstanceIndexItemAdapter = new InstanceIndexItemAdapter(instances, myBaseIndexItemSelectedListener, installedIndexItemDao, instanceIndexItemDao);
myGuidesInstanceIndexItemAdapter = new InstanceIndexItemAdapter(guides, myBaseIndexItemSelectedListener, installedIndexItemDao, instanceIndexItemDao);
myLessonsInstanceIndexItemAdapter = new InstanceIndexItemAdapter(lessons, myBaseIndexItemSelectedListener, installedIndexItemDao, instanceIndexItemDao);
myTemplatesInstanceIndexItemAdapter = new InstanceIndexItemAdapter(templates, myBaseIndexItemSelectedListener, installedIndexItemDao, instanceIndexItemDao);
ArrayList<InstanceIndexItemAdapter> myInstanceIndexItemAdapters = new ArrayList<InstanceIndexItemAdapter>();
myInstanceIndexItemAdapters.add(myHomeItemsInstanceIndexItemAdapter);
myInstanceIndexItemAdapters.add(myInstancesInstanceIndexItemAdapter);
myInstanceIndexItemAdapters.add(myGuidesInstanceIndexItemAdapter);
myInstanceIndexItemAdapters.add(myLessonsInstanceIndexItemAdapter);
myInstanceIndexItemAdapters.add(myTemplatesInstanceIndexItemAdapter);
ArrayList<Integer> myListLengths = new ArrayList<Integer>();
myListLengths.add(homeitems.size());
myListLengths.add(instances.size());
myListLengths.add(guides.size());
myListLengths.add(lessons.size());
myListLengths.add(templates.size());
ArrayList<String> myListNames = new ArrayList<String>();
myListNames.add("home");
myListNames.add("stories");
myListNames.add("guides");
myListNames.add("lessons");
myListNames.add("templates");
// Create the adapter that will return a fragment for each of the three
// primary sections of the activity.
mDemoCollectionPagerAdapter = new DemoCollectionPagerAdapter(getSupportFragmentManager(), myInstanceIndexItemAdapters, myListLengths, myListNames, mHomeTabInstanceCount, mHomeTabInstallationCount);
// Set up the ViewPager with the sections adapter.
//mViewPager = (SwipelessViewPager) findViewById(R.id.pager);
mViewPager = (ViewPager) findViewById(R.id.home_pager);
mViewPager.setAdapter(mDemoCollectionPagerAdapter);
mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
@Override
public void onPageSelected(int position) {
currentPage = position;
}
@Override
public void onPageScrollStateChanged(int state) {
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
}
});
//mViewPager.setPagingEnabled(false);
// Give the SlidingTabLayout the ViewPager, this must be done AFTER the ViewPager has had
// it's PagerAdapter set.
mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.home_sliding_tabs);
mSlidingTabLayout.setSelectedIndicatorColors(getResources().getColor(R.color.white));
//mSlidingTabLayout.setDistributeEvenly(true);
mSlidingTabLayout.setViewPager(mViewPager);
if (currentPage != -1) {
mViewPager.setCurrentItem(currentPage);
}
//} else {
// empty list
// TextView textView = (TextView) findViewById(R.id.textViewEmptyState);
// textView.setVisibility(View.VISIBLE);
//mSwipeRefreshLayout.setVisibility(View.GONE);
//}
}
Aggregations