• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package android.leanbackjank.app.data;
18 
19 import android.leanbackjank.app.model.Movie;
20 
21 import java.util.ArrayList;
22 import java.util.HashMap;
23 import java.util.List;
24 
25 /**
26  * Provides synthesized movie data.
27  */
28 public class VideoProvider {
29     private static HashMap<String, List<Movie>> sMovieList;
30     private static HashMap<String, Movie> sMovieListById;
31 
getMovieById(String mediaId)32     public static Movie getMovieById(String mediaId) {
33         return sMovieListById.get(mediaId);
34     }
35 
getMovieList()36     public static HashMap<String, List<Movie>> getMovieList() {
37         return sMovieList;
38     }
39 
buildMedia(int nCategories)40     public static HashMap<String, List<Movie>> buildMedia(int nCategories) {
41         if (null != sMovieList) {
42             return sMovieList;
43         }
44         sMovieList = new HashMap<>();
45         sMovieListById = new HashMap<>();
46 
47         String title = new String();
48         String studio = new String();
49         for (int i = 0; i < nCategories; i++) {
50             String category_name = String.format("Category %d",  i);
51             List<Movie> categoryList = new ArrayList<Movie>();
52             for (int j = 0; j < 20; j++) {
53                 String description = "This is description of a movie.";
54                 title = String.format("Video %d-%d", i, j);
55                 studio = String.format("Studio %d", (i + j) % 7);
56                 Movie movie = buildMovieInfo(category_name, title, description, studio);
57                 sMovieListById.put(movie.getId(), movie);
58                 categoryList.add(movie);
59             }
60             sMovieList.put(category_name, categoryList);
61         }
62         return sMovieList;
63     }
64 
buildMovieInfo(String category, String title, String description, String studio)65     private static Movie buildMovieInfo(String category,
66                                         String title,
67                                         String description,
68                                         String studio) {
69         Movie movie = new Movie();
70         movie.setId(Movie.getCount());
71         Movie.incrementCount();
72         movie.setTitle(title);
73         movie.setDescription(description);
74         movie.setStudio(studio);
75         movie.setCategory(category);
76 
77         return movie;
78     }
79 }
80