SHARE
TWEET

Untitled

a guest Sep 18th, 2019 116 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public class Home extends AppCompatActivity implements PassengerDetailsIObserver,NavigationView.OnNavigationItemSelectedListener, MyInterface {
  2.  
  3.  
  4.     private static final String TAG = "Home Activity";
  5.     DrawerLayout drawer;
  6.  
  7.     //widgets
  8.     private EditText number_plate1;
  9.     private EditText amount1;
  10.     private EditText name_passenger1;
  11.     private EditText phone_passenger1;
  12.     private EditText ID_passenger1;
  13.     private EditText destination1;
  14.  
  15.  
  16.     RecyclerView recyclerView;
  17.     RecyclerView.Adapter adapter;
  18.     private ArrayList<Paymentdetails>paymentdetails;
  19.     private ArrayList<PassengerDetails>passengerDetails;
  20.     @SuppressLint("WrongViewCast")
  21.     @Override
  22.     protected void onCreate(Bundle savedInstanceState) {
  23.         super.onCreate(savedInstanceState);
  24.         setContentView(R.layout.activity_home);
  25.  
  26.         credentialsSharedPreferences =getSharedPreferences(CREDENTIALSPREFERENCES, Context.MODE_PRIVATE);
  27.         credentialsEditor = credentialsSharedPreferences.edit();
  28.  
  29.  
  30.         findViewById(R.id.makePayment).setOnClickListener(new View.OnClickListener() {
  31.             @Override
  32.             public void onClick(View v) {
  33.                 Log.d(TAG, "onClick: opening dialog");
  34.                 CustomDialog dialog = new CustomDialog();
  35.                 dialog.show(getSupportFragmentManager(), "Custom Dialog");
  36.  
  37.  
  38.             }
  39.         });
  40.  
  41.  
  42.  
  43.         Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
  44.         setSupportActionBar(toolbar);
  45.  
  46.         drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  47.         ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
  48.                 this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
  49.         toggle.syncState();
  50.  
  51.         NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
  52.  
  53.         NavigationView navigationViewRight = (NavigationView) findViewById(R.id.nav_view_right);
  54.         navigationViewRight.setNavigationItemSelectedListener(this);
  55.         navigationView.setNavigationItemSelectedListener(this);
  56.  
  57.         View headerView = navigationView.getHeaderView(0);
  58.         TextView navUsername = (TextView) headerView.findViewById(R.id.user_name);
  59.         navUsername.setText(credentialsSharedPreferences.getString(Constants.name, "User Name"));
  60.  
  61.  
  62.         paymentdetails = new ArrayList <>();
  63.         passengerDetails = new ArrayList <>();
  64.  
  65.         recyclerView = findViewById(R.id.recyclerview);
  66.         adapter = new PaymentAdapter(paymentdetails);
  67.         recyclerView.setAdapter(adapter);
  68.         recyclerView.setHasFixedSize(true);
  69.         recyclerView.setLayoutManager(new LinearLayoutManager(this));
  70.  
  71.  
  72.  
  73.         retrievePaymentDetails();
  74.  
  75.     }
  76.  
  77.     private void retrievePaymentDetails() {
  78.         StringRequest stringRequest = new StringRequest(Request.Method.GET, paymentDetails,
  79.                 new Response.Listener <String>() {
  80.                     @Override
  81.                     public void onResponse(String s) {
  82.                         System.out.println("123RETRIEEEVE" + s);
  83. //                        textView.setText("retrieve details");
  84.                         Toast.makeText(getApplicationContext(), "successfully retrieved", Toast.LENGTH_SHORT).show();
  85.                         try {
  86.                             JSONObject jsonObject = new JSONObject(s);
  87.                             JSONArray array = jsonObject.getJSONArray("payments");
  88.  
  89.                             for (int i =0; i< array.length(); i++){
  90.                                 JSONObject row = array.getJSONObject(i);
  91.                                 Paymentdetails paymentdetail = new Paymentdetails(
  92.                                         row.getString("number_plate"),
  93.                                         row.getInt("amount"),
  94.                                         row.getString("no_of_passengers"),
  95.                                         row.getInt("rate"),
  96.                                         row.getString("destination")
  97.                                 );
  98.                                 paymentdetails.add(paymentdetail);
  99.                                 initializeData();
  100.  
  101.                             }
  102.  
  103.                         } catch (JSONException e) {
  104.                             e.printStackTrace();
  105.                         }
  106.                     }
  107.                 },
  108.                 new Response.ErrorListener() {
  109.                     @Override
  110.                     public void onErrorResponse(VolleyError volleyError) {
  111.                         System.out.println("volleyError error" + volleyError.getMessage());
  112.                         Toast.makeText(getApplicationContext(), "Poor network connection.", Toast.LENGTH_LONG).show();
  113.  
  114.                     }
  115.                 }) {
  116.         };
  117.  
  118.         RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
  119.         requestQueue.add(stringRequest);
  120.     }
  121.  
  122.     private void initializeData() {
  123.         PaymentAdapter paymentAdapter = new PaymentAdapter(paymentdetails);
  124.         recyclerView.setAdapter(paymentAdapter);
  125.  
  126.     }
  127.  
  128.  
  129.     @Override
  130.     public void onBackPressed() {
  131.         @SuppressLint("WrongViewCast") DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  132.         if (drawer.isDrawerOpen(GravityCompat.START)) {
  133.             drawer.closeDrawer(GravityCompat.START);
  134.         } else if (drawer.isDrawerOpen(GravityCompat.END)) {
  135.             drawer.closeDrawer(GravityCompat.END);
  136.         } else {
  137.             super.onBackPressed();
  138.         }
  139.     }
  140.  
  141.     @Override
  142.     public boolean onOptionsItemSelected(MenuItem item) {
  143.         // Handle action bar item clicks here. The action bar will
  144.         // automatically handle clicks on the Home/Up button, so long
  145.         // as you specify a parent activity in AndroidManifest.xml.
  146.         int id = item.getItemId();
  147.  
  148.         //noinspection SimplifiableIfStatement
  149.         if (id == R.id.action_right_menu) {
  150.             if (drawer.isDrawerOpen(GravityCompat.END)) {
  151.                 drawer.closeDrawer(GravityCompat.END);
  152.             } else {
  153.                 drawer.openDrawer(GravityCompat.END);
  154.             }
  155.             return true;
  156.         }
  157.  
  158.         return super.onOptionsItemSelected(item);
  159.     }
  160.  
  161.     @Override
  162.     public boolean onCreateOptionsMenu(Menu menu) {
  163.         // Inflate the menu; this adds items to the action bar if it is present.
  164.         getMenuInflater().inflate(R.menu.main, menu);
  165.         return true;
  166.     }
  167.  
  168.  
  169.  
  170.     @SuppressWarnings("StatementWithEmptyBody")
  171.     @Override
  172.     public boolean onNavigationItemSelected(@NonNull MenuItem item) {
  173.         // Handle navigation view item clicks here.
  174.         int id = item.getItemId();
  175.  
  176.         // Handle the camera action
  177.         //Toast.makeText(this,"id"+id,Toast.LENGTH_LONG).show();
  178.  
  179.         if (id == R.id.nav_home) {
  180.  
  181.                     Intent it = new Intent(Home.this, Home.class);
  182.                     startActivity(it);
  183.  
  184.         }
  185.         else if (id == R.id.nav_fare) {
  186.  
  187.             Intent intent = new Intent(Home.this, Fare.class);
  188.             startActivity(intent);
  189.         }
  190.         else if (id == R.id.nav_courier) {
  191.             Intent intent = new Intent(Home.this, Courier.class);
  192.             startActivity(intent);
  193.         }
  194.         else if (id == R.id.nav_logout) {
  195.             credentialsEditor.putString(Constants.user_id, "0");
  196.             credentialsEditor.apply();
  197.  
  198.             Intent intent = new Intent(Home.this, PinActivity.class);
  199.             startActivity(intent);
  200.  
  201.         }
  202. //        drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
  203.         drawer.closeDrawer(GravityCompat.START);
  204.         return true;
  205.     }
  206.  
  207.     @Override
  208.     public DrawerLayout getDrawer() {
  209.         return drawer;
  210.     }
  211.  
  212.  
  213.     @Override
  214.     public void onCardClicked(String passenger_name, int phone_no, int seat_no) {
  215.         Toast.makeText(getApplicationContext(), "=> "+passengerDetails.get(phone_no).passenger_name, Toast.LENGTH_LONG).show();
  216.  
  217.         Intent it = new Intent(Home.this, PassengerActivity.class);
  218.         it.putExtra("passenger_name", passengerDetails.get(phone_no).passenger_name);
  219.         it.putExtra("phone_no", passengerDetails.get(phone_no).phone_no);
  220.         it.putExtra("seat_no", passengerDetails.get(seat_no).seat_no);
  221.         startActivity(it);
  222.  
  223.     }
  224. }
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