Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /****************************************************************************
- Copyright (c) 2014 No PowerUp
- Copyright (c) 2014 Ketchapp
- Copyright (c) hiepndhut@gmail.com
- Permission is hereby granted, free of charge, to any person obtaining a copy
- of this software and associated documentation files (the "Software"), to deal
- in the Software without restriction, including without limitation the rights
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- copies of the Software, and to permit persons to whom the Software is
- furnished to do so, subject to the following conditions:
- The above copyright notice and this permission notice shall be included in
- all copies or substantial portions of the Software.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- THE SOFTWARE.
- ****************************************************************************/
- package com.wp.test.promotion;
- import java.util.Vector;
- import android.app.Activity;
- import android.content.SharedPreferences;
- public class Campaign {
- String id; // Currently unused
- Vector<App> apps;
- public Campaign() {
- apps = new Vector<Campaign.App>();
- id = "default";
- }
- public void addApp(App app) {
- apps.add(app);
- }
- Vector<App> getApps() {
- return apps;
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public void synchronizeWithPreferences(Activity activity) {
- SharedPreferences preferences = activity.getSharedPreferences(activity.getPackageName() + ".promotion", Activity.MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- for (App app : apps) {
- int displayCount = preferences.getInt(id + "-" + app.getId() + "-displayCount", 0);
- app.setDisplayCount(displayCount);
- editor.putString(id + "-" + app.getId() + "-id", app.getId());
- editor.putString(id + "-" + app.getId() + "-package", app.getPackageName());
- editor.putInt(id + "-" + app.getId() + "-displayLimit", app.getDisplayLimit());
- }
- editor.commit();
- }
- public void increaseDisplayCount(Activity activity, App app) {
- SharedPreferences preferences = activity.getSharedPreferences(activity.getPackageName() + ".promotion", Activity.MODE_PRIVATE);
- app.setDisplayCount(app.getDisplayCount() + 1);
- SharedPreferences.Editor editor = preferences.edit();
- editor.putInt(id + "-" + app.getId() + "-displayCount", app.getDisplayCount());
- editor.commit();
- }
- public class App {
- private String id;
- private String name;
- private String packageName;
- private String imageUrl;
- private int displayLimit;
- private int displayCount;
- private int order;
- private String cacheImage;
- public App() {
- }
- public App(String id, String name, String packageName, String imageUrl) {
- this.id = id;
- this.name = name;
- this.packageName = packageName;
- this.imageUrl = imageUrl;
- }
- public String getId() {
- return id;
- }
- public void setId(String id) {
- this.id = id;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPackageName() {
- return packageName;
- }
- public void setPackageName(String packageName) {
- this.packageName = packageName;
- }
- public String getImageUrl() {
- return imageUrl;
- }
- public void setImageUrl(String imageUrl) {
- this.imageUrl = imageUrl;
- }
- public int getDisplayLimit() {
- return displayLimit;
- // return 10;
- }
- public void setDisplayLimit(int displayLimit) {
- this.displayLimit = displayLimit;
- }
- public int getDisplayCount() {
- return displayCount;
- }
- public void setDisplayCount(int displayCount) {
- this.displayCount = displayCount;
- }
- public int getOrder() {
- return order;
- }
- public void setOrder(int order) {
- this.order = order;
- }
- public String getCacheImage() {
- return cacheImage;
- }
- public void setCacheImage(String cacheImage) {
- this.cacheImage = cacheImage;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement