Search in sources :

Example 1 with InstalledIndexItem

use of scal.io.liger.model.sqlbrite.InstalledIndexItem in project storymaker by StoryMaker.

the class BaseHomeActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // copy index file
    // TODO: REPLACE THIS WITH INDEX DOWNLOAD (IF LOGGED IN) <- NEED TO COPY FILE FOR BASELINE CONTENT
    StorymakerIndexManager.copyAvailableIndex(this, false);
    // initialize db
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    // version check (sqlite upgrade requires migration)
    int appMigrationVersion = preferences.getInt("APP_MIGRATION_VERSION", 0);
    Timber.d("MIGRATION CHECK: " + appMigrationVersion + " vs. " + Constants.APP_MIGRATION_VERSION);
    if (appMigrationVersion != Constants.APP_MIGRATION_VERSION) {
        Timber.d("MIGRATION REQUIRED, RE-ENCRYPTING DATABASE");
        final boolean[] dbStatus = { false };
        try {
            SQLiteDatabaseHook dbHook = new SQLiteDatabaseHook() {

                public void preKey(SQLiteDatabase database) {
                }

                public void postKey(SQLiteDatabase database) {
                    Cursor cursor = database.rawQuery("PRAGMA cipher_migrate", new String[] {});
                    String value = "";
                    if (cursor != null) {
                        cursor.moveToFirst();
                        value = cursor.getString(0);
                        cursor.close();
                    }
                    // this result is currently ignored, checking if db is null instead
                    dbStatus[0] = Integer.valueOf(value) == 0;
                }
            };
            File dbPath = getDatabasePath("sm.db");
            Timber.d("MIGRATING DATABASE AT " + dbPath.getPath());
            SQLiteDatabase sqldb = SQLiteDatabase.openOrCreateDatabase(dbPath, "foo", null, dbHook);
            if (sqldb != null) {
                Timber.d("MIGRATED DATABASE NOT NULL");
                sqldb.close();
                // update preferences if migration succeeded
                preferences.edit().putInt("APP_MIGRATION_VERSION", Constants.APP_MIGRATION_VERSION).commit();
            } else {
                Timber.e("MIGRATED DATABASE IS NULL");
            }
        } catch (Exception ex) {
            Timber.e("EXCEPTION WHILE MIGRATING DATABASE: " + ex.getMessage());
        }
    }
    int availableIndexVersion = preferences.getInt("AVAILABLE_INDEX_VERSION", 0);
    Timber.d("VERSION CHECK: " + availableIndexVersion + " vs. " + scal.io.liger.Constants.AVAILABLE_INDEX_VERSION);
    if (availableIndexVersion != scal.io.liger.Constants.AVAILABLE_INDEX_VERSION) {
        // load db from file
        HashMap<String, scal.io.liger.model.ExpansionIndexItem> availableItemsFromFile = scal.io.liger.IndexManager.loadAvailableIdIndex(this);
        if (availableItemsFromFile.size() == 0) {
            Timber.d("NOTHING LOADED FROM AVAILABLE FILE");
        } else {
            for (scal.io.liger.model.ExpansionIndexItem item : availableItemsFromFile.values()) {
                Timber.d("ADDING " + item.getExpansionId() + " TO DATABASE (AVAILABLE)");
                // replaces existing items, should trigger updates to installed items and table as needed
                availableIndexItemDao.addAvailableIndexItem(item, true);
                // ugly solution to deal with the fact that the popup menu assumes there will be threads for an item we tried to download/install
                ArrayList<Thread> noThreads = new ArrayList<Thread>();
                downloadThreads.put(item.getExpansionId(), noThreads);
            }
        }
        // the following migration stuff is currently piggy-backing on the index update stuff
        // if found, migrate installed index
        File installedFile = new File(StorageHelper.getActualStorageDirectory(this), "installed_index.json");
        if (installedFile.exists()) {
            HashMap<String, scal.io.liger.model.ExpansionIndexItem> installedItemsFromFile = scal.io.liger.IndexManager.loadInstalledIdIndex(this);
            if (installedItemsFromFile.size() == 0) {
                Timber.d("NOTHING LOADED FROM INSTALLED INDEX FILE");
            } else {
                for (scal.io.liger.model.ExpansionIndexItem item : installedItemsFromFile.values()) {
                    Timber.d("ADDING " + item.getExpansionId() + " TO DATABASE (INSTALLED)");
                    // replaces existing items, should trigger updates to installed items and table as needed
                    installedIndexItemDao.addInstalledIndexItem(item, true);
                }
            }
            installedFile.delete();
        } else {
            Timber.d("NO INSTALLED INDEX FILE");
        }
        // if found, migrate instance index
        File instanceFile = new File(StorageHelper.getActualStorageDirectory(this), "instance_index.json");
        if (instanceFile.exists()) {
            HashMap<String, scal.io.liger.model.InstanceIndexItem> instanceItemsFromFile = scal.io.liger.IndexManager.loadInstanceIndex(this);
            if (instanceItemsFromFile.size() == 0) {
                Timber.d("NOTHING LOADED FROM INSTANCE INDEX FILE");
            } else {
                for (scal.io.liger.model.InstanceIndexItem item : instanceItemsFromFile.values()) {
                    Timber.d("ADDING " + item.getInstanceFilePath() + " TO DATABASE (INSTANCE)");
                    // replaces existing items, should trigger updates to installed items and table as needed
                    instanceIndexItemDao.addInstanceIndexItem(item, true);
                }
            }
            instanceFile.delete();
        } else {
            Timber.d("NO INSTANCE INDEX FILE");
        }
        // update preferences
        preferences.edit().putInt("AVAILABLE_INDEX_VERSION", scal.io.liger.Constants.AVAILABLE_INDEX_VERSION).commit();
        if (getIntent() != null && getIntent().hasExtra("showlauncher")) {
            if (getIntent().getBooleanExtra("showlauncher", false)) {
                showLauncherIcon();
            }
        }
    }
    // dumb test
    // check values
    availableIndexItemDao.getAvailableIndexItems().take(1).subscribe(new Action1<List<AvailableIndexItem>>() {

        @Override
        public void call(List<AvailableIndexItem> expansionIndexItems) {
            for (ExpansionIndexItem item : expansionIndexItems) {
                Timber.d("AVAILABLE ITEM " + item.getExpansionId() + ", TITLE: " + item.getTitle());
            }
        }
    });
    installedIndexItemDao.getInstalledIndexItems().take(1).subscribe(new Action1<List<InstalledIndexItem>>() {

        @Override
        public void call(List<InstalledIndexItem> expansionIndexItems) {
            for (ExpansionIndexItem item : expansionIndexItems) {
                Timber.d("INSTALLED ITEM " + item.getExpansionId() + ", TITLE: " + item.getTitle());
            }
        }
    });
    // file cleanup
    File actualStorageDirectory = StorageHelper.getActualStorageDirectory(this);
    if (actualStorageDirectory != null) {
        JsonHelper.cleanup(actualStorageDirectory.getPath());
    } else {
    // this is an error, will deal with it below
    }
    // default
    loggedIn = false;
    if (actualStorageDirectory != null) {
        // NEW/TEMP
        // DOWNLOAD AVAILABE INDEX FOR CURRENT USER AND SAVE TO TARGET FILE
        // NEED TO ACCOUNT FOR POSSIBLE MISSING INDEX
        // force download at startup (maybe only force on a timetable?)
        IndexTask iTask = new IndexTask(this, true);
        iTask.execute();
    } else {
        //show storage error message
        new AlertDialog.Builder(this).setTitle(Utils.getAppName(this)).setIcon(android.R.drawable.ic_dialog_info).setMessage(R.string.err_storage_not_available).show();
    }
    // we want to grab required updates without restarting the app
    // integrate with index task
    // if (!DownloadHelper.checkAndDownload(this)) {
    //     Toast.makeText(this, "Downloading content and/or updating installed files", Toast.LENGTH_LONG).show(); // FIXME move to strings.xml
    // }
    // i don't think we ever want to do this
    // IndexManager.copyInstalledIndex(this);
    //setContentView(R.layout.activity_home);
    //mRecyclerView = (RecyclerView) findViewById(scal.io.liger.R.id.recyclerView);
    //mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    //mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    //mSwipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //    @Override
    //    public void onRefresh() {
    //        IndexTask iTask = new IndexTask(HomeActivity.this, true); // force download on manual refresh
    //        iTask.execute();
    //    }
    //});
    //mTabMenu = getMenu("home");
    // action bar stuff
    getActionBar().setDisplayHomeAsUpEnabled(true);
    checkForTor();
    checkForUpdates();
}
Also used : ArrayList(java.util.ArrayList) ExpansionIndexItem(scal.io.liger.model.sqlbrite.ExpansionIndexItem) InstalledIndexItem(scal.io.liger.model.sqlbrite.InstalledIndexItem) Cursor(net.sqlcipher.Cursor) InstanceIndexItem(scal.io.liger.model.sqlbrite.InstanceIndexItem) AvailableIndexItem(scal.io.liger.model.sqlbrite.AvailableIndexItem) List(java.util.List) ArrayList(java.util.ArrayList) SharedPreferences(android.content.SharedPreferences) IOException(java.io.IOException) SQLiteDatabase(net.sqlcipher.database.SQLiteDatabase) File(java.io.File) SQLiteDatabaseHook(net.sqlcipher.database.SQLiteDatabaseHook)

Example 2 with InstalledIndexItem

use of scal.io.liger.model.sqlbrite.InstalledIndexItem in project storymaker by StoryMaker.

the class BaseHomeActivity method handleClick.

// HAD TO SPLIT OUT INTO A METHOD
public void handleClick(ExpansionIndexItem eItem, HashMap<String, ExpansionIndexItem> installedIds, boolean showDialog) {
    // initiate check/download whether installed or not
    // <- THIS SHOULD PICK UP EXISTING PARTIAL FILES
    HashMap<String, Thread> newThreads = StorymakerDownloadHelper.checkAndDownload(BaseHomeActivity.this, eItem, installedIndexItemDao, queueItemDao, true);
    // <- THIS ALSO NEEDS TO NOT INTERACT WITH THE INDEX
    // <- METADATA UPDATE SHOULD HAPPEN WHEN APP IS INITIALIZED
    // if any download threads were initiated, item is not ready to open
    boolean readyToOpen = true;
    if (newThreads.size() > 0) {
        readyToOpen = false;
        // update stored threads for index item
        ArrayList<Thread> currentThreads = downloadThreads.get(eItem.getExpansionId());
        if (currentThreads == null) {
            currentThreads = new ArrayList<Thread>();
        }
        for (Thread thread : newThreads.values()) {
            currentThreads.add(thread);
        }
        downloadThreads.put(eItem.getExpansionId(), currentThreads);
    }
    if (!installedIds.containsKey(eItem.getExpansionId())) {
        // if clicked item is not installed, update index
        // un-installed AvailableIndexItems need to be converted to InstalledIndexItems
        InstalledIndexItem iItem = new InstalledIndexItem(eItem);
        // FIXME we need to move this somewhere in the liger library that handles opening storypaths because this won't be triggered if we open open an instance by means other than a direct click
        java.util.Date thisDate = new java.util.Date();
        iItem.setCreationDate(thisDate);
        iItem.setLastModifiedDate(thisDate);
        iItem.setCreationDate(thisDate);
        StorymakerIndexManager.installedIndexAdd(BaseHomeActivity.this, iItem, installedIndexItemDao);
        Timber.d(eItem.getExpansionId() + " NOT INSTALLED, ADDING ITEM TO INDEX");
        // wait for index serialization
        try {
            synchronized (this) {
                // FIXME holy race conditions, batman
                wait(1000);
            }
        } catch (InterruptedException e) {
        // nop
        }
    } else {
        Timber.d(eItem.getExpansionId() + " INSTALLED, CHECKING FILE");
        // if clicked item is installed, check state
        if (readyToOpen) {
            // clear saved threads
            if (downloadThreads.get(eItem.getExpansionId()) != null) {
                downloadThreads.remove(eItem.getExpansionId());
            }
            // update db record with flag
            if (!eItem.isInstalled()) {
                Timber.d("SET INSTALLED FLAG FOR " + eItem.getExpansionId());
                eItem.setInstalledFlag(true);
                InstalledIndexItem iItem = new InstalledIndexItem(eItem);
                StorymakerIndexManager.installedIndexAdd(this, iItem, installedIndexItemDao);
            }
            // if file has been downloaded, open file
            Timber.d(eItem.getExpansionId() + " INSTALLED, FILE OK");
            // update with new thumbnail path
            // move this somewhere that it can be triggered by completed download?
            ContentPackMetadata metadata = scal.io.liger.IndexManager.loadContentMetadata(BaseHomeActivity.this, eItem.getPackageName(), eItem.getExpansionId(), StoryMakerApp.getCurrentLocale().getLanguage());
            if (metadata == null) {
                Toast.makeText(BaseHomeActivity.this, getString(R.string.home_metadata_missing), Toast.LENGTH_LONG).show();
                Timber.e("failed to load content metadata");
            } else if ((eItem.getThumbnailPath() == null) || (!eItem.getThumbnailPath().equals(metadata.getContentPackThumbnailPath()))) {
                // FIXME use StringUtils
                Timber.d(eItem.getExpansionId() + " FIRST OPEN, UPDATING THUMBNAIL PATH");
                eItem.setThumbnailPath(metadata.getContentPackThumbnailPath());
                // un-installed AvailableIndexItems need to be converted to InstalledIndexItems
                InstalledIndexItem iItem = new InstalledIndexItem(eItem);
                StorymakerIndexManager.installedIndexAdd(BaseHomeActivity.this, iItem, installedIndexItemDao);
                // wait for index serialization
                try {
                    synchronized (this) {
                        // FIXME holy race conditions, batman
                        wait(1000);
                    }
                } catch (InterruptedException e) {
                // nop
                }
            }
            ArrayList<scal.io.liger.model.InstanceIndexItem> contentIndex = scal.io.liger.IndexManager.loadContentIndexAsList(BaseHomeActivity.this, eItem.getPackageName(), eItem.getExpansionId(), StoryMakerApp.getCurrentLocale().getLanguage());
            if ((contentIndex == null) || (contentIndex.size() < 1)) {
                Toast.makeText(BaseHomeActivity.this, getString(R.string.home_index_missing), Toast.LENGTH_LONG).show();
                Timber.e("failed to load content index");
            } else if (contentIndex.size() == 1) {
                launchLiger(BaseHomeActivity.this, null, null, contentIndex.get(0).getInstanceFilePath());
            } else {
                String[] names = new String[contentIndex.size()];
                String[] paths = new String[contentIndex.size()];
                int i = 0;
                for (scal.io.liger.model.InstanceIndexItem item : contentIndex) {
                    names[i] = item.getTitle();
                    paths[i] = item.getInstanceFilePath();
                    i++;
                }
                showSPLSelectorPopup(names, paths);
            }
        } else {
            // if file is being downloaded, don't open
            Timber.d(eItem.getExpansionId() + " INSTALLED, CURRENTLY DOWNLOADING FILE");
            // if necessary, un-flag db record (this probably indicates an installed file that is being patched
            if (eItem.isInstalled()) {
                Timber.d("UN-SET INSTALLED FLAG FOR " + eItem.getExpansionId());
                eItem.setInstalledFlag(false);
                InstalledIndexItem iItem = new InstalledIndexItem(eItem);
                StorymakerIndexManager.installedIndexAdd(this, iItem, installedIndexItemDao);
            }
            if (showDialog) {
                new AlertDialog.Builder(BaseHomeActivity.this).setTitle(R.string.stop_download).setMessage(eItem.getTitle()).setNegativeButton(getString(R.string.cancel), null).setNeutralButton(getString(R.string.pause), new PauseListener(eItem)).setPositiveButton(getString(R.string.stop), new CancelListener(eItem)).show();
            }
        // Toast.makeText(HomeActivity.this, "Please wait for this content pack to finish downloading", Toast.LENGTH_LONG).show(); // FIXME move to strings.xml
        }
    }
}
Also used : InstalledIndexItem(scal.io.liger.model.sqlbrite.InstalledIndexItem) InstanceIndexItem(scal.io.liger.model.sqlbrite.InstanceIndexItem) ContentPackMetadata(scal.io.liger.model.ContentPackMetadata)

Example 3 with InstalledIndexItem

use of scal.io.liger.model.sqlbrite.InstalledIndexItem 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);
//}
}
Also used : ArrayList(java.util.ArrayList) ExpansionIndexItem(scal.io.liger.model.sqlbrite.ExpansionIndexItem) InstalledIndexItem(scal.io.liger.model.sqlbrite.InstalledIndexItem) BaseIndexItem(scal.io.liger.model.sqlbrite.BaseIndexItem) InstanceIndexItem(scal.io.liger.model.sqlbrite.InstanceIndexItem) StorymakerIndexManager(scal.io.liger.StorymakerIndexManager) ViewPager(android.support.v4.view.ViewPager)

Aggregations

InstalledIndexItem (scal.io.liger.model.sqlbrite.InstalledIndexItem)3 InstanceIndexItem (scal.io.liger.model.sqlbrite.InstanceIndexItem)3 ArrayList (java.util.ArrayList)2 ExpansionIndexItem (scal.io.liger.model.sqlbrite.ExpansionIndexItem)2 SharedPreferences (android.content.SharedPreferences)1 ViewPager (android.support.v4.view.ViewPager)1 File (java.io.File)1 IOException (java.io.IOException)1 List (java.util.List)1 Cursor (net.sqlcipher.Cursor)1 SQLiteDatabase (net.sqlcipher.database.SQLiteDatabase)1 SQLiteDatabaseHook (net.sqlcipher.database.SQLiteDatabaseHook)1 StorymakerIndexManager (scal.io.liger.StorymakerIndexManager)1 ContentPackMetadata (scal.io.liger.model.ContentPackMetadata)1 AvailableIndexItem (scal.io.liger.model.sqlbrite.AvailableIndexItem)1 BaseIndexItem (scal.io.liger.model.sqlbrite.BaseIndexItem)1