Permalink
Browse files

Major shit two

  • Loading branch information...
xts400 committed Jan 13, 2018
1 parent bfb662f commit a38c90ab226517c8e1b88dc1d2b81e7dc0a416e4
View
@@ -24,7 +24,7 @@
</value>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8 (3)" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8 (3)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">
@@ -8,6 +8,7 @@
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Typeface;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
@@ -42,6 +43,7 @@
import com.androidnetworking.common.Priority;
import com.androidnetworking.error.ANError;
import com.androidnetworking.interfaces.StringRequestListener;
import com.bumptech.glide.Glide;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
import com.google.android.gms.common.GooglePlayServicesRepairableException;
@@ -61,22 +63,30 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.muddzdev.styleabletoastlibrary.StyleableToast;
import com.shadtaxi.shadtaxi.BuildConfig;
import com.shadtaxi.shadtaxi.R;
import com.shadtaxi.shadtaxi.adapters.VehicleTypesAdapter;
import com.shadtaxi.shadtaxi.constants.Constants;
import com.shadtaxi.shadtaxi.data.Data;
import com.shadtaxi.shadtaxi.database.DatabaseHelper;
import com.shadtaxi.shadtaxi.models.User;
import com.shadtaxi.shadtaxi.models.VehicleType;
import com.shadtaxi.shadtaxi.utils.EqualSpacingItemDecoration;
import com.shadtaxi.shadtaxi.utils.PreferenceHelper;
import com.shadtaxi.shadtaxi.utils.Utils;
import com.shadtaxi.shadtaxi.views.Btn;
import com.shadtaxi.shadtaxi.views.Edt;
import com.shadtaxi.shadtaxi.views.Txt;
import com.shadtaxi.shadtaxi.views.TxtSemiBold;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
@@ -104,18 +114,21 @@
private DecimalFormat decimalFormat;
private Btn btnFindTaxi;
private PreferenceHelper preferenceHelper;
private DatabaseHelper databaseHelper;
private ArrayList<VehicleType> vehicleTypes;
public static final int PERMISSIONS_REQUEST_CODE = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_dashboard);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
fusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);
utils = new Utils(this, this);
decimalFormat = new DecimalFormat("0.00");
preferenceHelper = new PreferenceHelper(this);
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
databaseHelper = new DatabaseHelper(this);
vehicleTypes = new ArrayList<>();
InitToolbar(getResources().getString(R.string.app_name));
@@ -144,13 +157,18 @@ public void onClick(View view) {
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
View headerView = navigationView.getHeaderView(0);
CircleImageView profileImage = (CircleImageView) headerView.findViewById(R.id.profile_image);
TxtSemiBold txtUsername = (TxtSemiBold) headerView.findViewById(R.id.txtUsername);
Txt txtUserMobileNumber = (Txt) headerView.findViewById(R.id.txtUserMobileNumber);
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(DashboardActivity.this, ProfileActivity.class);
startActivity(intent);
}
});
setProfile(profileImage, txtUsername, txtUserMobileNumber);
navigationView.setNavigationItemSelectedListener(this);
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
@@ -161,7 +179,8 @@ public void onClick(View view) {
ex.printStackTrace();
}
initVehicleTypes();
getVehicleTypes();
}
private void initViews() {
@@ -176,6 +195,21 @@ private void initViews() {
btnFindTaxi.setOnClickListener(this);
}
private void setProfile(CircleImageView profile_image, TxtSemiBold user_name, Txt user_mobile_number) {
ArrayList<User> users = databaseHelper.getAllUsers();
User user = users.get(0);
user_name.setText(user.getName());
user_mobile_number.setText(user.getPhone());
if (!user.getImage().isEmpty()) {
Glide.with(this).load(user.getImage()).into(profile_image);
} else {
Glide.with(this).load(R.drawable.default_image).into(profile_image);
}
}
private void checkDropOffAvailability() {
if (edtDropOffLocation.getText().toString().isEmpty()) {
layoutBookingDetails.setVisibility(View.GONE);
@@ -596,7 +630,7 @@ public void onClick(DialogInterface dialog, int which) {
alertLogout.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dialog.dismiss();
}
});
@@ -701,12 +735,12 @@ public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
private void initVehicleTypes() {
Data data = new Data();
VehicleTypesAdapter vehicleTypesAdapter = new VehicleTypesAdapter(this, data.vehicleTypeArrayList());
VehicleTypesAdapter vehicleTypesAdapter = new VehicleTypesAdapter(this, databaseHelper.getAllVehicleTypes());
RecyclerView listVehicleTypes = (RecyclerView) findViewById(R.id.listVehicleTypes);
listVehicleTypes.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, true));
listVehicleTypes.addItemDecoration(new EqualSpacingItemDecoration(16, EqualSpacingItemDecoration.HORIZONTAL));
listVehicleTypes.addItemDecoration(new EqualSpacingItemDecoration(0, EqualSpacingItemDecoration.HORIZONTAL));
//listVehicleTypes.smoothScrollToPosition(selectedPosition);
listVehicleTypes.setHasFixedSize(true);
listVehicleTypes.setHasFixedSize(false);
listVehicleTypes.addOnItemTouchListener(new RecyclerTouchListener(this, listVehicleTypes, new ClickListener() {
@Override
@@ -781,4 +815,79 @@ public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
}
private void getVehicleTypes(){
String token = preferenceHelper.getAccessToken();
AndroidNetworking.post(Constants.GET_VEHICLES)
.addHeaders("Authorization", "Bearer " + token)
.addHeaders("Accept","application/json")
.addHeaders("Content-Type","application/x-www-form-urlencoded")
.addBodyParameter("latlong", "-1.248462, 36.772894")
.setTag("vehicleTypes")
.setPriority(Priority.HIGH)
.build()
.getAsString(new StringRequestListener() {
@Override
public void onResponse(String response) {
showErrorToast(response);
try {
JSONObject jsonArray = new JSONObject(response);
JSONObject jsonObject = jsonArray.getJSONObject("data");
JSONArray jsonArray1 = jsonObject.getJSONArray("vehicletypes");
for (int i = 0; i<jsonArray1.length();i++){
JSONObject jsonObject1 = jsonArray1.getJSONObject(i);
final String id = jsonObject1.getString("id");
final String name = jsonObject1.getString("name");
final String icon = jsonObject1.getString("icon");
final double per_distance = jsonObject1.getDouble("per_distance");
final double per_minute = jsonObject1.getDouble("per_minute");
final double minimum_price = jsonObject1.getDouble("minimum_price");
final double base_price = jsonObject1.getDouble("base_price");
VehicleType vehicleType = new VehicleType();
vehicleType.setId(id);
vehicleType.setName(name);
vehicleType.setIcon(icon);
vehicleType.setBase_price(base_price);
vehicleType.setMinimum_price(minimum_price);
vehicleType.setPer_distance(per_distance);
vehicleType.setPer_minute(per_minute);
databaseHelper.addVehicleType(vehicleType);
}
} catch (JSONException e) {
Log.e("vehicles::", e.getMessage());
}
initVehicleTypes();
}
@Override
public void onError(ANError error) {
showErrorToast(error.getErrorBody());
}
});
}
private void showErrorToast(String message) {
StyleableToast styleableToast = new StyleableToast
.Builder(this)
.duration(Toast.LENGTH_LONG)
.text(message)
.textColor(Color.WHITE)
.typeface(Typeface.createFromAsset(getAssets(), "fonts/Roboto-Medium.ttf"))
.backgroundColor(Color.RED)
.build();
if (styleableToast != null) {
styleableToast.show();
styleableToast = null;
}
}
}
@@ -46,29 +46,30 @@ public VehicleTypesAdapter(Context context, ArrayList<VehicleType> vehicleTypeAr
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
holder.txtVehicleType.setText(vehicleTypeArrayList.get(position).getVehicle_type());
Glide.with(context).load(vehicleTypeArrayList.get(position).getVehicle_icon()).into(holder.imageViewVehicleIcon);
holder.txtVehicleType.setText(vehicleTypeArrayList.get(position).getName());
if (vehicleTypeArrayList.get(position).getIcon().isEmpty()) {
Glide.with(context).load(R.drawable.tuktuk).into(holder.imageViewVehicleIcon);
} else {
Glide.with(context).load(vehicleTypeArrayList.get(position).getIcon()).into(holder.imageViewVehicleIcon);
}
if (!selectedPositions.contains(position)) {
if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Boda")) {
if (vehicleTypeArrayList.get(position).getName().contains("BODA")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_motorbike_not_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Tuk")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("TUK")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_tuktuk_not_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Salon")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("TAXI")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_salon_not_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Matatu")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_matatu_not_selected);
}
holder.txtVehicleType.setTextColor(context.getResources().getColor(R.color.colorBlack));
} else {
if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Boda")) {
if (vehicleTypeArrayList.get(position).getName().contains("BODA")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_motorbike_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Tuk")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("TUK")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_tuktuk_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Salon")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("TAXI")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_salon_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Matatu")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_matatu_selected);
}
holder.txtVehicleType.setTextColor(context.getResources().getColor(R.color.colorPrimary));
}
@@ -78,14 +79,12 @@ public void onClick(View view) {
if (!selectedPositions.contains(position)) {
selectedPositions.clear();
selectedPositions.add(position);
if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Boda")) {
if (vehicleTypeArrayList.get(position).getName().contains("Boda")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_motorbike_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Tuk")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("Tuk")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_tuktuk_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Salon")) {
} else if (vehicleTypeArrayList.get(position).getName().contains("Salon")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_salon_selected);
} else if (vehicleTypeArrayList.get(position).getVehicle_type().contains("Matatu")) {
holder.imageViewVehicleIcon.setImageResource(R.drawable.icon_matatu_selected);
}
holder.txtVehicleType.setTextColor(context.getResources().getColor(R.color.colorPrimary));
notifyDataSetChanged();
@@ -5,10 +5,11 @@
*/
public class Constants {
public static final String BASE_URL = "http://31bbd90d.ngrok.io";
public static final String BASE_URL = "http://d1f95bd0.ngrok.io";
public static final String REGISTRATION_URL = BASE_URL + "/api/user/register/";
public static final String LOGIN_URL = BASE_URL + "/oauth/token";
public static final String GET_USER = BASE_URL + "/api/user";
public static final String GET_VEHICLES = BASE_URL + "/api/app/load";
public static final int BODA_PRICE_PER_KILOMETER = 100;
public static final int BODA_PRICE_PER_MINUTE = 5;
@@ -21,10 +21,16 @@ public Data() {
public ArrayList<VehicleType> vehicleTypeArrayList() {
ArrayList<VehicleType> vehicleTypes = new ArrayList<>();
vehicleTypes.add(new VehicleType("Matatu", R.drawable.icon_matatu_not_selected));
vehicleTypes.add(new VehicleType("Salon", R.drawable.icon_salon_not_selected));
vehicleTypes.add(new VehicleType("TukTuk", R.drawable.icon_tuktuk_not_selected));
vehicleTypes.add(new VehicleType("BodaBoda", R.drawable.icon_motorbike_not_selected));
VehicleType vehicleType = new VehicleType();
vehicleType.setId("1");
vehicleType.setName("Boda");
vehicleType.setIcon("");
vehicleType.setBase_price(0.00);
vehicleType.setMinimum_price(0.00);
vehicleType.setPer_distance(0.00);
vehicleType.setPer_minute(0.00);
vehicleTypes.add(vehicleType);
return vehicleTypes;
}
Oops, something went wrong.

0 comments on commit a38c90a

Please sign in to comment.