Commute Mobility App 
Tags: android, kotlin, mobility, carpooling
Published: 2022-02-02 16:53:47

[![IMAGE ALT TEXT HERE](https://img.youtube.com/vi/Kazi-JPonx4/0.jpg)](https://www.youtube.com/watch?v=Kazi-JPonx4)

---

Commute Sample is android application that display the list of vehicle and all the related information available in response. List of vehicles includes Taxi & Pool Vehicles from the nearby area. It also includes maps that show the points where the vehicle is available and whenever the user selects any vehicle it shows a window where all the information regarding the vehicle is displayed. Users can also get routes from Source to Destination on click of a window in Maps
 
---
## Pre-requisites
 :heavy_check_mark: Android studio installed in your system.<br/>
 :heavy_check_mark: Android Device or Emulator to run your app.<br/>
 
--- 

## Setup :hammer:

- You can clone the project using below line in your command prompt or download it directly.

```
  git clone https://github.com/dwarshb/Commute.git

```
<a href="https://github.com/dwarshb/Commute/archive/refs/heads/master.zip"><img src="https://shields.io/badge/Download-black?style=for-the-badge&logo=github" width="600" height="300"/></a>

Once the setup is done you can run the project in Android Studio.

---


## Technical Details
👉 Currently, it uses https://fake-poi-api.mytaxi.com API to get a list of vehicles. 
👉 Commute Sample App uses the API during SplashActivity and once data get fetched successfully, it passes the data to MainActivity. MainActivity includes BottomSheetNavigator with two Fragments "VehicleListFragment & DashboardFragment".
👉 VehicleListFragment is used to display the list of vehicles received in response. It arranges the list from String format using the below method which takes String as a parameter and returns a list of vehicles.

```
Utils.parseJSONToList(jsonObject: String)MutableList<Vehicle> 
```

👉 Once `VehicleListFragment` receives the list, it sets the same list to `VehicleListAdapter` which handles the view of each vehicle item in the list. `VehicleListAdapter` is a subclass of RecyclerView.Adapter which includes certain native methods that bind the data with UI. On click of each vehicle list item, a `MapsActivity` will be opened which will help to display the current position of the vehicle with its bound, and at the top window will be displayed which shows information regarding the vehicle. If users wish to get navigation from Source to Destination then, they can click on Window at the top which will redirect them to Google Maps App with Source & Destination Information.

---

## Folder Structure



### 📁 data/
- <b>📄 data/API.kt</b> -  API class is used to query the API used within App. It adds parameters such as `p1Lat={Latitude1}&p1Lon={Longitude1}&p2Lat={Latitude2}&p2Lon={Longitude}` in the API.

- <b>📄 data/Vehicle.kt</b> - Vehicle is a data class that is used to handle each item of the vehicle list.

---

### 📁 domain/
- <b>📄 domain/FetchVehicles.kt</b> - This method is used to execute the API. It passes the required data and returns the response.

---

### 📁 presentation
- <b>presentation/mainScreen/ui/vehicle/</b>
<ul>
<li><b> 📄 VehicleFragment.kt</b> - VehicleFragment is used to display a list of vehicles fetched from API. With the help of VehicleListViewModelit manages the list and helps to filter it based on its parameter. It also includes VehicleListAdapter which is used to manage each item of vehicles. On click of each item in VehicleList. It will open MapsActivity which will display the current position of the vehicle and other information.
</li>
<li><b> 📄 VehicleListViewModel.kt</b> - VehicleListViewModel is used to handle the operation which is used to manage VehicleListFragment. 
</li>
<li><b> 📄 VehicleListAdapter.kt</b> - VehicleListAdapter is an Adapter class that is used to manage the list of vehicles. It is used to manage each item of the vehicle list and perform required operations such as OnItemClick.
</li>
---

<b>📄 presentation/mainScreen/ui/FilterActionSheet.kt</b> - FilterActionSheet is subclass of BottomSheetDialogFragment which is used to display filter operations for the vehicle list shown in VehicleListFragment.
<b> 📄 presentation/mainScreen/MainActivity.kt</b> - It is Main Screen that includes BottomNavigationBar to navigate between two fragments i.eVehicleFragment& DashboardFragment 

---

- <b>presentation/mapScreen/</b>
<ul><li><b>📄 MapsActivity.kt</b> - MapsActivity is used to display various vehicles from the list to the map. It shows the vehicle icon at the designated position and displays its information. Whenever the user selects any marker from the map, then it will redirect the camera of the map to its location. Also on click of the dialog shown at the top, google will be opened with the route of that direction which includes origin & destination as well.
</li>
<li><b> 📄 MapsViewModel.kt</b> - MapsViewModel is a class that is used to handle the operation of MapsActivity
</li>
</ul>
---

- <b>presentation/splashScreen/</b>
<ul>
<li><b> 📄 SplashActivity.kt</b> - SplashActivity is the Entry Point of an application. It displays loading animation on the app icon till the data gets fetched from API successfully.
</li>
<li><b> 📄 SplashViewModel.kt</b>- SplashViewModel is used to get the trigger the fetch request from the API.
</li>
</ul>
---

<b> 📄 presentation/App.kt</b>- It is a custom application class that can be used to perform global operations in future

<b> 📄 presentation/NetworkErrorException.kt</b> - It is a subclass of the Exception class that is used to parse Network-related errors and help to bind the response with UI.

<b> 📄 presentation/State.kt</b> - It is used to handle the Loading, Error & Success State whenever API operation is performed

---

### 📁 utils
<ul>
<li><b> 📄 utils/Constants.kt</b> -  It contains the constant's value used across apps.</li>
<li><b> 📄 utils/DI.kt</b> -   It contains all the required functionality to make retrofit calls easier and more convenient to understand.</li>
<li><b> 📄 utils/Utils.kt</b> - Utils class is used to handle the independent operations. It is used accross app.</li>
</ul>

---

## Libraries

```
 //required if you want to use Espresso Test
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-intents:3.4.0'
    androidTestImplementation 'androidx.test.espresso:espresso-contrib:3.4.0'

    //UI Automator
    androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0'

    // required if you want to use Mockito for unit tests
    testImplementation 'org.mockito:mockito-core:3.7.7'

    // required if you want to use Mockito for Android tests
    androidTestImplementation 'org.mockito:mockito-android:3.7.7'


    //Co-routines Dependency
    implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2'

    //Hilt Dependencies
    implementation 'com.google.dagger:hilt-android:2.35'
    kapt 'com.google.dagger:hilt-android-compiler:2.35'

    //Retrofit Dependencies
    implementation"com.squareup.retrofit2:retrofit:2.9.0"
    implementation "com.squareup.retrofit2:converter-gson:2.9.0"

    //Google Play Services
    implementation "com.google.android.gms:play-services-places:$playServicesVersion"
    implementation "com.google.android.gms:play-services-maps:$playServicesVersion"
    implementation "com.google.maps.android:android-maps-utils:0.4+"
    implementation "com.google.android.gms:play-services-location:$playServicesVersion"

    //Dooka Documentation
    dokkaGfmPlugin("org.jetbrains.dokka:kotlin-as-java-plugin:1.6.10")
```
---

### TestCases 
The project contains required testcases that will help us to test the app thoroughly.

⛏️ **TestSuite.kt** - It is a suite of test cases files that runs multiple test cases sequentially.
⛏️ **SplashActivityTest.kt** - It is a test case file that includes tests related to SplashActivity. It checks whether apps get loaded in 5 seconds, 10 seconds, or 15 seconds.
⛏️ **MainActivityTest.kt** - It is a test case file that includes tests related to VehicleFragment which is part of MainActivity. It checks whether the data is loaded properly in the list or not. It also checks whether data is getting filtered properly based on certain filter parameters.
⛏️ **MapsActivityTest.kt** - It is a test case file that includes tests related to MapsActivity. It checks whether the operation performed on the marker are working fine.

---

## Screenshots


![Screenshot 1](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/710qk6dv7wjk6tg3x32n.PNG)

![Screenshot 2](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zxgjd9uvv3mpmimud2nn.PNG)


![Screenshot 3](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/per98cdwfo06nqtafujl.PNG)

---
## Github Repo
{% github dwarshb/Commute %}