2 Copyright (C) 2014 Samsung Electronics Polska Sp. z o.o.
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
10 http://www.gnu.org/licenses/agpl-3.0.txt
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.
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/>.
21 package com.samsung.srpol.data;
23 import java.util.ArrayList;
24 import java.util.Collections;
25 import java.util.List;
27 import com.samsung.srpol.loader.AppDetails;
29 import android.content.Context;
30 import android.graphics.drawable.Drawable;
32 public class Category {
34 private String mTitle;
35 private String mHeader;
36 private String mDescription;
37 private String mShortDescription;
38 private int mSubCategoriesMask;
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;
47 public Category(Context ctx, String title, String header,
48 String shortDescription, String description, int icon, String link,
49 boolean dataSend, ArrayList<Subcategory> subCategories) {
52 mShortDescription = shortDescription;
53 mDescription = description;
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();
64 public void removeAppFromList(AppDetails removed) {
65 mRelatedApps.remove(removed);
68 public int getSubCategoriesMask() {
69 return mSubCategoriesMask;
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);
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)))
85 mRelatedApps.add(toBeAdded);
88 public List<Subcategory> getSubCategories() {
89 return mSubCategories;
95 public void assignAppsToCategory(List<AppDetails> appDetailsList) {
98 if (appDetailsList != null && mSubCategories != null) {
99 for (AppDetails appDetails : appDetailsList) {
100 addAppToList(appDetails);
106 * @return the mRelatedApps
108 public ArrayList<AppDetails> getRelatedApps() {
112 public int getIconRes() {
116 public Drawable getIconDrawable() {
117 return mIconDrawable;
120 public String getTitle() {
124 public String getDescription() {
128 public String getHeader() {
132 public String getShortDescription() {
133 return mShortDescription;
136 public void updateVisibleCount(int size) {
137 mCurrentlyVisible = size;
140 public int getCurrentlyVisible() {
141 return mCurrentlyVisible;
144 public String getLink() {