SHARE
TWEET

Untitled

a guest Jun 18th, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public List<CartModelClass> getCarts() {
  2.  
  3.     SQLiteDatabase db = getReadableDatabase();
  4.     SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
  5.  
  6.     String[] sqlSelect = {"ID", "user_id", "Food_id", "quantity", "price", "origin", "destination", "description","company_name","search_id"};
  7.     String sqlTabel = "OrderDetails";
  8.  
  9.     qb.setTables(sqlTabel);
  10.     Cursor c = qb.query(db, sqlSelect, null, null, null, null,null);
  11.  
  12.     final List<CartModelClass> result = new ArrayList<>();
  13.     if (c.moveToFirst()) {
  14.         do {
  15.             result.add(new CartModelClass(
  16.                     c.getString(c.getColumnIndex("user_id")),
  17.                     c.getString(c.getColumnIndex("Food_id")),
  18.                     c.getString(c.getColumnIndex("quantity")),
  19.                     c.getString(c.getColumnIndex("price")),
  20.                     c.getString(c.getColumnIndex("origin")),
  21.                     c.getString(c.getColumnIndex("destination")),
  22.                     c.getString(c.getColumnIndex("description")),
  23.                     c.getString(c.getColumnIndex("company_name")),
  24.                     c.getString(c.getColumnIndex("search_id"))
  25.             ));
  26.         } while (c.moveToNext());
  27.     }
  28.     return result;
  29. }
  30.      
  31. public class SessionManager {
  32.  
  33.  
  34. SharedPreferences sharedPreferences;
  35. public SharedPreferences.Editor editor;
  36. public Context context;
  37. int PRIVATE_MODE = 0;
  38.  
  39. private static final String PREF_NAME = "LOGIN";
  40. private static final String LOGIN = "IS_LOGIN";
  41. private static final String NAME = "NAME";
  42. private static final String PHONE_NUM = "PHONE_NUM";
  43. private static final String EMAIL = "EMAIL";
  44. public static final String USER_ID = "USER_ID";
  45.  
  46.  
  47. public SessionManager(Context context) {
  48.     this.context = context;
  49.     sharedPreferences = context.getSharedPreferences(PREF_NAME,PRIVATE_MODE);
  50.     editor =sharedPreferences.edit();
  51. }
  52.  
  53. public void createSession(String name, String phone_num, String email , String user_id){
  54.  
  55.     editor.putBoolean(LOGIN, true);
  56.     editor.putString(NAME, name);
  57.     editor.putString(PHONE_NUM, phone_num);
  58.     editor.putString(EMAIL, email);
  59.     editor.putString(USER_ID, user_id);
  60.     editor.apply();
  61.  
  62. }
  63.  
  64. public HashMap<String, String> getUserDetail(){
  65.  
  66.     HashMap<String, String> user = new HashMap<>();
  67.     user.put(NAME, sharedPreferences.getString(NAME,null));
  68.     user.put(PHONE_NUM, sharedPreferences.getString(PHONE_NUM,null));
  69.     user.put(EMAIL, sharedPreferences.getString(EMAIL,null));
  70.     user.put(USER_ID, sharedPreferences.getString(USER_ID,null));
  71.  
  72.     return user ;
  73. }
  74.  
  75. public void logout(){
  76.  
  77.     editor.clear();
  78.     editor.commit();
  79.     Intent i = new Intent(context, LoginActivity.class);
  80.  
  81. }
  82.  
  83. }
  84.      
  85. private void loadListFood() {
  86.  
  87.  
  88.         listdata = new Database(this.getContext()).getCarts();
  89.  
  90.  
  91.         adapter = new CartAdapter(listdata, this.getContext());
  92.         recyclerView.setAdapter(adapter);
  93.  
  94.  
  95.         int total = 0;
  96.         for (CartModelClass order : listdata)
  97.  
  98.             total += (Integer.parseInt(order.getPrice())) * (Integer.parseInt(order.getQuantity()));
  99.         Locale locale = new Locale("en", "US");
  100.  
  101.         NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
  102.         txtTotalPrice.setText(fmt.format(total));
  103.  
  104.     }
  105.  
  106.  
  107. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top