/// <summary> The start of the normal poem-view process /// Shows the first line and some help text below it</summary> /// <param name="poem"></param> public void StartLoadPoem(Poem poem) { LoadTitleLine(poem); if (poem.IsEmpty) { // Remove clickability from Title line ((StackLayout.Children[0]) as ExtendedLabel).tapAction = null; // Set status Status = PoemViewerStatus.CompletePoem; } else { // Load help lines // Note that we don't increment DisplayedChunkIndex, because this isn't poem we're displaying, it's help text ExtendedLabel nextLineTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText); nextLineTap_HelpLabel.Text = PoemViewerHelpText.NextLineTap_Help; StackLayout.Children.Add(nextLineTap_HelpLabel); nextLineTap_HelpLabel.tapAction = () => ShowNextChunk(poem, DisplayedChunkIndex, Status); ExtendedLabel TitleTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText); TitleTap_HelpLabel.Text = PoemViewerHelpText.TitleTap_Help; StackLayout.Children.Add(TitleTap_HelpLabel); TitleTap_HelpLabel.tapAction = () => LoadWholePoem(poem); ExtendedLabel PreviousLineTap_HelpLabel = GetFormattedLabel(ChunkType.HelpText); PreviousLineTap_HelpLabel.Text = PoemViewerHelpText.PreviousLineTap_Help; StackLayout.Children.Add(PreviousLineTap_HelpLabel); // and define what we're doing Status = PoemViewerStatus.LineOnePlushelp; } }
/// <summary> Return an Extended label with formatting dependent on chunkType</summary> /// <param name="chunkType"></param> /// <returns></returns> private ExtendedLabel GetFormattedLabel(ChunkType chunkType) { ExtendedLabel label = new ExtendedLabel(); FormatLabel(label, chunkType); return(label); }
// Todo: Getting a log message: requestLayout() improperly called by ... NavigationPageRenderer // https://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called // Specifically this answer: https://stackoverflow.com/questions/24598977/android-requestlayout-improperly-called/24756631#24756631 /// <summary> Add a complete poem into the viewer</summary> /// <param name="poem"></param> public void LoadWholePoem(Poem poem) { StackLayout.Children.Clear(); DisplayedChunkIndex = 0; foreach (string chunk in poem.Chunks) { ChunkType chunkType = (DisplayedChunkIndex == 0) ? ChunkType.Title : ChunkType.NormalPoem; ExtendedLabel label = GetChunkToExtendedLabel(poem, DisplayedChunkIndex, chunkType); StackLayout.Children.Add(label); DisplayedChunkIndex++; } }
private void LoadTitleLine(Poem poem) { // Todo: Have setting and optionally allow [ddd] to be hidden when poem is loaded // This allows numbers for sorting without them being displayed StackLayout.Children.Clear(); DisplayedChunkIndex = 0; // Load the title line text ExtendedLabel titleLabel = GetChunkToExtendedLabel(poem, DisplayedChunkIndex, ChunkType.Title); // Enable clicking on it to load the whole poem titleLabel.tapAction = () => LoadWholePoem(poem); StackLayout.Children.Add(titleLabel); DisplayedChunkIndex++; }
private void FormatLabel(ExtendedLabel label, ChunkType chunkType) { switch (chunkType) { case ChunkType.Title: label.FontAttributes = FontAttributes.Bold; label.FontSize = defaultLabelFontSize * App.GoldenRatio; break; case ChunkType.HelpText: label.FontAttributes = FontAttributes.Italic; break; case ChunkType.CurrentLine: label.FontAttributes = FontAttributes.Bold; break; case ChunkType.NormalPoem: default: break; } }
/// <summary> Get the identified chunk and load it into a UI ExtendedLabel component </summary> /// <param name="poem"></param> /// <param name="chunkIndex"></param> /// <param name="chunkType"></param> /// <returns>The ExtendedLabel</returns> private ExtendedLabel GetChunkToExtendedLabel(Poem poem, int chunkIndex, ChunkType chunkType) { ExtendedLabel label = null; try { label = GetFormattedLabel(chunkType); if (poem.Chunks.Count > chunkIndex) { label.Text = poem.Chunks[chunkIndex]; } else { throw new IndexOutOfRangeException(); } } catch (Exception ex) { Log.Warn(logTag, string.Format("GetChunkToExtendedLabel() failed on chunkIndex={0} of {1} because {2}", chunkIndex, poem.Name, ex.Message)); } return(label); }