@@ -73,7 +73,7 @@ public int onStartCommand(Intent intent, int flags, int startId) {
73
73
if (intent .getExtras ().getStringArrayList (RecognizerIntent .EXTRA_RESULTS ) != null ) {
74
74
ArrayList <String > voiceResults = intent .getExtras ().getStringArrayList (RecognizerIntent .EXTRA_RESULTS );
75
75
for (String q : voiceResults ) {
76
- if (q .matches (VoiceControlForPlexApplication . recognition_regex )) {
76
+ if (q .matches (getString ( R . string . pattern_recognition ) )) {
77
77
queryText = q ;
78
78
break ;
79
79
}
@@ -217,22 +217,22 @@ private void handleVoiceSearch() {
217
217
Logger .d ("Servers: %d" , VoiceControlForPlexApplication .getPlexMediaServers ().size ());
218
218
219
219
// Check for a sentence starting with "resume watching"
220
- p = Pattern .compile ("^resume watching (.*)" );
220
+ p = Pattern .compile (getString ( R . string . pattern_resume_watching ) );
221
221
matcher = p .matcher (queryText );
222
222
if (matcher .find ()) {
223
223
resumePlayback = true ;
224
224
// Replace "resume watching" with just "watch" so the pattern matching below works
225
- queryText = queryText .replaceAll ("^resume watching " , "watch " );
225
+ queryText = matcher .replaceAll (getString ( R . string . pattern_watch ) );
226
226
}
227
227
228
- p = Pattern .compile ( "watch movie (.*)" , Pattern .DOTALL );
228
+ p = Pattern .compile ( getString ( R . string . pattern_watch_movie ) , Pattern .DOTALL );
229
229
matcher = p .matcher (queryText );
230
230
if (matcher .find ()) {
231
231
mediaType = "movie" ;
232
232
queryTerm = matcher .group (1 );
233
233
}
234
234
if (mediaType .equals ("" )) {
235
- p = Pattern .compile ("watch season ([0-9]+) episode ([0-9]+) of (.*)" );
235
+ p = Pattern .compile (getString ( R . string . pattern_watch_season_episode_of_show ) );
236
236
matcher = p .matcher (queryText );
237
237
238
238
if (matcher .find ()) {
@@ -243,7 +243,7 @@ private void handleVoiceSearch() {
243
243
}
244
244
}
245
245
if (mediaType .equals ("" )) {
246
- p = Pattern .compile ("watch (.*) season ([0-9]+) episode ([0-9]+)" );
246
+ p = Pattern .compile (getString ( R . string . pattern_watch_show_season_episode ) );
247
247
matcher = p .matcher (queryText );
248
248
249
249
if (matcher .find ()) {
@@ -254,7 +254,7 @@ private void handleVoiceSearch() {
254
254
}
255
255
}
256
256
if (mediaType .equals ("" )) {
257
- p = Pattern .compile ("watch episode (.*) of (.*)" );
257
+ p = Pattern .compile (getString ( R . string . pattern_watch_episode_of_show ) );
258
258
matcher = p .matcher (queryText );
259
259
if (matcher .find ()) {
260
260
mediaType = "show" ;
@@ -263,7 +263,7 @@ private void handleVoiceSearch() {
263
263
}
264
264
}
265
265
if (mediaType .equals ("" )) {
266
- p = Pattern .compile ("watch the next episode of (.*)" );
266
+ p = Pattern .compile (getString ( R . string . pattern_watch_next_episode_of_show ) );
267
267
matcher = p .matcher (queryText );
268
268
269
269
if (matcher .find ()) {
@@ -273,7 +273,7 @@ private void handleVoiceSearch() {
273
273
}
274
274
}
275
275
if (mediaType .equals ("" )) {
276
- p = Pattern .compile ("watch( the)? latest episode of (.*)" );
276
+ p = Pattern .compile (getString ( R . string . pattern_watch_latest_episode_of_show ) );
277
277
matcher = p .matcher (queryText );
278
278
279
279
if (matcher .find ()) {
@@ -283,7 +283,7 @@ private void handleVoiceSearch() {
283
283
}
284
284
}
285
285
if (mediaType .equals ("" )) {
286
- p = Pattern .compile ("watch (.*) episode (.*)" );
286
+ p = Pattern .compile (getString ( R . string . pattern_watch_show_episode_named ) );
287
287
matcher = p .matcher (queryText );
288
288
if (matcher .find ()) {
289
289
mediaType = "show" ;
@@ -293,7 +293,7 @@ private void handleVoiceSearch() {
293
293
}
294
294
// Lastly, try to find a movie matching whatever comes after "watch"
295
295
if (mediaType .equals ("" )) {
296
- p = Pattern .compile ("watch (.*)" );
296
+ p = Pattern .compile (getString ( R . string . pattern_watch2 ) );
297
297
matcher = p .matcher (queryText );
298
298
299
299
if (matcher .find ()) {
@@ -302,7 +302,7 @@ private void handleVoiceSearch() {
302
302
}
303
303
}
304
304
if (mediaType .equals ("" )) {
305
- p = Pattern .compile ("listen to the album (.*) by (.*)" );
305
+ p = Pattern .compile (getString ( R . string . pattern_listen_to_album_by_artist ) );
306
306
matcher = p .matcher (queryText );
307
307
if (matcher .find ()) {
308
308
mediaType = "music" ;
@@ -311,13 +311,14 @@ private void handleVoiceSearch() {
311
311
}
312
312
}
313
313
if (mediaType .equals ("" )) {
314
- p = Pattern .compile ("listen to the album (.*)" );
314
+ p = Pattern .compile (getString ( R . string . pattern_listen_to_album ) );
315
315
matcher = p .matcher (queryText );
316
316
if (matcher .find ()) {
317
317
mediaType = "music" ;
318
318
album = matcher .group (1 );
319
319
}
320
320
}
321
+ /*
321
322
if(mediaType.equals("")) {
322
323
p = Pattern.compile("listen to (.*) by (.*)");
323
324
matcher = p.matcher(queryText);
@@ -327,48 +328,49 @@ private void handleVoiceSearch() {
327
328
artist = matcher.group(2);
328
329
}
329
330
}
331
+ */
330
332
if (mediaType .equals ("" )) {
331
- p = Pattern .compile ("pause playback" , Pattern .DOTALL );
333
+ p = Pattern .compile (getString ( R . string . pattern_pause_playback ) , Pattern .DOTALL );
332
334
matcher = p .matcher (queryText );
333
335
if (matcher .find ()) {
334
336
Logger .d ("pausing playback" );
335
337
pausePlayback ();
336
338
return ;
337
339
}
338
- p = Pattern .compile ("resume playback" , Pattern .DOTALL );
340
+ p = Pattern .compile (getString ( R . string . pattern_resume_playback ) , Pattern .DOTALL );
339
341
matcher = p .matcher (queryText );
340
342
if (matcher .find ()) {
341
343
Logger .d ("resuming playback" );
342
344
resumePlayback ();
343
345
return ;
344
346
}
345
- p = Pattern .compile ("stop playback" , Pattern .DOTALL );
347
+ p = Pattern .compile (getString ( R . string . pattern_stop_playback ) , Pattern .DOTALL );
346
348
matcher = p .matcher (queryText );
347
349
if (matcher .find ()) {
348
350
Logger .d ("stopping playback" );
349
351
stopPlayback ();
350
352
return ;
351
353
}
352
- p = Pattern .compile ("(offset|timecode) ([0-9]+|two) (hours?|minutes?|seconds?)(?: ([0-9]+|two) (minutes?|seconds?))?(?: ([0-9]+|two) (seconds?))?" , Pattern .DOTALL );
354
+ p = Pattern .compile (getString ( R . string . pattern_offset ) , Pattern .DOTALL );
353
355
matcher = p .matcher (queryText );
354
356
if (matcher .find ()) {
355
- String groupOne = matcher .group (2 ) != null && matcher .group (2 ).equals ("two" ) ? "2" : matcher .group (2 );
356
- String groupThree = matcher .group (4 ) != null && matcher .group (4 ).equals ("two" ) ? "2" : matcher .group (4 );
357
- String groupFive = matcher .group (6 ) != null && matcher .group (6 ).equals ("two" ) ? "2" : matcher .group (6 );
357
+ String groupOne = matcher .group (2 ) != null && matcher .group (2 ).matches ("two|to " ) ? "2" : matcher .group (2 );
358
+ String groupThree = matcher .group (4 ) != null && matcher .group (4 ).matches ("two|to " ) ? "2" : matcher .group (4 );
359
+ String groupFive = matcher .group (6 ) != null && matcher .group (6 ).matches ("two|to " ) ? "2" : matcher .group (6 );
358
360
int hours = 0 , minutes = 0 , seconds = 0 ;
359
- if (matcher .group (5 ) != null && matcher .group (5 ).startsWith ( "minute" ))
361
+ if (matcher .group (5 ) != null && matcher .group (5 ).matches ( getString ( R . string . pattern_minutes ) ))
360
362
minutes = Integer .parseInt (groupThree );
361
- else if (matcher .group (3 ) != null && matcher .group (3 ).startsWith ( "minute" ))
363
+ else if (matcher .group (3 ) != null && matcher .group (3 ).matches ( getString ( R . string . pattern_minutes ) ))
362
364
minutes = Integer .parseInt (groupOne );
363
365
364
- if (matcher .group (6 ) != null && matcher .group (6 ). startsWith ( "second" ))
366
+ if (matcher .group (7 ) != null && matcher .group (7 ). matches ( getString ( R . string . pattern_seconds ) ))
365
367
seconds = Integer .parseInt (groupFive );
366
- else if (matcher .group (5 ) != null && matcher .group (5 ).startsWith ( "second" ))
368
+ else if (matcher .group (5 ) != null && matcher .group (5 ).matches ( getString ( R . string . pattern_seconds ) ))
367
369
seconds = Integer .parseInt (groupThree );
368
- else if (matcher .group (3 ).startsWith ( "second" ))
370
+ else if (matcher .group (3 ).matches ( getString ( R . string . pattern_seconds ) ))
369
371
seconds = Integer .parseInt (groupOne );
370
372
371
- if (matcher .group (3 ).startsWith ( "hour" ))
373
+ if (matcher .group (3 ).matches ( getString ( R . string . pattern_hours ) ))
372
374
hours = Integer .parseInt (groupOne );
373
375
374
376
seekTo (hours , minutes , seconds );
0 commit comments