Advertisement
Guest User

Untitled

a guest
Jul 30th, 2015
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.41 KB | None | 0 0
  1. /****************************************************************************
  2.  Copyright (c) 2014 No PowerUp
  3.  Copyright (c) 2014 Ketchapp
  4.  Copyright (c) hiepndhut@gmail.com
  5.  
  6.  Permission is hereby granted, free of charge, to any person obtaining a copy
  7.  of this software and associated documentation files (the "Software"), to deal
  8.  in the Software without restriction, including without limitation the rights
  9.  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10.  copies of the Software, and to permit persons to whom the Software is
  11.  furnished to do so, subject to the following conditions:
  12.  
  13.  The above copyright notice and this permission notice shall be included in
  14.  all copies or substantial portions of the Software.
  15.  
  16.  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19.  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20.  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21.  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  22.  THE SOFTWARE.
  23.  ****************************************************************************/
  24.  
  25. package com.wp.test.promotion;
  26.  
  27. import java.util.Vector;
  28.  
  29. import android.app.Activity;
  30. import android.content.SharedPreferences;
  31.  
  32. public class Campaign {
  33.     String id; // Currently unused
  34.     Vector<App> apps;
  35.    
  36.     public Campaign() {
  37.         apps = new Vector<Campaign.App>();
  38.         id = "default";
  39.     }
  40.    
  41.     public void addApp(App app) {
  42.         apps.add(app);
  43.     }
  44.    
  45.     Vector<App> getApps() {
  46.         return apps;
  47.     }
  48.    
  49.     public String getId() {
  50.         return id;
  51.     }
  52.  
  53.     public void setId(String id) {
  54.         this.id = id;
  55.     }
  56.    
  57.     public void synchronizeWithPreferences(Activity activity) {
  58.         SharedPreferences preferences = activity.getSharedPreferences(activity.getPackageName() + ".promotion", Activity.MODE_PRIVATE);
  59.         SharedPreferences.Editor editor = preferences.edit();
  60.         for (App app : apps) {
  61.             int displayCount = preferences.getInt(id + "-" + app.getId() + "-displayCount", 0);
  62.             app.setDisplayCount(displayCount);
  63.             editor.putString(id + "-" + app.getId() + "-id", app.getId());
  64.             editor.putString(id + "-" + app.getId() + "-package", app.getPackageName());
  65.             editor.putInt(id + "-" + app.getId() + "-displayLimit", app.getDisplayLimit());
  66.         }
  67.         editor.commit();
  68.     }
  69.    
  70.     public void increaseDisplayCount(Activity activity, App app) {
  71.         SharedPreferences preferences = activity.getSharedPreferences(activity.getPackageName() + ".promotion", Activity.MODE_PRIVATE);
  72.         app.setDisplayCount(app.getDisplayCount() + 1);
  73.         SharedPreferences.Editor editor = preferences.edit();
  74.         editor.putInt(id + "-" + app.getId() + "-displayCount", app.getDisplayCount());
  75.         editor.commit();
  76.     }
  77.    
  78.     public class App {
  79.         private String id;
  80.         private String name;
  81.         private String packageName;
  82.         private String imageUrl;
  83.        
  84.         private int displayLimit;
  85.         private int displayCount;
  86.         private int order;
  87.         private String cacheImage;
  88.        
  89.         public App() {
  90.            
  91.         }
  92.        
  93.         public App(String id, String name, String packageName, String imageUrl) {
  94.             this.id = id;
  95.             this.name = name;
  96.             this.packageName = packageName;
  97.             this.imageUrl = imageUrl;
  98.         }
  99.        
  100.         public String getId() {
  101.             return id;
  102.         }
  103.         public void setId(String id) {
  104.             this.id = id;
  105.         }
  106.         public String getName() {
  107.             return name;
  108.         }
  109.         public void setName(String name) {
  110.             this.name = name;
  111.         }
  112.         public String getPackageName() {
  113.             return packageName;
  114.         }
  115.         public void setPackageName(String packageName) {
  116.             this.packageName = packageName;
  117.         }
  118.         public String getImageUrl() {
  119.             return imageUrl;
  120.         }
  121.         public void setImageUrl(String imageUrl) {
  122.             this.imageUrl = imageUrl;
  123.         }
  124.         public int getDisplayLimit() {
  125.             return displayLimit;
  126. //          return 10;
  127.         }
  128.         public void setDisplayLimit(int displayLimit) {
  129.             this.displayLimit = displayLimit;
  130.         }
  131.         public int getDisplayCount() {
  132.             return displayCount;
  133.         }
  134.         public void setDisplayCount(int displayCount) {
  135.             this.displayCount = displayCount;
  136.         }
  137.         public int getOrder() {
  138.             return order;
  139.         }
  140.         public void setOrder(int order) {
  141.             this.order = order;
  142.         }
  143.        
  144.         public String getCacheImage() {
  145.             return cacheImage;
  146.         }
  147.  
  148.         public void setCacheImage(String cacheImage) {
  149.             this.cacheImage = cacheImage;
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement