/// <summary> /// Fired when the back button is pressed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { if(e.IsHandled) { return; } // Close the dialog Close_OnIconTapped(null, null); // Mark as handled. e.IsHandled = true; }
/// <summary> /// Fired when the back button is pressed. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { if(e.IsHandled) { return; } // Don't do anything while we are in the background. if(!m_isVisible) { return; } // We will always handle everything. We will ask the user if they want to leave an if so // call back ourselves. e.IsHandled = HasInfoToDraft(); if(e.IsHandled) { PrmoptUserForBackout(); } }
/// <summary> /// Fired when the memory manager wants some memory back. Lets see if we can help him out. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void MemoryMan_OnMemoryCleanUpRequest(object sender, BaconBackend.Managers.OnMemoryCleanupRequestArgs e) { // Memory pressure // Low - Only clean up pages that are very old and user forgot about // Medium - Clean up pages that are older and the user hopefully forgot about // High - Clean up just about everything we can. List<IPanel> cleanupPanelList = new List<IPanel>(); lock (m_panelStack) { if (m_state != State.Idle && e.CurrentPressure != MemoryPressureStates.HighNoAllocations) { // If we are not idle return unless we are high, then // we will take our chances. return; } // Figure out how many panels we need to keep. int minNumHistoryPages = 0; switch(e.CurrentPressure) { default: case MemoryPressureStates.None: case MemoryPressureStates.VeryLow: minNumHistoryPages = c_veryLowMemoryHistoryPagesLimit; break; case MemoryPressureStates.Low: minNumHistoryPages = c_lowMemoryHistoryPagesLimit; break; case MemoryPressureStates.Medium: minNumHistoryPages = c_mediumMemoryHistoryPagesLimit; break; case MemoryPressureStates.HighNoAllocations: minNumHistoryPages = c_highMemoryHistoryPagesLimit; break; } // Do a quick check to ensure we can do work. // Panel count - 4 (worse case we have 4 we have to keep) is the worse case # of history pages. (this can be (-)) // If that count is less then the min just return because we have nothing to do. if(m_panelStack.Count - 4 < minNumHistoryPages) { return; } // First find the most recent subreddit panel and the panel we are looking at. // If we are in split view we will always have two, if in single view we will only have one. Tuple<Type, string> currentPanel = null; PanelType currentPanelPanelType = PanelType.None; Tuple<Type, string> splitViewOtherCurrentPanel = null; for (int count = m_panelStack.Count - 1; count > 0; count--) { StackItem item = m_panelStack[count]; // If this is first this is what we are looking at. if(currentPanel == null) { currentPanel = new Tuple<Type, string>(item.Panel.GetType(), item.Id); currentPanelPanelType = GetPanelType(item.Panel); // If we are in single mode we only care about the first one. if (m_screenMode == ScreenMode.Single) { break; } } else { // If we get here we are in split view and are looking for the latest panel that is not the same type as the current panel. if (GetPanelType(item.Panel) != currentPanelPanelType) { splitViewOtherCurrentPanel = new Tuple<Type, string>(item.Panel.GetType(), item.Id); break; } } } // Check that we are good. if (currentPanel == null) { App.BaconMan.TelemetryMan.ReportUnexpectedEvent(this, "MemoryCleanupCurrentPanelNull"); return; } // We will always keep the welcome screen, the first subreddit. // We also might need to keep the two visible panels, but they might also be the same. int numRequiredPages = 2; // Now loop though all of the panels and kill them. for(int count = 0; count < m_panelStack.Count; count++) { StackItem item = m_panelStack[count]; if((item.Panel as WelcomePanel) != null) { // This is the welcome panel, skip continue; } else if(count == 1 && (item.Panel as SubredditPanel) != null) { // If this subreddit isn't the first visible panel we have one more required page. if (!item.Id.Equals(currentPanel.Item2) || !item.Panel.GetType().Equals(currentPanel.Item1)) { numRequiredPages++; } // If this subreddit also isn't the second visible panel we have one more required page. if (splitViewOtherCurrentPanel != null && (!item.Id.Equals(splitViewOtherCurrentPanel.Item2) || !item.Panel.GetType().Equals(splitViewOtherCurrentPanel.Item1))) { numRequiredPages++; } // Skip the first subreddit panel also. continue; } // Check if we are done, if our list is smaller than req + min history. if (m_panelStack.Count <= minNumHistoryPages + numRequiredPages) { break; } if (item.Id.Equals(currentPanel.Item2) && item.Panel.GetType().Equals(currentPanel.Item1)) { // If this is visible panel 1 don't kill it. continue; } if (splitViewOtherCurrentPanel != null && item.Id.Equals(splitViewOtherCurrentPanel.Item2) && item.Panel.GetType().Equals(splitViewOtherCurrentPanel.Item1)) { // If this is visible panel 2 don't kill it. continue; } // We found one we can kill from the list and back down the count. m_panelStack.RemoveAt(count); count--; // Now make sure there isn't another instance of it in the list, if so don't add // it to the clean up list. bool addToCleanUp = true; foreach(StackItem searchItem in m_panelStack) { if(item.Id.Equals(searchItem.Id) && item.Panel.GetType().Equals(searchItem.Panel.GetType())) { addToCleanUp = false; break; } } if(addToCleanUp) { cleanupPanelList.Add(item.Panel); } } } // Now that we are out of lock, delete the panels if we have any. if (cleanupPanelList.Count > 0) { // Keep track of how many pages have been cleaned up. App.BaconMan.UiSettingsMan.PagesMemoryCleanedUp += cleanupPanelList.Count; // Jump to the UI thread to do this. await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { foreach (IPanel panel in cleanupPanelList) { // Fire cleanup on the panel FireOnCleanupPanel(panel); } // Also update the back button. UpdateBackButton(); }); } }
private void SubredditMan_OnSubredditsUpdated(object sender, BaconBackend.Managers.OnSubredditsUpdatedArgs e) { m_takeChangeAction = false; SetSubredditList(); m_takeChangeAction = true; }
/// <summary> /// Fire when the user presses back. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { if (e.IsHandled) { return; } // Kill it if we are. e.IsHandled = ToggleFullScreen(false); }
/// <summary> /// Fired when the user tapped go back. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { // If the presenter is open close it and mark the back handled. if (ui_globalContentPresenter.State != GlobalContentStates.Idle) { ui_globalContentPresenter.Close(); e.IsHandled = true; } }
/// <summary> /// If the subreddits change update the UI /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void SubredditMan_OnSubredditsUpdated(object sender, BaconBackend.Managers.OnSubredditsUpdatedArgs e) { await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { SetupSubredditLists(); }); }
/// <summary> /// Fired when the user presses back. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { if (e.IsHandled) { return; } // If we are full screen reset the scroller which will take us out. if (m_base.IsFullscreen) { e.IsHandled = true; ui_scrollViewer.ChangeView(null, null, m_minZoomFactor); } }
/// <summary> /// Fired when the user presses back /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BaconMan_OnBackButton(object sender, BaconBackend.OnBackButtonArgs e) { if(e.IsHandled) { return; } if(m_host.IsFullScreen()) { e.IsHandled = true; ui_scrollViewer.ChangeView(null, null, m_minZoomFactor); } }