├── app
├── .gitignore
├── src
│ ├── main
│ │ ├── ic_launcher-web.png
│ │ ├── res
│ │ │ ├── mipmap-hdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-mdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-xxxhdpi
│ │ │ │ ├── ic_launcher.png
│ │ │ │ ├── ic_launcher_round.png
│ │ │ │ └── ic_launcher_foreground.png
│ │ │ ├── mipmap-anydpi
│ │ │ │ ├── ic_launcher.xml
│ │ │ │ └── ic_launcher_round.xml
│ │ │ ├── drawable
│ │ │ │ ├── ic_arrow_drop_down_black_24dp.xml
│ │ │ │ ├── ic_refresh_white_24dp.xml
│ │ │ │ └── ic_github_white_24dp.xml
│ │ │ ├── menu
│ │ │ │ └── activity_theatre.xml
│ │ │ ├── xml
│ │ │ │ └── backup_descriptor.xml
│ │ │ ├── values
│ │ │ │ ├── colors.xml
│ │ │ │ ├── dimens.xml
│ │ │ │ ├── strings.xml
│ │ │ │ └── styles.xml
│ │ │ └── layout
│ │ │ │ ├── holder_empty_seat.xml
│ │ │ │ ├── holder_chosen_seat.xml
│ │ │ │ ├── holder_reserved_seat.xml
│ │ │ │ ├── holder_unchosen_seat.xml
│ │ │ │ └── activity_theatre.xml
│ │ ├── java
│ │ │ └── io
│ │ │ │ └── github
│ │ │ │ └── lamtran
│ │ │ │ └── moviebooking
│ │ │ │ ├── presentation
│ │ │ │ ├── view
│ │ │ │ │ ├── base
│ │ │ │ │ │ ├── HasBoundData.java
│ │ │ │ │ │ ├── screen
│ │ │ │ │ │ │ ├── IsScreen.java
│ │ │ │ │ │ │ ├── IsScreenController.java
│ │ │ │ │ │ │ ├── ScreenController.java
│ │ │ │ │ │ │ └── BaseActivity.java
│ │ │ │ │ │ ├── controller
│ │ │ │ │ │ │ ├── IsController.java
│ │ │ │ │ │ │ └── BaseController.java
│ │ │ │ │ │ └── adapter
│ │ │ │ │ │ │ ├── IsHolderFactory.java
│ │ │ │ │ │ │ └── BaseAdapter.java
│ │ │ │ │ └── theatre
│ │ │ │ │ │ ├── seat
│ │ │ │ │ │ ├── SeatChanger.java
│ │ │ │ │ │ ├── EmptySeatHolder.java
│ │ │ │ │ │ ├── ChosenSeatHolder.java
│ │ │ │ │ │ ├── ReservedSeatHolder.java
│ │ │ │ │ │ ├── UnchosenSeatHolder.java
│ │ │ │ │ │ └── SeatAdapter.java
│ │ │ │ │ │ └── TheatreActivity.java
│ │ │ │ ├── util
│ │ │ │ │ ├── Toaster.java
│ │ │ │ │ └── TheatreUtils.java
│ │ │ │ └── App.java
│ │ │ │ ├── data
│ │ │ │ └── model
│ │ │ │ │ ├── theatre
│ │ │ │ │ ├── seat
│ │ │ │ │ │ ├── IsSeat.java
│ │ │ │ │ │ ├── Seat.java
│ │ │ │ │ │ ├── EmptySeat.java
│ │ │ │ │ │ ├── ChosenSeat.java
│ │ │ │ │ │ ├── ReservedSeat.java
│ │ │ │ │ │ └── UnChosenSeat.java
│ │ │ │ │ ├── IsTheatre.java
│ │ │ │ │ ├── BaseTheatre.java
│ │ │ │ │ └── Theatre.java
│ │ │ │ │ └── BaseModel.java
│ │ │ │ └── internal
│ │ │ │ ├── injection
│ │ │ │ └── scope
│ │ │ │ │ ├── ForApp.java
│ │ │ │ │ └── ForActivity.java
│ │ │ │ └── binding
│ │ │ │ └── ViewBinding.java
│ │ └── AndroidManifest.xml
│ ├── test
│ │ └── java
│ │ │ └── io
│ │ │ └── github
│ │ │ └── lamtran
│ │ │ └── moviebooking
│ │ │ └── ExampleUnitTest.java
│ └── androidTest
│ │ └── java
│ │ └── io
│ │ └── github
│ │ └── lamtran
│ │ └── moviebooking
│ │ └── ExampleInstrumentedTest.java
├── lint.xml
├── proguard-rules.pro
└── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── .idea
├── vcs.xml
└── codeStyleSettings.xml
├── gradle.properties
├── gradlew.bat
├── README.md
└── gradlew
/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | .idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 |
--------------------------------------------------------------------------------
/app/src/main/ic_launcher-web.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/ic_launcher-web.png
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/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/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/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/tranngoclam/movie-booking/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/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-hdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-mdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tranngoclam/movie-booking/HEAD/app/src/main/res/mipmap-xxxhdpi/ic_launcher_foreground.png
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sun Sep 03 23:39:58 ICT 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-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_arrow_drop_down_black_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/lint.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/HasBoundData.java:
--------------------------------------------------------------------------------
1 | package io.github.lamtran.moviebooking.presentation.view.base;
2 |
3 | import android.databinding.ViewDataBinding;
4 |
5 | /**
6 | * Author: JONATHAN MERRITT
7 | * Year: 2017
8 | * Contact: 11R00TT00RR11@GMAIL.COM
9 | */
10 |
11 | public interface HasBoundData {
12 | void setBindings(B binding);
13 |
14 | @SuppressWarnings("unused") B getBinding();
15 | }
16 |
--------------------------------------------------------------------------------
/app/src/test/java/io/github/lamtran/moviebooking/ExampleUnitTest.java:
--------------------------------------------------------------------------------
1 | package io.github.lamtran.moviebooking;
2 |
3 | import org.junit.Test;
4 |
5 | import static org.junit.Assert.assertEquals;
6 |
7 | /**
8 | * Example local unit test, which will execute on the development machine (host).
9 | *
10 | * @see Testing documentation
11 | */
12 | public class ExampleUnitTest {
13 |
14 | @Test public void addition_isCorrect() throws Exception {
15 | assertEquals(4, 2 + 2);
16 | }
17 | }
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_refresh_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
--------------------------------------------------------------------------------
/app/src/main/res/menu/activity_theatre.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/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 /Users/lam/Library/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 |
--------------------------------------------------------------------------------
/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/io/github/lamtran/moviebooking/presentation/util/Toaster.java:
--------------------------------------------------------------------------------
1 | package io.github.lamtran.moviebooking.presentation.util;
2 |
3 | import android.content.Context;
4 | import android.widget.Toast;
5 | import io.github.lamtran.moviebooking.internal.injection.scope.ForActivity;
6 | import io.github.lamtran.moviebooking.presentation.view.base.screen.BaseActivity;
7 | import javax.inject.Inject;
8 |
9 | /**
10 | * Author: JONATHAN MERRITT
11 | * Year: 2017
12 | * Contact: 11R00TT00RR11@GMAIL.COM
13 | */
14 |
15 | @ForActivity public class Toaster {
16 | private final Context context;
17 |
18 | @Inject Toaster(BaseActivity activity) {
19 | context = activity;
20 | }
21 |
22 | public void show(int stringId) {
23 | Toast.makeText(context, context.getString(stringId), Toast.LENGTH_SHORT).show();
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/app/src/androidTest/java/io/github/lamtran/moviebooking/ExampleInstrumentedTest.java:
--------------------------------------------------------------------------------
1 | package io.github.lamtran.moviebooking;
2 |
3 | import android.content.Context;
4 | import android.support.test.InstrumentationRegistry;
5 | import android.support.test.runner.AndroidJUnit4;
6 | import org.junit.Test;
7 | import org.junit.runner.RunWith;
8 |
9 | import static org.junit.Assert.assertEquals;
10 |
11 | /**
12 | * Instrumentation test, which will execute on an Android device.
13 | *
14 | * @see Testing documentation
15 | */
16 | @RunWith(AndroidJUnit4.class) public class ExampleInstrumentedTest {
17 |
18 | @Test public void useAppContext() throws Exception {
19 | // Context of the app under test.
20 | Context appContext = InstrumentationRegistry.getTargetContext();
21 |
22 | assertEquals("io.github.lamtran.moviebooking", appContext.getPackageName());
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_github_white_24dp.xml:
--------------------------------------------------------------------------------
1 |
6 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/app/src/main/res/xml/backup_descriptor.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/IsSeat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | /**
27 | * Author: JONATHAN MERRITT
28 | * Year: 2017
29 | * Contact: 11R00TT00RR11@GMAIL.COM
30 | */
31 | public interface IsSeat {
32 | int number();
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/screen/IsScreen.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.screen;
25 |
26 | /**
27 | * Author: JONATHAN MERRITT
28 | * Year: 2017
29 | * Contact: 11R00TT00RR11@GMAIL.COM
30 | */
31 | public interface IsScreen {
32 | @SuppressWarnings("SameReturnValue") int getLayout();
33 | }
34 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/controller/IsController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.controller;
25 |
26 | import android.view.View;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | interface IsController {
34 |
35 | void onClick(View view);
36 |
37 | void onLongClick(View view);
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/IsTheatre.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre;
25 |
26 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
27 | import java.util.List;
28 |
29 | /**
30 | * Author: JONATHAN MERRITT
31 | * Year: 2017
32 | * Contact: 11R00TT00RR11@GMAIL.COM
33 | */
34 | public interface IsTheatre {
35 | List seats();
36 |
37 | int tickets();
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/internal/injection/scope/ForApp.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.internal.injection.scope;
25 |
26 | import java.lang.annotation.Retention;
27 | import java.lang.annotation.RetentionPolicy;
28 | import javax.inject.Scope;
29 |
30 | /**
31 | * Author: JONATHAN MERRITT
32 | * Year: 2017
33 | * Contact: 11R00TT00RR11@GMAIL.COM
34 | */
35 | @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ForApp {
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/internal/injection/scope/ForActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.internal.injection.scope;
25 |
26 | import java.lang.annotation.Retention;
27 | import java.lang.annotation.RetentionPolicy;
28 | import javax.inject.Scope;
29 |
30 | /**
31 | * Author: JONATHAN MERRITT
32 | * Year: 2017
33 | * Contact: 11R00TT00RR11@GMAIL.COM
34 | */
35 | @Scope @Retention(RetentionPolicy.RUNTIME) public @interface ForActivity {
36 |
37 | }
38 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/adapter/IsHolderFactory.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.adapter;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.presentation.view.base.adapter.BaseAdapter.Holder;
28 |
29 | /**
30 | * Author: JONATHAN MERRITT
31 | * Year: 2017
32 | * Contact: 11R00TT00RR11@GMAIL.COM
33 | */
34 | public interface IsHolderFactory {
35 | Holder create(View view);
36 | }
37 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/screen/IsScreenController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.screen;
25 |
26 | import android.os.Bundle;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | @SuppressWarnings("unused") interface IsScreenController {
34 | void onStart();
35 |
36 | void onSave(Bundle savedState);
37 |
38 | void onRestore(Bundle restoredState);
39 | }
40 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/BaseTheatre.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre;
25 |
26 | import io.github.lamtran.moviebooking.data.model.BaseModel;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | abstract class BaseTheatre extends BaseModel implements IsTheatre {
34 |
35 | static int adjust(int index, boolean plus, boolean minus) {
36 | return plus ? index + 1 : minus ? index - 1 : index;
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/Seat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | import io.github.lamtran.moviebooking.data.model.BaseModel;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | public abstract class Seat extends BaseModel implements IsSeat {
34 |
35 | public static boolean check(Class extends Seat> cLass, Class extends Seat> cLass2) {
36 | return cLass.equals(cLass2);
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
26 | #0079c3
27 | #005c95
28 | #009e64
29 |
30 | #b4b4b4
31 | @color/colorAccent
32 | #616161
33 | #00000000
34 |
35 | #2cffffff
36 |
37 |
38 |
--------------------------------------------------------------------------------
/app/src/main/res/values/dimens.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 | 0dp
26 |
27 | 76dp
28 | 20sp
29 |
30 | 2dp
31 | 6dp
32 |
33 | 48dp
34 |
35 | 14sp
36 | 14sp
37 |
38 | 18dp
39 | 10dp
40 |
41 |
42 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/BaseModel.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model;
25 |
26 | import android.os.Bundle;
27 | import android.os.Parcelable;
28 |
29 | /**
30 | * Author: JONATHAN MERRITT
31 | * Year: 2017
32 | * Contact: 11R00TT00RR11@GMAIL.COM
33 | */
34 | public abstract class BaseModel implements Parcelable {
35 |
36 | public static M restore(Bundle bundle, String tag) {
37 | return bundle.getParcelable(tag + "_Model");
38 | }
39 |
40 | public void save(Bundle bundle, String tag) {
41 | bundle.putParcelable(tag + "_Model", this);
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/holder_empty_seat.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
28 |
29 |
33 |
34 |
40 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/internal/binding/ViewBinding.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.internal.binding;
25 |
26 | import android.databinding.BindingAdapter;
27 | import android.support.annotation.NonNull;
28 | import android.view.View;
29 |
30 | /**
31 | * Author: JONATHAN MERRITT
32 | * Year: 2017
33 | * Contact: 11R00TT00RR11@GMAIL.COM
34 | */
35 | public final class ViewBinding {
36 |
37 | @BindingAdapter("longClick")
38 | public static void setLongClick(@NonNull final View view, @NonNull final View.OnClickListener listener) {
39 | view.setOnLongClickListener((v -> {
40 | listener.onClick(v);
41 | return true;
42 | }));
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/controller/BaseController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.controller;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.data.model.BaseModel;
28 |
29 | /**
30 | * Author: JONATHAN MERRITT
31 | * Year: 2017
32 | * Contact: 11R00TT00RR11@GMAIL.COM
33 | */
34 | public class BaseController implements IsController {
35 | protected M model;
36 |
37 | public void setModel(M model) {
38 | this.model = model;
39 | }
40 |
41 | @Override public void onClick(View view) {
42 | }
43 |
44 | @Override public void onLongClick(View view) {
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 |
3 | android {
4 | compileSdkVersion 28
5 | defaultConfig {
6 | applicationId "io.github.lamtran.moviebooking"
7 | minSdkVersion 26
8 | targetSdkVersion 28
9 | versionCode 1
10 | versionName "1.0"
11 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12 | vectorDrawables.useSupportLibrary = true
13 | dataBinding {
14 | enabled = true
15 | }
16 | }
17 |
18 | buildTypes {
19 | release {
20 | minifyEnabled false
21 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
22 | }
23 | }
24 |
25 | compileOptions {
26 | sourceCompatibility JavaVersion.VERSION_1_8
27 | targetCompatibility JavaVersion.VERSION_1_8
28 | }
29 | }
30 |
31 | def android = "28.0.0"
32 | def dagger = "2.15"
33 |
34 | dependencies {
35 | implementation fileTree(dir: 'libs', include: ['*.jar'])
36 |
37 | implementation "com.android.support:appcompat-v7:$android"
38 | implementation "com.android.support:recyclerview-v7:$android"
39 | implementation 'com.android.support.constraint:constraint-layout:1.1.3'
40 |
41 | implementation "com.google.dagger:dagger:$dagger"
42 | implementation "com.google.dagger:dagger-android:$dagger"
43 | implementation "com.google.dagger:dagger-android-support:$dagger"
44 | annotationProcessor "com.google.dagger:dagger-compiler:$dagger"
45 | annotationProcessor "com.google.dagger:dagger-android-processor:$dagger"
46 | annotationProcessor "com.google.auto.value:auto-value:1.5.2"
47 |
48 | implementation "com.jakewharton.timber:timber:4.5.1"
49 | compileOnly 'com.jakewharton.auto.value:auto-value-annotations:1.4'
50 |
51 | //compile "io.reactivex.rxjava2:rxandroid:2.0.1"
52 |
53 | annotationProcessor "com.ryanharter.auto.value:auto-value-parcel:0.2.5"
54 |
55 | androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.2"
56 | testImplementation "junit:junit:4.12"
57 | }
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/EmptySeat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | import com.google.auto.value.AutoValue;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | @AutoValue public abstract class EmptySeat extends Seat {
34 |
35 | public static EmptySeat create(int number) {
36 | return new AutoValue_EmptySeat(number);
37 | }
38 |
39 | public static EmptySeat copy(Seat old) {
40 | return create(old.number());
41 | }
42 |
43 | public static boolean check(Class extends Seat> cLass) {
44 | return check(EmptySeat.class, cLass) || check(AutoValue_EmptySeat.class, cLass);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/ChosenSeat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | import com.google.auto.value.AutoValue;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | @AutoValue public abstract class ChosenSeat extends Seat {
34 |
35 | private static ChosenSeat create(int number) {
36 | return new AutoValue_ChosenSeat(number);
37 | }
38 |
39 | public static ChosenSeat copy(Seat old) {
40 | return create(old.number());
41 | }
42 |
43 | public static boolean check(Class extends Seat> cLass) {
44 | return check(ChosenSeat.class, cLass) || check(AutoValue_ChosenSeat.class, cLass);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/ReservedSeat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | import com.google.auto.value.AutoValue;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | @AutoValue public abstract class ReservedSeat extends Seat {
34 |
35 | private static ReservedSeat create(int number) {
36 | return new AutoValue_ReservedSeat(number);
37 | }
38 |
39 | public static ReservedSeat copy(Seat old) {
40 | return create(old.number());
41 | }
42 |
43 | public static boolean check(Class extends Seat> cLass) {
44 | return check(ReservedSeat.class, cLass) || check(AutoValue_ReservedSeat.class, cLass);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/seat/UnChosenSeat.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre.seat;
25 |
26 | import com.google.auto.value.AutoValue;
27 |
28 | /**
29 | * Author: JONATHAN MERRITT
30 | * Year: 2017
31 | * Contact: 11R00TT00RR11@GMAIL.COM
32 | */
33 | @AutoValue public abstract class UnChosenSeat extends Seat {
34 |
35 | public static UnChosenSeat create(int number) {
36 | return new AutoValue_UnChosenSeat(number);
37 | }
38 |
39 | public static UnChosenSeat copy(Seat old) {
40 | return create(old.number());
41 | }
42 |
43 | public static boolean check(Class extends Seat> cLass) {
44 | return check(UnChosenSeat.class, cLass) || check(AutoValue_UnChosenSeat.class, cLass);
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/screen/ScreenController.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.screen;
25 |
26 | import android.os.Bundle;
27 | import io.github.lamtran.moviebooking.data.model.BaseModel;
28 | import io.github.lamtran.moviebooking.presentation.view.base.controller.BaseController;
29 |
30 | /**
31 | * Author: JONATHAN MERRITT
32 | * Year: 2017
33 | * Contact: 11R00TT00RR11@GMAIL.COM
34 | */
35 | public class ScreenController extends BaseController implements IsScreenController {
36 |
37 | @Override public void onStart() {
38 | }
39 |
40 | @Override public void onSave(Bundle savedState) {
41 | }
42 |
43 | @Override public void onRestore(Bundle restoredState) {
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 | Movie Booking
26 |
27 | %s
28 |
29 | Set Tickets
30 | Click Seat
31 | Long Click Seat
32 |
33 | Unchosen %s
34 | Chosen %s
35 | Reserved %s
36 | Empty %s>
37 |
38 | No Tickets Left
39 | No Chosen Seats
40 | No Unchosen Seats
41 |
42 | Github
43 | Reset
44 |
45 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/holder_chosen_seat.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
29 |
30 |
31 |
35 |
36 |
42 |
47 |
48 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/holder_reserved_seat.xml:
--------------------------------------------------------------------------------
1 |
2 |
24 |
28 |
29 |
30 |
31 |
35 |
36 |
37 |
43 |
48 |
49 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/SeatChanger.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
27 | import io.github.lamtran.moviebooking.internal.injection.scope.ForActivity;
28 | import javax.inject.Inject;
29 |
30 | /**
31 | * Author: JONATHAN MERRITT
32 | * Year: 2017
33 | * Contact: 11R00TT00RR11@GMAIL.COM
34 | */
35 | @ForActivity public class SeatChanger {
36 | private Requester requester;
37 |
38 | @Inject public SeatChanger() {
39 | }
40 | public void setRequester(Requester requester) {
41 | this.requester = requester;
42 | }
43 | void request(Seat last, Class extends Seat> nextClass) {
44 | if (requester != null) requester.change(last, nextClass);
45 | }
46 |
47 | public interface Requester {
48 | void change(Seat last, Class extends Seat> nextClass);
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/holder_unchosen_seat.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
29 |
30 |
31 |
32 |
36 |
37 |
38 |
44 |
49 |
50 |
--------------------------------------------------------------------------------
/app/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
28 |
29 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/util/TheatreUtils.java:
--------------------------------------------------------------------------------
1 | package io.github.lamtran.moviebooking.presentation.util;
2 |
3 | import io.github.lamtran.moviebooking.R;
4 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ChosenSeat;
5 | import io.github.lamtran.moviebooking.data.model.theatre.seat.EmptySeat;
6 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ReservedSeat;
7 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
8 | import io.github.lamtran.moviebooking.data.model.theatre.seat.UnChosenSeat;
9 | import java.util.ArrayList;
10 | import java.util.List;
11 |
12 | /**
13 | * Author: JONATHAN MERRITT
14 | * Year: 2017
15 | * Contact: 11R00TT00RR11@GMAIL.COM
16 | */
17 |
18 | public class TheatreUtils {
19 | public static List seats() {
20 | final List seats = new ArrayList<>();
21 | int number = 1, total = 0;
22 | do {
23 | number = number + 4;
24 | seats.add(UnChosenSeat.create(number - 4));
25 | seats.add(UnChosenSeat.create(number - 3));
26 | seats.add(EmptySeat.create(number - 2));
27 | seats.add(UnChosenSeat.create(number - 1));
28 | total++;
29 | } while (total < 8);
30 | return seats;
31 | }
32 | public static Seat resolveSeat(Seat last, Class extends Seat> cLass) {
33 | return UnChosenSeat.check(cLass) ? UnChosenSeat.copy(last) : ChosenSeat.check(cLass) ? ChosenSeat.copy(last)
34 | : ReservedSeat.check(cLass) ? ReservedSeat.copy(last) : EmptySeat.copy(last);
35 | }
36 | public static int resolveLayout(Class extends Seat> cLass) {
37 | return UnChosenSeat.check(cLass) ? R.layout.holder_unchosen_seat
38 | : ChosenSeat.check(cLass) ? R.layout.holder_chosen_seat
39 | : ReservedSeat.check(cLass) ? R.layout.holder_reserved_seat : R.layout.holder_empty_seat;
40 | }
41 | public static Class extends Seat> swapSeat(Class extends Seat> cLass) {
42 | return UnChosenSeat.check(cLass) ? ChosenSeat.class : ChosenSeat.check(cLass) ? UnChosenSeat.class
43 | : ReservedSeat.check(cLass) ? EmptySeat.class
44 | : EmptySeat.check(cLass) ? ReservedSeat.class : EmptySeat.class;
45 | }
46 | public static Class extends Seat> swapSeatAlt(Class extends Seat> cLass) {
47 | return UnChosenSeat.check(cLass) ? ReservedSeat.class : ChosenSeat.check(cLass) ? EmptySeat.class
48 | : ReservedSeat.check(cLass) ? UnChosenSeat.class
49 | : EmptySeat.check(cLass) ? ChosenSeat.class : EmptySeat.class;
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/EmptySeatHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.data.model.theatre.seat.EmptySeat;
28 | import io.github.lamtran.moviebooking.databinding.HolderEmptySeatBinding;
29 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatAdapter.Holder;
30 | import javax.inject.Inject;
31 |
32 | /**
33 | * Author: JONATHAN MERRITT
34 | * Year: 2017
35 | * Contact: 11R00TT00RR11@GMAIL.COM
36 | */
37 | public class EmptySeatHolder extends Holder {
38 | private EmptySeatHolder(View view, Controller controller) {
39 | super(HolderEmptySeatBinding.bind(view), controller);
40 | }
41 | @Override public void setBindings(HolderEmptySeatBinding binding) {
42 | binding.setController(controller);
43 | }
44 | public static class Factory extends Holder.Factory {
45 | @Inject public Factory(Controller controller) {
46 | super(controller);
47 | }
48 | @Override public Holder create(View view) {
49 | return new EmptySeatHolder(view, controller);
50 | }
51 | }
52 | public static class Controller extends Holder.Controller {
53 | @Inject Controller(SeatChanger changer) {
54 | super(changer);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/ChosenSeatHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ChosenSeat;
28 | import io.github.lamtran.moviebooking.databinding.HolderChosenSeatBinding;
29 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatAdapter.Holder;
30 | import javax.inject.Inject;
31 |
32 | /**
33 | * Author: JONATHAN MERRITT
34 | * Year: 2017
35 | * Contact: 11R00TT00RR11@GMAIL.COM
36 | */
37 | public class ChosenSeatHolder extends Holder {
38 | private ChosenSeatHolder(View view, Controller controller) {
39 | super(HolderChosenSeatBinding.bind(view), controller);
40 | }
41 | @Override public void setBindings(HolderChosenSeatBinding binding) {
42 | binding.setController(controller);
43 | }
44 | public static class Factory extends Holder.Factory {
45 | @Inject public Factory(Controller controller) {
46 | super(controller);
47 | }
48 | @Override public Holder create(View view) {
49 | return new ChosenSeatHolder(view, controller);
50 | }
51 | }
52 | public static class Controller extends Holder.Controller {
53 | @Inject Controller(SeatChanger changer) {
54 | super(changer);
55 | }
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/ReservedSeatHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ReservedSeat;
28 | import io.github.lamtran.moviebooking.databinding.HolderReservedSeatBinding;
29 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatAdapter.Holder;
30 | import javax.inject.Inject;
31 |
32 | /**
33 | * Author: JONATHAN MERRITT
34 | * Year: 2017
35 | * Contact: 11R00TT00RR11@GMAIL.COM
36 | */
37 | public class ReservedSeatHolder
38 | extends Holder {
39 | private ReservedSeatHolder(View view, Controller controller) {
40 | super(HolderReservedSeatBinding.bind(view), controller);
41 | }
42 | @Override public void setBindings(HolderReservedSeatBinding binding) {
43 | binding.setController(controller);
44 | }
45 | public static class Factory extends Holder.Factory {
46 | @Inject public Factory(Controller controller) {
47 | super(controller);
48 | }
49 | @Override public Holder create(View view) {
50 | return new ReservedSeatHolder(view, controller);
51 | }
52 | }
53 | public static class Controller extends Holder.Controller {
54 | @Inject Controller(SeatChanger changer) {
55 | super(changer);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/UnchosenSeatHolder.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import android.view.View;
27 | import io.github.lamtran.moviebooking.data.model.theatre.seat.UnChosenSeat;
28 | import io.github.lamtran.moviebooking.databinding.HolderUnchosenSeatBinding;
29 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatAdapter.Holder;
30 | import javax.inject.Inject;
31 |
32 | /**
33 | * Author: JONATHAN MERRITT
34 | * Year: 2017
35 | * Contact: 11R00TT00RR11@GMAIL.COM
36 | */
37 | public class UnchosenSeatHolder
38 | extends Holder {
39 | private UnchosenSeatHolder(View view, Controller controller) {
40 | super(HolderUnchosenSeatBinding.bind(view), controller);
41 | }
42 | @Override public void setBindings(HolderUnchosenSeatBinding binding) {
43 | binding.setController(controller);
44 | }
45 | public static class Factory extends Holder.Factory {
46 | @Inject public Factory(Controller controller) {
47 | super(controller);
48 | }
49 | @Override public Holder create(View view) {
50 | return new UnchosenSeatHolder(view, controller);
51 | }
52 | }
53 | public static class Controller extends Holder.Controller {
54 | @Inject Controller(SeatChanger changer) {
55 | super(changer);
56 | }
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/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/java/io/github/lamtran/moviebooking/presentation/App.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation;
25 |
26 | import dagger.android.AndroidInjector;
27 | import dagger.android.ContributesAndroidInjector;
28 | import dagger.android.support.AndroidSupportInjectionModule;
29 | import dagger.android.support.DaggerApplication;
30 | import io.github.lamtran.moviebooking.BuildConfig;
31 | import io.github.lamtran.moviebooking.internal.injection.scope.ForActivity;
32 | import io.github.lamtran.moviebooking.internal.injection.scope.ForApp;
33 | import io.github.lamtran.moviebooking.presentation.view.theatre.TheatreActivity;
34 | import timber.log.Timber;
35 |
36 | /**
37 | * Author: JONATHAN MERRITT
38 | * Year: 2017
39 | * Contact: 11R00TT00RR11@GMAIL.COM
40 | */
41 | public class App extends DaggerApplication {
42 | public static final String GITHUB = "https://github.com/tranngoclam/movie-booking";
43 |
44 | @Override public void onCreate() {
45 | super.onCreate();
46 | if (BuildConfig.DEBUG) Timber.plant(new Timber.DebugTree());
47 | }
48 |
49 | @Override protected AndroidInjector extends DaggerApplication> applicationInjector() {
50 | return DaggerApp_Component.builder().create(this);
51 | }
52 |
53 | @ForApp @dagger.Component(modules = { AndroidSupportInjectionModule.class, Component.Module.class })
54 | public interface Component extends AndroidInjector {
55 | @dagger.Component.Builder abstract class Builder extends AndroidInjector.Builder {
56 | }
57 |
58 | @dagger.Module abstract class Module {
59 | @ForActivity @ContributesAndroidInjector(modules = TheatreActivity.Module.class)
60 | abstract TheatreActivity theatreActivity();
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/screen/BaseActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.screen;
25 |
26 | import android.databinding.DataBindingUtil;
27 | import android.databinding.ViewDataBinding;
28 | import android.os.Bundle;
29 | import dagger.android.support.DaggerAppCompatActivity;
30 | import io.github.lamtran.moviebooking.data.model.BaseModel;
31 | import io.github.lamtran.moviebooking.presentation.view.base.HasBoundData;
32 | import javax.inject.Inject;
33 |
34 | /**
35 | * Author: JONATHAN MERRITT
36 | * Year: 2017
37 | * Contact: 11R00TT00RR11@GMAIL.COM
38 | */
39 | public abstract class BaseActivity
40 | extends DaggerAppCompatActivity implements IsScreen, HasBoundData {
41 | @Inject protected C controller;
42 | private B binding;
43 | @Override protected void onCreate(Bundle createdState) {
44 | binding = DataBindingUtil.setContentView(this, getLayout());
45 | super.onCreate(createdState);
46 | if (createdState == null) controller.onStart();
47 | setBindings(binding);
48 | }
49 |
50 | @Override public void onSaveInstanceState(Bundle savedState) {
51 | controller.onSave(savedState);
52 | super.onSaveInstanceState(savedState);
53 | }
54 |
55 | @Override public void onRestoreInstanceState(Bundle restoredState) {
56 | if (restoredState != null) controller.onRestore(restoredState);
57 | super.onRestoreInstanceState(restoredState);
58 | }
59 |
60 | @Override public B getBinding() {
61 | return binding;
62 | }
63 |
64 | public abstract static class Controller extends ScreenController {
65 |
66 | @Override public void onSave(Bundle savedState) {
67 | super.onSave(savedState);
68 | model.save(savedState, getClass().getDeclaringClass().getSimpleName());
69 | }
70 |
71 | @Override public void onRestore(Bundle restoredState) {
72 | super.onRestore(restoredState);
73 | setModel(BaseModel.restore(restoredState, getClass().getDeclaringClass().getSimpleName()));
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/data/model/theatre/Theatre.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.data.model.theatre;
25 |
26 | import com.google.auto.value.AutoValue;
27 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ChosenSeat;
28 | import io.github.lamtran.moviebooking.data.model.theatre.seat.EmptySeat;
29 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ReservedSeat;
30 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
31 | import io.github.lamtran.moviebooking.data.model.theatre.seat.UnChosenSeat;
32 | import java.util.List;
33 |
34 | /**
35 | * Author: JONATHAN MERRITT
36 | * Year: 2017
37 | * Contact: 11R00TT00RR11@GMAIL.COM
38 | */
39 | @AutoValue public abstract class Theatre extends BaseTheatre {
40 |
41 | private static Theatre create(List seats, int tickets, int unchosen, int chosen, int reserved, int empty) {
42 | return new AutoValue_Theatre(seats, tickets, unchosen, chosen, reserved, empty);
43 | }
44 |
45 | private static Theatre copy(Theatre old) {
46 | return create(old.seats(), old.tickets(), old.unchosen(), old.chosen(), old.reserved(), old.empty());
47 | }
48 |
49 | public static Theatre idle(List seats) {
50 | int unchosen = 0, chosen = unchosen, reserved = chosen, empty = reserved;
51 | for (Seat seat : seats) {
52 | final Class extends Seat> cLass = seat.getClass();
53 | if (UnChosenSeat.check(cLass)) unchosen++;
54 | else if (ChosenSeat.check(cLass)) chosen++;
55 | else if (ReservedSeat.check(cLass)) reserved++;
56 | else if (EmptySeat.check(cLass)) empty++;
57 | }
58 | return create(seats, (unchosen + chosen) / 2, unchosen, chosen, reserved, empty);
59 | }
60 |
61 | public static Theatre reset(Theatre old, List seats) {
62 | Theatre theatre = old;
63 | for (Seat seat : seats) {
64 | final Class extends Seat> cLass = seat.getClass();
65 | final Class extends Seat> lastClass = old.seats().get(seats.indexOf(seat)).getClass();
66 | if (!Seat.check(cLass, lastClass)) theatre = Theatre.seat(theatre, seats, lastClass, cLass);
67 | }
68 | return copy(theatre);
69 | }
70 |
71 | public static Theatre tickets(Theatre old, int tickets) {
72 | return create(old.seats(), tickets, old.unchosen(), old.chosen(), old.reserved(), old.empty());
73 | }
74 |
75 | public static Theatre seat(Theatre old, List seats, Class extends Seat> lastClass,
76 | Class extends Seat> nextClass) {
77 | return create(seats, old.tickets(),
78 | adjust(old.unchosen(), UnChosenSeat.check(nextClass), UnChosenSeat.check(lastClass)),
79 | adjust(old.chosen(), ChosenSeat.check(nextClass), ChosenSeat.check(lastClass)),
80 | adjust(old.reserved(), ReservedSeat.check(nextClass), ReservedSeat.check(lastClass)),
81 | adjust(old.empty(), EmptySeat.check(nextClass), EmptySeat.check(lastClass)));
82 | }
83 |
84 | public abstract int unchosen();
85 |
86 | public abstract int chosen();
87 |
88 | public abstract int reserved();
89 |
90 | public abstract int empty();
91 | }
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
24 |
25 |
26 |
31 |
32 |
41 |
42 |
48 |
49 |
61 |
62 |
68 |
69 |
74 |
75 |
83 |
84 |
85 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/base/adapter/BaseAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.base.adapter;
25 |
26 | import android.databinding.ViewDataBinding;
27 | import android.support.v7.widget.RecyclerView.Adapter;
28 | import android.support.v7.widget.RecyclerView.ViewHolder;
29 | import android.view.ViewGroup;
30 | import io.github.lamtran.moviebooking.data.model.BaseModel;
31 | import io.github.lamtran.moviebooking.presentation.view.base.HasBoundData;
32 | import io.github.lamtran.moviebooking.presentation.view.base.controller.BaseController;
33 | import java.util.ArrayList;
34 | import java.util.List;
35 | import java.util.Map;
36 | import javax.inject.Provider;
37 |
38 | import static android.view.LayoutInflater.from;
39 |
40 | /**
41 | * Author: JONATHAN MERRITT
42 | * Year: 2017
43 | * Contact: 11R00TT00RR11@GMAIL.COM
44 | */
45 | public abstract class BaseAdapter>
46 | extends Adapter> {
47 | private final Map> factories;
48 | private final List models;
49 |
50 | protected BaseAdapter(Map> factories) {
51 | this.factories = factories;
52 | models = new ArrayList<>();
53 | }
54 |
55 | protected M getModel(int position) {
56 | return models.get(position);
57 | }
58 |
59 | @Override public int getItemCount() {
60 | return models.size();
61 | }
62 |
63 | @Override public Holder onCreateViewHolder(ViewGroup group, int type) {
64 | //noinspection unchecked
65 | return factories.get(type).get().create(from(group.getContext()).inflate(type, group, false));
66 | }
67 |
68 | @Override public void onBindViewHolder(Holder holder, int position) {
69 | holder.onBind(models.get(position));
70 | }
71 |
72 | public void setModels(List models) {
73 | this.models.clear();
74 | this.models.addAll(models);
75 | notifyDataSetChanged();
76 | }
77 |
78 | protected List replace(int index, M remove, M add) {
79 | if (models.contains(remove)) models.remove(remove);
80 | if (!models.contains(add)) models.add(index, add);
81 | if (getModel(index).equals(add)) notifyItemChanged(index);
82 | return models;
83 | }
84 |
85 | public static abstract class Holder>
86 | extends ViewHolder implements HasBoundData {
87 | protected final C controller;
88 | private final B binding;
89 |
90 | public Holder(B binding, C controller) {
91 | super(binding.getRoot());
92 | this.binding = binding;
93 | this.controller = controller;
94 | }
95 |
96 | void onBind(M model) {
97 | controller.setModel(model);
98 | setBindings(binding);
99 | binding.executePendingBindings();
100 | }
101 |
102 | @Override public B getBinding() {
103 | return binding;
104 | }
105 |
106 | public abstract static class Factory> implements IsHolderFactory {
107 | protected final C controller;
108 | protected Factory(C controller) {
109 | this.controller = controller;
110 | }
111 | }
112 |
113 | public abstract static class Controller extends BaseController {
114 | }
115 | }
116 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=tranngoclam288%40gmail%2ecom&lc=VN&item_name=Lam%20Tran¤cy_code=USD&bn=PP%2dDonationsBF%3abtn_donateCC_LG%2egif%3aNonHosted)
2 |
3 | # Movie Booking
4 |
5 | This is a simple example for booking movie seats in general movie/film mobile application. The concept is simply combined of `State Design Pattern`, `Android Data Binding` and `Multibinding + Autofactory` below.
6 |
7 | In the future, we can extend this concept by using `RxJava` to handle behavior in only a stream, also chain any stream to process our logic.
8 |
9 | Hope it will be useful for anyone who are building this context.
10 |
11 | # Concept
12 | ### State Design Pattern
13 |
14 | A seat has many states, such as:
15 | * **EMPTY**: this is not a seat, just a blank space, it does not have any action.
16 | * **RESERVED**: this is a reserved seat, which can not be booked anymore.
17 | * **AVAILABLE**: this seat can be book by selecting.
18 | * **SELECTED**: this seat is being selected, it can be deselected to be available.
19 |
20 | To manage these states, we use [State Design Pattern](https://github.com/iluwatar/java-design-patterns/tree/master/state), also for the definition of state action, current state and switching between different states.
21 | * An `available seat` can be select to be a `selected seat`, its state changes from `AVAILABLE` to `SELECTED`.
22 | * A `selected seat` can be deselected to be an `available seat`, its state changes from `SELECTED` to `AVAILABLE`
23 |
24 | ### Android Data Binding
25 | For any state changes, we update the UI of the seat correspondingly by using `@BindingAdapter` and `@Bindable` annotations defined in [Android Data Binding](https://developer.android.com/topic/libraries/data-binding/index.html). Example:
26 | * In a layout of a seat, we bind a state value to UI by: `app:state="@{data.state}"`.
27 | * A state defined in Java code is: `@Bindable State mState;` and must have getter `public State getState() { return mState; }`.
28 | * If we want to seatChange the state and update to the UI, we set `mState = new NewState();` then `notifyPropertyChanged(BR.state);`, noted that `BR.state` is generated after building our application.
29 |
30 | ### Multibinding and Autofactory
31 | For the Dependency Injection, we use [Dagger2](https://github.com/google/dagger) to setup. Dagger2 also supports Multibinding, it means that we can inject any `ViewHolder` into our adapter to render the corresponding layout of an item in a list.
32 |
33 | By using [Autofactory](https://github.com/google/auto/tree/master/factory), we construct some ViewHolders and provide these factory in a module. These factory must go with a key defined by `@IntKey`, which is an item view type. Example:
34 | ``` java
35 | @Provides
36 | @IntoMap
37 | @IntKey(Seat.Type.AVAILABLE)
38 | SeatViewHolderFactory provideAvailableSeatViewHolder() {
39 | return new AvailableSeatViewHolderFactory();
40 | }
41 | ```
42 |
43 | ``` java
44 | public interface SeatViewHolderFactory {
45 | SeatViewHolder createViewHolder(ViewDataBinding binding);
46 | }
47 | ```
48 |
49 | ``` java
50 | @Override
51 | public SeatViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
52 | ItemSeatBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_seat, parent, false);
53 | return mSeatViewHolderFactoryMap.get(viewType).createViewHolder(binding);
54 | }
55 | ```
56 |
57 | # TODO
58 | * Write Unit Test to verify any action from the views.
59 | * Support selecting many seats and handle exception if the selection reaches the maximum.
60 | * Try to use RxJava to extend the concept.
61 |
62 | # References
63 | * http://frogermcs.github.io/inject-everything-viewholder-and-dagger-2-example/
64 | * https://github.com/google/android-ui-toolkit-demos/tree/master/DataBinding/DataBoundRecyclerView
65 |
66 | # License
67 | ```
68 | MIT License
69 |
70 | Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
71 |
72 | Permission is hereby granted, free of charge, to any person obtaining a copy
73 | of this software and associated documentation files (the "Software"), to deal
74 | in the Software without restriction, including without limitation the rights
75 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
76 | copies of the Software, and to permit persons to whom the Software is
77 | furnished to do so, subject to the following conditions:
78 |
79 | The above copyright notice and this permission notice shall be included in all
80 | copies or substantial portions of the Software.
81 |
82 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
83 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
84 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
85 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
86 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
87 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
88 | SOFTWARE.
89 | ```
90 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/seat/SeatAdapter.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre.seat;
25 |
26 | import android.databinding.ObservableInt;
27 | import android.databinding.ViewDataBinding;
28 | import android.support.v7.widget.RecyclerView;
29 | import android.view.View;
30 | import dagger.Binds;
31 | import dagger.multibindings.IntKey;
32 | import dagger.multibindings.IntoMap;
33 | import io.github.lamtran.moviebooking.R;
34 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
35 | import io.github.lamtran.moviebooking.internal.injection.scope.ForActivity;
36 | import io.github.lamtran.moviebooking.presentation.util.TheatreUtils;
37 | import io.github.lamtran.moviebooking.presentation.view.base.adapter.BaseAdapter;
38 | import io.github.lamtran.moviebooking.presentation.view.base.adapter.IsHolderFactory;
39 | import java.util.List;
40 | import java.util.Map;
41 | import javax.inject.Inject;
42 | import javax.inject.Provider;
43 |
44 | /**
45 | * Author: JONATHAN MERRITT
46 | * Year: 2017
47 | * Contact: 11R00TT00RR11@GMAIL.COM
48 | */
49 | @ForActivity public class SeatAdapter extends BaseAdapter> {
50 |
51 | @Inject public SeatAdapter(Map> factories) {
52 | super(factories);
53 | }
54 | public List replace(Seat last, Class extends Seat> nextClass) {
55 | return replace(last.number() - 1, last, TheatreUtils.resolveSeat(last, nextClass));
56 | }
57 | @Override public int getItemViewType(int position) {
58 | return TheatreUtils.resolveLayout(getModel(position).getClass());
59 | }
60 | @Override public void onAttachedToRecyclerView(RecyclerView recyclerView) {
61 | final RecyclerView.ItemAnimator animator = recyclerView.getItemAnimator();
62 | animator.setChangeDuration(0);
63 | animator.setAddDuration(0);
64 | animator.setRemoveDuration(0);
65 | animator.setMoveDuration(0);
66 | super.onAttachedToRecyclerView(recyclerView);
67 | }
68 |
69 | public abstract static class Holder>
70 | extends BaseAdapter.Holder {
71 | Holder(B binding, C controller) {
72 | super(binding, controller);
73 | }
74 |
75 | static abstract class Factory>
76 | extends BaseAdapter.Holder.Factory {
77 | Factory(C controller) {
78 | super(controller);
79 | }
80 | }
81 |
82 | public abstract static class Controller extends BaseAdapter.Holder.Controller {
83 | public final ObservableInt number = new ObservableInt();
84 | private final SeatChanger changer;
85 |
86 | public Controller(SeatChanger changer) {
87 | super();
88 | this.changer = changer;
89 | }
90 |
91 | @Override public void setModel(S seat) {
92 | super.setModel(seat);
93 | number.set(seat.number());
94 | }
95 |
96 | @Override public void onClick(View view) {
97 | super.onClick(view);
98 | changer.request(model, TheatreUtils.swapSeat(model.getClass()));
99 | }
100 |
101 | @Override public void onLongClick(View view) {
102 | super.onLongClick(view);
103 | changer.request(model, TheatreUtils.swapSeatAlt(model.getClass()));
104 | }
105 | }
106 | }
107 | @dagger.Module public abstract class Module {
108 | @Binds @IntoMap @IntKey(R.layout.holder_unchosen_seat)
109 | abstract IsHolderFactory unchosenSeatFactory(UnchosenSeatHolder.Factory holderFactory);
110 |
111 | @Binds @IntoMap @IntKey(R.layout.holder_chosen_seat)
112 | abstract IsHolderFactory chosenSeatFactory(ChosenSeatHolder.Factory holderFactory);
113 |
114 | @Binds @IntoMap @IntKey(R.layout.holder_reserved_seat)
115 | abstract IsHolderFactory reservedSeatFactory(ReservedSeatHolder.Factory holderFactory);
116 |
117 | @Binds @IntoMap @IntKey(R.layout.holder_empty_seat)
118 | abstract IsHolderFactory emptySeatFactory(EmptySeatHolder.Factory holderFactory);
119 | }
120 | }
121 |
--------------------------------------------------------------------------------
/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/res/layout/activity_theatre.xml:
--------------------------------------------------------------------------------
1 |
2 |
25 |
30 |
31 |
32 |
36 |
37 |
38 |
42 |
43 |
53 |
54 |
64 |
65 |
75 |
76 |
86 |
87 |
98 |
99 |
110 |
111 |
122 |
123 |
134 |
135 |
--------------------------------------------------------------------------------
/app/src/main/java/io/github/lamtran/moviebooking/presentation/view/theatre/TheatreActivity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * MIT License
3 | *
4 | * Copyright (c) 2017 Lam Tran (tranngoclam288@gmail.com)
5 | *
6 | * Permission is hereby granted, free of charge, to any person obtaining a copy
7 | * of this software and associated documentation files (the "Software"), to deal
8 | * in the Software without restriction, including without limitation the rights
9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 | * copies of the Software, and to permit persons to whom the Software is
11 | * furnished to do so, subject to the following conditions:
12 | *
13 | * The above copyright notice and this permission notice shall be included in all
14 | * copies or substantial portions of the Software.
15 | *
16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 | * SOFTWARE.
23 | */
24 | package io.github.lamtran.moviebooking.presentation.view.theatre;
25 |
26 | import android.content.Intent;
27 | import android.databinding.ObservableInt;
28 | import android.net.Uri;
29 | import android.os.Bundle;
30 | import android.support.v7.widget.PopupMenu;
31 | import android.view.KeyEvent;
32 | import android.view.Menu;
33 | import android.view.MenuItem;
34 | import android.view.View;
35 | import dagger.Binds;
36 | import io.github.lamtran.moviebooking.R;
37 | import io.github.lamtran.moviebooking.data.model.theatre.Theatre;
38 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ChosenSeat;
39 | import io.github.lamtran.moviebooking.data.model.theatre.seat.EmptySeat;
40 | import io.github.lamtran.moviebooking.data.model.theatre.seat.ReservedSeat;
41 | import io.github.lamtran.moviebooking.data.model.theatre.seat.Seat;
42 | import io.github.lamtran.moviebooking.data.model.theatre.seat.UnChosenSeat;
43 | import io.github.lamtran.moviebooking.databinding.ActivityTheatreBinding;
44 | import io.github.lamtran.moviebooking.internal.injection.scope.ForActivity;
45 | import io.github.lamtran.moviebooking.presentation.App;
46 | import io.github.lamtran.moviebooking.presentation.util.TheatreUtils;
47 | import io.github.lamtran.moviebooking.presentation.util.Toaster;
48 | import io.github.lamtran.moviebooking.presentation.view.base.screen.BaseActivity;
49 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatAdapter;
50 | import io.github.lamtran.moviebooking.presentation.view.theatre.seat.SeatChanger;
51 | import java.util.List;
52 | import javax.inject.Inject;
53 |
54 | import static android.view.KeyEvent.KEYCODE_BACK;
55 | import static io.github.lamtran.moviebooking.presentation.util.TheatreUtils.swapSeat;
56 | import static io.github.lamtran.moviebooking.presentation.util.TheatreUtils.swapSeatAlt;
57 |
58 | /**
59 | * Author: JONATHAN MERRITT
60 | * Year: 2017
61 | * Contact: 11R00TT00RR11@GMAIL.COM
62 | */
63 | public class TheatreActivity extends BaseActivity {
64 |
65 | @Override public int getLayout() {
66 | return R.layout.activity_theatre;
67 | }
68 |
69 | @Override public void setBindings(ActivityTheatreBinding binding) {
70 | binding.setController(controller);
71 | }
72 |
73 | @Override public boolean onCreateOptionsMenu(Menu menu) {
74 | getMenuInflater().inflate(R.menu.activity_theatre, menu);
75 | return super.onCreateOptionsMenu(menu);
76 | }
77 |
78 | @Override public boolean onOptionsItemSelected(MenuItem item) {
79 | switch (item.getItemId()) {
80 | case R.id.item_github:
81 | startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(App.GITHUB)));
82 | break;
83 | case R.id.item_reset:
84 | controller.reset();
85 | break;
86 | }
87 | return super.onOptionsItemSelected(item);
88 | }
89 |
90 | @Override public boolean onKeyDown(int code, KeyEvent event) {
91 | if (code == KEYCODE_BACK && controller.hasChosen()) {
92 | controller.changeSeats(UnChosenSeat.class);
93 | return true;
94 | }
95 | return super.onKeyDown(code, event);
96 | }
97 |
98 | @ForActivity public static class Controller extends BaseActivity.Controller {
99 |
100 | public final ObservableInt unchosen = new ObservableInt(), chosen = new ObservableInt(), reserved =
101 | new ObservableInt(), empty = new ObservableInt();
102 | public final SeatAdapter adapter;
103 | private final Toaster toaster;
104 |
105 | @Inject public Controller(SeatAdapter adapter, Toaster toaster, SeatChanger changer) {
106 | super();
107 | this.adapter = adapter;
108 | this.toaster = toaster;
109 | changer.setRequester(this::changeSeat);
110 | }
111 |
112 | @Override public void onStart() {
113 | super.onStart();
114 | setModel(Theatre.idle(TheatreUtils.seats()));
115 | adapter.setModels(model.seats());
116 | }
117 |
118 | @Override public void onRestore(Bundle restoredState) {
119 | super.onRestore(restoredState);
120 | adapter.setModels(model.seats());
121 | }
122 |
123 | @Override public void setModel(Theatre model) {
124 | super.setModel(model);
125 | unchosen.set(model.unchosen());
126 | chosen.set(model.chosen());
127 | reserved.set(model.reserved());
128 | empty.set(model.empty());
129 | }
130 |
131 | @Override public void onClick(View view) {
132 | super.onClick(view);
133 | final int id = view.getId();
134 | switch (id) {
135 | case R.id.seat_click:
136 | case R.id.seat_long_click:
137 | case R.id.set_tickets:
138 | final PopupMenu popup = new PopupMenu(view.getContext(), view);
139 | for (int index = 0;
140 | index < (id != R.id.set_tickets ? model.seats().size() : unchosen.get() + chosen.get()); index++) {
141 | final Menu menu = popup.getMenu();
142 | final int number = index + 1;
143 | final String title = id == R.id.set_tickets && model.tickets() == number ? "Current " : "";
144 | menu.add(id, number, index, String.format("%s%s", title, number));
145 | }
146 | popup.setOnMenuItemClickListener(item -> {
147 | switch (id) {
148 | case R.id.seat_click:
149 | case R.id.seat_long_click:
150 | final Seat last = model.seats().get(item.getOrder());
151 | final Class extends Seat> lastClass = last.getClass();
152 | changeSeat(last, id == R.id.seat_click ? swapSeat(lastClass) : swapSeatAlt(lastClass));
153 | break;
154 |
155 | case R.id.set_tickets:
156 | setModel(Theatre.tickets(model, item.getItemId()));
157 | if (model.tickets() < chosen.get()) changeSeats(UnChosenSeat.class);
158 | break;
159 | }
160 | return true;
161 | });
162 | popup.show();
163 | break;
164 |
165 | case R.id.change_unchosen_to_chosen:
166 | if (model.tickets() == chosen.get()) toaster.show(R.string.no_tickets_left);
167 | else if (unchosen.get() > 0) changeSeats(ChosenSeat.class);
168 | else toaster.show(R.string.no_unchosen_seats);
169 | break;
170 |
171 | case R.id.change_chosen_to_unchosen:
172 | case R.id.change_chosen_to_reserved:
173 | case R.id.change_chosen_to_empty:
174 | if (hasChosen()) changeSeats(id == R.id.change_chosen_to_unchosen ? UnChosenSeat.class
175 | : id == R.id.change_chosen_to_reserved ? ReservedSeat.class : EmptySeat.class);
176 | else toaster.show(R.string.no_chosen_seats);
177 | break;
178 | }
179 | }
180 |
181 | private void changeSeat(Seat last, Class extends Seat> nextClass) {
182 | if (model.tickets() <= chosen.get() && ChosenSeat.check(nextClass)) toaster.show(R.string.no_tickets_left);
183 | else setModel(Theatre.seat(model, adapter.replace(last, nextClass), last.getClass(), nextClass));
184 | }
185 |
186 | private void changeSeats(Class extends Seat> nextClass) {
187 | final boolean nextChosen = ChosenSeat.check(nextClass);
188 | final Seat[] lasts = new Seat[nextChosen ? unchosen.get() : chosen.get()];
189 | int total = 0, changes = total;
190 | final List seats = model.seats();
191 | final int size = seats.size();
192 | if (total < size) {
193 | do {
194 | final Seat last = seats.get(total);
195 | final Class extends Seat> lastClass = last.getClass();
196 | if ((nextChosen ? UnChosenSeat.check(lastClass) : ChosenSeat.check(lastClass)) && (!nextChosen
197 | || chosen.get() + changes < model.tickets())) {
198 | lasts[changes] = last;
199 | changes++;
200 | }
201 | total++;
202 | } while (total < size);
203 | }
204 | for (int index = 0; index < changes; index++) changeSeat(lasts[index], nextClass);
205 | }
206 |
207 | private void reset() {
208 | setModel(Theatre.reset(model, TheatreUtils.seats()));
209 | adapter.setModels(model.seats());
210 | }
211 |
212 | private boolean hasChosen() {
213 | return chosen.get() > 0;
214 | }
215 | }
216 |
217 | @dagger.Module(includes = { SeatAdapter.Module.class }) public abstract class Module {
218 | @ForActivity @Binds abstract BaseActivity baseActivity(TheatreActivity activity);
219 | }
220 | }
221 |
--------------------------------------------------------------------------------
/.idea/codeStyleSettings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
847 |