├── nano.save
├── app
├── .gitignore
├── justgo.apk
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── drawable
│ │ │ │ ├── bus.jpg
│ │ │ │ ├── d1.png
│ │ │ │ ├── logo.png
│ │ │ │ ├── ln_logo.png
│ │ │ │ ├── spinner.gif
│ │ │ │ ├── background.jpg
│ │ │ │ ├── nav_image.jpg
│ │ │ │ ├── ic_edit_white_24dp.png
│ │ │ │ ├── ic_person_black_24dp.png
│ │ │ │ ├── ic_history_black_24dp.png
│ │ │ │ ├── ic_attach_money_black_24dp.png
│ │ │ │ ├── ic_directions_car_black_36dp.png
│ │ │ │ ├── ic_shopping_cart_black_24dp.png
│ │ │ │ ├── button_green_border.xml
│ │ │ │ ├── button_grey_border.xml
│ │ │ │ ├── side_nav_bar.xml
│ │ │ │ ├── ic_star_black.xml
│ │ │ │ ├── ic_person_name.xml
│ │ │ │ ├── ic_edit_profile.xml
│ │ │ │ ├── ic_event_seat_black_24dp.xml
│ │ │ │ ├── ic_email_black.xml
│ │ │ │ ├── ic_wallet.xml
│ │ │ │ ├── ic_location_on_black.xml
│ │ │ │ ├── input_box.xml
│ │ │ │ └── ic_phone_black.xml
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ └── ic_launcher_round.png
│ │ │ ├── layout
│ │ │ │ ├── item_divider.xml
│ │ │ │ ├── content_book.xml
│ │ │ │ ├── fragment_history.xml
│ │ │ │ ├── content_main.xml
│ │ │ │ ├── activity_main.xml
│ │ │ │ ├── activity_book.xml
│ │ │ │ ├── app_bar_main.xml
│ │ │ │ ├── recyclerview_item.xml
│ │ │ │ ├── splash_screen.xml
│ │ │ │ ├── nav_header_main.xml
│ │ │ │ ├── fragment_book.xml
│ │ │ │ ├── info_dialog.xml
│ │ │ │ ├── error_dialog.xml
│ │ │ │ ├── activity_order_details.xml
│ │ │ │ ├── activity_confirm_order.xml
│ │ │ │ ├── activity_profile.xml
│ │ │ │ ├── book_row.xml
│ │ │ │ ├── order_input_dialog.xml
│ │ │ │ ├── book_row2.xml
│ │ │ │ ├── fragment_select_route.xml
│ │ │ │ ├── activity_sign_in.xml
│ │ │ │ ├── orders_row.xml
│ │ │ │ └── activity_signup.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── drawables.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── styles.xml
│ │ │ │ └── strings.xml
│ │ │ └── menu
│ │ │ │ ├── main.xml
│ │ │ │ ├── menu_book.xml
│ │ │ │ ├── menu_confirm_order.xml
│ │ │ │ └── activity_main_drawer.xml
│ │ ├── java
│ │ │ └── com
│ │ │ │ └── codephillip
│ │ │ │ └── app
│ │ │ │ └── busticket
│ │ │ │ ├── provider
│ │ │ │ ├── base
│ │ │ │ │ ├── BaseModel.java
│ │ │ │ │ ├── AbstractContentValues.java
│ │ │ │ │ └── AbstractCursor.java
│ │ │ │ ├── locations
│ │ │ │ │ ├── LocationsModel.java
│ │ │ │ │ ├── LocationsCursor.java
│ │ │ │ │ ├── LocationsColumns.java
│ │ │ │ │ ├── LocationsContentValues.java
│ │ │ │ │ └── LocationsSelection.java
│ │ │ │ ├── orders
│ │ │ │ │ ├── OrdersModel.java
│ │ │ │ │ ├── OrdersColumns.java
│ │ │ │ │ ├── OrdersCursor.java
│ │ │ │ │ └── OrdersContentValues.java
│ │ │ │ ├── BusTicketSQLiteOpenHelperCallbacks.java
│ │ │ │ ├── routes
│ │ │ │ │ ├── RoutesModel.java
│ │ │ │ │ ├── RoutesColumns.java
│ │ │ │ │ ├── RoutesCursor.java
│ │ │ │ │ └── RoutesContentValues.java
│ │ │ │ ├── BusTicketSQLiteOpenHelper.java
│ │ │ │ └── BusTicketProvider.java
│ │ │ │ ├── Constants.java
│ │ │ │ ├── mymodels
│ │ │ │ ├── Orders.java
│ │ │ │ ├── routeobject
│ │ │ │ │ ├── Routes.java
│ │ │ │ │ ├── Bus.java
│ │ │ │ │ ├── Route.java
│ │ │ │ │ └── BusCompany.java
│ │ │ │ ├── Customers.java
│ │ │ │ ├── Locations.java
│ │ │ │ ├── Location.java
│ │ │ │ ├── Order.java
│ │ │ │ └── Customer.java
│ │ │ │ ├── retrofit
│ │ │ │ ├── ApiClient.java
│ │ │ │ └── ApiInterface.java
│ │ │ │ ├── BookActivity.java
│ │ │ │ ├── ProfileFragment.java
│ │ │ │ ├── broadcasts
│ │ │ │ └── MyReceiver.java
│ │ │ │ ├── SplashActivity.java
│ │ │ │ ├── OrdersFragment.java
│ │ │ │ ├── HistoryFragment.java
│ │ │ │ ├── adapters
│ │ │ │ ├── BookAdapter.java
│ │ │ │ ├── OrdersAdapter.java
│ │ │ │ └── SeatGridAdapter.java
│ │ │ │ ├── BookFragment.java
│ │ │ │ ├── MainActivity.java
│ │ │ │ ├── SelectRouteFragment.java
│ │ │ │ └── OrderDetailsActivity.java
│ │ └── AndroidManifest.xml
│ ├── androidTest
│ │ └── java
│ │ │ └── com
│ │ │ └── codephillip
│ │ │ └── app
│ │ │ └── busticket
│ │ │ └── ExampleInstrumentedTest.java
│ └── test
│ │ └── java
│ │ └── com
│ │ └── codephillip
│ │ └── app
│ │ └── busticket
│ │ ├── RegexValidatorTest.java
│ │ └── GeneralUnitTest.java
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── device-2017-05-11-201458.png
├── device-2017-05-11-201543.png
├── .idea
├── copyright
│ └── profiles_settings.xml
├── vcs.xml
├── modules.xml
├── runConfigurations.xml
├── gradle.xml
├── compiler.xml
└── misc.xml
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .gitignore
├── README.md
├── gradle.properties
├── gradlew.bat
└── gradlew
/nano.save:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/app/justgo.apk:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/justgo.apk
--------------------------------------------------------------------------------
/device-2017-05-11-201458.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/device-2017-05-11-201458.png
--------------------------------------------------------------------------------
/device-2017-05-11-201543.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/device-2017-05-11-201543.png
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/bus.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/bus.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/d1.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/d1.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/drawable/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ln_logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ln_logo.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/spinner.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/spinner.gif
--------------------------------------------------------------------------------
/app/src/main/res/drawable/background.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/background.jpg
--------------------------------------------------------------------------------
/app/src/main/res/drawable/nav_image.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/nav_image.jpg
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_edit_white_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_edit_white_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_person_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_person_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_history_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_history_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/base/BaseModel.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.base;
2 |
3 | public interface BaseModel {
4 | }
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_attach_money_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_attach_money_black_24dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_directions_car_black_36dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_directions_car_black_36dp.png
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_shopping_cart_black_24dp.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codephillip/Bus-Ticket-app/HEAD/app/src/main/res/drawable/ic_shopping_cart_black_24dp.png
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea/workspace.xml
5 | /.idea/libraries
6 | .DS_Store
7 | /build
8 | /captures
9 | .externalNativeBuild
10 | *.idea/
11 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/Constants.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | /**
4 | * Created by codephillip on 19/10/17.
5 | */
6 |
7 | public class Constants {
8 | public static final String HAS_BOOKED = "has_booked";
9 |
10 | }
11 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Oct 28 02:19:04 EAT 2017
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Bus-Ticket-app
2 | Android app that allows users to book bus tickets
3 |
4 | Libraries
5 |
6 | Content provider generator
7 | https://github.com/BoD/android-contentprovider-generator
8 |
9 | POJO site
10 | Get the json response from server and create POJO files
11 | http://www.jsonschema2pojo.org/
12 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_green_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/button_grey_border.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | -
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/side_nav_bar.xml:
--------------------------------------------------------------------------------
1 |
3 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/item_divider.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #009688
4 | #00796B
5 | #1DE9B6
6 | #848383
7 | #F44336
8 | #e4e4e4
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_star_black.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_person_name.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_edit_profile.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_event_seat_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_book.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_email_black.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/menu_confirm_order.xml:
--------------------------------------------------------------------------------
1 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_wallet.xml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_book.xml:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_location_on_black.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/input_box.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | -
8 |
9 |
10 |
11 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Orders.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import java.util.List;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | public class Orders {
9 |
10 | @SerializedName("orders")
11 | @Expose
12 | private List orders = null;
13 |
14 | public List getOrders() {
15 | return orders;
16 | }
17 |
18 | public void setOrders(List orders) {
19 | this.orders = orders;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/routeobject/Routes.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels.routeobject;
3 |
4 | import java.util.List;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | public class Routes {
9 |
10 | @SerializedName("routes")
11 | @Expose
12 | private List routes = null;
13 |
14 | public List getRoutes() {
15 | return routes;
16 | }
17 |
18 | public void setRoutes(List routes) {
19 | this.routes = routes;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_phone_black.xml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/runConfigurations.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
11 |
12 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Customers.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import java.util.List;
5 | import com.google.gson.annotations.Expose;
6 | import com.google.gson.annotations.SerializedName;
7 |
8 | public class Customers {
9 |
10 | @SerializedName("customers")
11 | @Expose
12 | private List customers = null;
13 |
14 | public List getCustomers() {
15 | return customers;
16 | }
17 |
18 | public void setCustomers(List customers) {
19 | this.customers = customers;
20 | }
21 |
22 | }
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_history.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
13 |
14 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Locations.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | import java.util.List;
8 |
9 | public class Locations {
10 |
11 | @SerializedName("locations")
12 | @Expose
13 | private List locations = null;
14 |
15 | public List getLocations() {
16 | return locations;
17 | }
18 |
19 | public void setLocations(List locations) {
20 | this.locations = locations;
21 | }
22 |
23 | }
24 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/retrofit/ApiClient.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.retrofit;
2 |
3 | import retrofit2.Retrofit;
4 | import retrofit2.converter.gson.GsonConverterFactory;
5 |
6 |
7 | public class ApiClient {
8 | private static Retrofit retrofit = null;
9 |
10 | public static Retrofit getClient(String url) {
11 | if (retrofit == null) {
12 | retrofit = new Retrofit.Builder()
13 | .baseUrl(url)
14 | .addConverterFactory(GsonConverterFactory.create())
15 | .build();
16 | }
17 | return retrofit;
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/drawables.xml:
--------------------------------------------------------------------------------
1 |
2 | - @android:drawable/ic_menu_camera
3 | - @android:drawable/ic_menu_gallery
4 | - @android:drawable/ic_menu_slideshow
5 | - @android:drawable/ic_menu_manage
6 | - @android:drawable/ic_menu_share
7 | - @android:drawable/ic_menu_send
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/BookActivity.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.v7.app.AppCompatActivity;
5 | import android.support.v7.widget.Toolbar;
6 |
7 | public class BookActivity extends AppCompatActivity {
8 |
9 | @Override
10 | protected void onCreate(Bundle savedInstanceState) {
11 | super.onCreate(savedInstanceState);
12 | setContentView(R.layout.activity_book);
13 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
14 | setSupportActionBar(toolbar);
15 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/.idea/gradle.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/content_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/.idea/compiler.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 |
3 | # IDE (e.g. Android Studio) users:
4 | # Gradle settings configured through the IDE *will override*
5 | # any settings specified in this file.
6 |
7 | # For more details on how to configure your build environment visit
8 | # http://www.gradle.org/docs/current/userguide/build_environment.html
9 |
10 | # Specifies the JVM arguments used for the daemon process.
11 | # The setting is particularly useful for tweaking memory settings.
12 | org.gradle.jvmargs=-Xmx1536m
13 |
14 | # When configured, Gradle will run in incubating parallel mode.
15 | # This option should only be used with decoupled projects. More details, visit
16 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17 | # org.gradle.parallel=true
18 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/ProfileFragment.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.view.LayoutInflater;
6 | import android.view.View;
7 | import android.view.ViewGroup;
8 |
9 | public class ProfileFragment extends Fragment {
10 |
11 | public ProfileFragment() {
12 | }
13 |
14 | public static ProfileFragment newInstance() {
15 | return new ProfileFragment();
16 | }
17 |
18 | @Override
19 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
20 | Bundle savedInstanceState) {
21 | View rootView = inflater.inflate(R.layout.activity_profile, container, false);
22 |
23 | return rootView;
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/broadcasts/MyReceiver.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.broadcasts;
2 |
3 | import android.content.BroadcastReceiver;
4 | import android.content.Context;
5 | import android.content.Intent;
6 | import android.util.Log;
7 |
8 | import com.codephillip.app.busticket.MainActivity;
9 |
10 | public class MyReceiver extends BroadcastReceiver {
11 | private final String TAG = MyReceiver.class.getSimpleName();
12 |
13 | @Override
14 | public void onReceive(Context context, Intent intent) {
15 | Log.d(TAG, "onReceive: STARTED");
16 | // broadcast received, indicating that the SetUpService has finished
17 | Intent mainIntent = new Intent(context, MainActivity.class);
18 | mainIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
19 | context.startActivity(mainIntent);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 16dp
4 | 16dp
5 | 16dp
6 | 160dp
7 | 16dp
8 | 8dp
9 | 180dp
10 | 16dp
11 | 18sp
12 | 8dp
13 | 5dp
14 | 10dp
15 | 40dp
16 | 30dp
17 | 20dp
18 |
19 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/SplashActivity.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.content.Intent;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.widget.Toast;
7 |
8 | public class SplashActivity extends AppCompatActivity {
9 |
10 | @Override
11 | protected void onCreate(Bundle savedInstanceState) {
12 | super.onCreate(savedInstanceState);
13 | setContentView(R.layout.splash_screen);
14 |
15 | if (Utils.isConnectedToInternet(SplashActivity.this))
16 | startService(new Intent(getApplicationContext(), SetUpService.class));
17 | else
18 | Toast.makeText(this, "Please check your Internet connection", Toast.LENGTH_SHORT).show();
19 | }
20 |
21 | @Override
22 | protected void onPause() {
23 | super.onPause();
24 | finish();
25 | }
26 | }
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_main_drawer.xml:
--------------------------------------------------------------------------------
1 |
2 |
23 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/locations/LocationsModel.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.locations;
2 |
3 | import com.codephillip.app.busticket.provider.base.BaseModel;
4 |
5 | import java.util.Date;
6 |
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 |
10 | /**
11 | * Data model for the {@code locations} table.
12 | */
13 | public interface LocationsModel extends BaseModel {
14 |
15 | /**
16 | * Get the {@code name} value.
17 | * Can be {@code null}.
18 | */
19 | @Nullable
20 | String getName();
21 |
22 | /**
23 | * Get the {@code latitude} value.
24 | * Can be {@code null}.
25 | */
26 | @Nullable
27 | Double getLatitude();
28 |
29 | /**
30 | * Get the {@code longitude} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | Double getLongitude();
35 | }
36 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/com/codephillip/app/busticket/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 |
7 | import org.junit.Test;
8 | import org.junit.runner.RunWith;
9 |
10 | import static org.junit.Assert.*;
11 |
12 | /**
13 | * Instrumentation test, which will execute on an Android device.
14 | *
15 | * @see Testing documentation
16 | */
17 | @RunWith(AndroidJUnit4.class)
18 | public class ExampleInstrumentedTest {
19 | @Test
20 | public void useAppContext() throws Exception {
21 | // Context of the app under test.
22 | Context appContext = InstrumentationRegistry.getTargetContext();
23 |
24 | assertEquals("com.codephillip.app.busticket", appContext.getPackageName());
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/app/src/test/java/com/codephillip/app/busticket/RegexValidatorTest.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 |
8 | import static org.junit.Assert.*;
9 |
10 | /**
11 | * Created by codephillip on 23/08/17.
12 | */
13 |
14 | public class RegexValidatorTest {
15 |
16 | @Test
17 | public void test_validators() throws Exception {
18 | assertEquals(5, 2 + 3);
19 | assertTrue(Utils.validateData("0756878567", Utils.PHONE_PATTERN));
20 | assertTrue(Utils.validateData("0786878567", Utils.PHONE_PATTERN));
21 | assertTrue(Utils.validateData("0776878567", Utils.PHONE_PATTERN));
22 | assertTrue(Utils.validateData("0706878567", Utils.PHONE_PATTERN));
23 | assertTrue(Utils.validateData("pas0*YhuUj*#e*", Utils.PASSWORD_PATTERN));
24 | assertTrue(Utils.validateData("1234", Utils.MM_CODE_PATTERN));
25 | assertTrue(Utils.validateData("6775", Utils.MM_CODE_PATTERN));
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/app/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # By default, the flags in this file are appended to flags specified
3 | # in /home/codephillip/Android/Sdk/tools/proguard/proguard-android.txt
4 | # You can edit the include path and order by changing the proguardFiles
5 | # directive in build.gradle.
6 | #
7 | # For more details, see
8 | # http://developer.android.com/guide/developing/tools/proguard.html
9 |
10 | # Add any project specific keep options here:
11 |
12 | # If your project uses WebView with JS, uncomment the following
13 | # and specify the fully qualified class name to the JavaScript interface
14 | # class:
15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16 | # public *;
17 | #}
18 |
19 | # Uncomment this to preserve the line number information for
20 | # debugging stack traces.
21 | #-keepattributes SourceFile,LineNumberTable
22 |
23 | # If you keep the line number information, uncomment this to
24 | # hide the original source file name.
25 | #-renamesourcefileattribute SourceFile
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
15 |
16 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_book.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/app_bar_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/recyclerview_item.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
13 |
14 |
20 |
21 |
22 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/retrofit/ApiInterface.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.retrofit;
2 |
3 | import com.codephillip.app.busticket.mymodels.Customer;
4 | import com.codephillip.app.busticket.mymodels.Customers;
5 | import com.codephillip.app.busticket.mymodels.Locations;
6 | import com.codephillip.app.busticket.mymodels.Order;
7 | import com.codephillip.app.busticket.mymodels.Orders;
8 | import com.codephillip.app.busticket.mymodels.routeobject.Routes;
9 |
10 | import retrofit2.Call;
11 | import retrofit2.http.Body;
12 | import retrofit2.http.GET;
13 | import retrofit2.http.POST;
14 | import retrofit2.http.PUT;
15 |
16 |
17 | public interface ApiInterface {
18 |
19 | @POST("/api/v1/customers")
20 | Call createCustomer(@Body Customer customer);
21 |
22 | @PUT("/api/v1/customers")
23 | Call signInCustomer(@Body Customer customer);
24 |
25 | @GET("/api/v1/routes?format=json")
26 | Call allRoutes();
27 |
28 | @GET("/api/v1/orders?format=json")
29 | Call allOrders();
30 |
31 | @GET("/api/v1/locations?format=json")
32 | Call allLocations();
33 |
34 | @POST("/api/v1/orders")
35 | Call createOrder(@Body Order order);
36 |
37 |
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Location.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Location {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("name")
13 | @Expose
14 | private String name;
15 | @SerializedName("longitude")
16 | @Expose
17 | private double longitude;
18 | @SerializedName("latitude")
19 | @Expose
20 | private double latitude;
21 |
22 | public Integer getId() {
23 | return id;
24 | }
25 |
26 | public void setId(Integer id) {
27 | this.id = id;
28 | }
29 |
30 | public String getName() {
31 | return name;
32 | }
33 |
34 | public void setName(String name) {
35 | this.name = name;
36 | }
37 |
38 | public double getLongitude() {
39 | return longitude;
40 | }
41 |
42 | public void setLongitude(double longitude) {
43 | this.longitude = longitude;
44 | }
45 |
46 | public double getLatitude() {
47 | return latitude;
48 | }
49 |
50 | public void setLatitude(double latitude) {
51 | this.latitude = latitude;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/splash_screen.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
11 |
12 |
17 |
18 |
24 |
25 |
26 |
27 |
28 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/base/AbstractContentValues.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.base;
2 |
3 | import android.content.Context;
4 | import android.content.ContentResolver;
5 | import android.content.ContentValues;
6 | import android.net.Uri;
7 |
8 | public abstract class AbstractContentValues {
9 | protected final ContentValues mContentValues = new ContentValues();
10 |
11 | /**
12 | * Returns the {@code uri} argument to pass to the {@code ContentResolver} methods.
13 | */
14 | public abstract Uri uri();
15 |
16 | /**
17 | * Returns the {@code ContentValues} wrapped by this object.
18 | */
19 | public ContentValues values() {
20 | return mContentValues;
21 | }
22 |
23 | /**
24 | * Inserts a row into a table using the values stored by this object.
25 | *
26 | * @param contentResolver The content resolver to use.
27 | */
28 | public Uri insert(ContentResolver contentResolver) {
29 | return contentResolver.insert(uri(), values());
30 | }
31 |
32 | /**
33 | * Inserts a row into a table using the values stored by this object.
34 | *
35 | * @param context The context to use.
36 | */
37 | public Uri insert(Context context) {
38 | return context.getContentResolver().insert(uri(), values());
39 | }
40 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/orders/OrdersModel.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.orders;
2 |
3 | import com.codephillip.app.busticket.provider.base.BaseModel;
4 |
5 | import java.util.Date;
6 |
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 |
10 | /**
11 | * Data model for the {@code orders} table.
12 | */
13 | public interface OrdersModel extends BaseModel {
14 |
15 | /**
16 | * Get the {@code code} value.
17 | * Can be {@code null}.
18 | */
19 | @Nullable
20 | String getCode();
21 |
22 | /**
23 | * Get the {@code valid} value.
24 | * Can be {@code null}.
25 | */
26 | @Nullable
27 | Boolean getValid();
28 |
29 | /**
30 | * Get the {@code datecreated} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | Date getDatecreated();
35 |
36 | /**
37 | * Get the {@code date} value.
38 | * Can be {@code null}.
39 | */
40 | @Nullable
41 | Date getDate();
42 |
43 | /**
44 | * Get the {@code customer} value.
45 | * Can be {@code null}.
46 | */
47 | @Nullable
48 | String getCustomer();
49 |
50 | /**
51 | * Get the {@code route} value.
52 | * Can be {@code null}.
53 | */
54 | @Nullable
55 | String getRoute();
56 | }
57 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/nav_header_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
21 |
22 |
30 |
31 |
32 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
17 |
18 |
24 |
25 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_book.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
14 |
15 |
22 |
23 |
30 |
31 |
32 |
33 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/routeobject/Bus.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels.routeobject;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Bus {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("number_plate")
13 | @Expose
14 | private String numberPlate;
15 | @SerializedName("bus_company")
16 | @Expose
17 | private BusCompany busCompany;
18 | @SerializedName("seats")
19 | @Expose
20 | private Integer seats;
21 | @SerializedName("model")
22 | @Expose
23 | private String model;
24 |
25 | public Integer getId() {
26 | return id;
27 | }
28 |
29 | public void setId(Integer id) {
30 | this.id = id;
31 | }
32 |
33 | public String getNumberPlate() {
34 | return numberPlate;
35 | }
36 |
37 | public void setNumberPlate(String numberPlate) {
38 | this.numberPlate = numberPlate;
39 | }
40 |
41 | public BusCompany getBusCompany() {
42 | return busCompany;
43 | }
44 |
45 | public void setBusCompany(BusCompany busCompany) {
46 | this.busCompany = busCompany;
47 | }
48 |
49 | public Integer getSeats() {
50 | return seats;
51 | }
52 |
53 | public void setSeats(Integer seats) {
54 | this.seats = seats;
55 | }
56 |
57 | public String getModel() {
58 | return model;
59 | }
60 |
61 | public void setModel(String model) {
62 | this.model = model;
63 | }
64 |
65 | }
66 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/BusTicketSQLiteOpenHelperCallbacks.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider;
2 |
3 | import android.content.Context;
4 | import android.database.sqlite.SQLiteDatabase;
5 |
6 | import android.util.Log;
7 |
8 | import com.codephillip.app.busticket.BuildConfig;
9 |
10 | /**
11 | * Implement your custom database creation or upgrade code here.
12 | *
13 | * This file will not be overwritten if you re-run the content provider generator.
14 | */
15 | public class BusTicketSQLiteOpenHelperCallbacks {
16 | private static final String TAG = BusTicketSQLiteOpenHelperCallbacks.class.getSimpleName();
17 |
18 | public void onOpen(final Context context, final SQLiteDatabase db) {
19 | if (BuildConfig.DEBUG) Log.d(TAG, "onOpen");
20 | // Insert your db open code here.
21 | }
22 |
23 | public void onPreCreate(final Context context, final SQLiteDatabase db) {
24 | if (BuildConfig.DEBUG) Log.d(TAG, "onPreCreate");
25 | // Insert your db creation code here. This is called before your tables are created.
26 | }
27 |
28 | public void onPostCreate(final Context context, final SQLiteDatabase db) {
29 | if (BuildConfig.DEBUG) Log.d(TAG, "onPostCreate");
30 | // Insert your db creation code here. This is called after your tables are created.
31 | }
32 |
33 | public void onUpgrade(final Context context, final SQLiteDatabase db, final int oldVersion, final int newVersion) {
34 | if (BuildConfig.DEBUG) Log.d(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion);
35 | // Insert your upgrading code here.
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 26
5 | buildToolsVersion '26.0.2'
6 | defaultConfig {
7 | applicationId "com.codephillip.app.busticket"
8 | minSdkVersion 14
9 | targetSdkVersion 26
10 | vectorDrawables.useSupportLibrary = true
11 | versionCode 1
12 | versionName "1.0"
13 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
14 | }
15 | buildTypes {
16 | release {
17 | minifyEnabled false
18 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19 | }
20 | }
21 | }
22 |
23 | dependencies {
24 | compile fileTree(dir: 'libs', include: ['*.jar'])
25 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
26 | exclude group: 'com.android.support', module: 'support-annotations'
27 | })
28 | compile 'com.android.support:appcompat-v7:26.1.0'
29 | compile 'com.android.support:design:26.1.0'
30 | compile 'com.android.support:recyclerview-v7:26.1.0'
31 | compile 'com.android.support:cardview-v7:26.1.0'
32 | compile 'com.google.code.gson:gson:2.7'
33 | compile 'com.squareup.retrofit2:retrofit:2.0.2'
34 | compile 'com.squareup.retrofit2:converter-gson:2.0.2'
35 | compile 'com.squareup.picasso:picasso:2.5.2'
36 | compile 'com.android.support.constraint:constraint-layout:1.0.2'
37 | compile 'com.android.support:support-v4:26.1.0'
38 | compile 'pl.droidsonroids.gif:android-gif-drawable:1.2.8'
39 | compile 'com.jaredrummler:material-spinner:1.2.1'
40 | testCompile 'junit:junit:4.12'
41 | }
42 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/OrdersFragment.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.codephillip.app.busticket.adapters.OrdersAdapter;
12 | import com.codephillip.app.busticket.provider.orders.OrdersCursor;
13 | import com.codephillip.app.busticket.provider.orders.OrdersSelection;
14 |
15 | public class OrdersFragment extends Fragment {
16 |
17 | RecyclerView recyclerView;
18 | public OrdersAdapter adapter;
19 |
20 | public OrdersFragment() {
21 | }
22 |
23 | public static OrdersFragment newInstance() {
24 | return new OrdersFragment();
25 | }
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | View rootView = inflater.inflate(R.layout.fragment_history, container, false);
31 | Utils.HISTROY_FRAG_ACTIVE = false;
32 | recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler);
33 | recyclerView.setHasFixedSize(true);
34 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
35 | adapter = new OrdersAdapter(getContext(), queryOrdersTable());
36 | recyclerView.setAdapter(adapter);
37 | return rootView;
38 | }
39 |
40 | private OrdersCursor queryOrdersTable() {
41 | return new OrdersSelection().valid(true).orderById(true).query(getContext().getContentResolver());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/HistoryFragment.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 |
11 | import com.codephillip.app.busticket.adapters.OrdersAdapter;
12 | import com.codephillip.app.busticket.provider.orders.OrdersCursor;
13 | import com.codephillip.app.busticket.provider.orders.OrdersSelection;
14 |
15 | public class HistoryFragment extends Fragment {
16 |
17 | RecyclerView recyclerView;
18 | public OrdersAdapter adapter;
19 |
20 | public HistoryFragment() {
21 | }
22 |
23 | public static HistoryFragment newInstance() {
24 | return new HistoryFragment();
25 | }
26 |
27 | @Override
28 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
29 | Bundle savedInstanceState) {
30 | View rootView = inflater.inflate(R.layout.fragment_history, container, false);
31 | Utils.HISTROY_FRAG_ACTIVE = true;
32 | recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler);
33 | recyclerView.setHasFixedSize(true);
34 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
35 | adapter = new OrdersAdapter(getContext(), queryOrdersTable());
36 | recyclerView.setAdapter(adapter);
37 | return rootView;
38 | }
39 |
40 | private OrdersCursor queryOrdersTable() {
41 | return new OrdersSelection().valid(false).orderById(true).query(getContext().getContentResolver());
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/locations/LocationsCursor.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.locations;
2 |
3 | import java.util.Date;
4 |
5 | import android.database.Cursor;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.codephillip.app.busticket.provider.base.AbstractCursor;
10 |
11 | /**
12 | * Cursor wrapper for the {@code locations} table.
13 | */
14 | public class LocationsCursor extends AbstractCursor implements LocationsModel {
15 | public LocationsCursor(Cursor cursor) {
16 | super(cursor);
17 | }
18 |
19 | /**
20 | * Primary key.
21 | */
22 | public long getId() {
23 | Long res = getLongOrNull(LocationsColumns._ID);
24 | if (res == null)
25 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition");
26 | return res;
27 | }
28 |
29 | /**
30 | * Get the {@code name} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | public String getName() {
35 | String res = getStringOrNull(LocationsColumns.NAME);
36 | return res;
37 | }
38 |
39 | /**
40 | * Get the {@code latitude} value.
41 | * Can be {@code null}.
42 | */
43 | @Nullable
44 | public Double getLatitude() {
45 | Double res = getDoubleOrNull(LocationsColumns.LATITUDE);
46 | return res;
47 | }
48 |
49 | /**
50 | * Get the {@code longitude} value.
51 | * Can be {@code null}.
52 | */
53 | @Nullable
54 | public Double getLongitude() {
55 | Double res = getDoubleOrNull(LocationsColumns.LONGITUDE);
56 | return res;
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/routes/RoutesModel.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.routes;
2 |
3 | import com.codephillip.app.busticket.provider.base.BaseModel;
4 |
5 | import java.util.Date;
6 |
7 | import android.support.annotation.NonNull;
8 | import android.support.annotation.Nullable;
9 |
10 | /**
11 | * Data model for the {@code routes} table.
12 | */
13 | public interface RoutesModel extends BaseModel {
14 |
15 | /**
16 | * Get the {@code routeid} value.
17 | * Can be {@code null}.
18 | */
19 | @Nullable
20 | Integer getRouteid();
21 |
22 | /**
23 | * Get the {@code code} value.
24 | * Can be {@code null}.
25 | */
26 | @Nullable
27 | Integer getCode();
28 |
29 | /**
30 | * Get the {@code source} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | String getSource();
35 |
36 | /**
37 | * Get the {@code destination} value.
38 | * Can be {@code null}.
39 | */
40 | @Nullable
41 | String getDestination();
42 |
43 | /**
44 | * Get the {@code buscompanyname} value.
45 | * Can be {@code null}.
46 | */
47 | @Nullable
48 | String getBuscompanyname();
49 |
50 | /**
51 | * Get the {@code buscompanyimage} value.
52 | * Can be {@code null}.
53 | */
54 | @Nullable
55 | String getBuscompanyimage();
56 |
57 | /**
58 | * Get the {@code price} value.
59 | * Can be {@code null}.
60 | */
61 | @Nullable
62 | Integer getPrice();
63 |
64 | /**
65 | * Get the {@code arrival} value.
66 | * Can be {@code null}.
67 | */
68 | @Nullable
69 | Date getArrival();
70 |
71 | /**
72 | * Get the {@code departure} value.
73 | * Can be {@code null}.
74 | */
75 | @Nullable
76 | Date getDeparture();
77 | }
78 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/locations/LocationsColumns.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.locations;
2 |
3 | import android.net.Uri;
4 | import android.provider.BaseColumns;
5 |
6 | import com.codephillip.app.busticket.provider.BusTicketProvider;
7 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
8 | import com.codephillip.app.busticket.provider.orders.OrdersColumns;
9 | import com.codephillip.app.busticket.provider.routes.RoutesColumns;
10 |
11 | /**
12 | * Columns for the {@code locations} table.
13 | */
14 | public class LocationsColumns implements BaseColumns {
15 | public static final String TABLE_NAME = "locations";
16 | public static final Uri CONTENT_URI = Uri.parse(BusTicketProvider.CONTENT_URI_BASE + "/" + TABLE_NAME);
17 |
18 | /**
19 | * Primary key.
20 | */
21 | public static final String _ID = BaseColumns._ID;
22 |
23 | public static final String NAME = "name";
24 |
25 | public static final String LATITUDE = "latitude";
26 |
27 | public static final String LONGITUDE = "longitude";
28 |
29 |
30 | public static final String DEFAULT_ORDER = TABLE_NAME + "." +_ID;
31 |
32 | // @formatter:off
33 | public static final String[] ALL_COLUMNS = new String[] {
34 | _ID,
35 | NAME,
36 | LATITUDE,
37 | LONGITUDE
38 | };
39 | // @formatter:on
40 |
41 | public static boolean hasColumns(String[] projection) {
42 | if (projection == null) return true;
43 | for (String c : projection) {
44 | if (c.equals(NAME) || c.contains("." + NAME)) return true;
45 | if (c.equals(LATITUDE) || c.contains("." + LATITUDE)) return true;
46 | if (c.equals(LONGITUDE) || c.contains("." + LONGITUDE)) return true;
47 | }
48 | return false;
49 | }
50 |
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Just Go
3 |
4 | Open navigation drawer
5 | Close navigation drawer
6 |
7 | Settings
8 | Filter
9 | Confirm order
10 |
11 | Email
12 | Password (optional)
13 | Sign in or register
14 | Sign in
15 | This phone number is invalid
16 | This password is too short
17 | This password is incorrect
18 | Unmatched Passwords
19 | This field is required
20 | Phone Number
21 | User Name
22 | Address(location)
23 | Password
24 | Sign In
25 | Register
26 | Password(confirm)
27 | Unmatched Password
28 | Sign Up
29 | Sign In
30 | Choose
31 | Error
32 | RECEIPT
33 | CANCEL
34 | PROCEED
35 |
36 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/info_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
30 |
31 |
37 |
38 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/error_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
30 |
31 |
38 |
39 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_order_details.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
23 |
24 |
31 |
32 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_confirm_order.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
16 |
17 |
24 |
25 |
32 |
33 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Order.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Order {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("code")
13 | @Expose
14 | private Integer code;
15 | @SerializedName("valid")
16 | @Expose
17 | private Boolean valid;
18 | @SerializedName("date")
19 | @Expose
20 | private String date;
21 | @SerializedName("customer")
22 | @Expose
23 | private Integer customer;
24 | @SerializedName("route")
25 | @Expose
26 | private Integer route;
27 |
28 | public Order(Integer customerId, Integer routeId, boolean valid, String date) {
29 | this.customer = customerId;
30 | this.route = routeId;
31 | this.valid = true;
32 | this.date = date;
33 | }
34 |
35 | public Order(Integer customerId, Integer routeId, boolean valid, String date, int order_code) {
36 | this.customer = customerId;
37 | this.route = routeId;
38 | this.valid = true;
39 | this.date = date;
40 | this.code = order_code;
41 | }
42 | public Integer getId() {
43 | return id;
44 | }
45 |
46 | public void setId(Integer id) {
47 | this.id = id;
48 | }
49 |
50 | public Integer getCode() {
51 | return code;
52 | }
53 |
54 | public void setCode(Integer code) {
55 | this.code = code;
56 | }
57 |
58 | public Boolean getValid() {
59 | return valid;
60 | }
61 |
62 | public void setValid(Boolean valid) {
63 | this.valid = valid;
64 | }
65 |
66 | public String getDate() {
67 | return date;
68 | }
69 |
70 | public void setDate(String date) {
71 | this.date = date;
72 | }
73 |
74 | public Integer getCustomer() {
75 | return customer;
76 | }
77 |
78 | public void setCustomer(Integer customer) {
79 | this.customer = customer;
80 | }
81 |
82 | public Integer getRoute() {
83 | return route;
84 | }
85 |
86 | public void setRoute(Integer route) {
87 | this.route = route;
88 | }
89 |
90 | }
91 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/orders/OrdersColumns.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.orders;
2 |
3 | import android.net.Uri;
4 | import android.provider.BaseColumns;
5 |
6 | import com.codephillip.app.busticket.provider.BusTicketProvider;
7 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
8 | import com.codephillip.app.busticket.provider.orders.OrdersColumns;
9 | import com.codephillip.app.busticket.provider.routes.RoutesColumns;
10 |
11 | /**
12 | * Columns for the {@code orders} table.
13 | */
14 | public class OrdersColumns implements BaseColumns {
15 | public static final String TABLE_NAME = "orders";
16 | public static final Uri CONTENT_URI = Uri.parse(BusTicketProvider.CONTENT_URI_BASE + "/" + TABLE_NAME);
17 |
18 | /**
19 | * Primary key.
20 | */
21 | public static final String _ID = BaseColumns._ID;
22 |
23 | public static final String CODE = "Code";
24 |
25 | public static final String VALID = "Valid";
26 |
27 | public static final String DATECREATED = "DateCreated";
28 |
29 | public static final String DATE = "Date";
30 |
31 | public static final String CUSTOMER = "Customer";
32 |
33 | public static final String ROUTE = "Route";
34 |
35 |
36 | public static final String DEFAULT_ORDER = TABLE_NAME + "." +_ID;
37 |
38 | // @formatter:off
39 | public static final String[] ALL_COLUMNS = new String[] {
40 | _ID,
41 | CODE,
42 | VALID,
43 | DATECREATED,
44 | DATE,
45 | CUSTOMER,
46 | ROUTE
47 | };
48 | // @formatter:on
49 |
50 | public static boolean hasColumns(String[] projection) {
51 | if (projection == null) return true;
52 | for (String c : projection) {
53 | if (c.equals(CODE) || c.contains("." + CODE)) return true;
54 | if (c.equals(VALID) || c.contains("." + VALID)) return true;
55 | if (c.equals(DATECREATED) || c.contains("." + DATECREATED)) return true;
56 | if (c.equals(DATE) || c.contains("." + DATE)) return true;
57 | if (c.equals(CUSTOMER) || c.contains("." + CUSTOMER)) return true;
58 | if (c.equals(ROUTE) || c.contains("." + ROUTE)) return true;
59 | }
60 | return false;
61 | }
62 |
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/routeobject/Route.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels.routeobject;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Route {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("code")
13 | @Expose
14 | private Integer code;
15 | @SerializedName("source")
16 | @Expose
17 | private String source;
18 | @SerializedName("destination")
19 | @Expose
20 | private String destination;
21 | @SerializedName("bus")
22 | @Expose
23 | private Bus bus;
24 | @SerializedName("price")
25 | @Expose
26 | private Integer price;
27 | @SerializedName("arrival")
28 | @Expose
29 | private String arrival;
30 | @SerializedName("departure")
31 | @Expose
32 | private String departure;
33 |
34 | public Integer getId() {
35 | return id;
36 | }
37 |
38 | public void setId(Integer id) {
39 | this.id = id;
40 | }
41 |
42 | public Integer getCode() {
43 | return code;
44 | }
45 |
46 | public void setCode(Integer code) {
47 | this.code = code;
48 | }
49 |
50 | public String getSource() {
51 | return source;
52 | }
53 |
54 | public void setSource(String source) {
55 | this.source = source;
56 | }
57 |
58 | public String getDestination() {
59 | return destination;
60 | }
61 |
62 | public void setDestination(String destination) {
63 | this.destination = destination;
64 | }
65 |
66 | public Bus getBus() {
67 | return bus;
68 | }
69 |
70 | public void setBus(Bus bus) {
71 | this.bus = bus;
72 | }
73 |
74 | public Integer getPrice() {
75 | return price;
76 | }
77 |
78 | public void setPrice(Integer price) {
79 | this.price = price;
80 | }
81 |
82 | public String getArrival() {
83 | return arrival;
84 | }
85 |
86 | public void setArrival(String arrival) {
87 | this.arrival = arrival;
88 | }
89 |
90 | public String getDeparture() {
91 | return departure;
92 | }
93 |
94 | public void setDeparture(String departure) {
95 | this.departure = departure;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/routeobject/BusCompany.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels.routeobject;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class BusCompany {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("name")
13 | @Expose
14 | private String name;
15 | @SerializedName("image")
16 | @Expose
17 | private String image;
18 | @SerializedName("phone")
19 | @Expose
20 | private String phone;
21 | @SerializedName("email")
22 | @Expose
23 | private String email;
24 | @SerializedName("address")
25 | @Expose
26 | private String address;
27 | @SerializedName("longitude")
28 | @Expose
29 | private Integer longitude;
30 | @SerializedName("latitude")
31 | @Expose
32 | private Integer latitude;
33 |
34 | public Integer getId() {
35 | return id;
36 | }
37 |
38 | public void setId(Integer id) {
39 | this.id = id;
40 | }
41 |
42 | public String getName() {
43 | return name;
44 | }
45 |
46 | public void setName(String name) {
47 | this.name = name;
48 | }
49 |
50 | public String getImage() {
51 | return image;
52 | }
53 |
54 | public void setImage(String image) {
55 | this.image = image;
56 | }
57 |
58 | public String getPhone() {
59 | return phone;
60 | }
61 |
62 | public void setPhone(String phone) {
63 | this.phone = phone;
64 | }
65 |
66 | public String getEmail() {
67 | return email;
68 | }
69 |
70 | public void setEmail(String email) {
71 | this.email = email;
72 | }
73 |
74 | public String getAddress() {
75 | return address;
76 | }
77 |
78 | public void setAddress(String address) {
79 | this.address = address;
80 | }
81 |
82 | public Integer getLongitude() {
83 | return longitude;
84 | }
85 |
86 | public void setLongitude(Integer longitude) {
87 | this.longitude = longitude;
88 | }
89 |
90 | public Integer getLatitude() {
91 | return latitude;
92 | }
93 |
94 | public void setLatitude(Integer latitude) {
95 | this.latitude = latitude;
96 | }
97 |
98 | }
99 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/orders/OrdersCursor.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.orders;
2 |
3 | import java.util.Date;
4 |
5 | import android.database.Cursor;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.codephillip.app.busticket.provider.base.AbstractCursor;
10 |
11 | /**
12 | * Cursor wrapper for the {@code orders} table.
13 | */
14 | public class OrdersCursor extends AbstractCursor implements OrdersModel {
15 | public OrdersCursor(Cursor cursor) {
16 | super(cursor);
17 | }
18 |
19 | /**
20 | * Primary key.
21 | */
22 | public long getId() {
23 | Long res = getLongOrNull(OrdersColumns._ID);
24 | if (res == null)
25 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition");
26 | return res;
27 | }
28 |
29 | /**
30 | * Get the {@code code} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | public String getCode() {
35 | String res = getStringOrNull(OrdersColumns.CODE);
36 | return res;
37 | }
38 |
39 | /**
40 | * Get the {@code valid} value.
41 | * Can be {@code null}.
42 | */
43 | @Nullable
44 | public Boolean getValid() {
45 | Boolean res = getBooleanOrNull(OrdersColumns.VALID);
46 | return res;
47 | }
48 |
49 | /**
50 | * Get the {@code datecreated} value.
51 | * Can be {@code null}.
52 | */
53 | @Nullable
54 | public Date getDatecreated() {
55 | Date res = getDateOrNull(OrdersColumns.DATECREATED);
56 | return res;
57 | }
58 |
59 | /**
60 | * Get the {@code date} value.
61 | * Can be {@code null}.
62 | */
63 | @Nullable
64 | public Date getDate() {
65 | Date res = getDateOrNull(OrdersColumns.DATE);
66 | return res;
67 | }
68 |
69 | /**
70 | * Get the {@code customer} value.
71 | * Can be {@code null}.
72 | */
73 | @Nullable
74 | public String getCustomer() {
75 | String res = getStringOrNull(OrdersColumns.CUSTOMER);
76 | return res;
77 | }
78 |
79 | /**
80 | * Get the {@code route} value.
81 | * Can be {@code null}.
82 | */
83 | @Nullable
84 | public String getRoute() {
85 | String res = getStringOrNull(OrdersColumns.ROUTE);
86 | return res;
87 | }
88 | }
89 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_profile.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
14 |
15 |
24 |
25 |
32 |
33 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/base/AbstractCursor.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.base;
2 |
3 | import java.util.Date;
4 | import java.util.HashMap;
5 |
6 | import android.database.Cursor;
7 | import android.database.CursorWrapper;
8 | import android.provider.BaseColumns;
9 |
10 | public abstract class AbstractCursor extends CursorWrapper {
11 | private final HashMap mColumnIndexes;
12 |
13 | public AbstractCursor(Cursor cursor) {
14 | super(cursor);
15 | mColumnIndexes = new HashMap(cursor.getColumnCount() * 4 / 3, .75f);
16 | }
17 |
18 | public abstract long getId();
19 |
20 | protected int getCachedColumnIndexOrThrow(String colName) {
21 | Integer index = mColumnIndexes.get(colName);
22 | if (index == null) {
23 | index = getColumnIndexOrThrow(colName);
24 | mColumnIndexes.put(colName, index);
25 | }
26 | return index;
27 | }
28 |
29 | public String getStringOrNull(String colName) {
30 | int index = getCachedColumnIndexOrThrow(colName);
31 | if (isNull(index)) return null;
32 | return getString(index);
33 | }
34 |
35 | public Integer getIntegerOrNull(String colName) {
36 | int index = getCachedColumnIndexOrThrow(colName);
37 | if (isNull(index)) return null;
38 | return getInt(index);
39 | }
40 |
41 | public Long getLongOrNull(String colName) {
42 | int index = getCachedColumnIndexOrThrow(colName);
43 | if (isNull(index)) return null;
44 | return getLong(index);
45 | }
46 |
47 | public Float getFloatOrNull(String colName) {
48 | int index = getCachedColumnIndexOrThrow(colName);
49 | if (isNull(index)) return null;
50 | return getFloat(index);
51 | }
52 |
53 | public Double getDoubleOrNull(String colName) {
54 | int index = getCachedColumnIndexOrThrow(colName);
55 | if (isNull(index)) return null;
56 | return getDouble(index);
57 | }
58 |
59 | public Boolean getBooleanOrNull(String colName) {
60 | int index = getCachedColumnIndexOrThrow(colName);
61 | if (isNull(index)) return null;
62 | return getInt(index) != 0;
63 | }
64 |
65 | public Date getDateOrNull(String colName) {
66 | int index = getCachedColumnIndexOrThrow(colName);
67 | if (isNull(index)) return null;
68 | return new Date(getLong(index));
69 | }
70 |
71 | public byte[] getBlobOrNull(String colName) {
72 | int index = getCachedColumnIndexOrThrow(colName);
73 | if (isNull(index)) return null;
74 | return getBlob(index);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/locations/LocationsContentValues.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.locations;
2 |
3 | import java.util.Date;
4 |
5 | import android.content.Context;
6 | import android.content.ContentResolver;
7 | import android.net.Uri;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 |
11 | import com.codephillip.app.busticket.provider.base.AbstractContentValues;
12 |
13 | /**
14 | * Content values wrapper for the {@code locations} table.
15 | */
16 | public class LocationsContentValues extends AbstractContentValues {
17 | @Override
18 | public Uri uri() {
19 | return LocationsColumns.CONTENT_URI;
20 | }
21 |
22 | /**
23 | * Update row(s) using the values stored by this object and the given selection.
24 | *
25 | * @param contentResolver The content resolver to use.
26 | * @param where The selection to use (can be {@code null}).
27 | */
28 | public int update(ContentResolver contentResolver, @Nullable LocationsSelection where) {
29 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
30 | }
31 |
32 | /**
33 | * Update row(s) using the values stored by this object and the given selection.
34 | *
35 | * @param contentResolver The content resolver to use.
36 | * @param where The selection to use (can be {@code null}).
37 | */
38 | public int update(Context context, @Nullable LocationsSelection where) {
39 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
40 | }
41 |
42 | public LocationsContentValues putName(@Nullable String value) {
43 | mContentValues.put(LocationsColumns.NAME, value);
44 | return this;
45 | }
46 |
47 | public LocationsContentValues putNameNull() {
48 | mContentValues.putNull(LocationsColumns.NAME);
49 | return this;
50 | }
51 |
52 | public LocationsContentValues putLatitude(@Nullable Double value) {
53 | mContentValues.put(LocationsColumns.LATITUDE, value);
54 | return this;
55 | }
56 |
57 | public LocationsContentValues putLatitudeNull() {
58 | mContentValues.putNull(LocationsColumns.LATITUDE);
59 | return this;
60 | }
61 |
62 | public LocationsContentValues putLongitude(@Nullable Double value) {
63 | mContentValues.put(LocationsColumns.LONGITUDE, value);
64 | return this;
65 | }
66 |
67 | public LocationsContentValues putLongitudeNull() {
68 | mContentValues.putNull(LocationsColumns.LONGITUDE);
69 | return this;
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/book_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
15 |
16 |
22 |
23 |
24 |
30 |
31 |
39 |
40 |
48 |
49 |
57 |
58 |
59 |
60 |
69 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/routes/RoutesColumns.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.routes;
2 |
3 | import android.net.Uri;
4 | import android.provider.BaseColumns;
5 |
6 | import com.codephillip.app.busticket.provider.BusTicketProvider;
7 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
8 | import com.codephillip.app.busticket.provider.orders.OrdersColumns;
9 | import com.codephillip.app.busticket.provider.routes.RoutesColumns;
10 |
11 | /**
12 | * Columns for the {@code routes} table.
13 | */
14 | public class RoutesColumns implements BaseColumns {
15 | public static final String TABLE_NAME = "routes";
16 | public static final Uri CONTENT_URI = Uri.parse(BusTicketProvider.CONTENT_URI_BASE + "/" + TABLE_NAME);
17 |
18 | /**
19 | * Primary key.
20 | */
21 | public static final String _ID = BaseColumns._ID;
22 |
23 | public static final String ROUTEID = "routeId";
24 |
25 | public static final String CODE = "Code";
26 |
27 | public static final String SOURCE = "source";
28 |
29 | public static final String DESTINATION = "Destination";
30 |
31 | public static final String BUSCOMPANYNAME = "BusCompanyName";
32 |
33 | public static final String BUSCOMPANYIMAGE = "BusCompanyImage";
34 |
35 | public static final String PRICE = "Price";
36 |
37 | public static final String ARRIVAL = "Arrival";
38 |
39 | public static final String DEPARTURE = "Departure";
40 |
41 |
42 | public static final String DEFAULT_ORDER = TABLE_NAME + "." +_ID;
43 |
44 | // @formatter:off
45 | public static final String[] ALL_COLUMNS = new String[] {
46 | _ID,
47 | ROUTEID,
48 | CODE,
49 | SOURCE,
50 | DESTINATION,
51 | BUSCOMPANYNAME,
52 | BUSCOMPANYIMAGE,
53 | PRICE,
54 | ARRIVAL,
55 | DEPARTURE
56 | };
57 | // @formatter:on
58 |
59 | public static boolean hasColumns(String[] projection) {
60 | if (projection == null) return true;
61 | for (String c : projection) {
62 | if (c.equals(ROUTEID) || c.contains("." + ROUTEID)) return true;
63 | if (c.equals(CODE) || c.contains("." + CODE)) return true;
64 | if (c.equals(SOURCE) || c.contains("." + SOURCE)) return true;
65 | if (c.equals(DESTINATION) || c.contains("." + DESTINATION)) return true;
66 | if (c.equals(BUSCOMPANYNAME) || c.contains("." + BUSCOMPANYNAME)) return true;
67 | if (c.equals(BUSCOMPANYIMAGE) || c.contains("." + BUSCOMPANYIMAGE)) return true;
68 | if (c.equals(PRICE) || c.contains("." + PRICE)) return true;
69 | if (c.equals(ARRIVAL) || c.contains("." + ARRIVAL)) return true;
70 | if (c.equals(DEPARTURE) || c.contains("." + DEPARTURE)) return true;
71 | }
72 | return false;
73 | }
74 |
75 | }
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/order_input_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
8 |
20 |
21 |
32 |
33 |
42 |
43 |
49 |
50 |
56 |
57 |
65 |
66 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/mymodels/Customer.java:
--------------------------------------------------------------------------------
1 |
2 | package com.codephillip.app.busticket.mymodels;
3 |
4 | import com.google.gson.annotations.Expose;
5 | import com.google.gson.annotations.SerializedName;
6 |
7 | public class Customer {
8 |
9 | @SerializedName("id")
10 | @Expose
11 | private Integer id;
12 | @SerializedName("name")
13 | @Expose
14 | private String name;
15 | @SerializedName("image")
16 | @Expose
17 | private String image;
18 | @SerializedName("phone")
19 | @Expose
20 | private String phone;
21 | @SerializedName("email")
22 | @Expose
23 | private String email;
24 | @SerializedName("password")
25 | @Expose
26 | private String password;
27 | @SerializedName("address")
28 | @Expose
29 | private String address;
30 | @SerializedName("longitude")
31 | @Expose
32 | private double longitude;
33 | @SerializedName("latitude")
34 | @Expose
35 | private double latitude;
36 |
37 | public Customer(String name, String address, String phoneNumber, String password, String emailAddress, double longitude, double latitude) {
38 | this.name = name;
39 | this.address = address;
40 | this.phone = phoneNumber;
41 | this.password = password;
42 | this.email = emailAddress;
43 | this.longitude = longitude;
44 | this.latitude = latitude;
45 | }
46 |
47 | public Customer(String phoneNumber, String password) {
48 | this.phone = phoneNumber;
49 | this.password = password;
50 | }
51 |
52 | public Customer(Integer id, String name, String address, String phone) {
53 | this.id = id;
54 | this.name = name;
55 | this.address = address;
56 | this.phone = phone;
57 | }
58 |
59 | public Integer getId() {
60 | return id;
61 | }
62 |
63 | public void setId(Integer id) {
64 | this.id = id;
65 | }
66 |
67 | public String getName() {
68 | return name;
69 | }
70 |
71 | public void setName(String name) {
72 | this.name = name;
73 | }
74 |
75 | public String getImage() {
76 | return image;
77 | }
78 |
79 | public void setImage(String image) {
80 | this.image = image;
81 | }
82 |
83 | public String getPhone() {
84 | return phone;
85 | }
86 |
87 | public void setPhone(String phone) {
88 | this.phone = phone;
89 | }
90 |
91 | public String getEmail() {
92 | return email;
93 | }
94 |
95 | public void setEmail(String email) {
96 | this.email = email;
97 | }
98 |
99 | public String getAddress() {
100 | return address;
101 | }
102 |
103 | public void setAddress(String address) {
104 | this.address = address;
105 | }
106 |
107 | public String getPassword() {
108 | return password;
109 | }
110 |
111 | public void setPassword(String password) {
112 | this.password = password;
113 | }
114 |
115 | public void setLongitude(double longitude) {
116 | this.longitude = longitude;
117 | }
118 |
119 | public void setLatitude(double latitude) {
120 | this.latitude = latitude;
121 | }
122 | }
123 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/routes/RoutesCursor.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.routes;
2 |
3 | import java.util.Date;
4 |
5 | import android.database.Cursor;
6 | import android.support.annotation.NonNull;
7 | import android.support.annotation.Nullable;
8 |
9 | import com.codephillip.app.busticket.provider.base.AbstractCursor;
10 |
11 | /**
12 | * Cursor wrapper for the {@code routes} table.
13 | */
14 | public class RoutesCursor extends AbstractCursor implements RoutesModel {
15 | public RoutesCursor(Cursor cursor) {
16 | super(cursor);
17 | }
18 |
19 | /**
20 | * Primary key.
21 | */
22 | public long getId() {
23 | Long res = getLongOrNull(RoutesColumns._ID);
24 | if (res == null)
25 | throw new NullPointerException("The value of '_id' in the database was null, which is not allowed according to the model definition");
26 | return res;
27 | }
28 |
29 | /**
30 | * Get the {@code routeid} value.
31 | * Can be {@code null}.
32 | */
33 | @Nullable
34 | public Integer getRouteid() {
35 | Integer res = getIntegerOrNull(RoutesColumns.ROUTEID);
36 | return res;
37 | }
38 |
39 | /**
40 | * Get the {@code code} value.
41 | * Can be {@code null}.
42 | */
43 | @Nullable
44 | public Integer getCode() {
45 | Integer res = getIntegerOrNull(RoutesColumns.CODE);
46 | return res;
47 | }
48 |
49 | /**
50 | * Get the {@code source} value.
51 | * Can be {@code null}.
52 | */
53 | @Nullable
54 | public String getSource() {
55 | String res = getStringOrNull(RoutesColumns.SOURCE);
56 | return res;
57 | }
58 |
59 | /**
60 | * Get the {@code destination} value.
61 | * Can be {@code null}.
62 | */
63 | @Nullable
64 | public String getDestination() {
65 | String res = getStringOrNull(RoutesColumns.DESTINATION);
66 | return res;
67 | }
68 |
69 | /**
70 | * Get the {@code buscompanyname} value.
71 | * Can be {@code null}.
72 | */
73 | @Nullable
74 | public String getBuscompanyname() {
75 | String res = getStringOrNull(RoutesColumns.BUSCOMPANYNAME);
76 | return res;
77 | }
78 |
79 | /**
80 | * Get the {@code buscompanyimage} value.
81 | * Can be {@code null}.
82 | */
83 | @Nullable
84 | public String getBuscompanyimage() {
85 | String res = getStringOrNull(RoutesColumns.BUSCOMPANYIMAGE);
86 | return res;
87 | }
88 |
89 | /**
90 | * Get the {@code price} value.
91 | * Can be {@code null}.
92 | */
93 | @Nullable
94 | public Integer getPrice() {
95 | Integer res = getIntegerOrNull(RoutesColumns.PRICE);
96 | return res;
97 | }
98 |
99 | /**
100 | * Get the {@code arrival} value.
101 | * Can be {@code null}.
102 | */
103 | @Nullable
104 | public Date getArrival() {
105 | Date res = getDateOrNull(RoutesColumns.ARRIVAL);
106 | return res;
107 | }
108 |
109 | /**
110 | * Get the {@code departure} value.
111 | * Can be {@code null}.
112 | */
113 | @Nullable
114 | public Date getDeparture() {
115 | Date res = getDateOrNull(RoutesColumns.DEPARTURE);
116 | return res;
117 | }
118 | }
119 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
16 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
31 |
34 |
35 |
36 |
40 |
41 |
44 |
45 |
48 |
51 |
52 |
56 |
61 |
64 |
65 |
66 |
67 |
68 |
69 |
74 |
77 |
78 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/book_row2.xml:
--------------------------------------------------------------------------------
1 |
2 |
15 |
16 |
19 |
20 |
24 |
25 |
31 |
32 |
42 |
43 |
44 |
45 |
54 |
55 |
61 |
62 |
67 |
68 |
73 |
74 |
79 |
80 |
81 |
90 |
91 |
92 |
93 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/orders/OrdersContentValues.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.orders;
2 |
3 | import java.util.Date;
4 |
5 | import android.content.Context;
6 | import android.content.ContentResolver;
7 | import android.net.Uri;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 |
11 | import com.codephillip.app.busticket.provider.base.AbstractContentValues;
12 |
13 | /**
14 | * Content values wrapper for the {@code orders} table.
15 | */
16 | public class OrdersContentValues extends AbstractContentValues {
17 | @Override
18 | public Uri uri() {
19 | return OrdersColumns.CONTENT_URI;
20 | }
21 |
22 | /**
23 | * Update row(s) using the values stored by this object and the given selection.
24 | *
25 | * @param contentResolver The content resolver to use.
26 | * @param where The selection to use (can be {@code null}).
27 | */
28 | public int update(ContentResolver contentResolver, @Nullable OrdersSelection where) {
29 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
30 | }
31 |
32 | /**
33 | * Update row(s) using the values stored by this object and the given selection.
34 | *
35 | * @param contentResolver The content resolver to use.
36 | * @param where The selection to use (can be {@code null}).
37 | */
38 | public int update(Context context, @Nullable OrdersSelection where) {
39 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
40 | }
41 |
42 | public OrdersContentValues putCode(@Nullable String value) {
43 | mContentValues.put(OrdersColumns.CODE, value);
44 | return this;
45 | }
46 |
47 | public OrdersContentValues putCodeNull() {
48 | mContentValues.putNull(OrdersColumns.CODE);
49 | return this;
50 | }
51 |
52 | public OrdersContentValues putValid(@Nullable Boolean value) {
53 | mContentValues.put(OrdersColumns.VALID, value);
54 | return this;
55 | }
56 |
57 | public OrdersContentValues putValidNull() {
58 | mContentValues.putNull(OrdersColumns.VALID);
59 | return this;
60 | }
61 |
62 | public OrdersContentValues putDatecreated(@Nullable Date value) {
63 | mContentValues.put(OrdersColumns.DATECREATED, value == null ? null : value.getTime());
64 | return this;
65 | }
66 |
67 | public OrdersContentValues putDatecreatedNull() {
68 | mContentValues.putNull(OrdersColumns.DATECREATED);
69 | return this;
70 | }
71 |
72 | public OrdersContentValues putDatecreated(@Nullable Long value) {
73 | mContentValues.put(OrdersColumns.DATECREATED, value);
74 | return this;
75 | }
76 |
77 | public OrdersContentValues putDate(@Nullable Date value) {
78 | mContentValues.put(OrdersColumns.DATE, value == null ? null : value.getTime());
79 | return this;
80 | }
81 |
82 | public OrdersContentValues putDateNull() {
83 | mContentValues.putNull(OrdersColumns.DATE);
84 | return this;
85 | }
86 |
87 | public OrdersContentValues putDate(@Nullable Long value) {
88 | mContentValues.put(OrdersColumns.DATE, value);
89 | return this;
90 | }
91 |
92 | public OrdersContentValues putCustomer(@Nullable String value) {
93 | mContentValues.put(OrdersColumns.CUSTOMER, value);
94 | return this;
95 | }
96 |
97 | public OrdersContentValues putCustomerNull() {
98 | mContentValues.putNull(OrdersColumns.CUSTOMER);
99 | return this;
100 | }
101 |
102 | public OrdersContentValues putRoute(@Nullable String value) {
103 | mContentValues.put(OrdersColumns.ROUTE, value);
104 | return this;
105 | }
106 |
107 | public OrdersContentValues putRouteNull() {
108 | mContentValues.putNull(OrdersColumns.ROUTE);
109 | return this;
110 | }
111 | }
112 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/fragment_select_route.xml:
--------------------------------------------------------------------------------
1 |
5 |
6 |
15 |
16 |
23 |
24 |
34 |
35 |
41 |
42 |
50 |
51 |
57 |
58 |
59 |
60 |
66 |
67 |
75 |
76 |
82 |
83 |
84 |
94 |
95 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/adapters/BookAdapter.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.adapters;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.codephillip.app.busticket.ConfirmOrderActivity;
14 | import com.codephillip.app.busticket.R;
15 | import com.codephillip.app.busticket.Utils;
16 | import com.codephillip.app.busticket.provider.orders.OrdersCursor;
17 | import com.codephillip.app.busticket.provider.routes.RoutesCursor;
18 |
19 |
20 | /**
21 | * Created by codephillip on 10/05/17.
22 | */
23 |
24 | public class BookAdapter extends RecyclerView.Adapter {
25 | private static final String TAG = BookAdapter.class.getSimpleName();
26 | private RoutesCursor dataCursor;
27 | private static Context context;
28 |
29 | public static class ViewHolder extends RecyclerView.ViewHolder {
30 | private ImageView imageView;
31 | private TextView companyNameView;
32 | private TextView sourceView;
33 | private TextView destinationView;
34 | private TextView departureView;
35 | private TextView priceView;
36 |
37 | private ViewHolder(View v) {
38 | super(v);
39 | imageView = (ImageView) v.findViewById(R.id.image);
40 | companyNameView = (TextView) v.findViewById(R.id.company_view);
41 | sourceView = (TextView) v.findViewById(R.id.source_view);
42 | destinationView = (TextView) v.findViewById(R.id.dest_view);
43 | departureView = (TextView) v.findViewById(R.id.departure_view);
44 | priceView = (TextView) v.findViewById(R.id.price_view);
45 | }
46 | }
47 |
48 | public BookAdapter(Context context, RoutesCursor cursor) {
49 | Utils.getInstance();
50 | Utils.cursor = cursor;
51 | dataCursor = cursor;
52 | this.context = context;
53 | Utils.getInstance();
54 | }
55 |
56 | public BookAdapter(Context context, OrdersCursor ordersCursor) {
57 | this.context = context;
58 | }
59 |
60 |
61 | @Override
62 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
63 | View cardview = LayoutInflater.from(parent.getContext())
64 | .inflate(R.layout.book_row2, parent, false);
65 | return new ViewHolder(cardview);
66 | }
67 |
68 | @Override
69 | public void onBindViewHolder(final ViewHolder holder, final int position) {
70 | dataCursor.moveToPosition(position);
71 | try {
72 | //todo add bus imageView
73 | holder.priceView.setText(String.valueOf(dataCursor.getPrice()));
74 | holder.companyNameView.setText(dataCursor.getBuscompanyname());
75 | //todo use string builder %s
76 | holder.sourceView.setText("From: " + dataCursor.getSource());
77 | holder.destinationView.setText("To: " + dataCursor.getDestination());
78 | //todo truncate date
79 | holder.departureView.setText("Departure: " + Utils.formatDateString(dataCursor.getDeparture().toString()));
80 |
81 | // picassoLoader(context, holder.imageView, dataCursor.getBuscompanyimage());
82 | } catch (Exception e) {
83 | e.printStackTrace();
84 | }
85 |
86 | holder.itemView.setOnClickListener(new View.OnClickListener() {
87 | @Override
88 | public void onClick(View view) {
89 | Log.d(TAG, "onClick: ");
90 | dataCursor.moveToPosition(position);
91 | context.startActivity(new Intent(context, ConfirmOrderActivity.class).putExtra(Utils.CURSOR_POSITION, position));
92 | }
93 | });
94 | }
95 |
96 | @Override
97 | public int getItemCount() {
98 | // any number other than zero will cause a bug
99 | return (dataCursor == null) ? 0 : dataCursor.getCount();
100 | }
101 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/BookFragment.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.v4.app.Fragment;
5 | import android.support.v7.widget.LinearLayoutManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.AdapterView;
12 | import android.widget.ArrayAdapter;
13 | import android.widget.Spinner;
14 |
15 | import com.codephillip.app.busticket.adapters.BookAdapter;
16 | import com.codephillip.app.busticket.provider.routes.RoutesCursor;
17 | import com.codephillip.app.busticket.provider.routes.RoutesSelection;
18 |
19 | import java.util.ArrayList;
20 | import java.util.List;
21 |
22 | public class BookFragment extends Fragment implements AdapterView.OnItemSelectedListener {
23 |
24 | private static final String TAG = BookFragment.class.getSimpleName();
25 | private Spinner spinner, spinner2;
26 | private RecyclerView recyclerView;
27 | private BookAdapter adapter;
28 | private List categories = new ArrayList<>();
29 | //category package is set according to which category is selected
30 | private List categoryPackages = new ArrayList<>();
31 |
32 | public BookFragment() {
33 | }
34 |
35 | public static BookFragment newInstance() {
36 | return new BookFragment();
37 | }
38 |
39 | @Override
40 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
41 | Bundle savedInstanceState) {
42 | View rootView = inflater.inflate(R.layout.fragment_book, container, false);
43 | spinner = (Spinner) rootView.findViewById(R.id.spinner);
44 | spinner.setOnItemSelectedListener(this);
45 | spinner2 = (Spinner) rootView.findViewById(R.id.spinner2);
46 | spinner2.setOnItemSelectedListener(this);
47 |
48 | recyclerView = (RecyclerView) rootView.findViewById(R.id.recycler);
49 | recyclerView.setHasFixedSize(true);
50 | recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
51 | adapter = new BookAdapter(getContext(), queryRoutesTable());
52 | recyclerView.setAdapter(adapter);
53 |
54 | initializeSpinners();
55 | return rootView;
56 | }
57 |
58 | private void initializeSpinners() {
59 | categories.add("Price");
60 | categories.add("Date");
61 | ArrayAdapter dataAdapter = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categories);
62 | dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
63 | spinner.setAdapter(dataAdapter);
64 |
65 | categoryPackages.add("20000");
66 | categoryPackages.add("30000");
67 | ArrayAdapter dataAdapter2 = new ArrayAdapter<>(getContext(), android.R.layout.simple_spinner_item, categoryPackages);
68 | dataAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
69 | spinner2.setAdapter(dataAdapter2);
70 | }
71 |
72 | private RoutesCursor queryRoutesTable() {
73 | // return new RoutesSelection().query(getContext().getContentResolver());
74 | Log.d(TAG, "queryRoutesTable: ### " + getActivity().getIntent().getStringExtra(Utils.SOURCE));
75 | return new RoutesSelection()
76 | .source(getActivity().getIntent().getStringExtra(Utils.SOURCE))
77 | .and()
78 | .destination(getActivity().getIntent().getStringExtra(Utils.DESTINATION))
79 | .query(getContext().getContentResolver());
80 | }
81 |
82 | @Override
83 | public void onItemSelected(AdapterView> parent, View view, int position, long id) {
84 | String item = parent.getItemAtPosition(position).toString();
85 | Log.d(TAG, "onItemSelected: item#" + item);
86 | Log.d(TAG, "onItemSelected: id#" + view.getId());
87 | // Log.d(TAG, "onItemSelected: parent id#" + parent.get);
88 | Log.d(TAG, "onItemSelected: position#" + position);
89 | Log.d(TAG, "onItemSelected: id#" + id);
90 |
91 | }
92 |
93 | @Override
94 | public void onNothingSelected(AdapterView> adapterView) {
95 | //dummy
96 | }
97 | }
98 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_sign_in.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
21 |
22 |
26 |
27 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
44 |
45 |
54 |
55 |
56 |
59 |
60 |
71 |
72 |
73 |
83 |
84 |
92 |
93 |
94 |
95 |
96 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.NavigationView;
5 | import android.support.v4.app.Fragment;
6 | import android.support.v4.view.GravityCompat;
7 | import android.support.v4.widget.DrawerLayout;
8 | import android.support.v7.app.ActionBarDrawerToggle;
9 | import android.support.v7.app.AppCompatActivity;
10 | import android.support.v7.widget.Toolbar;
11 | import android.util.Log;
12 | import android.view.Menu;
13 | import android.view.MenuItem;
14 |
15 | import static com.codephillip.app.busticket.Utils.screenNames;
16 |
17 | public class MainActivity extends AppCompatActivity
18 | implements NavigationView.OnNavigationItemSelectedListener {
19 |
20 | private static final String TAG = MainActivity.class.getSimpleName();
21 |
22 | @Override
23 | protected void onCreate(Bundle savedInstanceState) {
24 | super.onCreate(savedInstanceState);
25 | setContentView(R.layout.activity_main);
26 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
27 | setSupportActionBar(toolbar);
28 |
29 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
30 | ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
31 | this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
32 | drawer.setDrawerListener(toggle);
33 | toggle.syncState();
34 |
35 | NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
36 | navigationView.setNavigationItemSelectedListener(this);
37 |
38 | //populate the first default fragment
39 | Fragment fragment = SelectRouteFragment.newInstance();
40 | getSupportActionBar().setTitle(screenNames[0]);
41 | android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
42 | fragmentTransaction.replace(R.id.frame, fragment);
43 | fragmentTransaction.commit();
44 | }
45 |
46 | @Override
47 | public void onBackPressed() {
48 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
49 | if (drawer.isDrawerOpen(GravityCompat.START)) {
50 | drawer.closeDrawer(GravityCompat.START);
51 | } else {
52 | super.onBackPressed();
53 | }
54 | }
55 |
56 | @Override
57 | public boolean onCreateOptionsMenu(Menu menu) {
58 | // Inflate the menu; this adds items to the action bar if it is present.
59 | getMenuInflater().inflate(R.menu.main, menu);
60 | return true;
61 | }
62 |
63 | @Override
64 | public boolean onOptionsItemSelected(MenuItem item) {
65 | // Handle action bar item clicks here. The action bar will
66 | // automatically handle clicks on the Home/Up orderButton, so long
67 | // as you specify a parent activity in AndroidManifest.xml.
68 | int id = item.getItemId();
69 |
70 | //noinspection SimplifiableIfStatement
71 | if (id == R.id.action_settings) {
72 | return true;
73 | }
74 |
75 | return super.onOptionsItemSelected(item);
76 | }
77 |
78 | @SuppressWarnings("StatementWithEmptyBody")
79 | @Override
80 | public boolean onNavigationItemSelected(MenuItem item) {
81 | int id = item.getItemId();
82 | Log.d("Navigation bar", "onNavigationItemSelected: " + id);
83 | Fragment fragment;
84 |
85 | //todo change id names
86 | if (id == R.id.nav_camera) {
87 | fragment = SelectRouteFragment.newInstance();
88 | getSupportActionBar().setTitle(screenNames[0]);
89 | } else if (id == R.id.nav_gallery) {
90 | fragment = OrdersFragment.newInstance();
91 | getSupportActionBar().setTitle(screenNames[1]);
92 | } else if (id == R.id.nav_slideshow) {
93 | fragment = HistoryFragment.newInstance();
94 | getSupportActionBar().setTitle(screenNames[2]);
95 | } else if (id == R.id.nav_manage) {
96 | fragment = ProfileFragment.newInstance();
97 | getSupportActionBar().setTitle(screenNames[3]);
98 | } else {
99 | return true;
100 | }
101 | android.support.v4.app.FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
102 | fragmentTransaction.replace(R.id.frame, fragment);
103 | fragmentTransaction.commit();
104 |
105 | DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
106 | drawer.closeDrawer(GravityCompat.START);
107 | return true;
108 | }
109 | }
110 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/orders_row.xml:
--------------------------------------------------------------------------------
1 |
2 |
14 |
15 |
20 |
21 |
25 |
26 |
32 |
33 |
43 |
44 |
45 |
46 |
55 |
56 |
63 |
64 |
69 |
70 |
75 |
76 |
81 |
82 |
87 |
88 |
93 |
94 |
95 |
96 |
101 |
102 |
110 |
111 |
112 |
113 |
114 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/SelectRouteFragment.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.content.Intent;
4 | import android.database.Cursor;
5 | import android.os.Bundle;
6 | import android.support.annotation.Nullable;
7 | import android.support.design.widget.Snackbar;
8 | import android.support.v4.app.Fragment;
9 | import android.support.v4.app.LoaderManager;
10 | import android.support.v4.content.CursorLoader;
11 | import android.support.v4.content.Loader;
12 | import android.util.Log;
13 | import android.view.LayoutInflater;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.widget.ArrayAdapter;
17 | import android.widget.Button;
18 | import android.widget.Toast;
19 |
20 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
21 | import com.codephillip.app.busticket.provider.locations.LocationsCursor;
22 | import com.jaredrummler.materialspinner.MaterialSpinner;
23 |
24 | import java.util.ArrayList;
25 | import java.util.List;
26 |
27 | public class SelectRouteFragment extends Fragment implements MaterialSpinner.OnItemSelectedListener, LoaderManager.LoaderCallbacks {
28 |
29 | private static final String TAG = SelectRouteFragment.class.getSimpleName();
30 | private MaterialSpinner destSpinner;
31 | private MaterialSpinner sourceSpinner;
32 | private Button selectButton;
33 | private String destination;
34 | private String source;
35 |
36 | public SelectRouteFragment() {
37 | }
38 |
39 | public static SelectRouteFragment newInstance() {
40 | return new SelectRouteFragment();
41 | }
42 |
43 | @Override
44 | public View onCreateView(LayoutInflater inflater, ViewGroup container,
45 | Bundle savedInstanceState) {
46 | View rootView = inflater.inflate(R.layout.fragment_select_route, container, false);
47 | destSpinner = rootView.findViewById(R.id.dest_spinner);
48 | sourceSpinner = rootView.findViewById(R.id.source_spinner);
49 |
50 | destSpinner.setOnItemSelectedListener(this);
51 | sourceSpinner.setOnItemSelectedListener(this);
52 |
53 | selectButton = rootView.findViewById(R.id.select_button);
54 | selectButton.setOnClickListener(new View.OnClickListener() {
55 | @Override
56 | public void onClick(View view) {
57 | if (source.equals(destination)) {
58 | Toast.makeText(getContext(), "Choose a different Destination", Toast.LENGTH_SHORT).show();
59 | } else {
60 | Intent intent = new Intent(getContext(), BookActivity.class);
61 | intent.putExtra(Utils.SOURCE, source);
62 | intent.putExtra(Utils.DESTINATION, destination);
63 | getActivity().startActivity(intent);
64 | }
65 | }
66 | });
67 | return rootView;
68 | }
69 |
70 | @Override
71 | public void onActivityCreated(@Nullable Bundle savedInstanceState) {
72 | super.onActivityCreated(savedInstanceState);
73 | getLoaderManager().initLoader(2, null, this);
74 | }
75 |
76 | @Override
77 | public Loader onCreateLoader(int id, Bundle args) {
78 | return new CursorLoader(getContext(), LocationsColumns.CONTENT_URI, null, null, null, null);
79 | }
80 |
81 | @Override
82 | public void onLoadFinished(Loader loader, Cursor data) {
83 | Log.d(TAG, "onLoadFinished: started");
84 | LocationsCursor cursor = new LocationsCursor(data);
85 | List locations = new ArrayList<>();
86 | if (cursor.moveToFirst()) {
87 | do {
88 | locations.add(cursor.getName());
89 | } while (cursor.moveToNext());
90 | }
91 |
92 | // Set default route values
93 | source = locations.get(0);
94 | destination = locations.get(0);
95 |
96 | ArrayAdapter dataAdapter = new ArrayAdapter(getContext(), android.R.layout.simple_expandable_list_item_1, locations);
97 | dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
98 | sourceSpinner.setAdapter(dataAdapter);
99 | destSpinner.setAdapter(dataAdapter);
100 | }
101 |
102 | @Override
103 | public void onLoaderReset(Loader loader) {
104 |
105 | }
106 |
107 | @Override
108 | public void onItemSelected(MaterialSpinner view, int position, long id, Object itemObject) {
109 | Snackbar.make(view, "Clicked " + itemObject.toString(), Snackbar.LENGTH_LONG).show();
110 | String item = itemObject.toString();
111 | Log.d(TAG, "onItemSelected: " + item);
112 |
113 | if (view.getId() == destSpinner.getId()) {
114 | Log.d(TAG, "onItemSelected: clicked dest");
115 | destination = item;
116 | } else {
117 | Log.d(TAG, "onItemSelected: clicked source");
118 | source = item;
119 | }
120 | }
121 | }
122 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/OrderDetailsActivity.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import android.database.CursorIndexOutOfBoundsException;
4 | import android.os.Bundle;
5 | import android.support.v7.app.AppCompatActivity;
6 | import android.support.v7.widget.Toolbar;
7 | import android.util.Log;
8 | import android.view.View;
9 | import android.widget.Button;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.codephillip.app.busticket.provider.orders.OrdersCursor;
14 | import com.codephillip.app.busticket.provider.orders.OrdersSelection;
15 | import com.codephillip.app.busticket.provider.routes.RoutesCursor;
16 | import com.codephillip.app.busticket.provider.routes.RoutesSelection;
17 |
18 | import static com.codephillip.app.busticket.Utils.picassoLoader;
19 |
20 | public class OrderDetailsActivity extends AppCompatActivity {
21 |
22 | private static final String TAG = OrderDetailsActivity.class.getSimpleName();
23 | Button cancelButton;
24 | private ImageView toolbarImage;
25 | private TextView company;
26 | private TextView source;
27 | private TextView destination;
28 | private TextView arrival;
29 | private TextView departure;
30 | private TextView price;
31 | private TextView code;
32 | private TextView valid;
33 | private TextView dateCreated;
34 | private OrdersCursor cursor;
35 | private int cursorPosition;
36 | private OrdersCursor ordersCursor;
37 |
38 | @Override
39 | protected void onCreate(Bundle savedInstanceState) {
40 | super.onCreate(savedInstanceState);
41 | setContentView(R.layout.activity_order_details);
42 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
43 | setSupportActionBar(toolbar);
44 | getSupportActionBar().setDisplayHomeAsUpEnabled(true);
45 | Utils.getInstance();
46 |
47 | toolbarImage = (ImageView) findViewById(R.id.image);
48 | company = (TextView) findViewById(R.id.company_view);
49 | source = (TextView) findViewById(R.id.source_view);
50 | destination = (TextView) findViewById(R.id.dest_view);
51 | arrival = (TextView) findViewById(R.id.arrival_view);
52 | departure = (TextView) findViewById(R.id.departure_view);
53 | price = (TextView) findViewById(R.id.price_view);
54 | code = (TextView) findViewById(R.id.receipt_number_view);
55 | valid = (TextView) findViewById(R.id.valid_view);
56 | dateCreated = (TextView) findViewById(R.id.date);
57 |
58 | try {
59 | cursorPosition = getIntent().getIntExtra(Utils.CURSOR_POSITION, 0);
60 | Log.d(TAG, "onCreate: ###" + cursorPosition);
61 | if (Utils.HISTROY_FRAG_ACTIVE)
62 | ordersCursor = new OrdersSelection().valid(false).orderById(true).query(getContentResolver());
63 | else
64 | ordersCursor = new OrdersSelection().orderById(true).query(getContentResolver());
65 |
66 | ordersCursor.moveToPosition(cursorPosition);
67 | Log.d(TAG, "onCreate: CURSOR###" + ordersCursor.getCode() + ordersCursor.getValid());
68 | if (ordersCursor == null)
69 | throw new CursorIndexOutOfBoundsException("Cursor out of bounds");
70 | } catch (Exception e) {
71 | e.printStackTrace();
72 | }
73 |
74 | try {
75 | Log.d(TAG, "onCreate: ROUTE_ID ###" + ordersCursor.getRoute());
76 | Log.d(TAG, "onCreate: ROUTE_ID ###" + ordersCursor.getCode());
77 | Log.d(TAG, "onCreate: ROUTE_ID ###" + ordersCursor.getCustomer());
78 | RoutesCursor routesCursor = new RoutesSelection().routeid(Integer.valueOf(ordersCursor.getRoute())).query(getContentResolver());
79 | routesCursor.moveToFirst();
80 | Log.d(TAG, "onCreate: ROUTE COMPANY" + routesCursor.getBuscompanyname());
81 | company.setText(routesCursor.getBuscompanyname());
82 | source.setText(routesCursor.getSource());
83 | destination.setText(routesCursor.getDestination());
84 | arrival.setText(routesCursor.getArrival().toString());
85 | departure.setText(routesCursor.getDeparture().toString());
86 | price.setText(String.valueOf(routesCursor.getPrice()));
87 | Log.d(TAG, "onCreate: " + routesCursor.getBuscompanyimage());
88 | picassoLoader(this, toolbarImage, routesCursor.getBuscompanyimage());
89 | code.setText(ordersCursor.getCode());
90 | valid.setText(ordersCursor.getValid().toString());
91 | dateCreated.setText(ordersCursor.getDate().toString().substring(0, 10));
92 | ordersCursor.close();
93 | } catch (Exception e) {
94 | e.printStackTrace();
95 | }
96 |
97 | cancelButton = (Button) findViewById(R.id.cancel_button);
98 | cancelButton.setOnClickListener(new View.OnClickListener() {
99 |
100 | @Override
101 | public void onClick(View view) {
102 | finish();
103 | }
104 | });
105 | }
106 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/adapters/OrdersAdapter.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.adapters;
2 |
3 | import android.content.Context;
4 | import android.content.Intent;
5 | import android.support.v7.widget.RecyclerView;
6 | import android.util.Log;
7 | import android.view.LayoutInflater;
8 | import android.view.View;
9 | import android.view.ViewGroup;
10 | import android.widget.ImageView;
11 | import android.widget.TextView;
12 |
13 | import com.codephillip.app.busticket.OrderDetailsActivity;
14 | import com.codephillip.app.busticket.R;
15 | import com.codephillip.app.busticket.Utils;
16 | import com.codephillip.app.busticket.provider.orders.OrdersCursor;
17 | import com.codephillip.app.busticket.provider.routes.RoutesCursor;
18 | import com.codephillip.app.busticket.provider.routes.RoutesSelection;
19 |
20 | import static com.codephillip.app.busticket.Utils.picassoLoader;
21 |
22 | /**
23 | * Created by codephillip on 12/05/17.
24 | */
25 |
26 | public class OrdersAdapter extends RecyclerView.Adapter {
27 | private static final String TAG = OrdersAdapter.class.getSimpleName();
28 | private OrdersCursor dataCursor;
29 | private static Context context;
30 |
31 | public static class ViewHolder extends RecyclerView.ViewHolder {
32 | private ImageView imageView;
33 | private TextView companyNameView;
34 | private TextView sourceView;
35 | private TextView destinationView;
36 | private TextView departureView;
37 | private TextView priceView;
38 | private TextView validView;
39 | private TextView codeView;
40 |
41 | private ViewHolder(View v) {
42 | super(v);
43 | imageView = (ImageView) v.findViewById(R.id.image);
44 | companyNameView = (TextView) v.findViewById(R.id.company_view);
45 | sourceView = (TextView) v.findViewById(R.id.source_view);
46 | destinationView = (TextView) v.findViewById(R.id.dest_view);
47 | departureView = (TextView) v.findViewById(R.id.departure_view);
48 | priceView = (TextView) v.findViewById(R.id.price_view);
49 | validView = (TextView) v.findViewById(R.id.valid_view);
50 | codeView = (TextView) v.findViewById(R.id.code_view);
51 | }
52 | }
53 |
54 | public OrdersAdapter(Context context, OrdersCursor cursor) {
55 | Utils.getInstance();
56 | dataCursor = cursor;
57 | Utils.cursor = cursor;
58 | this.context = context;
59 | }
60 |
61 | public OrdersAdapter(Context context) {
62 | this.context = context;
63 | }
64 |
65 |
66 | @Override
67 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
68 | View cardview = LayoutInflater.from(parent.getContext())
69 | .inflate(R.layout.orders_row, parent, false);
70 | return new ViewHolder(cardview);
71 | }
72 |
73 | @Override
74 | public void onBindViewHolder(final ViewHolder holder, final int position) {
75 | dataCursor.moveToPosition(position);
76 | Log.d(TAG, "onBindViewHolder: attach");
77 | try {
78 | attackDataToViews(holder, position);
79 | } catch (Exception e) {
80 | e.printStackTrace();
81 | }
82 | holder.itemView.setOnClickListener(new View.OnClickListener() {
83 | @Override
84 | public void onClick(View view) {
85 | Log.d(TAG, "onClick: ");
86 | context.startActivity(new Intent(context, OrderDetailsActivity.class).putExtra(Utils.CURSOR_POSITION, position));
87 | }
88 | });
89 | }
90 |
91 | private void attackDataToViews(ViewHolder holder, int position) {
92 | Log.d(TAG, "attackDataToViews: ROUTE_ID" + dataCursor.getRoute());
93 | RoutesCursor routeCursor = new RoutesSelection().routeid(Integer.parseInt(dataCursor.getRoute())).query(context.getContentResolver());
94 | if (routeCursor.moveToFirst()) {
95 | try {
96 | holder.priceView.setText(String.valueOf(routeCursor.getPrice()));
97 | holder.companyNameView.setText(routeCursor.getBuscompanyname());
98 | holder.sourceView.setText("From: " + routeCursor.getSource());
99 | holder.destinationView.setText("To: " + routeCursor.getDestination());
100 | holder.departureView.setText("Departure: " + Utils.formatDateString(routeCursor.getDeparture().toString()));
101 | picassoLoader(context, holder.imageView, routeCursor.getBuscompanyimage());
102 | routeCursor.close();
103 | holder.validView.setText("Valid: " + dataCursor.getValid());
104 | holder.codeView.setText("Receipt: " + dataCursor.getCode());
105 | } catch (Exception e) {
106 | e.printStackTrace();
107 | }
108 | }
109 | }
110 |
111 | @Override
112 | public int getItemCount() {
113 | // any number other than zero will cause a bug
114 | return (dataCursor == null) ? 0 : dataCursor.getCount();
115 | }
116 | }
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/routes/RoutesContentValues.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.routes;
2 |
3 | import java.util.Date;
4 |
5 | import android.content.Context;
6 | import android.content.ContentResolver;
7 | import android.net.Uri;
8 | import android.support.annotation.NonNull;
9 | import android.support.annotation.Nullable;
10 |
11 | import com.codephillip.app.busticket.provider.base.AbstractContentValues;
12 |
13 | /**
14 | * Content values wrapper for the {@code routes} table.
15 | */
16 | public class RoutesContentValues extends AbstractContentValues {
17 | @Override
18 | public Uri uri() {
19 | return RoutesColumns.CONTENT_URI;
20 | }
21 |
22 | /**
23 | * Update row(s) using the values stored by this object and the given selection.
24 | *
25 | * @param contentResolver The content resolver to use.
26 | * @param where The selection to use (can be {@code null}).
27 | */
28 | public int update(ContentResolver contentResolver, @Nullable RoutesSelection where) {
29 | return contentResolver.update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
30 | }
31 |
32 | /**
33 | * Update row(s) using the values stored by this object and the given selection.
34 | *
35 | * @param contentResolver The content resolver to use.
36 | * @param where The selection to use (can be {@code null}).
37 | */
38 | public int update(Context context, @Nullable RoutesSelection where) {
39 | return context.getContentResolver().update(uri(), values(), where == null ? null : where.sel(), where == null ? null : where.args());
40 | }
41 |
42 | public RoutesContentValues putRouteid(@Nullable Integer value) {
43 | mContentValues.put(RoutesColumns.ROUTEID, value);
44 | return this;
45 | }
46 |
47 | public RoutesContentValues putRouteidNull() {
48 | mContentValues.putNull(RoutesColumns.ROUTEID);
49 | return this;
50 | }
51 |
52 | public RoutesContentValues putCode(@Nullable Integer value) {
53 | mContentValues.put(RoutesColumns.CODE, value);
54 | return this;
55 | }
56 |
57 | public RoutesContentValues putCodeNull() {
58 | mContentValues.putNull(RoutesColumns.CODE);
59 | return this;
60 | }
61 |
62 | public RoutesContentValues putSource(@Nullable String value) {
63 | mContentValues.put(RoutesColumns.SOURCE, value);
64 | return this;
65 | }
66 |
67 | public RoutesContentValues putSourceNull() {
68 | mContentValues.putNull(RoutesColumns.SOURCE);
69 | return this;
70 | }
71 |
72 | public RoutesContentValues putDestination(@Nullable String value) {
73 | mContentValues.put(RoutesColumns.DESTINATION, value);
74 | return this;
75 | }
76 |
77 | public RoutesContentValues putDestinationNull() {
78 | mContentValues.putNull(RoutesColumns.DESTINATION);
79 | return this;
80 | }
81 |
82 | public RoutesContentValues putBuscompanyname(@Nullable String value) {
83 | mContentValues.put(RoutesColumns.BUSCOMPANYNAME, value);
84 | return this;
85 | }
86 |
87 | public RoutesContentValues putBuscompanynameNull() {
88 | mContentValues.putNull(RoutesColumns.BUSCOMPANYNAME);
89 | return this;
90 | }
91 |
92 | public RoutesContentValues putBuscompanyimage(@Nullable String value) {
93 | mContentValues.put(RoutesColumns.BUSCOMPANYIMAGE, value);
94 | return this;
95 | }
96 |
97 | public RoutesContentValues putBuscompanyimageNull() {
98 | mContentValues.putNull(RoutesColumns.BUSCOMPANYIMAGE);
99 | return this;
100 | }
101 |
102 | public RoutesContentValues putPrice(@Nullable Integer value) {
103 | mContentValues.put(RoutesColumns.PRICE, value);
104 | return this;
105 | }
106 |
107 | public RoutesContentValues putPriceNull() {
108 | mContentValues.putNull(RoutesColumns.PRICE);
109 | return this;
110 | }
111 |
112 | public RoutesContentValues putArrival(@Nullable Date value) {
113 | mContentValues.put(RoutesColumns.ARRIVAL, value == null ? null : value.getTime());
114 | return this;
115 | }
116 |
117 | public RoutesContentValues putArrivalNull() {
118 | mContentValues.putNull(RoutesColumns.ARRIVAL);
119 | return this;
120 | }
121 |
122 | public RoutesContentValues putArrival(@Nullable Long value) {
123 | mContentValues.put(RoutesColumns.ARRIVAL, value);
124 | return this;
125 | }
126 |
127 | public RoutesContentValues putDeparture(@Nullable Date value) {
128 | mContentValues.put(RoutesColumns.DEPARTURE, value == null ? null : value.getTime());
129 | return this;
130 | }
131 |
132 | public RoutesContentValues putDepartureNull() {
133 | mContentValues.putNull(RoutesColumns.DEPARTURE);
134 | return this;
135 | }
136 |
137 | public RoutesContentValues putDeparture(@Nullable Long value) {
138 | mContentValues.put(RoutesColumns.DEPARTURE, value);
139 | return this;
140 | }
141 | }
142 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/BusTicketSQLiteOpenHelper.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider;
2 |
3 | import android.annotation.TargetApi;
4 | import android.content.Context;
5 | import android.database.DatabaseErrorHandler;
6 | import android.database.DefaultDatabaseErrorHandler;
7 | import android.database.sqlite.SQLiteDatabase;
8 | import android.database.sqlite.SQLiteOpenHelper;
9 | import android.os.Build;
10 | import android.util.Log;
11 |
12 | import com.codephillip.app.busticket.BuildConfig;
13 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
14 | import com.codephillip.app.busticket.provider.orders.OrdersColumns;
15 | import com.codephillip.app.busticket.provider.routes.RoutesColumns;
16 |
17 | public class BusTicketSQLiteOpenHelper extends SQLiteOpenHelper {
18 | private static final String TAG = BusTicketSQLiteOpenHelper.class.getSimpleName();
19 |
20 | public static final String DATABASE_FILE_NAME = "BusTicket.db";
21 | private static final int DATABASE_VERSION = 1;
22 | private static BusTicketSQLiteOpenHelper sInstance;
23 | private final Context mContext;
24 | private final BusTicketSQLiteOpenHelperCallbacks mOpenHelperCallbacks;
25 |
26 | // @formatter:off
27 | public static final String SQL_CREATE_TABLE_LOCATIONS = "CREATE TABLE IF NOT EXISTS "
28 | + LocationsColumns.TABLE_NAME + " ( "
29 | + LocationsColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
30 | + LocationsColumns.NAME + " TEXT, "
31 | + LocationsColumns.LATITUDE + " REAL, "
32 | + LocationsColumns.LONGITUDE + " REAL "
33 | + " );";
34 |
35 | public static final String SQL_CREATE_TABLE_ORDERS = "CREATE TABLE IF NOT EXISTS "
36 | + OrdersColumns.TABLE_NAME + " ( "
37 | + OrdersColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
38 | + OrdersColumns.CODE + " TEXT, "
39 | + OrdersColumns.VALID + " INTEGER, "
40 | + OrdersColumns.DATECREATED + " INTEGER, "
41 | + OrdersColumns.DATE + " INTEGER, "
42 | + OrdersColumns.CUSTOMER + " TEXT, "
43 | + OrdersColumns.ROUTE + " TEXT "
44 | + " );";
45 |
46 | public static final String SQL_CREATE_TABLE_ROUTES = "CREATE TABLE IF NOT EXISTS "
47 | + RoutesColumns.TABLE_NAME + " ( "
48 | + RoutesColumns._ID + " INTEGER PRIMARY KEY AUTOINCREMENT, "
49 | + RoutesColumns.ROUTEID + " INTEGER, "
50 | + RoutesColumns.CODE + " INTEGER, "
51 | + RoutesColumns.SOURCE + " TEXT, "
52 | + RoutesColumns.DESTINATION + " TEXT, "
53 | + RoutesColumns.BUSCOMPANYNAME + " TEXT, "
54 | + RoutesColumns.BUSCOMPANYIMAGE + " TEXT, "
55 | + RoutesColumns.PRICE + " INTEGER, "
56 | + RoutesColumns.ARRIVAL + " INTEGER, "
57 | + RoutesColumns.DEPARTURE + " INTEGER "
58 | + " );";
59 |
60 | // @formatter:on
61 |
62 | public static BusTicketSQLiteOpenHelper getInstance(Context context) {
63 | // Use the application context, which will ensure that you
64 | // don't accidentally leak an Activity's context.
65 | // See this article for more information: http://bit.ly/6LRzfx
66 | if (sInstance == null) {
67 | sInstance = newInstance(context.getApplicationContext());
68 | }
69 | return sInstance;
70 | }
71 |
72 | private static BusTicketSQLiteOpenHelper newInstance(Context context) {
73 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
74 | return newInstancePreHoneycomb(context);
75 | }
76 | return newInstancePostHoneycomb(context);
77 | }
78 |
79 |
80 | /*
81 | * Pre Honeycomb.
82 | */
83 | private static BusTicketSQLiteOpenHelper newInstancePreHoneycomb(Context context) {
84 | return new BusTicketSQLiteOpenHelper(context);
85 | }
86 |
87 | private BusTicketSQLiteOpenHelper(Context context) {
88 | super(context, DATABASE_FILE_NAME, null, DATABASE_VERSION);
89 | mContext = context;
90 | mOpenHelperCallbacks = new BusTicketSQLiteOpenHelperCallbacks();
91 | }
92 |
93 |
94 | /*
95 | * Post Honeycomb.
96 | */
97 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
98 | private static BusTicketSQLiteOpenHelper newInstancePostHoneycomb(Context context) {
99 | return new BusTicketSQLiteOpenHelper(context, new DefaultDatabaseErrorHandler());
100 | }
101 |
102 | @TargetApi(Build.VERSION_CODES.HONEYCOMB)
103 | private BusTicketSQLiteOpenHelper(Context context, DatabaseErrorHandler errorHandler) {
104 | super(context, DATABASE_FILE_NAME, null, DATABASE_VERSION, errorHandler);
105 | mContext = context;
106 | mOpenHelperCallbacks = new BusTicketSQLiteOpenHelperCallbacks();
107 | }
108 |
109 |
110 | @Override
111 | public void onCreate(SQLiteDatabase db) {
112 | if (BuildConfig.DEBUG) Log.d(TAG, "onCreate");
113 | mOpenHelperCallbacks.onPreCreate(mContext, db);
114 | db.execSQL(SQL_CREATE_TABLE_LOCATIONS);
115 | db.execSQL(SQL_CREATE_TABLE_ORDERS);
116 | db.execSQL(SQL_CREATE_TABLE_ROUTES);
117 | mOpenHelperCallbacks.onPostCreate(mContext, db);
118 | }
119 |
120 | @Override
121 | public void onOpen(SQLiteDatabase db) {
122 | super.onOpen(db);
123 | mOpenHelperCallbacks.onOpen(mContext, db);
124 | }
125 |
126 | @Override
127 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
128 | mOpenHelperCallbacks.onUpgrade(mContext, db, oldVersion, newVersion);
129 | }
130 | }
131 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/adapters/SeatGridAdapter.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.adapters;
2 |
3 | import android.content.Context;
4 | import android.content.SharedPreferences;
5 | import android.preference.PreferenceManager;
6 | import android.support.v7.widget.RecyclerView;
7 | import android.util.Log;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.ViewGroup;
11 | import android.widget.ImageView;
12 | import android.widget.TextView;
13 |
14 | import com.codephillip.app.busticket.R;
15 | import com.codephillip.app.busticket.Utils;
16 |
17 | import static com.codephillip.app.busticket.Constants.HAS_BOOKED;
18 |
19 | /**
20 | * Created by codephillip on 31/03/17.
21 | */
22 |
23 | public class SeatGridAdapter extends RecyclerView.Adapter {
24 |
25 | private static final String TAG = SeatGridAdapter.class.getSimpleName();
26 | private final Utils utils;
27 | private LayoutInflater mInflater;
28 | private static Context context;
29 | private ItemClickListener mClickListener;
30 | private ImageView oldSeatView;
31 | private TextView oldNumberView;
32 |
33 |
34 | public SeatGridAdapter(Context context) {
35 | Log.d(TAG, "SeatGridAdapter: ATTACHED");
36 | this.mInflater = LayoutInflater.from(context);
37 | this.context = context;
38 | utils = new Utils(context);
39 | utils.savePrefBoolean(HAS_BOOKED, false);
40 | }
41 |
42 |
43 | // stores and recycles views as they are scrolled off screen
44 | public class ViewHolder extends RecyclerView.ViewHolder {
45 | public TextView seatNumberText;
46 | public ImageView seatView;
47 |
48 | public ViewHolder(View itemView) {
49 | super(itemView);
50 | seatNumberText = (TextView) itemView.findViewById(R.id.seat_number);
51 | seatView = (ImageView) itemView.findViewById(R.id.seat_image);
52 | }
53 | }
54 |
55 | // inflates the cell layout from xml when needed
56 | @Override
57 | public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
58 | View view = mInflater.inflate(R.layout.recyclerview_item, parent, false);
59 | ViewHolder viewHolder = new ViewHolder(view);
60 | return viewHolder;
61 | }
62 |
63 | @Override
64 | public void onBindViewHolder(final ViewHolder holder, final int position) {
65 | // cursor.moveToPosition(position);
66 | holder.seatNumberText.setText(String.valueOf(position + 1));
67 | holder.itemView.setOnClickListener(new View.OnClickListener() {
68 | @Override
69 | public void onClick(View view) {
70 | changeSeatColourWhenBooked(holder.seatView, holder.seatNumberText);
71 | if (mClickListener != null)
72 | mClickListener.onItemClick(view, position);
73 | }
74 | });
75 | //todo replace with actual number of seats available
76 | //randomly place booked seats
77 | changeSeatColourRandomly(holder.seatView, holder.seatNumberText);
78 | }
79 |
80 | private void changeSeatColourWhenBooked(ImageView seatView, TextView numberView) {
81 | if (utils.getPrefBoolean(HAS_BOOKED)) {
82 | changeSeatColour(seatView, numberView);
83 | } else {
84 | setSeatColour(seatView, numberView, context.getResources().getColor((R.color.colorAccent)));
85 | }
86 |
87 | oldSeatView = seatView;
88 | oldNumberView = numberView;
89 | saveSeatNumber(numberView.getText().toString());
90 | utils.savePrefBoolean(HAS_BOOKED, true);
91 | }
92 |
93 | private void changeSeatColour(ImageView seatView, TextView numberView) {
94 | if (!oldSeatView.equals(seatView) && !oldNumberView.equals(numberView)) {
95 | setSeatColour(oldSeatView, oldNumberView, context.getResources().getColor((R.color.grey)));
96 | setSeatColour(seatView, numberView, context.getResources().getColor((R.color.colorAccent)));
97 | }
98 | }
99 |
100 | private void changeSeatColourRandomly(ImageView seatView, TextView numberView) {
101 | int colorId;
102 | if (getRandomBoolean())
103 | colorId = R.color.colorAccent;
104 | else
105 | colorId = R.color.grey;
106 | setSeatColour(seatView, numberView, context.getResources().getColor((colorId)));
107 | }
108 |
109 | private boolean getRandomBoolean() {
110 | return Math.random() < 0.5;
111 | }
112 |
113 | private void setSeatColour(ImageView seatView, TextView numberView, int color) {
114 | seatView.setColorFilter(color);
115 | numberView.setTextColor(color);
116 | }
117 |
118 | // total number of cells
119 | @Override
120 | public int getItemCount() {
121 | // return cursor.getCount();
122 | return 20;
123 | }
124 |
125 | // allows clicks events to be caught
126 | public void setClickListener(ItemClickListener itemClickListener) {
127 | this.mClickListener = itemClickListener;
128 | }
129 |
130 | // parent activity will implement this method to respond to click events
131 | public interface ItemClickListener {
132 | void onItemClick(View view, int position);
133 | }
134 |
135 | private void saveSeatNumber(String seatNumber) {
136 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
137 | SharedPreferences.Editor editor = prefs.edit();
138 | editor.putString(Utils.SEAT_NUMBER, seatNumber);
139 | editor.apply();
140 | }
141 |
142 | private String getSeatNumber() {
143 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
144 | return prefs.getString(Utils.SEAT_NUMBER, "1");
145 | }
146 | }
--------------------------------------------------------------------------------
/app/src/main/res/layout/activity_signup.xml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
21 |
22 |
26 |
27 |
32 |
33 |
36 |
45 |
46 |
47 |
50 |
58 |
59 |
60 |
63 |
72 |
73 |
74 |
77 |
85 |
86 |
87 |
90 |
101 |
102 |
103 |
106 |
117 |
118 |
119 |
129 |
130 |
131 |
132 |
133 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/locations/LocationsSelection.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider.locations;
2 |
3 | import java.util.Date;
4 |
5 | import android.content.Context;
6 | import android.content.ContentResolver;
7 | import android.database.Cursor;
8 | import android.net.Uri;
9 |
10 | import com.codephillip.app.busticket.provider.base.AbstractSelection;
11 |
12 | /**
13 | * Selection for the {@code locations} table.
14 | */
15 | public class LocationsSelection extends AbstractSelection {
16 | @Override
17 | protected Uri baseUri() {
18 | return LocationsColumns.CONTENT_URI;
19 | }
20 |
21 | /**
22 | * Query the given content resolver using this selection.
23 | *
24 | * @param contentResolver The content resolver to query.
25 | * @param projection A list of which columns to return. Passing null will return all columns, which is inefficient.
26 | * @return A {@code LocationsCursor} object, which is positioned before the first entry, or null.
27 | */
28 | public LocationsCursor query(ContentResolver contentResolver, String[] projection) {
29 | Cursor cursor = contentResolver.query(uri(), projection, sel(), args(), order());
30 | if (cursor == null) return null;
31 | return new LocationsCursor(cursor);
32 | }
33 |
34 | /**
35 | * Equivalent of calling {@code query(contentResolver, null)}.
36 | */
37 | public LocationsCursor query(ContentResolver contentResolver) {
38 | return query(contentResolver, null);
39 | }
40 |
41 | /**
42 | * Query the given content resolver using this selection.
43 | *
44 | * @param context The context to use for the query.
45 | * @param projection A list of which columns to return. Passing null will return all columns, which is inefficient.
46 | * @return A {@code LocationsCursor} object, which is positioned before the first entry, or null.
47 | */
48 | public LocationsCursor query(Context context, String[] projection) {
49 | Cursor cursor = context.getContentResolver().query(uri(), projection, sel(), args(), order());
50 | if (cursor == null) return null;
51 | return new LocationsCursor(cursor);
52 | }
53 |
54 | /**
55 | * Equivalent of calling {@code query(context, null)}.
56 | */
57 | public LocationsCursor query(Context context) {
58 | return query(context, null);
59 | }
60 |
61 |
62 | public LocationsSelection id(long... value) {
63 | addEquals("locations." + LocationsColumns._ID, toObjectArray(value));
64 | return this;
65 | }
66 |
67 | public LocationsSelection idNot(long... value) {
68 | addNotEquals("locations." + LocationsColumns._ID, toObjectArray(value));
69 | return this;
70 | }
71 |
72 | public LocationsSelection orderById(boolean desc) {
73 | orderBy("locations." + LocationsColumns._ID, desc);
74 | return this;
75 | }
76 |
77 | public LocationsSelection orderById() {
78 | return orderById(false);
79 | }
80 |
81 | public LocationsSelection name(String... value) {
82 | addEquals(LocationsColumns.NAME, value);
83 | return this;
84 | }
85 |
86 | public LocationsSelection nameNot(String... value) {
87 | addNotEquals(LocationsColumns.NAME, value);
88 | return this;
89 | }
90 |
91 | public LocationsSelection nameLike(String... value) {
92 | addLike(LocationsColumns.NAME, value);
93 | return this;
94 | }
95 |
96 | public LocationsSelection nameContains(String... value) {
97 | addContains(LocationsColumns.NAME, value);
98 | return this;
99 | }
100 |
101 | public LocationsSelection nameStartsWith(String... value) {
102 | addStartsWith(LocationsColumns.NAME, value);
103 | return this;
104 | }
105 |
106 | public LocationsSelection nameEndsWith(String... value) {
107 | addEndsWith(LocationsColumns.NAME, value);
108 | return this;
109 | }
110 |
111 | public LocationsSelection orderByName(boolean desc) {
112 | orderBy(LocationsColumns.NAME, desc);
113 | return this;
114 | }
115 |
116 | public LocationsSelection orderByName() {
117 | orderBy(LocationsColumns.NAME, false);
118 | return this;
119 | }
120 |
121 | public LocationsSelection latitude(Double... value) {
122 | addEquals(LocationsColumns.LATITUDE, value);
123 | return this;
124 | }
125 |
126 | public LocationsSelection latitudeNot(Double... value) {
127 | addNotEquals(LocationsColumns.LATITUDE, value);
128 | return this;
129 | }
130 |
131 | public LocationsSelection latitudeGt(double value) {
132 | addGreaterThan(LocationsColumns.LATITUDE, value);
133 | return this;
134 | }
135 |
136 | public LocationsSelection latitudeGtEq(double value) {
137 | addGreaterThanOrEquals(LocationsColumns.LATITUDE, value);
138 | return this;
139 | }
140 |
141 | public LocationsSelection latitudeLt(double value) {
142 | addLessThan(LocationsColumns.LATITUDE, value);
143 | return this;
144 | }
145 |
146 | public LocationsSelection latitudeLtEq(double value) {
147 | addLessThanOrEquals(LocationsColumns.LATITUDE, value);
148 | return this;
149 | }
150 |
151 | public LocationsSelection orderByLatitude(boolean desc) {
152 | orderBy(LocationsColumns.LATITUDE, desc);
153 | return this;
154 | }
155 |
156 | public LocationsSelection orderByLatitude() {
157 | orderBy(LocationsColumns.LATITUDE, false);
158 | return this;
159 | }
160 |
161 | public LocationsSelection longitude(Double... value) {
162 | addEquals(LocationsColumns.LONGITUDE, value);
163 | return this;
164 | }
165 |
166 | public LocationsSelection longitudeNot(Double... value) {
167 | addNotEquals(LocationsColumns.LONGITUDE, value);
168 | return this;
169 | }
170 |
171 | public LocationsSelection longitudeGt(double value) {
172 | addGreaterThan(LocationsColumns.LONGITUDE, value);
173 | return this;
174 | }
175 |
176 | public LocationsSelection longitudeGtEq(double value) {
177 | addGreaterThanOrEquals(LocationsColumns.LONGITUDE, value);
178 | return this;
179 | }
180 |
181 | public LocationsSelection longitudeLt(double value) {
182 | addLessThan(LocationsColumns.LONGITUDE, value);
183 | return this;
184 | }
185 |
186 | public LocationsSelection longitudeLtEq(double value) {
187 | addLessThanOrEquals(LocationsColumns.LONGITUDE, value);
188 | return this;
189 | }
190 |
191 | public LocationsSelection orderByLongitude(boolean desc) {
192 | orderBy(LocationsColumns.LONGITUDE, desc);
193 | return this;
194 | }
195 |
196 | public LocationsSelection orderByLongitude() {
197 | orderBy(LocationsColumns.LONGITUDE, false);
198 | return this;
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/app/src/main/java/com/codephillip/app/busticket/provider/BusTicketProvider.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket.provider;
2 |
3 | import java.util.Arrays;
4 |
5 | import android.content.ContentValues;
6 | import android.content.UriMatcher;
7 | import android.database.Cursor;
8 | import android.database.sqlite.SQLiteOpenHelper;
9 | import android.net.Uri;
10 | import android.support.annotation.NonNull;
11 | import android.util.Log;
12 |
13 | import com.codephillip.app.busticket.BuildConfig;
14 | import com.codephillip.app.busticket.provider.base.BaseContentProvider;
15 | import com.codephillip.app.busticket.provider.locations.LocationsColumns;
16 | import com.codephillip.app.busticket.provider.orders.OrdersColumns;
17 | import com.codephillip.app.busticket.provider.routes.RoutesColumns;
18 |
19 | public class BusTicketProvider extends BaseContentProvider {
20 | private static final String TAG = BusTicketProvider.class.getSimpleName();
21 |
22 | private static final boolean DEBUG = BuildConfig.DEBUG;
23 |
24 | private static final String TYPE_CURSOR_ITEM = "vnd.android.cursor.item/";
25 | private static final String TYPE_CURSOR_DIR = "vnd.android.cursor.dir/";
26 |
27 | public static final String AUTHORITY = "com.codephillip.app.busticket.provider";
28 | public static final String CONTENT_URI_BASE = "content://" + AUTHORITY;
29 |
30 | private static final int URI_TYPE_LOCATIONS = 0;
31 | private static final int URI_TYPE_LOCATIONS_ID = 1;
32 |
33 | private static final int URI_TYPE_ORDERS = 2;
34 | private static final int URI_TYPE_ORDERS_ID = 3;
35 |
36 | private static final int URI_TYPE_ROUTES = 4;
37 | private static final int URI_TYPE_ROUTES_ID = 5;
38 |
39 |
40 |
41 | private static final UriMatcher URI_MATCHER = new UriMatcher(UriMatcher.NO_MATCH);
42 |
43 | static {
44 | URI_MATCHER.addURI(AUTHORITY, LocationsColumns.TABLE_NAME, URI_TYPE_LOCATIONS);
45 | URI_MATCHER.addURI(AUTHORITY, LocationsColumns.TABLE_NAME + "/#", URI_TYPE_LOCATIONS_ID);
46 | URI_MATCHER.addURI(AUTHORITY, OrdersColumns.TABLE_NAME, URI_TYPE_ORDERS);
47 | URI_MATCHER.addURI(AUTHORITY, OrdersColumns.TABLE_NAME + "/#", URI_TYPE_ORDERS_ID);
48 | URI_MATCHER.addURI(AUTHORITY, RoutesColumns.TABLE_NAME, URI_TYPE_ROUTES);
49 | URI_MATCHER.addURI(AUTHORITY, RoutesColumns.TABLE_NAME + "/#", URI_TYPE_ROUTES_ID);
50 | }
51 |
52 | @Override
53 | protected SQLiteOpenHelper createSqLiteOpenHelper() {
54 | return BusTicketSQLiteOpenHelper.getInstance(getContext());
55 | }
56 |
57 | @Override
58 | protected boolean hasDebug() {
59 | return DEBUG;
60 | }
61 |
62 | @Override
63 | public String getType(Uri uri) {
64 | int match = URI_MATCHER.match(uri);
65 | switch (match) {
66 | case URI_TYPE_LOCATIONS:
67 | return TYPE_CURSOR_DIR + LocationsColumns.TABLE_NAME;
68 | case URI_TYPE_LOCATIONS_ID:
69 | return TYPE_CURSOR_ITEM + LocationsColumns.TABLE_NAME;
70 |
71 | case URI_TYPE_ORDERS:
72 | return TYPE_CURSOR_DIR + OrdersColumns.TABLE_NAME;
73 | case URI_TYPE_ORDERS_ID:
74 | return TYPE_CURSOR_ITEM + OrdersColumns.TABLE_NAME;
75 |
76 | case URI_TYPE_ROUTES:
77 | return TYPE_CURSOR_DIR + RoutesColumns.TABLE_NAME;
78 | case URI_TYPE_ROUTES_ID:
79 | return TYPE_CURSOR_ITEM + RoutesColumns.TABLE_NAME;
80 |
81 | }
82 | return null;
83 | }
84 |
85 | @Override
86 | public Uri insert(Uri uri, ContentValues values) {
87 | if (DEBUG) Log.d(TAG, "insert uri=" + uri + " values=" + values);
88 | return super.insert(uri, values);
89 | }
90 |
91 | @Override
92 | public int bulkInsert(Uri uri, ContentValues[] values) {
93 | if (DEBUG) Log.d(TAG, "bulkInsert uri=" + uri + " values.length=" + values.length);
94 | return super.bulkInsert(uri, values);
95 | }
96 |
97 | @Override
98 | public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
99 | if (DEBUG) Log.d(TAG, "update uri=" + uri + " values=" + values + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs));
100 | return super.update(uri, values, selection, selectionArgs);
101 | }
102 |
103 | @Override
104 | public int delete(Uri uri, String selection, String[] selectionArgs) {
105 | if (DEBUG) Log.d(TAG, "delete uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs));
106 | return super.delete(uri, selection, selectionArgs);
107 | }
108 |
109 | @Override
110 | public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
111 | if (DEBUG)
112 | Log.d(TAG, "query uri=" + uri + " selection=" + selection + " selectionArgs=" + Arrays.toString(selectionArgs) + " sortOrder=" + sortOrder
113 | + " groupBy=" + uri.getQueryParameter(QUERY_GROUP_BY) + " having=" + uri.getQueryParameter(QUERY_HAVING) + " limit=" + uri.getQueryParameter(QUERY_LIMIT));
114 | return super.query(uri, projection, selection, selectionArgs, sortOrder);
115 | }
116 |
117 | @Override
118 | protected QueryParams getQueryParams(Uri uri, String selection, String[] projection) {
119 | QueryParams res = new QueryParams();
120 | String id = null;
121 | int matchedId = URI_MATCHER.match(uri);
122 | switch (matchedId) {
123 | case URI_TYPE_LOCATIONS:
124 | case URI_TYPE_LOCATIONS_ID:
125 | res.table = LocationsColumns.TABLE_NAME;
126 | res.idColumn = LocationsColumns._ID;
127 | res.tablesWithJoins = LocationsColumns.TABLE_NAME;
128 | res.orderBy = LocationsColumns.DEFAULT_ORDER;
129 | break;
130 |
131 | case URI_TYPE_ORDERS:
132 | case URI_TYPE_ORDERS_ID:
133 | res.table = OrdersColumns.TABLE_NAME;
134 | res.idColumn = OrdersColumns._ID;
135 | res.tablesWithJoins = OrdersColumns.TABLE_NAME;
136 | res.orderBy = OrdersColumns.DEFAULT_ORDER;
137 | break;
138 |
139 | case URI_TYPE_ROUTES:
140 | case URI_TYPE_ROUTES_ID:
141 | res.table = RoutesColumns.TABLE_NAME;
142 | res.idColumn = RoutesColumns._ID;
143 | res.tablesWithJoins = RoutesColumns.TABLE_NAME;
144 | res.orderBy = RoutesColumns.DEFAULT_ORDER;
145 | break;
146 |
147 | default:
148 | throw new IllegalArgumentException("The uri '" + uri + "' is not supported by this ContentProvider");
149 | }
150 |
151 | switch (matchedId) {
152 | case URI_TYPE_LOCATIONS_ID:
153 | case URI_TYPE_ORDERS_ID:
154 | case URI_TYPE_ROUTES_ID:
155 | id = uri.getLastPathSegment();
156 | }
157 | if (id != null) {
158 | if (selection != null) {
159 | res.selection = res.table + "." + res.idColumn + "=" + id + " and (" + selection + ")";
160 | } else {
161 | res.selection = res.table + "." + res.idColumn + "=" + id;
162 | }
163 | } else {
164 | res.selection = selection;
165 | }
166 | return res;
167 | }
168 | }
169 |
--------------------------------------------------------------------------------
/app/src/test/java/com/codephillip/app/busticket/GeneralUnitTest.java:
--------------------------------------------------------------------------------
1 | package com.codephillip.app.busticket;
2 |
3 | import org.junit.Test;
4 |
5 | import java.util.Date;
6 |
7 | import static org.junit.Assert.assertEquals;
8 |
9 | public class GeneralUnitTest {
10 |
11 | @Test
12 | public void addition_isCorrect() throws Exception {
13 | assertEquals(4, 2 + 2);
14 | }
15 |
16 | @Test
17 | public void checkServerSoapString() throws Exception {
18 | String soapString = "\n" +
19 | "\n" +
20 | " \n" +
21 | " \n" +
22 | " 2560110004776\n" +
23 | " BD3B1BB8B4822636B7520B96C4A568C7\n" +
24 | " \n" +
25 | " \n" +
26 | " 20170503144638\n" +
27 | " \n" +
28 | " \n" +
29 | " \n" +
30 | " \n" +
31 | " 200\n" +
32 | " \n" +
33 | " DueAmount\n" +
34 | " 500\n" +
35 | " \n" +
36 | " \n" +
37 | " MSISDNNum\n" +
38 | " 256789900760\n" +
39 | " \n" +
40 | " \n" +
41 | " ProcessingNumber\n" +
42 | " \n" +
43 | " %s\n" +
44 | " \n" +
45 | " \n" +
46 | " serviceId\n" +
47 | " appchallenge3.sp\n" +
48 | " \n" +
49 | " \n" +
50 | " AcctRef\n" +
51 | " 101\n" +
52 | " \n" +
53 | " \n" +
54 | " AcctBalance\n" +
55 | " 300000\n" +
56 | " \n" +
57 | " \n" +
58 | " MinDueAmount\n" +
59 | " 200\n" +
60 | " \n" +
61 | " \n" +
62 | " Narration\n" +
63 | " You have made payment for a bus ticket\n" +
64 | " \n" +
65 | " \n" +
66 | " PrefLang\n" +
67 | " en\n" +
68 | " \n" +
69 | " \n" +
70 | " OpCoID\n" +
71 | " 25601\n" +
72 | " \n" +
73 | " \n" +
74 | " CurrCode\n" +
75 | " UGX\n" +
76 | " \n" +
77 | " \n" +
78 | " \n" +
79 | "";
80 |
81 | String expectedSoapString = "\n" +
82 | "\n" +
83 | " \n" +
84 | " \n" +
85 | " 2560110004776\n" +
86 | " BD3B1BB8B4822636B7520B96C4A568C7\n" +
87 | " \n" +
88 | " \n" +
89 | " 20170503144638\n" +
90 | " \n" +
91 | " \n" +
92 | " \n" +
93 | " \n" +
94 | " 200\n" +
95 | " \n" +
96 | " DueAmount\n" +
97 | " 500\n" +
98 | " \n" +
99 | " \n" +
100 | " MSISDNNum\n" +
101 | " 256789900760\n" +
102 | " \n" +
103 | " \n" +
104 | " ProcessingNumber\n" +
105 | " \n" +
106 | " hello\n" +
107 | " \n" +
108 | " \n" +
109 | " serviceId\n" +
110 | " appchallenge3.sp\n" +
111 | " \n" +
112 | " \n" +
113 | " AcctRef\n" +
114 | " 101\n" +
115 | " \n" +
116 | " \n" +
117 | " AcctBalance\n" +
118 | " 300000\n" +
119 | " \n" +
120 | " \n" +
121 | " MinDueAmount\n" +
122 | " 200\n" +
123 | " \n" +
124 | " \n" +
125 | " Narration\n" +
126 | " You have made payment for a bus ticket\n" +
127 | " \n" +
128 | " \n" +
129 | " PrefLang\n" +
130 | " en\n" +
131 | " \n" +
132 | " \n" +
133 | " OpCoID\n" +
134 | " 25601\n" +
135 | " \n" +
136 | " \n" +
137 | " CurrCode\n" +
138 | " UGX\n" +
139 | " \n" +
140 | " \n" +
141 | " \n" +
142 | "";
143 |
144 | soapString = String.format(soapString, "hello");
145 |
146 | assertEquals(expectedSoapString, soapString);
147 | }
148 |
149 | @Test
150 | public void testFormatDate() throws Exception {
151 | assertEquals("Wed Aug 30", Utils.formatDateString(new Date().toString()));
152 | }
153 | }
--------------------------------------------------------------------------------