Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SharedPreferences.Editor editor = getSharedPreferences(prefName, MODE_PRIVATE).edit();
- editor.putInt("lorBucks", lorandBucks[0]);
- editor.commit();
- //But wait there's more!
- SharedPreferences.Editor editor2 = getSharedPreferences("BoughtStuff", MODE_PRIVATE).edit();
- System.out.println("IS THIS THE CULPRIT: BOUGHTITEMS SIZE: " + boughtItems.size());
- editor2.putInt("Items Amount", boughtItems.size());
- editor2.apply();
- for(int i = 0; i<boughtItems.size(); i++) {
- editor2.putString(Integer.toString(i) + " name", boughtItems.get(i).name);
- editor2.putInt(Integer.toString(i) + " price", boughtItems.get(i).price);
- editor2.putString(Integer.toString(i) + " image", boughtItems.get(i).imageName);
- }
- editor2.commit();
- }
- //Loading and Creating Bought Items
- SharedPreferences sps = getSharedPreferences("BoughtStuff", MODE_PRIVATE);
- for(int i = 0; i<sps.getInt("Items Amount", 0); i++){
- System.out.println("Items Amount: " + sps.getInt("Items Amount", 0));
- boughtItems.add(new StoreItem(sps.getInt(Integer.toString(i) + " price", -1), sps.getString(Integer.toString(i) + " name", " "), sps.getString(Integer.toString(i) + " image", " "), layout, this));
- System.out.println(sps.getString("0 name", "DAMNIT!!"));
- System.out.println(boughtItems.get(i).name);
- System.out.println("NUMBER OF BOUGHT ITEMS: " + boughtItems.size());
- }
- @Override
- public void onResume(){
- super.onResume();
- showItems();
- }
- public void showItems(){
- for(int i = 0; i<boughtItems.size(); i++){
- boughtItems.get(i).setUpShop();
- //final StoreItem[] stores = new StoreItem[1];
- // stores[0] = boughtItems.get(i);
- // final int[] c = new int[1];
- // boughtItems.get(i).getIb().setOnClickListener(new View.OnClickListener(){
- // @Override
- // public void onClick(View v){
- // c[0] = 1;
- // }
- // });
- // if(c[0] == 1){
- // boughtItems.remove(i);
- // }
- }
- }
- public void setUpShop() {
- ib.setImageResource(getResourceID(imageName, "drawable", act.getApplicationContext()));
- ib.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1200));
- ib.setScaleType(ImageView.ScaleType.CENTER_CROP);
- TextView shopLabel = new TextView(act);
- shopLabel.setText(name + ": " + price + " Love Bucks");
- shopLabel.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
- shopLabel.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 100));
- layout.addView(shopLabel);
- layout.addView(ib);
- }
- SharedPreferences prefs = context.getSharedPreferences(PREF_NAME,PRIVATE_MODE);
- SharedPreferences.Editor editor;
- public void setListToPreferance(String key, ArrayList<OBJECT_OF_MODELCLASS> list) {
- Gson gson = new Gson();
- String json = gson.toJson(list);
- editor = prefs.edit();
- editor.putString(key, json);
- editor.apply();
- }
- public ArrayList<OBJECT_OF_MODELCLASS> getListProductModel(String key) {
- Type type = new TypeToken<ArrayList<OBJECT_OF_MODELCLASS>>() {
- }.getType();
- ArrayList<OBJECT_OF_MODELCLASS> list = AppClass.getGson().fromJson(prefs.getString(key, ""), type);
- if (list == null) {
- list = new ArrayList<OBJECT_OF_MODELCLASS>();
- }
- return list;
- }
Add Comment
Please, Sign In to add comment