daily pastebin goal
0%
SHARE
TWEET

Untitled

a guest Feb 11th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.nujek.driver;
  2.  
  3.  
  4. import android.content.DialogInterface;
  5. import android.content.Intent;
  6. import android.os.Bundle;
  7. import android.support.annotation.Nullable;
  8. import android.support.design.widget.AppBarLayout;
  9. import android.support.v4.app.Fragment;
  10. import android.support.v7.app.AlertDialog;
  11. import android.view.LayoutInflater;
  12. import android.view.Menu;
  13. import android.view.MenuInflater;
  14. import android.view.MenuItem;
  15. import android.view.View;
  16. import android.view.ViewGroup;
  17. import android.widget.Button;
  18. import android.widget.ImageView;
  19. import android.widget.TextView;
  20. import android.widget.Toast;
  21.  
  22. import com.bumptech.glide.Glide;
  23. import com.nujek.driver.config.Session;
  24. import com.nujek.driver.config.Settings;
  25. import com.nujek.driver.model.asset.AssetType;
  26. import com.nujek.driver.model.asset.PartnerAsset;
  27. import com.nujek.driver.model.asset.Vehicle;
  28. import com.nujek.driver.model.auth.Account;
  29. import com.nujek.driver.ui.auth.login.LoginActivity;
  30. import com.nujek.driver.ui.widget.ToastComposer;
  31.  
  32. import java.util.List;
  33.  
  34.  
  35. /**
  36.  * A simple {@link Fragment} subclass.
  37.  */
  38. public class OthersFragment extends Fragment {
  39.  
  40.     private TextView name, lisencePlat, email, phoneNumber;
  41.     private ImageView photo;
  42.  
  43.     private TextView tv_toolbar;
  44.     private AppBarLayout appBar;
  45.  
  46.  
  47.     public OthersFragment() {
  48.         // Required empty public constructor
  49.         setHasOptionsMenu(true);
  50.     }
  51.  
  52.  
  53.     @Override
  54.     public View onCreateView(LayoutInflater inflater, ViewGroup container,
  55.                              Bundle savedInstanceState) {
  56.         // Inflate the layout for this fragment
  57.         View view = inflater.inflate(R.layout.fragment_others, container, false);
  58.  
  59. //        appBar = view.findViewById(R.id.app_barr);
  60.  
  61.         tv_toolbar = view.findViewById(R.id.toolbar_title);
  62.         tv_toolbar.setText("Profile");
  63.  
  64.  
  65.  
  66.         photo = view.findViewById(R.id.iv_photo);
  67.         name = view.findViewById(R.id.tv_name);
  68.         lisencePlat = view.findViewById(R.id.tv_plat_number);
  69.         email = view.findViewById(R.id.tv_email);
  70.         phoneNumber = view.findViewById(R.id.tv_phone_number);
  71.  
  72.  
  73.         name.setText(Account.getInstance().getName());
  74.         email.setText(Account.getInstance().getEmail());
  75.         phoneNumber.setText(Account.getInstance().getPhone());
  76.         Glide.with(getActivity())
  77.                 .load(Account.getInstance().getAvatar())
  78.                 .into(photo);
  79.  
  80.         List<PartnerAsset> assets = Account.getInstance().getAssets();
  81.         for (int i = 0; i < assets.size(); i++) {
  82.             PartnerAsset partnerAsset = assets.get(i);
  83.             if (partnerAsset instanceof Vehicle) {
  84.                 Vehicle vehicle = (Vehicle) partnerAsset;
  85.                 lisencePlat.setText(vehicle.getLicensePlate());
  86.             }
  87.  
  88.         }
  89.  
  90.  
  91.         Button btnLogout = view.findViewById(R.id.btn_logout);
  92.  
  93.         btnLogout.setOnClickListener(new View.OnClickListener() {
  94.             @Override
  95.             public void onClick(View v) {
  96.                 new AlertDialog.Builder(getActivity())
  97.                         .setTitle("Logout")
  98.                         .setMessage("Are you sure?")
  99.                         .setIcon(android.R.drawable.ic_dialog_alert)
  100.                         .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
  101.  
  102.                             public void onClick(DialogInterface dialog, int whichButton) {
  103.                                 Account.getInstance().deleteCurrentUser();
  104.                                 Session.logout();
  105.  
  106.                                 Intent intent = new Intent(getActivity(), LoginActivity.class);
  107.                                 startActivity(intent);
  108.                                 getActivity().finish();
  109.                             }
  110.                         })
  111.                         .setNegativeButton(android.R.string.no, null).show();
  112.             }
  113.         });
  114.  
  115.  
  116.         return view;
  117.     }
  118.  
  119.     public void onCreate(Bundle savedInstanceState) {
  120.         super.onCreate(savedInstanceState);
  121.         setHasOptionsMenu(true);
  122.  
  123.     }
  124.  
  125.     @Override
  126.     public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  127.         // Do something that differs the Activity's menu here
  128.         super.onCreateOptionsMenu(menu, inflater);
  129.     }
  130.  
  131.     @Override
  132.     public boolean onOptionsItemSelected(MenuItem item) {
  133.         switch (item.getItemId()) {
  134.  
  135.             case R.id.edit_number:
  136.  
  137.                 // Not implemented here
  138.                 return false;
  139.             case R.id.logout:
  140.  
  141.                 // Do Fragment menu item stuff here
  142.                 return true;
  143.  
  144.             default:
  145.                 break;
  146.         }
  147.  
  148.         return false;
  149.     }
  150.  
  151. }
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