diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/ContainerDetailActivity.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/ContainerDetailActivity.java index 69ec82c..6cd1067 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/ContainerDetailActivity.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/ContainerDetailActivity.java @@ -7,32 +7,46 @@ import android.text.Html; import android.util.Log; import android.view.View; import android.widget.Button; +import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import androidx.activity.EdgeToEdge; import androidx.appcompat.app.AppCompatActivity; +import androidx.core.content.ContextCompat; import androidx.core.graphics.Insets; import androidx.core.view.ViewCompat; import androidx.core.view.WindowInsetsCompat; import androidx.lifecycle.ViewModelProvider; import com.utopiaindustries.selftrucking.Activities.dashboardScreens.viewModels.HomeViewModel; +import com.utopiaindustries.selftrucking.Activities.loginScreens.SplashActivity; import com.utopiaindustries.selftrucking.R; +import com.utopiaindustries.selftrucking.helper.Helper; import com.utopiaindustries.selftrucking.models.ContainerWorkflow; +import com.utopiaindustries.selftrucking.models.DriverResponse; import com.utopiaindustries.selftrucking.models.PickResponse; import com.utopiaindustries.selftrucking.models.PickupRequest; +import com.utopiaindustries.selftrucking.models.PickupRequestForComplete; import com.utopiaindustries.selftrucking.utils.ProgressDialogFragment; +import java.util.ArrayList; +import java.util.List; + public class ContainerDetailActivity extends AppCompatActivity { - TextView container_no, container_origin, containerDestination, driverId, driverName; + TextView container_no, container_origin, containerDestination, driverId, driverName, container_status; Button btnMarkPicked; //FoodDetailObj singleList; ContainerWorkflow containerWorkflow; String truckerId = ""; String truckerName = ""; HomeViewModel homeViewModel; + String currentStatus = "PICKED"; + int currentPosition = 0; + DriverResponse driverResponse; + List containerList = new ArrayList<>(); + ImageView img_back; @Override protected void onCreate(Bundle savedInstanceState) { @@ -45,18 +59,59 @@ public class ContainerDetailActivity extends AppCompatActivity { return insets; }); + if( !Helper.isNetworkConnected(this) ){ + Toast.makeText( this, "No Internet Connection", Toast.LENGTH_LONG ).show(); + } + initializeLayout(); + img_back.setOnClickListener(v -> finish()); + btnMarkPicked.setOnClickListener(v -> { + + /*if (currentStatus.equalsIgnoreCase("DROPPED")) { + PickupRequestForComplete request = new PickupRequestForComplete(containerWorkflow.getOriginId(), + containerWorkflow.getDestinationId(), + containerWorkflow.getContainerNo(), + currentStatus, + 50, + "USD", + Integer.parseInt(truckerId), + containerWorkflow.getTruckLoadId() != null ? containerWorkflow.getTruckLoadId() : 0); + + Log.e("Pick-Request: ", ""+ request.toString()); + homeViewModel.pickTruckLoad(request); + } + else { + PickupRequest request = new PickupRequest(containerWorkflow.getOriginId(), + containerWorkflow.getDestinationId(), + containerWorkflow.getContainerNo(), + currentStatus, + 50, + "USD", + Integer.parseInt(truckerId)); + }*/ + + /*if (currentStatus.equalsIgnoreCase("DROPPED")) { + Log.e("Pick-Request: ", "DROPPED "+currentStatus); + } + else { + Log.e("Pick-Request: ", "ELSE "+currentStatus); + }*/ + PickupRequest request = new PickupRequest(containerWorkflow.getOriginId(), containerWorkflow.getDestinationId(), containerWorkflow.getContainerNo(), + currentStatus, 50, "USD", - Integer.parseInt(truckerId)); - Log.e("Pick-Request: ", "" + request.toString()); + Integer.parseInt(truckerId), + containerWorkflow.getTruckLoadId() != null ? containerWorkflow.getTruckLoadId() : 0); + + // Log.e("Pick-Request: ", ""+ request.toString()); homeViewModel.pickTruckLoad(request); - Toast.makeText(this, "Container marked as picked", Toast.LENGTH_SHORT).show(); + + //Toast.makeText(this, "Container marked as picked", Toast.LENGTH_SHORT).show(); //Intent intent = new Intent(ContainerDetailActivity.this, TrackingActivity.class); //intent.putExtra("container_id", container.getContainerId()); @@ -69,14 +124,23 @@ public class ContainerDetailActivity extends AppCompatActivity { container_no = findViewById(R.id.container_no); container_origin = findViewById(R.id.container_origin); containerDestination = findViewById(R.id.container_destination); + container_status = findViewById(R.id.container_status); driverId = findViewById(R.id.driver_Id); driverName = findViewById(R.id.driver_name); btnMarkPicked = findViewById(R.id.btn_mark_picked); + img_back = findViewById(R.id.img_back); homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class); containerWorkflow = (ContainerWorkflow) getIntent().getSerializableExtra("SingleContainerInfo"); + truckerId = getIntent().getStringExtra("TruckerId"); truckerName = getIntent().getStringExtra("TruckerName"); + currentPosition = getIntent().getIntExtra("position",0); + // Log.e("currentPosition: ",""+currentPosition); + + driverResponse = Helper.getPreferenceObjectJson(this, "DriverResponse"); + //assert driverResponse != null; + //containerList.addAll(driverResponse.getContainerWorkflowData()); homeViewModel.getLoadingState().observe(this, isLoading -> { if (isLoading != null && isLoading) { @@ -86,11 +150,69 @@ public class ContainerDetailActivity extends AppCompatActivity { } }); + homeViewModel.getErrorMessage().observe(this, errorResponse -> { + Toast.makeText(this, errorResponse, Toast.LENGTH_SHORT).show(); + }); + homeViewModel.getPickLiveData().observe(this, pickResponse -> { if (pickResponse != null) { - Log.d("API", "Message: " + pickResponse.getMessage()); - Log.d("API", "Status: " + pickResponse.isStatus()); - Toast.makeText(ContainerDetailActivity.this,pickResponse.getMessage(), Toast.LENGTH_SHORT).show(); + //Log.d("API", "Message: " + pickResponse.getMessage()); + //Log.d("API", "Status: " + pickResponse.getStatus()); + + Toast.makeText(this, pickResponse.getMessage(), Toast.LENGTH_SHORT).show(); + ContainerWorkflow containerToUpdate = driverResponse.getContainerWorkflowData().get(currentPosition); + + // Modify the values + + containerToUpdate.setCurrentStatus(pickResponse.getTruckLoad().getStatus()); + containerToUpdate.setTruckLoadId(pickResponse.getTruckLoad().getTruckLoadId()); + + Helper.setPreferenceObject(getApplicationContext(), driverResponse, "DriverResponse"); + + DriverResponse driverResponse1 = Helper.getPreferenceObjectJson(getApplicationContext(), "DriverResponse"); + ContainerWorkflow containerToUpdate1 = driverResponse1.getContainerWorkflowData().get(currentPosition); + containerWorkflow = driverResponse1.getContainerWorkflowData().get(currentPosition); + //Log.e("driverResponse1: ",""+driverResponse1.getContainerWorkflowData()); + + /*Log.e("After Update: ","****************************************"); + Log.e("containerToUpdate1-ContainerNo: ",""+containerWorkflow.getContainerNo()); + Log.e("containerToUpdate1-OriginId: ",""+containerWorkflow.getOriginId()); + Log.e("containerToUpdate1-origin: ",""+containerWorkflow.getOrigin()); + Log.e("containerToUpdate1-destination: ",""+containerWorkflow.getDestination()); + Log.e("containerToUpdate1-destinationId: ",""+containerWorkflow.getDestinationId()); + Log.e("containerToUpdate1-Status: ",""+containerWorkflow.getCurrentStatus()); + Log.e("containerToUpdate1-truckLoadId: ",""+containerWorkflow.getTruckLoadId());*/ + + setContainerDetail(containerWorkflow); + + //Toast.makeText(ContainerDetailActivity.this,pickResponse.getMessage(), Toast.LENGTH_SHORT).show(); + + /*if (driverResponse != null && driverResponse.getContainerWorkflowData() != null + && currentPosition < driverResponse.getContainerWorkflowData().size()) { + ContainerWorkflow containerToUpdate = driverResponse.getContainerWorkflowData().get(currentPosition); + + // Modify the values + + containerToUpdate.setCurrentStatus(pickResponse.getTruckLoad().getStatus()); + containerToUpdate.setTruckLoadId(pickResponse.getTruckLoad().getTruckLoadId()); + + Helper.setPreferenceObject(getApplicationContext(), driverResponse, "DriverResponse"); + + DriverResponse driverResponse1 = Helper.getPreferenceObjectJson(getApplicationContext(), "DriverResponse"); + ContainerWorkflow containerToUpdate1 = driverResponse1.getContainerWorkflowData().get(currentPosition); + containerWorkflow = driverResponse1.getContainerWorkflowData().get(currentPosition); + + Log.e("After Update: ","****************************************"); + Log.e("containerToUpdate1-ContainerNo: ",""+containerWorkflow.getContainerNo()); + Log.e("containerToUpdate1-OriginId: ",""+containerWorkflow.getOriginId()); + Log.e("containerToUpdate1-origin: ",""+containerWorkflow.getOrigin()); + Log.e("containerToUpdate1-destination: ",""+containerWorkflow.getDestination()); + Log.e("containerToUpdate1-destinationId: ",""+containerWorkflow.getDestinationId()); + Log.e("containerToUpdate1-Status: ",""+containerWorkflow.getCurrentStatus()); + Log.e("containerToUpdate1-truckLoadId: ",""+containerWorkflow.getTruckLoadId()); + + setContainerDetail(containerWorkflow); + }*/ } }); @@ -100,11 +222,68 @@ public class ContainerDetailActivity extends AppCompatActivity { private void setContainerDetail(ContainerWorkflow containerWorkflow) { + /* Log.e("Before Update: ","****************************************"); + Log.e("containerToUpdate1-ContainerNo: ",""+containerWorkflow.getContainerNo()); + Log.e("containerToUpdate1-OriginId: ",""+containerWorkflow.getOriginId()); + Log.e("containerToUpdate1-origin: ",""+containerWorkflow.getOrigin()); + Log.e("containerToUpdate1-destination: ",""+containerWorkflow.getDestination()); + Log.e("containerToUpdate1-destinationId: ",""+containerWorkflow.getDestinationId()); + Log.e("containerToUpdate1-Status: ",""+containerWorkflow.getCurrentStatus()); + Log.e("containerToUpdate1-truckLoadId: ",""+containerWorkflow.getTruckLoadId());*/ + container_no.setText(Html.fromHtml("Container No: " + containerWorkflow.getContainerNo(), Html.FROM_HTML_MODE_LEGACY)); container_origin.setText(Html.fromHtml("Container Origin: " + containerWorkflow.getOrigin(), Html.FROM_HTML_MODE_LEGACY)); containerDestination.setText(Html.fromHtml("Container Destination: " + containerWorkflow.getDestination(), Html.FROM_HTML_MODE_LEGACY)); driverId.setText(Html.fromHtml("Driver Id: " + truckerId, Html.FROM_HTML_MODE_LEGACY)); driverName.setText(Html.fromHtml("Driver Name: " + truckerName, Html.FROM_HTML_MODE_LEGACY)); + currentStatus = containerWorkflow.getCurrentStatus(); + + if (containerWorkflow.getCurrentStatus() != null && !containerWorkflow.getCurrentStatus().equalsIgnoreCase("")) { + container_status.setText(Html.fromHtml("Container Status: " + containerWorkflow.getCurrentStatus(), Html.FROM_HTML_MODE_LEGACY)); + } + else { + container_status.setText(Html.fromHtml("Container Status: " + "Assigned", Html.FROM_HTML_MODE_LEGACY)); + } + + if (containerWorkflow.getCurrentStatus() != null) { + // Log.e("Status: ",""+(containerWorkflow.getCurrentStatus().toLowerCase())); + switch (containerWorkflow.getCurrentStatus()) { + + + case "PICKED": + btnMarkPicked.setBackgroundColor(ContextCompat.getColor(this, R.color.picked_color)); + btnMarkPicked.setText("Mark it Dropped"); + currentStatus = "DROPPED"; + break; + + case "DROPPED": + btnMarkPicked.setBackgroundColor(ContextCompat.getColor(this, R.color.dropped_color)); + btnMarkPicked.setText("Mark it Completed"); + currentStatus = "COMPLETED"; + break; + + case "COMPLETED": + //btnMarkPicked.setBackgroundColor(ContextCompat.getColor(this, R.color.completed_color)); + btnMarkPicked.setText("Mark it Picked"); + currentStatus = "PICKED"; + + Intent myIntent = new Intent(ContainerDetailActivity.this, HomeActivity.class); + myIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(myIntent); + overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); + finish(); + break; + + default: + btnMarkPicked.setBackgroundColor(ContextCompat.getColor(this, R.color.theme_color)); + btnMarkPicked.setText("Mark it Picked"); + currentStatus = "PICKED"; + } + } + else { + btnMarkPicked.setBackgroundColor(ContextCompat.getColor(this, R.color.theme_color)); + currentStatus = "PICKED"; + } } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/HomeActivity.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/HomeActivity.java index 0a2ab5a..7f05c38 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/HomeActivity.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/HomeActivity.java @@ -6,9 +6,13 @@ import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.os.Bundle; import android.text.Html; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; @@ -47,17 +51,18 @@ import retrofit2.Response; public class HomeActivity extends AppCompatActivity implements SelectListener { - //String[] item = {"Material", "Design", "Components", "Android", "5.0 Lollipop"}; - //AutoCompleteTextView autoCompleteTextView; - //ArrayAdapter adapterItems; + String[] item = {"All", "Assigned", "Picked", "Dropped", "Completed"}; + AutoCompleteTextView autoCompleteTextView; + ArrayAdapter adapterItems; HomeViewModel homeViewModel; RecyclerView containerRecyclerView; ContainerAdapter adapter; List containerList = new ArrayList<>(); + List tempList = new ArrayList<>(); ApiService apiService; MotiveApiService motiveApiService; DriverResponse driverResponse; - TextView txtDriverName; + TextView txtDriverName, txtNoData; ImageView imgLogout; @Override @@ -71,16 +76,21 @@ public class HomeActivity extends AppCompatActivity implements SelectListener { return insets; }); + if (!Helper.isNetworkConnected(this)) { + Toast.makeText(this, "No Internet Connection", Toast.LENGTH_LONG).show(); + } + initializeLayout(); - /*autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { + autoCompleteTextView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView adapterView, View view, int position, long l) { String item = adapterView.getItemAtPosition(position).toString(); - Log.e("Item: ", ""+ item); + Log.e("Item-----------: ", "" + item); + filterList(item); } - });*/ + }); imgLogout.setOnClickListener(new View.OnClickListener() { @Override @@ -90,7 +100,6 @@ public class HomeActivity extends AppCompatActivity implements SelectListener { }); } - public void initializeLayout() { homeViewModel = new ViewModelProvider(this).get(HomeViewModel.class); containerRecyclerView = findViewById(R.id.container_list); @@ -98,70 +107,84 @@ public class HomeActivity extends AppCompatActivity implements SelectListener { apiService = ApiServiceFactory.getApiService(); motiveApiService = ApiServiceFactory.getMotiveApiService(); txtDriverName = findViewById(R.id.txt_driver_name); + txtNoData = findViewById(R.id.txt_no_data); imgLogout = findViewById(R.id.img_logout); - driverResponse = Helper.getPreferenceObjectJson(this, "DriverResponse"); - assert driverResponse != null; - containerList.addAll(driverResponse.getContainerWorkflowData()); - - //dummyData(); - txtDriverName.setText(Html.fromHtml("Welcome: " + driverResponse.getTruckerName(), Html.FROM_HTML_MODE_LEGACY)); - - adapter = new ContainerAdapter(containerList, this); - containerRecyclerView.setAdapter(adapter); - - /*autoCompleteTextView = findViewById(R.id.auto_complete_textview); + autoCompleteTextView = findViewById(R.id.auto_complete_textview); adapterItems = new ArrayAdapter(this, R.layout.list_items, item); - autoCompleteTextView.setAdapter(adapterItems);*/ + autoCompleteTextView.setAdapter(adapterItems); + if (item.length > 0) { + autoCompleteTextView.setText(item[0], false); + } + + } + + private void filterList(String status) { + containerList.clear(); + for (ContainerWorkflow cx : tempList) { + Log.e("tempList-status: ", "" + cx.getCurrentStatus()); + } + + + if (status.equals("All")) { + containerList.addAll(tempList); + } /*else if (status.equalsIgnoreCase("Assigned")) { + for (ContainerWorkflow item : tempList) { + if (item.getCurrentStatus() != null + && !item.getCurrentStatus().equalsIgnoreCase("Picked") + && !item.getCurrentStatus().equalsIgnoreCase("Dropped") + && !item.getCurrentStatus().equalsIgnoreCase("Completed")) { + containerList.add(item); + } + } + }*/ else { + for (ContainerWorkflow item : tempList) { + if (item.getCurrentStatus() != null && item.getCurrentStatus().equalsIgnoreCase(status)) { + containerList.add(item); + } + } + } + + if (!containerList.isEmpty()) { + txtNoData.setVisibility(View.GONE); + } else { + txtNoData.setVisibility(View.VISIBLE); + } + + adapter.notifyDataSetChanged(); } @Override - public void onItemClicked(ContainerWorkflow container) { - Toast.makeText(this, String.valueOf(container.getContainerNo()), Toast.LENGTH_SHORT).show(); - - Intent intent = new Intent(HomeActivity.this, ContainerDetailActivity.class); - intent.putExtra("TruckerId", driverResponse.getTruckerId().toString()); - intent.putExtra("TruckerName", driverResponse.getTruckerName()); - intent.putExtra("SingleContainerInfo", (Serializable) container); - startActivity(intent); - overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); - + public void onItemClicked(ContainerWorkflow container, int pos) { + if (container.getCurrentStatus() != null && container.getCurrentStatus().equalsIgnoreCase("COMPLETED")) { + Toast.makeText(this, "Already Completed", Toast.LENGTH_SHORT).show(); + } else { + //Toast.makeText(this, String.valueOf(container.getContainerNo()), Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(HomeActivity.this, ContainerDetailActivity.class); + intent.putExtra("TruckerId", driverResponse.getTruckerId().toString()); + intent.putExtra("TruckerName", driverResponse.getTruckerName()); + intent.putExtra("position", pos); + intent.putExtra("SingleContainerInfo", (Serializable) container); + startActivity(intent); + overridePendingTransition(R.anim.slide_in_right, R.anim.slide_out_left); + } } - /*public void dummyData() { - Container container1 = new Container("1","Karachi To Lahore","Assigned","11","abc"); - Container container2 = new Container("2","Lahore To Lahore","Assigned","11","abc"); - Container container3 = new Container("3","Islamabad To Lahore","Assigned","11","abc"); - Container container4 = new Container("4","Peshawar To Lahore","Assigned","11","abc"); - Container container5 = new Container("5","Multan To Lahore","Assigned","11","abc"); - Container container6 = new Container("6","Faisalabad To Lahore","Assigned","11","abc"); - Container container7 = new Container("7","Quetta To Lahore","Assigned","11","abc"); - - containerList.add(container1); - containerList.add(container2); - containerList.add(container3); - containerList.add(container4); - containerList.add(container5); - containerList.add(container6); - containerList.add(container7); - }*/ - private void fetchAssignedContainers() { apiService.fetchAllReports("").enqueue(new Callback>() { @Override public void onResponse(Call> call, Response> response) { - if( response.isSuccessful() && response.body() != null ){ + if (response.isSuccessful() && response.body() != null) { - } - else { + } else { } } @Override public void onFailure(Call> call, Throwable t) { - System.out.println( t.getMessage() ); + System.out.println(t.getMessage()); } }); } @@ -226,4 +249,28 @@ public class HomeActivity extends AppCompatActivity implements SelectListener { alertDialog.show(); } + + @Override + protected void onResume() { + super.onResume(); + + containerList.clear(); + tempList.clear(); + driverResponse = Helper.getPreferenceObjectJson(this, "DriverResponse"); + assert driverResponse != null; + containerList.addAll(driverResponse.getContainerWorkflowData()); + tempList.addAll(driverResponse.getContainerWorkflowData()); + + //dummyData(); + txtDriverName.setText(Html.fromHtml("Welcome: " + "" + driverResponse.getTruckerName() + "", Html.FROM_HTML_MODE_LEGACY)); + + adapter = new ContainerAdapter(containerList, this, HomeActivity.this); + containerRecyclerView.setAdapter(adapter); + + if (!containerList.isEmpty()) { + txtNoData.setVisibility(View.GONE); + } else { + txtNoData.setVisibility(View.VISIBLE); + } + } } \ No newline at end of file diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/adapters/ContainerAdapter.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/adapters/ContainerAdapter.java index 42782cc..f47fe99 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/adapters/ContainerAdapter.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/adapters/ContainerAdapter.java @@ -1,5 +1,7 @@ package com.utopiaindustries.selftrucking.Activities.dashboardScreens.adapters; +import android.content.Context; +import android.content.Intent; import android.text.Html; import android.view.LayoutInflater; import android.view.View; @@ -7,8 +9,11 @@ import android.view.ViewGroup; import android.widget.TextView; import androidx.annotation.NonNull; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.RecyclerView; +import com.utopiaindustries.selftrucking.Activities.dashboardScreens.ContainerDetailActivity; +import com.utopiaindustries.selftrucking.Activities.dashboardScreens.HomeActivity; import com.utopiaindustries.selftrucking.Activities.dashboardScreens.interfaces.SelectListener; import com.utopiaindustries.selftrucking.models.Container; import com.utopiaindustries.selftrucking.R; @@ -20,10 +25,12 @@ public class ContainerAdapter extends RecyclerView.Adapter containerList; private SelectListener listener; + private Context context; - public ContainerAdapter(List containerList, SelectListener listener) { + public ContainerAdapter(List containerList, SelectListener listener, Context context) { this.containerList = containerList; this.listener = listener; + this.context = context; } @NonNull @@ -37,12 +44,40 @@ public class ContainerAdapter extends RecyclerView.AdapterContainer No: " + container.getContainerNo(), Html.FROM_HTML_MODE_LEGACY)); - holder.container_origin.setText(Html.fromHtml("Container Origin: " + container.getOrigin(), Html.FROM_HTML_MODE_LEGACY)); - holder.container_destination.setText(Html.fromHtml("Container Destination: " + container.getDestination(), Html.FROM_HTML_MODE_LEGACY)); + //holder.container_no.setText(Html.fromHtml("Container No: " + container.getContainerNo(), Html.FROM_HTML_MODE_LEGACY)); + holder.container_no.setText(container.getContainerNo()); + holder.container_origin.setText(container.getOrigin()); + holder.container_destination.setText(container.getDestination()); + if (container.getCurrentStatus() != null && !container.getCurrentStatus().equalsIgnoreCase("")) { + holder.container_status.setText(container.getCurrentStatus()); + } else { + holder.container_status.setText("Assigned"); + } - holder.itemView.setOnClickListener(v -> listener.onItemClicked(container)); + if (container.getCurrentStatus() != null && !container.getCurrentStatus().equalsIgnoreCase("")) { + switch (container.getCurrentStatus()) { + case "PICKED": + holder.container_status.setBackgroundColor(ContextCompat.getColor(context, R.color.picked_color)); + break; + + case "DROPPED": + holder.container_status.setBackgroundColor(ContextCompat.getColor(context, R.color.dropped_color)); + break; + + case "COMPLETED": + holder.container_status.setBackgroundColor(ContextCompat.getColor(context, R.color.completed_color)); + break; + + default: + holder.container_status.setBackgroundColor(ContextCompat.getColor(context, R.color.theme_color)); + + } + } else { + holder.container_status.setBackgroundColor(ContextCompat.getColor(context, R.color.theme_color)); + } + + holder.itemView.setOnClickListener(v -> listener.onItemClicked(container, position)); } @Override @@ -51,13 +86,14 @@ public class ContainerAdapter extends RecyclerView.Adapter pickTruckLoad( @Body PickupRequest request ); diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/apiservice/RetrofitClient.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/apiservice/RetrofitClient.java index 938a136..a47f68a 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/apiservice/RetrofitClient.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/apiservice/RetrofitClient.java @@ -3,12 +3,15 @@ package com.utopiaindustries.selftrucking.Activities.dashboardScreens.apiservice import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import java.util.concurrent.TimeUnit; + +import okhttp3.OkHttpClient; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class RetrofitClient { - private final static String BASE_URL = "http://192.168.90.228:8080/cosmos/";//"http://192.168.90.27:8080/uind/"; + private final static String BASE_URL = "http://192.168.90.228:8081/cosmos/";//"http://192.168.90.27:8080/uind/"; private static Retrofit retrofit; @@ -18,11 +21,19 @@ public class RetrofitClient { //.registerTypeAdapter(Boolean.class, new BooleanTypeAdapter()) .create(); + if (retrofit == null) { try { + + OkHttpClient okHttpClient = new OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .readTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .build(); + retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) - //.client( SSLCheckHttpClient.getOkHttpClient() ) + .client(okHttpClient) .addConverterFactory(GsonConverterFactory.create(gson)) .build(); } catch (Exception e) { diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/interfaces/SelectListener.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/interfaces/SelectListener.java index c941cc6..afeabe2 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/interfaces/SelectListener.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/interfaces/SelectListener.java @@ -5,5 +5,5 @@ import com.utopiaindustries.selftrucking.models.ContainerWorkflow; public interface SelectListener { - void onItemClicked(ContainerWorkflow container); + void onItemClicked(ContainerWorkflow container, int position); } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/viewModels/HomeViewModel.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/viewModels/HomeViewModel.java index 597ca64..1ae052e 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/viewModels/HomeViewModel.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/dashboardScreens/viewModels/HomeViewModel.java @@ -38,6 +38,10 @@ public class HomeViewModel extends ViewModel { return isLoading; } + public LiveData getErrorMessage() { + return errorLiveData; + } + public void pickTruckLoad(PickupRequest pickupRequest) { isLoading.setValue(true); @@ -46,24 +50,15 @@ public class HomeViewModel extends ViewModel { public void onResponse(Call call, Response response) { isLoading.setValue(false); if (response.isSuccessful()) { - Log.e("API_CALL", "Successfull."); - if (response.isSuccessful()) { - userLiveData.setValue(response.body()); + userLiveData.setValue(response.body()); - } else { - errorLiveData.setValue(response.message()); - } } else { - // Handle the case where the server responds with an error - Log.e("API_CALL", "Error: " + response.code()); errorLiveData.setValue(response.message()); } } @Override public void onFailure(Call call, Throwable t) { - // Handle the failure - Log.e("API_CALL", "Failed", t); isLoading.setValue(false); errorLiveData.setValue(t.getMessage()); } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/LoginActivity.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/LoginActivity.java index 13cf1ca..55340eb 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/LoginActivity.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/LoginActivity.java @@ -40,6 +40,10 @@ public class LoginActivity extends AppCompatActivity { return insets; }); + if( !Helper.isNetworkConnected(this) ){ + Toast.makeText( this, "No Internet Connection", Toast.LENGTH_LONG ).show(); + } + initializeLayouts(); btnLogin.setOnClickListener(v -> { @@ -69,6 +73,10 @@ public class LoginActivity extends AppCompatActivity { } }); + loginViewModel.getErrorMessage().observe(this, errorResponse -> { + Toast.makeText(this, errorResponse, Toast.LENGTH_SHORT).show(); + }); + loginViewModel.getUserLiveData().observe(this, user -> { if (user != null) { Preference.setMyBooleanPref(Helper.project_file, "isLoggedIn", getApplicationContext(), true); diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/viewModels/LoginViewModel.java b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/viewModels/LoginViewModel.java index 502e30a..5a73cae 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/viewModels/LoginViewModel.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/Activities/loginScreens/viewModels/LoginViewModel.java @@ -35,6 +35,10 @@ public class LoginViewModel extends ViewModel { return isLoading; } + public LiveData getErrorMessage() { + return errorLiveData; + } + public void authenticateUser(String user, String password) { isLoading.setValue(true); apiService.isUserAuthenticated(user, password).enqueue(new Callback() { diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/helper/Helper.java b/app/src/main/java/com/utopiaindustries/selftrucking/helper/Helper.java index c87ddca..5e4497e 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/helper/Helper.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/helper/Helper.java @@ -2,6 +2,8 @@ package com.utopiaindustries.selftrucking.helper; import android.content.Context; import android.content.SharedPreferences; +import android.net.ConnectivityManager; +import android.net.NetworkInfo; import android.text.TextUtils; import androidx.preference.PreferenceManager; @@ -38,4 +40,10 @@ public class Helper { DriverResponse selectedUser = gson.fromJson(json, DriverResponse.class); return selectedUser; } + + public static boolean isNetworkConnected(Context context) { + ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); + NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo(); + return activeNetwork != null && activeNetwork.isConnectedOrConnecting(); + } } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/models/ContainerWorkflow.java b/app/src/main/java/com/utopiaindustries/selftrucking/models/ContainerWorkflow.java index ea6d465..e5c55b0 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/models/ContainerWorkflow.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/models/ContainerWorkflow.java @@ -23,6 +23,13 @@ public class ContainerWorkflow implements Serializable { @SerializedName("destination") @Expose private String destination; + @SerializedName("currentStatus") + @Expose + private String currentStatus = "Assigned"; + @SerializedName("truckLoadId") + @Expose + private Integer truckLoadId; + public String getContainerNo() { return containerNo; @@ -63,4 +70,20 @@ public class ContainerWorkflow implements Serializable { public void setDestinationId(Integer destinationId) { this.destinationId = destinationId; } + + public String getCurrentStatus() { + return currentStatus; + } + + public void setCurrentStatus(String currentStatus) { + this.currentStatus = currentStatus; + } + + public Integer getTruckLoadId() { + return truckLoadId; + } + + public void setTruckLoadId(Integer truckLoadId) { + this.truckLoadId = truckLoadId; + } } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/models/PickResponse.java b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickResponse.java index bbba429..011ce22 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/models/PickResponse.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickResponse.java @@ -1,11 +1,28 @@ package com.utopiaindustries.selftrucking.models; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + public class PickResponse { + @SerializedName("truck_load") + @Expose + private TruckLoad truckLoad; + @SerializedName("message") + @Expose private String message; - private boolean status; + @SerializedName("status") + @Expose + private Boolean status; + + public TruckLoad getTruckLoad() { + return truckLoad; + } + + public void setTruckLoad(TruckLoad truckLoad) { + this.truckLoad = truckLoad; + } - // Getters and setters public String getMessage() { return message; } @@ -14,11 +31,12 @@ public class PickResponse { this.message = message; } - public boolean isStatus() { + public Boolean getStatus() { return status; } - public void setStatus(boolean status) { + public void setStatus(Boolean status) { this.status = status; } + } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequest.java b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequest.java index a71fad9..9437e37 100644 --- a/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequest.java +++ b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequest.java @@ -6,17 +6,21 @@ public class PickupRequest { private int dropoffLocation; private String loadTypeId; private double agreedAmount; + private String status; private String agreedAmountCurrency; private int assignedToDriver; + private int truckLoadId; - public PickupRequest(int pickupLocation, int dropoffLocation, String loadTypeId, - double agreedAmount, String agreedAmountCurrency, int assignedToDriver) { + public PickupRequest(int pickupLocation, int dropoffLocation, String loadTypeId, String status, + double agreedAmount, String agreedAmountCurrency, int assignedToDriver, int truckLoadId) { this.pickupLocation = pickupLocation; this.dropoffLocation = dropoffLocation; this.loadTypeId = loadTypeId; + this.status = status; this.agreedAmount = agreedAmount; this.agreedAmountCurrency = agreedAmountCurrency; this.assignedToDriver = assignedToDriver; + this.truckLoadId = truckLoadId; } @Override @@ -26,8 +30,10 @@ public class PickupRequest { ", dropoffLocation=" + dropoffLocation + ", loadTypeId='" + loadTypeId + '\'' + ", agreedAmount=" + agreedAmount + + ", status='" + status + '\'' + ", agreedAmountCurrency='" + agreedAmountCurrency + '\'' + ", assignedToDriver=" + assignedToDriver + + ", truckLoadId=" + truckLoadId + '}'; } } diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequestForComplete.java b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequestForComplete.java new file mode 100644 index 0000000..73c6070 --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/selftrucking/models/PickupRequestForComplete.java @@ -0,0 +1,39 @@ +package com.utopiaindustries.selftrucking.models; + +public class PickupRequestForComplete { + + private int pickupLocation; + private int dropoffLocation; + private String loadTypeId; + private double agreedAmount; + private String status; + private String agreedAmountCurrency; + private int assignedToDriver; + private int truckLoadId; + + public PickupRequestForComplete(int pickupLocation, int dropoffLocation, String loadTypeId, String status, + double agreedAmount, String agreedAmountCurrency, int assignedToDriver, int truckLoadId) { + this.pickupLocation = pickupLocation; + this.dropoffLocation = dropoffLocation; + this.loadTypeId = loadTypeId; + this.status = status; + this.agreedAmount = agreedAmount; + this.agreedAmountCurrency = agreedAmountCurrency; + this.assignedToDriver = assignedToDriver; + this.truckLoadId = truckLoadId; + } + + @Override + public String toString() { + return "PickupRequest{" + + "pickupLocation=" + pickupLocation + + ", dropoffLocation=" + dropoffLocation + + ", loadTypeId='" + loadTypeId + '\'' + + ", agreedAmount=" + agreedAmount + + ", status='" + status + '\'' + + ", agreedAmountCurrency='" + agreedAmountCurrency + '\'' + + ", assignedToDriver=" + assignedToDriver + + ", truckLoadId=" + truckLoadId + + '}'; + } +} diff --git a/app/src/main/java/com/utopiaindustries/selftrucking/models/TruckLoad.java b/app/src/main/java/com/utopiaindustries/selftrucking/models/TruckLoad.java new file mode 100644 index 0000000..14108da --- /dev/null +++ b/app/src/main/java/com/utopiaindustries/selftrucking/models/TruckLoad.java @@ -0,0 +1,164 @@ + +package com.utopiaindustries.selftrucking.models; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +public class TruckLoad { + + @SerializedName("truckLoadId") + @Expose + private Integer truckLoadId; + @SerializedName("dateCreated") + @Expose + private String dateCreated; + @SerializedName("createdBy") + @Expose + private String createdBy; + @SerializedName("pickupLocation") + @Expose + private Integer pickupLocation; + @SerializedName("dropoffLocation") + @Expose + private Integer dropoffLocation; + @SerializedName("status") + @Expose + private String status; + @SerializedName("loadType") + @Expose + private String loadType; + @SerializedName("loadTypeId") + @Expose + private String loadTypeId; + @SerializedName("agreedAmount") + @Expose + private Double agreedAmount; + @SerializedName("agreedAmountCurrency") + @Expose + private String agreedAmountCurrency; + @SerializedName("assignedToDriver") + @Expose + private Integer assignedToDriver; + @SerializedName("assignedBy") + @Expose + private String assignedBy; + @SerializedName("dateAssigned") + @Expose + private String dateAssigned; + @SerializedName("marketplace") + @Expose + private String marketplace; + + public Integer getTruckLoadId() { + return truckLoadId; + } + + public void setTruckLoadId(Integer truckLoadId) { + this.truckLoadId = truckLoadId; + } + + public String getDateCreated() { + return dateCreated; + } + + public void setDateCreated(String dateCreated) { + this.dateCreated = dateCreated; + } + + public String getCreatedBy() { + return createdBy; + } + + public void setCreatedBy(String createdBy) { + this.createdBy = createdBy; + } + + public Integer getPickupLocation() { + return pickupLocation; + } + + public void setPickupLocation(Integer pickupLocation) { + this.pickupLocation = pickupLocation; + } + + public Integer getDropoffLocation() { + return dropoffLocation; + } + + public void setDropoffLocation(Integer dropoffLocation) { + this.dropoffLocation = dropoffLocation; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + public String getLoadType() { + return loadType; + } + + public void setLoadType(String loadType) { + this.loadType = loadType; + } + + public String getLoadTypeId() { + return loadTypeId; + } + + public void setLoadTypeId(String loadTypeId) { + this.loadTypeId = loadTypeId; + } + + public Double getAgreedAmount() { + return agreedAmount; + } + + public void setAgreedAmount(Double agreedAmount) { + this.agreedAmount = agreedAmount; + } + + public String getAgreedAmountCurrency() { + return agreedAmountCurrency; + } + + public void setAgreedAmountCurrency(String agreedAmountCurrency) { + this.agreedAmountCurrency = agreedAmountCurrency; + } + + public Integer getAssignedToDriver() { + return assignedToDriver; + } + + public void setAssignedToDriver(Integer assignedToDriver) { + this.assignedToDriver = assignedToDriver; + } + + public String getAssignedBy() { + return assignedBy; + } + + public void setAssignedBy(String assignedBy) { + this.assignedBy = assignedBy; + } + + public String getDateAssigned() { + return dateAssigned; + } + + public void setDateAssigned(String dateAssigned) { + this.dateAssigned = dateAssigned; + } + + public String getMarketplace() { + return marketplace; + } + + public void setMarketplace(String marketplace) { + this.marketplace = marketplace; + } + +} diff --git a/app/src/main/res/drawable/arrow_back.xml b/app/src/main/res/drawable/arrow_back.xml new file mode 100644 index 0000000..7b7c7d0 --- /dev/null +++ b/app/src/main/res/drawable/arrow_back.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_container_detail.xml b/app/src/main/res/layout/activity_container_detail.xml index 8476d85..401ac88 100644 --- a/app/src/main/res/layout/activity_container_detail.xml +++ b/app/src/main/res/layout/activity_container_detail.xml @@ -5,6 +5,7 @@ android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" + android:background="@color/white" tools:context=".Activities.dashboardScreens.ContainerDetailActivity"> - +