Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public List<CartModelClass> getCarts() {
- SQLiteDatabase db = getReadableDatabase();
- SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
- String[] sqlSelect = {"ID", "user_id", "Food_id", "quantity", "price", "origin", "destination", "description","company_name","search_id"};
- String sqlTabel = "OrderDetails";
- qb.setTables(sqlTabel);
- Cursor c = qb.query(db, sqlSelect, null, null, null, null,null);
- final List<CartModelClass> result = new ArrayList<>();
- if (c.moveToFirst()) {
- do {
- result.add(new CartModelClass(
- c.getString(c.getColumnIndex("user_id")),
- c.getString(c.getColumnIndex("Food_id")),
- c.getString(c.getColumnIndex("quantity")),
- c.getString(c.getColumnIndex("price")),
- c.getString(c.getColumnIndex("origin")),
- c.getString(c.getColumnIndex("destination")),
- c.getString(c.getColumnIndex("description")),
- c.getString(c.getColumnIndex("company_name")),
- c.getString(c.getColumnIndex("search_id"))
- ));
- } while (c.moveToNext());
- }
- return result;
- }
- public class SessionManager {
- SharedPreferences sharedPreferences;
- public SharedPreferences.Editor editor;
- public Context context;
- int PRIVATE_MODE = 0;
- private static final String PREF_NAME = "LOGIN";
- private static final String LOGIN = "IS_LOGIN";
- private static final String NAME = "NAME";
- private static final String PHONE_NUM = "PHONE_NUM";
- private static final String EMAIL = "EMAIL";
- public static final String USER_ID = "USER_ID";
- public SessionManager(Context context) {
- this.context = context;
- sharedPreferences = context.getSharedPreferences(PREF_NAME,PRIVATE_MODE);
- editor =sharedPreferences.edit();
- }
- public void createSession(String name, String phone_num, String email , String user_id){
- editor.putBoolean(LOGIN, true);
- editor.putString(NAME, name);
- editor.putString(PHONE_NUM, phone_num);
- editor.putString(EMAIL, email);
- editor.putString(USER_ID, user_id);
- editor.apply();
- }
- public HashMap<String, String> getUserDetail(){
- HashMap<String, String> user = new HashMap<>();
- user.put(NAME, sharedPreferences.getString(NAME,null));
- user.put(PHONE_NUM, sharedPreferences.getString(PHONE_NUM,null));
- user.put(EMAIL, sharedPreferences.getString(EMAIL,null));
- user.put(USER_ID, sharedPreferences.getString(USER_ID,null));
- return user ;
- }
- public void logout(){
- editor.clear();
- editor.commit();
- Intent i = new Intent(context, LoginActivity.class);
- }
- }
- private void loadListFood() {
- listdata = new Database(this.getContext()).getCarts();
- adapter = new CartAdapter(listdata, this.getContext());
- recyclerView.setAdapter(adapter);
- int total = 0;
- for (CartModelClass order : listdata)
- total += (Integer.parseInt(order.getPrice())) * (Integer.parseInt(order.getQuantity()));
- Locale locale = new Locale("en", "US");
- NumberFormat fmt = NumberFormat.getCurrencyInstance(locale);
- txtTotalPrice.setText(fmt.format(total));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement