8
8
9
9
import com .atomjack .shared .Logger ;
10
10
import com .atomjack .shared .Preferences ;
11
- import com .atomjack .vcfp .interfaces .PlexDirectoryHandler ;
12
- import com .atomjack .vcfp .interfaces .PlexMediaHandler ;
13
- import com .atomjack .vcfp .model .PlexDirectory ;
14
- import com .atomjack .vcfp .model .PlexMedia ;
15
11
import com .atomjack .vcfp .model .PlexServer ;
16
12
import com .atomjack .vcfp .model .PlexTrack ;
17
13
import com .atomjack .vcfp .model .PlexVideo ;
@@ -62,12 +58,7 @@ public void start() {
62
58
handler .removeCallbacks (onFinishFailure );
63
59
int delay = Utils .getRandomInt (10 , 20 );
64
60
Logger .d ("Delaying %d seconds for hint" , delay );
65
- job = new Runnable () {
66
- @ Override
67
- public void run () {
68
- doHint ();
69
- }
70
- };
61
+ job = () -> doHint ();
71
62
handler .postDelayed (job , delay *1000 );
72
63
}
73
64
@@ -85,12 +76,9 @@ public void success() {
85
76
server = VoiceControlForPlexApplication .gsonRead .fromJson (prefs .get (Preferences .SERVER , "" ), PlexServer .class );
86
77
final int delay = Utils .getRandomInt (5 , 15 );
87
78
Logger .d ("Finished doing hint, delaying %d before next hint" , delay );
88
- handler .postDelayed (new Runnable () {
89
- @ Override
90
- public void run () {
91
- hintTextView .startAnimation (out );
92
- handler .postDelayed (job , delay * 1000 );
93
- }
79
+ handler .postDelayed (() -> {
80
+ hintTextView .startAnimation (out );
81
+ handler .postDelayed (job , delay * 1000 );
94
82
}, 15 * 1000 ); // leave this hint up for 15 seconds, then delay for the random amount
95
83
}
96
84
}
@@ -103,19 +91,9 @@ public void failure() {
103
91
104
92
private HintRunnable onFinish = new HintRunnable ();
105
93
106
- private Runnable onFinishSuccess = new Runnable () {
107
- @ Override
108
- public void run () {
109
- onFinish .success ();
110
- }
111
- };
94
+ private Runnable onFinishSuccess = () -> onFinish .success ();
112
95
113
- private Runnable onFinishFailure = new Runnable () {
114
- @ Override
115
- public void run () {
116
- onFinish .failure ();
117
- }
118
- };
96
+ private Runnable onFinishFailure = () -> onFinish .failure ();
119
97
120
98
public void doHint () {
121
99
if (active ) {
@@ -150,137 +128,111 @@ private void setText(String text) {
150
128
// hint methods
151
129
152
130
private void hintWatchMovie () {
153
- PlexHttpClient .getRandomMovie (server , new PlexMediaHandler () {
154
- @ Override
155
- public void onFinish (PlexMedia media ) {
156
- if (media != null ) {
157
- setText (String .format (context .getString (R .string .hint_watch_movie ), media .getTitle ()));
158
- handler .post (onFinishSuccess );
159
- } else {
160
- handler .post (onFinishFailure );
161
- }
131
+ PlexHttpClient .getRandomMovie (server , media -> {
132
+ if (media != null ) {
133
+ setText (String .format (context .getString (R .string .hint_watch_movie ), media .getTitle ()));
134
+ handler .post (onFinishSuccess );
135
+ } else {
136
+ handler .post (onFinishFailure );
162
137
}
163
138
});
164
139
}
165
140
166
141
private void hintWatchOnDeckEpisode () {
167
- PlexHttpClient .getRandomOnDeck (server , new PlexMediaHandler () {
168
- @ Override
169
- public void onFinish (PlexMedia media ) {
170
- if (media != null ) {
171
- setText (String .format (context .getString (R .string .hint_watch_movie ), media .getTitle ()));
172
- handler .post (onFinishSuccess );
173
- } else {
174
- handler .post (onFinishFailure );
175
- }
142
+ PlexHttpClient .getRandomOnDeck (server , media -> {
143
+ if (media != null ) {
144
+ setText (String .format (context .getString (R .string .hint_watch_movie ), media .getTitle ()));
145
+ handler .post (onFinishSuccess );
146
+ } else {
147
+ handler .post (onFinishFailure );
176
148
}
177
149
});
178
150
}
179
151
180
152
// watch season x episode y of show
181
153
private void hintWatchSeasonEpisode () {
182
- PlexHttpClient .getRandomEpisode (server , new PlexMediaHandler () {
183
- @ Override
184
- public void onFinish (PlexMedia media ) {
185
- if (media != null ) {
186
- PlexVideo video = (PlexVideo ) media ;
187
- setText (String .format (context .getString (R .string .hint_watch_season_episode ), video .parentIndex , video .index , video .getTitle ()));
188
- handler .post (onFinishSuccess );
189
- } else {
190
- handler .post (onFinishFailure );
191
- }
154
+ PlexHttpClient .getRandomEpisode (server , media -> {
155
+ if (media != null ) {
156
+ PlexVideo video = (PlexVideo ) media ;
157
+ setText (String .format (context .getString (R .string .hint_watch_season_episode ), video .parentIndex , video .index , video .getTitle ()));
158
+ handler .post (onFinishSuccess );
159
+ } else {
160
+ handler .post (onFinishFailure );
192
161
}
193
162
});
194
163
}
195
164
196
165
private void hintWatchSeasonEpisodeAlternate () {
197
- PlexHttpClient .getRandomEpisode (server , new PlexMediaHandler () {
198
- @ Override
199
- public void onFinish (PlexMedia media ) {
200
- if (media != null ) {
201
- Logger .d ("Got media: %s" , media .getTitle ());
202
- PlexVideo video = (PlexVideo ) media ;
203
- setText (String .format (context .getString (R .string .hint_watch_season_episode2 ), video .getTitle (), video .parentIndex , video .index ));
204
- handler .post (onFinishSuccess );
205
- } else {
206
- handler .post (onFinishFailure );
207
- }
166
+ PlexHttpClient .getRandomEpisode (server , media -> {
167
+ if (media != null ) {
168
+ Logger .d ("Got media: %s" , media .getTitle ());
169
+ PlexVideo video = (PlexVideo ) media ;
170
+ setText (String .format (context .getString (R .string .hint_watch_season_episode2 ), video .getTitle (), video .parentIndex , video .index ));
171
+ handler .post (onFinishSuccess );
172
+ } else {
173
+ handler .post (onFinishFailure );
208
174
}
209
175
});
210
176
}
211
177
212
178
private void hintWatchEpisode () {
213
- PlexHttpClient .getRandomEpisode (server , new PlexMediaHandler () {
214
- @ Override
215
- public void onFinish (PlexMedia media ) {
216
- if (media != null ) {
217
- PlexVideo video = (PlexVideo ) media ;
218
- setText (String .format (context .getString (R .string .hint_watch_episode ), video .getEpisodeTitle (), video .getTitle ()));
219
- handler .post (onFinishSuccess );
220
- } else {
221
- handler .post (onFinishFailure );
222
- }
179
+ PlexHttpClient .getRandomEpisode (server , media -> {
180
+ if (media != null ) {
181
+ PlexVideo video = (PlexVideo ) media ;
182
+ Logger .d ("[VCFPHint] video: %s %s" , video .getEpisodeTitle (), video .getTitle ());
183
+ setText (String .format (context .getString (R .string .hint_watch_episode ), video .getEpisodeTitle (), video .getTitle ()));
184
+ handler .post (onFinishSuccess );
185
+ } else {
186
+ handler .post (onFinishFailure );
223
187
}
224
188
});
225
189
}
226
190
227
191
// listen to song by artist
228
192
private void hintListenToSong () {
229
- PlexHttpClient .getRandomSong (server , new PlexMediaHandler () {
230
- @ Override
231
- public void onFinish (PlexMedia media ) {
232
- if (media != null ) {
233
- PlexTrack track = (PlexTrack ) media ;
234
- setText (String .format (context .getString (R .string .hint_listen_to_song ), track .title , track .grandparentTitle ));
235
- handler .post (onFinishSuccess );
236
- } else {
237
- handler .post (onFinishFailure );
238
- }
193
+ PlexHttpClient .getRandomSong (server , media -> {
194
+ if (media != null ) {
195
+ PlexTrack track = (PlexTrack ) media ;
196
+ setText (String .format (context .getString (R .string .hint_listen_to_song ), track .title , track .grandparentTitle ));
197
+ handler .post (onFinishSuccess );
198
+ } else {
199
+ handler .post (onFinishFailure );
239
200
}
240
201
});
241
202
}
242
203
243
204
// listen to album by artist
244
205
private void hintListenToAlbumByArtist () {
245
- PlexHttpClient .getRandomAlbum (server , new PlexDirectoryHandler () {
246
- @ Override
247
- public void onFinish (PlexDirectory directory ) {
248
- if (directory != null ) {
249
- setText (String .format (context .getString (R .string .hint_listen_to_album_by_artist ), directory .title , directory .parentTitle ));
250
- handler .post (onFinishSuccess );
251
- } else {
252
- handler .post (onFinishFailure );
253
- }
206
+ PlexHttpClient .getRandomAlbum (server , directory -> {
207
+ if (directory != null ) {
208
+ setText (String .format (context .getString (R .string .hint_listen_to_album_by_artist ), directory .title , directory .parentTitle ));
209
+ handler .post (onFinishSuccess );
210
+ } else {
211
+ handler .post (onFinishFailure );
254
212
}
255
213
});
256
214
}
257
215
258
216
// listen to album
259
217
private void hintListenToAlbum () {
260
- PlexHttpClient .getRandomAlbum (server , new PlexDirectoryHandler () {
261
- @ Override
262
- public void onFinish (PlexDirectory directory ) {
263
- if (directory != null ) {
264
- setText (String .format (context .getString (R .string .hint_listen_to_album ), directory .title ));
265
- handler .post (onFinishSuccess );
266
- } else {
267
- handler .post (onFinishFailure );
268
- }
218
+ PlexHttpClient .getRandomAlbum (server , directory -> {
219
+ if (directory != null ) {
220
+ setText (String .format (context .getString (R .string .hint_listen_to_album ), directory .title ));
221
+ handler .post (onFinishSuccess );
222
+ } else {
223
+ handler .post (onFinishFailure );
269
224
}
270
225
});
271
226
}
272
227
273
228
// listen to artist
274
229
private void hintListenToArtist () {
275
- PlexHttpClient .getRandomArtist (server , new PlexDirectoryHandler () {
276
- @ Override
277
- public void onFinish (PlexDirectory directory ) {
278
- if (directory != null ) {
279
- setText (String .format (context .getString (R .string .hint_listen_to_artist ), directory .title ));
280
- handler .post (onFinishSuccess );
281
- } else {
282
- handler .post (onFinishFailure );
283
- }
230
+ PlexHttpClient .getRandomArtist (server , directory -> {
231
+ if (directory != null ) {
232
+ setText (String .format (context .getString (R .string .hint_listen_to_artist ), directory .title ));
233
+ handler .post (onFinishSuccess );
234
+ } else {
235
+ handler .post (onFinishFailure );
284
236
}
285
237
});
286
238
}
0 commit comments