예제 #1
0
        public MainViewModel()
        {
            _logger.Info($"Starting AudibleBookmarks {TitleProvider.GetTitleWithVersion()}");
            ISubscribable fileSvc = new FileDialogService();

            fileSvc.StartListening();
            ISubscribable alertSvc = new AlertService();

            alertSvc.StartListening();

            _dbService = new DatabaseService();

            Books     = new ObservableCollection <Book>();
            Bookmarks = new ObservableCollection <Bookmark>();

            FilterableBooks            = CollectionViewSource.GetDefaultView(Books);
            FilterableBooks.Filter     = FilterBooks;
            FilterableBookmarks        = CollectionViewSource.GetDefaultView(Bookmarks);
            FilterableBookmarks.Filter = FilterBookmarks;

            if (!DesignerProperties.GetIsInDesignMode(new DependencyObject()))
            {
                FileOpened(PathHelper.TryToGuessPathToLibrary());
            }
        }
예제 #2
0
        public void FindBestSearchResult(ComboBox cbResults, string SearchString)
        {
            TitleProvider provider = TitleProvider.GetCurrentProvider();

            cbResults.SelectedIndex = 0;
            //Restore previously selected result
            if (provider.SelectedResults.ContainsKey(SearchString) && cbResults.Items.Contains(provider.SelectedResults[SearchString]))
            {
                cbResults.SelectedIndex = cbResults.Items.IndexOf(provider.SelectedResults[SearchString]);
            }
            else
            {
                List <string> languages = new List <string>(Helper.ReadProperties(ConfigKeyConstants.PREFERRED_RESULT_LANGUAGES_KEY));
                if (languages.Count > 0)
                {
                    //get a list of matching results with correct language, then use shortest one
                    int minlength = Int32.MaxValue;
                    int pos       = 0;
                    for (int j = 0; j < cbResults.Items.Count; j++)
                    {
                        string str = cbResults.Items[j].ToString();
                        if (Regex.IsMatch(str, languages[0]))
                        {
                            if (str.Length < minlength)
                            {
                                minlength = str.Length;
                                pos       = j;
                            }
                        }
                    }
                    cbResults.SelectedIndex = pos;
                }
            }
        }
예제 #3
0
        public void SearchButtonClicked(object sender, EventArgs e)
        {
            //note: this starts at 0, even though the gui placement starts at 1
            int      row           = Int32.Parse(((Control)sender).Name.Substring(((Control)sender).Name.Length - 2));
            TextBox  SearchBox     = (TextBox)tableLayoutPanel1.Controls["TextBox " + row];
            ComboBox ProviderBox   = (ComboBox)tableLayoutPanel1.Controls["ComboBox Providers " + row];
            Label    ShownameLabel = (Label)tableLayoutPanel1.Controls["Label " + row];

            DataGenerator.ParsedSearch Search = DataGenerator.Search(TitleProvider.GetProviderByName(ProviderBox.SelectedItem.ToString()), SearchBox.Text, ShownameLabel.Text);
            ComboBox cbResults = (ComboBox)tableLayoutPanel1.Controls["ComboBox " + row];

            cbResults.Items.Clear();
            TitleProvider provider = TitleProvider.GetCurrentProvider();

            if (Search.Results != null && Search.Results.Count != 0)
            {
                foreach (string s in Search.Results.Keys)
                {
                    cbResults.Items.Add(s);
                }
                FindBestSearchResult(cbResults, Search.SearchString);
            }
            else
            {
                cbResults.Items.Add("No results found");
                cbResults.SelectedIndex = 0;
            }
            Results[row] = Search;
        }
예제 #4
0
        public void NotifyDataSetChanged()
        {
            mTabLayout.RemoveAllViews();
            TitleProvider adapter = (TitleProvider)mViewPager.Adapter;
            int           count   = ((PagerAdapter)adapter).Count;

            for (int i = 0; i < count; i++)
            {
                AddTab(adapter.GetTitle(i), i);
            }
            if (mSelectedTabIndex > count)
            {
                mSelectedTabIndex = count - 1;
            }
            SetCurrentItem(mSelectedTabIndex);
            RequestLayout();
        }
예제 #5
0
        public void SetViewPager(ViewPager view)
        {
            var adapter = view.Adapter;

            if (adapter == null)
            {
                throw new IllegalStateException("ViewPager does not have adapter instance.");
            }
            if (!(adapter is TitleProvider))
            {
                throw new IllegalStateException("ViewPager adapter must implement TitleProvider to be used with TitlePageIndicator.");
            }
            mViewPager = view;
            mViewPager.SetOnPageChangeListener(this);
            mTitleProvider = (TitleProvider)adapter;
            Invalidate();
        }
예제 #6
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            TitleProvider provider = TitleProvider.GetCurrentProvider();

            for (int i = 0; i < Results.Count; i++)
            {
                ComboBox cbResults = (ComboBox)tableLayoutPanel1.Controls["ComboBox " + i];
                TextBox  SearchBox = (TextBox)tableLayoutPanel1.Controls["TextBox " + i];
                Results[i].SelectedResult = cbResults.SelectedItem.ToString();
                if (SearchBox.Text != "No results found")
                {
                    if (provider.SelectedResults.ContainsKey(SearchBox.Text))
                    {
                        provider.SelectedResults[SearchBox.Text] = cbResults.SelectedItem.ToString();
                    }
                    else
                    {
                        provider.SelectedResults.Add(SearchBox.Text, cbResults.SelectedItem.ToString());
                    }
                }
            }
            this.DialogResult = DialogResult.OK;
            Close();
        }
 public void SetViewPager(ViewPager view)
 {
     var adapter = view.Adapter;
     if (adapter == null) {
         throw new IllegalStateException("ViewPager does not have adapter instance.");
     }
     if (!(adapter is TitleProvider)) {
         throw new IllegalStateException("ViewPager adapter must implement TitleProvider to be used with TitlePageIndicator.");
     }
     mViewPager = view;
     mViewPager.SetOnPageChangeListener(this);
     mTitleProvider = (TitleProvider)adapter;
     Invalidate();
 }
예제 #8
0
        public ShownameSearch(List <DataGenerator.ParsedSearch> results)
        {
            InitializeComponent();
            Results    = results;
            KeyPreview = true;
            for (int i = 0; i < Results.Count; i++)
            {
                DataGenerator.ParsedSearch ps = Results[i];
                tableLayoutPanel1.RowCount++;
                tableLayoutPanel1.RowStyles.Add(new RowStyle(SizeType.AutoSize));
                Label lbl = new Label();
                lbl.Text   = ps.Showname;
                lbl.Name   = "Label " + i;
                lbl.Anchor = AnchorStyles.Left | AnchorStyles.Right | AnchorStyles.Bottom;
                tableLayoutPanel1.Controls.Add(lbl, 0, i + 1);
                TextBox tb = new TextBox();
                tb.Text     = ps.Showname;
                tb.Name     = "TextBox " + i;
                tb.Anchor   = AnchorStyles.Left | AnchorStyles.Right;
                tb.KeyDown += new KeyEventHandler(SearchBoxKeyDown);
                tableLayoutPanel1.Controls.Add(tb, 1, i + 1);
                ComboBox cbProviders = new ComboBox();
                cbProviders.DropDownStyle = ComboBoxStyle.DropDownList;
                cbProviders.Name          = "ComboBox Providers " + i;
                cbProviders.Items.AddRange(TitleProvider.getProviderNames().ToArray());
                cbProviders.Anchor = AnchorStyles.Left | AnchorStyles.Right;
                TitleProvider provider = TitleProvider.GetCurrentProvider();
                cbProviders.SelectedItem = provider.Name;
                tableLayoutPanel1.Controls.Add(cbProviders, 2, i + 1);
                Button btn = new Button();
                btn.Text   = "Search";
                btn.Name   = "Button " + i;
                btn.Anchor = AnchorStyles.Left | AnchorStyles.Right;
                btn.Click += new EventHandler(SearchButtonClicked);
                tableLayoutPanel1.Controls.Add(btn, 3, i + 1);
                ComboBox cb = new ComboBox();
                cb.DropDownStyle = ComboBoxStyle.DropDownList;
                cb.Name          = "ComboBox " + i;
                cb.Sorted        = true;

                if (ps.Results != null && ps.Results.Count != 0)
                {
                    foreach (string key in ps.Results.Keys)
                    {
                        cb.Items.Add(key);
                    }
                    FindBestSearchResult(cb, ps.SearchString);
                }
                else
                {
                    cb.Items.Add("No results found");
                    cb.SelectedIndex = 0;
                }


                cb.Anchor = AnchorStyles.Left | AnchorStyles.Right;
                tableLayoutPanel1.Controls.Add(cb, 4, i + 1);
            }

            //add one more because of stretching
            tableLayoutPanel1.RowCount++;
            if (Settings.Instance.IsMonoCompatibilityMode)
            {
                AutoSize = false;
                Height   = tableLayoutPanel1.Height + 107;
            }
            if (Height > maxHeight)
            {
                AutoSize = false;
                Height   = maxHeight;
                //107 is the height of the dialog minus the table control
                tableLayoutPanel1.AutoSize = false;
                tableLayoutPanel1.Height   = maxHeight - 107;
            }
            BringToFront();
        }