public void PlaySound(WordModel theWord, List<WaveModel> waves) { if (theWord.Status == WordStatus.COMPLETE) { int lastPlayedIdx = -1; if (mLastPlayed.ContainsKey(theWord.Word)) lastPlayedIdx = mLastPlayed[theWord.Word]; if (lastPlayedIdx < waves.Count - 1) lastPlayedIdx++; else lastPlayedIdx = 0; var localFile = Path.Combine ("file://", MainModel.GetSoundsDirectory (), waves[lastPlayedIdx].WaveFileName); mCurrentSound = AVAudioPlayer.FromData (MonoTouch.Foundation.NSData.FromFile(localFile)); mCurrentSound.Play (); mLastPlayed[theWord.Word] = lastPlayedIdx; } }
private bool NeedsSearch(WordModel word) { if (word.Status == WordStatus.QUERYING_AH || word.Status == WordStatus.NETWORK_ERROR) return true; List<WaveModel> theWaves = GetWavesForWord(word); foreach (var wave in theWaves) { var localFile = Path.Combine (MainModel.GetSoundsDirectory (), wave.WaveFileName); if (!File.Exists(localFile)) return true; } return false; }
private List<WaveModel> GetWavesForWord(WordModel word) { using (var conn = new SQLite.SQLiteConnection(mDatabasePath)) { return conn.Table<WaveModel>().Where(w => w.WordID == word.ID).ToList(); } }
public void AddWord(string word) { word = Sanitize(word); using (var conn = new SQLite.SQLiteConnection(mDatabasePath)) { if (FindWord (conn, word) != null) return; var newWordModel = new WordModel(); newWordModel.Word = word; newWordModel.Status = WordStatus.NOT_STARTED; newWordModel.Pronunciation = ""; newWordModel.IdxOrder = mMaxIdxOrder++; conn.Insert(newWordModel); LoadNextWord (conn); RefreshWordsList(conn); } }
public void ActionOnWord(WordModel theWord) { if (theWord.Status == WordStatus.COMPLETE) { mPlaySoundModel.PlaySound(theWord, GetWavesForWord(theWord)); } else if (!mDictionarySearcher.IsSearching) { using (var conn = new SQLite.SQLiteConnection(mDatabasePath)) { theWord.Status = WordStatus.QUERYING_AH; conn.Update (theWord); mDictionarySearcher.Search (theWord.Word); RefreshWordsList (conn); } } }