Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Hans.Lahe
/
thesis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Pipelines
Snippets
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
df953f27
authored
Jun 05, 2017
by
Joosep L
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added features/bug fixes
parent
4ffec09d
Hide whitespace changes
Inline
Side-by-side
Showing
52 changed files
with
1554 additions
and
274 deletions
app/build.gradle
app/src/main/AndroidManifest.xml
app/src/main/java/ee/ttu/thesis/data/AppDataManager.java
app/src/main/java/ee/ttu/thesis/data/model/Answer.java
app/src/main/java/ee/ttu/thesis/data/model/AnswerResponse.java
app/src/main/java/ee/ttu/thesis/data/model/Bound.java
app/src/main/java/ee/ttu/thesis/data/model/BoundResponse.java
app/src/main/java/ee/ttu/thesis/data/model/CheckIn.java
app/src/main/java/ee/ttu/thesis/data/model/CheckInResponse.java
app/src/main/java/ee/ttu/thesis/data/model/User.java
app/src/main/java/ee/ttu/thesis/data/model/UserGame.java
app/src/main/java/ee/ttu/thesis/data/network/ApiEndPoint.java
app/src/main/java/ee/ttu/thesis/data/network/ApiHelper.java
app/src/main/java/ee/ttu/thesis/data/network/AppApiHelper.java
app/src/main/java/ee/ttu/thesis/data/prefs/AppPreferencesHelper.java
app/src/main/java/ee/ttu/thesis/data/prefs/PreferencesHelper.java
app/src/main/java/ee/ttu/thesis/ui/future/FutureGameActivity.java
app/src/main/java/ee/ttu/thesis/ui/game/GameActivity.java
app/src/main/java/ee/ttu/thesis/ui/game/GamePresenter.java
app/src/main/java/ee/ttu/thesis/ui/game/GameTreasureHuntPresenter.java
app/src/main/java/ee/ttu/thesis/ui/game/GameView.java
app/src/main/java/ee/ttu/thesis/ui/game/InfoDialogFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/map/MapFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/point/DialogFragmentSolveQuestion.java
app/src/main/java/ee/ttu/thesis/ui/game/point/GameFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/point/GameLocationFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/point/GamePhotoFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/point/QRScannerDialogFragment.java
app/src/main/java/ee/ttu/thesis/ui/game/point/SolveFragment.java
app/src/main/java/ee/ttu/thesis/ui/list/GamesAdapter.java
app/src/main/java/ee/ttu/thesis/ui/list/ListActivity.java
app/src/main/java/ee/ttu/thesis/ui/list/ListPresenter.java
app/src/main/java/ee/ttu/thesis/ui/list/ListTreasureHuntPresenter.java
app/src/main/java/ee/ttu/thesis/ui/list/ViewHolderGamesButtons.java
app/src/main/java/ee/ttu/thesis/ui/login/LoginActivity.java
app/src/main/java/ee/ttu/thesis/ui/login/LoginPresenter.java
app/src/main/java/ee/ttu/thesis/ui/login/LoginTreasureHuntPresenter.java
app/src/main/java/ee/ttu/thesis/ui/login/LoginView.java
app/src/main/java/ee/ttu/thesis/ui/past/HistoryActivity.java
app/src/main/java/ee/ttu/thesis/ui/start/StartActivity.java
app/src/main/java/ee/ttu/thesis/ui/start/StartPresenter.java
app/src/main/java/ee/ttu/thesis/ui/start/StartTreasureHuntPresenter.java
app/src/main/res/drawable/gradient_rectangle_map_overlay.xml
app/src/main/res/layout/activity_history.xml
app/src/main/res/layout/activity_main.xml
app/src/main/res/layout/dialog_info.xml
app/src/main/res/layout/fragment_compass.xml
app/src/main/res/layout/item_game_button.xml
app/src/main/res/layout/layout_compass.xml
app/src/main/res/layout/layout_distance.xml
app/src/main/res/values/colors.xml
app/src/main/res/values/strings.xml
app/build.gradle
View file @
df953f27
...
@@ -62,6 +62,7 @@ dependencies {
...
@@ -62,6 +62,7 @@ dependencies {
compile
'com.github.deano2390:MaterialShowcaseView:1.1.0'
compile
'com.github.deano2390:MaterialShowcaseView:1.1.0'
compile
'com.facebook.android:facebook-android-sdk:[4,5)'
compile
(
'com.github.worker8:tourguide:1.0.17-SNAPSHOT@aar'
){
compile
(
'com.github.worker8:tourguide:1.0.17-SNAPSHOT@aar'
){
transitive
=
true
transitive
=
true
...
...
app/src/main/AndroidManifest.xml
View file @
df953f27
...
@@ -7,28 +7,52 @@
...
@@ -7,28 +7,52 @@
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<uses-permission
android:name=
"android.permission.READ_CONTACTS"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.READ_PROFILE"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_FINE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.ACCESS_COARSE_LOCATION"
/>
<uses-permission
android:name=
"android.permission.NFC"
/>
<uses-permission
android:name=
"android.permission.NFC"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"android.permission.CAMERA"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"android.permission.VIBRATE"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-feature
android:name=
"android.hardware.nfc"
android:required=
"true"
/>
<uses-feature
android:name=
"android.hardware.nfc"
android:required=
"true"
/>
<application
<application
android:name=
".ThesisApp"
android:name=
".ThesisApp"
android:allowBackup=
"true"
android:allowBackup=
"true"
android:icon=
"@mipmap/ic_launcher"
android:hardwareAccelerated=
"true"
android:hardwareAccelerated=
"true"
android:icon=
"@mipmap/ic_launcher"
android:label=
"@string/app_name"
android:label=
"@string/app_name"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:roundIcon=
"@mipmap/ic_launcher_round"
android:supportsRtl=
"true"
android:supportsRtl=
"true"
android:theme=
"@style/AppTheme"
>
android:theme=
"@style/AppTheme"
>
<meta-data
android:name=
"com.facebook.sdk.ApplicationId"
android:value=
"@string/facebook_app_id"
/>
<activity
android:name=
"com.facebook.FacebookActivity"
android:configChanges=
"keyboard|keyboardHidden|screenLayout|screenSize|orientation"
android:label=
"@string/app_name"
/>
<activity
android:name=
"com.facebook.CustomTabActivity"
android:exported=
"true"
>
<intent-filter>
<action
android:name=
"android.intent.action.VIEW"
/>
<category
android:name=
"android.intent.category.DEFAULT"
/>
<category
android:name=
"android.intent.category.BROWSABLE"
/>
<data
android:scheme=
"@string/fb_login_protocol_scheme"
/>
</intent-filter>
</activity>
<activity
<activity
android:name=
".ui.login.LoginActivity"
android:name=
".ui.login.LoginActivity"
android:
screenOrientation=
"portrait
"
android:
label=
"@string/app_name
"
android:
label=
"@string/app_name
"
>
android:
screenOrientation=
"portrait
"
>
<intent-filter>
<intent-filter>
<action
android:name=
"android.intent.action.MAIN"
/>
<action
android:name=
"android.intent.action.MAIN"
/>
...
@@ -38,34 +62,28 @@
...
@@ -38,34 +62,28 @@
<activity
<activity
android:name=
".ui.list.ListActivity"
android:name=
".ui.list.ListActivity"
android:screenOrientation=
"portrait"
>
android:screenOrientation=
"portrait"
></activity>
</activity>
<activity
<activity
android:name=
".ui.start.StartActivity"
android:name=
".ui.start.StartActivity"
android:screenOrientation=
"portrait"
>
android:screenOrientation=
"portrait"
></activity>
</activity>
<activity
<activity
android:name=
".ui.game.GameActivity"
android:name=
".ui.game.GameActivity"
android:screenOrientation=
"portrait"
>
android:screenOrientation=
"portrait"
></activity>
</activity>
<activity
<activity
android:name=
".ui.future.FutureGameActivity"
android:name=
".ui.future.FutureGameActivity"
android:screenOrientation=
"portrait"
>
android:screenOrientation=
"portrait"
></activity>
</activity>
<activity
<activity
android:name=
".ui.past.HistoryActivity"
android:name=
".ui.past.HistoryActivity"
android:screenOrientation=
"portrait"
>
android:screenOrientation=
"portrait"
></activity>
</activity>
<meta-data
<meta-data
android:name=
"com.google.android.geo.API_KEY"
android:name=
"com.google.android.geo.API_KEY"
android:value=
"AIzaSyCVOu0A8kPjB3jfA09CzqoEwrZ-VAbJuyQ"
/>
android:value=
"AIzaSyCVOu0A8kPjB3jfA09CzqoEwrZ-VAbJuyQ"
/>
</application>
</application>
</manifest>
</manifest>
\ No newline at end of file
app/src/main/java/ee/ttu/thesis/data/AppDataManager.java
View file @
df953f27
...
@@ -8,6 +8,7 @@ import javax.inject.Inject;
...
@@ -8,6 +8,7 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
...
@@ -67,6 +68,11 @@ public class AppDataManager implements DataManager {
...
@@ -67,6 +68,11 @@ public class AppDataManager implements DataManager {
}
}
@Override
@Override
public
Observable
<
String
>
endGame
(
String
userGameId
)
{
return
mApiHelper
.
endGame
(
userGameId
);
}
@Override
public
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
)
{
public
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
)
{
return
mApiHelper
.
getGame
(
gameCode
);
return
mApiHelper
.
getGame
(
gameCode
);
}
}
...
@@ -82,16 +88,31 @@ public class AppDataManager implements DataManager {
...
@@ -82,16 +88,31 @@ public class AppDataManager implements DataManager {
}
}
@Override
@Override
public
Observable
<
List
<
Bound
>>
getBounds
(
String
gameId
)
{
return
mApiHelper
.
getBounds
(
gameId
);
}
@Override
public
Observable
<
String
>
postAnswer
(
Answer
answer
)
{
public
Observable
<
String
>
postAnswer
(
Answer
answer
)
{
return
mApiHelper
.
postAnswer
(
answer
);
return
mApiHelper
.
postAnswer
(
answer
);
}
}
@Override
@Override
public
Observable
<
String
>
login
(
String
service
,
String
access_token
)
{
return
mApiHelper
.
login
(
service
,
access_token
);
}
@Override
public
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
)
{
public
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
)
{
return
mApiHelper
.
getStats
(
user_id
,
game_id
);
return
mApiHelper
.
getStats
(
user_id
,
game_id
);
}
}
@Override
@Override
public
Observable
<
UserGame
>
getUserGame
(
String
gameCode
,
String
userId
)
{
return
mApiHelper
.
getUserGame
(
gameCode
,
userId
);
}
@Override
public
int
getCurrentUserId
()
{
public
int
getCurrentUserId
()
{
return
mPreferencesHelper
.
getCurrentUserId
();
return
mPreferencesHelper
.
getCurrentUserId
();
}
}
...
@@ -102,12 +123,33 @@ public class AppDataManager implements DataManager {
...
@@ -102,12 +123,33 @@ public class AppDataManager implements DataManager {
}
}
@Override
@Override
public
int
getCurrentGam
e
()
{
public
String
getCurrentGameCod
e
()
{
return
0
;
return
mPreferencesHelper
.
getCurrentGameCode
()
;
}
}
@Override
@Override
public
void
setCurrentGameId
(
int
gameId
)
{
public
void
setCurrentGameCode
(
String
gameCode
)
{
mPreferencesHelper
.
setCurrentGameCode
(
gameCode
);
}
@Override
public
String
getService
()
{
return
mPreferencesHelper
.
getService
();
}
@Override
public
void
setService
(
String
service
)
{
mPreferencesHelper
.
setService
(
service
);
}
@Override
public
int
getCurrentPoint
()
{
return
mPreferencesHelper
.
getCurrentPoint
();
}
@Override
public
void
setCurrentPoint
(
int
currentPoint
)
{
mPreferencesHelper
.
setCurrentPoint
(
currentPoint
);
}
}
}
}
app/src/main/java/ee/ttu/thesis/data/model/Answer.java
View file @
df953f27
...
@@ -30,9 +30,21 @@ public class Answer {
...
@@ -30,9 +30,21 @@ public class Answer {
private
String
answer
;
private
String
answer
;
@Expose
@Expose
@SerializedName
(
"photo"
)
private
String
photoInBase64
;
@Expose
@SerializedName
(
"is_correct"
)
@SerializedName
(
"is_correct"
)
private
boolean
is_correct
;
private
boolean
is_correct
;
public
String
getPhotoInBase64
()
{
return
photoInBase64
;
}
public
void
setPhotoInBase64
(
String
photoInBase64
)
{
this
.
photoInBase64
=
photoInBase64
;
}
public
int
getId
()
{
public
int
getId
()
{
return
id
;
return
id
;
}
}
...
@@ -89,6 +101,9 @@ public class Answer {
...
@@ -89,6 +101,9 @@ public class Answer {
this
.
is_correct
=
is_correct
;
this
.
is_correct
=
is_correct
;
}
}
public
Answer
()
{
}
public
Answer
(
String
answer
)
{
public
Answer
(
String
answer
)
{
this
.
answer
=
answer
;
this
.
answer
=
answer
;
}
}
...
...
app/src/main/java/ee/ttu/thesis/data/model/AnswerResponse.java
0 → 100644
View file @
df953f27
package
ee
.
ttu
.
thesis
.
data
.
model
;
/**
* Created by hajola on 5.06.17.
*/
public
class
AnswerResponse
{
String
id
;
public
String
getId
()
{
return
id
;
}
public
void
setId
(
String
id
)
{
this
.
id
=
id
;
}
}
app/src/main/java/ee/ttu/thesis/data/model/Bound.java
View file @
df953f27
...
@@ -21,6 +21,17 @@ public class Bound {
...
@@ -21,6 +21,17 @@ public class Bound {
@SerializedName
(
"notification_text"
)
@SerializedName
(
"notification_text"
)
private
String
text
;
private
String
text
;
@Expose
@SerializedName
(
"mpoly"
)
private
String
mpoly
;
public
String
getMpoly
()
{
return
mpoly
;
}
public
void
setMpoly
(
String
mpoly
)
{
this
.
mpoly
=
mpoly
;
}
@Expose
@Expose
@SerializedName
(
"violated_on"
)
@SerializedName
(
"violated_on"
)
...
...
app/src/main/java/ee/ttu/thesis/data/model/BoundResponse.java
0 → 100644
View file @
df953f27
package
ee
.
ttu
.
thesis
.
data
.
model
;
import
java.util.ArrayList
;
import
java.util.List
;
/**
* Created by hajola on 4.06.17.
*/
public
class
BoundResponse
{
List
<
Bound
>
mBounds
;
public
List
<
Bound
>
getmBounds
()
{
return
mBounds
;
}
public
void
setmBounds
(
List
<
Bound
>
mBounds
)
{
this
.
mBounds
=
mBounds
;
}
}
app/src/main/java/ee/ttu/thesis/data/model/CheckIn.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
data
.
model
;
package
ee
.
ttu
.
thesis
.
data
.
model
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.SerializedName
;
import
com.google.gson.annotations.SerializedName
;
...
@@ -42,9 +43,21 @@ public class CheckIn {
...
@@ -42,9 +43,21 @@ public class CheckIn {
private
int
current_point_id
;
private
int
current_point_id
;
@Expose
@Expose
@SerializedName
(
"current_point"
)
private
int
current_point
;
@Expose
@SerializedName
(
"latest_answer_id"
)
@SerializedName
(
"latest_answer_id"
)
private
int
latest_answer_id
;
private
int
latest_answer_id
;
public
int
getCurrent_point
()
{
return
current_point
;
}
public
void
setCurrent_point
(
int
current_point
)
{
this
.
current_point
=
current_point
;
}
public
int
getUser_game_id
()
{
public
int
getUser_game_id
()
{
return
user_game_id
;
return
user_game_id
;
}
}
...
@@ -77,6 +90,10 @@ public class CheckIn {
...
@@ -77,6 +90,10 @@ public class CheckIn {
this
.
current_point_id
=
current_point_id
;
this
.
current_point_id
=
current_point_id
;
}
}
public
LatLng
getLatLng
(){
return
new
LatLng
(
lat
,
lon
);
}
public
int
getLatest_answer_id
()
{
public
int
getLatest_answer_id
()
{
return
latest_answer_id
;
return
latest_answer_id
;
}
}
...
...
app/src/main/java/ee/ttu/thesis/data/model/CheckInResponse.java
View file @
df953f27
...
@@ -5,8 +5,6 @@ import com.google.gson.annotations.SerializedName;
...
@@ -5,8 +5,6 @@ import com.google.gson.annotations.SerializedName;
import
java.util.List
;
import
java.util.List
;
import
io.reactivex.Observable
;
/**
/**
* Created by hajola on 17.05.17.
* Created by hajola on 17.05.17.
*/
*/
...
@@ -25,6 +23,17 @@ public class CheckInResponse {
...
@@ -25,6 +23,17 @@ public class CheckInResponse {
@SerializedName
(
"answer"
)
@SerializedName
(
"answer"
)
private
Answer
answer
;
private
Answer
answer
;
@Expose
@SerializedName
(
"isover"
)
private
int
isOver
;
public
int
getIsOver
()
{
return
isOver
;
}
public
void
setIsOver
(
int
isOver
)
{
this
.
isOver
=
isOver
;
}
public
List
<
Bound
>
getBounds
()
{
public
List
<
Bound
>
getBounds
()
{
return
bounds
;
return
bounds
;
...
...
app/src/main/java/ee/ttu/thesis/data/model/User.java
View file @
df953f27
...
@@ -12,11 +12,22 @@ import com.google.gson.annotations.SerializedName;
...
@@ -12,11 +12,22 @@ import com.google.gson.annotations.SerializedName;
public
class
User
implements
Parcelable
{
public
class
User
implements
Parcelable
{
@Expose
@Expose
@SerializedName
(
"user_id"
)
@SerializedName
(
"user_id"
)
private
int
id
;
private
int
id
;
@Expose
@SerializedName
(
"service"
)
private
String
service
;
public
String
getService
()
{
return
service
;
}
public
void
setService
(
String
service
)
{
this
.
service
=
service
;
}
public
int
getId
()
{
public
int
getId
()
{
return
id
;
return
id
;
}
}
...
@@ -25,6 +36,9 @@ public class User implements Parcelable {
...
@@ -25,6 +36,9 @@ public class User implements Parcelable {
this
.
id
=
id
;
this
.
id
=
id
;
}
}
public
User
()
{
}
@Override
@Override
public
int
describeContents
()
{
public
int
describeContents
()
{
return
0
;
return
0
;
...
@@ -33,16 +47,15 @@ public class User implements Parcelable {
...
@@ -33,16 +47,15 @@ public class User implements Parcelable {
@Override
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeInt
(
this
.
id
);
dest
.
writeInt
(
this
.
id
);
}
dest
.
writeString
(
this
.
service
);
public
User
()
{
}
}
protected
User
(
Parcel
in
)
{
protected
User
(
Parcel
in
)
{
this
.
id
=
in
.
readInt
();
this
.
id
=
in
.
readInt
();
this
.
service
=
in
.
readString
();
}
}
public
static
final
Parcelable
.
Creator
<
User
>
CREATOR
=
new
Parcelable
.
Creator
<
User
>()
{
public
static
final
Creator
<
User
>
CREATOR
=
new
Creator
<
User
>()
{
@Override
@Override
public
User
createFromParcel
(
Parcel
source
)
{
public
User
createFromParcel
(
Parcel
source
)
{
return
new
User
(
source
);
return
new
User
(
source
);
...
...
app/src/main/java/ee/ttu/thesis/data/model/UserGame.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
data
.
model
;
package
ee
.
ttu
.
thesis
.
data
.
model
;
import
android.os.Parcel
;
import
android.os.Parcelable
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.Expose
;
import
com.google.gson.annotations.SerializedName
;
import
com.google.gson.annotations.SerializedName
;
import
java.util.Date
;
/**
/**
* Created by hajola on 9.05.17.
* Created by hajola on 9.05.17.
*/
*/
public
class
UserGame
{
public
class
UserGame
implements
Parcelable
{
@Expose
@Expose
@SerializedName
(
"user_game_id"
)
@SerializedName
(
"user_game_id"
)
...
@@ -17,6 +22,14 @@ public class UserGame {
...
@@ -17,6 +22,14 @@ public class UserGame {
@SerializedName
(
"game"
)
@SerializedName
(
"game"
)
private
Game
game
;
private
Game
game
;
@Expose
@SerializedName
(
"start_time"
)
private
Date
start
;
@Expose
@SerializedName
(
"end_time"
)
private
Date
end
;
public
int
getUserGameId
()
{
public
int
getUserGameId
()
{
return
UserGameId
;
return
UserGameId
;
}
}
...
@@ -33,8 +46,61 @@ public class UserGame {
...
@@ -33,8 +46,61 @@ public class UserGame {
this
.
game
=
game
;
this
.
game
=
game
;
}
}
public
Date
getStart
()
{
return
start
;
}
public
void
setStart
(
Date
start
)
{
this
.
start
=
start
;
}
public
Date
getEnd
()
{
return
end
;
}
public
void
setEnd
(
Date
end
)
{
this
.
end
=
end
;
}
@Override
@Override
public
String
toString
()
{
public
String
toString
()
{
return
"id: "
+
UserGameId
+
" game: "
+
game
.
toString
();
return
"id: "
+
UserGameId
+
" game: "
+
game
.
toString
();
}
}
@Override
public
int
describeContents
()
{
return
0
;
}
@Override
public
void
writeToParcel
(
Parcel
dest
,
int
flags
)
{
dest
.
writeInt
(
this
.
UserGameId
);
dest
.
writeParcelable
(
this
.
game
,
flags
);
dest
.
writeLong
(
this
.
start
!=
null
?
this
.
start
.
getTime
()
:
-
1
);
dest
.
writeLong
(
this
.
end
!=
null
?
this
.
end
.
getTime
()
:
-
1
);
}
public
UserGame
()
{
}
protected
UserGame
(
Parcel
in
)
{
this
.
UserGameId
=
in
.
readInt
();
this
.
game
=
in
.
readParcelable
(
Game
.
class
.
getClassLoader
());
long
tmpStart
=
in
.
readLong
();
this
.
start
=
tmpStart
==
-
1
?
null
:
new
Date
(
tmpStart
);
long
tmpEnd
=
in
.
readLong
();
this
.
end
=
tmpEnd
==
-
1
?
null
:
new
Date
(
tmpEnd
);
}
public
static
final
Parcelable
.
Creator
<
UserGame
>
CREATOR
=
new
Parcelable
.
Creator
<
UserGame
>()
{
@Override
public
UserGame
createFromParcel
(
Parcel
source
)
{
return
new
UserGame
(
source
);
}
@Override
public
UserGame
[]
newArray
(
int
size
)
{
return
new
UserGame
[
size
];
}
};
}
}
app/src/main/java/ee/ttu/thesis/data/network/ApiEndPoint.java
View file @
df953f27
...
@@ -7,7 +7,7 @@ package ee.ttu.thesis.data.network;
...
@@ -7,7 +7,7 @@ package ee.ttu.thesis.data.network;
public
final
class
ApiEndPoint
{
public
final
class
ApiEndPoint
{
//
//
public
static
final
String
BASE_URL
=
"http://12
7.0.0.1
/api"
;
public
static
final
String
BASE_URL
=
"http://12
8.199.63.125
/api"
;
public
static
final
String
ENDPOINT_GET_GAMES
=
BASE_URL
public
static
final
String
ENDPOINT_GET_GAMES
=
BASE_URL
+
"/user/games"
;
+
"/user/games"
;
...
@@ -24,15 +24,24 @@ public final class ApiEndPoint {
...
@@ -24,15 +24,24 @@ public final class ApiEndPoint {
public
static
final
String
ENDPOINT_GET_CHECK_INS
=
BASE_URL
public
static
final
String
ENDPOINT_GET_CHECK_INS
=
BASE_URL
+
"/game/stats"
;
+
"/game/stats"
;
public
static
final
String
ENDPOINT_GET_BOUNDS
=
BASE_URL
+
"/game/bounds"
;
public
static
final
String
ENDPOINT_START_GAME
=
BASE_URL
public
static
final
String
ENDPOINT_START_GAME
=
BASE_URL
+
"/game/start"
;
+
"/game/start"
;
public
static
final
String
ENDPOINT_END_GAME
=
BASE_URL
+
"/game/end"
;
public
static
final
String
ENDPOINT_GET_GAME
=
BASE_URL
public
static
final
String
ENDPOINT_GET_GAME
=
BASE_URL
+
"/games"
;
+
"/games"
;
public
static
final
String
ENDPOINT_MAKE_USER
=
BASE_URL
public
static
final
String
ENDPOINT_MAKE_USER
=
BASE_URL
+
"/user/add"
;
+
"/user/add"
;
public
static
final
String
ENDPOINT_LOGIN
=
BASE_URL
+
"/user/login"
;
public
static
final
String
ENDPOINT_POST_MESSAGE
=
BASE_URL
public
static
final
String
ENDPOINT_POST_MESSAGE
=
BASE_URL
+
"/game/message"
;
+
"/game/message"
;
...
...
app/src/main/java/ee/ttu/thesis/data/network/ApiHelper.java
View file @
df953f27
...
@@ -3,6 +3,7 @@ package ee.ttu.thesis.data.network;
...
@@ -3,6 +3,7 @@ package ee.ttu.thesis.data.network;
import
java.util.List
;
import
java.util.List
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
...
@@ -32,14 +33,22 @@ public interface ApiHelper {
...
@@ -32,14 +33,22 @@ public interface ApiHelper {
Observable
<
String
>
startGame
(
String
userGameId
);
Observable
<
String
>
startGame
(
String
userGameId
);
Observable
<
String
>
endGame
(
String
userGameId
);
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
);
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
);
Observable
<
User
>
makeUser
(
String
userName
,
String
deviceId
);
Observable
<
User
>
makeUser
(
String
userName
,
String
deviceId
);
Observable
<
String
>
postMessage
(
Message
request
);
Observable
<
String
>
postMessage
(
Message
request
);
Observable
<
List
<
Bound
>>
getBounds
(
String
gameId
);
Observable
<
String
>
postAnswer
(
Answer
answer
);
Observable
<
String
>
postAnswer
(
Answer
answer
);
Observable
<
String
>
login
(
String
service
,
String
access_token
);
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
);
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
);
Observable
<
UserGame
>
getUserGame
(
String
gameCode
,
String
userId
);
}
}
app/src/main/java/ee/ttu/thesis/data/network/AppApiHelper.java
View file @
df953f27
...
@@ -8,6 +8,7 @@ import javax.inject.Inject;
...
@@ -8,6 +8,7 @@ import javax.inject.Inject;
import
javax.inject.Singleton
;
import
javax.inject.Singleton
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
...
@@ -87,6 +88,14 @@ public class AppApiHelper implements ApiHelper {
...
@@ -87,6 +88,14 @@ public class AppApiHelper implements ApiHelper {
}
}
@Override
@Override
public
Observable
<
String
>
endGame
(
String
userGameId
)
{
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_END_GAME
)
.
addBodyParameter
(
"user_game_id"
,
userGameId
)
.
build
()
.
getObjectObservable
(
String
.
class
);
}
@Override
public
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
)
{
public
Observable
<
List
<
Game
>>
getGame
(
String
gameCode
)
{
return
Rx2AndroidNetworking
.
get
(
ApiEndPoint
.
ENDPOINT_GET_GAME
)
return
Rx2AndroidNetworking
.
get
(
ApiEndPoint
.
ENDPOINT_GET_GAME
)
.
addQueryParameter
(
"game_code"
,
gameCode
)
.
addQueryParameter
(
"game_code"
,
gameCode
)
...
@@ -114,23 +123,63 @@ public class AppApiHelper implements ApiHelper {
...
@@ -114,23 +123,63 @@ public class AppApiHelper implements ApiHelper {
}
}
@Override
@Override
public
Observable
<
List
<
Bound
>>
getBounds
(
String
gameId
)
{
return
Rx2AndroidNetworking
.
get
(
ApiEndPoint
.
ENDPOINT_GET_BOUNDS
)
.
addQueryParameter
(
"game"
,
gameId
)
.
build
()
.
getObjectListObservable
(
Bound
.
class
);
}
@Override
public
Observable
<
String
>
postAnswer
(
Answer
answer
)
{
public
Observable
<
String
>
postAnswer
(
Answer
answer
)
{
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_POST_ANSWER
)
if
(
answer
.
getPhotoInBase64
()
==
null
)
{
.
addBodyParameter
(
"user_game_id"
,
Integer
.
toString
(
answer
.
getUser_game_id
()))
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_POST_ANSWER
)
.
addBodyParameter
(
"point_id"
,
Integer
.
toString
(
answer
.
getPoint_id
()))
.
addBodyParameter
(
"user_game_id"
,
Integer
.
toString
(
answer
.
getUser_game_id
()))
.
addBodyParameter
(
"problem_type_id"
,
Integer
.
toString
(
answer
.
getProblem_type
().
getId
()))
.
addBodyParameter
(
"point_id"
,
Integer
.
toString
(
answer
.
getPoint_id
()))
.
addBodyParameter
(
"given_answer"
,
answer
.
getAnswer
())
.
addBodyParameter
(
"problem_type_id"
,
Integer
.
toString
(
answer
.
getProblem_type
().
getId
()))
.
addBodyParameter
(
"is_correct"
,
answer
.
is_correct
()
?
"1"
:
"0"
)
.
addBodyParameter
(
"given_answer"
,
answer
.
getAnswer
())
.
addBodyParameter
(
"is_correct"
,
answer
.
is_correct
()
?
"1"
:
"0"
)
.
build
()
.
getObjectObservable
(
String
.
class
);
}
else
{
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_POST_ANSWER
)
.
addBodyParameter
(
"user_game_id"
,
Integer
.
toString
(
answer
.
getUser_game_id
()))
.
addBodyParameter
(
"point_id"
,
Integer
.
toString
(
answer
.
getPoint_id
()))
.
addBodyParameter
(
"problem_type_id"
,
Integer
.
toString
(
answer
.
getProblem_type
().
getId
()))
.
addBodyParameter
(
"given_answer"
,
answer
.
getAnswer
())
.
addBodyParameter
(
"photo"
,
answer
.
getPhotoInBase64
())
.
addBodyParameter
(
"is_correct"
,
answer
.
is_correct
()
?
"1"
:
"0"
)
.
build
()
.
getObjectObservable
(
String
.
class
);
}
}
@Override
public
Observable
<
String
>
login
(
String
service
,
String
access_token
)
{
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_LOGIN
)
.
addBodyParameter
(
"service"
,
service
)
.
addBodyParameter
(
"access_token"
,
access_token
)
.
build
()
.
build
()
.
getObjectObservable
(
String
.
class
);
.
getObjectObservable
(
String
.
class
);
}
}
@Override
@Override
public
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
)
{
public
Observable
<
List
<
CheckIn
>>
getStats
(
String
user_id
,
String
game_id
)
{
return
Rx2AndroidNetworking
.
get
(
ApiEndPoint
.
ENDPOINT_GET_
POINT
S
)
return
Rx2AndroidNetworking
.
get
(
ApiEndPoint
.
ENDPOINT_GET_
CHECK_IN
S
)
.
addQueryParameter
(
"user_id"
,
user_id
)
.
addQueryParameter
(
"user_id"
,
user_id
)
.
addQueryParameter
(
"game_id"
,
game_id
)
.
addQueryParameter
(
"game_id"
,
game_id
)
.
build
()
.
build
()
.
getObjectListObservable
(
CheckIn
.
class
);
.
getObjectListObservable
(
CheckIn
.
class
);
}
}
@Override
public
Observable
<
UserGame
>
getUserGame
(
String
gameCode
,
String
userId
)
{
return
Rx2AndroidNetworking
.
post
(
ApiEndPoint
.
ENDPOINT_ADD_USER_GAME
)
.
addBodyParameter
(
"game_code"
,
gameCode
)
.
addBodyParameter
(
"user_id"
,
userId
)
.
build
()
.
getObjectObservable
(
UserGame
.
class
);
}
}
}
app/src/main/java/ee/ttu/thesis/data/prefs/AppPreferencesHelper.java
View file @
df953f27
...
@@ -20,6 +20,10 @@ public class AppPreferencesHelper implements PreferencesHelper {
...
@@ -20,6 +20,10 @@ public class AppPreferencesHelper implements PreferencesHelper {
private
static
final
String
PREF_KEY_CURRENT_GAME
=
"PREF_KEY_CURRENT_GAME"
;
private
static
final
String
PREF_KEY_CURRENT_GAME
=
"PREF_KEY_CURRENT_GAME"
;
private
static
final
String
PREF_KEY_SERVICE
=
"PREF_KEY_SERVICE"
;
private
static
final
String
PREF_KEY_CURRENT_POINT
=
"PREF_KEY_CURRENT_POINT"
;
private
final
SharedPreferences
mPrefs
;
private
final
SharedPreferences
mPrefs
;
@Inject
@Inject
...
@@ -31,8 +35,6 @@ public class AppPreferencesHelper implements PreferencesHelper {
...
@@ -31,8 +35,6 @@ public class AppPreferencesHelper implements PreferencesHelper {
@Override
@Override
public
int
getCurrentUserId
()
{
public
int
getCurrentUserId
()
{
int
userId
=
mPrefs
.
getInt
(
PREF_KEY_CURRENT_USER_ID
,
0
);
int
userId
=
mPrefs
.
getInt
(
PREF_KEY_CURRENT_USER_ID
,
0
);
if
(
userId
==
0
)
return
1
;
return
userId
;
return
userId
;
}
}
...
@@ -43,14 +45,35 @@ public class AppPreferencesHelper implements PreferencesHelper {
...
@@ -43,14 +45,35 @@ public class AppPreferencesHelper implements PreferencesHelper {
}
}
@Override
@Override
public
int
getCurrentGame
()
{
public
String
getCurrentGameCode
()
{
int
id
=
mPrefs
.
getInt
(
PREF_KEY_CURRENT_GAME
,
0
);
String
gameCode
=
mPrefs
.
getString
(
PREF_KEY_CURRENT_GAME
,
null
);
return
id
;
return
gameCode
;
}
@Override
public
void
setCurrentGameCode
(
String
gameCode
)
{
mPrefs
.
edit
().
putString
(
PREF_KEY_CURRENT_GAME
,
gameCode
).
apply
();
}
@Override
public
String
getService
()
{
String
service
=
mPrefs
.
getString
(
PREF_KEY_SERVICE
,
null
);
return
service
;
}
}
@Override
@Override
public
void
setCurrentGameId
(
int
gameId
)
{
public
void
setService
(
String
service
)
{
int
id
=
gameId
;
mPrefs
.
edit
().
putString
(
PREF_KEY_SERVICE
,
service
).
apply
();
mPrefs
.
edit
().
putInt
(
PREF_KEY_CURRENT_GAME
,
id
).
apply
();
}
}
@Override
public
int
getCurrentPoint
()
{
return
mPrefs
.
getInt
(
PREF_KEY_CURRENT_POINT
,
-
1
);
}
@Override
public
void
setCurrentPoint
(
int
currentPoint
)
{
mPrefs
.
edit
().
putInt
(
PREF_KEY_CURRENT_POINT
,
currentPoint
).
apply
();
}
}
}
app/src/main/java/ee/ttu/thesis/data/prefs/PreferencesHelper.java
View file @
df953f27
...
@@ -10,8 +10,17 @@ public interface PreferencesHelper {
...
@@ -10,8 +10,17 @@ public interface PreferencesHelper {
void
setCurrentUserId
(
int
userId
);
void
setCurrentUserId
(
int
userId
);
int
getCurrentGame
();
String
getCurrentGameCode
();
void
setCurrentGameCode
(
String
gameCode
);
String
getService
();
void
setService
(
String
service
);
int
getCurrentPoint
();
void
setCurrentPoint
(
int
currentPoint
);
void
setCurrentGameId
(
int
gameId
);
}
}
app/src/main/java/ee/ttu/thesis/ui/future/FutureGameActivity.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
future
;
package
ee
.
ttu
.
thesis
.
ui
.
future
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.CountDownTimer
;
import
android.os.CountDownTimer
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
...
@@ -13,10 +14,16 @@ import butterknife.BindView;
...
@@ -13,10 +14,16 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
import
butterknife.OnClick
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.ui.list.ListActivity
;
import
ee.ttu.thesis.ui.start.StartActivity
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
/**
/**
* Created by hajola on 28.04.17.
* Created by hajola on 28.04.17.
...
@@ -38,6 +45,8 @@ public class FutureGameActivity extends BaseActivity {
...
@@ -38,6 +45,8 @@ public class FutureGameActivity extends BaseActivity {
TextView
mDescription
;
TextView
mDescription
;
Game
mGame
;
Game
mGame
;
User
mUser
;
UserGame
mUserGame
;
@Override
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
...
@@ -46,6 +55,8 @@ public class FutureGameActivity extends BaseActivity {
...
@@ -46,6 +55,8 @@ public class FutureGameActivity extends BaseActivity {
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mUserGame
=
getIntent
().
getParcelableExtra
(
USER_GAME_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
mTitle
.
setText
(
mGame
.
getTitle
());
mTitle
.
setText
(
mGame
.
getTitle
());
mDescription
.
setText
(
mGame
.
getDescription
());
mDescription
.
setText
(
mGame
.
getDescription
());
...
@@ -78,7 +89,12 @@ public class FutureGameActivity extends BaseActivity {
...
@@ -78,7 +89,12 @@ public class FutureGameActivity extends BaseActivity {
}
}
public
void
onFinish
()
{
public
void
onFinish
()
{
// mTextField.setText("done!");
Intent
intent
=
new
Intent
(
FutureGameActivity
.
this
,
StartActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
USER_GAME_KEY
,
mUserGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
finish
();
}
}
}.
start
();
}.
start
();
...
...
app/src/main/java/ee/ttu/thesis/ui/game/GameActivity.java
View file @
df953f27
...
@@ -21,6 +21,7 @@ import android.support.v4.app.FragmentManager;
...
@@ -21,6 +21,7 @@ import android.support.v4.app.FragmentManager;
import
android.support.v4.app.FragmentStatePagerAdapter
;
import
android.support.v4.app.FragmentStatePagerAdapter
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.content.ContextCompat
;
import
android.support.v4.view.ViewPager
;
import
android.support.v4.view.ViewPager
;
import
android.view.View
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.ConnectionResult
;
...
@@ -48,18 +49,24 @@ import butterknife.BindView;
...
@@ -48,18 +49,24 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.
Messag
e
;
import
ee.ttu.thesis.data.model.
AnswerRespons
e
;
import
ee.ttu.thesis.data.model.
User
;
import
ee.ttu.thesis.data.model.
Bound
;
import
ee.ttu.thesis.
ui.base.BaseActivity
;
import
ee.ttu.thesis.
data.model.BoundResponse
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.Message
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.game.map.MapFragment
;
import
ee.ttu.thesis.ui.game.map.MapFragment
;
import
ee.ttu.thesis.ui.game.messages.NotificationFragment
;
import
ee.ttu.thesis.ui.game.messages.NotificationFragment
;
import
ee.ttu.thesis.ui.game.point.GameFragment
;
import
ee.ttu.thesis.ui.game.point.GameFragment
;
import
ee.ttu.thesis.ui.list.AddGameDialogFragment
;
import
ee.ttu.thesis.ui.list.ListActivity
;
import
ee.ttu.thesis.ui.list.ListActivity
;
import
ee.ttu.thesis.ui.past.HistoryActivity
;
import
ee.ttu.thesis.utils.RxBus
;
import
ee.ttu.thesis.utils.RxBus
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.CompositeDisposable
;
import
io.reactivex.disposables.CompositeDisposable
;
...
@@ -74,12 +81,13 @@ public class GameActivity extends BaseActivity
...
@@ -74,12 +81,13 @@ public class GameActivity extends BaseActivity
GoogleApiClient
.
OnConnectionFailedListener
,
GoogleApiClient
.
OnConnectionFailedListener
,
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
ConnectionCallbacks
,
LocationListener
,
LocationListener
,
GameView
{
GameView
{
@Inject
@Inject
GameTreasureHuntPresenter
<
GameView
>
mPresenter
;
GameTreasureHuntPresenter
<
GameView
>
mPresenter
;
public
static
final
String
GAME_KEY
=
"game"
;
public
static
final
String
GAME_KEY
=
"game"
;
public
static
final
String
USER_GAME_KEY
=
"UserGame"
;
// Keys for storing activity state in the Bundle.
// Keys for storing activity state in the Bundle.
protected
final
static
String
KEY_REQUESTING_LOCATION_UPDATES
=
"requesting-location-updates"
;
protected
final
static
String
KEY_REQUESTING_LOCATION_UPDATES
=
"requesting-location-updates"
;
protected
final
static
String
KEY_LOCATION
=
"location"
;
protected
final
static
String
KEY_LOCATION
=
"location"
;
...
@@ -107,6 +115,7 @@ public class GameActivity extends BaseActivity
...
@@ -107,6 +115,7 @@ public class GameActivity extends BaseActivity
TabLayout
mTabLayout
;
TabLayout
mTabLayout
;
Game
mGame
;
Game
mGame
;
UserGame
mUserGame
;
User
mUser
;
User
mUser
;
Answer
mLatestAnswer
=
null
;
Answer
mLatestAnswer
=
null
;
ArrayList
<
Point
>
mPoints
;
ArrayList
<
Point
>
mPoints
;
...
@@ -115,7 +124,8 @@ public class GameActivity extends BaseActivity
...
@@ -115,7 +124,8 @@ public class GameActivity extends BaseActivity
RxBus
_rxBus
=
null
;
RxBus
_rxBus
=
null
;
CompositeDisposable
mDisposables
;
CompositeDisposable
mDisposables
;
ScreenSlidePagerAdapter
mPagerAdapter
;
ScreenSlidePagerAdapter
mPagerAdapter
;
// Et ainult iga teine asukoha muutus salvestataks
boolean
isNeedToCheckIn
=
false
;
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -126,9 +136,21 @@ public class GameActivity extends BaseActivity
...
@@ -126,9 +136,21 @@ public class GameActivity extends BaseActivity
mPresenter
.
onAttach
(
this
);
mPresenter
.
onAttach
(
this
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
m
Presenter
.
onViewInitialized
(
new
GamesRequest
.
PointsRequest
(
mGame
.
getId
())
);
m
UserGame
=
getIntent
().
getParcelableExtra
(
USER_GAME_KEY
);
if
(
mPresenter
.
getCurrentPoint
()
>=
0
){
mCurrentPoint
=
mPresenter
.
getCurrentPoint
();
FragmentManager
fm
=
getSupportFragmentManager
();
InfoDialogFragment
infoDialogFragment
=
InfoDialogFragment
.
newInstance
(
"Welcome back!"
);
infoDialogFragment
.
show
(
fm
,
"info_fragment"
);
}
else
{
mPresenter
.
saveCurrentPoint
(
mCurrentPoint
);
}
mPresenter
.
onViewInitialized
(
new
GamesRequest
.
PointsRequest
(
mGame
.
getId
()));
updateValuesFromBundle
(
savedInstanceState
);
updateValuesFromBundle
(
savedInstanceState
);
buildGoogleApiClient
();
buildGoogleApiClient
();
...
@@ -145,6 +167,11 @@ public class GameActivity extends BaseActivity
...
@@ -145,6 +167,11 @@ public class GameActivity extends BaseActivity
return
_rxBus
;
return
_rxBus
;
}
}
public
void
onGameFinished
(){
mPresenter
.
gameEnded
(
Integer
.
toString
(
mUserGame
.
getUserGameId
()));
}
/**
/**
* Updates fields based on data stored in the bundle.
* Updates fields based on data stored in the bundle.
*
*
...
@@ -359,18 +386,35 @@ public class GameActivity extends BaseActivity
...
@@ -359,18 +386,35 @@ public class GameActivity extends BaseActivity
@Override
@Override
public
void
accept
(
@io
.
reactivex
.
annotations
.
NonNull
Object
o
)
throws
Exception
{
public
void
accept
(
@io
.
reactivex
.
annotations
.
NonNull
Object
o
)
throws
Exception
{
if
(
o
instanceof
Answer
)
{
if
(
o
instanceof
Answer
)
{
((
Answer
)
o
).
setUser_game_id
(
mGame
.
getUserGameId
());
postAnswer
((
Answer
)
o
);
if
(((
Answer
)
o
).
is_correct
())
}
else
if
(
o
instanceof
Message
)
{
mCurrentPoint
++;
mLatestAnswer
=
(
Answer
)
o
;
mPresenter
.
postAnswer
((
Answer
)
o
);
}
else
if
(
o
instanceof
Message
){
mPresenter
.
postMessage
((
Message
)
o
);
mPresenter
.
postMessage
((
Message
)
o
);
}
else
if
(
o
instanceof
CheckInResponse
){
Answer
a
=
((
CheckInResponse
)
o
).
getAnswer
();
if
(
a
!=
null
)
{
if
(
a
.
getId
()
==
mLatestAnswer
.
getId
()
&&
a
.
is_correct
())
{
mCurrentPoint
++;
mPresenter
.
saveCurrentPoint
(
mCurrentPoint
);
}
else
{
}
}
}
}
}
}
}));
}));
}
}
public
void
postAnswer
(
Answer
answer
){
answer
.
setUser_game_id
(
mGame
.
getUserGameId
());
if
(
answer
.
is_correct
()){
mCurrentPoint
++;
mPresenter
.
saveCurrentPoint
(
mCurrentPoint
);
}
mLatestAnswer
=
answer
;
mPresenter
.
postAnswer
(
answer
);
}
@Override
@Override
protected
void
onNewIntent
(
Intent
intent
)
{
protected
void
onNewIntent
(
Intent
intent
)
{
if
(
NfcAdapter
.
ACTION_NDEF_DISCOVERED
.
equals
(
getIntent
().
getAction
()))
{
if
(
NfcAdapter
.
ACTION_NDEF_DISCOVERED
.
equals
(
getIntent
().
getAction
()))
{
...
@@ -476,10 +520,24 @@ public class GameActivity extends BaseActivity
...
@@ -476,10 +520,24 @@ public class GameActivity extends BaseActivity
public
void
onLocationChanged
(
Location
location
)
{
public
void
onLocationChanged
(
Location
location
)
{
mCurrentLocation
=
location
;
mCurrentLocation
=
location
;
mLastUpdateTime
=
DateFormat
.
getTimeInstance
().
format
(
new
Date
());
mLastUpdateTime
=
DateFormat
.
getTimeInstance
().
format
(
new
Date
());
if
(
mLatestAnswer
!=
null
&&
mLatestAnswer
.
getId
()
>
0
&&
mPoints
!=
null
&&
mPoints
.
get
(
mCurrentPoint
)
!=
null
)
if
(
mPoints
.
size
()
>=
mCurrentPoint
)
mPresenter
.
postCheckIn
(
new
CheckIn
(
mGame
.
getUserGameId
(),
location
.
getLatitude
(),
location
.
getLongitude
(),
mPoints
.
get
(
mCurrentPoint
).
getId
(),
mLatestAnswer
.
getId
()));
Logger
.
wtf
(
"might happen with debugging, if not then bug"
);
else
mPresenter
.
postCheckIn
(
new
CheckIn
(
mGame
.
getUserGameId
(),
location
.
getLatitude
(),
location
.
getLongitude
(),
mPoints
.
get
(
mCurrentPoint
).
getId
()));
if
(
mLatestAnswer
!=
null
&&
mLatestAnswer
.
getId
()
>
0
&&
mPoints
!=
null
&&
mPoints
.
get
(
mCurrentPoint
)
!=
null
)
{
if
(
isNeedToCheckIn
&&
location
.
getAccuracy
()
<
8
)
{
mPresenter
.
postCheckIn
(
new
CheckIn
(
mGame
.
getUserGameId
(),
location
.
getLatitude
(),
location
.
getLongitude
(),
mPoints
.
get
(
mCurrentPoint
).
getId
(),
mLatestAnswer
.
getId
()));
isNeedToCheckIn
=
false
;
}
else
{
isNeedToCheckIn
=
true
;
}
}
else
{
if
(
isNeedToCheckIn
&&
location
.
getAccuracy
()
<
8
)
{
mPresenter
.
postCheckIn
(
new
CheckIn
(
mGame
.
getUserGameId
(),
location
.
getLatitude
(),
location
.
getLongitude
(),
mPoints
.
get
(
mCurrentPoint
).
getId
()));
isNeedToCheckIn
=
false
;
}
else
{
isNeedToCheckIn
=
true
;
}
}
updateLocationUI
();
updateLocationUI
();
}
}
...
@@ -540,7 +598,7 @@ public class GameActivity extends BaseActivity
...
@@ -540,7 +598,7 @@ public class GameActivity extends BaseActivity
Collections
.
sort
(
mPoints
,
new
Comparator
<
Point
>()
{
Collections
.
sort
(
mPoints
,
new
Comparator
<
Point
>()
{
@Override
@Override
public
int
compare
(
Point
p1
,
Point
p2
)
{
public
int
compare
(
Point
p1
,
Point
p2
)
{
return
p1
.
getOrder
()
-
p2
.
getOrder
();
return
p1
.
getOrder
()
-
p2
.
getOrder
();
}
}
});
});
...
@@ -551,12 +609,25 @@ public class GameActivity extends BaseActivity
...
@@ -551,12 +609,25 @@ public class GameActivity extends BaseActivity
setUpTabLayout
();
setUpTabLayout
();
hideLoading
();
hideLoading
();
mPresenter
.
getBounds
(
Integer
.
toString
(
mGame
.
getId
()));
}
@Override
public
void
loadBounds
(
BoundResponse
boundResponse
)
{
if
(
_rxBus
.
hasObservers
())
_rxBus
.
send
(
boundResponse
);
}
}
@Override
@Override
public
void
checkInResponse
(
CheckInResponse
checkInResponse
)
{
public
void
checkInResponse
(
CheckInResponse
checkInResponse
)
{
if
(
_rxBus
.
hasObservers
())
if
(
checkInResponse
.
getIsOver
()
==
1
){
_rxBus
.
send
(
checkInResponse
);
gameEnded
();
}
else
{
if
(
_rxBus
.
hasObservers
())
_rxBus
.
send
(
checkInResponse
);
}
}
}
@Override
@Override
...
@@ -565,8 +636,22 @@ public class GameActivity extends BaseActivity
...
@@ -565,8 +636,22 @@ public class GameActivity extends BaseActivity
}
}
@Override
@Override
public
void
answerPosted
(
String
id
)
{
public
void
answerPosted
(
AnswerResponse
id
)
{
mLatestAnswer
.
setId
(
Integer
.
parseInt
(
id
));
mLatestAnswer
.
setId
(
Integer
.
parseInt
(
id
.
getId
()));
if
(
_rxBus
.
hasObservers
())
_rxBus
.
send
(
id
);
}
@Override
public
void
gameEnded
()
{
// delete game from preferences
mPresenter
.
deleteGameFromMemory
();
mUserGame
.
setEnd
(
new
Date
());
Intent
intent
=
new
Intent
(
GameActivity
.
this
,
HistoryActivity
.
class
);
intent
.
putExtra
(
USER_GAME_KEY
,
mUserGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
finish
();
}
}
private
class
ScreenSlidePagerAdapter
extends
FragmentStatePagerAdapter
{
private
class
ScreenSlidePagerAdapter
extends
FragmentStatePagerAdapter
{
...
@@ -584,10 +669,10 @@ public class GameActivity extends BaseActivity
...
@@ -584,10 +669,10 @@ public class GameActivity extends BaseActivity
public
Fragment
getItem
(
int
position
)
{
public
Fragment
getItem
(
int
position
)
{
Fragment
fragment
;
Fragment
fragment
;
if
(
position
==
0
)
{
if
(
position
==
0
)
{
fragment
=
GameFragment
.
newInstance
(
mGame
,
mPoints
);
fragment
=
GameFragment
.
newInstance
(
mGame
,
mPoints
,
mCurrentPoint
);
}
else
if
(
position
==
1
)
{
}
else
if
(
position
==
1
)
{
fragment
=
MapFragment
.
newInstance
(
mGame
,
mPoints
);
fragment
=
MapFragment
.
newInstance
(
mGame
,
mPoints
);
}
else
{
}
else
{
fragment
=
NotificationFragment
.
newInstance
(
mGame
,
mPoints
,
mUser
);
fragment
=
NotificationFragment
.
newInstance
(
mGame
,
mPoints
,
mUser
);
}
}
...
...
app/src/main/java/ee/ttu/thesis/ui/game/GamePresenter.java
View file @
df953f27
...
@@ -6,6 +6,9 @@ import javax.inject.Inject;
...
@@ -6,6 +6,9 @@ import javax.inject.Inject;
import
ee.ttu.thesis.data.DataManager
;
import
ee.ttu.thesis.data.DataManager
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.AnswerResponse
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.BoundResponse
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.GamesRequest
;
...
@@ -105,6 +108,7 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
...
@@ -105,6 +108,7 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
}));
}));
}
}
@Override
@Override
public
void
postAnswer
(
Answer
answer
)
{
public
void
postAnswer
(
Answer
answer
)
{
getmThesisView
().
showLoading
();
getmThesisView
().
showLoading
();
...
@@ -120,8 +124,65 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
...
@@ -120,8 +124,65 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
if
(!
isViewAttached
())
{
if
(!
isViewAttached
())
{
return
;
return
;
}
}
AnswerResponse
answerResponse
=
new
AnswerResponse
();
answerResponse
.
setId
(
s
);
getmThesisView
().
answerPosted
(
answerResponse
);
}
},
new
Consumer
<
Throwable
>()
{
@Override
public
void
accept
(
@NonNull
Throwable
throwable
)
throws
Exception
{
getmThesisView
().
onError
(
throwable
.
getMessage
());
getmThesisView
().
hideLoading
();
}
}));
}
@Override
public
void
getBounds
(
String
gameId
)
{
getCompositeDisposable
().
add
(
getDataManager
()
.
getBounds
(
gameId
)
.
subscribeOn
(
getSchedulerProvider
().
io
())
.
observeOn
(
getSchedulerProvider
().
ui
())
.
subscribe
(
new
Consumer
<
List
<
Bound
>>()
{
@Override
public
void
accept
(
@NonNull
List
<
Bound
>
bounds
)
throws
Exception
{
BoundResponse
boundResponse
=
new
BoundResponse
();
boundResponse
.
setmBounds
(
bounds
);
getmThesisView
().
loadBounds
(
boundResponse
);
}
},
new
Consumer
<
Throwable
>()
{
@Override
public
void
accept
(
@NonNull
Throwable
throwable
)
throws
Exception
{
getmThesisView
().
hideLoading
();
getmThesisView
().
onError
(
throwable
.
getMessage
());
}
}));
}
@Override
public
void
deleteGameFromMemory
()
{
getDataManager
().
setCurrentPoint
(-
1
);
getDataManager
().
setCurrentGameCode
(
null
);
}
@Override
public
void
saveCurrentPoint
(
int
currentPoint
)
{
getDataManager
().
setCurrentPoint
(
currentPoint
);
}
@Override
public
void
gameEnded
(
String
userGameId
)
{
getmThesisView
().
showLoading
();
getmThesisView
().
answerPosted
(
s
);
getCompositeDisposable
().
add
(
getDataManager
()
.
endGame
(
userGameId
)
.
subscribeOn
(
getSchedulerProvider
().
io
())
.
observeOn
(
getSchedulerProvider
().
ui
())
.
subscribe
(
new
Consumer
<
String
>()
{
@Override
public
void
accept
(
@NonNull
String
s
)
throws
Exception
{
getmThesisView
().
gameEnded
();
}
}
},
new
Consumer
<
Throwable
>()
{
},
new
Consumer
<
Throwable
>()
{
@Override
@Override
...
@@ -130,4 +191,9 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
...
@@ -130,4 +191,9 @@ public class GamePresenter<V extends GameView> extends BasePresenter<V> implemen
}
}
}));
}));
}
}
@Override
public
int
getCurrentPoint
()
{
return
getDataManager
().
getCurrentPoint
();
}
}
}
app/src/main/java/ee/ttu/thesis/ui/game/GameTreasureHuntPresenter.java
View file @
df953f27
...
@@ -20,4 +20,14 @@ public interface GameTreasureHuntPresenter<V extends GameView> extends TreauseHu
...
@@ -20,4 +20,14 @@ public interface GameTreasureHuntPresenter<V extends GameView> extends TreauseHu
void
postAnswer
(
Answer
answer
);
void
postAnswer
(
Answer
answer
);
void
getBounds
(
String
gameId
);
void
deleteGameFromMemory
();
void
saveCurrentPoint
(
int
currentPoint
);
void
gameEnded
(
String
userGameId
);
int
getCurrentPoint
();
}
}
app/src/main/java/ee/ttu/thesis/ui/game/GameView.java
View file @
df953f27
...
@@ -2,6 +2,9 @@ package ee.ttu.thesis.ui.game;
...
@@ -2,6 +2,9 @@ package ee.ttu.thesis.ui.game;
import
java.util.List
;
import
java.util.List
;
import
ee.ttu.thesis.data.model.AnswerResponse
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.BoundResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.ui.base.TreasureHuntView
;
import
ee.ttu.thesis.ui.base.TreasureHuntView
;
...
@@ -14,9 +17,14 @@ public interface GameView extends TreasureHuntView {
...
@@ -14,9 +17,14 @@ public interface GameView extends TreasureHuntView {
void
loadPoints
(
List
<
Point
>
response
);
void
loadPoints
(
List
<
Point
>
response
);
void
loadBounds
(
BoundResponse
boundResponse
);
void
checkInResponse
(
CheckInResponse
checkInResponse
);
void
checkInResponse
(
CheckInResponse
checkInResponse
);
void
messagePosted
();
void
messagePosted
();
void
answerPosted
(
String
id
);
void
answerPosted
(
AnswerResponse
id
);
void
gameEnded
();
}
}
app/src/main/java/ee/ttu/thesis/ui/game/InfoDialogFragment.java
0 → 100644
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
game
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.DialogFragment
;
import
android.view.KeyEvent
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.ViewGroup
;
import
android.view.WindowManager
;
import
android.view.inputmethod.EditorInfo
;
import
android.widget.Button
;
import
android.widget.TextView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
import
ee.ttu.thesis.R
;
/**
* Created by hajola on 4.06.17.
*/
public
class
InfoDialogFragment
extends
DialogFragment
{
@BindView
(
R
.
id
.
dialog_info_ok
)
Button
mOk
;
@BindView
(
R
.
id
.
dialog_info_textview
)
TextView
mInfo
;
public
static
final
String
INFO_KEY
=
"info"
;
public
InfoDialogFragment
()
{
}
public
static
InfoDialogFragment
newInstance
(
String
info
)
{
Bundle
args
=
new
Bundle
();
InfoDialogFragment
fragment
=
new
InfoDialogFragment
();
args
.
putString
(
INFO_KEY
,
info
);
fragment
.
setArguments
(
args
);
return
fragment
;
}
@OnClick
(
R
.
id
.
dialog_info_ok
)
public
void
onOkClicked
(
View
v
)
{
dismiss
();
}
@Nullable
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
View
v
=
inflater
.
inflate
(
R
.
layout
.
dialog_info
,
container
);
ButterKnife
.
bind
(
this
,
v
);
return
v
;
}
@Override
public
void
onViewCreated
(
View
view
,
@Nullable
Bundle
savedInstanceState
)
{
super
.
onViewCreated
(
view
,
savedInstanceState
);
mInfo
.
setText
(
getArguments
().
getString
(
INFO_KEY
));
}
}
app/src/main/java/ee/ttu/thesis/ui/game/map/MapFragment.java
View file @
df953f27
...
@@ -2,6 +2,7 @@ package ee.ttu.thesis.ui.game.map;
...
@@ -2,6 +2,7 @@ package ee.ttu.thesis.ui.game.map;
import
android.graphics.Bitmap
;
import
android.graphics.Bitmap
;
import
android.graphics.Canvas
;
import
android.graphics.Canvas
;
import
android.graphics.Color
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuff
;
import
android.graphics.drawable.Drawable
;
import
android.graphics.drawable.Drawable
;
import
android.location.Location
;
import
android.location.Location
;
...
@@ -22,14 +23,19 @@ import com.google.android.gms.maps.model.CameraPosition;
...
@@ -22,14 +23,19 @@ import com.google.android.gms.maps.model.CameraPosition;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.android.gms.maps.model.MapStyleOptions
;
import
com.google.android.gms.maps.model.MapStyleOptions
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
com.google.android.gms.maps.model.MarkerOptions
;
import
com.google.android.gms.maps.model.Polygon
;
import
com.google.android.gms.maps.model.PolygonOptions
;
import
com.orhanobut.logger.Logger
;
import
com.orhanobut.logger.Logger
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Arrays
;
import
java.util.List
;
import
java.util.List
;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Bound
;
import
ee.ttu.thesis.data.model.BoundResponse
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.PointType
;
import
ee.ttu.thesis.data.model.PointType
;
...
@@ -48,7 +54,8 @@ import static ee.ttu.thesis.ui.game.GameActivity.POINT_KEY;
...
@@ -48,7 +54,8 @@ import static ee.ttu.thesis.ui.game.GameActivity.POINT_KEY;
* Created by hajola on 18.04.17.
* Created by hajola on 18.04.17.
*/
*/
public
class
MapFragment
extends
Fragment
implements
OnMapReadyCallback
{
public
class
MapFragment
extends
Fragment
implements
OnMapReadyCallback
,
GoogleMap
.
OnPolygonClickListener
{
private
CameraPosition
mCameraPosition
;
private
CameraPosition
mCameraPosition
;
...
@@ -105,12 +112,38 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
...
@@ -105,12 +112,38 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
mCurrentPoint
++;
mCurrentPoint
++;
newPoint
();
newPoint
();
}
}
}
else
if
(
o
instanceof
BoundResponse
){
boundsToMap
(((
BoundResponse
)
o
).
getmBounds
());
}
}
}
}
}));
}));
}
}
private
void
boundsToMap
(
List
<
Bound
>
bounds
){
for
(
Bound
b:
bounds
){
String
mpoly
=
b
.
getMpoly
();
List
<
LatLng
>
latLngs
=
new
ArrayList
<>();
String
lat
,
lng
;
mpoly
=
mpoly
.
substring
(
mpoly
.
lastIndexOf
(
'('
)+
1
,
mpoly
.
indexOf
(
')'
)
);
String
[]
together
=
mpoly
.
split
(
", "
);
for
(
String
s:
together
){
String
[]
ltln
=
s
.
split
(
" "
);
LatLng
latLng
=
new
LatLng
(
Double
.
parseDouble
(
ltln
[
1
]),
Double
.
parseDouble
(
ltln
[
0
]));
latLngs
.
add
(
latLng
);
}
LatLng
[]
arr
=
new
LatLng
[
latLngs
.
size
()];
arr
=
latLngs
.
toArray
(
arr
);
Polygon
polygon
=
mMap
.
addPolygon
(
new
PolygonOptions
()
.
add
(
arr
)
.
strokeColor
(
getResources
().
getColor
(
R
.
color
.
colorAccent
))
.
fillColor
(
getResources
().
getColor
(
R
.
color
.
mapBoundFillColor
)));
}
}
@Nullable
@Nullable
@Override
@Override
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
public
View
onCreateView
(
LayoutInflater
inflater
,
@Nullable
ViewGroup
container
,
@Nullable
Bundle
savedInstanceState
)
{
...
@@ -218,4 +251,9 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
...
@@ -218,4 +251,9 @@ public class MapFragment extends Fragment implements OnMapReadyCallback {
if
(!
isCameraAboveUser
&&
mMap
!=
null
)
if
(!
isCameraAboveUser
&&
mMap
!=
null
)
getDeviceLocation
();
getDeviceLocation
();
}
}
@Override
public
void
onPolygonClick
(
Polygon
polygon
)
{
}
}
}
app/src/main/java/ee/ttu/thesis/ui/game/point/DialogFragmentSolveQuestion.java
View file @
df953f27
...
@@ -80,7 +80,8 @@ public class DialogFragmentSolveQuestion extends DialogFragment {
...
@@ -80,7 +80,8 @@ public class DialogFragmentSolveQuestion extends DialogFragment {
Answer
answer
=
new
Answer
(
mPoint
.
getId
(),
mPoint
.
getProblemType
(),
correctSolution
,
correctId
==
mRadioGroup
.
getCheckedRadioButtonId
());
Answer
answer
=
new
Answer
(
mPoint
.
getId
(),
mPoint
.
getProblemType
(),
correctSolution
,
correctId
==
mRadioGroup
.
getCheckedRadioButtonId
());
if
(
_rxBus
.
hasObservers
()
)
if
(
_rxBus
.
hasObservers
()
)
_rxBus
.
send
(
answer
);
_rxBus
.
send
(
answer
);
if
(!
answer
.
is_correct
())
((
SolveFragment
)
getParentFragment
()).
onWrongAnswer
(
answer
);
dismiss
();
dismiss
();
}
}
...
...
app/src/main/java/ee/ttu/thesis/ui/game/point/GameFragment.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
game
.
point
;
package
ee
.
ttu
.
thesis
.
ui
.
game
.
point
;
import
android.content.Context
;
import
android.location.Location
;
import
android.location.Location
;
import
android.media.MediaPlayer
;
import
android.media.MediaPlayer
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Vibrator
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentTransaction
;
import
android.support.v4.app.FragmentTransaction
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
import
android.view.View
;
import
android.view.View
;
...
@@ -31,6 +30,7 @@ import ee.ttu.thesis.data.model.Point;
...
@@ -31,6 +30,7 @@ import ee.ttu.thesis.data.model.Point;
import
ee.ttu.thesis.data.model.PointType
;
import
ee.ttu.thesis.data.model.PointType
;
import
ee.ttu.thesis.data.model.ProblemType
;
import
ee.ttu.thesis.data.model.ProblemType
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.game.InfoDialogFragment
;
import
ee.ttu.thesis.utils.RxBus
;
import
ee.ttu.thesis.utils.RxBus
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.annotations.NonNull
;
import
io.reactivex.annotations.NonNull
;
...
@@ -56,8 +56,8 @@ public class GameFragment extends Fragment {
...
@@ -56,8 +56,8 @@ public class GameFragment extends Fragment {
TextView
mOrder
;
TextView
mOrder
;
@BindView
(
R
.
id
.
fragment_solve_point_description
)
@BindView
(
R
.
id
.
fragment_solve_point_description
)
TextView
mDescription
;
TextView
mDescription
;
TextView
mDistance
;
LinearLayout
mDistance
;
CompassView
mCompassView
;
LinearLayout
mCompassView
;
@BindView
(
R
.
id
.
fragment_compass_hint_root
)
@BindView
(
R
.
id
.
fragment_compass_hint_root
)
LinearLayout
mHintRoot
;
LinearLayout
mHintRoot
;
@BindView
(
R
.
id
.
fragment_compass_compass_root
)
@BindView
(
R
.
id
.
fragment_compass_compass_root
)
...
@@ -78,10 +78,11 @@ public class GameFragment extends Fragment {
...
@@ -78,10 +78,11 @@ public class GameFragment extends Fragment {
List
<
Point
>
mPoints
;
List
<
Point
>
mPoints
;
public
static
GameFragment
newInstance
(
Game
game
,
ArrayList
<
Point
>
points
)
{
public
static
GameFragment
newInstance
(
Game
game
,
ArrayList
<
Point
>
points
,
int
mCurrentPoint
)
{
Bundle
args
=
new
Bundle
();
Bundle
args
=
new
Bundle
();
args
.
putParcelable
(
GAME_KEY
,
game
);
args
.
putParcelable
(
GAME_KEY
,
game
);
args
.
putParcelableArrayList
(
POINT_KEY
,
points
);
args
.
putParcelableArrayList
(
POINT_KEY
,
points
);
args
.
putInt
(
"currentpoint"
,
mCurrentPoint
);
GameFragment
fragment
=
new
GameFragment
();
GameFragment
fragment
=
new
GameFragment
();
fragment
.
setArguments
(
args
);
fragment
.
setArguments
(
args
);
return
fragment
;
return
fragment
;
...
@@ -93,6 +94,7 @@ public class GameFragment extends Fragment {
...
@@ -93,6 +94,7 @@ public class GameFragment extends Fragment {
View
v
=
inflater
.
inflate
(
R
.
layout
.
fragment_game
,
container
,
false
);
View
v
=
inflater
.
inflate
(
R
.
layout
.
fragment_game
,
container
,
false
);
ButterKnife
.
bind
(
this
,
v
);
ButterKnife
.
bind
(
this
,
v
);
mGame
=
getArguments
().
getParcelable
(
GAME_KEY
);
mGame
=
getArguments
().
getParcelable
(
GAME_KEY
);
mCurrentPoint
=
getArguments
().
getInt
(
"currentpoint"
);
mPoints
=
getArguments
().
getParcelableArrayList
(
POINT_KEY
);
mPoints
=
getArguments
().
getParcelableArrayList
(
POINT_KEY
);
return
v
;
return
v
;
}
}
...
@@ -195,10 +197,13 @@ public class GameFragment extends Fragment {
...
@@ -195,10 +197,13 @@ public class GameFragment extends Fragment {
if
(
degrees
<
0
)
{
if
(
degrees
<
0
)
{
degrees
+=
360
;
degrees
+=
360
;
}
}
if
(
mDistance
!=
null
)
if
(
mDistance
!=
null
)
{
mDistance
.
setText
(
""
+
distanceInMeters
+
" meters away from the point "
);
((
TextView
)
mDistance
.
findViewById
(
R
.
id
.
fragment_compass_distance
)).
setText
(
""
+
distanceInMeters
+
" meters away from the point "
);
((
TextView
)
mDistance
.
findViewById
(
R
.
id
.
fragment_compass_distance_accuracy
)).
setText
(
"accuracy: "
+
mCurrentLocation
.
getAccuracy
()
+
" meters"
);
}
if
(
mCompassView
!=
null
)
if
(
mCompassView
!=
null
)
mCompassView
.
updateUI
(
degrees
,
distanceInMeters
);
((
CompassView
)
mCompassView
.
findViewById
(
R
.
id
.
compassView
))
.
updateUI
(
degrees
,
distanceInMeters
);
}
}
}
}
...
@@ -211,7 +216,7 @@ public class GameFragment extends Fragment {
...
@@ -211,7 +216,7 @@ public class GameFragment extends Fragment {
mHintRoot
.
removeAllViews
();
mHintRoot
.
removeAllViews
();
mHintView
=
null
;
mHintView
=
null
;
}
else
{
}
else
{
if
(
mHintView
==
null
)
{
if
(
mHintView
==
null
)
{
mHintView
=
(
TextView
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_hint
,
null
);
mHintView
=
(
TextView
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_hint
,
null
);
mHintRoot
.
addView
(
mHintView
);
mHintRoot
.
addView
(
mHintView
);
}
}
...
@@ -222,8 +227,8 @@ public class GameFragment extends Fragment {
...
@@ -222,8 +227,8 @@ public class GameFragment extends Fragment {
mCompassRoot
.
removeAllViews
();
mCompassRoot
.
removeAllViews
();
mCompassView
=
null
;
mCompassView
=
null
;
}
else
{
}
else
{
if
(
mCompassView
==
null
)
{
if
(
mCompassView
==
null
)
{
mCompassView
=
(
CompassView
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_compass
,
null
);
mCompassView
=
(
LinearLayout
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_compass
,
null
);
mCompassRoot
.
addView
(
mCompassView
);
mCompassRoot
.
addView
(
mCompassView
);
}
}
}
}
...
@@ -232,8 +237,8 @@ public class GameFragment extends Fragment {
...
@@ -232,8 +237,8 @@ public class GameFragment extends Fragment {
mDistanceRoot
.
removeAllViews
();
mDistanceRoot
.
removeAllViews
();
mDistance
=
null
;
mDistance
=
null
;
}
else
{
}
else
{
if
(
mDistance
==
null
)
{
if
(
mDistance
==
null
)
{
mDistance
=
(
TextView
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_distance
,
null
);
mDistance
=
(
LinearLayout
)
getActivity
().
getLayoutInflater
().
inflate
(
R
.
layout
.
layout_distance
,
null
);
mDistanceRoot
.
addView
(
mDistance
);
mDistanceRoot
.
addView
(
mDistance
);
}
}
}
}
...
@@ -254,11 +259,15 @@ public class GameFragment extends Fragment {
...
@@ -254,11 +259,15 @@ public class GameFragment extends Fragment {
e
.
printStackTrace
();
e
.
printStackTrace
();
}
}
if
(
mPoints
.
size
()
-
1
<=
mCurrentPoint
)
{
if
(
mPoints
.
size
()
-
1
<=
mCurrentPoint
)
{
// TODO WON GAME
Toast
.
makeText
(
getActivity
(),
"Game won!"
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
getActivity
(),
"Game won!"
,
Toast
.
LENGTH_SHORT
).
show
();
((
GameActivity
)
getActivity
()).
onGameFinished
();
}
else
{
}
else
{
mCurrentPoint
++;
mCurrentPoint
++;
displayNewPoint
();
displayNewPoint
();
FragmentManager
fm
=
getFragmentManager
();
InfoDialogFragment
infoDialogFragment
=
InfoDialogFragment
.
newInstance
(
"Point completed!"
);
infoDialogFragment
.
show
(
fm
,
"info_fragment"
);
}
}
}
}
...
...
app/src/main/java/ee/ttu/thesis/ui/game/point/GameLocationFragment.java
View file @
df953f27
...
@@ -2,11 +2,13 @@ package ee.ttu.thesis.ui.game.point;
...
@@ -2,11 +2,13 @@ package ee.ttu.thesis.ui.game.point;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuff
;
import
android.location.Location
;
import
android.location.Location
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentManager
;
import
android.view.View
;
import
android.view.View
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.orhanobut.logger.Logger
;
import
com.orhanobut.logger.Logger
;
import
butterknife.OnClick
;
import
butterknife.OnClick
;
...
@@ -56,7 +58,21 @@ public class GameLocationFragment extends SolveFragment {
...
@@ -56,7 +58,21 @@ public class GameLocationFragment extends SolveFragment {
@Override
@Override
public
void
accept
(
@NonNull
Object
o
)
throws
Exception
{
public
void
accept
(
@NonNull
Object
o
)
throws
Exception
{
if
(
o
instanceof
Location
)
{
if
(
o
instanceof
Location
)
{
Location
loc
=
(
Location
)
o
;
Location
pointLoc
=
new
Location
(
""
);
pointLoc
.
setLatitude
(
mPoint
.
getLat
());
pointLoc
.
setLongitude
(
mPoint
.
getLon
());
double
distance
=
loc
.
distanceTo
(
pointLoc
);
if
(
distance
<
loc
.
getAccuracy
()+
5
&&
loc
.
getAccuracy
()
<
10
){
if
(
mPoint
.
getProblemType
().
getTitle
().
equals
(
ProblemType
.
QUIZ
))
{
onAskAQuestion
();
}
else
{
Answer
answer
=
new
Answer
(
mPoint
.
getId
(),
mPoint
.
getProblemType
(),
"automaatne"
,
true
);
if
(
_rxBus
.
hasObservers
())
_rxBus
.
send
(
answer
);
}
}
}
}
}
}
}));
}));
...
@@ -85,8 +101,10 @@ public class GameLocationFragment extends SolveFragment {
...
@@ -85,8 +101,10 @@ public class GameLocationFragment extends SolveFragment {
mIcon
.
setImageDrawable
(
getResources
().
getDrawable
(
R
.
drawable
.
ic_create_black_24dp
));
mIcon
.
setImageDrawable
(
getResources
().
getDrawable
(
R
.
drawable
.
ic_create_black_24dp
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mInstructions
.
setText
(
mPoint
.
getProblemDescription
());
mInstructions
.
setText
(
mPoint
.
getProblemDescription
());
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
DST_OUT
);
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
SRC_IN
);
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
4
,
getActivity
()));
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
4
,
getActivity
()));
}
mIcon
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
mIcon
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
@Override
...
...
app/src/main/java/ee/ttu/thesis/ui/game/point/GamePhotoFragment.java
View file @
df953f27
...
@@ -5,12 +5,26 @@ import android.graphics.Bitmap;
...
@@ -5,12 +5,26 @@ import android.graphics.Bitmap;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.provider.MediaStore
;
import
android.provider.MediaStore
;
import
android.util.Base64
;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.orhanobut.logger.Logger
;
import
java.io.ByteArrayOutputStream
;
import
butterknife.OnClick
;
import
butterknife.OnClick
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.AnswerResponse
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.utils.RxBus
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.annotations.NonNull
;
import
io.reactivex.disposables.CompositeDisposable
;
import
io.reactivex.functions.Consumer
;
import
static
android
.
app
.
Activity
.
RESULT_OK
;
import
static
android
.
app
.
Activity
.
RESULT_OK
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
POINT_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
POINT_KEY
;
...
@@ -23,6 +37,9 @@ public class GamePhotoFragment extends SolveFragment {
...
@@ -23,6 +37,9 @@ public class GamePhotoFragment extends SolveFragment {
static
final
int
REQUEST_IMAGE_CAPTURE
=
1
;
static
final
int
REQUEST_IMAGE_CAPTURE
=
1
;
Answer
answer
;
CompositeDisposable
mDisposables
;
public
static
GamePhotoFragment
newInstance
(
Point
point
)
{
public
static
GamePhotoFragment
newInstance
(
Point
point
)
{
Bundle
args
=
new
Bundle
();
Bundle
args
=
new
Bundle
();
...
@@ -41,18 +58,23 @@ public class GamePhotoFragment extends SolveFragment {
...
@@ -41,18 +58,23 @@ public class GamePhotoFragment extends SolveFragment {
@Override
@Override
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
public
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
Toast
.
makeText
(
getActivity
(),
"
Mängujuht hindaks pilti (oota 4s)
"
,
Toast
.
LENGTH_LONG
).
show
();
Toast
.
makeText
(
getActivity
(),
"
Game coordinator will verify the picture
"
,
Toast
.
LENGTH_LONG
).
show
();
onPhotoTaken
();
onPhotoTaken
();
if
(
requestCode
==
REQUEST_IMAGE_CAPTURE
&&
resultCode
==
RESULT_OK
)
{
if
(
requestCode
==
REQUEST_IMAGE_CAPTURE
&&
resultCode
==
RESULT_OK
)
{
Bundle
extras
=
data
.
getExtras
();
Bundle
extras
=
data
.
getExtras
();
Bitmap
imageBitmap
=
(
Bitmap
)
extras
.
get
(
"data"
);
Bitmap
imageBitmap
=
(
Bitmap
)
extras
.
get
(
"data"
);
new
Handler
().
postDelayed
(
new
Runnable
()
{
ByteArrayOutputStream
baos
=
new
ByteArrayOutputStream
();
@Override
imageBitmap
.
compress
(
Bitmap
.
CompressFormat
.
JPEG
,
100
,
baos
);
public
void
run
()
{
byte
[]
imageBytes
=
baos
.
toByteArray
();
// mOnPointCompletedListener.onPointCompleted();
String
encodedImage
=
Base64
.
encodeToString
(
imageBytes
,
Base64
.
DEFAULT
);
}
answer
=
new
Answer
();
answer
.
setPoint_id
(
mPoint
.
getId
());
},
4000
);
answer
.
setProblem_type
(
mPoint
.
getProblemType
());
answer
.
setAnswer
(
"photo"
);
answer
.
setIs_correct
(
false
);
answer
.
setPhotoInBase64
(
encodedImage
);
Logger
.
d
(
answer
.
getPhotoInBase64
());
((
GameActivity
)
getActivity
()).
postAnswer
(
answer
);
}
}
}
}
...
@@ -62,15 +84,6 @@ public class GamePhotoFragment extends SolveFragment {
...
@@ -62,15 +84,6 @@ public class GamePhotoFragment extends SolveFragment {
mIcon
.
setVisibility
(
View
.
INVISIBLE
);
mIcon
.
setVisibility
(
View
.
INVISIBLE
);
mProgressBar
.
setVisibility
(
View
.
VISIBLE
);
mProgressBar
.
setVisibility
(
View
.
VISIBLE
);
new
Handler
().
postDelayed
(
new
Runnable
()
{
@Override
public
void
run
()
{
mInstructions
.
setText
(
"Please wait"
);
mIcon
.
setVisibility
(
View
.
VISIBLE
);
mProgressBar
.
setVisibility
(
View
.
INVISIBLE
);
}
},
6000
);
}
}
private
void
dispatchTakePictureIntent
()
{
private
void
dispatchTakePictureIntent
()
{
...
@@ -80,4 +93,38 @@ public class GamePhotoFragment extends SolveFragment {
...
@@ -80,4 +93,38 @@ public class GamePhotoFragment extends SolveFragment {
}
}
}
}
@Override
public
void
onStart
()
{
super
.
onStart
();
_rxBus
=
((
GameActivity
)
getActivity
()).
getRxBusSingleton
();
mDisposables
=
new
CompositeDisposable
();
mDisposables
.
add
(
_rxBus
.
asFlowable
()
.
subscribeOn
(
AndroidSchedulers
.
mainThread
())
.
subscribe
(
new
Consumer
<
Object
>()
{
@Override
public
void
accept
(
@NonNull
Object
o
)
throws
Exception
{
if
(
o
instanceof
AnswerResponse
){
answer
.
setId
(
Integer
.
parseInt
(((
AnswerResponse
)
o
).
getId
()));
}
else
if
(
o
instanceof
CheckInResponse
)
{
Logger
.
d
(
o
.
toString
());
Answer
a
=
((
CheckInResponse
)
o
).
getAnswer
();
if
(
a
!=
null
&&
a
.
getId
()
==
answer
.
getId
()){
if
(!
a
.
is_correct
()){
mInstructions
.
setText
(
"Please try again"
);
mIcon
.
setVisibility
(
View
.
VISIBLE
);
mProgressBar
.
setVisibility
(
View
.
INVISIBLE
);
onWrongAnswer
(
a
);
}
else
{
mInstructions
.
setText
(
"Well done!!"
);
mIcon
.
setVisibility
(
View
.
VISIBLE
);
mProgressBar
.
setVisibility
(
View
.
INVISIBLE
);
((
GameFragment
)
getParentFragment
()).
onPointCompleted
();
}
}
}
}
}));
}
}
}
app/src/main/java/ee/ttu/thesis/ui/game/point/QRScannerDialogFragment.java
View file @
df953f27
...
@@ -113,6 +113,8 @@ public class QRScannerDialogFragment extends DialogFragment {
...
@@ -113,6 +113,8 @@ public class QRScannerDialogFragment extends DialogFragment {
Answer
answer
=
new
Answer
(
mPoint
.
getId
(),
mPoint
.
getProblemType
(),
data
,
Answer
.
isAnswerCorrect
(
mPoint
,
data
));
Answer
answer
=
new
Answer
(
mPoint
.
getId
(),
mPoint
.
getProblemType
(),
data
,
Answer
.
isAnswerCorrect
(
mPoint
,
data
));
if
(
_rxBus
.
hasObservers
())
if
(
_rxBus
.
hasObservers
())
_rxBus
.
send
(
answer
);
_rxBus
.
send
(
answer
);
if
(!
answer
.
is_correct
())
((
SolveFragment
)
getParentFragment
()).
onWrongAnswer
(
answer
);
}
}
dismiss
();
dismiss
();
...
...
app/src/main/java/ee/ttu/thesis/ui/game/point/SolveFragment.java
View file @
df953f27
...
@@ -2,10 +2,10 @@ package ee.ttu.thesis.ui.game.point;
...
@@ -2,10 +2,10 @@ package ee.ttu.thesis.ui.game.point;
import
android.content.Context
;
import
android.content.Context
;
import
android.graphics.PorterDuff
;
import
android.graphics.PorterDuff
;
import
android.os.Build
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Handler
;
import
android.os.Vibrator
;
import
android.os.Vibrator
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.v4.app.Fragment
;
import
android.support.v4.app.Fragment
;
import
android.view.LayoutInflater
;
import
android.view.LayoutInflater
;
...
@@ -19,16 +19,13 @@ import butterknife.BindView;
...
@@ -19,16 +19,13 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.Answer
;
import
ee.ttu.thesis.data.model.CheckInResponse
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.Point
;
import
ee.ttu.thesis.data.model.ProblemType
;
import
ee.ttu.thesis.data.model.ProblemType
;
import
ee.ttu.thesis.data.model.Solution
;
import
ee.ttu.thesis.data.model.Solution
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.utils.DeviceDimensionsHelper
;
import
ee.ttu.thesis.utils.DeviceDimensionsHelper
;
import
ee.ttu.thesis.utils.RxBus
;
import
ee.ttu.thesis.utils.RxBus
;
import
io.reactivex.android.schedulers.AndroidSchedulers
;
import
io.reactivex.disposables.CompositeDisposable
;
import
io.reactivex.disposables.CompositeDisposable
;
import
io.reactivex.functions.Consumer
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
POINT_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
POINT_KEY
;
...
@@ -68,7 +65,9 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
...
@@ -68,7 +65,9 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
case
(
ProblemType
.
QR
):
case
(
ProblemType
.
QR
):
mIcon
.
setImageDrawable
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
ic_qrcode_scan
));
mIcon
.
setImageDrawable
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
ic_qrcode_scan
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
getActivity
()));
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
getActivity
()));
}
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
SRC_IN
);
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
SRC_IN
);
mInstructions
.
setText
(
getResources
().
getString
(
R
.
string
.
solve_qr
));
mInstructions
.
setText
(
getResources
().
getString
(
R
.
string
.
solve_qr
));
...
@@ -88,8 +87,10 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
...
@@ -88,8 +87,10 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
case
(
ProblemType
.
CAMERA
):
case
(
ProblemType
.
CAMERA
):
mIcon
.
setImageDrawable
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
ic_photo_camera_black_24dp
));
mIcon
.
setImageDrawable
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
ic_photo_camera_black_24dp
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mIcon
.
setBackground
(
getActivity
().
getResources
().
getDrawable
(
R
.
drawable
.
circle_login_icons
));
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
DST_OUT
);
mIcon
.
setColorFilter
(
getResources
().
getColor
(
R
.
color
.
white
),
PorterDuff
.
Mode
.
SRC_IN
);
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
getActivity
()));
if
(
Build
.
VERSION
.
SDK_INT
>=
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mIcon
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
getActivity
()));
}
mInstructions
.
setText
(
getResources
().
getString
(
R
.
string
.
solve_photo
));
mInstructions
.
setText
(
getResources
().
getString
(
R
.
string
.
solve_photo
));
break
;
break
;
...
@@ -109,17 +110,17 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
...
@@ -109,17 +110,17 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
super
.
onStart
();
super
.
onStart
();
_rxBus
=
((
GameActivity
)
getActivity
()).
getRxBusSingleton
();
_rxBus
=
((
GameActivity
)
getActivity
()).
getRxBusSingleton
();
mDisposables
=
new
CompositeDisposable
();
mDisposables
=
new
CompositeDisposable
();
mDisposables
.
add
(
_rxBus
.
asFlowable
()
//
mDisposables.add(_rxBus.asFlowable()
.
subscribeOn
(
AndroidSchedulers
.
mainThread
())
//
.subscribeOn(AndroidSchedulers.mainThread())
.
subscribe
(
new
Consumer
<
Object
>()
{
//
.subscribe(new Consumer<Object>() {
@Override
//
@Override
public
void
accept
(
@NonNull
Object
o
)
throws
Exception
{
//
public void accept(@NonNull Object o) throws Exception {
if
(
o
instanceof
CheckInResponse
)
{
//
if (o instanceof CheckInResponse) {
if
(
isUserWaitingForAnswer
&&
((
CheckInResponse
)
o
).
getAnswer
().
getProblem_type
().
getTitle
().
equals
(
ProblemType
.
CAMERA
))
//
if (isUserWaitingForAnswer && ((CheckInResponse) o).getAnswer().getProblem_type().getTitle().equals(ProblemType.CAMERA))
onWrongAnswer
(((
CheckInResponse
)
o
).
getAnswer
());
//
onWrongAnswer(((CheckInResponse) o).getAnswer());
}
//
}
}
//
}
}));
//
}));
}
}
@Override
@Override
...
@@ -137,14 +138,14 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
...
@@ -137,14 +138,14 @@ public class SolveFragment extends Fragment implements onAnswerGivenListener {
}
}
}
}
}
}
if
(!
answer
.
getProblem_type
().
getTitle
().
equals
(
ProblemType
.
CAMERA
))
onWrongAnswer
(
answer
);
onWrongAnswer
(
answer
);
}
}
p
rivate
void
onWrongAnswer
(
Answer
answer
)
{
p
ublic
void
onWrongAnswer
(
Answer
answer
)
{
isUserWaitingForAnswer
=
false
;
isUserWaitingForAnswer
=
false
;
mInstructions
.
setText
(
getActivity
().
getResources
().
getString
(
R
.
string
.
solve_wrong_answer
,
mPoint
.
getTimePenalty
()));
mInstructions
.
setText
(
getActivity
().
getResources
().
getString
(
R
.
string
.
solve_wrong_answer
,
mPoint
.
getTimePenalty
()
/
1000
));
Vibrator
v
=
(
Vibrator
)
getActivity
().
getSystemService
(
Context
.
VIBRATOR_SERVICE
);
Vibrator
v
=
(
Vibrator
)
getActivity
().
getSystemService
(
Context
.
VIBRATOR_SERVICE
);
v
.
vibrate
(
500
);
v
.
vibrate
(
500
);
...
...
app/src/main/java/ee/ttu/thesis/ui/list/GamesAdapter.java
View file @
df953f27
...
@@ -11,6 +11,7 @@ import java.util.List;
...
@@ -11,6 +11,7 @@ import java.util.List;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.ui.game.messages.ViewHolderGameNotification
;
import
ee.ttu.thesis.ui.list.ViewHolderGamesCategory
;
import
ee.ttu.thesis.ui.list.ViewHolderGamesCategory
;
import
ee.ttu.thesis.ui.list.ViewHolderGamesGame
;
import
ee.ttu.thesis.ui.list.ViewHolderGamesGame
;
...
@@ -22,12 +23,13 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -22,12 +23,13 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
private
List
<
Object
>
mObjects
;
private
List
<
Object
>
mObjects
;
private
Context
mContext
;
private
Context
mContext
;
private
int
mCurrentPoint
;
public
final
static
int
CATEGORY_TITLE
=
0
,
GAME
=
1
,
BUTTON
=
2
;
public
final
static
int
CATEGORY_TITLE
=
0
,
GAME
=
1
;
public
GamesAdapter
(
List
<
Object
>
mObjects
,
Context
mContext
,
int
currentPoint
)
{
public
GamesAdapter
(
List
<
Object
>
mObjects
,
Context
mContext
)
{
this
.
mObjects
=
mObjects
;
this
.
mObjects
=
mObjects
;
this
.
mContext
=
mContext
;
this
.
mContext
=
mContext
;
this
.
mCurrentPoint
=
currentPoint
;
}
}
public
Context
getContext
()
{
public
Context
getContext
()
{
...
@@ -48,6 +50,10 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -48,6 +50,10 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
View
game_view
=
inflater
.
inflate
(
R
.
layout
.
item_game
,
parent
,
false
);
View
game_view
=
inflater
.
inflate
(
R
.
layout
.
item_game
,
parent
,
false
);
viewHolder
=
new
ViewHolderGamesGame
(
game_view
);
viewHolder
=
new
ViewHolderGamesGame
(
game_view
);
break
;
break
;
case
BUTTON:
View
button_view
=
inflater
.
inflate
(
R
.
layout
.
item_game_button
,
parent
,
false
);
viewHolder
=
new
ViewHolderGamesButtons
(
button_view
);
break
;
default
:
default
:
View
default_view
=
inflater
.
inflate
(
R
.
layout
.
item_game_category
,
parent
,
false
);
View
default_view
=
inflater
.
inflate
(
R
.
layout
.
item_game_category
,
parent
,
false
);
viewHolder
=
new
ViewHolderGamesCategory
(
default_view
);
viewHolder
=
new
ViewHolderGamesCategory
(
default_view
);
...
@@ -67,15 +73,28 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -67,15 +73,28 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
ViewHolderGamesGame
viewHolderGamesGame
=
(
ViewHolderGamesGame
)
holder
;
ViewHolderGamesGame
viewHolderGamesGame
=
(
ViewHolderGamesGame
)
holder
;
configureGameViewHolder
(
viewHolderGamesGame
,
position
);
configureGameViewHolder
(
viewHolderGamesGame
,
position
);
break
;
break
;
case
BUTTON:
ViewHolderGamesButtons
viewHolderGamesButtons
=
(
ViewHolderGamesButtons
)
holder
;
configureGameButtonViewHolder
(
viewHolderGamesButtons
,
position
);
break
;
}
}
}
}
private
void
configureGameButtonViewHolder
(
ViewHolderGamesButtons
holder
,
int
position
){
}
private
void
configureGameViewHolder
(
ViewHolderGamesGame
viewHolderGamesGame
,
int
position
)
{
private
void
configureGameViewHolder
(
ViewHolderGamesGame
viewHolderGamesGame
,
int
position
)
{
Game
game
=
(
Game
)
mObjects
.
get
(
position
);
Game
game
=
(
Game
)
mObjects
.
get
(
position
);
viewHolderGamesGame
.
getGameNameTV
().
setText
(
game
.
getTitle
());
viewHolderGamesGame
.
getGameNameTV
().
setText
(
game
.
getTitle
());
viewHolderGamesGame
.
getGameLocationTV
().
setText
(
"@"
+
game
.
getLocationName
());
viewHolderGamesGame
.
getGameLocationTV
().
setText
(
"@"
+
game
.
getLocationName
());
if
(
position
==
1
){
if
(
position
==
1
){
viewHolderGamesGame
.
getGameTimeTV
().
setText
(
"• Now"
);
if
(
mCurrentPoint
>=
0
)
viewHolderGamesGame
.
getGameTimeTV
().
setText
(
"• Continue"
);
else
viewHolderGamesGame
.
getGameTimeTV
().
setText
(
"• Start"
);
viewHolderGamesGame
.
getGameTimeTV
().
setTextColor
(
getContext
().
getResources
().
getColor
(
R
.
color
.
colorAccent
));
viewHolderGamesGame
.
getGameTimeTV
().
setTextColor
(
getContext
().
getResources
().
getColor
(
R
.
color
.
colorAccent
));
}
else
{
}
else
{
SimpleDateFormat
dateFormatter
=
new
SimpleDateFormat
(
"E, d-M-y"
);
SimpleDateFormat
dateFormatter
=
new
SimpleDateFormat
(
"E, d-M-y"
);
...
@@ -93,7 +112,9 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
...
@@ -93,7 +112,9 @@ public class GamesAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>
@Override
@Override
public
int
getItemViewType
(
int
position
)
{
public
int
getItemViewType
(
int
position
)
{
if
(
mObjects
.
get
(
position
)
instanceof
String
)
if
(
position
==
mObjects
.
size
()-
1
)
return
BUTTON
;
else
if
(
mObjects
.
get
(
position
)
instanceof
String
)
return
CATEGORY_TITLE
;
return
CATEGORY_TITLE
;
else
else
return
GAME
;
return
GAME
;
...
...
app/src/main/java/ee/ttu/thesis/ui/list/ListActivity.java
View file @
df953f27
...
@@ -2,6 +2,7 @@ package ee.ttu.thesis.ui.list;
...
@@ -2,6 +2,7 @@ package ee.ttu.thesis.ui.list;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.StringRes
;
import
android.support.annotation.StringRes
;
import
android.support.v4.app.FragmentManager
;
import
android.support.v4.app.FragmentManager
;
...
@@ -10,6 +11,14 @@ import android.support.v7.widget.RecyclerView;
...
@@ -10,6 +11,14 @@ import android.support.v7.widget.RecyclerView;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.facebook.login.LoginManager
;
import
com.google.android.gms.auth.api.Auth
;
import
com.google.android.gms.auth.api.signin.GoogleSignInOptions
;
import
com.google.android.gms.common.ConnectionResult
;
import
com.google.android.gms.common.api.GoogleApiClient
;
import
com.google.android.gms.common.api.ResultCallback
;
import
com.google.android.gms.common.api.Status
;
import
com.google.android.gms.plus.Plus
;
import
com.orhanobut.logger.Logger
;
import
com.orhanobut.logger.Logger
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -22,25 +31,28 @@ import butterknife.BindView;
...
@@ -22,25 +31,28 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
butterknife.OnClick
;
import
butterknife.OnClick
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.future.FutureGameActivity
;
import
ee.ttu.thesis.ui.future.FutureGameActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.login.LoginActivity
;
import
ee.ttu.thesis.ui.past.HistoryActivity
;
import
ee.ttu.thesis.ui.past.HistoryActivity
;
import
ee.ttu.thesis.ui.start.StartActivity
;
import
ee.ttu.thesis.ui.start.StartActivity
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.utils.DividerDecoration
;
import
ee.ttu.thesis.utils.DividerDecoration
;
import
ee.ttu.thesis.utils.ItemClickSupport
;
import
ee.ttu.thesis.utils.ItemClickSupport
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
/**
/**
* Created by hajola on 22.03.17.
* Created by hajola on 22.03.17.
*/
*/
public
class
ListActivity
extends
BaseActivity
implements
AddGameDialogFragment
.
OnGameAddListener
,
ListView
{
public
class
ListActivity
extends
BaseActivity
implements
AddGameDialogFragment
.
OnGameAddListener
,
ListView
,
GoogleApiClient
.
ConnectionCallbacks
,
GoogleApiClient
.
OnConnectionFailedListener
{
@Inject
@Inject
ListTreasureHuntPresenter
<
ListView
>
mPresenter
;
ListTreasureHuntPresenter
<
ListView
>
mPresenter
;
...
@@ -53,6 +65,8 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -53,6 +65,8 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
List
<
UserGame
>
mUserGames
=
new
ArrayList
<>();
List
<
UserGame
>
mUserGames
=
new
ArrayList
<>();
GoogleApiClient
mGoogleApiClient
;
User
mUser
;
User
mUser
;
@Override
@Override
...
@@ -60,13 +74,28 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -60,13 +74,28 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
setContentView
(
R
.
layout
.
activity_main
);
setContentView
(
R
.
layout
.
activity_main
);
GoogleSignInOptions
gso
=
new
GoogleSignInOptions
.
Builder
(
GoogleSignInOptions
.
DEFAULT_SIGN_IN
)
.
requestEmail
()
.
requestId
()
.
requestIdToken
(
getString
(
R
.
string
.
server_client_id
))
.
build
();
mGoogleApiClient
=
new
GoogleApiClient
.
Builder
(
this
)
.
enableAutoManage
(
this
,
this
)
.
addApi
(
Auth
.
GOOGLE_SIGN_IN_API
,
gso
)
.
build
();
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
getActivityComponent
().
inject
(
this
);
getActivityComponent
().
inject
(
this
);
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
mPresenter
.
onAttach
(
this
);
mPresenter
.
onAttach
(
this
);
mPresenter
.
onViewInitialized
(
new
GamesRequest
.
UserGamesRequest
(
1
));
mPresenter
.
onViewInitialized
(
new
GamesRequest
.
UserGamesRequest
(
mUser
.
getId
()
));
m
User
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
m
Objects
.
add
(
"logout"
);
mAdapter
=
new
GamesAdapter
(
mObjects
,
this
);
mAdapter
=
new
GamesAdapter
(
mObjects
,
this
,
mPresenter
.
getCurrentPoint
()
);
mRecyclerView
.
setAdapter
(
mAdapter
);
mRecyclerView
.
setAdapter
(
mAdapter
);
mRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
this
));
mRecyclerView
.
setLayoutManager
(
new
LinearLayoutManager
(
this
));
...
@@ -78,24 +107,79 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -78,24 +107,79 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
new
ItemClickSupport
.
OnItemClickListener
()
{
new
ItemClickSupport
.
OnItemClickListener
()
{
@Override
@Override
public
void
onItemClicked
(
RecyclerView
recyclerView
,
int
position
,
View
v
)
{
public
void
onItemClicked
(
RecyclerView
recyclerView
,
int
position
,
View
v
)
{
if
(
mObjects
.
get
(
position
)
instanceof
Game
)
{
if
(
mObjects
.
size
()
-
1
==
position
)
{
if
(
mPresenter
.
getService
().
equals
(
"fb"
))
{
LoginManager
.
getInstance
().
logOut
();
mPresenter
.
logOut
();
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
LoginActivity
.
class
);
startActivity
(
intent
);
finish
();
}
else
{
if
(
mGoogleApiClient
!=
null
&&
mGoogleApiClient
.
isConnected
())
{
Auth
.
GoogleSignInApi
.
signOut
(
mGoogleApiClient
).
setResultCallback
(
new
ResultCallback
<
Status
>()
{
@Override
public
void
onResult
(
Status
status
)
{
mGoogleApiClient
.
disconnect
();
mPresenter
.
logOut
();
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
LoginActivity
.
class
);
startActivity
(
intent
);
finish
();
}
});
}
}
}
else
if
(
mObjects
.
get
(
position
)
instanceof
Game
)
{
Game
game
=
(
Game
)
mObjects
.
get
(
position
);
Game
game
=
(
Game
)
mObjects
.
get
(
position
);
Date
now
=
new
Date
();
Date
now
=
new
Date
();
Date
start
=
game
.
getStartTime
();
Date
start
=
game
.
getStartTime
();
Date
end
=
game
.
getEndTime
();
Date
end
=
game
.
getEndTime
();
if
(
start
.
before
(
now
)
&&
end
.
after
(
now
))
{
if
(
start
.
before
(
now
)
&&
end
.
after
(
now
))
{
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
StartActivity
.
class
);
Intent
intent
;
if
(
mPresenter
.
getCurrentPoint
()
>=
0
)
intent
=
new
Intent
(
ListActivity
.
this
,
GameActivity
.
class
);
else
intent
=
new
Intent
(
ListActivity
.
this
,
StartActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
((
Game
)
mObjects
.
get
(
position
)));
intent
.
putExtra
(
GAME_KEY
,
((
Game
)
mObjects
.
get
(
position
)));
UserGame
userGame
=
null
;
for
(
UserGame
g
:
mUserGames
)
{
if
(((
Game
)
mObjects
.
get
(
position
)).
getId
()
==
g
.
getGame
().
getId
())
{
userGame
=
g
;
break
;
}
}
intent
.
putExtra
(
USER_GAME_KEY
,
userGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
startActivity
(
intent
);
finish
();
finish
();
}
else
if
(
start
.
after
(
now
))
{
}
else
if
(
start
.
after
(
now
))
{
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
FutureGameActivity
.
class
);
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
FutureGameActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
((
Game
)
mObjects
.
get
(
position
)));
intent
.
putExtra
(
GAME_KEY
,
((
Game
)
mObjects
.
get
(
position
)));
UserGame
userGame
=
null
;
for
(
UserGame
g
:
mUserGames
)
{
if
(((
Game
)
mObjects
.
get
(
position
)).
getId
()
==
g
.
getGame
().
getId
())
{
userGame
=
g
;
break
;
}
}
intent
.
putExtra
(
USER_GAME_KEY
,
userGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
startActivity
(
intent
);
}
else
{
}
else
{
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
HistoryActivity
.
class
);
Intent
intent
=
new
Intent
(
ListActivity
.
this
,
HistoryActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
((
Game
)
mObjects
.
get
(
position
)));
UserGame
userGame
=
null
;
for
(
UserGame
g
:
mUserGames
)
{
if
(((
Game
)
mObjects
.
get
(
position
)).
getId
()
==
g
.
getGame
().
getId
())
{
userGame
=
g
;
break
;
}
}
intent
.
putExtra
(
USER_GAME_KEY
,
userGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
startActivity
(
intent
);
}
}
...
@@ -116,7 +200,7 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -116,7 +200,7 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
@Override
@Override
public
void
onFinishEditDialog
(
String
gameName
)
{
public
void
onFinishEditDialog
(
String
gameName
)
{
Toast
.
makeText
(
this
,
gameName
,
Toast
.
LENGTH_SHORT
).
show
();
Toast
.
makeText
(
this
,
gameName
,
Toast
.
LENGTH_SHORT
).
show
();
mPresenter
.
onAddGame
(
new
GamesRequest
.
AddGameRequest
(
1
,
gameName
));
mPresenter
.
onAddGame
(
new
GamesRequest
.
AddGameRequest
(
mUser
.
getId
()
,
gameName
));
}
}
@Override
@Override
...
@@ -176,11 +260,11 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -176,11 +260,11 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
mObjects
.
add
(
past
,
g
);
mObjects
.
add
(
past
,
g
);
}
}
}
}
if
(
_bpast
)
if
(
_bpast
)
mObjects
.
add
(
past
,
"Past"
);
mObjects
.
add
(
past
,
"Past"
);
if
(
_bupcoming
)
if
(
_bupcoming
)
mObjects
.
add
(
upcoming
,
"Upcoming"
);
mObjects
.
add
(
upcoming
,
"Upcoming"
);
if
(
_bcurrent
)
if
(
_bcurrent
)
mObjects
.
add
(
0
,
"Current"
);
mObjects
.
add
(
0
,
"Current"
);
mAdapter
.
notifyDataSetChanged
();
mAdapter
.
notifyDataSetChanged
();
...
@@ -237,4 +321,34 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
...
@@ -237,4 +321,34 @@ public class ListActivity extends BaseActivity implements AddGameDialogFragment.
}
}
mAdapter
.
notifyDataSetChanged
();
mAdapter
.
notifyDataSetChanged
();
}
}
@Override
public
void
onConnected
(
@Nullable
Bundle
bundle
)
{
}
@Override
public
void
onConnectionSuspended
(
int
i
)
{
}
@Override
protected
void
onStart
()
{
super
.
onStart
();
mGoogleApiClient
.
connect
();
}
@Override
protected
void
onStop
()
{
super
.
onStop
();
if
(
mGoogleApiClient
.
isConnected
())
{
mGoogleApiClient
.
disconnect
();
}
}
@Override
public
void
onConnectionFailed
(
@NonNull
ConnectionResult
connectionResult
)
{
}
}
}
app/src/main/java/ee/ttu/thesis/ui/list/ListPresenter.java
View file @
df953f27
...
@@ -83,4 +83,27 @@ public class ListPresenter<V extends ListView> extends BasePresenter<V> implemen
...
@@ -83,4 +83,27 @@ public class ListPresenter<V extends ListView> extends BasePresenter<V> implemen
}));
}));
}
}
@Override
public
String
getService
()
{
return
getDataManager
().
getService
();
}
@Override
public
String
getGameCode
()
{
return
getDataManager
().
getCurrentGameCode
();
}
@Override
public
int
getCurrentPoint
()
{
return
getDataManager
().
getCurrentPoint
();
}
@Override
public
void
logOut
()
{
getDataManager
().
setService
(
null
);
getDataManager
().
setCurrentUserId
(
0
);
getDataManager
().
setCurrentGameCode
(
null
);
getDataManager
().
setCurrentPoint
(-
1
);
}
}
}
app/src/main/java/ee/ttu/thesis/ui/list/ListTreasureHuntPresenter.java
View file @
df953f27
...
@@ -15,4 +15,11 @@ public interface ListTreasureHuntPresenter<V extends ListView> extends TreauseHu
...
@@ -15,4 +15,11 @@ public interface ListTreasureHuntPresenter<V extends ListView> extends TreauseHu
void
onAddGame
(
GamesRequest
.
AddGameRequest
userGamesRequest
);
void
onAddGame
(
GamesRequest
.
AddGameRequest
userGamesRequest
);
String
getService
();
String
getGameCode
();
int
getCurrentPoint
();
void
logOut
();
}
}
app/src/main/java/ee/ttu/thesis/ui/list/ViewHolderGamesButtons.java
0 → 100644
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
list
;
import
android.support.v7.widget.RecyclerView
;
import
android.view.View
;
import
android.widget.TextView
;
import
butterknife.BindView
;
import
butterknife.ButterKnife
;
import
ee.ttu.thesis.R
;
/**
* Created by hajola on 4.06.17.
*/
public
class
ViewHolderGamesButtons
extends
RecyclerView
.
ViewHolder
{
@BindView
(
R
.
id
.
logout
)
TextView
logOut
;
public
ViewHolderGamesButtons
(
View
itemView
)
{
super
(
itemView
);
ButterKnife
.
bind
(
this
,
itemView
);
}
public
TextView
getLogOut
()
{
return
logOut
;
}
public
void
setLogOut
(
TextView
logOut
)
{
this
.
logOut
=
logOut
;
}
}
\ No newline at end of file
app/src/main/java/ee/ttu/thesis/ui/login/LoginActivity.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
login
;
package
ee
.
ttu
.
thesis
.
ui
.
login
;
import
android.app.Activity
;
import
android.content.Intent
;
import
android.content.Intent
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.NonNull
;
import
android.support.annotation.NonNull
;
...
@@ -14,6 +15,14 @@ import android.widget.ProgressBar;
...
@@ -14,6 +15,14 @@ import android.widget.ProgressBar;
import
android.widget.TextView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
com.facebook.AccessToken
;
import
com.facebook.AccessTokenTracker
;
import
com.facebook.CallbackManager
;
import
com.facebook.FacebookCallback
;
import
com.facebook.FacebookException
;
import
com.facebook.FacebookSdk
;
import
com.facebook.login.LoginManager
;
import
com.facebook.login.LoginResult
;
import
com.google.android.gms.auth.api.Auth
;
import
com.google.android.gms.auth.api.Auth
;
import
com.google.android.gms.auth.api.signin.GoogleSignInAccount
;
import
com.google.android.gms.auth.api.signin.GoogleSignInAccount
;
import
com.google.android.gms.auth.api.signin.GoogleSignInOptions
;
import
com.google.android.gms.auth.api.signin.GoogleSignInOptions
;
...
@@ -22,7 +31,9 @@ import com.google.android.gms.common.ConnectionResult;
...
@@ -22,7 +31,9 @@ import com.google.android.gms.common.ConnectionResult;
import
com.google.android.gms.common.api.GoogleApiClient
;
import
com.google.android.gms.common.api.GoogleApiClient
;
import
com.google.android.gms.common.api.OptionalPendingResult
;
import
com.google.android.gms.common.api.OptionalPendingResult
;
import
com.google.android.gms.common.api.ResultCallback
;
import
com.google.android.gms.common.api.ResultCallback
;
import
com.orhanobut.logger.Logger
;
import
java.util.Arrays
;
import
java.util.Date
;
import
java.util.Date
;
import
java.util.List
;
import
java.util.List
;
...
@@ -35,6 +46,7 @@ import ee.ttu.thesis.R;
...
@@ -35,6 +46,7 @@ import ee.ttu.thesis.R;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.GamesRequest
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.list.ListActivity
;
import
ee.ttu.thesis.ui.list.ListActivity
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.data.model.UserGame
;
...
@@ -43,6 +55,7 @@ import ee.ttu.thesis.utils.CommonUtils;
...
@@ -43,6 +55,7 @@ import ee.ttu.thesis.utils.CommonUtils;
import
ee.ttu.thesis.utils.DeviceDimensionsHelper
;
import
ee.ttu.thesis.utils.DeviceDimensionsHelper
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
public
class
LoginActivity
extends
BaseActivity
implements
GoogleApiClient
.
OnConnectionFailedListener
,
LoginView
{
public
class
LoginActivity
extends
BaseActivity
implements
GoogleApiClient
.
OnConnectionFailedListener
,
LoginView
{
...
@@ -58,11 +71,14 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -58,11 +71,14 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
String
userName
=
""
;
String
userName
=
""
;
Game
mGame
;
Game
mGame
;
UserGame
mUserGame
;
User
mUser
;
User
mUser
;
boolean
isGameReady
=
false
;
boolean
isGameReady
=
false
;
@BindView
(
R
.
id
.
signInButton_activity_login_google
)
@BindView
(
R
.
id
.
signInButton_activity_login_google
)
View
mGoogleSignInButton
;
View
mGoogleSignInButton
;
@BindView
(
R
.
id
.
signInButton_activity_login_facebook
)
View
mFacebookSignIn
;
@BindView
(
R
.
id
.
activity_login_game_code_editText
)
@BindView
(
R
.
id
.
activity_login_game_code_editText
)
EditText
mGameCodeET
;
EditText
mGameCodeET
;
@BindView
(
R
.
id
.
activity_login_user_name_editText
)
@BindView
(
R
.
id
.
activity_login_user_name_editText
)
...
@@ -80,6 +96,16 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -80,6 +96,16 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
@BindView
(
R
.
id
.
activity_login_gameInfo
)
@BindView
(
R
.
id
.
activity_login_gameInfo
)
TextView
mInfo
;
TextView
mInfo
;
AccessToken
accessToken
;
CallbackManager
callbackManager
;
// saada user_id ja game_id
// Saad vastu user_game_id ja game'i, sealt toimetad edasi nagu tavaliselt
//
// Erinevus
//-Listview current
// - mäng on alustatud
// - mängu pole alustatud
@Override
@Override
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
Bundle
savedInstanceState
)
{
...
@@ -89,6 +115,52 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -89,6 +115,52 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
mPresenter
.
onAttach
(
this
);
mPresenter
.
onAttach
(
this
);
// Kas vaja automaatselt liigutada kasutaja mangu
if
(
mPresenter
.
getService
()
==
null
){
if
(
mPresenter
.
getGameCode
()
!=
null
){
//Liigume automaatselt mangu
showLargeLoading
();
mPresenter
.
getUserGame
(
mPresenter
.
getGameCode
(),
mPresenter
.
getUserId
());
}
}
FacebookSdk
.
sdkInitialize
(
this
.
getApplicationContext
());
callbackManager
=
CallbackManager
.
Factory
.
create
();
LoginManager
.
getInstance
().
registerCallback
(
callbackManager
,
new
FacebookCallback
<
LoginResult
>()
{
@Override
public
void
onSuccess
(
LoginResult
loginResult
)
{
if
(
accessToken
!=
null
)
logIn
(
"fb"
,
accessToken
.
getToken
());
}
@Override
public
void
onCancel
()
{
Logger
.
d
(
"cancel"
);
}
@Override
public
void
onError
(
FacebookException
error
)
{
Logger
.
d
(
error
.
toString
());
}
});
final
AccessTokenTracker
accessTokenTracker
=
new
AccessTokenTracker
()
{
@Override
protected
void
onCurrentAccessTokenChanged
(
AccessToken
oldAccessToken
,
AccessToken
currentAccessToken
)
{
// Set the access token using
// currentAccessToken when it's loaded or set.
if
(
accessToken
==
null
)
{
accessToken
=
AccessToken
.
getCurrentAccessToken
();
logIn
(
"fb"
,
accessToken
.
getToken
());
}
accessToken
=
AccessToken
.
getCurrentAccessToken
();
}
};
// If the access token is available already assign it.
accessToken
=
AccessToken
.
getCurrentAccessToken
();
GoogleSignInOptions
gso
=
new
GoogleSignInOptions
.
Builder
(
GoogleSignInOptions
.
DEFAULT_SIGN_IN
)
GoogleSignInOptions
gso
=
new
GoogleSignInOptions
.
Builder
(
GoogleSignInOptions
.
DEFAULT_SIGN_IN
)
.
requestEmail
()
.
requestEmail
()
.
requestId
()
.
requestId
()
...
@@ -142,6 +214,16 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -142,6 +214,16 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
}
}
});
});
if
(
mPresenter
.
getService
()
!=
null
&&
mPresenter
.
getService
().
equals
(
"fb"
)){
mFacebookSignIn
.
callOnClick
();
}
}
@OnClick
(
R
.
id
.
signInButton_activity_login_facebook
)
public
void
onFaceBookSignIn
(
View
v
){
LoginManager
.
getInstance
().
logInWithReadPermissions
(
this
,
Arrays
.
asList
(
"email"
,
"public_profile"
));
}
}
@OnClick
(
R
.
id
.
activity_login_enter_button
)
@OnClick
(
R
.
id
.
activity_login_enter_button
)
...
@@ -193,22 +275,20 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -193,22 +275,20 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
@Override
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
super
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
// Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...);
if
(
requestCode
==
RC_SIGN_IN
)
{
if
(
requestCode
==
RC_SIGN_IN
)
{
GoogleSignInResult
result
=
Auth
.
GoogleSignInApi
.
getSignInResultFromIntent
(
data
);
GoogleSignInResult
result
=
Auth
.
GoogleSignInApi
.
getSignInResultFromIntent
(
data
);
handleSignInResult
(
result
);
handleSignInResult
(
result
);
}
}
callbackManager
.
onActivityResult
(
requestCode
,
resultCode
,
data
);
}
}
private
void
handleSignInResult
(
GoogleSignInResult
result
)
{
private
void
handleSignInResult
(
GoogleSignInResult
result
)
{
Log
.
d
(
"LoginActivity"
,
"handleSignInResult:"
+
result
.
isSuccess
());
Log
.
d
(
"LoginActivity"
,
"handleSignInResult:"
+
result
.
isSuccess
());
if
(
result
.
isSuccess
())
{
if
(
result
.
isSuccess
())
{
// Signed in successfully, show authenticated UI.
GoogleSignInAccount
acct
=
result
.
getSignInAccount
();
GoogleSignInAccount
acct
=
result
.
getSignInAccount
();
String
idToken
=
acct
.
getIdToken
();
String
idToken
=
acct
.
getIdToken
();
// TODO(user): send token to server and validate server-side
logIn
(
"google"
,
idToken
);
goToGame
(
true
);
}
else
{
}
else
{
// Signed out, show unauthenticated UI.
// Signed out, show unauthenticated UI.
// goToGame(false, null;
// goToGame(false, null;
...
@@ -216,9 +296,8 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -216,9 +296,8 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
}
}
private
void
goToGame
(
boolean
isRegisterdUser
){
private
void
goToGame
(
boolean
isRegisterdUser
){
mPresenter
.
saveUser
(
mUser
);
if
(
isRegisterdUser
){
if
(
isRegisterdUser
){
mUser
=
new
User
();
mUser
.
setId
(
1
);
Intent
intent
=
new
Intent
(
this
,
ListActivity
.
class
);
Intent
intent
=
new
Intent
(
this
,
ListActivity
.
class
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
startActivity
(
intent
);
...
@@ -227,6 +306,7 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -227,6 +306,7 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
Intent
intent
=
new
Intent
(
this
,
StartActivity
.
class
);
Intent
intent
=
new
Intent
(
this
,
StartActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_GAME_KEY
,
mUserGame
);
startActivity
(
intent
);
startActivity
(
intent
);
finish
();
finish
();
}
}
...
@@ -240,16 +320,28 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -240,16 +320,28 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
mGameTitle
.
setVisibility
(
View
.
INVISIBLE
);
mGameTitle
.
setVisibility
(
View
.
INVISIBLE
);
}
}
private
void
logIn
(
String
service
,
String
access_token
){
Logger
.
d
(
"accesstoken log in: "
+
access_token
);
mUser
=
new
User
();
mUser
.
setService
(
service
);
mPresenter
.
saveService
(
service
);
mPresenter
.
logIn
(
service
,
access_token
);
}
private
void
elevateEnter
(
boolean
elevate
)
{
private
void
elevateEnter
(
boolean
elevate
)
{
isGameReady
=
elevate
;
isGameReady
=
elevate
;
if
(
elevate
)
{
if
(
elevate
)
{
mEnterButton
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
login_rounded_rectangle_filled
));
mEnterButton
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
login_rounded_rectangle_filled
));
mEnterButton
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
white
));
mEnterButton
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
white
));
mEnterButton
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
LoginActivity
.
this
));
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mEnterButton
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
6
,
LoginActivity
.
this
));
}
}
else
{
}
else
{
mEnterButton
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
rounded_rectangle
));
mEnterButton
.
setBackground
(
getResources
().
getDrawable
(
R
.
drawable
.
rounded_rectangle
));
mEnterButton
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
colorPrimaryLight
));
mEnterButton
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
colorPrimaryLight
));
mEnterButton
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
0
,
LoginActivity
.
this
));
if
(
android
.
os
.
Build
.
VERSION
.
SDK_INT
>=
android
.
os
.
Build
.
VERSION_CODES
.
LOLLIPOP
)
{
mEnterButton
.
setElevation
(
DeviceDimensionsHelper
.
convertDpToPixel
(
0
,
LoginActivity
.
this
));
}
}
}
}
}
...
@@ -283,11 +375,6 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -283,11 +375,6 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
}
}
@Override
@Override
public
void
hideKeyboard
()
{
}
@Override
public
void
loadGame
(
List
<
Game
>
games
)
{
public
void
loadGame
(
List
<
Game
>
games
)
{
if
(
games
==
null
||
games
.
size
()
<
1
)
{
if
(
games
==
null
||
games
.
size
()
<
1
)
{
mJoinTheAdventure
.
setVisibility
(
View
.
VISIBLE
);
mJoinTheAdventure
.
setVisibility
(
View
.
VISIBLE
);
...
@@ -327,14 +414,23 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -327,14 +414,23 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
@Override
@Override
public
void
userAdded
(
User
user
)
{
public
void
userAdded
(
User
user
)
{
mUser
=
user
;
mUser
=
user
;
mPresenter
.
saveUser
(
user
);
mPresenter
.
addUserToAGame
(
new
GamesRequest
.
AddGameRequest
(
user
.
getId
(),
gameCode
));
mPresenter
.
addUserToAGame
(
new
GamesRequest
.
AddGameRequest
(
user
.
getId
(),
gameCode
));
}
}
@Override
@Override
public
void
loggedIn
(
String
userId
)
{
if
(
mUser
==
null
)
mUser
=
new
User
();
mUser
.
setId
(
Integer
.
parseInt
(
userId
));
goToGame
(
true
);
}
@Override
public
void
showLargeLoading
()
{
public
void
showLargeLoading
()
{
super
.
hideKeyboard
();
if
(!
isFinishing
())
{
super
.
showLoading
();
super
.
hideKeyboard
();
super
.
showLoading
();
}
}
}
@Override
@Override
...
@@ -345,8 +441,28 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
...
@@ -345,8 +441,28 @@ public class LoginActivity extends BaseActivity implements GoogleApiClient.OnCon
@Override
@Override
public
void
gameAdded
(
UserGame
userGame
)
{
public
void
gameAdded
(
UserGame
userGame
)
{
mGame
=
userGame
.
getGame
();
mGame
=
userGame
.
getGame
();
mUserGame
=
userGame
;
mGame
.
setUserGameId
(
userGame
.
getUserGameId
());
mGame
.
setUserGameId
(
userGame
.
getUserGameId
());
goToGame
(
false
);
goToGame
(
false
);
}
}
// Automaatselt mangu
@Override
public
void
loadUserGame
(
UserGame
userGame
)
{
mGame
=
userGame
.
getGame
();
mGame
.
setUserGameId
(
userGame
.
getUserGameId
());
mUserGame
=
userGame
;
if
(
mUser
==
null
){
mUser
=
new
User
();
mUser
.
setId
(
Integer
.
parseInt
(
mPresenter
.
getUserId
()));
}
Intent
intent
=
new
Intent
(
this
,
GameActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_GAME_KEY
,
mUserGame
);
startActivity
(
intent
);
finish
();
}
}
}
app/src/main/java/ee/ttu/thesis/ui/login/LoginPresenter.java
View file @
df953f27
...
@@ -113,4 +113,74 @@ public class LoginPresenter<V extends LoginView> extends BasePresenter<V> implem
...
@@ -113,4 +113,74 @@ public class LoginPresenter<V extends LoginView> extends BasePresenter<V> implem
public
void
saveUser
(
User
user
)
{
public
void
saveUser
(
User
user
)
{
getDataManager
().
setCurrentUserId
(
user
.
getId
());
getDataManager
().
setCurrentUserId
(
user
.
getId
());
}
}
@Override
public
void
saveService
(
String
service
)
{
getDataManager
().
setService
(
service
);
}
@Override
public
String
getService
()
{
return
getDataManager
().
getService
();
}
@Override
public
String
getGameCode
()
{
return
getDataManager
().
getCurrentGameCode
();
}
@Override
public
String
getUserId
()
{
return
Integer
.
toString
(
getDataManager
().
getCurrentUserId
());
}
@Override
public
void
getUserGame
(
String
gameCode
,
String
userId
)
{
getmThesisView
().
showLargeLoading
();
getCompositeDisposable
().
add
(
getDataManager
()
.
getUserGame
(
gameCode
,
userId
)
.
subscribeOn
(
getSchedulerProvider
().
io
())
.
observeOn
(
getSchedulerProvider
().
ui
())
.
subscribe
(
new
Consumer
<
UserGame
>()
{
@Override
public
void
accept
(
@NonNull
UserGame
userGame
)
throws
Exception
{
getmThesisView
().
hideLargeLoading
();
if
(!
isViewAttached
())
{
return
;
}
if
(
userGame
!=
null
)
{
getmThesisView
().
loadUserGame
(
userGame
);
}
}
},
new
Consumer
<
Throwable
>()
{
@Override
public
void
accept
(
@NonNull
Throwable
throwable
)
throws
Exception
{
getmThesisView
().
hideLargeLoading
();
getmThesisView
().
onError
(
throwable
.
getMessage
());
}
}));
}
@Override
public
void
logIn
(
String
service
,
String
access_token
)
{
getmThesisView
().
showLargeLoading
();
getCompositeDisposable
().
add
(
getDataManager
()
.
login
(
service
,
access_token
)
.
subscribeOn
(
getSchedulerProvider
().
io
())
.
observeOn
(
getSchedulerProvider
().
ui
())
.
subscribe
(
new
Consumer
<
String
>()
{
@Override
public
void
accept
(
@NonNull
String
s
)
throws
Exception
{
getmThesisView
().
hideLargeLoading
();
getmThesisView
().
loggedIn
(
s
);
}
},
new
Consumer
<
Throwable
>()
{
@Override
public
void
accept
(
@NonNull
Throwable
throwable
)
throws
Exception
{
getmThesisView
().
hideLargeLoading
();
getmThesisView
().
onError
(
throwable
.
getMessage
());
}
}));
}
}
}
app/src/main/java/ee/ttu/thesis/ui/login/LoginTreasureHuntPresenter.java
View file @
df953f27
...
@@ -18,4 +18,16 @@ public interface LoginTreasureHuntPresenter<V extends LoginView> extends Treause
...
@@ -18,4 +18,16 @@ public interface LoginTreasureHuntPresenter<V extends LoginView> extends Treause
void
saveUser
(
User
user
);
void
saveUser
(
User
user
);
void
saveService
(
String
service
);
String
getService
();
String
getGameCode
();
String
getUserId
();
void
getUserGame
(
String
gameCode
,
String
userId
);
void
logIn
(
String
service
,
String
access_token
);
}
}
app/src/main/java/ee/ttu/thesis/ui/login/LoginView.java
View file @
df953f27
...
@@ -17,10 +17,14 @@ public interface LoginView extends TreasureHuntView {
...
@@ -17,10 +17,14 @@ public interface LoginView extends TreasureHuntView {
void
userAdded
(
User
user
);
void
userAdded
(
User
user
);
void
loggedIn
(
String
userId
);
void
showLargeLoading
();
void
showLargeLoading
();
void
hideLargeLoading
();
void
hideLargeLoading
();
void
gameAdded
(
UserGame
userGame
);
void
gameAdded
(
UserGame
userGame
);
void
loadUserGame
(
UserGame
userGame
);
}
}
app/src/main/java/ee/ttu/thesis/ui/past/HistoryActivity.java
View file @
df953f27
package
ee
.
ttu
.
thesis
.
ui
.
past
;
package
ee
.
ttu
.
thesis
.
ui
.
past
;
import
android.location.Location
;
import
android.os.Bundle
;
import
android.os.Bundle
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.Nullable
;
import
android.support.annotation.StringRes
;
import
android.support.annotation.StringRes
;
import
android.widget.ScrollView
;
import
android.widget.ScrollView
;
import
android.widget.TextView
;
import
android.widget.Toast
;
import
com.google.android.gms.maps.CameraUpdateFactory
;
import
com.google.android.gms.maps.CameraUpdateFactory
;
import
com.google.android.gms.maps.GoogleMap
;
import
com.google.android.gms.maps.GoogleMap
;
import
com.google.android.gms.maps.OnMapReadyCallback
;
import
com.google.android.gms.maps.OnMapReadyCallback
;
import
com.google.android.gms.maps.model.JointType
;
import
com.google.android.gms.maps.model.JointType
;
import
com.google.android.gms.maps.model.LatLng
;
import
com.google.android.gms.maps.model.MapStyleOptions
;
import
com.google.android.gms.maps.model.MapStyleOptions
;
import
com.google.android.gms.maps.model.Polyline
;
import
com.google.android.gms.maps.model.Polyline
;
import
com.google.android.gms.maps.model.PolylineOptions
;
import
com.google.android.gms.maps.model.PolylineOptions
;
import
com.google.android.gms.maps.model.RoundCap
;
import
com.google.android.gms.maps.model.RoundCap
;
import
com.orhanobut.logger.Logger
;
import
com.orhanobut.logger.Logger
;
import
java.text.SimpleDateFormat
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Locale
;
import
java.util.concurrent.TimeUnit
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
...
@@ -24,11 +29,13 @@ import butterknife.BindView;
...
@@ -24,11 +29,13 @@ import butterknife.BindView;
import
butterknife.ButterKnife
;
import
butterknife.ButterKnife
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.CheckIn
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.game.map.WorkAroundMapFragment
;
import
ee.ttu.thesis.ui.game.map.WorkAroundMapFragment
;
import
ee.ttu.thesis.ui.start.StartTreasureHuntPresenter
;
import
ee.ttu.thesis.ui.start.StartView
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
/**
/**
* Created by hajola on 29.04.17.
* Created by hajola on 29.04.17.
...
@@ -37,27 +44,51 @@ import ee.ttu.thesis.ui.start.StartView;
...
@@ -37,27 +44,51 @@ import ee.ttu.thesis.ui.start.StartView;
public
class
HistoryActivity
extends
BaseActivity
public
class
HistoryActivity
extends
BaseActivity
implements
OnMapReadyCallback
,
implements
OnMapReadyCallback
,
GoogleMap
.
OnPolylineClickListener
,
GoogleMap
.
OnPolylineClickListener
,
HistoryView
{
HistoryView
{
GoogleMap
mMap
;
GoogleMap
mMap
;
@Inject
@Inject
HistoryTreasureHuntPresenter
<
HistoryView
>
mPresenter
;
HistoryTreasureHuntPresenter
<
HistoryView
>
mPresenter
;
Game
mGame
;
UserGame
mGame
;
User
mUser
;
@BindView
(
R
.
id
.
activity_history_scrollview
)
@BindView
(
R
.
id
.
activity_history_scrollview
)
ScrollView
mScrollView
;
ScrollView
mScrollView
;
// @BindView(R.id.activity_history_rank)
// TextView mRank;
@BindView
(
R
.
id
.
activity_history_distance_traveled
)
TextView
mDistance
;
@BindView
(
R
.
id
.
activity_history_time_taken
)
TextView
mTimeTaken
;
@BindView
(
R
.
id
.
activity_history_number_of_points
)
TextView
mNumbOfPoints
;
@BindView
(
R
.
id
.
activityV_history_average_speed
)
TextView
mAverageSpeed
;
@BindView
(
R
.
id
.
activity_history_average_point_speed
)
TextView
mAveragePointSpeed
;
@BindView
(
R
.
id
.
activity_history_start_time
)
TextView
mStart
;
@BindView
(
R
.
id
.
activity_history_end_time
)
TextView
mEnd
;
@Override
@Override
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
protected
void
onCreate
(
@Nullable
Bundle
savedInstanceState
)
{
super
.
onCreate
(
savedInstanceState
);
super
.
onCreate
(
savedInstanceState
);
getActivityComponent
().
inject
(
this
);
setContentView
(
R
.
layout
.
activity_history
);
setContentView
(
R
.
layout
.
activity_history
);
mPresenter
.
onAttach
(
this
);
ButterKnife
.
bind
(
this
);
ButterKnife
.
bind
(
this
);
mGame
=
getIntent
().
getParcelableExtra
(
USER_GAME_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
WorkAroundMapFragment
mapFragment
=
(
WorkAroundMapFragment
)
getSupportFragmentManager
()
WorkAroundMapFragment
mapFragment
=
(
WorkAroundMapFragment
)
getSupportFragmentManager
()
.
findFragmentById
(
R
.
id
.
map
);
.
findFragmentById
(
R
.
id
.
map
);
mapFragment
.
getMapAsync
(
this
);
mapFragment
.
getMapAsync
(
this
);
mPresenter
.
getStats
(
Integer
.
toString
(
mUser
.
getId
()),
Integer
.
toString
(
mGame
.
getGame
().
getId
()));
}
}
@Override
@Override
...
@@ -80,25 +111,6 @@ public class HistoryActivity extends BaseActivity
...
@@ -80,25 +111,6 @@ public class HistoryActivity extends BaseActivity
mScrollView
.
requestDisallowInterceptTouchEvent
(
true
);
mScrollView
.
requestDisallowInterceptTouchEvent
(
true
);
}
}
});
});
// a single polyline. Read the rest of the tutorial to learn more.
Polyline
polyline1
=
googleMap
.
addPolyline
(
new
PolylineOptions
()
.
add
(
new
LatLng
(-
35.016
,
143.321
),
new
LatLng
(-
34.747
,
145.592
),
new
LatLng
(-
34.364
,
147.891
),
new
LatLng
(-
33.501
,
150.217
),
new
LatLng
(-
32.306
,
149.248
),
new
LatLng
(-
32.491
,
147.309
)));
// Position the map's camera near Alice Springs in the center of Australia,
// and set the zoom factor so most of Australia shows on the screen.
polyline1
.
setEndCap
(
new
RoundCap
());
polyline1
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorAccent
));
polyline1
.
setJointType
(
JointType
.
ROUND
);
googleMap
.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
new
LatLng
(-
23.684
,
133.903
),
4
));
// Set listeners for click events.
googleMap
.
setOnPolylineClickListener
(
this
);
}
}
@Override
@Override
...
@@ -107,16 +119,6 @@ public class HistoryActivity extends BaseActivity
...
@@ -107,16 +119,6 @@ public class HistoryActivity extends BaseActivity
}
}
@Override
@Override
public
void
showLoading
()
{
}
@Override
public
void
hideLoading
()
{
}
@Override
public
void
openActivityOnTokenExpire
()
{
public
void
openActivityOnTokenExpire
()
{
}
}
...
@@ -128,7 +130,7 @@ public class HistoryActivity extends BaseActivity
...
@@ -128,7 +130,7 @@ public class HistoryActivity extends BaseActivity
@Override
@Override
public
void
onError
(
String
message
)
{
public
void
onError
(
String
message
)
{
Toast
.
makeText
(
this
,
message
,
Toast
.
LENGTH_LONG
).
show
();
}
}
@Override
@Override
...
@@ -143,6 +145,76 @@ public class HistoryActivity extends BaseActivity
...
@@ -143,6 +145,76 @@ public class HistoryActivity extends BaseActivity
@Override
@Override
public
void
loadStats
(
List
<
CheckIn
>
checkIns
)
{
public
void
loadStats
(
List
<
CheckIn
>
checkIns
)
{
if
(
checkIns
.
size
()
>
0
)
{
int
numbOfPoints
=
0
;
PolylineOptions
polylineOptions
=
new
PolylineOptions
();
int
lastPointId
=
-
1
;
for
(
CheckIn
c
:
checkIns
)
{
if
(
c
.
getCurrent_point
()
>
0
){
if
(
lastPointId
!=
c
.
getCurrent_point
()){
lastPointId
=
c
.
getCurrent_point
();
numbOfPoints
++;
}
}
polylineOptions
.
add
(
c
.
getLatLng
());
}
Polyline
polyline1
=
mMap
.
addPolyline
(
polylineOptions
);
polyline1
.
setEndCap
(
new
RoundCap
());
polyline1
.
setColor
(
getResources
().
getColor
(
R
.
color
.
colorAccent
));
polyline1
.
setJointType
(
JointType
.
ROUND
);
mMap
.
moveCamera
(
CameraUpdateFactory
.
newLatLngZoom
(
checkIns
.
get
(
0
).
getLatLng
(),
4
));
// Set listener for click events.
mMap
.
setOnPolylineClickListener
(
this
);
// DISTANCE
float
distance
=
0
;
if
(
checkIns
.
size
()
>
1
)
{
for
(
int
i
=
1
;
i
<
checkIns
.
size
();
i
++)
{
Location
loc1
=
new
Location
(
""
);
loc1
.
setLatitude
(
checkIns
.
get
(
i
-
1
).
getLat
());
loc1
.
setLongitude
(
checkIns
.
get
(
i
-
1
).
getLon
());
Location
loc2
=
new
Location
(
""
);
loc2
.
setLatitude
(
checkIns
.
get
(
i
).
getLat
());
loc2
.
setLongitude
(
checkIns
.
get
(
i
).
getLon
());
distance
+=
loc1
.
distanceTo
(
loc2
);
}
String
s
=
String
.
format
(
"%.0f meters"
,
distance
);
mDistance
.
setText
(
s
);
}
else
{
mDistance
.
setText
(
"0 meters"
);
}
// TIME TAKEN
long
duration
=
mGame
.
getEnd
().
getTime
()
-
mGame
.
getStart
().
getTime
();
// long diffInSeconds = TimeUnit.MILLISECONDS.toSeconds(duration);
float
diffInMinutes
=
TimeUnit
.
MILLISECONDS
.
toMinutes
(
duration
);
String
s
=
String
.
format
(
"%.0f minutes"
,
diffInMinutes
);
mTimeTaken
.
setText
(
s
);
// NUMBER OF POINTS
mNumbOfPoints
.
setText
(
Integer
.
toString
(
numbOfPoints
));
// AVERAGE SPEEDS
double
averageSpeed
=
(
distance
/
1000
)/(
diffInMinutes
/
60
);
s
=
String
.
format
(
"%.2f"
,
averageSpeed
);
mAverageSpeed
.
setText
(
s
+
" km / h"
);
averageSpeed
=
(
numbOfPoints
)/(
diffInMinutes
/
60
);
s
=
String
.
format
(
"%.2f"
,
averageSpeed
);
mAveragePointSpeed
.
setText
(
s
+
" point / h"
);
// START AND END TIME
SimpleDateFormat
dateFormatter
=
new
SimpleDateFormat
(
"E, d-M-y hh:mm"
,
Locale
.
US
);
mStart
.
setText
(
dateFormatter
.
format
(
mGame
.
getStart
()));
mEnd
.
setText
(
dateFormatter
.
format
(
mGame
.
getEnd
()));
hideLoading
();
}
}
}
}
}
app/src/main/java/ee/ttu/thesis/ui/start/StartActivity.java
View file @
df953f27
...
@@ -13,6 +13,8 @@ import android.support.v4.view.ViewPager;
...
@@ -13,6 +13,8 @@ import android.support.v4.view.ViewPager;
import
android.view.View
;
import
android.view.View
;
import
android.widget.Toast
;
import
android.widget.Toast
;
import
java.util.Date
;
import
javax.inject.Inject
;
import
javax.inject.Inject
;
import
butterknife.BindView
;
import
butterknife.BindView
;
...
@@ -20,11 +22,13 @@ import butterknife.ButterKnife;
...
@@ -20,11 +22,13 @@ import butterknife.ButterKnife;
import
butterknife.OnClick
;
import
butterknife.OnClick
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.R
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.User
;
import
ee.ttu.thesis.data.model.UserGame
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.base.BaseActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.ui.game.GameActivity
;
import
ee.ttu.thesis.data.model.Game
;
import
ee.ttu.thesis.data.model.Game
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_GAME_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
import
static
ee
.
ttu
.
thesis
.
ui
.
game
.
GameActivity
.
USER_KEY
;
/**
/**
...
@@ -36,6 +40,7 @@ public class StartActivity extends BaseActivity implements StartView {
...
@@ -36,6 +40,7 @@ public class StartActivity extends BaseActivity implements StartView {
StartTreasureHuntPresenter
<
StartView
>
mPresenter
;
StartTreasureHuntPresenter
<
StartView
>
mPresenter
;
Game
mGame
;
Game
mGame
;
UserGame
mUserGame
;
User
mUser
;
User
mUser
;
@BindView
(
R
.
id
.
activity_start_viewpager
)
@BindView
(
R
.
id
.
activity_start_viewpager
)
...
@@ -55,6 +60,7 @@ public class StartActivity extends BaseActivity implements StartView {
...
@@ -55,6 +60,7 @@ public class StartActivity extends BaseActivity implements StartView {
mPresenter
.
onAttach
(
this
);
mPresenter
.
onAttach
(
this
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mGame
=
getIntent
().
getParcelableExtra
(
GAME_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
mUser
=
getIntent
().
getParcelableExtra
(
USER_KEY
);
mUserGame
=
getIntent
().
getParcelableExtra
(
USER_GAME_KEY
);
mPagerAdapter
=
new
ScreenSlidePagerAdapter
(
getSupportFragmentManager
(),
this
);
mPagerAdapter
=
new
ScreenSlidePagerAdapter
(
getSupportFragmentManager
(),
this
);
mPager
.
setAdapter
(
mPagerAdapter
);
mPager
.
setAdapter
(
mPagerAdapter
);
mTabLayout
.
setupWithViewPager
(
mPager
,
true
);
mTabLayout
.
setupWithViewPager
(
mPager
,
true
);
...
@@ -62,6 +68,7 @@ public class StartActivity extends BaseActivity implements StartView {
...
@@ -62,6 +68,7 @@ public class StartActivity extends BaseActivity implements StartView {
@OnClick
(
R
.
id
.
activity_start_button
)
@OnClick
(
R
.
id
.
activity_start_button
)
public
void
onStartClicked
(
View
v
){
public
void
onStartClicked
(
View
v
){
mUserGame
.
setStart
(
new
Date
());
mPresenter
.
startGame
(
Integer
.
toString
(
mGame
.
getUserGameId
()));
mPresenter
.
startGame
(
Integer
.
toString
(
mGame
.
getUserGameId
()));
}
}
...
@@ -92,12 +99,13 @@ public class StartActivity extends BaseActivity implements StartView {
...
@@ -92,12 +99,13 @@ public class StartActivity extends BaseActivity implements StartView {
@Override
@Override
public
void
gameStarted
()
{
public
void
gameStarted
()
{
mPresenter
.
saveUserAndGame
(
mUser
.
getId
(),
mGame
.
getGameCode
());
Intent
intent
=
new
Intent
(
StartActivity
.
this
,
GameActivity
.
class
);
Intent
intent
=
new
Intent
(
StartActivity
.
this
,
GameActivity
.
class
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
GAME_KEY
,
mGame
);
intent
.
putExtra
(
USER_GAME_KEY
,
mUserGame
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
intent
.
putExtra
(
USER_KEY
,
mUser
);
startActivity
(
intent
);
startActivity
(
intent
);
finish
();
finish
();
}
}
private
class
ScreenSlidePagerAdapter
extends
FragmentStatePagerAdapter
{
private
class
ScreenSlidePagerAdapter
extends
FragmentStatePagerAdapter
{
...
@@ -122,7 +130,6 @@ public class StartActivity extends BaseActivity implements StartView {
...
@@ -122,7 +130,6 @@ public class StartActivity extends BaseActivity implements StartView {
fragment
=
new
TutorialThreeFragment
();
fragment
=
new
TutorialThreeFragment
();
}
else
if
(
position
==
3
)
{
}
else
if
(
position
==
3
)
{
fragment
=
new
TutorialFourFragment
();
fragment
=
new
TutorialFourFragment
();
}
else
{
}
else
{
fragment
=
new
TutorialFiveFragment
();
fragment
=
new
TutorialFiveFragment
();
...
...
app/src/main/java/ee/ttu/thesis/ui/start/StartPresenter.java
View file @
df953f27
...
@@ -41,4 +41,10 @@ public class StartPresenter<V extends StartView> extends BasePresenter<V> implem
...
@@ -41,4 +41,10 @@ public class StartPresenter<V extends StartView> extends BasePresenter<V> implem
}
}
}));
}));
}
}
@Override
public
void
saveUserAndGame
(
int
userId
,
String
gameCode
)
{
getDataManager
().
setCurrentUserId
(
userId
);
getDataManager
().
setCurrentGameCode
(
gameCode
);
}
}
}
app/src/main/java/ee/ttu/thesis/ui/start/StartTreasureHuntPresenter.java
View file @
df953f27
...
@@ -9,4 +9,6 @@ import ee.ttu.thesis.ui.base.TreauseHuntPresenter;
...
@@ -9,4 +9,6 @@ import ee.ttu.thesis.ui.base.TreauseHuntPresenter;
public
interface
StartTreasureHuntPresenter
<
V
extends
StartView
>
extends
TreauseHuntPresenter
<
V
>
{
public
interface
StartTreasureHuntPresenter
<
V
extends
StartView
>
extends
TreauseHuntPresenter
<
V
>
{
void
startGame
(
String
userGameId
);
void
startGame
(
String
userGameId
);
void
saveUserAndGame
(
int
userId
,
String
gameCode
);
}
}
\ No newline at end of file
app/src/main/res/drawable/gradient_rectangle_map_overlay.xml
View file @
df953f27
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
<shape
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:shape=
"rectangle"
>
android:shape=
"rectangle"
>
<gradient
<gradient
android:startColor=
"@color/colorPrimary"
android:startColor=
"@color/colorPrimary
Dark
"
android:endColor=
"@android:color/transparent"
android:endColor=
"@android:color/transparent"
android:angle=
"90"
android:angle=
"90"
android:type=
"linear"
android:type=
"linear"
...
...
app/src/main/res/layout/activity_history.xml
View file @
df953f27
...
@@ -3,12 +3,12 @@
...
@@ -3,12 +3,12 @@
android:id=
"@+id/activity_history_scrollview"
android:id=
"@+id/activity_history_scrollview"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/colorPrimary"
>
android:background=
"@color/colorPrimary
Dark
"
>
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/colorPrimary"
android:background=
"@color/colorPrimary
Dark
"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
<RelativeLayout
<RelativeLayout
...
@@ -40,31 +40,31 @@
...
@@ -40,31 +40,31 @@
android:orientation=
"vertical"
android:orientation=
"vertical"
android:padding=
"16dp"
>
android:padding=
"16dp"
>
<
LinearLayout
<
!--<LinearLayout-->
android:layout_width=
"match_parent"
<!--android:layout_width="match_parent"-->
android:layout_height=
"wrap_content"
<!--android:layout_height="wrap_content"-->
android:orientation=
"horizontal"
<!--android:orientation="horizontal"-->
android:paddingBottom=
"32dp"
>
<!--android:paddingBottom="32dp">--
>
<
TextView
<
!--<TextView-->
android:id=
"@+id/textView15"
<!--android:id="@+id/textView15"-->
android:layout_width=
"wrap_content"
<!--android:layout_width="wrap_content"-->
android:layout_height=
"wrap_content"
<!--android:layout_height="wrap_content"-->
android:paddingRight=
"16dp"
<!--android:paddingRight="16dp"-->
android:text=
"Rank:"
<!--android:text="Rank:"-->
android:textColor=
"@color/colorSecondaryMain"
<!--android:textColor="@color/colorSecondaryMain"-->
android:textSize=
"24sp"
/
>
<!--android:textSize="24sp" />--
>
<
TextView
<
!--<TextView-->
android:id=
"@+id/textView17"
<!--android:id="@+id/activity_history_rank"-->
android:layout_width=
"0px"
<!--android:layout_width="0px"-->
android:layout_height=
"wrap_content"
<!--android:layout_height="wrap_content"-->
android:layout_weight=
"1"
<!--android:layout_weight="1"-->
android:text=
"2nd"
<!--android:text="NULL"-->
android:textAlignment=
"textStart"
<!--android:textAlignment="textStart"-->
android:textColor=
"@color/white"
<!--android:textColor="@color/white"-->
android:textSize=
"24sp"
/
>
<!--android:textSize="24sp" />--
>
<
/LinearLayout
>
<
!--</LinearLayout>--
>
<LinearLayout
<LinearLayout
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
@@ -86,7 +86,7 @@
...
@@ -86,7 +86,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
12.4 km
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -108,11 +108,11 @@
...
@@ -108,11 +108,11 @@
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
<TextView
<TextView
android:id=
"@+id/
textView175
"
android:id=
"@+id/
activity_history_time_taken
"
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
147 minutes
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -138,7 +138,7 @@
...
@@ -138,7 +138,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
12
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -164,7 +164,7 @@
...
@@ -164,7 +164,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
6.27 km/h
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -190,7 +190,7 @@
...
@@ -190,7 +190,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
12 min/point
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -216,7 +216,7 @@
...
@@ -216,7 +216,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
DD/MM hh:mm
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
@@ -242,7 +242,7 @@
...
@@ -242,7 +242,7 @@
android:layout_width=
"0px"
android:layout_width=
"0px"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_weight=
"1"
android:layout_weight=
"1"
android:text=
"
DD/MM hh:mm
"
android:text=
"
NULL
"
android:textAlignment=
"textStart"
android:textAlignment=
"textStart"
android:textColor=
"@color/white"
android:textColor=
"@color/white"
android:textSize=
"24sp"
/>
android:textSize=
"24sp"
/>
...
...
app/src/main/res/layout/activity_main.xml
View file @
df953f27
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
<android.support.design.widget.CoordinatorLayout
xmlns:tools=
"http://schemas.android.com/tools"
android:id=
"@+id/main_content"
android:id=
"@+id/main_content"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
xmlns:app=
"http://schemas.android.com/apk/res-auto"
...
@@ -7,21 +7,6 @@
...
@@ -7,21 +7,6 @@
android:background=
"@color/colorPrimaryDark"
android:background=
"@color/colorPrimaryDark"
android:layout_height=
"match_parent"
>
android:layout_height=
"match_parent"
>
<!--<TextView-->
<!--android:id="@+id/activity_main_textview"-->
<!--android:text="text"-->
<!--android:layout_margin="20dp"-->
<!--android:textSize="24sp"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" />-->
<!--<Button-->
<!--android:id="@+id/button2"-->
<!--android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content"-->
<!--android:text="LogOut" />-->
<android.support.v7.widget.RecyclerView
<android.support.v7.widget.RecyclerView
android:id=
"@+id/activity_main_recyclerview"
android:id=
"@+id/activity_main_recyclerview"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
...
@@ -42,6 +27,7 @@
...
@@ -42,6 +27,7 @@
app:layout_behavior=
"ee.ttu.thesis.utils.ScrollAwareFABBehavior"
app:layout_behavior=
"ee.ttu.thesis.utils.ScrollAwareFABBehavior"
app:layout_anchor=
"@id/activity_main_recyclerview"
app:layout_anchor=
"@id/activity_main_recyclerview"
app:layout_anchorGravity=
"bottom|right|end"
app:layout_anchorGravity=
"bottom|right|end"
app:srcCompat=
"@drawable/ic_add_black_48dp"
/>
app:srcCompat=
"@drawable/ic_add_black_48dp"
tools:ignore=
"VectorDrawableCompat"
/>
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>
\ No newline at end of file
app/src/main/res/layout/dialog_info.xml
0 → 100644
View file @
df953f27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@color/colorPrimaryDark"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/dialog_info_textview"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:padding=
"16dp"
android:text=
"Welcome Back!"
android:textAlignment=
"center"
android:textColor=
"@color/white"
/>
<RelativeLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingBottom=
"8dp"
android:paddingRight=
"4dp"
android:paddingTop=
"8dp"
>
<Button
android:id=
"@+id/dialog_info_ok"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentEnd=
"true"
android:layout_alignParentStart=
"true"
android:layout_alignParentTop=
"true"
android:layout_marginLeft=
"4dp"
android:background=
"@android:color/transparent"
android:text=
"OK"
android:textColor=
"@color/colorAccent"
/>
</RelativeLayout>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/fragment_compass.xml
View file @
df953f27
...
@@ -61,7 +61,7 @@
...
@@ -61,7 +61,7 @@
android:textSize=
"14sp"
/>
android:textSize=
"14sp"
/>
<LinearLayout
<LinearLayout
android:id=
"@+id/fragment_compass_hint_root"
android:id=
"@+id/fragment_compass_hint_roo
rere
t"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
...
@@ -71,7 +71,7 @@
...
@@ -71,7 +71,7 @@
</LinearLayout>
</LinearLayout>
<LinearLayout
<LinearLayout
android:id=
"@+id/fragment_compass_compass_root"
android:id=
"@+id/fragment_compass_compass_r
dsadsa
oot"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
>
android:orientation=
"vertical"
>
...
...
app/src/main/res/layout/item_game_button.xml
0 → 100644
View file @
df953f27
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_gravity=
"bottom|center_horizontal"
android:layout_marginTop=
"64dp"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/logout"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_alignParentBottom=
"true"
android:layout_alignParentEnd=
"true"
android:layout_gravity=
"bottom|center_horizontal"
android:layout_margin=
"4dp"
android:layout_marginBottom=
"8dp"
android:layout_marginEnd=
"8dp"
android:layout_marginLeft=
"8dp"
android:layout_marginRight=
"8dp"
android:layout_marginStart=
"8dp"
android:layout_marginTop=
"8dp"
android:background=
"@drawable/login_rounded_rectangle_filled"
android:elevation=
"8dp"
android:paddingBottom=
"8dp"
android:paddingEnd=
"32dp"
android:paddingLeft=
"32dp"
android:paddingRight=
"32dp"
android:paddingStart=
"32dp"
android:paddingTop=
"8dp"
android:text=
"LOGOUT"
android:textAlignment=
"center"
android:textColor=
"@color/white"
android:textSize=
"18sp"
/>
'
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/layout_compass.xml
View file @
df953f27
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<ee.ttu.thesis.ui.game.point.CompassView
xmlns:android=
"http://schemas.android.com/apk/res/android"
<LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/compassView"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"400dp"
android:layout_height=
"wrap_content"
android:padding=
"16dp"
/>
android:orientation=
"vertical"
>
\ No newline at end of file
<ee.ttu.thesis.ui.game.point.CompassView
android:id=
"@+id/compassView"
android:layout_width=
"match_parent"
android:layout_height=
"500dp"
android:padding=
"16dp"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/layout/layout_distance.xml
View file @
df953f27
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<
TextView
xmlns:android=
"http://schemas.android.com/apk/res/android"
<
LinearLayout
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/fragment_compass_distance"
android:id=
"@+id/fragment_compass_distance
_ll
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:paddingBottom=
"32dp"
android:orientation=
"vertical"
>
android:paddingLeft=
"32dp"
android:paddingRight=
"32dp"
<TextView
android:paddingTop=
"24dp"
android:id=
"@+id/fragment_compass_distance"
android:textAlignment=
"center"
android:layout_width=
"match_parent"
android:textColor=
"@color/colorSecondaryMain"
android:layout_height=
"wrap_content"
android:textSize=
"24sp"
/>
android:paddingBottom=
"8dp"
android:paddingLeft=
"16dp"
android:paddingRight=
"16dp"
android:paddingTop=
"24dp"
android:textAlignment=
"center"
android:textColor=
"@color/colorSecondaryMain"
android:textSize=
"24sp"
/>
<TextView
xmlns:android=
"http://schemas.android.com/apk/res/android"
android:id=
"@+id/fragment_compass_distance_accuracy"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:paddingBottom=
"32dp"
android:paddingLeft=
"32dp"
android:paddingRight=
"32dp"
android:textAlignment=
"center"
android:textColor=
"@color/colorSecondaryMain"
android:textSize=
"14sp"
/>
</LinearLayout>
\ No newline at end of file
app/src/main/res/values/colors.xml
View file @
df953f27
...
@@ -38,4 +38,7 @@
...
@@ -38,4 +38,7 @@
<color
name=
"OrderSelectedTabTextColor"
>
@color/colorAccent
</color>
<color
name=
"OrderSelectedTabTextColor"
>
@color/colorAccent
</color>
<color
name=
"OrderUnSelectedTabTextColor"
>
@color/colorPrimary
</color>
<color
name=
"OrderUnSelectedTabTextColor"
>
@color/colorPrimary
</color>
<color
name=
"mapBoundFillColor"
>
#642d303c
</color>
</resources>
</resources>
app/src/main/res/values/strings.xml
View file @
df953f27
...
@@ -20,4 +20,8 @@
...
@@ -20,4 +20,8 @@
<string
name=
"api_default_error"
>
Something went wrong
</string>
<string
name=
"api_default_error"
>
Something went wrong
</string>
<string
name=
"connection_error"
>
Internet connection lost
</string>
<string
name=
"connection_error"
>
Internet connection lost
</string>
<string
name=
"api_retry_error"
>
Try again
</string>
<string
name=
"api_retry_error"
>
Try again
</string>
<string
name=
"facebook_app_id"
>
122204701691617
</string>
<string
name=
"fb_login_protocol_scheme"
>
fb122204701691617
</string>
</resources>
</resources>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment