Release.
[mobilnebezpieczenstwo.git] / src / com / samsung / srpol / data / Category.java
1 /*
2    Copyright (C) 2014  Samsung Electronics Polska Sp. z o.o.
3
4     This program is free software: you can redistribute it and/or modify
5     it under the terms of the GNU AFFERO General Public License as published by
6     the Free Software Foundation, either version 3 of the License, or
7     (at your option) any later version.
8     You may obtain a copy of the License at
9
10                 http://www.gnu.org/licenses/agpl-3.0.txt
11
12     This program is distributed in the hope that it will be useful,
13     but WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.
16
17     You should have received a copy of the GNU General Public License
18     along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 package com.samsung.srpol.data;
22
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
26
27 import com.samsung.srpol.loader.AppDetails;
28
29 import android.content.Context;
30 import android.graphics.drawable.Drawable;
31
32 public class Category {
33
34     private String mTitle;
35     private String mHeader;
36     private String mDescription;
37     private String mShortDescription;
38     private int mSubCategoriesMask;
39     private int mIconRes;
40     private String mLink;
41     private boolean mCanSendData;
42     private Drawable mIconDrawable;
43     private ArrayList<Subcategory> mSubCategories;
44     private ArrayList<AppDetails> mRelatedApps = new ArrayList<AppDetails>();
45     private int mCurrentlyVisible;
46
47     public Category(Context ctx, String title, String header,
48             String shortDescription, String description, int icon, String link,
49             boolean dataSend, ArrayList<Subcategory> subCategories) {
50         mTitle = title;
51         mHeader = header;
52         mShortDescription = shortDescription;
53         mDescription = description;
54         mIconRes = icon;
55         mLink = link;
56         mIconDrawable = ctx.getResources().getDrawable(mIconRes);
57         mSubCategories = subCategories;
58         for (Subcategory subcategory : mSubCategories)
59             mSubCategoriesMask = mSubCategoriesMask | subcategory.getId();
60         mCanSendData = dataSend;
61         mCurrentlyVisible = mRelatedApps.size();
62     }
63
64     public void removeAppFromList(AppDetails removed) {
65         mRelatedApps.remove(removed);
66     }
67
68     public int getSubCategoriesMask() {
69         return mSubCategoriesMask;
70     }
71     
72     public void addApplicationToCategory(AppDetails toBeAdded) {
73         int size = mRelatedApps.size();
74         addAppToList(toBeAdded);
75         if (size < mRelatedApps.size())
76             Collections.sort(mRelatedApps, AppDetails.SMART_COMPARATOR);
77     }
78
79     private void addAppToList(AppDetails toBeAdded) {
80         // Checking if any subcategory fits
81         if (!toBeAdded.isInSubcategory(mSubCategoriesMask)
82                 || (mCanSendData && !toBeAdded
83                         .isInSubcategory(Subcategory.CAN_SEND_DATA_SUB_CATEGORY_ID)))
84             return;
85         mRelatedApps.add(toBeAdded);
86     }
87
88     public List<Subcategory> getSubCategories() {
89         return mSubCategories;
90     }
91
92     /**
93      * Create app list
94      */
95     public void assignAppsToCategory(List<AppDetails> appDetailsList) {
96         mRelatedApps.clear();
97
98         if (appDetailsList != null && mSubCategories != null) {
99             for (AppDetails appDetails : appDetailsList) {
100                 addAppToList(appDetails);
101             }
102         }
103     }
104
105     /**
106      * @return the mRelatedApps
107      */
108     public ArrayList<AppDetails> getRelatedApps() {
109         return mRelatedApps;
110     }
111
112     public int getIconRes() {
113         return mIconRes;
114     }
115
116     public Drawable getIconDrawable() {
117         return mIconDrawable;
118     }
119
120     public String getTitle() {
121         return mTitle;
122     }
123
124     public String getDescription() {
125         return mDescription;
126     }
127
128     public String getHeader() {
129         return mHeader;
130     }
131
132     public String getShortDescription() {
133         return mShortDescription;
134     }
135
136     public void updateVisibleCount(int size) {
137         mCurrentlyVisible = size;
138     }
139
140     public int getCurrentlyVisible() {
141         return mCurrentlyVisible;
142     }
143
144     public String getLink() {
145         return mLink;
146     }
147 }