예제 #1
0
        protected InputHandlerResult handleDirectVerseInput(
            UserSession us,
            string input)
        {
            try
            {
                int verse_id = -1;
                VerseSection vs = (VerseSection)us.getVariableObject("Browse.verse_section");
                if (vs == null)
                {
                    Console.WriteLine("Expected Browse.verse_section present, but not found");
                    return new InputHandlerResult(
                       InputHandlerResult.UNDEFINED_MENU_ACTION,
                       InputHandlerResult.DEFAULT_MENU_ID,
                       InputHandlerResult.DEFAULT_PAGE_ID);
                }
                if (Int32.TryParse(input, out verse_id))
                {
                    Verse curr_start_verse = vs.start_verse;
                    Verse end_verse = vs.end_verse;
                    Verse start_verse = curr_start_verse.chapter.getVerse(verse_id);

                    if (start_verse != null)
                    {
                        //end_verse = getDefaultEndVerse(start_verse);
                        end_verse = start_verse;
                        vs = new VerseSection(start_verse, end_verse);//we set end verse to distinguish browsing from direct input
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(start_verse, end_verse);
                        return new InputHandlerResult(InputHandlerResult.NEW_MENU_ACTION,
                                    us.current_menu_loc,
                                    InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    else
                    {
                        return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                }
                else
                {
                    VerseSection vs1 = (VerseSection)us.getVariableObject("Browse.verse_section");
                    if (vs1 == null)
                    {
                        Console.WriteLine("Expected Browse.verse_section present, but not found");
                        return new InputHandlerResult(
                           InputHandlerResult.UNDEFINED_MENU_ACTION,
                           InputHandlerResult.DEFAULT_MENU_ID,
                           InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    String current_book = "";
                    String current_chapter = "";
                    input = input.Replace(".", ":");
                    if(vs1 != null && vs1.start_verse != null)
                    {
                        current_book = vs1.start_verse.book.name;
                        current_chapter = vs1.start_verse.chapter.chapter_id.ToString(); // TODO: check the taking of chapter from start verse and not end verse
                    }
                    VerseSection vsection = Verse_Handler.getVerseSection(us, input, current_book, current_chapter);
                    if (vsection != null)
                    {
                        us.setVariable("Browse.verse_section", vsection);
                        Verse start_verse = vsection.start_verse;
                        Verse end_verse = vsection.end_verse;
                        us.recordVerseSelection(start_verse, end_verse);
                        return new InputHandlerResult(
                            InputHandlerResult.NEW_MENU_ACTION,
                            us.current_menu_loc,
                            InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                    else
                    {
                        return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
                    }
                }

            }
            catch (Exception e)
            {
                return new InputHandlerResult(
                          InputHandlerResult.UNDEFINED_MENU_ACTION,
                          InputHandlerResult.DEFAULT_MENU_ID,
                          InputHandlerResult.DEFAULT_PAGE_ID);
            }
        }
예제 #2
0
        public override void init(UserSession us)
        {
            //Console.WriteLine("Init Browse Interaction");
            //first we need a way to know if the screen should be cleared.
            us.setVariable(BROWSE_CLEAR_SCREEN, true);
            //now this is one big hack
            Boolean direct_select;
            try
            {
                Object o = us.removeVariable("Browse.directSelect");
                if(o==null)
                    direct_select = false;
                else
                    direct_select = (Boolean)o;
            }catch(Exception e)
            {
                direct_select = false;
            }

            int verse_history_index = getVerseHistoryIndex(us);

            //Verse was selected from history of verses
            if (verse_history_index > -1)
            {
                ReadOnlyCollection<VerseHistoryRecord> history_list = us.verse_history.getHistoryListForDisplay();
                VerseHistoryRecord vhr = history_list[verse_history_index];
                Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), vhr.start_verse);
                Verse end_verse;
                if (vhr.end_verse == null || vhr.start_verse.Equals(vhr.end_verse))
                    end_verse = start_verse;
                else if ("NULL".Equals(vhr.end_verse))
                    end_verse = BrowseBibleScreenOutputAdapter.getDefaultEndVerse(start_verse);
                else
                    end_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), vhr.end_verse);

                VerseSection vs = new VerseSection(start_verse, end_verse);
                us.setVariable("Browse.verse_section", vs);
            }
            else
            {
                String top_fav_verse = getTopFavouriteSelectedVerse(us);
                if (top_fav_verse != null)
                {
                    VerseSection vs = Verse_Handler.getVerseSection(us, top_fav_verse, null, null);
                    if (vs != null)
                    {
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                    }
                }
                else
                {
                    int fav_verse_index = getFavouriteVerseIndex(us);

                    //Verse was selected from history of verses
                    if (fav_verse_index > -1)
                    {
                        ReadOnlyCollection<FavouriteVerseRecord> favourite_list = us.favourite_verses.getFavouriteListForDisplay();
                        FavouriteVerseRecord fvr = favourite_list[fav_verse_index];
                        Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), fvr.start_verse);
                        Verse end_verse;
                        if (fvr.end_verse == null || fvr.start_verse.Equals(fvr.end_verse))
                            end_verse = start_verse;
                        else if ("NULL".Equals(fvr.end_verse))
                            end_verse = BrowseBibleScreenOutputAdapter.getDefaultEndVerse(start_verse);
                        else
                            end_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), fvr.end_verse);

                        VerseSection vs = new VerseSection(start_verse, end_verse);
                        us.setVariable("Browse.verse_section", vs);
                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                    }
                    else{
                        String bookmark_verse = getBookmarkVerse(us);
                        if (bookmark_verse != null)
                        {
                            VerseSection vs = Verse_Handler.getVerseSection(us, bookmark_verse, null, null);
                            if (vs != null)
                            {
                                us.setVariable("Browse.verse_section", vs);
                                us.recordVerseSelection(vs.start_verse, vs.end_verse);
                            }
                        }
                        else
                        {
                            String daily_verse = getDailyVerseSelected(us);
                            if (daily_verse != null)
                            {
                                VerseSection vs = Verse_Handler.getVerseSection(us, daily_verse, null, null);
                                if (vs != null)
                                {
                                    us.setVariable("Browse.verse_section", vs);
                                    us.recordVerseSelection(vs.start_verse, vs.end_verse);
                                }
                            }
                            else
                            {
                                String topic_verse = getTopicVerse(us);
                                if (topic_verse != null)
                                {
                                    VerseSection vs = Verse_Handler.getVerseSection(us, topic_verse, null, null);
                                    if (vs != null)
                                    {
                                        us.setVariable("Browse.verse_section", vs);
                                        us.recordVerseSelection(vs.start_verse, vs.end_verse);
                                    }
                                }
                                else
                                {
                                    String search_verse = getSearchVerse(us);
                                    if (search_verse != null)
                                    {
                                        int search_verse_index = Int32.Parse(search_verse) - 1;
                                        SearchVerseRecord svr = us.search_results[search_verse_index];
                                        Verse start_verse = Verse_Handler.getStartingVerse(us.user_profile.getDefaultTranslationId(), svr.start_verse);
                                        VerseSection vs = new VerseSection(start_verse, start_verse);
                                        if (vs != null)
                                        {
                                            us.setVariable("Browse.verse_section", vs);
                                            us.recordVerseSelection(start_verse, start_verse);
                                        }
                                    }
                                    //verse was selected from direct select
                                    else if (direct_select == false)
                                    {

                                        Verse start_verse = BibleContainer.getInstance().getVerse(
                                                Int32.Parse(us.user_profile.getDefaultTranslationId()),
                                                Int32.Parse(us.getVariable("Testament_Handler.testament_id")),
                                                us.getVariable("BookOptionSet.book_id"),
                                                Int32.Parse(us.getVariable("ChapterOptionSet.chapter_id")),
                                                1);
                                        VerseSection vs = new VerseSection(start_verse, null);
                                        us.setVariable("Browse.verse_section", vs);
                                        us.recordVerseSelection(start_verse, null);
                                    }
                                    //Verse was selected by browsing
                                    else
                                    {
                                        VerseSection vs = (VerseSection)us.getVariableObject("Browse.verse_section");
                                        if (vs == null)
                                        {
                                            Console.WriteLine("Warning...verse_section context var was not found");
                                            throw new Exception("Expected Browse.verse_section var present but not found");
                                        }
                                        Verse start_verse = vs.start_verse;
                                        Verse end_verse = vs.end_verse;
                                        us.recordVerseSelection(start_verse, end_verse);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }