Compare commits
539 Commits
background
...
master
Author | SHA1 | Date | |
---|---|---|---|
faed9e05b7 | |||
1095386659 | |||
b7e1e4a984 | |||
4473834218 | |||
5a96d93d37 | |||
33cfa90a28 | |||
6fa458d198 | |||
2ca95e0ba0 | |||
eb30100183 | |||
e1c266263a | |||
d88525a764 | |||
430914bab1 | |||
786a73c963 | |||
1f2867cb43 | |||
5770217c45 | |||
17b7f4c9a2 | |||
f46d9cc60e | |||
325f8a99a2 | |||
0ec0e95798 | |||
085dc1e4d6 | |||
9f78eaf688 | |||
b528ec68bb | |||
7b79a5339a | |||
6e98eeff16 | |||
5fccb72843 | |||
377ee3bcbc | |||
282f74f5e0 | |||
b126cbfe31 | |||
fae7a5f0fe | |||
e64f5d380c | |||
2f25f06d18 | |||
a27c18b468 | |||
311cd7868b | |||
be58fba3ad | |||
2f93dc5d54 | |||
c8cdc3aac0 | |||
f872b08acc | |||
97bb141a81 | |||
a98b188978 | |||
20f585509c | |||
ad83c5ed88 | |||
623957bcb2 | |||
ec68ae14ef | |||
393f25b1f9 | |||
3379faf59b | |||
1f888ad1f2 | |||
ebe2266036 | |||
f36a811d03 | |||
ffff380560 | |||
6d73598d5e | |||
f98e4289fb | |||
d583c807d5 | |||
86b6a1a86f | |||
4300c33d65 | |||
b7b284252b | |||
5dcaca9dd2 | |||
c55578c8ae | |||
59cb517ac7 | |||
ae3c355259 | |||
022669c6ee | |||
9c03d84b0a | |||
b978ee560c | |||
c188ce38a8 | |||
f02afb5e56 | |||
59c28e35d8 | |||
76d008e098 | |||
d87a08a9e8 | |||
a98ec8de47 | |||
d0b714731b | |||
aaca6c008e | |||
413fc7d49a | |||
cf016bc6f4 | |||
d78ae83877 | |||
6bd109e1cc | |||
1ba6cdf6f0 | |||
7a41dcbb1f | |||
4bb9452cbc | |||
701ee6e9d5 | |||
8da6ca8c0d | |||
654bcb3653 | |||
3e7e77a430 | |||
2d93b23197 | |||
66fa45baa0 | |||
065fff7867 | |||
51dcefcc62 | |||
489901dca1 | |||
a4c0881300 | |||
8ab7e526e6 | |||
bca6885591 | |||
e2f15ea772 | |||
fac7ae0fdf | |||
7e043c9826 | |||
e9f71d5790 | |||
3b4bb9cbae | |||
72eea53a8c | |||
9a96f474d9 | |||
5c5b9c745e | |||
e4b0bb1f3d | |||
331e7b5fe3 | |||
9525d47600 | |||
1f5ac834e5 | |||
25e8d42ee0 | |||
eb4147557b | |||
3f0ccda50b | |||
da018120f1 | |||
dfc30c3790 | |||
46cdaa8ef9 | |||
cb1e7bcdef | |||
5db5d2f8e0 | |||
ec29191342 | |||
42f501f8e2 | |||
35ef25b2b7 | |||
9e32a909d9 | |||
bc6e5179c7 | |||
8a88629b9a | |||
87e0be8e79 | |||
39d2d78ad8 | |||
ed2ec41d8d | |||
4fceb4195f | |||
8e610c52ca | |||
7d1460353d | |||
f9226262ed | |||
cff66ef70d | |||
a0934638b3 | |||
0147a83034 | |||
81af3360f7 | |||
7d74d46d27 | |||
2338e484f8 | |||
1eed752b1a | |||
6902a62d07 | |||
af1e1a53b4 | |||
3a6f20d12e | |||
d9ada9319b | |||
a908623064 | |||
8e94d86968 | |||
77d15a734e | |||
b81e28cd61 | |||
4d921f7321 | |||
8bcecbbed5 | |||
88d016779f | |||
ea0d6e1e96 | |||
88f263217a | |||
a4fd031a36 | |||
94368b05d1 | |||
6bdf402df8 | |||
|
b323939067 | ||
b366c0a17c | |||
44e392c027 | |||
be7a0cec0a | |||
9059cbd01d | |||
96e31166c6 | |||
aec9eaae19 | |||
fce812f3ce | |||
c8e68e3bb6 | |||
150caf187d | |||
1a5c85c213 | |||
0bf3d147f0 | |||
540536a4a8 | |||
4fd2795377 | |||
9dd2a62d43 | |||
598e603dfb | |||
18547a3c52 | |||
7f169e5b61 | |||
87642c5d7a | |||
84e6b95675 | |||
2178b4d61d | |||
|
552badf5a9 | ||
ee815260a4 | |||
69c42b323d | |||
381f7b0033 | |||
956cd83f9b | |||
8d7ba2e947 | |||
fa0b69920f | |||
6334706165 | |||
3eb8c922c9 | |||
ac3e8310d1 | |||
6030ec6d84 | |||
d80b83f2b5 | |||
7ac5ac2d6f | |||
bf6c8c3f51 | |||
41c5dcebfd | |||
|
020ec1d41e | ||
8fdcdf4f80 | |||
9255da3969 | |||
303841c14e | |||
4d33a07a30 | |||
1eeaee7da1 | |||
60c7283ba1 | |||
cae8a22c25 | |||
ce14928bc6 | |||
4bdebcf52d | |||
48ce4c76c8 | |||
6b1537cd77 | |||
5bf380b666 | |||
2d9c8aa6cc | |||
00ea68379b | |||
3ddcccb176 | |||
c1bf626bbc | |||
fe0115122d | |||
4fc348af56 | |||
5f48949014 | |||
df1b380152 | |||
9d82261be9 | |||
c1e20934e4 | |||
e7a2ecf86a | |||
a0f78aef2d | |||
962a222fa8 | |||
9f0ef0590d | |||
264f752b20 | |||
7f16515074 | |||
80b0948033 | |||
e2a6bfd56c | |||
f7edee0c56 | |||
6498f2e58d | |||
b0ccb9cf4f | |||
dee33a2ec3 | |||
c8145323c5 | |||
f37fe44f2e | |||
672a6bee06 | |||
41288f000b | |||
90aa21be1d | |||
39da105bc8 | |||
baa8cac0e4 | |||
3139d41ba4 | |||
7dd3e0cc00 | |||
0884fc4873 | |||
e775961ed2 | |||
|
a3a847fdeb | ||
|
f568cea711 | ||
2f4f3c13b6 | |||
8e5b33793d | |||
355d800909 | |||
f15e86cb21 | |||
afd3463bec | |||
|
0c1bfb46c2 | ||
|
2147f533be | ||
|
2332823ba8 | ||
9ffa64e793 | |||
5f8e03986a | |||
e34642fd6e | |||
caa60e6f25 | |||
2dda6ef65f | |||
041375b53f | |||
1803ac13b6 | |||
f757f36312 | |||
ba73d08cd4 | |||
|
9aa9e8e0df | ||
03c5a9a3ce | |||
b0927c174a | |||
a6d4ef55d2 | |||
|
3f725cd3b3 | ||
023926e36c | |||
844d636d6e | |||
f4a0c71a18 | |||
930876a2f5 | |||
4c2f706422 | |||
764518d49c | |||
5ffdf75b66 | |||
385df14b2f | |||
fc428451a9 | |||
5fe12a3f4b | |||
|
3344449bf4 | ||
1abae28ae9 | |||
3a38c1052d | |||
c8e49af5da | |||
e5f7a81c9a | |||
80cd393cc9 | |||
fd49c66ee1 | |||
77ddbc39a5 | |||
527701420b | |||
|
f177b80fa4 | ||
f8abf61553 | |||
5a8ec2d9fc | |||
a9469cce76 | |||
26e12d68f3 | |||
d735950e7a | |||
ca91124b8f | |||
8f6a07acea | |||
8a44eaa8d0 | |||
c96e19cb2d | |||
367bc7518e | |||
0182d2e041 | |||
d9909a66bd | |||
0cec17dd16 | |||
8be7d3aa11 | |||
b4dd785504 | |||
57702fd3a1 | |||
381373b4b7 | |||
45dac22ec4 | |||
0dd0b0dc23 | |||
d1adf451a0 | |||
261002d131 | |||
899fb9958b | |||
ce3d261c48 | |||
7fb1d90ab7 | |||
e095e9069f | |||
f0f1e59947 | |||
118296aa03 | |||
9c9402c8c1 | |||
2ca64a66ba | |||
3eed883079 | |||
fc4f49c3e0 | |||
b2e5a0e0c5 | |||
5e51be5d0b | |||
5fc5140866 | |||
76c3ba5054 | |||
15529eccb4 | |||
7174d7d117 | |||
|
e3e88d168f | ||
6115958efb | |||
|
f3f2f3b90a | ||
ee6d11fe44 | |||
7c1b9e4494 | |||
957cee1b23 | |||
eb1ab75d6d | |||
c05d03a4d0 | |||
a7ba5bf27c | |||
a52e5dd89b | |||
79d48bb269 | |||
f6cfb7f352 | |||
1e07168725 | |||
d7bc56f5f9 | |||
72f2ac798a | |||
c452e5dbf5 | |||
ab74f0b7e1 | |||
|
66dba76ed4 | ||
8fbce4d9d3 | |||
|
e96981c8b9 | ||
519115ed5e | |||
|
c43aabf739 | ||
6dbe50761a | |||
2b19229552 | |||
abbd887db7 | |||
6684274488 | |||
50ef5b1e8b | |||
bbc7803177 | |||
3177b43f26 | |||
012f2af3f2 | |||
db3ac7378c | |||
789a2dbaf1 | |||
ba67a8b088 | |||
52ff05767e | |||
|
64082727b2 | ||
|
9b291117ef | ||
493395d36a | |||
3a2c4f10d4 | |||
b14052eb21 | |||
854ddadeea | |||
35ba11129c | |||
|
ffff4bb7c0 | ||
|
da944c37d5 | ||
f0df7b7440 | |||
aef7174d90 | |||
422b1079da | |||
73fc5f9b0b | |||
554c2f7bfa | |||
|
ac27fc3f34 | ||
fca6cd936c | |||
|
4eb721fb1a | ||
be6a487a92 | |||
2b4e2d3b99 | |||
f4ea4a4378 | |||
b75e3e5ae3 | |||
18841ab372 | |||
fce151be6f | |||
6fb4b655d8 | |||
b8eedc565c | |||
f2357c846e | |||
8c9eb2c706 | |||
662b8c29c4 | |||
955f823b25 | |||
|
ffcc68c107 | ||
|
549c2f6484 | ||
|
66de4ffa1d | ||
|
86cafe1d5a | ||
18900340ee | |||
688341e072 | |||
8a29b93533 | |||
|
70001e36c3 | ||
5e1e3b5bce | |||
157855d911 | |||
b02ec917ed | |||
d62c451adb | |||
892216cc0c | |||
50a427313f | |||
|
e1496ce65c | ||
d5114a8587 | |||
aa3c2eb9b8 | |||
1acac4edc4 | |||
b0e81d474e | |||
e0973ca732 | |||
5dad15f135 | |||
e664e00212 | |||
|
49f47986f0 | ||
|
bb4831ec89 | ||
|
c04373a59c | ||
0aa87c44fa | |||
|
fd9cb37fb3 | ||
|
8669e040b5 | ||
|
f89971d059 | ||
5d3ba7e1a1 | |||
|
8083b67fc4 | ||
|
bca8cb782b | ||
|
c9b4548f45 | ||
|
1323c02b30 | ||
|
9f23aae620 | ||
|
35311af645 | ||
e34ccbb6d8 | |||
d1a249e5cf | |||
|
b64280bf3f | ||
77b7c50e4e | |||
64b24cef1b | |||
647b030b81 | |||
98cc5bcc20 | |||
511d1a8fef | |||
505e890f8b | |||
|
5d595c4c65 | ||
|
295be86eee | ||
|
9cd0f053e3 | ||
|
5f65d8e6fb | ||
1094ef942b | |||
c62b901c10 | |||
b23d82d74d | |||
ba4e097f86 | |||
|
5757a58edf | ||
583305ff31 | |||
03235ce18b | |||
03c38a8f23 | |||
|
8ca2f7dc31 | ||
|
90074affb1 | ||
98ee8d1a21 | |||
|
61f94c7beb | ||
|
2b53506651 | ||
|
1e40b77205 | ||
|
40101ef7d0 | ||
|
cad9f466c2 | ||
7189193dac | |||
64256d2d67 | |||
8553b934a6 | |||
2c61d22db7 | |||
afbf736e63 | |||
d2b5fbf35d | |||
d8cf220293 | |||
|
8a0ccfa60a | ||
|
f57141d0f2 | ||
05e4de95c2 | |||
78957bb62b | |||
bf694594e4 | |||
484f1a2114 | |||
e4b33da25b | |||
44b84fef0e | |||
aa3dbfb185 | |||
b21aff1ef0 | |||
ca24cc5437 | |||
b1dfb6611d | |||
27c92af38d | |||
7019864b9a | |||
45c78e64c0 | |||
5fa0fbe38e | |||
eff4802c9d | |||
|
340e41bc01 | ||
|
d023f0aea5 | ||
|
d090893044 | ||
7191fcf6e7 | |||
|
1ae9217819 | ||
|
fe13bee1f5 | ||
|
c67d4ba4c8 | ||
d6710a5406 | |||
ca26b03d49 | |||
|
2d9e041b6b | ||
|
b7b7f8a6a1 | ||
|
2a79537fbe | ||
|
9a2054deb2 | ||
f5edf67c15 | |||
|
9aca72bdfe | ||
d879258266 | |||
b0cfda8548 | |||
|
d2405d36f6 | ||
|
2c81359665 | ||
d4aa5b5261 | |||
4701387d48 | |||
299e25d0f9 | |||
edd5fb76a3 | |||
b87646088c | |||
1e281b3ea5 | |||
49199ccc44 | |||
|
b1af9f6798 | ||
c7231bc70a | |||
31f7408ea6 | |||
aa6810a633 | |||
|
5dab4eaf4b | ||
d60a3c413c | |||
091b714b18 | |||
1d677ac7e1 | |||
95978dad72 | |||
2b4b83a0d2 | |||
2568b03197 | |||
61e5faa81b | |||
9162c7fd34 | |||
dc0af04e5d | |||
f60bac1c3c | |||
bd775d5d0d | |||
10c3397949 | |||
e9c4aef12c | |||
3584b1ce1e | |||
82f0ecd2b0 | |||
19ba07beba | |||
5511e5b40e | |||
1de4b0a2ab | |||
fa519cf312 | |||
5cabcde90b | |||
c765ac0782 | |||
d35262843a | |||
2948ff7db9 | |||
2ebbe42d50 | |||
850d588744 | |||
|
b87f859d75 | ||
|
a98a500f08 | ||
c78757da65 | |||
ebb228fdec | |||
fcff6463bf | |||
ae5c8d91e2 | |||
6d6db2efe0 | |||
92c1892501 | |||
997765ddb5 | |||
89ef83033b | |||
64c594174a | |||
4bbd4f65db | |||
d294f97a49 | |||
883b2ef7db | |||
02db1722a2 | |||
45cc04a072 | |||
170050406c | |||
9ca1617e29 | |||
|
355c78de5d | ||
ad58983d32 | |||
2f802ad64f | |||
|
7072ecfe59 | ||
6bfdc768a3 |
4
.gitignore
vendored
@ -1,6 +1,5 @@
|
||||
# Built application files
|
||||
*.apk
|
||||
*.ap_
|
||||
|
||||
|
||||
# Files for the ART/Dalvik VM
|
||||
*.dex
|
||||
@ -65,3 +64,4 @@ fastlane/Preview.html
|
||||
fastlane/screenshots
|
||||
fastlane/test_output
|
||||
fastlane/readme.md
|
||||
app/src/main/res/.DS_Store
|
||||
|
@ -5,22 +5,26 @@
|
||||
<option name="myDefaultNotNull" value="android.support.annotation.NonNull" />
|
||||
<option name="myNullables">
|
||||
<value>
|
||||
<list size="5">
|
||||
<list size="7">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.Nullable" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nullable" />
|
||||
<item index="2" class="java.lang.String" itemvalue="javax.annotation.CheckForNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.Nullable" />
|
||||
<item index="4" class="java.lang.String" itemvalue="android.support.annotation.Nullable" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.Nullable" />
|
||||
<item index="6" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNullable" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
<option name="myNotNulls">
|
||||
<value>
|
||||
<list size="4">
|
||||
<list size="6">
|
||||
<item index="0" class="java.lang.String" itemvalue="org.jetbrains.annotations.NotNull" />
|
||||
<item index="1" class="java.lang.String" itemvalue="javax.annotation.Nonnull" />
|
||||
<item index="2" class="java.lang.String" itemvalue="edu.umd.cs.findbugs.annotations.NonNull" />
|
||||
<item index="3" class="java.lang.String" itemvalue="android.support.annotation.NonNull" />
|
||||
<item index="4" class="java.lang.String" itemvalue="androidx.annotation.NonNull" />
|
||||
<item index="5" class="java.lang.String" itemvalue="androidx.annotation.RecentlyNonNull" />
|
||||
</list>
|
||||
</value>
|
||||
</option>
|
||||
|
17
.project
Normal file
@ -0,0 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>FindMyTutorAndroid</name>
|
||||
<comment>Project FindMyTutorAndroid created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
2
.settings/org.eclipse.buildship.core.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
connection.project.dir=
|
||||
eclipse.preferences.version=1
|
6
app/.classpath
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||
<classpathentry kind="output" path="bin/default"/>
|
||||
</classpath>
|
23
app/.project
Normal file
@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>app</name>
|
||||
<comment>Project app created by Buildship.</comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
2
app/.settings/org.eclipse.buildship.core.prefs
Normal file
@ -0,0 +1,2 @@
|
||||
connection.project.dir=..
|
||||
eclipse.preferences.version=1
|
@ -8,11 +8,13 @@ android {
|
||||
}
|
||||
defaultConfig {
|
||||
applicationId "com.uam.wmi.findmytutor"
|
||||
minSdkVersion 23
|
||||
minSdkVersion 22
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode 66
|
||||
versionName "1.0.0"
|
||||
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables.useSupportLibrary = true
|
||||
resConfigs "en", "pl"
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
@ -22,10 +24,26 @@ android {
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
maven {
|
||||
url 'http://dl.bintray.com/amulyakhare/maven'
|
||||
}
|
||||
}
|
||||
def acraVersion = '5.2.1'
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation "ch.acra:acra-http:$acraVersion"
|
||||
implementation "ch.acra:acra-toast:$acraVersion"
|
||||
implementation "ch.acra:acra-notification:$acraVersion"
|
||||
implementation "ch.acra:acra-limiter:$acraVersion"
|
||||
|
||||
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'com.android.support:preference-v7:27.1.1'
|
||||
implementation 'com.android.support:cardview-v7:27.1.1'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
implementation 'com.android.support:support-v4:27.1.1'
|
||||
implementation 'com.android.support:support-vector-drawable:27.1.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
@ -33,18 +51,30 @@ dependencies {
|
||||
implementation 'com.google.code.gson:gson:2.8.5'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.4.0'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.4.0'
|
||||
implementation "io.swagger:swagger-annotations:1.5.15"
|
||||
implementation "org.threeten:threetenbp:1.3.5"
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.4.0'
|
||||
implementation 'io.swagger:swagger-annotations:1.5.15'
|
||||
implementation 'org.threeten:threetenbp:1.3.5'
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-android-sdk:6.7.2'
|
||||
implementation 'com.mapbox.mapboxsdk:mapbox-sdk-turf:4.0.0'
|
||||
implementation 'io.reactivex.rxjava2:rxjava:2.2.0'
|
||||
implementation 'com.android.support:recyclerview-v7:27.1.1'
|
||||
implementation 'io.reactivex.rxjava2:rxandroid:2.1.0'
|
||||
implementation "com.jakewharton:butterknife:8.8.1"
|
||||
implementation 'com.jakewharton:butterknife:8.8.1'
|
||||
annotationProcessor "com.jakewharton:butterknife-compiler:8.8.1"
|
||||
implementation "com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0"
|
||||
implementation "com.squareup.okhttp3:okhttp:3.11.0"
|
||||
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
|
||||
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
|
||||
implementation 'com.jakewharton.retrofit:retrofit2-rxjava2-adapter:1.0.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:3.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp-urlconnection:3.10.0'
|
||||
implementation 'com.squareup.okhttp3:logging-interceptor:3.11.0'
|
||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
||||
implementation 'com.auth0.android:jwtdecode:1.1.1'
|
||||
implementation 'com.annimon:stream:1.2.1'
|
||||
implementation 'com.google.android.gms:play-services-location:16.0.0'
|
||||
// FloatingBarMenu
|
||||
implementation 'com.getbase:floatingactionbutton:1.10.1'
|
||||
implementation 'org.apache.commons:commons-collections4:4.0'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
|
||||
// spinner loaders library
|
||||
implementation 'com.github.ybq:Android-SpinKit:1.2.0'
|
||||
// rx binding
|
||||
implementation 'com.jakewharton.rxbinding:rxbinding:0.3.0'
|
||||
}
|
||||
|
BIN
app/release/release/app.aab
Normal file
BIN
app/release/release/fmtBeta0.9.5v18.aab
Normal file
@ -4,69 +4,80 @@
|
||||
package="com.uam.wmi.findmytutor">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
|
||||
<uses-feature
|
||||
android:name="android.hardware.location"
|
||||
android:required="true" />
|
||||
<uses-feature
|
||||
android:name="android.hardware.location.gps"
|
||||
android:required="true" />
|
||||
<uses-permission android:name="android.permission.ACCESS_COARSE_UPDATES" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
|
||||
<uses-feature android:name="android.hardware.location.gps" />
|
||||
|
||||
<application
|
||||
android:name=".FindMyTutor"
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
|
||||
<receiver android:name=".utils.BroadcastLocalizationHandler"
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
>
|
||||
<intent-filter>
|
||||
<action android:name="background.location.broadcast">
|
||||
</action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".activity.StartupActivity"
|
||||
android:label="@string/title_activity_startup"
|
||||
android:launchMode="singleInstance">
|
||||
android:configChanges="locale"
|
||||
tools:ignore="AllowBackup,GoogleAppIndexingWarning">
|
||||
<activity
|
||||
android:name=".activity.StartupActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:launchMode="singleInstance"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name=".activity.MainActivity"
|
||||
android:label="@string/title_activity_main"
|
||||
android:launchMode="singleTop">
|
||||
</activity>
|
||||
|
||||
android:name=".activity.MapActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:launchMode="singleTop"
|
||||
android:screenOrientation="portrait"
|
||||
android:windowSoftInputMode="adjustPan" />
|
||||
<activity
|
||||
android:name=".activity.LoginActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:excludeFromRecents="true"
|
||||
android:launchMode="singleTask"
|
||||
android:label="@string/title_activity_login"
|
||||
android:noHistory="true">
|
||||
</activity>
|
||||
android:noHistory="true"
|
||||
android:screenOrientation="portrait" />
|
||||
<activity
|
||||
android:name=".activity.SettingsActivity"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="portrait" />
|
||||
|
||||
<service
|
||||
android:name=".service.BackgroundLocalizationService"
|
||||
android:launchMode="singleTop"
|
||||
android:enabled="true"
|
||||
android:exported="false"
|
||||
/>
|
||||
android:launchMode="singleTop" />
|
||||
|
||||
<activity
|
||||
android:name=".activity.TutorTab"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:windowSoftInputMode="stateHidden|adjustPan"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme" />
|
||||
<activity
|
||||
android:name=".activity.WhiteList"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme" />
|
||||
<activity
|
||||
android:name=".activity.BlackList"
|
||||
android:configChanges="keyboardHidden|orientation|screenSize"
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/AppTheme" />
|
||||
|
||||
</application>
|
||||
|
||||
|
398
app/src/main/assets/building.geojson
Normal file
@ -0,0 +1,398 @@
|
||||
{
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło B",
|
||||
"longitude" : 52.466669,
|
||||
"latitude" : 16.926624
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
],
|
||||
[
|
||||
16.926435,
|
||||
52.466201
|
||||
],
|
||||
[
|
||||
16.92646,
|
||||
52.466255
|
||||
],
|
||||
[
|
||||
16.926516,
|
||||
52.466244
|
||||
],
|
||||
[
|
||||
16.926999,
|
||||
52.46711
|
||||
],
|
||||
[
|
||||
16.926796,
|
||||
52.467145
|
||||
],
|
||||
[
|
||||
16.926782,
|
||||
52.467117
|
||||
],
|
||||
[
|
||||
16.926784,
|
||||
52.467121
|
||||
],
|
||||
[
|
||||
16.926691,
|
||||
52.467139
|
||||
],
|
||||
[
|
||||
16.926662,
|
||||
52.46709
|
||||
],
|
||||
[
|
||||
16.926757,
|
||||
52.467072
|
||||
],
|
||||
[
|
||||
16.926544,
|
||||
52.466691
|
||||
],
|
||||
[
|
||||
16.926434,
|
||||
52.46671
|
||||
],
|
||||
[
|
||||
16.926396,
|
||||
52.466655
|
||||
],
|
||||
[
|
||||
16.926519,
|
||||
52.466628
|
||||
],
|
||||
[
|
||||
16.926323,
|
||||
52.466281
|
||||
],
|
||||
[
|
||||
16.926213,
|
||||
52.466307
|
||||
],
|
||||
[
|
||||
16.92618,
|
||||
52.466248
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "41798cf663bc55c10e6c51c3fe174eda"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Biblioteka",
|
||||
"longitude" : 52.467351,
|
||||
"latitude" : 16.926900
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
],
|
||||
[
|
||||
16.926627,
|
||||
52.467295
|
||||
],
|
||||
[
|
||||
16.926732,
|
||||
52.467482
|
||||
],
|
||||
[
|
||||
16.926876,
|
||||
52.467461
|
||||
],
|
||||
[
|
||||
16.926967,
|
||||
52.467428
|
||||
],
|
||||
[
|
||||
16.927014,
|
||||
52.467402
|
||||
],
|
||||
[
|
||||
16.927171,
|
||||
52.467359
|
||||
],
|
||||
[
|
||||
16.9271,
|
||||
52.467202
|
||||
],
|
||||
[
|
||||
16.927048,
|
||||
52.46721
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "7328c3c9dffd3e76be8d3dcef4f58ddc"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Łącznik",
|
||||
"longitude" : 52.466619,
|
||||
"latitude" : 16.926860
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
],
|
||||
[
|
||||
16.927088,
|
||||
52.46661
|
||||
],
|
||||
[
|
||||
16.927019,
|
||||
52.466502
|
||||
],
|
||||
[
|
||||
16.9267,
|
||||
52.466571
|
||||
],
|
||||
[
|
||||
16.926759,
|
||||
52.466683
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "8c19ee28e4c07ece9756fd21f290713b"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło A",
|
||||
"longitude" : 52.466559,
|
||||
"latitude" : 16.927163
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
],
|
||||
[
|
||||
16.926898,
|
||||
52.466079
|
||||
],
|
||||
[
|
||||
16.926926,
|
||||
52.466126
|
||||
],
|
||||
[
|
||||
16.927026,
|
||||
52.466107
|
||||
],
|
||||
[
|
||||
16.92723,
|
||||
52.466473
|
||||
],
|
||||
[
|
||||
16.927184,
|
||||
52.466483
|
||||
],
|
||||
[
|
||||
16.927243,
|
||||
52.466586
|
||||
],
|
||||
[
|
||||
16.927334,
|
||||
52.46656
|
||||
],
|
||||
[
|
||||
16.927602,
|
||||
52.466889
|
||||
],
|
||||
[
|
||||
16.927275,
|
||||
52.466959
|
||||
],
|
||||
[
|
||||
16.926771,
|
||||
52.466106
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c33bfba772c85cc38ae417843d31b1ff"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Aule",
|
||||
"longitude" : 52.467114,
|
||||
"latitude" : 16.927621
|
||||
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.46718
|
||||
],
|
||||
[
|
||||
16.927348,
|
||||
52.467199
|
||||
],
|
||||
[
|
||||
16.927393,
|
||||
52.467224
|
||||
],
|
||||
[
|
||||
16.927426,
|
||||
52.467239
|
||||
],
|
||||
[
|
||||
16.927476,
|
||||
52.467258
|
||||
],
|
||||
[
|
||||
16.92755,
|
||||
52.467264
|
||||
],
|
||||
[
|
||||
16.927625,
|
||||
52.467263
|
||||
],
|
||||
[
|
||||
16.927699,
|
||||
52.467246
|
||||
],
|
||||
[
|
||||
16.92776,
|
||||
52.467212
|
||||
],
|
||||
[
|
||||
16.927821,
|
||||
52.467158
|
||||
],
|
||||
[
|
||||
16.927838,
|
||||
52.467099
|
||||
],
|
||||
[
|
||||
16.927827,
|
||||
52.467059
|
||||
],
|
||||
[
|
||||
16.927793,
|
||||
52.467012
|
||||
],
|
||||
[
|
||||
16.927738,
|
||||
52.466976
|
||||
],
|
||||
[
|
||||
16.927661,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927581,
|
||||
52.466939
|
||||
],
|
||||
[
|
||||
16.927534,
|
||||
52.466938
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466949
|
||||
],
|
||||
[
|
||||
16.927387,
|
||||
52.467047
|
||||
],
|
||||
[
|
||||
16.927315,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.92731,
|
||||
52.467158
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c779419e3fd7faef8555e1099547a82c"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Hol",
|
||||
"longitude" : 52.4671021,
|
||||
"latitude" : 16.927122
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
],
|
||||
[
|
||||
16.926568,
|
||||
52.46719
|
||||
],
|
||||
[
|
||||
16.927008,
|
||||
52.467108
|
||||
],
|
||||
[
|
||||
16.926953,
|
||||
52.467024
|
||||
],
|
||||
[
|
||||
16.927463,
|
||||
52.466919
|
||||
],
|
||||
[
|
||||
16.927467,
|
||||
52.466956
|
||||
],
|
||||
[
|
||||
16.927316,
|
||||
52.467153
|
||||
],
|
||||
[
|
||||
16.926907,
|
||||
52.467235
|
||||
],
|
||||
[
|
||||
16.926625,
|
||||
52.467294
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "facdd5349991758b9ad99d4e123c91cc"
|
||||
}
|
||||
],
|
||||
"type": "FeatureCollection"
|
||||
}
|
727
app/src/main/assets/wmi1floor.geojson
Normal file
@ -0,0 +1,727 @@
|
||||
{
|
||||
"features": [
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Pokoje profesorskie"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926707,
|
||||
52.46657
|
||||
],
|
||||
[
|
||||
16.92652,
|
||||
52.466244
|
||||
],
|
||||
[
|
||||
16.926459,
|
||||
52.466255
|
||||
],
|
||||
[
|
||||
16.926645,
|
||||
52.466582
|
||||
],
|
||||
[
|
||||
16.926707,
|
||||
52.46657
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "07f45cd94d45bb5ad0b6b285b0f6fbbb"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło B"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926961,
|
||||
52.467026
|
||||
],
|
||||
[
|
||||
16.92677,
|
||||
52.466682
|
||||
],
|
||||
[
|
||||
16.92652,
|
||||
52.466244
|
||||
],
|
||||
[
|
||||
16.926459,
|
||||
52.466255
|
||||
],
|
||||
[
|
||||
16.926428,
|
||||
52.466203
|
||||
],
|
||||
[
|
||||
16.926175,
|
||||
52.46625
|
||||
],
|
||||
[
|
||||
16.92621,
|
||||
52.466306
|
||||
],
|
||||
[
|
||||
16.926323,
|
||||
52.466282
|
||||
],
|
||||
[
|
||||
16.926515,
|
||||
52.466632
|
||||
],
|
||||
[
|
||||
16.926408,
|
||||
52.466654
|
||||
],
|
||||
[
|
||||
16.92644,
|
||||
52.466712
|
||||
],
|
||||
[
|
||||
16.926543,
|
||||
52.46669
|
||||
],
|
||||
[
|
||||
16.926754,
|
||||
52.467067
|
||||
],
|
||||
[
|
||||
16.926961,
|
||||
52.467026
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "143facf35f322434cfc5776f70f1db36"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Winda"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92669,
|
||||
52.467141
|
||||
],
|
||||
[
|
||||
16.92666,
|
||||
52.467089
|
||||
],
|
||||
[
|
||||
16.926755,
|
||||
52.46707
|
||||
],
|
||||
[
|
||||
16.926786,
|
||||
52.467121
|
||||
],
|
||||
[
|
||||
16.92669,
|
||||
52.467141
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "1a35bfafd619b80ffb8b36f03549e9e3"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "D2"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926876,
|
||||
52.466659
|
||||
],
|
||||
[
|
||||
16.926984,
|
||||
52.466635
|
||||
],
|
||||
[
|
||||
16.92694,
|
||||
52.466557
|
||||
],
|
||||
[
|
||||
16.926831,
|
||||
52.46658
|
||||
],
|
||||
[
|
||||
16.926876,
|
||||
52.466659
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "3e0a32a0583254e9e7c47fea1f402472"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Sale A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92714,
|
||||
52.466489
|
||||
],
|
||||
[
|
||||
16.926925,
|
||||
52.466127
|
||||
],
|
||||
[
|
||||
16.927027,
|
||||
52.466106
|
||||
],
|
||||
[
|
||||
16.927232,
|
||||
52.466472
|
||||
],
|
||||
[
|
||||
16.92714,
|
||||
52.466489
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "3e56cb54baf90049a3ce2f16577c2cd8"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "D1"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926984,
|
||||
52.466635
|
||||
],
|
||||
[
|
||||
16.927084,
|
||||
52.466614
|
||||
],
|
||||
[
|
||||
16.92704,
|
||||
52.466536
|
||||
],
|
||||
[
|
||||
16.92694,
|
||||
52.466557
|
||||
],
|
||||
[
|
||||
16.926984,
|
||||
52.466635
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "56c2a7ab4e4d2ac14a46448d523470dc"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Hol"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927104,
|
||||
52.467081
|
||||
],
|
||||
[
|
||||
16.927039,
|
||||
52.467095
|
||||
],
|
||||
[
|
||||
16.9268,
|
||||
52.467145
|
||||
],
|
||||
[
|
||||
16.926754,
|
||||
52.467067
|
||||
],
|
||||
[
|
||||
16.926961,
|
||||
52.467026
|
||||
],
|
||||
[
|
||||
16.927277,
|
||||
52.46696
|
||||
],
|
||||
[
|
||||
16.927272,
|
||||
52.466951
|
||||
],
|
||||
[
|
||||
16.927451,
|
||||
52.466918
|
||||
],
|
||||
[
|
||||
16.927494,
|
||||
52.467002
|
||||
],
|
||||
[
|
||||
16.927278,
|
||||
52.467047
|
||||
],
|
||||
[
|
||||
16.927144,
|
||||
52.467073
|
||||
],
|
||||
[
|
||||
16.927104,
|
||||
52.467081
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "6f1db27a4df5a46f7a6913556b01effe"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Pokoje profesorskie"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92677,
|
||||
52.466683
|
||||
],
|
||||
[
|
||||
16.926961,
|
||||
52.467026
|
||||
],
|
||||
[
|
||||
16.926887,
|
||||
52.467041
|
||||
],
|
||||
[
|
||||
16.926695,
|
||||
52.466699
|
||||
],
|
||||
[
|
||||
16.92677,
|
||||
52.466683
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "94f310dcaa6cee75d9e7800bf8d94155"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Biblioteka"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926801,
|
||||
52.467144
|
||||
],
|
||||
[
|
||||
16.926971,
|
||||
52.467424
|
||||
],
|
||||
[
|
||||
16.926956,
|
||||
52.46743
|
||||
],
|
||||
[
|
||||
16.926944,
|
||||
52.467436
|
||||
],
|
||||
[
|
||||
16.92693,
|
||||
52.467441
|
||||
],
|
||||
[
|
||||
16.926903,
|
||||
52.467452
|
||||
],
|
||||
[
|
||||
16.926861,
|
||||
52.467464
|
||||
],
|
||||
[
|
||||
16.926778,
|
||||
52.467476
|
||||
],
|
||||
[
|
||||
16.926731,
|
||||
52.467485
|
||||
],
|
||||
[
|
||||
16.926567,
|
||||
52.467194
|
||||
],
|
||||
[
|
||||
16.926801,
|
||||
52.467144
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "aadab5775bdeb4eaf82c940255ddadd7"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Sale A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927082,
|
||||
52.466492
|
||||
],
|
||||
[
|
||||
16.926999,
|
||||
52.466509
|
||||
],
|
||||
[
|
||||
16.926771,
|
||||
52.466109
|
||||
],
|
||||
[
|
||||
16.926857,
|
||||
52.466088
|
||||
],
|
||||
[
|
||||
16.927082,
|
||||
52.466492
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "b39857ed605e5794fa6c9cdee5d7d6cf"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Pokoje profesorskie"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926754,
|
||||
52.467066
|
||||
],
|
||||
[
|
||||
16.926814,
|
||||
52.467054
|
||||
],
|
||||
[
|
||||
16.926605,
|
||||
52.466676
|
||||
],
|
||||
[
|
||||
16.926542,
|
||||
52.46669
|
||||
],
|
||||
[
|
||||
16.926564,
|
||||
52.466728
|
||||
],
|
||||
[
|
||||
16.926754,
|
||||
52.467066
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "b754d867fde3826e72fe8c243399ff26"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Sale A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927272,
|
||||
52.46695
|
||||
],
|
||||
[
|
||||
16.927083,
|
||||
52.466613
|
||||
],
|
||||
[
|
||||
16.927167,
|
||||
52.466595
|
||||
],
|
||||
[
|
||||
16.92735,
|
||||
52.466936
|
||||
],
|
||||
[
|
||||
16.927272,
|
||||
52.46695
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c3726b2a2b3a589995fd3f17eecd1f53"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "D3"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92677,
|
||||
52.466682
|
||||
],
|
||||
[
|
||||
16.926876,
|
||||
52.466659
|
||||
],
|
||||
[
|
||||
16.926832,
|
||||
52.46658
|
||||
],
|
||||
[
|
||||
16.926725,
|
||||
52.466604
|
||||
],
|
||||
[
|
||||
16.92677,
|
||||
52.466682
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "c73d9bdbccc15d9907e24b8bb731118a"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Pokoje profesorskie"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.926324,
|
||||
52.466282
|
||||
],
|
||||
[
|
||||
16.926503,
|
||||
52.46661
|
||||
],
|
||||
[
|
||||
16.926579,
|
||||
52.466595
|
||||
],
|
||||
[
|
||||
16.926398,
|
||||
52.466268
|
||||
],
|
||||
[
|
||||
16.926324,
|
||||
52.466282
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "d54475cedfa0a866e13933c56bf35d76"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Sale A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927607,
|
||||
52.466891
|
||||
],
|
||||
[
|
||||
16.92734,
|
||||
52.466562
|
||||
],
|
||||
[
|
||||
16.927242,
|
||||
52.466585
|
||||
],
|
||||
[
|
||||
16.927451,
|
||||
52.466918
|
||||
],
|
||||
[
|
||||
16.927607,
|
||||
52.466891
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "d97989e446002de50bc8844d2d9cdf5c"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Winda"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.92669,
|
||||
52.467141
|
||||
],
|
||||
[
|
||||
16.92666,
|
||||
52.467089
|
||||
],
|
||||
[
|
||||
16.926755,
|
||||
52.46707
|
||||
],
|
||||
[
|
||||
16.926786,
|
||||
52.467121
|
||||
],
|
||||
[
|
||||
16.92669,
|
||||
52.467141
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "dfdba4ee1ee0c55193b8dd04f8b00f6c"
|
||||
},
|
||||
{
|
||||
"type": "Feature",
|
||||
"properties": {
|
||||
"name": "Skrzydło A"
|
||||
},
|
||||
"geometry": {
|
||||
"coordinates": [
|
||||
[
|
||||
[
|
||||
16.927606,
|
||||
52.466891
|
||||
],
|
||||
[
|
||||
16.927339,
|
||||
52.466562
|
||||
],
|
||||
[
|
||||
16.927242,
|
||||
52.466585
|
||||
],
|
||||
[
|
||||
16.92718,
|
||||
52.466482
|
||||
],
|
||||
[
|
||||
16.927232,
|
||||
52.466473
|
||||
],
|
||||
[
|
||||
16.927025,
|
||||
52.466105
|
||||
],
|
||||
[
|
||||
16.926924,
|
||||
52.466126
|
||||
],
|
||||
[
|
||||
16.926896,
|
||||
52.466078
|
||||
],
|
||||
[
|
||||
16.92677,
|
||||
52.466108
|
||||
],
|
||||
[
|
||||
16.926998,
|
||||
52.466509
|
||||
],
|
||||
[
|
||||
16.927041,
|
||||
52.466537
|
||||
],
|
||||
[
|
||||
16.927075,
|
||||
52.466595
|
||||
],
|
||||
[
|
||||
16.927082,
|
||||
52.466614
|
||||
],
|
||||
[
|
||||
16.927277,
|
||||
52.46696
|
||||
],
|
||||
[
|
||||
16.927358,
|
||||
52.466942
|
||||
],
|
||||
[
|
||||
16.927354,
|
||||
52.466935
|
||||
],
|
||||
[
|
||||
16.92745,
|
||||
52.466918
|
||||
],
|
||||
[
|
||||
16.927606,
|
||||
52.466891
|
||||
]
|
||||
]
|
||||
],
|
||||
"type": "Polygon"
|
||||
},
|
||||
"id": "faaa569e3642a741f70a77071f19f131"
|
||||
}
|
||||
],
|
||||
"type": "FeatureCollection"
|
||||
}
|
BIN
app/src/main/ic_launcher-web.png
Normal file
After Width: | Height: | Size: 51 KiB |
95
app/src/main/java/com/uam/wmi/findmytutor/FindMyTutor.java
Normal file
@ -0,0 +1,95 @@
|
||||
package com.uam.wmi.findmytutor;
|
||||
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.annotation.AcraLimiter;
|
||||
import org.acra.annotation.AcraNotification;
|
||||
import org.acra.config.CoreConfigurationBuilder;
|
||||
import org.acra.config.HttpSenderConfigurationBuilder;
|
||||
import org.acra.config.ToastConfigurationBuilder;
|
||||
import org.acra.data.StringFormat;
|
||||
import org.acra.sender.HttpSender;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.acra.ReportField.ANDROID_VERSION;
|
||||
import static org.acra.ReportField.BUILD_CONFIG;
|
||||
import static org.acra.ReportField.CUSTOM_DATA;
|
||||
import static org.acra.ReportField.LOGCAT;
|
||||
import static org.acra.ReportField.PHONE_MODEL;
|
||||
import static org.acra.ReportField.REPORT_ID;
|
||||
import static org.acra.ReportField.SHARED_PREFERENCES;
|
||||
import static org.acra.ReportField.STACK_TRACE;
|
||||
import static org.acra.ReportField.USER_APP_START_DATE;
|
||||
import static org.acra.ReportField.USER_CRASH_DATE;
|
||||
|
||||
|
||||
@AcraNotification(resText = R.string.notification_text,
|
||||
resTitle = R.string.notification_title,
|
||||
resChannelName = R.string.notification_channel)
|
||||
@AcraLimiter(failedReportLimit = 2)
|
||||
public class FindMyTutor extends Application {
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(base);
|
||||
//super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
|
||||
// ACRA core
|
||||
CoreConfigurationBuilder builder = new CoreConfigurationBuilder(this)
|
||||
.setBuildConfigClass(BuildConfig.class)
|
||||
.setReportContent(REPORT_ID, PHONE_MODEL, LOGCAT, USER_APP_START_DATE, USER_CRASH_DATE, SHARED_PREFERENCES,
|
||||
ANDROID_VERSION, STACK_TRACE, CUSTOM_DATA, BUILD_CONFIG)
|
||||
.setReportFormat(StringFormat.JSON);
|
||||
|
||||
// Toast for user
|
||||
builder.setBuildConfigClass(BuildConfig.class)
|
||||
.setReportFormat(StringFormat.JSON);
|
||||
builder.getPluginConfigurationBuilder(
|
||||
ToastConfigurationBuilder.class
|
||||
).setResText(R.string.acra_toast_text);
|
||||
|
||||
|
||||
SharedPreferences sharedPreferences = base.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
|
||||
Map header = new HashMap();
|
||||
String token = sharedPreferences.getString("API_KEY", "KEY_EMPTY");
|
||||
header.put("Authorization", "Bearer " + token);
|
||||
|
||||
// Api POST
|
||||
builder.getPluginConfigurationBuilder(
|
||||
HttpSenderConfigurationBuilder.class
|
||||
// ).setUri("http://192.168.0.15:3000/api/acra")
|
||||
).setUri(Const.BASE_URL + "api/Feedback/autoFeedback")
|
||||
.setHttpMethod(HttpSender.Method.POST)
|
||||
.setHttpHeaders(header)
|
||||
.setEnabled(true);
|
||||
|
||||
ACRA.init(this, builder);
|
||||
//Shared preferences
|
||||
ACRA.getErrorReporter().putCustomData("USER_ID", sharedPreferences.getString("USER_ID", "no user id"));
|
||||
}
|
||||
|
||||
// Called by the system when the device configuration changes while your component is running.
|
||||
// Overriding this method is totally optional!
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
// This is called when the overall system is running low on memory,
|
||||
// and would like actively running processes to tighten their belts.
|
||||
// Overriding this method is totally optional!
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
}
|
||||
}
|
@ -0,0 +1,115 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceActivity;
|
||||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatDelegate;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
|
||||
/**
|
||||
* A {@link android.preference.PreferenceActivity} which implements and proxies the necessary calls
|
||||
* to be used with AppCompat.
|
||||
*/
|
||||
public abstract class AppCompatPreferenceActivity extends PreferenceActivity {
|
||||
|
||||
private AppCompatDelegate mDelegate;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
getDelegate().installViewFactory();
|
||||
getDelegate().onCreate(savedInstanceState);
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
getDelegate().onPostCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
public ActionBar getSupportActionBar() {
|
||||
return getDelegate().getSupportActionBar();
|
||||
}
|
||||
|
||||
public void setSupportActionBar(@Nullable Toolbar toolbar) {
|
||||
getDelegate().setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MenuInflater getMenuInflater() {
|
||||
return getDelegate().getMenuInflater();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(@LayoutRes int layoutResID) {
|
||||
getDelegate().setContentView(layoutResID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view) {
|
||||
getDelegate().setContentView(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().setContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addContentView(View view, ViewGroup.LayoutParams params) {
|
||||
getDelegate().addContentView(view, params);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostResume() {
|
||||
super.onPostResume();
|
||||
getDelegate().onPostResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onTitleChanged(CharSequence title, int color) {
|
||||
super.onTitleChanged(title, color);
|
||||
getDelegate().setTitle(title);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
getDelegate().onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
getDelegate().onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
getDelegate().onDestroy();
|
||||
}
|
||||
|
||||
public void invalidateOptionsMenu() {
|
||||
getDelegate().invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private AppCompatDelegate getDelegate() {
|
||||
if (mDelegate == null) {
|
||||
mDelegate = AppCompatDelegate.create(this, null);
|
||||
}
|
||||
return mDelegate;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,461 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Configuration;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.widget.DrawerLayout;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||
import com.uam.wmi.findmytutor.utils.FeedbackUtils;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RxSearchObservable;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.defaultMapZoom;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.onlineBackgroundLocationInterval;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.searchMapZoom;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
|
||||
|
||||
public abstract class BaseActivity
|
||||
extends AppCompatActivity
|
||||
implements BottomNavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private final static int REQUEST_CODE_ASK_PERMISSIONS = 1;
|
||||
private static final String[] REQUIRED_SDK_PERMISSIONS = new String[]{
|
||||
Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_LOCATION_EXTRA_COMMANDS};
|
||||
public DrawerLayout drawerLayout;
|
||||
protected BottomNavigationView navigationView;
|
||||
protected NavigationView drawerNavigationView;
|
||||
protected DrawerLayout sideDrawer;
|
||||
protected Toolbar toolbar;
|
||||
protected boolean isTutor;
|
||||
|
||||
String tag = getClass().getName();
|
||||
|
||||
protected FeedbackUtils feedbackUtils;
|
||||
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
private SharingFragment sharingFragment;
|
||||
|
||||
private Fragment userListFragment;
|
||||
public ActiveFragment activeFragment = ActiveFragment.NONE;
|
||||
private Fragment activeBottomMenu = null;
|
||||
public SearchView searchView;
|
||||
public MenuItem infoMenuItem;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getContentViewId());
|
||||
|
||||
drawerNavigationView = findViewById(R.id.nav_view);
|
||||
sideDrawer = findViewById(R.id.activity_container);
|
||||
feedbackUtils = new FeedbackUtils(BaseActivity.this);
|
||||
|
||||
drawerNavigationView.setNavigationItemSelectedListener(
|
||||
item -> {
|
||||
String itemName = (String) item.getTitle();
|
||||
Intent launchIntent;
|
||||
if (itemName.equals(getResources().getString(R.string.navigation_item_whitelist))) {
|
||||
launchIntent = new Intent(getApplicationContext(), WhiteList.class);
|
||||
startActivity(launchIntent);
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_blacklist))) {
|
||||
launchIntent = new Intent(getApplicationContext(),BlackList.class);
|
||||
startActivity(launchIntent);
|
||||
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_profile))) {
|
||||
|
||||
launchIntent = new Intent(getApplicationContext(), TutorTab.class);
|
||||
startActivity(launchIntent);
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_settings))) {
|
||||
launchIntent = new Intent(getApplicationContext(), SettingsActivity.class);
|
||||
startActivity(launchIntent);
|
||||
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_logout))) {
|
||||
if(PrefUtils.isBackgroundLocationServiceRunning(getApplicationContext())) {
|
||||
stopBackgroundLocalizationTask();
|
||||
}
|
||||
logout();
|
||||
|
||||
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_feedback))) {
|
||||
feedbackUtils.showNoteDialog("FEEDBACK");
|
||||
|
||||
/*showNoteDialog(BaseActivity.this, );*/
|
||||
} else if (itemName.equals(getResources().getString(R.string.navigation_item_bug))) {
|
||||
feedbackUtils.showNoteDialog("BUG REPORT");
|
||||
/*showNoteDialog(BaseActivity.this, "BUG REPORT");*/
|
||||
}
|
||||
|
||||
sideDrawer.closeDrawers();
|
||||
|
||||
return true;
|
||||
}
|
||||
);
|
||||
|
||||
navigationView = findViewById(R.id.navigation);
|
||||
navigationView.setOnNavigationItemSelectedListener(this);
|
||||
sharingFragment = new SharingFragment();
|
||||
userListFragment = new UsersListFragment();
|
||||
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (!isTutor) {
|
||||
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
drawerNavigationView.getMenu().setGroupVisible(R.id.drawer_group_tutor, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected void logout(){
|
||||
storeBackgroundLocationStatus(getApplication(), false);
|
||||
PrefUtils.storeIsLoggedIn(getApplicationContext(), false);
|
||||
PrefUtils.setBatteryExlusionInfoStatus(getApplicationContext(), true);
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
if (i != null) {
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
}
|
||||
startActivity(i);
|
||||
finish();
|
||||
}
|
||||
|
||||
protected void checkPermissions() {
|
||||
final List<String> missingPermissions = new ArrayList<String>();
|
||||
|
||||
for (final String permission : REQUIRED_SDK_PERMISSIONS) {
|
||||
final int result = ContextCompat.checkSelfPermission(this, permission);
|
||||
if (result != PackageManager.PERMISSION_GRANTED) {
|
||||
missingPermissions.add(permission);
|
||||
}
|
||||
}
|
||||
if (!missingPermissions.isEmpty()) {
|
||||
// request all missing permissions
|
||||
final String[] permissions = missingPermissions
|
||||
.toArray(new String[missingPermissions.size()]);
|
||||
ActivityCompat.requestPermissions(this, permissions, REQUEST_CODE_ASK_PERMISSIONS);
|
||||
} else {
|
||||
final int[] grantResults = new int[REQUIRED_SDK_PERMISSIONS.length];
|
||||
Arrays.fill(grantResults, PackageManager.PERMISSION_GRANTED);
|
||||
onRequestPermissionsResult(REQUEST_CODE_ASK_PERMISSIONS, REQUIRED_SDK_PERMISSIONS,
|
||||
grantResults);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[],
|
||||
@NonNull int[] grantResults) {
|
||||
switch (requestCode) {
|
||||
case REQUEST_CODE_ASK_PERMISSIONS:
|
||||
for (int index = permissions.length - 1; index >= 0; --index) {
|
||||
if (grantResults[index] != PackageManager.PERMISSION_GRANTED) {
|
||||
// exit the app if one permission is not granted
|
||||
Toast.makeText(this, "Required permission '" + permissions[index]
|
||||
+ "' not granted, exiting", Toast.LENGTH_LONG).show();
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void stopBackgroundLocalizationTask() {
|
||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), false);
|
||||
|
||||
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
stopIntent.putExtra("request_stop", true);
|
||||
|
||||
stopService(stopIntent);
|
||||
|
||||
}
|
||||
|
||||
public void startBackgroundLocalizationTask() {
|
||||
checkPermissions();
|
||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), true);
|
||||
|
||||
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
startIntent.putExtra("notify_interval", onlineBackgroundLocationInterval);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(startIntent);
|
||||
} else {
|
||||
startService(startIntent);
|
||||
}
|
||||
}
|
||||
|
||||
public void handleBackgroundTaskLifeCycle() {
|
||||
Boolean shouldServiceRun = PrefUtils.isEnableSharingLocalization(getApplicationContext()) && isTutor;
|
||||
|
||||
if (shouldServiceRun) {
|
||||
startBackgroundLocalizationTask();
|
||||
} else {
|
||||
stopBackgroundLocalizationTask();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setContentView(int layoutResID) {
|
||||
DrawerLayout fullView = (DrawerLayout) getLayoutInflater().inflate(R.layout.base_activity, null);
|
||||
FrameLayout activityContainer = fullView.findViewById(R.id.activity_content);
|
||||
getLayoutInflater().inflate(layoutResID, activityContainer, true);
|
||||
super.setContentView(fullView);
|
||||
|
||||
initToolbar();
|
||||
}
|
||||
|
||||
private void initToolbar() {
|
||||
toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
}
|
||||
|
||||
private void setUpNav() {
|
||||
|
||||
drawerLayout = findViewById(R.id.activity_container);
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawerLayout.addDrawerListener(actionBarDrawerToggle);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
actionBar.setDisplayShowTitleEnabled(false);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
setUpNav();
|
||||
|
||||
actionBarDrawerToggle.syncState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConfigurationChanged(Configuration newConfig) {
|
||||
super.onConfigurationChanged(newConfig);
|
||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
infoMenuItem = menu.findItem(R.id.action_info);
|
||||
|
||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||
searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
|
||||
searchView.setOnQueryTextFocusChangeListener((v, hasFocus) -> {
|
||||
if (!hasFocus && activeFragment.equals(ActiveFragment.NONE)) {
|
||||
restoreMapMarkers();
|
||||
adjustMapToSearch(defaultMapZoom);
|
||||
}
|
||||
|
||||
if (!hasFocus && activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
((UsersListFragment) userListFragment).restoreUsersList();
|
||||
}
|
||||
|
||||
if(hasFocus && activeFragment.equals(ActiveFragment.NONE)){
|
||||
adjustMapToSearch(searchMapZoom);
|
||||
}
|
||||
});
|
||||
|
||||
RxSearchObservable.fromView(searchView)
|
||||
.skip(0)
|
||||
.map(String::toLowerCase)
|
||||
.filter(t -> !t.isEmpty())
|
||||
.debounce(250, TimeUnit.MILLISECONDS)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.switchMap((Function<String, ObservableSource<String>>) Observable::just)
|
||||
.subscribe(this::executeSearch);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void executeSearch(String input) {
|
||||
if (activeFragment.equals(ActiveFragment.USER_LIST)) {
|
||||
((UsersListFragment) userListFragment).searchUser(input);
|
||||
|
||||
} else if (activeFragment.equals(ActiveFragment.NONE)) {
|
||||
searchUser(input);
|
||||
}
|
||||
}
|
||||
|
||||
abstract void searchUser(String textToSearch);
|
||||
|
||||
abstract void restoreMapMarkers();
|
||||
|
||||
abstract void adjustMapToSearch(Integer zoom);
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (item.getItemId()==R.id.action_info){
|
||||
int layoutID;
|
||||
switch (activeFragment){
|
||||
case SHARED_PREFERENCES:
|
||||
layoutID = R.layout.info_popup_sharing_tab;
|
||||
break;
|
||||
case USER_LIST:
|
||||
layoutID = R.layout.info_popup_userlist;
|
||||
break;
|
||||
default:
|
||||
layoutID = R.layout.info_popup_map;
|
||||
}
|
||||
|
||||
View popupView = getLayoutInflater().inflate(layoutID,null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(popupView,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
// If the PopupWindow should be focusable
|
||||
popupWindow.setFocusable(true);
|
||||
// If you need the PopupWindow to dismiss when when touched outside
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable());
|
||||
// Get the View's(the one that was clicked in the Fragment) location
|
||||
View anchorView= getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
updateNavigationBarState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
overridePendingTransition(0, 0);
|
||||
}
|
||||
|
||||
private void removeFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
navigationView.postDelayed(() -> {
|
||||
int itemId = item.getItemId();
|
||||
|
||||
if (itemId == R.id.nav_map) {
|
||||
removeFragment(sharingFragment);
|
||||
removeFragment(userListFragment);
|
||||
activeFragment = ActiveFragment.NONE;
|
||||
findViewById(R.id.action_search).setVisibility(View.VISIBLE);
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
loadUserSettingsFragment();
|
||||
findViewById(R.id.action_search).setVisibility(View.GONE);
|
||||
} else if (itemId == R.id.nav_user_list) {
|
||||
loadUserListFragment();
|
||||
findViewById(R.id.action_search).setVisibility(View.VISIBLE);
|
||||
}
|
||||
selectBottomNavigationBarItem(itemId);
|
||||
}, 300);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void loadUserSettingsFragment() {
|
||||
activeFragment = ActiveFragment.SHARED_PREFERENCES;
|
||||
sharingFragment = SharingFragment.newInstance();
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, sharingFragment);
|
||||
//ft.addToBackStack(null);
|
||||
ft.commit();
|
||||
}
|
||||
|
||||
private void loadUserListFragment() {
|
||||
activeFragment = ActiveFragment.USER_LIST;
|
||||
|
||||
userListFragment = UsersListFragment.newInstance();
|
||||
FragmentTransaction ft = getFragmentManager().beginTransaction();
|
||||
ft.replace(R.id.activity_content, userListFragment);
|
||||
//ft.addToBackStack(null);
|
||||
ft.commit();
|
||||
|
||||
}
|
||||
|
||||
public void updateNavigationBarState() {
|
||||
int actionId = getNavigationMenuItemId();
|
||||
selectBottomNavigationBarItem(actionId);
|
||||
}
|
||||
|
||||
private void selectBottomNavigationBarItem(int itemId) {
|
||||
MenuItem item = navigationView.getMenu().findItem(itemId);
|
||||
item.setChecked(true);
|
||||
}
|
||||
|
||||
abstract int getNavigationMenuItemId();
|
||||
abstract int getContentViewId();
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,370 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.github.ybq.android.spinkit.SpinKitView;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.adapters.BlackListAdapter;
|
||||
import com.uam.wmi.findmytutor.model.IsUsingListBool;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import com.uam.wmi.findmytutor.model.StudentIdModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.model.UserResponseModel;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class BlackList extends AppCompatActivity {
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private UserService userService;
|
||||
private boolean didFetched = false;
|
||||
private String tutorId;
|
||||
|
||||
@BindView(R.id.recycler_view_blacklist)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.black_list_empty_text_view)
|
||||
TextView noNotesView;
|
||||
@BindView(R.id.switch_blacklist_toggle)
|
||||
Switch aSwitch;
|
||||
@BindView(R.id.add_to_black_list_fab)
|
||||
FloatingActionButton addToBlackListFab;
|
||||
@BindView(R.id.loader)
|
||||
SpinKitView loader;
|
||||
|
||||
|
||||
private Integer prevSize;
|
||||
private BlackListAdapter mAdapter;
|
||||
private List<User> blacklistedUsers = new ArrayList<>();
|
||||
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
setContentView(R.layout.activity_black_list);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tutorId = PrefUtils.getUserId(getApplicationContext());
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
if (PrefUtils.isBlackListing(this)){
|
||||
aSwitch.setText(getString(R.string.action_black_list) + " " +getString(R.string.on));
|
||||
aSwitch.setChecked(true);
|
||||
handleChangeRequest(true);
|
||||
}else{
|
||||
aSwitch.setText(getString(R.string.action_black_list) + " " +getString(R.string.off) );
|
||||
aSwitch.setChecked(false);
|
||||
handleChangeRequest(false);
|
||||
}
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(getString(R.string.activity_title_blacklist));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
mAdapter = new BlackListAdapter(this, blacklistedUsers);
|
||||
recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getApplicationContext()));
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
|
||||
fetchBlackListedUsers();
|
||||
/**
|
||||
* On long press on RecyclerView item, open alert dialog
|
||||
* with options to choose
|
||||
* Edit and Delete
|
||||
* */
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
}
|
||||
}));
|
||||
|
||||
addToBlackListFab.setOnClickListener(this::showFabDialog);
|
||||
handleSwitch();
|
||||
}
|
||||
|
||||
private Observable<List<String>> getListOfBlacklistedUsers(String userId) {
|
||||
return userService.getTutorBlacklistedByID(userId)
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private Observable<User> getUserObservable(String userId) {
|
||||
return userService
|
||||
.getUserById(userId)
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private void fetchBlackListedUsers() {
|
||||
disposable.add(getListOfBlacklistedUsers(tutorId)
|
||||
.doOnSubscribe(this::handleDoOnSubscribe)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(Observable::fromIterable)
|
||||
.flatMap(this::getUserObservable)
|
||||
.subscribe(user -> blacklistedUsers.add(user), this::handleError,this::handleComplete));
|
||||
}
|
||||
|
||||
private void handleDoOnSubscribe(Disposable disposable) {
|
||||
prevSize = blacklistedUsers.size();
|
||||
blacklistedUsers.clear();
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void handleComplete() {
|
||||
Collections.sort(blacklistedUsers, this::sortByUserName);
|
||||
didFetched = true;
|
||||
refreshUI();
|
||||
}
|
||||
private void handleError(Throwable e){
|
||||
showError(e);
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void refreshUI(){
|
||||
toggleEmptyNotes();
|
||||
mAdapter.notifyItemRangeInserted(prevSize, blacklistedUsers.size() - prevSize);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private int sortByUserName(User t1, User t2) {
|
||||
return plCollator.compare(t1.getLastName(), t2.getLastName());
|
||||
}
|
||||
|
||||
private void showFabDialog(View v){
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.black_list_fab_modal, null);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
|
||||
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
|
||||
|
||||
alertDialogBuilderUserInput
|
||||
.setPositiveButton(R.string.add, null)
|
||||
.setNegativeButton(R.string.cancel, null);
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
EditText modalUserInput = view.findViewById(R.id.black_list_modal_input);
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
|
||||
dismissButton.setOnClickListener(view1 -> alertDialog.dismiss());
|
||||
|
||||
sendButton.setOnClickListener(view1 -> {
|
||||
String body = modalUserInput.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(body)) {
|
||||
Toast.makeText(getApplicationContext(), R.string.can_not_be_empty, Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
} else {
|
||||
sendUserToBlacklist(body);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void sendUserToBlacklist(String body) {
|
||||
StudentIdModel studentIdModel = new StudentIdModel(body);
|
||||
disposable.add(
|
||||
userService.addStudentToBlacklist(PrefUtils.getUserId(getApplicationContext()), studentIdModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleAddUser,this::showError)
|
||||
);
|
||||
}
|
||||
|
||||
private void handleAddUser(User user) {
|
||||
Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show();
|
||||
blacklistedUsers.clear();
|
||||
fetchBlackListedUsers();
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
if (((HttpException) e).response().code() == 404) {
|
||||
message = getString(R.string.no_such_a_user);
|
||||
}
|
||||
} else {
|
||||
message = "Network Error !";
|
||||
}
|
||||
|
||||
Toast.makeText(this, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void toggleEmptyNotes() {
|
||||
if (didFetched && blacklistedUsers.size() == 0) {
|
||||
noNotesView.setVisibility(View.VISIBLE);
|
||||
noNotesView.setText(R.string.list_is_empty);
|
||||
loader.setVisibility(View.GONE);
|
||||
}else if (blacklistedUsers.size() > 0) {
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
loader.setVisibility(View.GONE);
|
||||
} else {
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_black_list, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if (item.getItemId()==R.id.action_blacklist_info_popup){
|
||||
int layoutID = R.layout.info_popup_blacklist;
|
||||
|
||||
View popupView = getLayoutInflater().inflate(layoutID,null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(popupView,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
// If the PopupWindow should be focusable
|
||||
popupWindow.setFocusable(true);
|
||||
// If you need the PopupWindow to dismiss when when touched outside
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable());
|
||||
// Get the View's(the one that was clicked in the Fragment) location
|
||||
View anchorView= getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void handleSwitch(){
|
||||
aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked){
|
||||
aSwitch.setText(getString(R.string.action_black_list) + " "+ getString(R.string.on));
|
||||
handleChangeRequest(true);
|
||||
PrefUtils.useBlacklist(this,true);
|
||||
}else {
|
||||
aSwitch.setText(getString(R.string.action_black_list) + " "+getString(R.string.off));
|
||||
handleChangeRequest(false);
|
||||
PrefUtils.useBlacklist(this,false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleChangeRequest(boolean value){
|
||||
IsUsingListBool isUsingListBool = new IsUsingListBool();
|
||||
isUsingListBool.setIsUsing(value);
|
||||
disposable.add(
|
||||
userService.setTutorBlacklist(tutorId, isUsingListBool)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(()->{
|
||||
},this::showError)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
}
|
@ -3,402 +3,219 @@ package com.uam.wmi.findmytutor.activity;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.content.CursorLoader;
|
||||
import android.content.Intent;
|
||||
import android.content.Loader;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.ToggleButton;
|
||||
|
||||
import com.auth0.android.jwt.Claim;
|
||||
import com.auth0.android.jwt.JWT;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.model.ValidateUser;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.LdapService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static android.Manifest.permission.READ_CONTACTS;
|
||||
public class LoginActivity extends AppCompatActivity {
|
||||
|
||||
/**
|
||||
* A login screen that offers login via email/password.
|
||||
*/
|
||||
public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<Cursor> {
|
||||
|
||||
/**
|
||||
* Id to identity READ_CONTACTS permission request.
|
||||
*/
|
||||
private static final int REQUEST_READ_CONTACTS = 0;
|
||||
|
||||
/**
|
||||
* A dummy authentication store containing known user names and passwords.
|
||||
* TODO: remove after connecting to a real authentication system.
|
||||
*/
|
||||
private static final String[] DUMMY_CREDENTIALS = new String[]{
|
||||
"adam@o2.pl:adamadam", "foo@example.com:hello", "bar@example.com:world"
|
||||
};
|
||||
/**
|
||||
* Keep track of the login task to ensure we can cancel it if requested.
|
||||
*/
|
||||
private UserLoginTask mAuthTask = null;
|
||||
|
||||
// UI references.
|
||||
private AutoCompleteTextView mEmailView;
|
||||
private AutoCompleteTextView mLoginNameView;
|
||||
private EditText mPasswordView;
|
||||
private View mProgressView;
|
||||
private View mLoginFormView;
|
||||
private boolean loginOption;
|
||||
private LdapService ldapService;
|
||||
private UserService userService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_login);
|
||||
// Set up the login form.
|
||||
mEmailView = (AutoCompleteTextView) findViewById(R.id.email);
|
||||
populateAutoComplete();
|
||||
mLoginNameView = findViewById(R.id.email);
|
||||
|
||||
mPasswordView = (EditText) findViewById(R.id.password);
|
||||
mPasswordView.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
||||
@Override
|
||||
public boolean onEditorAction(TextView textView, int id, KeyEvent keyEvent) {
|
||||
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
ldapService = ApiClient.getClient(getApplicationContext())
|
||||
.create(LdapService.class);
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
Switch tutorLogin = (Switch) findViewById(R.id.tutor_login_switch);
|
||||
tutorLogin.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
loginOption = tutorLogin.isChecked();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Button mEmailSignInButton = (Button) findViewById(R.id.email_sign_in_button);
|
||||
mEmailSignInButton.setOnClickListener(new OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
mPasswordView = findViewById(R.id.password);
|
||||
mPasswordView.setOnEditorActionListener((textView, id, keyEvent) -> {
|
||||
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
Button mEmailSignInButton = findViewById(R.id.email_sign_in_button);
|
||||
mEmailSignInButton.setOnClickListener(view -> attemptLogin());
|
||||
|
||||
mLoginFormView = findViewById(R.id.login_form);
|
||||
mProgressView = findViewById(R.id.login_progress);
|
||||
}
|
||||
|
||||
private void populateAutoComplete() {
|
||||
if (!mayRequestContacts()) {
|
||||
return;
|
||||
}
|
||||
|
||||
getLoaderManager().initLoader(0, null, this);
|
||||
}
|
||||
|
||||
private boolean mayRequestContacts() {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
return true;
|
||||
}
|
||||
if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||
return true;
|
||||
}
|
||||
if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
|
||||
Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
|
||||
.setAction(android.R.string.ok, new View.OnClickListener() {
|
||||
@Override
|
||||
@TargetApi(Build.VERSION_CODES.M)
|
||||
public void onClick(View v) {
|
||||
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback received when a permissions request has been completed.
|
||||
*/
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||
@NonNull int[] grantResults) {
|
||||
if (requestCode == REQUEST_READ_CONTACTS) {
|
||||
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
populateAutoComplete();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Attempts to sign in or register the account specified by the login form.
|
||||
* If there are form errors (invalid email, missing fields, etc.), the
|
||||
* errors are presented and no actual login attempt is made.
|
||||
*/
|
||||
private void attemptLogin() {
|
||||
if (mAuthTask != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset errors.
|
||||
mEmailView.setError(null);
|
||||
mLoginNameView.setError(null);
|
||||
mPasswordView.setError(null);
|
||||
|
||||
// Store values at the time of the login attempt.
|
||||
String email = mEmailView.getText().toString();
|
||||
String loginName = mLoginNameView.getText().toString();
|
||||
String password = mPasswordView.getText().toString();
|
||||
|
||||
boolean cancel = false;
|
||||
View focusView = null;
|
||||
|
||||
// Check for a valid password, if the user entered one.
|
||||
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
|
||||
mPasswordView.setError(getString(R.string.error_invalid_password));
|
||||
// Check for a valid email address.
|
||||
if (TextUtils.isEmpty(loginName)) {
|
||||
mLoginNameView.setError(getString(R.string.error_field_required));
|
||||
focusView = mLoginNameView;
|
||||
cancel = true;
|
||||
} else if (!isEmailValid(loginName)) {
|
||||
mLoginNameView.setError(getString(R.string.error_invalid_login_name));
|
||||
focusView = mLoginNameView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// Check for a valid password address.
|
||||
if (TextUtils.isEmpty(password)) {
|
||||
mPasswordView.setError(getString(R.string.error_field_required));
|
||||
focusView = mPasswordView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// Check for a valid email address.
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
mEmailView.setError(getString(R.string.error_field_required));
|
||||
focusView = mEmailView;
|
||||
cancel = true;
|
||||
} else if (!isEmailValid(email)) {
|
||||
mEmailView.setError(getString(R.string.error_invalid_email));
|
||||
focusView = mEmailView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
// There was an error; don't attempt login and focus the first
|
||||
// form field with an error.
|
||||
focusView.requestFocus();
|
||||
} else {
|
||||
// Show a progress spinner, and kick off a background task to
|
||||
// perform the user login attempt.
|
||||
showProgress(true);
|
||||
mAuthTask = new UserLoginTask(email, password, loginOption);
|
||||
mAuthTask.execute((Void) null);
|
||||
loginProcess(loginName, password);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isEmailValid(String email) {
|
||||
//TODO: Replace this with your own logic
|
||||
return email.contains("@");
|
||||
private boolean isEmailValid(String loginName) {
|
||||
Pattern pattern = Pattern.compile("\\s");
|
||||
Matcher matcher = pattern.matcher(loginName);
|
||||
return !matcher.find();
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
//TODO: Replace this with your own logic
|
||||
return password.length() > 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the progress UI and hides the login form.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
||||
private void showProgress(final boolean show) {
|
||||
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
||||
// for very easy animations. If available, use these APIs to fade-in
|
||||
// the progress spinner.
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
|
||||
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mProgressView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// The ViewPropertyAnimator APIs are not available, so simply show
|
||||
// and hide the relevant UI components.
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||
return new CursorLoader(this,
|
||||
// Retrieve data rows for the device user's 'profile' contact.
|
||||
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
|
||||
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
|
||||
|
||||
// Select only email addresses.
|
||||
ContactsContract.Contacts.Data.MIMETYPE +
|
||||
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
|
||||
.CONTENT_ITEM_TYPE},
|
||||
|
||||
// Show primary email addresses first. Note that there won't be
|
||||
// a primary email address if the user hasn't specified one.
|
||||
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||
List<String> emails = new ArrayList<>();
|
||||
cursor.moveToFirst();
|
||||
while (!cursor.isAfterLast()) {
|
||||
emails.add(cursor.getString(ProfileQuery.ADDRESS));
|
||||
cursor.moveToNext();
|
||||
}
|
||||
|
||||
addEmailsToAutoComplete(emails);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLoaderReset(Loader<Cursor> cursorLoader) {
|
||||
|
||||
}
|
||||
|
||||
private void addEmailsToAutoComplete(List<String> emailAddressCollection) {
|
||||
//Create adapter to tell the AutoCompleteTextView what to show in its dropdown list.
|
||||
ArrayAdapter<String> adapter =
|
||||
new ArrayAdapter<>(LoginActivity.this,
|
||||
android.R.layout.simple_dropdown_item_1line, emailAddressCollection);
|
||||
|
||||
mEmailView.setAdapter(adapter);
|
||||
}
|
||||
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
|
||||
|
||||
private interface ProfileQuery {
|
||||
String[] PROJECTION = {
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||
};
|
||||
|
||||
int ADDRESS = 0;
|
||||
int IS_PRIMARY = 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents an asynchronous login/registration task used to authenticate
|
||||
* the user.
|
||||
*/
|
||||
public class UserLoginTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private final String mEmail;
|
||||
private final String mPassword;
|
||||
private boolean isTutor;
|
||||
private LdapService ldapService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private Boolean isAuthorizate;
|
||||
|
||||
// Constructor
|
||||
UserLoginTask(String email, String password, Boolean loginOption) {
|
||||
mEmail = email;
|
||||
mPassword = password;
|
||||
isTutor = loginOption;
|
||||
this.ldapService = ApiClient.getClient(getApplicationContext())
|
||||
.create(LdapService.class);
|
||||
this.isAuthorizate = false;
|
||||
|
||||
PrefUtils.storeIsTutor(getApplicationContext(), this.isTutor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
LdapUser user = new LdapUser("admin@admin",mPassword,"admin",(isTutor)?"Tutor":"Student","string","string",mEmail);
|
||||
|
||||
disposable.add(
|
||||
ldapService
|
||||
.fakeValidate(user)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<JwtToken>() {
|
||||
@Override
|
||||
public void onSuccess(JwtToken jwtToken) {
|
||||
String token = jwtToken.getToken();
|
||||
|
||||
JWT jwt = new JWT(token);
|
||||
Claim role = jwt.getClaim("nameid");
|
||||
|
||||
PrefUtils.isLoggedIn(getApplicationContext(), true);
|
||||
PrefUtils.storeApiKey(getApplicationContext(), token);
|
||||
PrefUtils.storeUserId(getApplicationContext(), role.asString());
|
||||
|
||||
onPostExecute(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Timber.e("onError: %s", e.getMessage());
|
||||
}
|
||||
}));
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final Boolean success) {
|
||||
mAuthTask = null;
|
||||
showProgress(false);
|
||||
|
||||
if (success) {
|
||||
// TODO: Ma zwracac 666 i cos jeszcze, do tego wpisywac jwt to shared prefs... kurwa
|
||||
Intent data = new Intent();
|
||||
String txt = "test text to Startup compo";
|
||||
data.setData(Uri.parse(txt));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
} else {
|
||||
mPasswordView.setError(getString(R.string.error_incorrect_password));
|
||||
mPasswordView.requestFocus();
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mProgressView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void loginProcess(String email, String password) {
|
||||
ValidateUser user = new ValidateUser(email, password);
|
||||
// LdapUser fakeUser = new LdapUser(email, password,"wmi","tutor",email,"Fałszywy",email);
|
||||
disposable.add(ldapService.validate(user)
|
||||
//disposable.add(ldapService.fakeValidate(fakeUser)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
}
|
||||
|
||||
private void getUserProfile(String userId) {
|
||||
|
||||
disposable.add(userService.getUserById(userId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::saveUserProfileToSharedPreferences, this::handleError));
|
||||
}
|
||||
|
||||
private void showSnackBarMessage(String message) {
|
||||
Snackbar.make(findViewById(R.id.login_form), message, Snackbar.LENGTH_LONG)
|
||||
.show();
|
||||
}
|
||||
|
||||
private void handleResponse(JwtToken jwtToken) {
|
||||
showProgress(false);
|
||||
|
||||
String token = jwtToken.getToken();
|
||||
JWT jwt = new JWT(token);
|
||||
Claim userId = jwt.getClaim("nameid");
|
||||
Claim role = jwt.getClaim("http://schemas.microsoft.com/ws/2008/06/identity/claims/role");
|
||||
|
||||
if (Objects.requireNonNull(role.asString()).equals("Student")) {
|
||||
PrefUtils.storeIsTutor(getApplicationContext(), false);
|
||||
} else {
|
||||
PrefUtils.storeIsTutor(getApplicationContext(), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
mAuthTask = null;
|
||||
showProgress(false);
|
||||
PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
|
||||
PrefUtils.storeApiKey(getApplicationContext(), token);
|
||||
PrefUtils.storeUserId(getApplicationContext(), userId.asString());
|
||||
|
||||
getUserProfile(userId.asString());
|
||||
|
||||
|
||||
Intent data = new Intent();
|
||||
String txt = "Main Activity";
|
||||
data.setData(Uri.parse(txt));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
showProgress(false);
|
||||
|
||||
if (error instanceof HttpException) {
|
||||
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
showSnackBarMessage(RestApiHelper.getErrorMessage(responseBody));
|
||||
|
||||
} else {
|
||||
showSnackBarMessage("Network Error !");
|
||||
}
|
||||
}
|
||||
|
||||
private void saveUserProfileToSharedPreferences(User user) {
|
||||
PrefUtils.storeUserFirstName(getApplicationContext(), user.getFirstName());
|
||||
PrefUtils.storeUserLastName(getApplicationContext(), user.getLastName());
|
||||
PrefUtils.storeUserName(getApplicationContext(), user.getUserName());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,203 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.utils.BroadcastLocalizationHandler;
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import timber.log.Timber;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private BottomNavigationView mMainNav;
|
||||
private FrameLayout mMainFrame;
|
||||
private boolean isTutor;
|
||||
private MapFragment mapFragment;
|
||||
private NotificationFragment notificationFragment;
|
||||
private ProfileFragment profileFragment;
|
||||
public static IntentFilter backgroundLocalizationService = null;
|
||||
|
||||
private BroadcastReceiver broadcastReceiver = null;
|
||||
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
private boolean boolean_permission = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
mMainFrame = findViewById(R.id.main_frame);
|
||||
mMainNav = findViewById(R.id.main_nav);
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (!isTutor) {
|
||||
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mapFragment = new MapFragment();
|
||||
notificationFragment = new NotificationFragment();
|
||||
profileFragment = new ProfileFragment();
|
||||
|
||||
// Default frag here
|
||||
setFragment(mapFragment);
|
||||
mMainNav.setSelectedItemId(R.id.nav_map);
|
||||
|
||||
mMainNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_map:
|
||||
setFragment(mapFragment);
|
||||
return true;
|
||||
case R.id.nav_notif:
|
||||
setFragment(notificationFragment);
|
||||
return true;
|
||||
case R.id.nav_profile:
|
||||
setFragment(profileFragment);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Logout button
|
||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||
button.setOnClickListener(view -> {
|
||||
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
unRegisterLocalizationService();
|
||||
finish();
|
||||
startActivity(i);
|
||||
|
||||
});
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
this.broadcastReceiver = new BroadcastLocalizationHandler();
|
||||
}
|
||||
}
|
||||
|
||||
private void setFragment(Fragment fragment) {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.replace(R.id.main_frame, fragment);
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void fn_permission() {
|
||||
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
|
||||
|
||||
if ((ActivityCompat.shouldShowRequestPermissionRationale(MainActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
|
||||
|
||||
} else {
|
||||
ActivityCompat.requestPermissions(MainActivity.this, new String[]{android.Manifest.permission.ACCESS_FINE_LOCATION
|
||||
|
||||
},
|
||||
REQUEST_PERMISSIONS);
|
||||
}
|
||||
} else {
|
||||
|
||||
if (isTutor) {
|
||||
Intent intent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
startService(intent);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
//startForegroundService(intent);
|
||||
ContextCompat.startForegroundService(getApplicationContext(),intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
|
||||
switch (requestCode) {
|
||||
case REQUEST_PERMISSIONS: {
|
||||
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||
boolean_permission = true;
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please allow the permission", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
backgroundLocalizationService = new IntentFilter(BackgroundLocalizationService.str_receiver);
|
||||
|
||||
if (isTutor)
|
||||
registerReceiver(this.broadcastReceiver, backgroundLocalizationService);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
|
||||
if (isTutor)
|
||||
unregisterReceiver(this.broadcastReceiver);
|
||||
}
|
||||
|
||||
protected void onDestroy() {
|
||||
unRegisterLocalizationService();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
private void unRegisterLocalizationService() {
|
||||
if (this.broadcastReceiver != null) {
|
||||
try {
|
||||
LocalBroadcastManager.getInstance(this).unregisterReceiver(broadcastReceiver);
|
||||
|
||||
Intent intent = new Intent(this, BackgroundLocalizationService.class);
|
||||
stopService(intent);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.d("RECIEVER UNREGISTER ERROR");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,797 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.location.Location;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.PowerManager;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.getbase.floatingactionbutton.FloatingActionButton;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.android.core.permissions.PermissionsListener;
|
||||
import com.mapbox.android.core.permissions.PermissionsManager;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.IconFactory;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponent;
|
||||
import com.mapbox.mapboxsdk.location.LocationComponentOptions;
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleUtils;
|
||||
import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
|
||||
import com.uam.wmi.findmytutor.utils.MapMarker;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.uam.wmi.findmytutor.utils.Const.mapRefreshInterval;
|
||||
|
||||
public class MapActivity extends BaseActivity
|
||||
implements PermissionsListener, OnMapReadyCallback {
|
||||
|
||||
private HashMap<Long, String> markerUserHash = new HashMap<>();
|
||||
private String tag = getClass().getName();
|
||||
private PermissionsManager permissionsManager;
|
||||
private LocationComponent locationComponent;
|
||||
private CoordinateService coordinateService;
|
||||
private UserService userService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private int mInterval = mapRefreshInterval;
|
||||
private Handler mHandler = new Handler();
|
||||
private Runnable mStatusChecker;
|
||||
private MapView mapView;
|
||||
private MapboxMap mapboxMap;
|
||||
private Button selectLocationButton;
|
||||
private Button removeLocationButton;
|
||||
private Marker tmpLocalMarker;
|
||||
private Coordinate droppedMarkercoordinate;
|
||||
public HashMap<String, Coordinate> coordsMap = new HashMap<>();
|
||||
private HashMap<String, MapMarker> markerHash = new HashMap<>();
|
||||
private Set<String> previousCoordsIds = new HashSet<>();
|
||||
private ManualLocationUtils manualLocationUtils;
|
||||
// Camera Animation params
|
||||
private int zoomParam = 17;
|
||||
private int bearingParam = 180;
|
||||
private int tiltParam = 30;
|
||||
private String myId;
|
||||
private boolean isTutor;
|
||||
private ApproximatedLocalization approximatedLocalization;
|
||||
private boolean shouldFetchNewCoords = true;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
isTutor = PrefUtils.getIsTutor(this);
|
||||
myId = PrefUtils.getUserId(getApplicationContext());
|
||||
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
if (shouldFetchNewCoords) {
|
||||
checkIfUsesCanBeTutor();
|
||||
fetchTopCoords();
|
||||
}
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, mInterval);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
selectLocationButton = findViewById(R.id.select_location_button);
|
||||
removeLocationButton = findViewById(R.id.remove_location_button);
|
||||
mapView = findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
//start background task
|
||||
handleBackgroundTaskLifeCycle();
|
||||
manualLocationUtils = new ManualLocationUtils(MapActivity.this);
|
||||
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
|
||||
if(isTutor){
|
||||
MapUtils.BatteryOptimizationsExceptionCheck(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
MapActivity.this.mapboxMap = mapboxMap;
|
||||
mStatusChecker.run();
|
||||
enableLocationPlugin();
|
||||
|
||||
mapboxMap.setOnMarkerClickListener(marker -> {
|
||||
String id = markerUserHash.get(marker.getId());
|
||||
createMarkerModal(id);
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
if (isTutor) {
|
||||
setOnMapLongClickListener();
|
||||
}
|
||||
|
||||
|
||||
setOnMapClickListener();
|
||||
MapUtils.setMapBoundsArea(getApplicationContext(), mapboxMap, mapView, true);
|
||||
}
|
||||
|
||||
private void updateUserHashMap(String userId, Long markerId) {
|
||||
disposable.add(userService.getUserById(userId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(t -> saveUserToHashMap(t, markerId), this::handleError));
|
||||
}
|
||||
|
||||
private void saveUserToHashMap(User user, Long markerId) {
|
||||
markerUserHash.put(markerId, user.getId());
|
||||
markerHash.get(user.getId()).getMarker().setTitle(user.getFirstName() + " " + user.getLastName());
|
||||
}
|
||||
|
||||
private void createMarkerModal(String userId) {
|
||||
disposable.add(userService.getUserById(userId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::createMarkerModalView, this::handleError));
|
||||
}
|
||||
|
||||
private void createMarkerModalView(User user) {
|
||||
String cordStatus = coordsMap.get(user.getId()).getLabel();
|
||||
String sharingLevel = coordsMap.get(user.getId()).getDisplayMode();
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.marker_modal, null);
|
||||
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
|
||||
alertDialogBuilderUserInput.setView(view);
|
||||
|
||||
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||
// User cancelled the dialog
|
||||
});
|
||||
|
||||
TextView userName = view.findViewById(R.id.userName);
|
||||
TextView status = view.findViewById(R.id.label);
|
||||
TextView sharingLevelView = view.findViewById(R.id.sharing_level);
|
||||
|
||||
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
|
||||
|
||||
if (cordStatus.equals("")) {
|
||||
status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), getString(R.string.lack_of_status)));
|
||||
} else {
|
||||
status.setText(String.format("%s: %s", getResources().getString(R.string.status_switch_title), cordStatus));
|
||||
}
|
||||
|
||||
String sharingLevelToRender = sharingLevel;
|
||||
Log.e("LOCALE",PrefUtils.getLocale(getApplicationContext()));
|
||||
|
||||
if (PrefUtils.getLocale(getApplicationContext()).equals("pl") ||
|
||||
PrefUtils.getLocale(getApplicationContext()).equals("pl-PL") ||
|
||||
PrefUtils.getLocale(getApplicationContext()).equals("[pl-PL]")) {
|
||||
if (sharingLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||
sharingLevelToRender = getString(R.string.manual_mode);
|
||||
} else if (sharingLevel.equals(SharingLevel.EXACT.toString())) {
|
||||
sharingLevelToRender = getString(R.string.exact_mode);
|
||||
} else if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
sharingLevelToRender = getString(R.string.approx_mode);
|
||||
}
|
||||
}
|
||||
|
||||
sharingLevelView.setText(String.format("%s: %s", getResources().getString(R.string.settings_location_level), sharingLevelToRender));
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
showError(error);
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = getString(R.string.network_error);
|
||||
}
|
||||
|
||||
Toast.makeText(MapActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void setOnMapClickListener() {
|
||||
|
||||
mapboxMap.addOnMapClickListener(e -> {
|
||||
removeLocationButton.setVisibility(View.GONE);
|
||||
selectLocationButton.setVisibility(View.GONE);
|
||||
restoreMapMarkers();
|
||||
});
|
||||
}
|
||||
|
||||
private void setOnMapLongClickListener() {
|
||||
|
||||
mapboxMap.addOnMapLongClickListener((LatLng latLng) -> {
|
||||
selectLocationButton.setVisibility(View.VISIBLE);
|
||||
removeLocationButton.setVisibility(View.GONE);
|
||||
|
||||
if (tmpLocalMarker == null) {
|
||||
String sharingLevel = SharingLevel.MANUAL.toString();
|
||||
Icon defaultIcon = getMapIcon(sharingLevel, myId);
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.setIcon(defaultIcon)
|
||||
.position(latLng);
|
||||
|
||||
tmpLocalMarker = mapboxMap.addMarker(markerOptions);
|
||||
new MapMarker(tmpLocalMarker, markerOptions, defaultIcon, sharingLevel);
|
||||
|
||||
} else {
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(tmpLocalMarker, "position",
|
||||
new MapUtils.LatLngEvaluator(), tmpLocalMarker.getPosition(), latLng);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.start();
|
||||
}
|
||||
|
||||
selectLocationButton.setOnClickListener((View view) -> {
|
||||
if (tmpLocalMarker != null) {
|
||||
|
||||
String approximatedLocation = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude()));
|
||||
|
||||
try {
|
||||
droppedMarkercoordinate = new Coordinate(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
approximatedLocation,
|
||||
PrefUtils.getUserFirstName(getApplicationContext()) + " " + PrefUtils.getUserLastName(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
PrefUtils.getLocationLevel(getApplicationContext())
|
||||
);
|
||||
|
||||
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
||||
EnableSharingDialog sharingDialog = new EnableSharingDialog();
|
||||
sharingDialog.show(getFragmentManager(), "Sharing");
|
||||
}
|
||||
|
||||
PrefUtils.putManualLocation(this, latLng, approximatedLocation);
|
||||
|
||||
handleBackgroundTaskLifeCycle();
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
}
|
||||
|
||||
Toast.makeText(
|
||||
MapActivity.this,
|
||||
getString(R.string.manual_location_selected),
|
||||
Toast.LENGTH_LONG
|
||||
).show();
|
||||
|
||||
selectLocationButton.setVisibility(View.GONE);
|
||||
mapboxMap.removeMarker(tmpLocalMarker);
|
||||
tmpLocalMarker = null;
|
||||
|
||||
showLocationDialog(latLng);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
public void showLocationDialog(LatLng latLng) {
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.location_modal, null);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new android.support.v7.app.AlertDialog.Builder(this);
|
||||
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
|
||||
|
||||
alertDialogBuilderUserInput
|
||||
.setPositiveButton(R.string.lbl_ok, null)
|
||||
.setNegativeButton(R.string.lbl_cancel, null);
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
|
||||
EditText modalUserInput = view.findViewById(R.id.manual_input);
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
|
||||
dismissButton.setOnClickListener(view1 -> {
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), getString(R.string.other_location));
|
||||
PrefUtils.putCurrentManualLocation(getApplicationContext(), "-1");
|
||||
|
||||
alertDialog.dismiss();
|
||||
});
|
||||
|
||||
sendButton.setOnClickListener(view1 -> {
|
||||
String body = modalUserInput.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(body)) {
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.modal_location_hint), Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
} else {
|
||||
sendLocation(body, latLng);
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), body);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
|
||||
private void sendLocation(String body, LatLng latLng) {
|
||||
PredefinedCoordinatesService predefinedCoordinatesService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class);
|
||||
|
||||
PredefinedCoordViewModel droppedMarkercoordinate = new PredefinedCoordViewModel(
|
||||
latLng.getLatitude(),
|
||||
latLng.getLongitude(),
|
||||
latLng.getAltitude(),
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(latLng.getLongitude(), latLng.getLatitude())),
|
||||
SharingLevel.PREDEFINED.toString(),
|
||||
body
|
||||
);
|
||||
|
||||
CompositeDisposable disposable = new CompositeDisposable();
|
||||
disposable.add(
|
||||
predefinedCoordinatesService.postUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), droppedMarkercoordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::SaveCurrentManualLocation, this::handleError)
|
||||
);
|
||||
}
|
||||
|
||||
private void SaveCurrentManualLocation(PredefinedCoordViewModel resp) {
|
||||
Toast.makeText(getApplicationContext(), R.string.location_saved, Toast.LENGTH_SHORT).show();
|
||||
PrefUtils.putCurrentManualLocation(getApplicationContext(), resp.getPredefinedCoordinateId());
|
||||
}
|
||||
|
||||
|
||||
private void checkIfUsesCanBeTutor(){
|
||||
disposable.add(
|
||||
userService.getSelf(myId)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<User>() {
|
||||
@Override
|
||||
public void onSuccess(User user) {
|
||||
boolean tutorFromBackend = user.getTitle().equals("tutor");
|
||||
|
||||
if(tutorFromBackend != PrefUtils.getIsTutor(getApplicationContext())){
|
||||
logout();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
private void fetchTopCoords() {
|
||||
|
||||
disposable.add(
|
||||
coordinateService.getOnlineCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(tutors -> Stream.of(tutors).
|
||||
filterNot(t -> t.getDisplayMode().equals(SharingLevel.PRESENCE.toString())).toList())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
if (tmpLocalMarker != null && coordsList.isEmpty()) {
|
||||
Log.e("MapActivity", "200 empty []");
|
||||
mapboxMap.clear();
|
||||
|
||||
}
|
||||
|
||||
ArrayList<String> tmp = new ArrayList<>();
|
||||
for (Coordinate coordinate : coordsList) {
|
||||
tmp.add(coordinate.getUserId());
|
||||
}
|
||||
|
||||
Set<String> currentCoordsIds = new HashSet<>(tmp);
|
||||
if (previousCoordsIds.isEmpty()) {
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
} else {
|
||||
// here we clear + it returns bool if sth was removed
|
||||
|
||||
previousCoordsIds.removeAll(currentCoordsIds);
|
||||
for (String toRemoveId : previousCoordsIds) {
|
||||
Log.e(tag + "delete: ", "removing: " + toRemoveId + ": " + markerHash.get(toRemoveId));
|
||||
mapboxMap.removeMarker(markerHash.get(toRemoveId).getMarker());
|
||||
markerHash.remove(toRemoveId);
|
||||
coordsMap.remove(toRemoveId);
|
||||
}
|
||||
}
|
||||
|
||||
for (Coordinate element : coordsList) {
|
||||
String id = element.getUserId();
|
||||
String newLabel = element.getLabel();
|
||||
String newSharingLevel = element.getDisplayMode();
|
||||
|
||||
Coordinate coordinate = coordsMap.get(id);
|
||||
|
||||
Log.e(tag, "hashMapSize: " + coordsMap.size());
|
||||
Log.e(tag, "markerMapSize: " + coordsMap.size());
|
||||
|
||||
if (coordinate != null) {
|
||||
|
||||
boolean isTheSameLocalization = coordinate.getLatitude().equals(element.getLatitude()) || coordinate.getLongitude().equals(element.getLongitude());
|
||||
|
||||
if (!isTheSameLocalization) {
|
||||
//Replace prev marker and animate
|
||||
Marker marker = markerHash.get(id).getMarker();
|
||||
Boolean showModalAfterAnimation = false;
|
||||
|
||||
if (marker.isInfoWindowShown()) {
|
||||
marker.hideInfoWindow();
|
||||
showModalAfterAnimation = true;
|
||||
}
|
||||
|
||||
LatLng toDestination = new LatLng(element.getLatitude(), element.getLongitude());
|
||||
|
||||
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
|
||||
new MapUtils.LatLngEvaluator(),
|
||||
marker.getPosition(),
|
||||
toDestination);
|
||||
markerAnimator.setDuration(2000);
|
||||
markerAnimator.setInterpolator(new LinearInterpolator());
|
||||
markerAnimator.start();
|
||||
|
||||
|
||||
coordsMap.put(id, element);
|
||||
marker.setPosition(toDestination);
|
||||
|
||||
|
||||
if (showModalAfterAnimation) {
|
||||
mapboxMap.selectMarker(marker);
|
||||
}
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
//Add new marker
|
||||
coordsMap.put(id, element);
|
||||
|
||||
String sharingLevel = coordsMap.get(id).getDisplayMode();
|
||||
Icon defaultIcon = getMapIcon(sharingLevel, id);
|
||||
|
||||
MarkerOptions markerOptions = new MarkerOptions()
|
||||
.setIcon(defaultIcon)
|
||||
.position(new LatLng(element.getLatitude(), element.getLongitude()));
|
||||
|
||||
Marker markerMapbox = mapboxMap.addMarker(markerOptions);
|
||||
MapMarker marker = new MapMarker(markerMapbox, markerOptions, defaultIcon, sharingLevel);
|
||||
|
||||
markerHash.put(id, marker);
|
||||
updateUserHashMap(id, marker.getMarker().getId());
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Change marker if sharing mode has been changed
|
||||
Boolean newLocalizationMode = markerHash.get(id).getMarkerType().equals(newSharingLevel);
|
||||
|
||||
if (!newLocalizationMode) {
|
||||
Icon defaultIcon = getMapIcon(newSharingLevel, id);
|
||||
MapMarker marker = markerHash.get(id);
|
||||
coordsMap.get(id).setDisplayMode(newSharingLevel);
|
||||
|
||||
marker.setDefaultIcon(defaultIcon);
|
||||
marker.restoreDefaultIcon();
|
||||
markerHash.get(id).setMarkerType(newSharingLevel);
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
coordsMap.get(id).setLabel(newLabel);
|
||||
}
|
||||
|
||||
// For next fetch
|
||||
previousCoordsIds.clear();
|
||||
previousCoordsIds.addAll(currentCoordsIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private Icon getMapIcon(String sharingLevel, String id) {
|
||||
Icon defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.exact_localization_marker);
|
||||
|
||||
if (sharingLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.approximate_localization_marker);
|
||||
} else if (sharingLevel.equals(SharingLevel.MANUAL.toString()) ||
|
||||
sharingLevel.equals(SharingLevel.PREDEFINED.toString())) {
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.manual_localization_marker);
|
||||
} else if (id.equals(myId)) {
|
||||
defaultIcon = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.my_marker);
|
||||
}
|
||||
|
||||
return defaultIcon;
|
||||
}
|
||||
|
||||
@SuppressWarnings({"MissingPermission"})
|
||||
private void enableLocationPlugin() {
|
||||
Log.e(tag, "enableLocationPlugin");
|
||||
|
||||
// Check if permissions are enabled and if not request
|
||||
if (PermissionsManager.areLocationPermissionsGranted(this)) {
|
||||
Log.e(tag, "enableLocationPlugin true");
|
||||
|
||||
|
||||
LocationComponentOptions options = LocationComponentOptions.builder(this)
|
||||
.trackingGesturesManagement(false)
|
||||
.accuracyColor(ContextCompat.getColor(this, R.color.mapboxGray))
|
||||
.build();
|
||||
|
||||
// Get an instance of the component
|
||||
locationComponent = mapboxMap.getLocationComponent();
|
||||
|
||||
Log.e(tag + "Last", locationComponent.getLastKnownLocation() + "");
|
||||
|
||||
// Activate with options
|
||||
locationComponent.activateLocationComponent(this, options);
|
||||
|
||||
// Enable to make component visible + camera animation
|
||||
// https://www.mapbox.com/android-docs/maps/overview/location-component/
|
||||
locationComponent.setLocationComponentEnabled(true);
|
||||
|
||||
// Set the component's camera mode
|
||||
locationComponent.setCameraMode(CameraMode.NONE);
|
||||
locationComponent.setRenderMode(RenderMode.COMPASS);
|
||||
|
||||
// Button 4 centring
|
||||
FloatingActionButton myLocFAB = findViewById(R.id.myLocationButton);
|
||||
myLocFAB.setVisibility(View.VISIBLE);
|
||||
myLocFAB.setOnClickListener(v -> {
|
||||
|
||||
Location lastKnownLocation = locationComponent.getLastKnownLocation();
|
||||
if (lastKnownLocation != null) {
|
||||
MapUtils.makeNewCamera(mapboxMap,
|
||||
lastKnownLocation.getLatitude(),
|
||||
lastKnownLocation.getLongitude(),
|
||||
zoomParam,
|
||||
bearingParam,
|
||||
tiltParam,
|
||||
4000);
|
||||
}
|
||||
|
||||
// Camera aniamtion
|
||||
zoomParam = (zoomParam == 17) ? 19 : 17;
|
||||
bearingParam += 90;
|
||||
tiltParam = (tiltParam == 30) ? 0 : 30;
|
||||
});
|
||||
} else {
|
||||
Log.e(tag, "enableLocationPlugin false");
|
||||
|
||||
permissionsManager = new PermissionsManager(this);
|
||||
permissionsManager.requestLocationPermissions(this);
|
||||
permissionsManager.onRequestPermissionsResult(0, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, new int[]{0});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() {
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
return R.layout.activity_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getNavigationMenuItemId() {
|
||||
return R.id.nav_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @android.support.annotation.NonNull String[] permissions, @android.support.annotation.NonNull int[] grantResults) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onExplanationNeeded(List<String> permissionsToExplain) {
|
||||
Toast.makeText(this, R.string.user_location_permission_explanation, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPermissionResult(boolean granted) {
|
||||
// if (granted) {
|
||||
// enableLocationPlugin();
|
||||
// } else {
|
||||
// Toast.makeText(this, R.string.user_location_permission_not_granted, Toast.LENGTH_LONG).show();
|
||||
// finish();
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void searchUser(String textToSearch) {
|
||||
getUserFromApi(textToSearch);
|
||||
|
||||
Log.e("LOCALE", LocaleUtils.getCurrentLocale());
|
||||
}
|
||||
|
||||
private void getUserFromApi(String userNameToSearch) {
|
||||
disposable.add(
|
||||
userService.getAllOnlineTutors()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(tutors -> Stream.of(tutors).filter(t ->
|
||||
t.toSearchAbleUserName().toLowerCase().contains(userNameToSearch.toLowerCase())).toList())
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
Log.e("USERS", String.valueOf(users));
|
||||
filterMarkers(users);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
public void filterMarkers(List<User> users) {
|
||||
restoreMapMarkers();
|
||||
|
||||
Icon markedMarker = IconFactory.getInstance(MapActivity.this).fromResource(R.drawable.search_marker);
|
||||
List<MapMarker> markersToSet = Stream.of(mapboxMap.getMarkers())
|
||||
.filter(m -> Stream.of(users).anyMatch(u -> u.getId().equals(markerUserHash.get(m.getId()))))
|
||||
.map(m -> markerUserHash.get(m.getId()))
|
||||
.map(m -> markerHash.get(m))
|
||||
.toList();
|
||||
|
||||
for (MapMarker marker : markersToSet) {
|
||||
marker.getMarker().setIcon(markedMarker);
|
||||
|
||||
if (markersToSet.size() == 1)
|
||||
mapboxMap.selectMarker(marker.getMarker());
|
||||
}
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
}
|
||||
|
||||
public void restoreMapMarkers() {
|
||||
try {
|
||||
for (Marker marker : mapboxMap.getMarkers()) {
|
||||
MapMarker markerMap = markerHash.get(markerUserHash.get(marker.getId()));
|
||||
|
||||
markerMap.restoreDefaultIcon();
|
||||
mapboxMap.deselectMarker(marker);
|
||||
}
|
||||
|
||||
mapboxMap.getMarkerViewManager().update();
|
||||
} catch (Exception e) {
|
||||
Log.e("MAP", String.valueOf(e));
|
||||
}
|
||||
}
|
||||
|
||||
public void adjustMapToSearch(Integer zoom) {
|
||||
MapUtils.setZoom(mapboxMap, zoom);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
shouldFetchNewCoords = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
shouldFetchNewCoords = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
shouldFetchNewCoords = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
shouldFetchNewCoords = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
}
|
@ -1,98 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class MapFragment extends Fragment {
|
||||
private MapView mapView;
|
||||
|
||||
|
||||
public MapFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_map, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
CoordinateService service = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// mapView.onDestroy();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class NotificationFragment extends Fragment {
|
||||
|
||||
|
||||
public NotificationFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_notification, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class ProfileFragment extends Fragment {
|
||||
|
||||
|
||||
public ProfileFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,145 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
|
||||
|
||||
public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||
|
||||
String currentLang;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
getFragmentManager().beginTransaction().replace(android.R.id.content, new MainPreferenceFragment()).commit();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
public void setLocale(String localeName) {
|
||||
Context context = LocaleHelper.setLocale(this, localeName);
|
||||
Resources res = context.getResources();
|
||||
Locale myLocale = new Locale(localeName);
|
||||
DisplayMetrics dm = res.getDisplayMetrics();
|
||||
Configuration conf = res.getConfiguration();
|
||||
conf.locale = myLocale;
|
||||
res.updateConfiguration(conf, dm);
|
||||
Intent refresh = new Intent(this, MapActivity.class);
|
||||
refresh.putExtra(currentLang, localeName);
|
||||
startActivity(refresh);
|
||||
}
|
||||
|
||||
public static class MainPreferenceFragment extends PreferenceFragment {
|
||||
@SuppressLint("ResourceType")
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.layout.pref_main);
|
||||
|
||||
Preference languagesList = findPreference(getResources().getString(R.string.key_language));
|
||||
languagesList.setDefaultValue(0);
|
||||
|
||||
if(PrefUtils.getLocale(getActivity()).equals("1")){
|
||||
languagesList.setDefaultValue(1);
|
||||
}
|
||||
|
||||
languagesList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
if (!newValue.toString().equals("0")){
|
||||
LocaleHelper.setLocale(getActivity(), "pl");
|
||||
((SettingsActivity)getActivity()).setLocale("pl");
|
||||
PrefUtils.storeLocale(getActivity(),"pl");
|
||||
LocaleHelper.setLocale(getActivity(), "pl");
|
||||
}else{
|
||||
LocaleHelper.setLocale(getActivity(), "en");
|
||||
((SettingsActivity)getActivity()).setLocale("en");
|
||||
PrefUtils.storeLocale(getActivity(),"en");
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (item.getItemId() == android.R.id.home) {
|
||||
onBackPressed();
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private static void bindPreferenceSummaryToValue(Preference preference) {
|
||||
preference.setOnPreferenceChangeListener(sBindPreferenceSummaryToValueListener);
|
||||
|
||||
sBindPreferenceSummaryToValueListener.onPreferenceChange(preference,
|
||||
PreferenceManager
|
||||
.getDefaultSharedPreferences(preference.getContext())
|
||||
.getString(preference.getKey(), ""));
|
||||
}
|
||||
|
||||
/**
|
||||
* A preference value change listener that updates the preference's summary
|
||||
* to reflect its new value.
|
||||
*/
|
||||
private static Preference.OnPreferenceChangeListener sBindPreferenceSummaryToValueListener = new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
String stringValue = newValue.toString();
|
||||
|
||||
if (preference instanceof ListPreference) {
|
||||
// For list preferences, look up the correct display value in
|
||||
// the preference's 'entries' list.
|
||||
ListPreference listPreference = (ListPreference) preference;
|
||||
int index = listPreference.findIndexOfValue(stringValue);
|
||||
|
||||
// Set the summary to reflect the new value.
|
||||
preference.setSummary(
|
||||
index >= 0
|
||||
? listPreference.getEntries()[index]
|
||||
: null);
|
||||
|
||||
} else if (preference instanceof EditTextPreference) {
|
||||
if (preference.getKey().equals("key_gallery_name")) {
|
||||
// update the changed gallery name to summary filed
|
||||
preference.setSummary(stringValue);
|
||||
}
|
||||
} else {
|
||||
preference.setSummary(stringValue);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,508 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceCategory;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.SwitchPreference;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.annimon.stream.IntPair;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedCoordinatesService;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.RightButtonPreference;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
|
||||
public class SharingFragment extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
protected SwitchPreference locationSharing;
|
||||
protected SwitchPreference statusSwitch;
|
||||
protected Preference locationMode;
|
||||
protected ListPreference manualLocationList;
|
||||
protected PreferenceCategory preferenceCategory;
|
||||
protected RightButtonPreference manualLocationButton;
|
||||
protected RightButtonPreference removeManualLocation;
|
||||
protected RightButtonPreference removeManualStatus;
|
||||
protected Preference manualStatus;
|
||||
protected ListPreference statusList;
|
||||
protected List<PredefinedCoordViewModel> predefinedCoordsList = new ArrayList<>();
|
||||
private HashMap<String, String> locationMap;
|
||||
private ArrayList<String> locationUUIDs;
|
||||
private HashMap<Integer, String> locationLevelMapping;
|
||||
private HashMap<Integer, String> statusMapping;
|
||||
private PredefinedStatusesService statusesService;
|
||||
private PredefinedCoordinatesService locationService;
|
||||
private CompositeDisposable disposable;
|
||||
private AlertDialog.Builder builder;
|
||||
private String[] statusesArray;
|
||||
private boolean statusSwitchFlag;
|
||||
private ArrayList<String> predefinedLocationsList;
|
||||
|
||||
public static SharingFragment newInstance() {
|
||||
return new SharingFragment();
|
||||
}
|
||||
|
||||
void getStatuses(CompositeDisposable disposable) {
|
||||
|
||||
disposable.add(statusesService.getUserPredefinedStatuses(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<String>>() {
|
||||
@Override
|
||||
public void onSuccess(List<String> strings) {
|
||||
statusesArray = strings.toArray(new String[strings.size()]);
|
||||
if (strings.isEmpty()) {
|
||||
disableStatusPreferences();
|
||||
} else {
|
||||
enableStatusPreferences();
|
||||
}
|
||||
// Log.d("STATUSES",Integer.toString(statusesArray.length ));
|
||||
setListPreferenceData(statusList, statusesArray, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(getApplicationContext(), R.string.error_status_fetch, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
void getLocations(CompositeDisposable disposable) {
|
||||
disposable.add(locationService.getUserPredefinedCoords(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<PredefinedCoordViewModel>>() {
|
||||
|
||||
@Override
|
||||
public void onSuccess(List<PredefinedCoordViewModel> coords) {
|
||||
|
||||
String currentCoordId = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
locationMap = new HashMap<String, String>();
|
||||
locationUUIDs = new ArrayList<String>();
|
||||
for (PredefinedCoordViewModel i : coords)
|
||||
locationMap.put(i.getPredefinedCoordinateId(), i.getName());
|
||||
for (PredefinedCoordViewModel i : coords)
|
||||
locationUUIDs.add(i.getPredefinedCoordinateId());
|
||||
List<String> predefinedLocationsNames = Stream.of(coords).map(PredefinedCoordViewModel::getName).toList();
|
||||
List<String> predefinedLocationsUUIDs = Stream.of(coords).map(PredefinedCoordViewModel::getPredefinedCoordinateId).toList();
|
||||
predefinedCoordsList.addAll(coords);
|
||||
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
|
||||
preferenceCategory.removePreference(manualLocationList);
|
||||
preferenceCategory.removePreference(removeManualLocation);
|
||||
preferenceCategory.removePreference(manualLocationButton);
|
||||
} else {
|
||||
if (!predefinedCoordsList.isEmpty()) {
|
||||
|
||||
manualLocationList.setEnabled(true);
|
||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||
removeManualLocation.setEnabled(true);
|
||||
locationSharing.setEnabled(true);
|
||||
}
|
||||
}
|
||||
String[] stringnames = predefinedLocationsNames.toArray(new String[0]);
|
||||
predefinedLocationsList = new ArrayList<>(Arrays.asList(stringnames));
|
||||
List<Integer> activesId = Stream.of(coords).indexed()
|
||||
.filter(v -> v.getSecond().getPredefinedCoordinateId().equals(currentCoordId)).map(IntPair::getFirst).toList();
|
||||
|
||||
if (activesId.size() == 0) {
|
||||
setListPreferenceData(manualLocationList, stringnames, null);
|
||||
} else {
|
||||
setListPreferenceData(manualLocationList, stringnames, activesId.get(0));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Toast.makeText(getApplicationContext(), R.string.error_location_fetch, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("ResourceType")
|
||||
@Override
|
||||
public void onCreate(final Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
addPreferencesFromResource(R.xml.pref_sharing);
|
||||
locationSharing = (SwitchPreference) findPreference("key_sharing_enabled");
|
||||
statusSwitch = (SwitchPreference) findPreference("key_status_enabled");
|
||||
locationMode = findPreference("key_location_level");
|
||||
preferenceCategory = (PreferenceCategory) findPreference("category_sharing");
|
||||
manualLocationList = (ListPreference) findPreference("key_manual_location_value");
|
||||
manualLocationButton = (RightButtonPreference) findPreference("manual_location_button");
|
||||
removeManualLocation = (RightButtonPreference) findPreference("remove_manual_location");
|
||||
builder = new AlertDialog.Builder(getActivity());
|
||||
removeManualStatus = (RightButtonPreference) findPreference("remove_manual_status");
|
||||
manualStatus = findPreference("key_manual_status");
|
||||
statusList = (ListPreference) findPreference("key_status_value");
|
||||
statusesService = ApiClient.getClient(getApplicationContext()).create(PredefinedStatusesService.class);
|
||||
locationService = ApiClient.getClient(getApplicationContext()).create(PredefinedCoordinatesService.class);
|
||||
disposable = new CompositeDisposable();
|
||||
statusesArray = new String[0];
|
||||
predefinedLocationsList = new ArrayList<String>();
|
||||
getStatuses(disposable);
|
||||
getLocations(disposable);
|
||||
locationLevelMapping = new HashMap<Integer, String>();
|
||||
locationLevelMapping.put(0, SharingLevel.PRESENCE.toString());
|
||||
locationLevelMapping.put(1, SharingLevel.APPROXIMATED.toString());
|
||||
locationLevelMapping.put(2, SharingLevel.EXACT.toString());
|
||||
locationLevelMapping.put(3, SharingLevel.MANUAL.toString());
|
||||
|
||||
statusMapping = new HashMap<Integer, String>();
|
||||
statusMapping.put(0, "available");
|
||||
statusMapping.put(1, "consultation");
|
||||
statusMapping.put(2, "busy");
|
||||
|
||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||
manualLocationList.setSummary(PrefUtils.getCurrentManualLocationName(getApplicationContext()));
|
||||
|
||||
|
||||
/** Main sharing switch**/
|
||||
locationSharing.setOnPreferenceChangeListener((buttonView, newValue) -> {
|
||||
PrefUtils.storeEnableSharingLocalization(getApplicationContext(), (Boolean) newValue);
|
||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||
return true;
|
||||
});
|
||||
|
||||
/** Sharing level list **/
|
||||
locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
((MapActivity) getActivity()).stopBackgroundLocalizationTask();
|
||||
((MapActivity) getActivity()).startBackgroundLocalizationTask();
|
||||
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
|
||||
|
||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
|
||||
if (!predefinedCoordsList.isEmpty()) {
|
||||
preferenceCategory.addPreference(manualLocationList);
|
||||
preferenceCategory.addPreference(removeManualLocation);
|
||||
}
|
||||
preferenceCategory.addPreference(manualLocationButton);
|
||||
} else {
|
||||
locationSharing.setEnabled(true);
|
||||
preferenceCategory.removePreference(manualLocationList);
|
||||
preferenceCategory.removePreference(manualLocationButton);
|
||||
preferenceCategory.removePreference(removeManualLocation);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
/** Manual location category hiding when location level is != manual **/
|
||||
|
||||
|
||||
/** Custom manual location list change listener **/
|
||||
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
CharSequence[] entries = lp.getEntries();
|
||||
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
|
||||
|
||||
//sharing dialog -> ask for start BG
|
||||
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
|
||||
EnableSharingDialog sharingDialog = new EnableSharingDialog();
|
||||
sharingDialog.show(getFragmentManager(), "Sharing");
|
||||
}
|
||||
|
||||
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation());
|
||||
PrefUtils.putCurrentManualLocation(getApplicationContext(), temp.getPredefinedCoordinateId());
|
||||
PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String) lp.getEntries()[Integer.parseInt((String) newValue)]);
|
||||
lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]);
|
||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
/** Button 'choose from map' button listener **/
|
||||
manualLocationButton.setOnPreferenceChangeListener((preference, o) -> {
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(SharingFragment.this);
|
||||
fragmentTransaction.commit();
|
||||
((MapActivity) getActivity()).updateNavigationBarState();
|
||||
return true;
|
||||
});
|
||||
statusSwitch.setOnPreferenceChangeListener((preference, newValue) -> true);
|
||||
/** Status list change listener **/
|
||||
statusList.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
ListPreference lp = (ListPreference) preference;
|
||||
CharSequence[] entries = lp.getEntries();
|
||||
PrefUtils.storeStatus(getApplicationContext(), (String) entries[Integer.parseInt((String) newValue)]);
|
||||
lp.setSummary(entries[Integer.parseInt((String) newValue)]);
|
||||
return true;
|
||||
});
|
||||
statusList.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
|
||||
if (statusesArray.length == 0) {
|
||||
builder.setTitle("nie ma wody na pustyni");
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
/** Custom status edittext change listener **/
|
||||
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
|
||||
disposable.add(statusesService.postUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), (String) newValue)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
|
||||
return true;
|
||||
});
|
||||
removeManualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||
showRemoveDialog(statusList.getEntries(), "status");
|
||||
return true;
|
||||
});
|
||||
|
||||
removeManualLocation.setOnPreferenceChangeListener(((preference, newValue) -> {
|
||||
showRemoveDialog(manualLocationList.getEntries(), "location");
|
||||
return true;
|
||||
|
||||
}));
|
||||
}
|
||||
|
||||
public void showRemoveDialog(CharSequence[] entries, String service) {
|
||||
boolean[] checked = new boolean[entries.length];
|
||||
ArrayList<String> tobeDeleted = new ArrayList<String>();
|
||||
// Log.d("sharingDialog", "no to siup");
|
||||
builder.setPositiveButton("DELETE", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
if (checked[i] == true) {
|
||||
tobeDeleted.add((String) entries[i]);
|
||||
}
|
||||
}
|
||||
removeEntries(service, tobeDeleted);
|
||||
// Log.d("MANAGE-PREF",tobeDeleted.toString());
|
||||
}
|
||||
});
|
||||
builder.setMultiChoiceItems(entries, checked, new DialogInterface.OnMultiChoiceClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
Objects.requireNonNull(view).setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
protected void removeEntries(String service, ArrayList<String> toBeDeleted) {
|
||||
|
||||
// Log.d("MANAGE-PREF", toBeDeleted.toString());
|
||||
if (service.equals("status")) {
|
||||
for (String uuid : toBeDeleted) {
|
||||
disposable.add(statusesService.deleteUserPredefinedStatus(PrefUtils.getUserId(getApplicationContext()), uuid)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleDeleteStatuses, this::handleError));
|
||||
}
|
||||
} else {
|
||||
ArrayList<String> uuidsToBeDeleted = new ArrayList<String>();
|
||||
for (String name : toBeDeleted) {
|
||||
for (String uuid : locationUUIDs) {
|
||||
if (locationMap.get(uuid).equals(name)) {
|
||||
uuidsToBeDeleted.add(uuid);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (String uuid : uuidsToBeDeleted) {
|
||||
// predefinedCoordsList.removeIf(x -> x.getPredefinedCoordinateId().equals(uuid));
|
||||
predefinedCoordsList.removeAll(Stream.of(predefinedCoordsList).filter(x -> x.getPredefinedCoordinateId().equals(uuid)).toList());
|
||||
disposable.add(locationService.deleteUserPredefinedCoord(PrefUtils.getUserId(getApplicationContext()), uuid)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleDeleteLocations, this::handleError));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void setListPreferenceData(ListPreference lp, String[] entries, Integer activeId) {
|
||||
|
||||
try {
|
||||
lp.setEntries(entries);
|
||||
CharSequence[] entryValues = new CharSequence[entries.length];
|
||||
|
||||
for (int i = 0; i < entries.length; i++) {
|
||||
entryValues[i] = Integer.toString(i);
|
||||
}
|
||||
|
||||
lp.setDefaultValue(0);
|
||||
lp.setEntryValues(entryValues);
|
||||
|
||||
if (entries.length > 0 && activeId != null)
|
||||
lp.setValueIndex(activeId);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.e("Failed to set listPref", e.getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
private void handleResponse(List<String> resp) {
|
||||
if (resp.size() == 1) {
|
||||
enableStatusPreferences();
|
||||
if (PrefUtils.isStatusEnabled(getApplicationContext()) == false) {
|
||||
PrefUtils.enableStatus(getApplicationContext());
|
||||
statusSwitch.setChecked(true);
|
||||
}
|
||||
}
|
||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||
setListPreferenceData(statusList, statusesArray, resp.size() - 1);
|
||||
statusList.setValueIndex(resp.size() - 1);
|
||||
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1));
|
||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
if (error instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
Toast.makeText(getApplicationContext(),
|
||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
private void handleDeleteStatuses(List<String> resp) {
|
||||
if (resp.isEmpty()) {
|
||||
disableStatusPreferences();
|
||||
} else {
|
||||
String[] statusesArray = resp.toArray(new String[resp.size()]);
|
||||
setListPreferenceData(statusList, statusesArray, null);
|
||||
String currentEntry = PrefUtils.getUserStatus(getApplicationContext());
|
||||
if (resp.contains(currentEntry)) {
|
||||
statusList.setValueIndex(resp.indexOf(currentEntry));
|
||||
} else {
|
||||
statusList.setValueIndex(0);
|
||||
statusList.setSummary(resp.get(0));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void handleDeleteLocations(List<PredefinedCoordViewModel> resp) {
|
||||
getLocations(disposable);
|
||||
String currentEntry = PrefUtils.getCurrentManualLocation(getApplicationContext());
|
||||
if (resp.isEmpty()) {
|
||||
disableManualLocationPreferences();
|
||||
} else {
|
||||
if (!Stream.of(resp).filter(x -> x.getName().equals(currentEntry)).toList().isEmpty()) {
|
||||
for (PredefinedCoordViewModel location : resp) {
|
||||
if (location.getName().equals(currentEntry)) {
|
||||
manualLocationList.setValueIndex(resp.indexOf(location));
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
manualLocationList.setValueIndex(0);
|
||||
manualLocationList.setSummary(resp.get(0).getName());
|
||||
//todo czy na pewno w shared pref sa dobre wartosci
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void disableStatusPreferences() {
|
||||
removeManualStatus.setEnabled(false);
|
||||
statusList.setEnabled(false);
|
||||
statusSwitch.setEnabled(false);
|
||||
statusList.setSummary("");
|
||||
PrefUtils.disableStatus(getApplicationContext());
|
||||
|
||||
}
|
||||
|
||||
private void enableStatusPreferences() {
|
||||
removeManualStatus.setEnabled(true);
|
||||
statusList.setEnabled(true);
|
||||
statusSwitch.setEnabled(true);
|
||||
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
|
||||
}
|
||||
|
||||
private void disableManualLocationPreferences() {
|
||||
removeManualLocation.setEnabled(false);
|
||||
manualLocationList.setEnabled(false);
|
||||
manualLocationList.setSummary("");
|
||||
locationSharing.setChecked(false);
|
||||
locationSharing.setEnabled(false);
|
||||
PrefUtils.disableSharing(getApplicationContext());
|
||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||
|
||||
}
|
||||
|
||||
private void enableManualLocationPreferences() {
|
||||
removeManualLocation.setEnabled(true);
|
||||
manualLocationList.setEnabled(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
locationSharing.setChecked(PrefUtils.isEnableSharingLocalization(getApplicationContext()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
public abstract class SpecialList extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState){
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(getContentViewId());
|
||||
|
||||
}
|
||||
|
||||
abstract int getContentViewId();
|
||||
|
||||
|
||||
}
|
@ -1,45 +1,73 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.PowerManager;
|
||||
import android.provider.Settings;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.widget.ScrollView;
|
||||
import android.widget.Toast;
|
||||
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class StartupActivity extends AppCompatActivity {
|
||||
private static final int AUTHENTICATION_REQUEST_CODE = 666;
|
||||
String currentLang;
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
if (isLoggedIn()) {
|
||||
Intent startupIntent = new Intent(this, MainActivity.class);
|
||||
if (PrefUtils.isLoggedIn(getApplicationContext())){
|
||||
Intent startupIntent = new Intent(this, MapActivity.class);
|
||||
PrefUtils.storeLocale(getApplicationContext(),PrefUtils.getLocale(getApplicationContext()));
|
||||
startupIntent.putExtra(currentLang, PrefUtils.getLocale(getApplicationContext()));
|
||||
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(startupIntent);
|
||||
finish();
|
||||
} else {
|
||||
Intent loginIntent = new Intent(this, LoginActivity.class);
|
||||
startActivityForResult(loginIntent, AUTHENTICATION_REQUEST_CODE);
|
||||
|
||||
}
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
private boolean isLoggedIn() {
|
||||
return PrefUtils.getIsTutor(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||
Intent startupIntent = new Intent(this, MainActivity.class);
|
||||
Intent startupIntent = new Intent(this, MapActivity.class);
|
||||
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(startupIntent);
|
||||
}
|
||||
|
||||
finish();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,49 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.app.TimePickerDialog;
|
||||
import android.os.Bundle;
|
||||
import android.text.format.DateFormat;
|
||||
import android.widget.TextView;
|
||||
import android.widget.TimePicker;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public class TimePickerFragment extends DialogFragment
|
||||
implements TimePickerDialog.OnTimeSetListener {
|
||||
private TextView textView;
|
||||
private String field;
|
||||
private DutyHourViewModel duty;
|
||||
@SuppressLint("ValidFragment")
|
||||
public TimePickerFragment(TextView view, DutyHourViewModel duty, String field){
|
||||
this.textView = view;
|
||||
this.duty=duty;
|
||||
this.field=field;
|
||||
}
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
// Use the current time as the default values for the picker
|
||||
final Calendar c = Calendar.getInstance();
|
||||
int hour = c.get(Calendar.HOUR_OF_DAY);
|
||||
int minute = c.get(Calendar.MINUTE);
|
||||
|
||||
// Create a new instance of TimePickerDialog and return it
|
||||
return new TimePickerDialog(getActivity(), this, hour, minute,
|
||||
DateFormat.is24HourFormat(getActivity()));
|
||||
}
|
||||
|
||||
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
|
||||
String time = String.format("%d:%02d",hourOfDay,minute);
|
||||
textView.setText(time);
|
||||
if(field.equals("start")){
|
||||
duty.setStart(time);
|
||||
}else{
|
||||
duty.setEnd(time);
|
||||
}
|
||||
// Do something with the time chosen by the user
|
||||
}
|
||||
}
|
303
app/src/main/java/com/uam/wmi/findmytutor/activity/TutorTab.java
Normal file
@ -0,0 +1,303 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TextInputEditText;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.adapters.DutyHoursAdapter;
|
||||
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.TutorTabApi;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Response;
|
||||
import static java.lang.String.valueOf;
|
||||
|
||||
public class TutorTab extends AppCompatActivity {
|
||||
private TutorTabApi tutorTabService;
|
||||
private UserService userService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private TextView userName;
|
||||
private TextView userDutyHours;
|
||||
private TextInputEditText userNote;
|
||||
private TextView userRoom;
|
||||
private TextView userEmail;
|
||||
private TextView department;
|
||||
private Button addDutyButton;
|
||||
private Button saveButon;
|
||||
private Button scrapButton;
|
||||
private Boolean ifTutorTabExists = true;
|
||||
private List<DutyHourViewModel> dutyHourList;
|
||||
private RecyclerView dutyHoursRecycller;
|
||||
private DutyHoursAdapter dutyHoursAdapter;
|
||||
private RecyclerView.LayoutManager dutyHoursLayoutManager;
|
||||
private TutorTabViewModel newTab;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
setContentView(R.layout.content_tutor_tab);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(R.string.profile_activity_title);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
userName = findViewById(R.id.userName);
|
||||
userNote = findViewById(R.id.userNote);
|
||||
userRoom = findViewById(R.id.userRoom);
|
||||
userEmail = findViewById(R.id.userEmail);
|
||||
department = findViewById(R.id.userDepartment);
|
||||
saveButon = findViewById(R.id.saveButton);
|
||||
scrapButton = findViewById(R.id.scrapTutorTab);
|
||||
addDutyButton = findViewById(R.id.addDuty);
|
||||
dutyHoursRecycller = findViewById(R.id.dutyHourView);
|
||||
dutyHoursLayoutManager = new LinearLayoutManager(this);
|
||||
dutyHoursRecycller.setLayoutManager(dutyHoursLayoutManager);
|
||||
|
||||
tutorTabService = ApiClient.getClient(getApplicationContext())
|
||||
.create(TutorTabApi.class);
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
getTutorTab();
|
||||
|
||||
userName.setText(String.format("%s %s", PrefUtils.getUserFirstName(getApplicationContext()), PrefUtils.getUserLastName(getApplicationContext())));
|
||||
|
||||
disposable.add(
|
||||
userService.getUserById(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<User>() {
|
||||
@Override
|
||||
public void onSuccess(User user) {
|
||||
department.setText(user.getDepartment());
|
||||
Log.d("TUTORTAB", (user.getDepartment()));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
setUpSaveListener(saveButon);
|
||||
scrapButton.setOnClickListener(view -> scrapTutorTab());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_profile, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if (item.getItemId()==R.id.action_profile_info_popup){
|
||||
int layoutID = R.layout.info_popup_tutor_tab;
|
||||
|
||||
View popupView = getLayoutInflater().inflate(layoutID,null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(popupView,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
// If the PopupWindow should be focusable
|
||||
popupWindow.setFocusable(true);
|
||||
// If you need the PopupWindow to dismiss when when touched outside
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable());
|
||||
// Get the View's(the one that was clicked in the Fragment) location
|
||||
View anchorView= getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
popupWindow.showAtLocation(anchorView,Gravity.TOP|Gravity.END, 0, 0);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void getTutorTab(){
|
||||
disposable.add(
|
||||
tutorTabService.apiUsersTutorTabByTutorIdGet(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
|
||||
@Override
|
||||
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
|
||||
|
||||
dutyHourList = tutorTabViewModel.getDutyHours();
|
||||
if(dutyHourList != null){
|
||||
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),dutyHourList, getFragmentManager());
|
||||
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
|
||||
addDutyButton.setOnClickListener(v -> addEmptyDuty(dutyHoursAdapter));
|
||||
}
|
||||
userRoom.setText(String.format("%s", tutorTabViewModel.getRoom()));
|
||||
userEmail.setText(String.format("%s", tutorTabViewModel.getEmailTutorTab()));
|
||||
if (!tutorTabViewModel.getNote().equals("")) {
|
||||
userNote.setText(String.format("%s", tutorTabViewModel.getNote()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
int code = 0;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
code = ((HttpException) e).response().code();
|
||||
}
|
||||
|
||||
if( code == 404){
|
||||
ifTutorTabExists = false;
|
||||
dutyHoursAdapter = new DutyHoursAdapter(getApplicationContext(),new ArrayList<DutyHourViewModel>(), getFragmentManager());
|
||||
dutyHoursRecycller.setAdapter(dutyHoursAdapter);
|
||||
addDutyButton.setOnClickListener(v -> addEmptyDuty(dutyHoursAdapter));
|
||||
}
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private void addEmptyDuty(DutyHoursAdapter adapter){
|
||||
adapter.addDuty(new DutyHourViewModel());
|
||||
adapter.notifyItemInserted(adapter.getItemCount());
|
||||
dutyHoursRecycller.scrollToPosition(adapter.getItemCount()-1);
|
||||
}
|
||||
|
||||
private void setUpSaveListener(Button button) {
|
||||
button.setOnClickListener(view -> {
|
||||
if( isEmailValid(userEmail.getText().toString())){
|
||||
newTab = new TutorTabViewModel(PrefUtils.getUserId(getApplicationContext()),
|
||||
userRoom.getText().toString(),
|
||||
userEmail.getText().toString(),
|
||||
userNote.getText().toString(),
|
||||
dutyHoursAdapter.getDutyList());
|
||||
if(ifTutorTabExists){
|
||||
putUserTab(newTab);
|
||||
}else{
|
||||
postUserTab(newTab);
|
||||
ifTutorTabExists=true;
|
||||
}
|
||||
}else{
|
||||
userEmail.setError(getString(R.string.error_invalid_email));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void putUserTab(TutorTabViewModel tutorTabViewModel) {
|
||||
disposable.add(tutorTabService.apiUsersTutorTabByTutorIdPut(PrefUtils.getUserId(getApplicationContext()), tutorTabViewModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponsePut, this::handleError));
|
||||
}
|
||||
|
||||
private void postUserTab(TutorTabViewModel tutorTabViewModel) {
|
||||
disposable.add(tutorTabService.apiUsersTutorTabByTutorIdPost(PrefUtils.getUserId(getApplicationContext()), tutorTabViewModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponsePost, this::handleError));
|
||||
}
|
||||
private void scrapTutorTab() {
|
||||
|
||||
disposable.add(tutorTabService.apiUsersScrapTutorTabByTutorIdPost(PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponseScrap, this::handleError));
|
||||
|
||||
}
|
||||
|
||||
private void handleResponseScrap() {
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.scrap_tutor_msg), Toast.LENGTH_SHORT).show();
|
||||
getTutorTab();
|
||||
}
|
||||
|
||||
private void handleResponsePut(Response<Void> resp) {
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void handleResponsePost(TutorTabViewModel tutorTabViewModel ) {
|
||||
Toast.makeText(getApplicationContext(), getApplicationContext().getString(R.string.updateToast), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
if (error instanceof HttpException) {
|
||||
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
Toast.makeText(getApplicationContext(),
|
||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(),
|
||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
|
||||
Log.e("WMI SUCC", String.valueOf(error));
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = "Network Error!";
|
||||
}
|
||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
public boolean isEmailValid(String email)
|
||||
{
|
||||
String regExpn =
|
||||
"^(([\\w-]+\\.)+[\\w-]+|([a-zA-Z]{1}|[\\w-]{2,}))@"
|
||||
+"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
|
||||
+"[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\."
|
||||
+"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\\.([0-1]?"
|
||||
+"[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
|
||||
+"([a-zA-Z]+[\\w-]+\\.)+[a-zA-Z]{2,4})$";
|
||||
|
||||
CharSequence inputStr = email;
|
||||
|
||||
Pattern pattern = Pattern.compile(regExpn,Pattern.CASE_INSENSITIVE);
|
||||
Matcher matcher = pattern.matcher(inputStr);
|
||||
|
||||
return matcher.matches();
|
||||
}
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
//import android.app.Fragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentTabHost;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
public class TutorsListTab extends Fragment {
|
||||
private FragmentTabHost mTabHost;
|
||||
|
||||
public TutorsListTab() {
|
||||
}
|
||||
|
||||
public static TutorsListTab newInstance() {
|
||||
return new TutorsListTab();
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
}
|
||||
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View rootView = inflater.inflate(R.layout.tutors_list_tabs, container, false);
|
||||
|
||||
mTabHost = rootView.findViewById(android.R.id.tabhost);
|
||||
mTabHost.setup(getActivity(), getFragmentManager(), R.id.realtabcontent);
|
||||
|
||||
mTabHost.addTab(mTabHost.newTabSpec("fragmentb").setIndicator("Fragment B"),
|
||||
UsersListFragment.class, null);
|
||||
mTabHost.addTab(mTabHost.newTabSpec("fragmentc").setIndicator("Fragment C"),
|
||||
UsersListFragment.class, null);
|
||||
|
||||
|
||||
|
||||
return rootView;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,481 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.CoordinatorLayout;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.SearchView;
|
||||
import android.text.Spannable;
|
||||
import android.text.SpannableString;
|
||||
import android.text.format.DateFormat;
|
||||
import android.text.style.ImageSpan;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
import com.github.ybq.android.spinkit.SpinKitView;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.adapters.TutorsListAdapter;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.TutorTabApi;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.ActiveFragment;
|
||||
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class UsersListFragment extends Fragment {
|
||||
private static final String TAG = UsersListFragment.class.getSimpleName();
|
||||
|
||||
@BindView(R.id.coordinator_layout)
|
||||
CoordinatorLayout coordinatorLayout;
|
||||
@BindView(R.id.recycler_view)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.txt_empty_notes_view)
|
||||
TextView noNotesView;
|
||||
@BindView(R.id.loader)
|
||||
SpinKitView loader;
|
||||
|
||||
private SearchView searchView;
|
||||
private UserService userService;
|
||||
private TutorTabApi tutorTabService;
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private TutorsListAdapter mAdapter;
|
||||
private List<User> tutorsList = new ArrayList<>();
|
||||
private HashMap<String, String> tutorsTimeStamps = new HashMap<>();
|
||||
|
||||
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
||||
private Boolean fetchOnlyOnlineUsers = PrefUtils.getShowOnlyOnlineUsers(getApplicationContext());
|
||||
|
||||
public UsersListFragment() {
|
||||
}
|
||||
|
||||
public static UsersListFragment newInstance() {
|
||||
return new UsersListFragment();
|
||||
}
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
mAdapter = new TutorsListAdapter(getActivity().getApplicationContext(), tutorsList, tutorsTimeStamps);
|
||||
View view = inflater.inflate(R.layout.users_list, container, false);
|
||||
view.setBackgroundColor(getResources().getColor(android.R.color.white));
|
||||
setHasOptionsMenu(true);
|
||||
return view;
|
||||
}
|
||||
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
ButterKnife.bind(this, view);
|
||||
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
tutorTabService = ApiClient.getClient(getActivity().getApplicationContext())
|
||||
.create(TutorTabApi.class);
|
||||
coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
RecyclerView.LayoutManager mLayoutManager = new LinearLayoutManager(getActivity());
|
||||
recyclerView.setLayoutManager(mLayoutManager);
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.setVerticalScrollBarEnabled(true);
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(getActivity(), LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
|
||||
fetchAllTutors();
|
||||
fetchTopCords();
|
||||
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(getActivity().getApplicationContext(),
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
showNoteDialog(tutorsList.get(position));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
}
|
||||
}));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onPrepareOptionsMenu(Menu menu) {
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
try {
|
||||
menu.findItem(R.id.showOnlineUsersOnly).setChecked(fetchOnlyOnlineUsers);
|
||||
} catch (Exception e) {
|
||||
Log.e(TAG, "onPrepareOptionsMenu error");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
//item.setChecked(fetchOnlyOnlineUsers);
|
||||
switch (item.getItemId()) {
|
||||
case R.id.showOnlineUsersOnly:
|
||||
|
||||
if (item.isChecked()) {
|
||||
fetchOnlyOnlineUsers = false;
|
||||
item.setChecked(false);
|
||||
} else {
|
||||
item.setChecked(true);
|
||||
fetchOnlyOnlineUsers = true;
|
||||
}
|
||||
|
||||
PrefUtils.putShowOnlyOnlineUsers(getApplicationContext(), fetchOnlyOnlineUsers);
|
||||
fetchAllTutors();
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.users_list_menu, menu);
|
||||
menu.getItem(0).setChecked(fetchOnlyOnlineUsers);
|
||||
|
||||
MenuItem myActionMenuItem = menu.findItem(R.id.action_search);
|
||||
searchView = (SearchView) myActionMenuItem.getActionView();
|
||||
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
public void searchUser(String textToSearch) {
|
||||
searchTutorInBackend(textToSearch);
|
||||
}
|
||||
|
||||
private void showNoteDialog(final User user) {
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
|
||||
View view = layoutInflaterAndroid.inflate(R.layout.user_list_modal, null);
|
||||
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(getActivity());
|
||||
alertDialogBuilderUserInput.setView(view);
|
||||
|
||||
alertDialogBuilderUserInput.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||
// User cancelled the dialog
|
||||
});
|
||||
|
||||
|
||||
TextView userName = view.findViewById(R.id.userName);
|
||||
ListView userDutyHours = view.findViewById(R.id.userDutyHours);
|
||||
TextView userDutyHoursTitle = view.findViewById(R.id.userDutyHoursTitle);
|
||||
TextView userNote = view.findViewById(R.id.userNote);
|
||||
TextView userRoom = view.findViewById(R.id.userRoom);
|
||||
TextView userEmail = view.findViewById(R.id.userEmail);
|
||||
TextView department = view.findViewById(R.id.userDepartment);
|
||||
TextView userStatusLabel = view.findViewById(R.id.user_status_label);
|
||||
LinearLayout userStatusLabelLL = view.findViewById(R.id.user_status_label_linearLayout);
|
||||
|
||||
|
||||
|
||||
userName.setText(String.format("%s %s", user.getFirstName(), user.getLastName()));
|
||||
Drawable image;
|
||||
if (user.isIsOnline()) {
|
||||
image = this.getResources().getDrawable(R.drawable.user_list_online);
|
||||
} else {
|
||||
image = this.getResources().getDrawable(R.drawable.user_list_offline);
|
||||
}
|
||||
|
||||
if (!user.isIsActive()) {
|
||||
image = this.getResources().getDrawable(R.drawable.user_list_off);
|
||||
}
|
||||
|
||||
Spannable span = new SpannableString(" " + userName.getText()); // or set your text manually
|
||||
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
|
||||
ImageSpan imageSpan = new ImageSpan(image);
|
||||
span.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
|
||||
userName.setText(span);
|
||||
|
||||
UsersListFragment usersListFragment = this;
|
||||
disposable.add(
|
||||
tutorTabService.apiUsersTutorTabByTutorIdGet(user.getId())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<TutorTabViewModel>() {
|
||||
@Override
|
||||
public void onSuccess(TutorTabViewModel tutorTabViewModel) {
|
||||
final AlertDialog alertDialog;
|
||||
if (((MapActivity) getActivity()).coordsMap.containsKey(user.getId())) {
|
||||
|
||||
alertDialogBuilderUserInput.setPositiveButton(R.string.show_on_map, (dialog, id) -> {
|
||||
// User cancelled the dialog
|
||||
((MapActivity) getActivity()).activeFragment = ActiveFragment.NONE;
|
||||
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
|
||||
fragmentTransaction.hide(usersListFragment);
|
||||
fragmentTransaction.commit();
|
||||
((MapActivity) getActivity()).searchUser(user.getFirstName());
|
||||
((MapActivity) getActivity()).updateNavigationBarState();
|
||||
});
|
||||
}
|
||||
alertDialog = alertDialogBuilderUserInput.create();
|
||||
|
||||
String userNoteText = tutorTabViewModel.getNote();
|
||||
List<String> dutyHoursList = Stream.of(tutorTabViewModel.getDutyHours())
|
||||
.map(DutyHourViewModel::getSummary).toList();
|
||||
|
||||
if (dutyHoursList.isEmpty()) {
|
||||
dutyHoursList.add(getString(R.string.lack_duty_hours));
|
||||
}
|
||||
|
||||
if (tutorTabViewModel.getNote().isEmpty()) {
|
||||
userNoteText = getString(R.string.lack_note);
|
||||
}
|
||||
|
||||
userRoom.setText(String.format("%s: %s", getString(R.string.userRoom), tutorTabViewModel.getRoom()));
|
||||
userEmail.setText(String.format("%s: %s", getString(R.string.userEmail), tutorTabViewModel.getEmailTutorTab()));
|
||||
userNote.setText(String.format("%s: %s", getString(R.string.userNote), userNoteText));
|
||||
department.setText(String.format("%s: %s", getString(R.string.userDepartment), user.getDepartment()));
|
||||
userDutyHoursTitle.setText(String.format("%s:", getString(R.string.userDutyHoursHeader)));
|
||||
|
||||
Coordinate coordinate = ((MapActivity) getActivity()).coordsMap.get(user.getId());
|
||||
if (coordinate != null){
|
||||
String label = coordinate.getLabel();
|
||||
if (!label.isEmpty()) {
|
||||
userStatusLabelLL.setVisibility(View.VISIBLE);
|
||||
userStatusLabel.setText(String.format("%s: %s", getString(R.string.user_status_label),label));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(getActivity(),
|
||||
R.layout.duty_hours_item, dutyHoursList);
|
||||
|
||||
userDutyHours.setAdapter(arrayAdapter);
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
private void fetchAllTutors() {
|
||||
disposable.add(
|
||||
(fetchOnlyOnlineUsers ?
|
||||
userService.getAllActiveTutors() :
|
||||
userService.getAllTutors())
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.map(this::mapUsersToSortedList)
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
tutorsList.clear();
|
||||
tutorsList.addAll(users);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
toggleEmptyNotes();
|
||||
fetchTopCords();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
private List<User> mapUsersToSortedList(List<User> tutors) {
|
||||
List<User> tutorsList = new ArrayList<>(tutors);
|
||||
List<User> onlineTutors = Stream.of(tutorsList).filter(User::isIsOnline).toList();
|
||||
List<User> activeNotOnlineTutors = Stream.of(tutorsList)
|
||||
.filter(t -> t.isIsActive() && !onlineTutors.contains(t)).toList();
|
||||
List<User> notActiveTutors = Stream.of(tutorsList)
|
||||
.filterNot(User::isIsActive).toList();
|
||||
|
||||
Collections.sort(onlineTutors, this::sortByUserName);
|
||||
Collections.sort(activeNotOnlineTutors, this::sortByUserName);
|
||||
Collections.sort(notActiveTutors, this::sortByUserName);
|
||||
|
||||
List<User> sortedUserList = new ArrayList<>(onlineTutors);
|
||||
sortedUserList.addAll(activeNotOnlineTutors);
|
||||
sortedUserList.addAll(notActiveTutors);
|
||||
|
||||
return sortedUserList;
|
||||
}
|
||||
|
||||
private void searchTutorInBackend(String searchString) {
|
||||
disposable.add(
|
||||
userService.searchUser(searchString)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<User>>() {
|
||||
@Override
|
||||
public void onSuccess(List<User> users) {
|
||||
tutorsList.clear();
|
||||
tutorsList.addAll(users);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
showSearchError(e);
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
public void restoreUsersList() {
|
||||
fetchAllTutors();
|
||||
fetchTopCords();
|
||||
}
|
||||
|
||||
private int sortByUserName(User t1, User t2) {
|
||||
return plCollator.compare(t1.getLastName(), t2.getLastName());
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
Log.e(TAG, String.valueOf(e));
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = getString(R.string.network_err);
|
||||
}
|
||||
|
||||
createSnackbar(message);
|
||||
}
|
||||
|
||||
private void showSearchError(Throwable e) {
|
||||
String message;
|
||||
Log.e(TAG, String.valueOf(e));
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = getString(R.string.search_null);
|
||||
}
|
||||
|
||||
createSnackbar(message);
|
||||
}
|
||||
|
||||
private void createSnackbar(String msg) {
|
||||
Snackbar snackbar = Snackbar.make(coordinatorLayout, msg, Snackbar.LENGTH_LONG);
|
||||
View view = snackbar.getView();
|
||||
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams) view.getLayoutParams();
|
||||
params.gravity = Gravity.TOP;
|
||||
view.setLayoutParams(params);
|
||||
snackbar.show();
|
||||
}
|
||||
|
||||
private void toggleEmptyNotes() {
|
||||
loader.setVisibility(View.GONE);
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
|
||||
if (tutorsList.size() == 0) {
|
||||
noNotesView.setVisibility(View.VISIBLE);
|
||||
if (fetchOnlyOnlineUsers)
|
||||
noNotesView.setText(R.string.no_online_users);
|
||||
else {
|
||||
noNotesView.setText(R.string.no_offline_users);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
private void fetchTopCords(){
|
||||
disposable.add(
|
||||
coordinateService.getTopCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::addTimestamps,this::showError));
|
||||
}
|
||||
|
||||
private void addTimestamps(List<Coordinate> coordinates) {
|
||||
for (Coordinate crd :
|
||||
coordinates) {
|
||||
Long ts = crd.getTimeStamp();
|
||||
tutorsTimeStamps.put(crd.getUserId(), getDate(ts));
|
||||
}
|
||||
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private String getDate(long time) {
|
||||
Calendar cal = Calendar.getInstance(Locale.ENGLISH);
|
||||
cal.setTimeInMillis(time);
|
||||
return DateFormat.format("HH:mm dd/MM", cal).toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
fetchAllTutors();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,363 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.DefaultItemAnimator;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.ybq.android.spinkit.SpinKitView;
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.adapters.WhiteListAdapter;
|
||||
import com.uam.wmi.findmytutor.model.IsUsingListBool;
|
||||
import com.uam.wmi.findmytutor.model.StudentIdModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.LocaleHelper;
|
||||
import com.uam.wmi.findmytutor.utils.MyDividerItemDecoration;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RecyclerTouchListener;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
import com.uam.wmi.findmytutor.utils.WrapContentLinearLayoutManager;
|
||||
|
||||
import java.text.Collator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableSource;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.disposables.Disposable;
|
||||
import io.reactivex.functions.Function;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class WhiteList extends AppCompatActivity {
|
||||
|
||||
@BindView(R.id.recycler_view_whitelist)
|
||||
RecyclerView recyclerView;
|
||||
@BindView(R.id.white_list_empty_text_view)
|
||||
TextView noNotesView;
|
||||
@BindView(R.id.switch_whitelist_toggle)
|
||||
Switch aSwitch;
|
||||
@BindView(R.id.add_to_white_list_fab)
|
||||
FloatingActionButton addToWhiteListFab;
|
||||
|
||||
@BindView(R.id.loader)
|
||||
SpinKitView loader;
|
||||
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private UserService userService;
|
||||
private boolean didFetched = false;
|
||||
private String tutorId;
|
||||
private WhiteListAdapter mAdapter;
|
||||
private Integer prevSize;
|
||||
private List<User> whitelistedUsers = new ArrayList<>();
|
||||
private Collator plCollator = Collator.getInstance(Locale.forLanguageTag("pl-PL"));
|
||||
|
||||
@Override
|
||||
protected void attachBaseContext(Context base) {
|
||||
super.attachBaseContext(LocaleHelper.onAttach(base));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
setContentView(R.layout.activity_white_list);
|
||||
ButterKnife.bind(this);
|
||||
|
||||
tutorId = PrefUtils.getUserId(getApplicationContext());
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
|
||||
if (PrefUtils.isWhiteListing(this)) {
|
||||
aSwitch.setText(getString(R.string.action_white_list) +" "+getString(R.string.on) );
|
||||
aSwitch.setChecked(true);
|
||||
handleChangeRequest(true);
|
||||
} else {
|
||||
aSwitch.setText(getString(R.string.action_white_list) +" "+getString(R.string.off) );
|
||||
aSwitch.setChecked(false);
|
||||
handleChangeRequest(false);
|
||||
}
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
toolbar.setTitle(getString(R.string.activity_title_whitelist));
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
mAdapter = new WhiteListAdapter(this, whitelistedUsers);
|
||||
recyclerView.setLayoutManager(new WrapContentLinearLayoutManager(getApplicationContext()));
|
||||
recyclerView.setItemAnimator(new DefaultItemAnimator());
|
||||
recyclerView.addItemDecoration(new MyDividerItemDecoration(this, LinearLayoutManager.VERTICAL, 16));
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
|
||||
/**
|
||||
* On long press on RecyclerView item, open alert dialog
|
||||
* with options to choose
|
||||
* Edit and Delete
|
||||
* */
|
||||
recyclerView.addOnItemTouchListener(new RecyclerTouchListener(this,
|
||||
recyclerView, new RecyclerTouchListener.ClickListener() {
|
||||
@Override
|
||||
public void onClick(View view, final int position) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongClick(View view, int position) {
|
||||
}
|
||||
}));
|
||||
|
||||
addToWhiteListFab.setOnClickListener(this::showFabDialog);
|
||||
fetchWhiteListedUsers();
|
||||
handleSwitch();
|
||||
}
|
||||
|
||||
private Observable<List<String>> getListOfWhitelistedUsers(String userId) {
|
||||
return userService.getTutorWhitelistedByID(userId)
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private Observable<User> getUserObservable(String userId) {
|
||||
return userService
|
||||
.getUserById(userId)
|
||||
.toObservable()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread());
|
||||
}
|
||||
|
||||
private void fetchWhiteListedUsers() {
|
||||
disposable.add(getListOfWhitelistedUsers(tutorId)
|
||||
.doOnSubscribe(this::handleDoOnSubscribe)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.flatMap(Observable::fromIterable)
|
||||
.flatMap(this::getUserObservable)
|
||||
.subscribe(user -> whitelistedUsers.add(user), this::handleError,this::handleComplete));
|
||||
}
|
||||
|
||||
private void handleDoOnSubscribe(Disposable disposable) {
|
||||
prevSize = whitelistedUsers.size();
|
||||
whitelistedUsers.clear();
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void handleComplete() {
|
||||
Collections.sort(whitelistedUsers, this::sortByUserName);
|
||||
didFetched = true;
|
||||
refreshUI();
|
||||
}
|
||||
private void handleError(Throwable e){
|
||||
showError(e);
|
||||
didFetched = false;
|
||||
}
|
||||
|
||||
private void refreshUI() {
|
||||
toggleEmptyNotes();
|
||||
mAdapter.notifyItemRangeInserted(prevSize, whitelistedUsers.size() - prevSize);
|
||||
mAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private int sortByUserName(User t1, User t2) {
|
||||
return plCollator.compare(t1.getLastName(), t2.getLastName());
|
||||
}
|
||||
|
||||
private void showFabDialog(View v) {
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getApplicationContext());
|
||||
@SuppressLint("InflateParams") View view = layoutInflaterAndroid.inflate(R.layout.white_list_fab_modal, null);
|
||||
AlertDialog.Builder alertDialogBuilderUserInput = new AlertDialog.Builder(this);
|
||||
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(getApplicationContext().getString(R.string.modal_location_send), null);
|
||||
|
||||
alertDialogBuilderUserInput
|
||||
.setPositiveButton(R.string.add, null)
|
||||
.setNegativeButton(R.string.cancel, null);
|
||||
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
|
||||
|
||||
EditText modalUserInput = view.findViewById(R.id.white_list_modal_input);
|
||||
|
||||
alertDialog.setOnShowListener(dialogInterface -> {
|
||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
|
||||
Button dismissButton = alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE);
|
||||
|
||||
dismissButton.setOnClickListener(view1 -> alertDialog.dismiss());
|
||||
|
||||
sendButton.setOnClickListener(view1 -> {
|
||||
String body = modalUserInput.getText().toString();
|
||||
|
||||
if (TextUtils.isEmpty(body)) {
|
||||
Toast.makeText(getApplicationContext(), R.string.can_not_be_empty, Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
} else {
|
||||
sendUserToWhitelist(body);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void sendUserToWhitelist(String body) {
|
||||
StudentIdModel studentIdModel = new StudentIdModel(body);
|
||||
|
||||
disposable.add(
|
||||
userService.addStudentToWhitelist(tutorId, studentIdModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleAddUser, this::showError)
|
||||
);
|
||||
}
|
||||
|
||||
private void handleAddUser(User user) {
|
||||
Toast.makeText(this, R.string.add_user_to_list, Snackbar.LENGTH_LONG).show();
|
||||
fetchWhiteListedUsers();
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
if (((HttpException) e).response().code() == 404) {
|
||||
message = getString(R.string.no_such_a_user);
|
||||
}
|
||||
} else {
|
||||
message = "Network Error !";
|
||||
}
|
||||
Log.e("ERR", message);
|
||||
Toast.makeText(this, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void toggleEmptyNotes() {
|
||||
|
||||
if (didFetched && whitelistedUsers.size() == 0) {
|
||||
noNotesView.setVisibility(View.VISIBLE);
|
||||
noNotesView.setText(R.string.list_is_empty);
|
||||
loader.setVisibility(View.GONE);
|
||||
} else if (whitelistedUsers.size() > 0) {
|
||||
noNotesView.setVisibility(View.GONE);
|
||||
loader.setVisibility(View.GONE);
|
||||
} else {
|
||||
loader.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
|
||||
if (item.getItemId() == R.id.action_whitelist_info_popup) {
|
||||
int layoutID = R.layout.info_popup_whitelist;
|
||||
|
||||
View popupView = getLayoutInflater().inflate(layoutID, null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(popupView,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
// If the PopupWindow should be focusable
|
||||
popupWindow.setFocusable(true);
|
||||
// If you need the PopupWindow to dismiss when when touched outside
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable());
|
||||
// Get the View's(the one that was clicked in the Fragment) location
|
||||
View anchorView = getWindow().getDecorView().findViewById(android.R.id.content);
|
||||
popupWindow.showAtLocation(anchorView, Gravity.TOP | Gravity.END, 0, 0);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void handleSwitch() {
|
||||
aSwitch.setOnCheckedChangeListener((buttonView, isChecked) -> {
|
||||
if (isChecked) {
|
||||
aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.on));
|
||||
handleChangeRequest(true);
|
||||
PrefUtils.useWhitelist(this, true);
|
||||
} else {
|
||||
aSwitch.setText(getString(R.string.action_white_list) + " " + getString(R.string.off));
|
||||
handleChangeRequest(false);
|
||||
PrefUtils.useWhitelist(this, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void handleChangeRequest(boolean value) {
|
||||
IsUsingListBool isUsingListBool = new IsUsingListBool();
|
||||
isUsingListBool.setIsUsing(value);
|
||||
disposable.add(
|
||||
userService.setTutorWhitelist(tutorId, isUsingListBool)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(() -> {
|
||||
}, this::showError)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.menu_white_list, menu);
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,119 @@
|
||||
package com.uam.wmi.findmytutor.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.StudentIdModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
|
||||
public class BlackListAdapter extends RecyclerView.Adapter<BlackListAdapter.MyViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<User> tutorsList;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private UserService userService;
|
||||
|
||||
public BlackListAdapter(Context context, List<User> tutors) {
|
||||
this.context = context;
|
||||
this.tutorsList = tutors;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.black_list_row, parent, false);
|
||||
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
Drawable image = null;
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(tutor.getFirstName() + " " + tutor.getLastName());
|
||||
holder.lastName.setText("Index: " + tutor.getLdapLogin() + " Email: " + tutor.getEmail());
|
||||
//"s416196"
|
||||
holder.imageButton.setOnClickListener(l ->{
|
||||
StudentIdModel studentIdModel = new StudentIdModel(tutor.getLdapLogin());
|
||||
String tutorId = PrefUtils.getUserId(getApplicationContext());
|
||||
disposable.add(
|
||||
userService.removeStudentFromBlacklist(tutorId, studentIdModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(()->{
|
||||
Toast.makeText(getApplicationContext(), R.string.user_removed, Toast.LENGTH_SHORT).show();
|
||||
tutorsList.remove(position);
|
||||
notifyDataSetChanged();
|
||||
},this::showError)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return tutorsList.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.firstName)
|
||||
TextView firstName;
|
||||
|
||||
@BindView(R.id.lastName)
|
||||
TextView lastName;
|
||||
|
||||
@BindView(R.id.removeUserImageButton)
|
||||
ImageButton imageButton;
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = "Network Error !";
|
||||
}
|
||||
|
||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,181 @@
|
||||
package com.uam.wmi.findmytutor.adapters;
|
||||
|
||||
import android.app.DialogFragment;
|
||||
import android.app.FragmentManager;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import com.annimon.stream.Collectors;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.activity.TimePickerFragment;
|
||||
import com.uam.wmi.findmytutor.model.DutyHourViewModel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class DutyHoursAdapter extends RecyclerView.Adapter<DutyHoursAdapter.MyViewHolder> {
|
||||
private Context context;
|
||||
private List<DutyHourViewModel> hours;
|
||||
private FragmentManager fragmentManager;
|
||||
|
||||
public DutyHoursAdapter(Context context, List<DutyHourViewModel> hours, FragmentManager fragmentManager) {
|
||||
this.context = context;
|
||||
this.hours = new ArrayList<DutyHourViewModel>(hours);
|
||||
this.fragmentManager = fragmentManager;
|
||||
}
|
||||
|
||||
|
||||
public List<DutyHourViewModel> getDutyList(){
|
||||
ArrayList<DutyHourViewModel> notEmpty = Stream.of(hours).filter(DutyHourViewModel::isValid).collect(Collectors.toCollection(ArrayList::new));
|
||||
return notEmpty;
|
||||
}
|
||||
public void addDuty(DutyHourViewModel duty){
|
||||
hours.add(duty);
|
||||
}
|
||||
private void removeDuty(int pos){
|
||||
hours.remove(pos);
|
||||
this.notifyItemRemoved(pos);
|
||||
Log.d("DutyIndex af rm size",Integer.toString(getItemCount()));
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.duty_hour_row, parent, false);
|
||||
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
DutyHourViewModel duty = hours.get(position);
|
||||
holder.dutyDay.setText(duty.getDay());
|
||||
holder.dutyDay.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
duty.setDay(holder.dutyDay.getText().toString());
|
||||
}
|
||||
});
|
||||
holder.dutyStart.setText(duty.getStart());
|
||||
/* holder.dutyStart.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
duty.setStart(holder.dutyStart.getText().toString());
|
||||
}
|
||||
});*/
|
||||
holder.dutyStart.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DialogFragment picker = new TimePickerFragment(holder.dutyStart,duty,"start");
|
||||
picker.show(fragmentManager,"time picker");
|
||||
}
|
||||
});
|
||||
holder.dutyStop.setText(duty.getEnd());
|
||||
holder.dutyStop.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DialogFragment picker = new TimePickerFragment(holder.dutyStop,duty,"stop");
|
||||
picker.show(fragmentManager,"time picker");
|
||||
}
|
||||
});
|
||||
/* holder.dutyStop.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
duty.setEnd(holder.dutyStop.getText().toString());
|
||||
}
|
||||
});*/
|
||||
holder.deleteRow.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
try{
|
||||
// Log.d("DutyIndex bf rm size",Integer.toString(getItemCount()));
|
||||
// Log.d("DutyIndex bf rm pos",Integer.toString(holder.getLayoutPosition()));
|
||||
removeDuty(holder.getLayoutPosition());
|
||||
// Log.d("DutyIndex af rm pos",Integer.toString(holder.getLayoutPosition()));
|
||||
|
||||
|
||||
}catch(Error e){
|
||||
// Log.e("DutyIndex error",e.getMessage());
|
||||
// Log.e("DutyIndex size",Integer.toString(getItemCount()));
|
||||
// Log.e("DutyIndex pos",Integer.toString(holder.getAdapterPosition()));
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return hours.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.duty_day_value)
|
||||
TextView dutyDay;
|
||||
|
||||
@BindView(R.id.duty_start_value)
|
||||
TextView dutyStart;
|
||||
|
||||
@BindView(R.id.duty_stop_value)
|
||||
TextView dutyStop;
|
||||
|
||||
@BindView(R.id.deleteRow)
|
||||
ImageButton deleteRow;
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
/*
|
||||
package com.uam.wmi.findmytutor.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.github.ybq.android.spinkit.SpinKitView;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.MyViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<User> tutorsList;
|
||||
private HashMap<String, String> tutorsTimeStamps;
|
||||
|
||||
public TutorsListAdapter(Context context, List<User> tutors, HashMap<String,String> tutorsTimeStamps) {
|
||||
this.context = context;
|
||||
this.tutorsList = tutors;
|
||||
this.tutorsTimeStamps = tutorsTimeStamps;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.tutor_list_row, parent, false);
|
||||
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
Drawable image = null;
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(String.format("%s %s", tutor.getFirstName(), tutor.getLastName()));
|
||||
String ts = tutorsTimeStamps.get(tutor.getId());
|
||||
|
||||
if (tutor.isIsOnline()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_online);
|
||||
holder.lastSeen.setText(R.string.available_now);
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
} else {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_offline);
|
||||
|
||||
if (ts != null){
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
holder.lastSeen.append(String.format(": %s", ts));
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (!tutor.isIsActive()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_off);
|
||||
if(ts != null){
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
holder.lastSeen.append(String.format(": %s", ts));
|
||||
}else{
|
||||
holder.lastSeen.setVisibility(View.GONE);
|
||||
}
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
|
||||
holder.isOnline.setCompoundDrawables(image, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return tutorsList.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.firstName)
|
||||
TextView firstName;
|
||||
|
||||
@BindView(R.id.lastSeen)
|
||||
TextView lastSeen;
|
||||
|
||||
@BindView(R.id.isOnline)
|
||||
TextView isOnline;
|
||||
|
||||
@BindView(R.id.loader)
|
||||
SpinKitView loader;
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
||||
package com.uam.wmi.findmytutor.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.github.ybq.android.spinkit.SpinKitView;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
|
||||
public class TutorsListAdapter extends RecyclerView.Adapter<TutorsListAdapter.MyViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<User> tutorsList;
|
||||
private HashMap<String, String> tutorsTimeStamps;
|
||||
|
||||
public TutorsListAdapter(Context context, List<User> tutors, HashMap<String,String> tutorsTimeStamps) {
|
||||
this.context = context;
|
||||
this.tutorsList = tutors;
|
||||
this.tutorsTimeStamps = tutorsTimeStamps;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.tutor_list_row, parent, false);
|
||||
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
Drawable image = null;
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(String.format("%s %s", tutor.getFirstName(), tutor.getLastName()));
|
||||
String ts = tutorsTimeStamps.get(tutor.getId());
|
||||
|
||||
if (tutor.isIsOnline()) {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_online);
|
||||
holder.lastSeen.setText(R.string.available_now);
|
||||
holder.lastSeen.setVisibility(View.VISIBLE);
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
} else if(tutor.isIsActive()){
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_offline);
|
||||
|
||||
if (ts != null){
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
holder.lastSeen.append(String.format(": %s", ts));
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
}
|
||||
} else {
|
||||
image = context.getResources().getDrawable(R.drawable.user_list_off);
|
||||
|
||||
if(ts == null){
|
||||
holder.lastSeen.setText(R.string.never_logged_in);
|
||||
}else{
|
||||
holder.lastSeen.setText(R.string.last_sign);
|
||||
holder.lastSeen.append(String.format(": %s", ts));
|
||||
}
|
||||
holder.loader.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
image.setBounds(0, 0, image.getIntrinsicWidth(), image.getIntrinsicHeight());
|
||||
holder.isOnline.setCompoundDrawables(image, null, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return tutorsList.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.firstName)
|
||||
TextView firstName;
|
||||
|
||||
@BindView(R.id.lastSeen)
|
||||
TextView lastSeen;
|
||||
|
||||
@BindView(R.id.isOnline)
|
||||
TextView isOnline;
|
||||
|
||||
@BindView(R.id.loader)
|
||||
SpinKitView loader;
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -0,0 +1,117 @@
|
||||
package com.uam.wmi.findmytutor.adapters;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.StudentIdModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.UserService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.RestApiHelper;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
|
||||
public class WhiteListAdapter extends RecyclerView.Adapter<WhiteListAdapter.MyViewHolder> {
|
||||
|
||||
private Context context;
|
||||
private List<User> tutorsList;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private UserService userService;
|
||||
|
||||
public WhiteListAdapter(Context context, List<User> tutors) {
|
||||
this.context = context;
|
||||
this.tutorsList = tutors;
|
||||
}
|
||||
@NonNull
|
||||
@Override
|
||||
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
userService = ApiClient.getClient(getApplicationContext())
|
||||
.create(UserService.class);
|
||||
View itemView = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.white_list_row, parent, false);
|
||||
|
||||
return new MyViewHolder(itemView);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
|
||||
Drawable image = null;
|
||||
User tutor = tutorsList.get(position);
|
||||
|
||||
holder.firstName.setText(tutor.getFirstName() + " " + tutor.getLastName());
|
||||
holder.lastName.setText("Index: " + tutor.getLdapLogin() + " Email: " + tutor.getEmail());
|
||||
//""
|
||||
holder.imageButton.setOnClickListener(l ->{
|
||||
StudentIdModel studentIdModel = new StudentIdModel(tutor.getLdapLogin());
|
||||
String tutorId = PrefUtils.getUserId(getApplicationContext());
|
||||
disposable.add(
|
||||
userService.removeStudentFromWhitelist(tutorId, studentIdModel)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(()->{
|
||||
Toast.makeText(getApplicationContext(), R.string.user_removed, Toast.LENGTH_SHORT).show();
|
||||
tutorsList.remove(position);
|
||||
notifyDataSetChanged();
|
||||
},this::showError)
|
||||
);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return tutorsList.size();
|
||||
}
|
||||
|
||||
class MyViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
@BindView(R.id.firstName)
|
||||
TextView firstName;
|
||||
|
||||
@BindView(R.id.lastName)
|
||||
TextView lastName;
|
||||
|
||||
@BindView(R.id.removeUserImageButton)
|
||||
ImageButton imageButton;
|
||||
|
||||
MyViewHolder(View view) {
|
||||
super(view);
|
||||
ButterKnife.bind(this, view);
|
||||
}
|
||||
}
|
||||
|
||||
private void showError(Throwable e) {
|
||||
String message;
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message = "Network Error !";
|
||||
}
|
||||
Toast.makeText(getApplicationContext(), message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -3,7 +3,9 @@ package com.uam.wmi.findmytutor.model;
|
||||
import android.util.Range;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -14,11 +16,9 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
*/
|
||||
|
||||
public class Coordinate extends BaseResponse {
|
||||
Range<Double> latitudeRange = Range.create(52.466709, 52.467007);
|
||||
Range<Double> longtitudeRange = Range.create(16.926159, 16.926976);
|
||||
|
||||
@SerializedName("coordinateId")
|
||||
private UUID coordinateId = null;
|
||||
private Range<Double> latitudeRange = Const.buildingLatitudeRange;
|
||||
private Range<Double> longtitudeRange = Const.buildingLongitudeRange;
|
||||
private List<String> allowedApproximatedLocations = Const.validApproximatedLocations;
|
||||
|
||||
@SerializedName("latitude")
|
||||
private Double latitude;
|
||||
@ -44,14 +44,18 @@ public class Coordinate extends BaseResponse {
|
||||
@SerializedName("label")
|
||||
private String label;
|
||||
|
||||
public Coordinate (Double latitude, Double longitude, String label, String userId) {
|
||||
//if (!latitudeRange.contains(latitude)) throw new IllegalArgumentException("Inappropriate latitude value" + latitude);
|
||||
//if (!longtitudeRange.contains(longitude)) throw new IllegalArgumentException("Inappropriate longitude value" + longitude);
|
||||
public Coordinate (Double latitude, Double longitude, Double altitude, String approximatedLocation, String label, String userId, String displayMode) {
|
||||
if (!latitudeRange.contains(latitude)) throw new IllegalArgumentException("Inappropriate latitude value" + latitude);
|
||||
if (!longtitudeRange.contains(longitude)) throw new IllegalArgumentException("Inappropriate longitude value" + longitude);
|
||||
if (!allowedApproximatedLocations.contains(approximatedLocation)) throw new IllegalArgumentException("Inappropriate approximatedLocation");
|
||||
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.userId = userId;
|
||||
this.altitude = altitude;
|
||||
this.label = label;
|
||||
this.userId = userId;
|
||||
this.approximatedLocation = approximatedLocation;
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
public Coordinate (Double latitude) {
|
||||
@ -59,23 +63,9 @@ public class Coordinate extends BaseResponse {
|
||||
}
|
||||
|
||||
public Coordinate coordinateId(UUID coordinateId) {
|
||||
this.coordinateId = coordinateId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get coordinateId
|
||||
* @return coordinateId
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public UUID getCoordinateId() {
|
||||
return coordinateId;
|
||||
}
|
||||
|
||||
public void setCoordinateId(UUID coordinateId) {
|
||||
this.coordinateId = coordinateId;
|
||||
}
|
||||
|
||||
public Coordinate latitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
return this;
|
||||
@ -229,8 +219,7 @@ public class Coordinate extends BaseResponse {
|
||||
return false;
|
||||
}
|
||||
Coordinate coordinate = (Coordinate) o;
|
||||
return Objects.equals(this.coordinateId, coordinate.coordinateId) &&
|
||||
Objects.equals(this.latitude, coordinate.latitude) &&
|
||||
return Objects.equals(this.latitude, coordinate.latitude) &&
|
||||
Objects.equals(this.longitude, coordinate.longitude) &&
|
||||
Objects.equals(this.altitude, coordinate.altitude) &&
|
||||
Objects.equals(this.userId, coordinate.userId) &&
|
||||
@ -242,7 +231,7 @@ public class Coordinate extends BaseResponse {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(coordinateId, latitude, longitude, altitude, userId, approximatedLocation, displayMode, timeStamp, label);
|
||||
return Objects.hash( latitude, longitude, altitude, userId, approximatedLocation, displayMode, timeStamp, label);
|
||||
}
|
||||
|
||||
|
||||
@ -251,7 +240,6 @@ public class Coordinate extends BaseResponse {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class Coordinate {\n");
|
||||
|
||||
sb.append(" coordinateId: ").append(toIndentedString(coordinateId)).append("\n");
|
||||
sb.append(" latitude: ").append(toIndentedString(latitude)).append("\n");
|
||||
sb.append(" longitude: ").append(toIndentedString(longitude)).append("\n");
|
||||
sb.append(" altitude: ").append(toIndentedString(altitude)).append("\n");
|
||||
|
@ -0,0 +1,140 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
/**
|
||||
* DutyHourViewModel
|
||||
*/
|
||||
|
||||
public class DutyHourViewModel {
|
||||
@SerializedName("day")
|
||||
private String day = null;
|
||||
|
||||
@SerializedName("start")
|
||||
private String start = null;
|
||||
|
||||
@SerializedName("end")
|
||||
private String end = null;
|
||||
|
||||
public DutyHourViewModel day(String day) {
|
||||
this.day = day;
|
||||
return this;
|
||||
}
|
||||
public Boolean isValid(){
|
||||
if(this.day.isEmpty()){
|
||||
return false;
|
||||
}else if( !this.start.isEmpty() && this.end.isEmpty() ){
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
public DutyHourViewModel(){
|
||||
day="";
|
||||
start="";
|
||||
end="";
|
||||
}
|
||||
|
||||
/**
|
||||
* Get day
|
||||
* @return day
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getDay() {
|
||||
return day;
|
||||
}
|
||||
|
||||
public void setDay(String day) {
|
||||
this.day = day;
|
||||
}
|
||||
|
||||
public DutyHourViewModel start(String start) {
|
||||
this.start = start;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get start
|
||||
* @return start
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
public void setStart(String start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
public DutyHourViewModel end(String end) {
|
||||
this.end = end;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end
|
||||
* @return end
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
public void setEnd(String end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
DutyHourViewModel dutyHourViewModel = (DutyHourViewModel) o;
|
||||
return Objects.equals(this.day, dutyHourViewModel.day) &&
|
||||
Objects.equals(this.start, dutyHourViewModel.start) &&
|
||||
Objects.equals(this.end, dutyHourViewModel.end);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(day, start, end);
|
||||
}
|
||||
|
||||
|
||||
public String getSummary() {
|
||||
return this.getDay() + ": " + this.getStart() + " - " + this.getEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class DutyHourViewModel {\n");
|
||||
|
||||
sb.append(" day: ").append(toIndentedString(day)).append("\n");
|
||||
sb.append(" start: ").append(toIndentedString(start)).append("\n");
|
||||
sb.append(" end: ").append(toIndentedString(end)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
}
|
||||
|
178
app/src/main/java/com/uam/wmi/findmytutor/model/Feedback.java
Normal file
@ -0,0 +1,178 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Feedback {
|
||||
|
||||
@SerializedName("isAnonymous")
|
||||
@Expose
|
||||
private Boolean isAnonymous;
|
||||
@SerializedName("type")
|
||||
@Expose
|
||||
private String type;
|
||||
@SerializedName("user")
|
||||
@Expose
|
||||
private String user;
|
||||
@SerializedName("deviceOS")
|
||||
@Expose
|
||||
private String deviceOS;
|
||||
@SerializedName("appVersion")
|
||||
@Expose
|
||||
private String appVersion;
|
||||
@SerializedName("deviceModel")
|
||||
@Expose
|
||||
private String deviceModel;
|
||||
@SerializedName("body")
|
||||
@Expose
|
||||
private String body;
|
||||
|
||||
/**
|
||||
* No args constructor for use in serialization
|
||||
*
|
||||
*/
|
||||
public Feedback() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param body
|
||||
* @param appVersion
|
||||
* @param deviceModel
|
||||
* @param type
|
||||
* @param isAnonymous
|
||||
* @param user
|
||||
* @param deviceOS
|
||||
*/
|
||||
public Feedback(Boolean isAnonymous, String type, String user, String deviceOS, String appVersion, String deviceModel, String body) {
|
||||
super();
|
||||
this.isAnonymous = isAnonymous;
|
||||
this.type = type;
|
||||
this.user = user;
|
||||
this.deviceOS = deviceOS;
|
||||
this.appVersion = appVersion;
|
||||
this.deviceModel = deviceModel;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Boolean getIsAnonymous() {
|
||||
return isAnonymous;
|
||||
}
|
||||
|
||||
public void setIsAnonymous(Boolean isAnonymous) {
|
||||
this.isAnonymous = isAnonymous;
|
||||
}
|
||||
|
||||
public Feedback withIsAnonymous(Boolean isAnonymous) {
|
||||
this.isAnonymous = isAnonymous;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public Feedback withType(String type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public Feedback withUser(String user) {
|
||||
this.user = user;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDeviceOS() {
|
||||
return deviceOS;
|
||||
}
|
||||
|
||||
public void setDeviceOS(String deviceOS) {
|
||||
this.deviceOS = deviceOS;
|
||||
}
|
||||
|
||||
public Feedback withDeviceOS(String deviceOS) {
|
||||
this.deviceOS = deviceOS;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getAppVersion() {
|
||||
return appVersion;
|
||||
}
|
||||
|
||||
public void setAppVersion(String appVersion) {
|
||||
this.appVersion = appVersion;
|
||||
}
|
||||
|
||||
public Feedback withAppVersion(String appVersion) {
|
||||
this.appVersion = appVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDeviceModel() {
|
||||
return deviceModel;
|
||||
}
|
||||
|
||||
public void setDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel;
|
||||
}
|
||||
|
||||
public Feedback withDeviceModel(String deviceModel) {
|
||||
this.deviceModel = deviceModel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Feedback withBody(String body) {
|
||||
this.body = body;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Boolean.toString(this.isAnonymous) + this.type + this.user+this.deviceOS+this.appVersion+this.deviceModel+this.body;
|
||||
}
|
||||
// @Override
|
||||
// public String toString() {
|
||||
// return new ToStringBuilder(this).append("isAnonymous", isAnonymous).append("type", type).append("user", user).append("deviceOS", deviceOS).append("appVersion", appVersion).append("deviceModel", deviceModel).append("body", body).toString();
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
// private Boolean isAnonymous;
|
||||
// @SerializedName("type")
|
||||
// @Expose
|
||||
// private String type;
|
||||
// @SerializedName("user")
|
||||
// @Expose
|
||||
// private String user;
|
||||
// @SerializedName("deviceOS")
|
||||
// @Expose
|
||||
// private String deviceOS;
|
||||
// @SerializedName("appVersion")
|
||||
// @Expose
|
||||
// private String appVersion;
|
||||
// @SerializedName("deviceModel")
|
||||
// @Expose
|
||||
// private String deviceModel;
|
||||
// @SerializedName("body")
|
||||
// @Expose
|
||||
// private String body;
|
@ -11,7 +11,7 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
* LdapUser
|
||||
*/
|
||||
|
||||
public class LdapUser extends BaseResponse{
|
||||
public class LdapUser extends BaseResponse {
|
||||
@SerializedName("login")
|
||||
private String login = null;
|
||||
|
||||
@ -198,7 +198,7 @@ public class LdapUser extends BaseResponse{
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class LdapUser {\n");
|
||||
|
||||
|
||||
sb.append(" login: ").append(toIndentedString(login)).append("\n");
|
||||
sb.append(" password: ").append(toIndentedString(password)).append("\n");
|
||||
sb.append(" department: ").append(toIndentedString(department)).append("\n");
|
||||
|
@ -1,3 +1,4 @@
|
||||
/*
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
|
||||
@ -14,3 +15,4 @@ public class Model
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
|
@ -1,3 +1,4 @@
|
||||
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
@ -9,7 +10,7 @@ public class PagedResult {
|
||||
|
||||
@SerializedName("results")
|
||||
@Expose
|
||||
private List<User> results = null;
|
||||
private List<ReturnedTutors> results = null;
|
||||
@SerializedName("currentPage")
|
||||
@Expose
|
||||
private Integer currentPage;
|
||||
@ -29,11 +30,11 @@ public class PagedResult {
|
||||
@Expose
|
||||
private Integer lastRowOnPage;
|
||||
|
||||
public List<User> getResults() {
|
||||
public List<ReturnedTutors> getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(List<User> results) {
|
||||
public void setResults(List<ReturnedTutors> results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
@ -86,3 +87,15 @@ public class PagedResult {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,89 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.uam.wmi.findmytutor.model.Results;
|
||||
|
||||
public class PagedResultReturnedTutors extends BaseResponse{
|
||||
|
||||
@SerializedName("results")
|
||||
@Expose
|
||||
private Results results;
|
||||
@SerializedName("currentPage")
|
||||
@Expose
|
||||
private Integer currentPage;
|
||||
@SerializedName("pageCount")
|
||||
@Expose
|
||||
private Integer pageCount;
|
||||
@SerializedName("pageSize")
|
||||
@Expose
|
||||
private Integer pageSize;
|
||||
@SerializedName("rowCount")
|
||||
@Expose
|
||||
private Integer rowCount;
|
||||
@SerializedName("firstRowOnPage")
|
||||
@Expose
|
||||
private Integer firstRowOnPage;
|
||||
@SerializedName("lastRowOnPage")
|
||||
@Expose
|
||||
private Integer lastRowOnPage;
|
||||
|
||||
public Results getResults() {
|
||||
return results;
|
||||
}
|
||||
|
||||
public void setResults(Results results) {
|
||||
this.results = results;
|
||||
}
|
||||
|
||||
public Integer getCurrentPage() {
|
||||
return currentPage;
|
||||
}
|
||||
|
||||
public void setCurrentPage(Integer currentPage) {
|
||||
this.currentPage = currentPage;
|
||||
}
|
||||
|
||||
public Integer getPageCount() {
|
||||
return pageCount;
|
||||
}
|
||||
|
||||
public void setPageCount(Integer pageCount) {
|
||||
this.pageCount = pageCount;
|
||||
}
|
||||
|
||||
public Integer getPageSize() {
|
||||
return pageSize;
|
||||
}
|
||||
|
||||
public void setPageSize(Integer pageSize) {
|
||||
this.pageSize = pageSize;
|
||||
}
|
||||
|
||||
public Integer getRowCount() {
|
||||
return rowCount;
|
||||
}
|
||||
|
||||
public void setRowCount(Integer rowCount) {
|
||||
this.rowCount = rowCount;
|
||||
}
|
||||
|
||||
public Integer getFirstRowOnPage() {
|
||||
return firstRowOnPage;
|
||||
}
|
||||
|
||||
public void setFirstRowOnPage(Integer firstRowOnPage) {
|
||||
this.firstRowOnPage = firstRowOnPage;
|
||||
}
|
||||
|
||||
public Integer getLastRowOnPage() {
|
||||
return lastRowOnPage;
|
||||
}
|
||||
|
||||
public void setLastRowOnPage(Integer lastRowOnPage) {
|
||||
this.lastRowOnPage = lastRowOnPage;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -14,24 +15,31 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
public class PagedResultUserResponseModel extends BaseResponse {
|
||||
@SerializedName("results")
|
||||
@Expose
|
||||
private List<UserResponseModel> results = null;
|
||||
|
||||
@SerializedName("currentPage")
|
||||
@Expose
|
||||
private Integer currentPage = null;
|
||||
|
||||
@SerializedName("pageCount")
|
||||
@Expose
|
||||
private Integer pageCount = null;
|
||||
|
||||
@SerializedName("pageSize")
|
||||
@Expose
|
||||
private Integer pageSize = null;
|
||||
|
||||
@SerializedName("rowCount")
|
||||
@Expose
|
||||
private Integer rowCount = null;
|
||||
|
||||
@SerializedName("firstRowOnPage")
|
||||
@Expose
|
||||
private Integer firstRowOnPage = null;
|
||||
|
||||
@SerializedName("lastRowOnPage")
|
||||
@Expose
|
||||
private Integer lastRowOnPage = null;
|
||||
|
||||
public PagedResultUserResponseModel results(List<UserResponseModel> results) {
|
||||
|
@ -0,0 +1,203 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
import java.util.UUID;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
|
||||
public class PredefinedCoordViewModel {
|
||||
|
||||
@SerializedName("predefinedCoordinateId")
|
||||
@Expose
|
||||
private String predefinedCoordinateId;
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
@SerializedName("latitude")
|
||||
@Expose
|
||||
private Double latitude;
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
@SerializedName("longitude")
|
||||
@Expose
|
||||
private Double longitude;
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
@SerializedName("altitude")
|
||||
@Expose
|
||||
private Double altitude;
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
@SerializedName("userId")
|
||||
@Expose
|
||||
private String userId;
|
||||
@SerializedName("approximatedLocation")
|
||||
@Expose
|
||||
private String approximatedLocation;
|
||||
@SerializedName("displayMode")
|
||||
@Expose
|
||||
private String displayMode = "predefined";
|
||||
@SerializedName("name")
|
||||
@Expose
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* No args constructor for use in serialization
|
||||
*
|
||||
*/
|
||||
public PredefinedCoordViewModel() {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param altitude
|
||||
* @param userId
|
||||
* @param displayMode
|
||||
* @param name
|
||||
* @param longitude
|
||||
* @param latitude
|
||||
* @param approximatedLocation
|
||||
*/
|
||||
public PredefinedCoordViewModel(Double latitude, Double longitude, Double altitude, String userId, String approximatedLocation, String displayMode, String name) {
|
||||
super();
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.altitude = altitude;
|
||||
this.userId = userId;
|
||||
this.approximatedLocation = approximatedLocation;
|
||||
this.displayMode = displayMode;
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getPredefinedCoordinateId() {
|
||||
return predefinedCoordinateId;
|
||||
}
|
||||
|
||||
public void setPredefinedCoordinateId(String predefinedCoordinateId) {
|
||||
this.predefinedCoordinateId = predefinedCoordinateId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public Double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public void setAltitude(Double altitude) {
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* (Required)
|
||||
*
|
||||
*/
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String getApproximatedLocation() {
|
||||
return approximatedLocation;
|
||||
}
|
||||
|
||||
public void setApproximatedLocation(String approximatedLocation) {
|
||||
this.approximatedLocation = approximatedLocation;
|
||||
}
|
||||
|
||||
public String getDisplayMode() {
|
||||
return displayMode;
|
||||
}
|
||||
|
||||
public void setDisplayMode(String displayMode) {
|
||||
this.displayMode = displayMode;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class PredefinedCoordinate {\n");
|
||||
|
||||
sb.append(" lat: ").append(latitude).append("\n");
|
||||
sb.append(" long: ").append(longitude).append("\n");
|
||||
sb.append(" att: ").append(altitude).append("\n");
|
||||
sb.append(" userID: ").append(userId).append("\n");
|
||||
sb.append(" approx: ").append(approximatedLocation).append("\n");
|
||||
sb.append(" dispMode: ").append(displayMode).append("\n");
|
||||
sb.append(" name: ").append(name).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
public LatLng getGeoData(){
|
||||
return new LatLng(this.latitude,this.longitude,this.altitude);
|
||||
}
|
||||
}
|
33
app/src/main/java/com/uam/wmi/findmytutor/model/Results.java
Normal file
@ -0,0 +1,33 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Results extends BaseResponse {
|
||||
|
||||
@SerializedName("tutors")
|
||||
@Expose
|
||||
private List<Tutor> tutors = null;
|
||||
@SerializedName("blacklistersTutors")
|
||||
@Expose
|
||||
private List<Object> blacklistersTutors = null;
|
||||
|
||||
public List<Tutor> getTutors() {
|
||||
return tutors;
|
||||
}
|
||||
|
||||
public void setTutors(List<Tutor> tutors) {
|
||||
this.tutors = tutors;
|
||||
}
|
||||
|
||||
public List<Object> getBlacklistersTutors() {
|
||||
return blacklistersTutors;
|
||||
}
|
||||
|
||||
public void setBlacklistersTutors(List<Object> blacklistersTutors) {
|
||||
this.blacklistersTutors = blacklistersTutors;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ReturnedTutors {
|
||||
|
||||
@SerializedName("id")
|
||||
@Expose
|
||||
private String id;
|
||||
@SerializedName("isOnline")
|
||||
@Expose
|
||||
private Boolean isOnline;
|
||||
@SerializedName("title")
|
||||
@Expose
|
||||
private String title;
|
||||
@SerializedName("firstName")
|
||||
@Expose
|
||||
private String firstName;
|
||||
@SerializedName("lastName")
|
||||
@Expose
|
||||
private String lastName;
|
||||
@SerializedName("department")
|
||||
@Expose
|
||||
private String department;
|
||||
@SerializedName("userName")
|
||||
@Expose
|
||||
private String userName;
|
||||
@SerializedName("email")
|
||||
@Expose
|
||||
private String email;
|
||||
@SerializedName("isActive")
|
||||
@Expose
|
||||
private Boolean isActive;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Boolean getIsOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
public void setIsOnline(Boolean isOnline) {
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Boolean getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(Boolean isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
}
|
@ -18,6 +18,15 @@ public class StudentIdModel extends BaseResponse{
|
||||
@SerializedName("ldapLogin")
|
||||
private String ldapLogin = null;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param str
|
||||
*/
|
||||
public StudentIdModel(String str){
|
||||
// this.studentId = str;
|
||||
this.ldapLogin = str;
|
||||
}
|
||||
|
||||
public StudentIdModel studentId(String studentId) {
|
||||
this.studentId = studentId;
|
||||
return this;
|
||||
|
109
app/src/main/java/com/uam/wmi/findmytutor/model/Tutor.java
Normal file
@ -0,0 +1,109 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
|
||||
import com.google.gson.annotations.Expose;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class Tutor {
|
||||
|
||||
@SerializedName("id")
|
||||
@Expose
|
||||
private String id;
|
||||
@SerializedName("isOnline")
|
||||
@Expose
|
||||
private Boolean isOnline;
|
||||
@SerializedName("title")
|
||||
@Expose
|
||||
private String title;
|
||||
@SerializedName("firstName")
|
||||
@Expose
|
||||
private String firstName;
|
||||
@SerializedName("lastName")
|
||||
@Expose
|
||||
private String lastName;
|
||||
@SerializedName("department")
|
||||
@Expose
|
||||
private String department;
|
||||
@SerializedName("userName")
|
||||
@Expose
|
||||
private String userName;
|
||||
@SerializedName("email")
|
||||
@Expose
|
||||
private String email;
|
||||
@SerializedName("isActive")
|
||||
@Expose
|
||||
private Boolean isActive;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Boolean getIsOnline() {
|
||||
return isOnline;
|
||||
}
|
||||
|
||||
public void setIsOnline(Boolean isOnline) {
|
||||
this.isOnline = isOnline;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public String getDepartment() {
|
||||
return department;
|
||||
}
|
||||
|
||||
public void setDepartment(String department) {
|
||||
this.department = department;
|
||||
}
|
||||
|
||||
public String getUserName() {
|
||||
return userName;
|
||||
}
|
||||
|
||||
public void setUserName(String userName) {
|
||||
this.userName = userName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public void setEmail(String email) {
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public Boolean getIsActive() {
|
||||
return isActive;
|
||||
}
|
||||
|
||||
public void setIsActive(Boolean isActive) {
|
||||
this.isActive = isActive;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* TutorTabViewModel
|
||||
*/
|
||||
|
||||
public class TutorTabViewModel {
|
||||
@SerializedName("tutorTabId")
|
||||
private UUID tutorTabId = null;
|
||||
|
||||
@SerializedName("userId")
|
||||
private String userId = null;
|
||||
|
||||
@SerializedName("room")
|
||||
private String room = "";
|
||||
|
||||
@SerializedName("emailTutorTab")
|
||||
private String emailTutorTab = "";
|
||||
|
||||
@SerializedName("note")
|
||||
private String note = "";
|
||||
|
||||
@SerializedName("dutyHours")
|
||||
private List<DutyHourViewModel> dutyHours = null;
|
||||
|
||||
public TutorTabViewModel(String userId, String room, String email, String note, List<DutyHourViewModel> dutyHours){
|
||||
this.userId=userId;
|
||||
this.room=room;
|
||||
this.emailTutorTab=email;
|
||||
this.note=note;
|
||||
this.dutyHours = new ArrayList<DutyHourViewModel>(dutyHours);
|
||||
}
|
||||
|
||||
public TutorTabViewModel tutorTabId(UUID tutorTabId) {
|
||||
this.tutorTabId = tutorTabId;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get tutorTabId
|
||||
* @return tutorTabId
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public UUID getTutorTabId() {
|
||||
return tutorTabId;
|
||||
}
|
||||
|
||||
public void setTutorTabId(UUID tutorTabId) {
|
||||
this.tutorTabId = tutorTabId;
|
||||
}
|
||||
|
||||
public TutorTabViewModel userId(String userId) {
|
||||
this.userId = userId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get userId
|
||||
* @return userId
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public TutorTabViewModel room(String room) {
|
||||
this.room = room;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get room
|
||||
* @return room
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getRoom() {
|
||||
return room;
|
||||
}
|
||||
|
||||
public void setRoom(String room) {
|
||||
this.room = room;
|
||||
}
|
||||
|
||||
public TutorTabViewModel emailTutorTab(String emailTutorTab) {
|
||||
this.emailTutorTab = emailTutorTab;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get emailTutorTab
|
||||
* @return emailTutorTab
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public String getEmailTutorTab() {
|
||||
return emailTutorTab;
|
||||
}
|
||||
|
||||
public void setEmailTutorTab(String emailTutorTab) {
|
||||
this.emailTutorTab = emailTutorTab;
|
||||
}
|
||||
|
||||
public TutorTabViewModel note(String note) {
|
||||
this.note = note;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public String getNote() {
|
||||
if(note == null)
|
||||
return "";
|
||||
|
||||
return note;
|
||||
}
|
||||
|
||||
public void setNote(String note) {
|
||||
this.note = note;
|
||||
}
|
||||
|
||||
public TutorTabViewModel dutyHours(List<DutyHourViewModel> dutyHours) {
|
||||
this.dutyHours = dutyHours;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TutorTabViewModel addDutyHoursItem(DutyHourViewModel dutyHoursItem) {
|
||||
if (this.dutyHours == null) {
|
||||
this.dutyHours = new ArrayList<DutyHourViewModel>();
|
||||
}
|
||||
this.dutyHours.add(dutyHoursItem);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get dutyHours
|
||||
* @return dutyHours
|
||||
**/
|
||||
@ApiModelProperty(value = "")
|
||||
public List<DutyHourViewModel> getDutyHours() {
|
||||
return dutyHours;
|
||||
}
|
||||
|
||||
public void setDutyHours(List<DutyHourViewModel> dutyHours) {
|
||||
this.dutyHours = dutyHours;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
TutorTabViewModel tutorTabViewModel = (TutorTabViewModel) o;
|
||||
return Objects.equals(this.tutorTabId, tutorTabViewModel.tutorTabId) &&
|
||||
Objects.equals(this.userId, tutorTabViewModel.userId) &&
|
||||
Objects.equals(this.room, tutorTabViewModel.room) &&
|
||||
Objects.equals(this.emailTutorTab, tutorTabViewModel.emailTutorTab) &&
|
||||
Objects.equals(this.note, tutorTabViewModel.note) &&
|
||||
Objects.equals(this.dutyHours, tutorTabViewModel.dutyHours);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(tutorTabId, userId, room, emailTutorTab, note, dutyHours);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class TutorTabViewModel {\n");
|
||||
|
||||
sb.append(" tutorTabId: ").append(toIndentedString(tutorTabId)).append("\n");
|
||||
sb.append(" userId: ").append(toIndentedString(userId)).append("\n");
|
||||
sb.append(" room: ").append(toIndentedString(room)).append("\n");
|
||||
sb.append(" emailTutorTab: ").append(toIndentedString(emailTutorTab)).append("\n");
|
||||
sb.append(" note: ").append(toIndentedString(note)).append("\n");
|
||||
sb.append(" dutyHours: ").append(toIndentedString(dutyHours)).append("\n");
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,94 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
|
||||
|
||||
/**
|
||||
* ValidateUser
|
||||
*/
|
||||
|
||||
public class ValidateUser extends BaseResponse {
|
||||
@SerializedName("login")
|
||||
private String login = null;
|
||||
|
||||
@SerializedName("password")
|
||||
private String password = null;;
|
||||
|
||||
public ValidateUser(String login, String password) {
|
||||
this.login = login;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public ValidateUser login(String login) {
|
||||
this.login = login;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get login
|
||||
* @return login
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public String getLogin() {
|
||||
return login;
|
||||
}
|
||||
|
||||
public void setLogin(String login) {
|
||||
this.login = login;
|
||||
}
|
||||
|
||||
public ValidateUser password(String password) {
|
||||
this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(java.lang.Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass()) {
|
||||
return false;
|
||||
}
|
||||
ValidateUser ValidateUser = (ValidateUser) o;
|
||||
return Objects.equals(this.login, ValidateUser.login) &&
|
||||
Objects.equals(this.password, ValidateUser.password);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(login, password);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("class ValidateUser {\n");
|
||||
|
||||
sb.append(" login: ").append(toIndentedString(login)).append("\n");
|
||||
sb.append(" password: ").append(toIndentedString(password)).append("\n");
|
||||
|
||||
sb.append("}");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert the given object to string with each line indented by 4 spaces
|
||||
* (except the first line).
|
||||
*/
|
||||
private String toIndentedString(java.lang.Object o) {
|
||||
if (o == null) {
|
||||
return "null";
|
||||
}
|
||||
return o.toString().replace("\n", "\n ");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,15 +4,20 @@ import android.content.Context;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.CipherSuite;
|
||||
import okhttp3.ConnectionSpec;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.TlsVersion;
|
||||
import okhttp3.logging.HttpLoggingInterceptor;
|
||||
import retrofit2.Retrofit;
|
||||
import retrofit2.converter.gson.GsonConverterFactory;
|
||||
@ -22,7 +27,6 @@ public class ApiClient {
|
||||
private static Retrofit retrofit = null;
|
||||
private static int REQUEST_TIMEOUT = 60;
|
||||
private static OkHttpClient okHttpClient;
|
||||
private static final String BASE_URL = "https://s416084.projektstudencki.pl/develop/";
|
||||
|
||||
public static Retrofit getClient(Context context) {
|
||||
|
||||
@ -31,45 +35,45 @@ public class ApiClient {
|
||||
|
||||
if (retrofit == null) {
|
||||
retrofit = new Retrofit.Builder()
|
||||
.baseUrl(BASE_URL)
|
||||
.baseUrl(Const.BASE_URL)
|
||||
.client(okHttpClient)
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.addConverterFactory(GsonConverterFactory.create())
|
||||
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
|
||||
.build();
|
||||
}
|
||||
|
||||
return retrofit;
|
||||
}
|
||||
|
||||
private static void initOkHttp(final Context context) {
|
||||
OkHttpClient.Builder httpClient = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
|
||||
.readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
|
||||
.writeTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS);
|
||||
private static void initOkHttp(final Context context) {
|
||||
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
OkHttpClient.Builder httpClient = new OkHttpClient().newBuilder()
|
||||
.connectTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
|
||||
.readTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS)
|
||||
.writeTimeout(REQUEST_TIMEOUT, TimeUnit.SECONDS);
|
||||
|
||||
httpClient.addInterceptor(interceptor);
|
||||
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
|
||||
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
|
||||
httpClient.addInterceptor(new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request original = chain.request();
|
||||
Request.Builder requestBuilder = original.newBuilder()
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json");
|
||||
httpClient.addInterceptor(interceptor);
|
||||
|
||||
// Adding Authorization token (API Key)
|
||||
// Requests will be denied without API key
|
||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||
}
|
||||
httpClient.addInterceptor(chain -> {
|
||||
Request original = chain.request();
|
||||
Request.Builder requestBuilder = original.newBuilder()
|
||||
.addHeader("Accept", "application/json")
|
||||
.addHeader("Content-Type", "application/json");
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
});
|
||||
|
||||
okHttpClient = httpClient.build();
|
||||
}
|
||||
};
|
||||
// Adding Authorization token (API Key)
|
||||
// Requests will be denied without API key
|
||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||
}
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
return chain.proceed(request);
|
||||
});
|
||||
|
||||
okHttpClient = httpClient.build();
|
||||
}
|
||||
};
|
||||
|
@ -6,170 +6,256 @@ import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
import android.location.LocationListener;
|
||||
import android.location.LocationManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.IBinder;
|
||||
import android.os.Looper;
|
||||
import android.support.annotation.RequiresApi;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.NotificationCompat;
|
||||
import android.util.Log;
|
||||
import android.content.Context;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.annimon.stream.Stream;
|
||||
import com.google.android.gms.location.FusedLocationProviderClient;
|
||||
import com.google.android.gms.location.LocationCallback;
|
||||
import com.google.android.gms.location.LocationRequest;
|
||||
import com.google.android.gms.location.LocationResult;
|
||||
import com.google.android.gms.location.LocationServices;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
|
||||
import com.uam.wmi.findmytutor.utils.Const;
|
||||
import com.uam.wmi.findmytutor.utils.MapUtils;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
import com.uam.wmi.findmytutor.utils.SharingLevel;
|
||||
import com.uam.wmi.findmytutor.utils.WifiUtils;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import org.apache.commons.collections4.queue.CircularFifoQueue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.observers.DisposableCompletableObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.offlineBackgroundLocationInterval;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.onlineBackgroundLocationInterval;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.presenceApproximatedName;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.presenceLatitude;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.presenceLongitude;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.storeBackgroundLocationStatus;
|
||||
import static java.lang.String.valueOf;
|
||||
|
||||
public class BackgroundLocalizationService extends Service {
|
||||
|
||||
public static String str_receiver = "background.location.broadcast";
|
||||
private static final String TAG = "background.location.broadcast";
|
||||
private LocationManager mLocationManager = null;
|
||||
private static final int LOCATION_INTERVAL = 10000;
|
||||
private static final float LOCATION_DISTANCE = 10f;
|
||||
private static final String TAG = "MyLocationService";
|
||||
private static Integer notify_interval = onlineBackgroundLocationInterval;
|
||||
private static Integer notify_interval_inside_building = onlineBackgroundLocationInterval;
|
||||
private static Integer notify_interval_outside_building = offlineBackgroundLocationInterval;
|
||||
private static int coordinatesHistoryLength = 10;
|
||||
private Boolean highAccuracyMode;
|
||||
private Location mLastLocation;
|
||||
private Boolean stopService = false;
|
||||
private ArrayList<String> providers = new ArrayList<String>();
|
||||
private CircularFifoQueue<Location> coordinatesHistory = new CircularFifoQueue<Location>(coordinatesHistoryLength);
|
||||
private Handler mHandler = new Handler();
|
||||
private static long notify_interval = 100000;
|
||||
Location mLastLocation;
|
||||
Intent intent;
|
||||
LocationManager locationManager;
|
||||
Location location;
|
||||
private Runnable mStatusChecker;
|
||||
private FusedLocationProviderClient mFusedLocationClient;
|
||||
private Location fakeLoc = null;
|
||||
private LocationRequest mLocationRequest;
|
||||
private Location mCurrentLocation;
|
||||
private LocationCallback mLocationCallback;
|
||||
private LocationListener mLocationListener;
|
||||
|
||||
double latitude, longitude;
|
||||
// Constants
|
||||
private static final int ID_SERVICE = 101;
|
||||
public BackgroundLocalizationService() {
|
||||
providers.add(LocationManager.GPS_PROVIDER);
|
||||
providers.add(LocationManager.NETWORK_PROVIDER);
|
||||
providers.add(LocationManager.PASSIVE_PROVIDER);
|
||||
fakeLoc = new Location("");
|
||||
|
||||
|
||||
boolean isGPSEnable = false;
|
||||
boolean isNetworkEnable = false;
|
||||
|
||||
private class LocationListener implements android.location.LocationListener {
|
||||
|
||||
LocationListener(String provider) {
|
||||
Timber.e("LocationListener %s", provider);
|
||||
mLastLocation = new Location(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Timber.e("onLocationChanged: %s", location);
|
||||
mLastLocation.set(location);
|
||||
sendToBroadcast(mLastLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
Timber.e("onProviderDisabled: %s", provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
Timber.e("onProviderEnabled: %s", provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
Timber.e("onStatusChanged: %s", provider);
|
||||
}
|
||||
fakeLoc.setLatitude(0);
|
||||
fakeLoc.setLongitude(0);
|
||||
fakeLoc.setAltitude(0);
|
||||
}
|
||||
|
||||
LocationListener[] mLocationListeners = new LocationListener[]{
|
||||
new LocationListener(LocationManager.GPS_PROVIDER),
|
||||
new LocationListener(LocationManager.NETWORK_PROVIDER),
|
||||
new LocationListener(LocationManager.PASSIVE_PROVIDER)
|
||||
};
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent arg0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void startJob() throws InterruptedException {
|
||||
//do job here
|
||||
|
||||
//job completed. Rest for 5 second before doing another one
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
Log.e("loc","job") ;
|
||||
fn_getlocation();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
//do job again
|
||||
startJob();
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG,"onStartCommand");
|
||||
Log.e(TAG, "onStartCommand");
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
/*
|
||||
|
||||
Thread t = new Thread(() -> {
|
||||
try {
|
||||
startJob();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
t.start();
|
||||
|
||||
*/
|
||||
|
||||
/* if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
|
||||
Notification.Builder builder = new Notification.Builder(this, "FOREGROUND_SERVICE")
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText("background")
|
||||
.setAutoCancel(true);
|
||||
|
||||
Notification notification = builder.build();
|
||||
startForeground(101, notification);
|
||||
|
||||
} else {
|
||||
|
||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
|
||||
.setContentTitle(getString(R.string.app_name))
|
||||
.setContentText("background")
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setAutoCancel(true);
|
||||
|
||||
Notification notification = builder.build();
|
||||
|
||||
startForeground(101, notification);
|
||||
if (intent != null) {
|
||||
stopService = intent.getBooleanExtra("request_stop", false);
|
||||
notify_interval = intent.getIntExtra("notify_interval", onlineBackgroundLocationInterval);
|
||||
}
|
||||
*/
|
||||
|
||||
if (stopService) {
|
||||
storeBackgroundLocationStatus(getApplication(), false);
|
||||
stopForeground(true);
|
||||
stopSelf();
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
return START_STICKY;
|
||||
}
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground(){
|
||||
|
||||
String NOTIFICATION_CHANNEL_ID = "com.example.simpleapp";
|
||||
String channelName = "My Background Service";
|
||||
private void createLocationCallback() {
|
||||
mLocationCallback = new LocationCallback() {
|
||||
@Override
|
||||
public void onLocationResult(LocationResult locationResult) {
|
||||
super.onLocationResult(locationResult);
|
||||
if (locationResult != null) {
|
||||
mCurrentLocation = locationResult.getLastLocation();
|
||||
sendCoordinateToBackend(mCurrentLocation);
|
||||
changeBackgroundMode();
|
||||
|
||||
//Restart service when a user started using presence in GPS mode and wmi is currently available
|
||||
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())
|
||||
&& PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
|
||||
restartService();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
Log.e(TAG, "onCreate");
|
||||
storeBackgroundLocationStatus(getApplication(), true);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||
startMyOwnForeground();
|
||||
else {
|
||||
Notification notification = new NotificationCompat.Builder(this, "NOTIFICATION_CHANNEL")
|
||||
.setContentText("Content").build();
|
||||
startForeground(1001, notification);
|
||||
}
|
||||
|
||||
if (!stopService) {
|
||||
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.PRESENCE.toString())) {
|
||||
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())) {
|
||||
Location presenceFakeLoc = new Location("");
|
||||
|
||||
presenceFakeLoc.setLatitude(Const.presenceLatitude);
|
||||
presenceFakeLoc.setLongitude(Const.presenceLongitude);
|
||||
presenceFakeLoc.setAltitude(0);
|
||||
createPresenceLooper(presenceFakeLoc);
|
||||
} else {
|
||||
createFusedLocationClient();
|
||||
}
|
||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.EXACT.toString())
|
||||
|| PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.APPROXIMATED.toString())
|
||||
) {
|
||||
createFusedLocationClient();
|
||||
} else if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
|
||||
Location manualFakeLoc = new Location("");
|
||||
|
||||
manualFakeLoc.setLatitude(0);
|
||||
manualFakeLoc.setLongitude(0);
|
||||
manualFakeLoc.setAltitude(0);
|
||||
createLowBatteryLooper(manualFakeLoc);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void createLowBatteryLooper(Location fakeLoc) {
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
sendCoordinateToBackend(fakeLoc);
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, notify_interval);
|
||||
}
|
||||
};
|
||||
AsyncTask.execute(mStatusChecker);
|
||||
}
|
||||
|
||||
private void createPresenceLooper(Location fakeLoc) {
|
||||
mStatusChecker = () -> {
|
||||
try {
|
||||
if (WifiUtils.checkIfUserIsInRangeOfWmiWifi(getApplicationContext())) {
|
||||
sendCoordinateToBackend(fakeLoc);
|
||||
} else {
|
||||
restartService();
|
||||
}
|
||||
} finally {
|
||||
mHandler.postDelayed(mStatusChecker, notify_interval);
|
||||
}
|
||||
};
|
||||
AsyncTask.execute(mStatusChecker);
|
||||
}
|
||||
|
||||
|
||||
private void createFusedLocationClient() {
|
||||
Integer saveMode = Long.valueOf(notify_interval).compareTo(Long.valueOf(offlineBackgroundLocationInterval));
|
||||
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
mLocationRequest = new LocationRequest();
|
||||
|
||||
if (saveMode != 0) {
|
||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
|
||||
} else {
|
||||
mLocationRequest.setPriority(LocationRequest.PRIORITY_LOW_POWER);
|
||||
}
|
||||
|
||||
mLocationRequest.setFastestInterval(notify_interval);
|
||||
mLocationRequest.setInterval(notify_interval);
|
||||
|
||||
createLocationCallback();
|
||||
|
||||
if (!stopService) {
|
||||
mFusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
|
||||
mFusedLocationClient.requestLocationUpdates(mLocationRequest,
|
||||
mLocationCallback, Looper.getMainLooper());
|
||||
}
|
||||
}
|
||||
|
||||
private void changeBackgroundMode() {
|
||||
Integer prevInterval = notify_interval;
|
||||
Boolean shouldExtendTimeInterval = Stream.of(coordinatesHistory)
|
||||
.map(MapUtils::checkIfCoordinateIsValid).takeWhile(s -> !s).toList().size() == coordinatesHistoryLength;
|
||||
|
||||
Boolean shouldAbbreviateTimeInterval = Stream.of(coordinatesHistory).
|
||||
map(MapUtils::checkIfCoordinateIsValid).filter(x -> x).toList().size() > 0;
|
||||
|
||||
if (shouldExtendTimeInterval) {
|
||||
notify_interval = notify_interval_outside_building;
|
||||
}
|
||||
|
||||
if (shouldAbbreviateTimeInterval) {
|
||||
notify_interval = notify_interval_inside_building;
|
||||
}
|
||||
|
||||
|
||||
Integer changedMode = Long.valueOf(prevInterval).compareTo(Long.valueOf(notify_interval));
|
||||
if (changedMode != 0) {
|
||||
updateListeners();
|
||||
}
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground() {
|
||||
String NOTIFICATION_CHANNEL_ID = "com.example.fmt";
|
||||
String channelName = "FMT Background location service";
|
||||
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
||||
chan.setLightColor(Color.BLUE);
|
||||
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
@ -186,234 +272,143 @@ public class BackgroundLocalizationService extends Service {
|
||||
startForeground(2, notification);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
Timber.e("onCreate");
|
||||
|
||||
initializeLocationManager();
|
||||
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(
|
||||
LocationManager.PASSIVE_PROVIDER,
|
||||
LOCATION_INTERVAL,
|
||||
LOCATION_DISTANCE,
|
||||
mLocationListeners[0]
|
||||
);
|
||||
} catch (java.lang.SecurityException ex) {
|
||||
Timber.i(ex, "fail to request location update, ignore");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Timber.d("network provider does not exist, %s", ex.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(
|
||||
LocationManager.GPS_PROVIDER,
|
||||
LOCATION_INTERVAL,
|
||||
LOCATION_DISTANCE,
|
||||
mLocationListeners[1]
|
||||
);
|
||||
} catch (java.lang.SecurityException ex) {
|
||||
Timber.i(ex, "fail to request location update, ignore");
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Timber.d("gps provider does not exist %s", ex.getMessage());
|
||||
}
|
||||
|
||||
Timer mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTaskToGetLocation(), 5, notify_interval);
|
||||
intent = new Intent(str_receiver);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O)
|
||||
startMyOwnForeground();
|
||||
else
|
||||
startForeground(1, new Notification());
|
||||
}
|
||||
|
||||
private void fn_getlocation() {
|
||||
try {
|
||||
locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
|
||||
isGPSEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
isNetworkEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
|
||||
} catch (Exception e) {
|
||||
Timber.d("isProviderEnabled does not exist %s", e.getMessage());
|
||||
}
|
||||
|
||||
if (isGPSEnable && isNetworkEnable) {
|
||||
|
||||
} else {
|
||||
|
||||
Log.e("loc","dzialam") ;
|
||||
if (isGPSEnable) {
|
||||
location = null;
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, mLocationListeners[1]);
|
||||
if (locationManager != null) {
|
||||
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
||||
if (location != null) {
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
|
||||
sendToBroadcast(location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isNetworkEnable) {
|
||||
location = null;
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
|
||||
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, mLocationListeners[0]);
|
||||
|
||||
if (locationManager != null) {
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
// TODO: Consider calling
|
||||
// ActivityCompat#requestPermissions
|
||||
// here to request the missing permissions, and then overriding
|
||||
// public void onRequestPermissionsResult(int requestCode, String[] permissions,
|
||||
// int[] grantResults)
|
||||
// to handle the case where the user grants the permission. See the documentation
|
||||
// for ActivityCompat#requestPermissions for more details.
|
||||
return;
|
||||
}
|
||||
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
||||
if (location != null) {
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
sendToBroadcast(location);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private class TimerTaskToGetLocation extends TimerTask {
|
||||
@Override
|
||||
public void run() {
|
||||
mHandler.post(BackgroundLocalizationService.this::fn_getlocation);
|
||||
}
|
||||
}
|
||||
/*
|
||||
private void fn_update(Location location) {
|
||||
intent.putExtra("latitude", location.getLatitude());
|
||||
intent.putExtra("longitude", location.getLongitude());
|
||||
sendToBroadcast(Location location);
|
||||
}*/
|
||||
|
||||
private void sendToBroadcast(Location location) {
|
||||
Timber.e(String.valueOf(location));
|
||||
Log.e("err", String.valueOf(location));
|
||||
|
||||
intent.putExtra("latitude", location.getLatitude());
|
||||
intent.putExtra("longitude", location.getLongitude());
|
||||
private void sendCoordinateToBackend(Location location) {
|
||||
new Task(location).execute();
|
||||
|
||||
// sendBroadcast(intent);
|
||||
}
|
||||
|
||||
private void getLocation() {
|
||||
sendToBroadcast(mLastLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Timber.e("onDestroy");
|
||||
Log.e(TAG, "onDestroy");
|
||||
|
||||
super.onDestroy();
|
||||
mHandler.removeCallbacks(mStatusChecker);
|
||||
destroyLocationListeners();
|
||||
}
|
||||
|
||||
if (mLocationManager != null) {
|
||||
for (LocationListener mLocationListener : mLocationListeners) {
|
||||
try {
|
||||
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
mLocationManager.removeUpdates(mLocationListener);
|
||||
} catch (Exception ex) {
|
||||
Timber.i(ex, "fail to remove location listener, ignore");
|
||||
}
|
||||
}
|
||||
private void destroyLocationListeners() {
|
||||
if (mFusedLocationClient != null) {
|
||||
mFusedLocationClient.removeLocationUpdates(mLocationCallback);
|
||||
mFusedLocationClient = null;
|
||||
mLocationCallback = null;
|
||||
mLocationRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeLocationManager() {
|
||||
Timber.e("initializeLocationManager - LOCATION_INTERVAL: " + LOCATION_INTERVAL + " LOCATION_DISTANCE: " + LOCATION_DISTANCE);
|
||||
|
||||
if (mLocationManager == null) {
|
||||
mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
private void updateListeners() {
|
||||
if (mFusedLocationClient != null) {
|
||||
mFusedLocationClient.removeLocationUpdates(mLocationCallback)
|
||||
.addOnCompleteListener(task -> {
|
||||
restartService();
|
||||
mFusedLocationClient = null;
|
||||
mLocationCallback = null;
|
||||
mLocationRequest = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void restartService() {
|
||||
|
||||
Intent stopIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
stopIntent.putExtra("request_stop", true);
|
||||
|
||||
stopService(stopIntent);
|
||||
|
||||
Intent startIntent = new Intent(getApplicationContext(), BackgroundLocalizationService.class);
|
||||
startIntent.putExtra("notify_interval", notify_interval);
|
||||
|
||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.O) {
|
||||
startForegroundService(startIntent);
|
||||
} else {
|
||||
startService(startIntent);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
private class Task extends AsyncTask {
|
||||
private ApproximatedLocalization approximatedLocalization;
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
private Double altitude;
|
||||
private String approximatedBuildingPart = null;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
private Task(Location location) {
|
||||
this.latitude = location.getLatitude();
|
||||
this.longitude = location.getLongitude();
|
||||
latitude = location.getLatitude();
|
||||
longitude = location.getLongitude();
|
||||
altitude = location.getAltitude();
|
||||
Log.e(TAG, "TASK" + latitude + " " + longitude);
|
||||
approximatedLocalization = new ApproximatedLocalization(MapUtils.loadJsonFromAsset(getApplicationContext(), "building.geojson"));
|
||||
approximatedBuildingPart = approximatedLocalization.getNameOfBuildingPart(Point.fromLngLat(longitude, latitude));
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
|
||||
try {
|
||||
String locationLevel = PrefUtils.getLocationLevel(getApplicationContext());
|
||||
String status = (PrefUtils.isStatusEnabled(getApplicationContext())) ? PrefUtils.getUserStatus(getApplicationContext()) : "";
|
||||
|
||||
if (locationLevel.equals(SharingLevel.PRESENCE.toString())) {
|
||||
if (!MapUtils.checkIfCoordinateIsValid(latitude, longitude)) {
|
||||
coordinatesHistory.add(fakeLoc);
|
||||
return null;
|
||||
}
|
||||
|
||||
latitude = presenceLatitude;
|
||||
longitude = presenceLongitude;
|
||||
approximatedBuildingPart = presenceApproximatedName;
|
||||
} else if (locationLevel.equals(SharingLevel.APPROXIMATED.toString())) {
|
||||
List<Double> points = approximatedLocalization.getMiddlePointOfBuildingPart(approximatedBuildingPart);
|
||||
latitude = points.get(0);
|
||||
longitude = points.get(1);
|
||||
} else if (locationLevel.equals(SharingLevel.MANUAL.toString())) {
|
||||
LatLng latLng = PrefUtils.getManualLocation(getApplicationContext());
|
||||
latitude = latLng.getLatitude();
|
||||
longitude = latLng.getLongitude();
|
||||
approximatedBuildingPart = PrefUtils.getManualLocationApproximation(getApplicationContext());
|
||||
}
|
||||
|
||||
Location fakeLoc = new Location("");
|
||||
|
||||
fakeLoc.setLatitude(latitude);
|
||||
fakeLoc.setLongitude(longitude);
|
||||
coordinatesHistory.add(fakeLoc);
|
||||
|
||||
try {
|
||||
Coordinate coordinate = new Coordinate(
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
PrefUtils.getUserStatus(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext())
|
||||
latitude,
|
||||
longitude,
|
||||
altitude,
|
||||
approximatedBuildingPart,
|
||||
status,
|
||||
PrefUtils.getUserId(getApplicationContext()),
|
||||
locationLevel
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.putCoordinate(coordinate, PrefUtils.getUserId(getApplicationContext()))
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@SuppressLint("LongLogTag")
|
||||
.subscribeWith(new DisposableCompletableObserver() {
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e("CoordinateService onSuccess", String.valueOf(coord));
|
||||
public void onComplete() {
|
||||
Log.e(TAG, "CoordinateSuccess");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("LoginError", "onError: " + e.getMessage());
|
||||
Log.e(TAG, "onErr" + valueOf(e));
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
Log.e(TAG, e.toString());
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,20 +1,13 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Single;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
@ -32,7 +25,7 @@ public interface CoordinateService {
|
||||
Single<List<Coordinate>> getCoordinatesByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/userTop/{userId}")
|
||||
Single<List<Coordinate>> getTopCoordinatesByUserId(@Path("userId") String userId);
|
||||
Single <Coordinate> getTopCoordinateByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/top")
|
||||
Single<List<Coordinate>> getTopCoordinates();
|
||||
@ -44,10 +37,11 @@ public interface CoordinateService {
|
||||
Single <Coordinate> postCoordinate(@Body Coordinate coordinate);
|
||||
|
||||
@PUT("api/coordinates/{id}")
|
||||
Single<Coordinate> putCoordinatesById(@Path("id") String id);
|
||||
Completable putCoordinate(@Body Coordinate coordinate, @Path("id") String id);
|
||||
|
||||
@DELETE("api/coordinates/{id}")
|
||||
Single<Coordinate> deleteCoordinatesById(@Path("id") String id);
|
||||
Completable deleteCoordinatesById(@Path("id") String id);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,17 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.Feedback;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface FeedbackService {
|
||||
@POST("api/Feedback")
|
||||
Observable<Response<Void>> postFeedback(@Body Feedback feedback);
|
||||
|
||||
@GET("api/Feedback")
|
||||
Observable<Void> getFeedback();
|
||||
}
|
@ -2,6 +2,7 @@ package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
||||
import com.uam.wmi.findmytutor.model.ValidateUser;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Body;
|
||||
@ -15,7 +16,7 @@ public interface LdapService {
|
||||
Single<JwtToken> fakeValidate(@Body LdapUser user);
|
||||
|
||||
@POST("api/ldap/validate")
|
||||
Single<JwtToken> validate(@Body LdapUser user);
|
||||
Single<JwtToken> validate(@Body ValidateUser user);
|
||||
|
||||
@GET("api/ldap/getUserData/{login}")
|
||||
Single<LdapUser> getUserDataByLogin(@Path("login") String userLogin);
|
||||
|
@ -0,0 +1,24 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.HTTP;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface PredefinedCoordinatesService {
|
||||
@GET("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> getUserPredefinedCoords(@Path("tutorId") String tutorId);
|
||||
|
||||
@POST("api/users/predefined/coordinate/{tutorId}")
|
||||
Single <PredefinedCoordViewModel> postUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);
|
||||
|
||||
@HTTP(method = "DELETE", path = "api/users/predefined/coordinate/{tutorId}", hasBody = true)
|
||||
Single<List<PredefinedCoordViewModel>> deleteUserPredefinedCoord(@Path("tutorId") String tutorId, @Body String uuid);
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import java.util.List;
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.HTTP;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.Path;
|
||||
|
||||
public interface PredefinedStatusesService {
|
||||
@GET("api/users/predefined/status/{tutorId}")
|
||||
Single<List<String>> getUserPredefinedStatuses(@Path("tutorId") String tutorId);
|
||||
|
||||
@POST("api/users/predefined/status/{tutorId}")
|
||||
Single<List<String>> postUserPredefinedStatus(@Path("tutorId") String tutorId, @Body String status);
|
||||
|
||||
// @DELETE("api/users/predefined/status/{tutorId}")
|
||||
@HTTP(method = "DELETE", path = "api/users/predefined/status/{tutorId}", hasBody = true)
|
||||
Single<List<String>> deleteUserPredefinedStatus(@Path("tutorId") String tutorId, @Body String status);
|
||||
|
||||
/* @GET("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> getUserPredefinedCoords(@Path("tutorId") String tutorId);
|
||||
|
||||
@POST("api/users/predefined/coordinate/{tutorId}")
|
||||
Single <PredefinedCoordViewModel> postUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);
|
||||
|
||||
@DELETE("api/users/predefined/coordinate/{tutorId}")
|
||||
Single<List<PredefinedCoordViewModel>> deleteUserPredefinedCoord(@Path("tutorId") String tutorId, @Body PredefinedCoordViewModel coord);*/
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
|
||||
import com.uam.wmi.findmytutor.model.TutorTabViewModel;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.*;
|
||||
|
||||
|
||||
public interface TutorTabApi {
|
||||
/**
|
||||
* Scrap all tutor tabs
|
||||
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
|
||||
* @param tutorId (required)
|
||||
* @return Call<Void>
|
||||
*/
|
||||
@POST("api/users/scrapTutorTab/{tutorId}")
|
||||
Completable apiUsersScrapTutorTabByTutorIdPost(
|
||||
@retrofit2.http.Path("tutorId") String tutorId
|
||||
);
|
||||
|
||||
/**
|
||||
* Scrap all tutor tabs
|
||||
* With this method, you can initialize tutor tabs scrapper. The effect will be: - all tutor tabs will be overwritten with data from the WMI source
|
||||
* @return Call<Void>
|
||||
*/
|
||||
@POST("api/users/scrapTutorTab")
|
||||
Single<Void> apiUsersScrapTutorTabPost();
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param tutorId (required)
|
||||
* @return Call<TutorTabViewModel>
|
||||
*/
|
||||
@GET("api/users/tutorTab/{tutorId}")
|
||||
Single<TutorTabViewModel> apiUsersTutorTabByTutorIdGet(
|
||||
@retrofit2.http.Path("tutorId") String tutorId
|
||||
);
|
||||
|
||||
@POST("api/users/tutorTab/{tutorId}")
|
||||
Single<TutorTabViewModel> apiUsersTutorTabByTutorIdPost(
|
||||
@retrofit2.http.Path("tutorId") String tutorId, @retrofit2.http.Body TutorTabViewModel tutorTab
|
||||
);
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @param tutorId (required)
|
||||
* @param tutorTab (optional)
|
||||
* @return Call<Void>
|
||||
*/
|
||||
@Headers({
|
||||
"Content-Type:application/json"
|
||||
})
|
||||
@PUT("api/users/tutorTab/{tutorId}")
|
||||
Observable<Response<Void>> apiUsersTutorTabByTutorIdPut(
|
||||
@retrofit2.http.Path("tutorId") String tutorId, @retrofit2.http.Body TutorTabViewModel tutorTab
|
||||
);
|
||||
|
||||
}
|
@ -1,40 +1,70 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.IsUsingListBool;
|
||||
import com.uam.wmi.findmytutor.model.PagedResult;
|
||||
import com.uam.wmi.findmytutor.model.PagedResultReturnedTutors;
|
||||
import com.uam.wmi.findmytutor.model.ReturnedTutors;
|
||||
import com.uam.wmi.findmytutor.model.StudentIdModel;
|
||||
import com.uam.wmi.findmytutor.model.User;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.Completable;
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.ObservableEmitter;
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.Response;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.HTTP;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
import retrofit2.http.Path;
|
||||
import retrofit2.http.Query;
|
||||
|
||||
|
||||
public interface UserService {
|
||||
@GET("api/users")
|
||||
Single <List<User>> getAllUsers();
|
||||
|
||||
@GET("api/users")
|
||||
Single <List<User>> apiUsersGet();
|
||||
|
||||
@GET("api/users/tutors")
|
||||
Single <List<User>> getAllTutors();
|
||||
|
||||
@GET("api/users/tutors/online")
|
||||
Single <List<User>> getAllOnlineTutors();
|
||||
|
||||
@GET("api/users/tutors/active")
|
||||
Single <List<User>> getAllActiveTutors();
|
||||
|
||||
|
||||
|
||||
|
||||
@GET("api/users/tutors/offline")
|
||||
Single <List<User>> getAllOfflineTutors();
|
||||
|
||||
@GET("api/users/tutors/search")
|
||||
Single <List<User>> searchUser(@Query(value = "searchString", encoded = true) String searchString);
|
||||
|
||||
@POST("api/users")
|
||||
Completable createUser(@Body User user);
|
||||
|
||||
@GET("api/users/page/{pageNum}")
|
||||
Single <PagedResult> getPagedUsers(@Path("pageNum") String pageNum );
|
||||
Single <PagedResultReturnedTutors> getPagedUsers(@Path("pageNum") String pageNum );
|
||||
|
||||
@GET("api/users/tutors/page/{pageNum}")
|
||||
Single <PagedResult> getPagedTutors(@Path("pageNum") String pageNum);
|
||||
Single <PagedResultReturnedTutors> getPagedTutors(@Path("pageNum") Integer pageNum );
|
||||
|
||||
@GET("api/users/students/page/{pageNum}")
|
||||
Single<PagedResult> getPagedStudents(@Path("pageNum") String pageNum);
|
||||
Single<PagedResultReturnedTutors> getPagedStudents(@Path("pageNum") String pageNum);
|
||||
|
||||
@GET("api/users/{id}")
|
||||
Single<User> getUserByID(@Path("id") String userID);
|
||||
Single <User> getUserById(@Path("id") String userID);
|
||||
|
||||
@GET("api/users/self/{id}")
|
||||
Single <User> getSelf(@Path("id") String userID);
|
||||
|
||||
@PUT("api/users/{id}")
|
||||
Completable updateUserByID(@Path("id") String userID, @Body User user);
|
||||
@ -52,26 +82,28 @@ public interface UserService {
|
||||
Completable setUserInActive(@Path("userID") String userID);
|
||||
|
||||
@GET("api/users/blacklist/{tutorID}")
|
||||
Single<List<User>> getTutorBlacklistedByID(@Path("tutorID") String tutorID);
|
||||
Single <List<String>> getTutorBlacklistedByID(@Path("tutorID") String tutorID);
|
||||
|
||||
@PUT("api/users/blacklist/{tutorID}")
|
||||
Completable setTutorBlacklist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing);
|
||||
|
||||
@POST("api/users/blacklist/{tutorID}")
|
||||
Completable addStudentToBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
Observable <User> addStudentToBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
|
||||
@DELETE("api/users/blacklist/{tutorID}")
|
||||
// @DELETE("api/users/blacklist/{tutorID}")
|
||||
@HTTP(method = "DELETE", path = "api/users/blacklist/{tutorID}", hasBody = true)
|
||||
Completable removeStudentFromBlacklist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
|
||||
@GET("api/users/whitelist/{tutorID}")
|
||||
Single<List<User>> getTutorwhitelistedByID(@Path("tutorID") String tutorID);
|
||||
Single<List<String>> getTutorWhitelistedByID(@Path("tutorID") String tutorID);
|
||||
|
||||
@PUT("api/users/whitelist/{tutorID}")
|
||||
Completable setTutorWhitelist(@Path("tutorID") String tutorID, @Body IsUsingListBool isUsing);
|
||||
|
||||
@POST("api/users/whitelist/{tutorID}")
|
||||
Completable addStudentTowhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
Observable <User> addStudentToWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
|
||||
@DELETE("api/users/whitelist/{tutorID}")
|
||||
// @DELETE("api/users/whitelist/{tutorID}")
|
||||
@HTTP(method = "DELETE", path = "api/users/whitelist/{tutorID}", hasBody = true)
|
||||
Completable removeStudentFromWhitelist(@Path("tutorID") String tutorID, @Body StudentIdModel student);
|
||||
}
|
||||
|
@ -0,0 +1,8 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
public enum ActiveFragment {
|
||||
USER_LIST,
|
||||
SHARED_PREFERENCES,
|
||||
NONE
|
||||
}
|
||||
|
@ -0,0 +1,53 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import com.mapbox.geojson.Feature;
|
||||
import com.mapbox.geojson.FeatureCollection;
|
||||
import com.mapbox.geojson.Point;
|
||||
import com.mapbox.geojson.Polygon;
|
||||
import com.mapbox.turf.TurfClassification;
|
||||
import com.mapbox.turf.TurfJoins;
|
||||
import com.mapbox.turf.TurfMeasurement;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
;import static com.mapbox.geojson.FeatureCollection.fromJson;
|
||||
|
||||
public class ApproximatedLocalization {
|
||||
private FeatureCollection buildingSchema = null;
|
||||
|
||||
public ApproximatedLocalization(String buildingObject) {
|
||||
buildingSchema = fromJson(buildingObject);
|
||||
}
|
||||
|
||||
public String getNameOfBuildingPart(Point point) {
|
||||
|
||||
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
|
||||
boolean isInside = TurfJoins.inside(point, (Polygon) Objects.requireNonNull(feature.geometry()));
|
||||
|
||||
if (isInside)
|
||||
return Objects.requireNonNull(Objects.requireNonNull(feature.getStringProperty("name")));
|
||||
}
|
||||
|
||||
return Const.presenceApproximatedName;
|
||||
}
|
||||
|
||||
public List<Double> getMiddlePointOfBuildingPart(String buildingPart) {
|
||||
|
||||
for (Feature feature : Objects.requireNonNull(buildingSchema.features())) {
|
||||
String partName = feature.getStringProperty("name");
|
||||
|
||||
|
||||
if (buildingPart != null && buildingPart.equals(partName)) {
|
||||
|
||||
Double longitude = feature.getNumberProperty("longitude").doubleValue();
|
||||
Double latitude = feature.getNumberProperty("latitude").doubleValue();
|
||||
|
||||
return Arrays.asList(longitude, latitude);
|
||||
}
|
||||
}
|
||||
|
||||
return Arrays.asList(0.0, 0.0);
|
||||
}
|
||||
}
|
@ -1,88 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import timber.log.Timber;
|
||||
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class BroadcastLocalizationHandler extends BroadcastReceiver {
|
||||
|
||||
@Override
|
||||
public void onReceive(Context arg0, Intent intent) {
|
||||
final PendingResult pendingResult = goAsync();
|
||||
Task asyncTask = new Task(pendingResult, intent);
|
||||
asyncTask.execute();
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static class Task extends AsyncTask {
|
||||
private Double latitude;
|
||||
private Double longitude;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private CoordinateService coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
|
||||
private Task(PendingResult pendingResult, Intent intent) {
|
||||
this.latitude = intent.getDoubleExtra("latitude", 0);
|
||||
this.longitude = intent.getDoubleExtra("longitude", 0);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Object doInBackground(Object[] objects) {
|
||||
|
||||
try {
|
||||
|
||||
Coordinate coordinate = new Coordinate(
|
||||
this.latitude,
|
||||
this.longitude,
|
||||
PrefUtils.getUserStatus(getApplicationContext()),
|
||||
PrefUtils.getUserId(getApplicationContext())
|
||||
);
|
||||
|
||||
disposable.add(
|
||||
coordinateService
|
||||
.postCoordinate(coordinate)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<Coordinate>() {
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onSuccess(Coordinate coord) {
|
||||
Log.e("CoordinateService onSuccess", String.valueOf(coord));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("LoginError", "onError: " + e.getMessage());
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
26
app/src/main/java/com/uam/wmi/findmytutor/utils/Const.java
Normal file
@ -0,0 +1,26 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.util.Range;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class Const {
|
||||
public final static String BASE_URL = "https://s416084.projektstudencki.pl/master/";
|
||||
public final static Integer mapRefreshInterval = 6000;
|
||||
public final static Integer onlineBackgroundLocationInterval = 7000;
|
||||
public final static Integer offlineBackgroundLocationInterval = 360000;
|
||||
public final static Integer defaultMapZoom = 17;
|
||||
public final static Integer searchMapZoom = 13;
|
||||
public final static Double presenceLatitude = 52.466365;
|
||||
public final static Double presenceLongitude = 16.926792;
|
||||
public final static String presenceApproximatedName = "Unknown";
|
||||
public final static Range<Double> buildingLatitudeRange = Range.create(52.466092, 52.467529);
|
||||
public final static Range<Double> buildingLongitudeRange = Range.create(16.926159, 16.927759);
|
||||
public final static Range<Double> outsideLatitudeRange = Range.create(52.4651, 52.468837);
|
||||
public final static Range<Double> outsideLongitudeRange = Range.create(16.9186, 16.936004);
|
||||
public final static List<String> validApproximatedLocations = Arrays.asList("Skrzydło B", "Skrzydło A", "Aule", "Łącznik", "Biblioteka", "Hol", "Unknown");
|
||||
public final static String WMI_SSID_NAME = "wmi";
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,31 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.app.Dialog;
|
||||
import android.app.DialogFragment;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.activity.MapActivity;
|
||||
|
||||
public class EnableSharingDialog extends DialogFragment {
|
||||
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
return new AlertDialog.Builder(getActivity())
|
||||
.setTitle(R.string.sharing_modal_title)
|
||||
.setMessage(R.string.enable_sharing_question)
|
||||
.setPositiveButton(R.string.possitive_dialog_button, (dialog, which) ->
|
||||
dialogPositiveAnswer(getActivity())
|
||||
)
|
||||
.setNegativeButton(R.string.negative_dialog_button, (dialog, which) -> dialog.cancel()).create();
|
||||
}
|
||||
|
||||
private void dialogPositiveAnswer(Context context) {
|
||||
PrefUtils.storeEnableSharingLocalization(context, true);
|
||||
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,134 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.activity.BaseActivity;
|
||||
import com.uam.wmi.findmytutor.model.Feedback;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.FeedbackService;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Response;
|
||||
|
||||
public class FeedbackUtils {
|
||||
private Context activityContext;
|
||||
AlertDialog.Builder alertDialogBuilderUserInput;
|
||||
public FeedbackUtils(Context context){
|
||||
activityContext = context;
|
||||
}
|
||||
public void showNoteDialog(String subject) {
|
||||
|
||||
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(activityContext);
|
||||
View view = layoutInflaterAndroid.inflate(R.layout.feedback_modal, null);
|
||||
alertDialogBuilderUserInput = new AlertDialog.Builder(activityContext);
|
||||
alertDialogBuilderUserInput.setView(view).setPositiveButton(activityContext.getString(R.string.modal_feedback_send),null);
|
||||
final AlertDialog alertDialog = alertDialogBuilderUserInput.create();
|
||||
|
||||
EditText modalUserInput = view.findViewById(R.id.feedback_input);
|
||||
CheckBox modalIsAnonymous = view.findViewById(R.id.feedback_is_anonymous);
|
||||
TextView modalTitle = view.findViewById(R.id.feedback_modal_title);
|
||||
TextView modalSubtitle = view.findViewById(R.id.feedback_modal_subtitle);
|
||||
modalTitle.setText(subject);
|
||||
if( subject.equals(activityContext.getString(R.string.title_bug_report)) ){
|
||||
modalSubtitle.setText(activityContext.getString(R.string.title_bug_report_notice));
|
||||
} else {
|
||||
modalSubtitle.setText(activityContext.getString(R.string.title_feedback_report_notice));
|
||||
}
|
||||
alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialogInterface) {
|
||||
Button sendButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);
|
||||
sendButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
String body = modalUserInput.getText().toString();
|
||||
if(TextUtils.isEmpty(body)){
|
||||
Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_hint), Toast.LENGTH_SHORT).show();
|
||||
modalUserInput.requestFocus();
|
||||
}else{
|
||||
boolean mode = modalIsAnonymous.isChecked();
|
||||
sendFeedback(subject,body,mode);
|
||||
alertDialog.dismiss();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
alertDialog.show();
|
||||
}
|
||||
|
||||
private void sendFeedback(String header, String body, boolean mode) {
|
||||
String appVersion = null;
|
||||
String metadata = null;
|
||||
Feedback userFeedback= null;
|
||||
try {
|
||||
appVersion = activityContext.getPackageManager().getPackageInfo(activityContext.getPackageName(), 0).versionName;
|
||||
if( !mode ){
|
||||
userFeedback = new Feedback(mode,
|
||||
header,
|
||||
PrefUtils.getUserFirstName(activityContext) + " " + PrefUtils.getUserLastName(activityContext) + " | " + PrefUtils.getUserId(activityContext),
|
||||
"Android "+ Build.VERSION.RELEASE,
|
||||
appVersion,
|
||||
Build.MODEL,
|
||||
body);
|
||||
Log.d("FEEDBACK non anon", userFeedback.toString());
|
||||
|
||||
}else{
|
||||
userFeedback = new Feedback(mode,
|
||||
header,
|
||||
"anonymous",
|
||||
"Android "+ Build.VERSION.RELEASE,
|
||||
appVersion,
|
||||
Build.MODEL,
|
||||
body);
|
||||
Log.d("FEEDBACK anon",userFeedback.toString());
|
||||
}
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
|
||||
}
|
||||
FeedbackService feedbackService = ApiClient.getClient(activityContext).create(FeedbackService.class);
|
||||
|
||||
CompositeDisposable disposable = new CompositeDisposable();
|
||||
disposable.add(feedbackService.postFeedback(userFeedback)
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(this::handleResponse, this::handleError));
|
||||
}
|
||||
private void handleResponse( Response<Void> resp) {
|
||||
Toast.makeText(activityContext, activityContext.getString(R.string.modal_feedback_thankyou), Toast.LENGTH_SHORT).show();
|
||||
Log.d("FEEDBACK toast","gdzie jest mój tost");
|
||||
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
if (error instanceof HttpException) {
|
||||
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
Toast.makeText(activityContext,
|
||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
// Toast.makeText(activityContext,
|
||||
// "Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
Log.d("FEEDBACK handerr ",error.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class InfoHelperUtils {
|
||||
|
||||
public static void infoPopUp(View anchorView, int layoutId) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater)getApplicationContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
View popupView = Objects.requireNonNull(layoutInflater).inflate(layoutId, null);
|
||||
|
||||
PopupWindow popupWindow = new PopupWindow(popupView,
|
||||
LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
|
||||
// If the PopupWindow should be focusable
|
||||
popupWindow.setFocusable(true);
|
||||
// If you need the PopupWindow to dismiss when when touched outside
|
||||
popupWindow.setBackgroundDrawable(new ColorDrawable());
|
||||
int location[] = new int[2];
|
||||
// Get the View's(the one that was clicked in the Fragment) location
|
||||
anchorView.getLocationOnScreen(location);
|
||||
// Using location, the PopupWindow will be displayed right under anchorView
|
||||
popupWindow.showAtLocation(anchorView, Gravity.NO_GRAVITY,
|
||||
location[0] + anchorView.getWidth() / 2, location[1] + anchorView.getHeight());
|
||||
}
|
||||
}
|
@ -0,0 +1,80 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocaleHelper {
|
||||
|
||||
private static final String SELECTED_LANGUAGE = "Locale.Helper.Selected.Language";
|
||||
|
||||
public static Context onAttach(Context context) {
|
||||
String lang = getPersistedData(context, Locale.getDefault().getLanguage());
|
||||
return setLocale(context, lang);
|
||||
}
|
||||
|
||||
public static Context onAttach(Context context, String defaultLanguage) {
|
||||
String lang = getPersistedData(context, defaultLanguage);
|
||||
return setLocale(context, lang);
|
||||
}
|
||||
|
||||
public static String getLanguage(Context context) {
|
||||
return getPersistedData(context, Locale.getDefault().getLanguage());
|
||||
}
|
||||
|
||||
public static Context setLocale(Context context, String language) {
|
||||
persist(context, language);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
return updateResources(context, language);
|
||||
}
|
||||
|
||||
return updateResourcesLegacy(context, language);
|
||||
}
|
||||
|
||||
private static String getPersistedData(Context context, String defaultLanguage) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
return preferences.getString(SELECTED_LANGUAGE, defaultLanguage);
|
||||
}
|
||||
|
||||
private static void persist(Context context, String language) {
|
||||
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
|
||||
editor.putString(SELECTED_LANGUAGE, language);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.N)
|
||||
private static Context updateResources(Context context, String language) {
|
||||
Locale locale = new Locale(language);
|
||||
Locale.setDefault(locale);
|
||||
|
||||
Configuration configuration = context.getResources().getConfiguration();
|
||||
configuration.setLocale(locale);
|
||||
|
||||
return context.createConfigurationContext(configuration);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private static Context updateResourcesLegacy(Context context, String language) {
|
||||
Locale locale = new Locale(language);
|
||||
Locale.setDefault(locale);
|
||||
|
||||
Resources resources = context.getResources();
|
||||
|
||||
Configuration configuration = resources.getConfiguration();
|
||||
configuration.locale = locale;
|
||||
|
||||
resources.updateConfiguration(configuration, resources.getDisplayMetrics());
|
||||
|
||||
return context;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.support.v4.os.ConfigurationCompat;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class LocaleUtils {
|
||||
public static String getCurrentLocale() {
|
||||
return String.valueOf(ConfigurationCompat.getLocales(Resources.getSystem().getConfiguration()));
|
||||
}
|
||||
|
||||
private static Context updateResources(Context context, String language) {
|
||||
Locale locale = new Locale(language);
|
||||
Locale.setDefault(locale);
|
||||
|
||||
Resources res = context.getResources();
|
||||
Configuration config = new Configuration(res.getConfiguration());
|
||||
if (Build.VERSION.SDK_INT >= 22) {
|
||||
config.setLocale(locale);
|
||||
context = context.createConfigurationContext(config);
|
||||
} else {
|
||||
config.locale = locale;
|
||||
res.updateConfiguration(config, res.getDisplayMetrics());
|
||||
}
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,59 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.activity.BaseActivity;
|
||||
import com.uam.wmi.findmytutor.activity.MapActivity;
|
||||
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
import static java.security.AccessController.getContext;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public class ManualLocationUtils {
|
||||
private Context activityContext;
|
||||
|
||||
public ManualLocationUtils(Context context) {
|
||||
activityContext = context;
|
||||
}
|
||||
|
||||
private void handleError(Throwable error) {
|
||||
if (error instanceof HttpException) {
|
||||
|
||||
ResponseBody responseBody = ((HttpException) error).response().errorBody();
|
||||
Toast.makeText(activityContext,
|
||||
RestApiHelper.getErrorMessage(responseBody), Toast.LENGTH_SHORT).show();
|
||||
|
||||
} else {
|
||||
Toast.makeText(activityContext,
|
||||
"Network error " + error.getMessage(), Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.View;
|
||||
|
||||
import com.mapbox.mapboxsdk.annotations.Icon;
|
||||
import com.mapbox.mapboxsdk.annotations.InfoWindow;
|
||||
import com.mapbox.mapboxsdk.annotations.Marker;
|
||||
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
public class MapMarker{
|
||||
|
||||
private MarkerOptions markerOptions;
|
||||
private Marker marker;
|
||||
private String markerType;
|
||||
private Icon defaultIcon;
|
||||
private Icon markerIcon;
|
||||
|
||||
|
||||
public MapMarker(Marker marker, MarkerOptions markerOptions, Icon icon, String markerType) {
|
||||
this.setMarker(marker);
|
||||
this.setMarkerOptions(markerOptions);
|
||||
this.defaultIcon = icon;
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
public void restoreDefaultIcon() {
|
||||
this.marker.setIcon(this.defaultIcon);
|
||||
}
|
||||
|
||||
public void setDefaultIcon(Icon icon) {
|
||||
this.defaultIcon = icon;
|
||||
}
|
||||
|
||||
private void changeMarkerType(String markerType) {
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
public MarkerOptions getMarkerOptions() {
|
||||
return markerOptions;
|
||||
}
|
||||
|
||||
private void setMarkerOptions(MarkerOptions marker) {
|
||||
this.markerOptions = marker;
|
||||
}
|
||||
|
||||
public Marker getMarker() {
|
||||
return marker;
|
||||
}
|
||||
|
||||
public void setMarker(Marker marker) {
|
||||
this.marker = marker;
|
||||
}
|
||||
|
||||
public String getMarkerType() {
|
||||
return markerType;
|
||||
}
|
||||
|
||||
public void setMarkerType(String markerType) {
|
||||
this.markerType = markerType;
|
||||
}
|
||||
|
||||
}
|
127
app/src/main/java/com/uam/wmi/findmytutor/utils/MapUtils.java
Normal file
@ -0,0 +1,127 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.animation.TypeEvaluator;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.net.Uri;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLngBounds;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.outsideLatitudeRange;
|
||||
import static com.uam.wmi.findmytutor.utils.Const.outsideLongitudeRange;
|
||||
import static com.uam.wmi.findmytutor.utils.PrefUtils.shouldBatteryExclusionBeShown;
|
||||
|
||||
public class MapUtils {
|
||||
|
||||
// Boundires
|
||||
private static final LatLngBounds WMI_BOUNDS = new LatLngBounds.Builder()
|
||||
.include(new LatLng(52.46588041661952, 16.92543089389801))
|
||||
.include(new LatLng(52.467824943492374, 16.928574442863464))
|
||||
.build();
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setMapBoundsArea(Context context, MapboxMap mapboxMap, MapView mapView, Boolean check) {
|
||||
|
||||
if (check) {
|
||||
// Set bounds to WMI
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(WMI_BOUNDS);
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, 17, 0, 0, 4000);
|
||||
mapboxMap.setMinZoomPreference(16); // TODO export to map config
|
||||
} else {
|
||||
mapboxMap.setLatLngBoundsForCameraTarget(null);
|
||||
mapboxMap.setMinZoomPreference(2);
|
||||
}
|
||||
}
|
||||
|
||||
// Map Bounds Area
|
||||
public static void setZoom(MapboxMap mapboxMap, Integer zoom) {
|
||||
makeNewCamera(mapboxMap, 52.466799, 16.927002, zoom, 0, 0, 1000);
|
||||
mapboxMap.setMinZoomPreference(16); // TODO export to map config
|
||||
}
|
||||
|
||||
public static void makeNewCamera(MapboxMap mapboxMap, double lat, double lon, int zoomParam, int bearingParam, int tiltParam, int duration) {
|
||||
CameraPosition position = new CameraPosition.Builder()
|
||||
.target(new LatLng(lat, lon)) // Sets the new camera position
|
||||
.zoom(zoomParam) // Sets the zoom
|
||||
.bearing(bearingParam) // Rotate the camera
|
||||
.tilt(tiltParam) // Set the camera tilt
|
||||
.build(); // Creates a CameraPosition from the builder
|
||||
|
||||
mapboxMap.animateCamera(CameraUpdateFactory
|
||||
.newCameraPosition(position), duration);
|
||||
}
|
||||
|
||||
// read file to JSON
|
||||
public static String loadJsonFromAsset(Context context, String filename) {
|
||||
try {
|
||||
InputStream is = context.getAssets().open(filename);
|
||||
int size = is.available();
|
||||
byte[] buffer = new byte[size];
|
||||
is.read(buffer);
|
||||
is.close();
|
||||
return new String(buffer, "UTF-8");
|
||||
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static Boolean checkIfCoordinateIsValid(Location coordinate) {
|
||||
return outsideLatitudeRange.contains(coordinate.getLatitude()) && outsideLongitudeRange.contains(coordinate.getLongitude());
|
||||
}
|
||||
|
||||
public static Boolean checkIfCoordinateIsValid(Double latitude, Double longitude) {
|
||||
return Const.buildingLatitudeRange.contains(latitude) && Const.buildingLongitudeRange.contains(longitude);
|
||||
}
|
||||
|
||||
public static void BatteryOptimizationsExceptionCheck(Context context) {
|
||||
if (shouldBatteryExclusionBeShown(getApplicationContext())) {
|
||||
PrefUtils.setBatteryExlusionInfoStatus(getApplicationContext(), false);
|
||||
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
builder.setTitle(R.string.batter_exclusions_title);
|
||||
builder.setMessage(R.string.batter_exclusions_message)
|
||||
.setPositiveButton(R.string.ok, (dialog, id) -> {
|
||||
Intent intent = new Intent();
|
||||
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
Uri uri = Uri.fromParts("package", getApplicationContext().getPackageName(), null);
|
||||
intent.setData(uri);
|
||||
context.startActivity(intent);
|
||||
})
|
||||
.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||
|
||||
}).show();
|
||||
}
|
||||
}
|
||||
|
||||
// Function for marker animation
|
||||
public static class LatLngEvaluator implements TypeEvaluator<LatLng> {
|
||||
// Method is used to interpolate the marker animation.
|
||||
|
||||
private LatLng latLng = new LatLng();
|
||||
|
||||
@Override
|
||||
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
|
||||
latLng.setLatitude(startValue.getLatitude()
|
||||
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
|
||||
latLng.setLongitude(startValue.getLongitude()
|
||||
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
|
||||
return latLng;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
|
||||
public class MyDividerItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private static final int[] ATTRS = new int[]{
|
||||
android.R.attr.listDivider
|
||||
};
|
||||
|
||||
public static final int HORIZONTAL_LIST = LinearLayoutManager.HORIZONTAL;
|
||||
public static final int VERTICAL_LIST = LinearLayoutManager.VERTICAL;
|
||||
|
||||
private Drawable mDivider;
|
||||
private int mOrientation;
|
||||
private Context context;
|
||||
private int margin;
|
||||
|
||||
public MyDividerItemDecoration(Context context, int orientation, int margin) {
|
||||
this.context = context;
|
||||
this.margin = margin;
|
||||
final TypedArray a = context.obtainStyledAttributes(ATTRS);
|
||||
mDivider = a.getDrawable(0);
|
||||
a.recycle();
|
||||
setOrientation(orientation);
|
||||
}
|
||||
|
||||
public void setOrientation(int orientation) {
|
||||
if (orientation != HORIZONTAL_LIST && orientation != VERTICAL_LIST) {
|
||||
throw new IllegalArgumentException("invalid orientation");
|
||||
}
|
||||
mOrientation = orientation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
|
||||
if (mOrientation == VERTICAL_LIST) {
|
||||
drawVertical(c, parent);
|
||||
} else {
|
||||
drawHorizontal(c, parent);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawVertical(Canvas c, RecyclerView parent) {
|
||||
final int left = parent.getPaddingLeft();
|
||||
final int right = parent.getWidth() - parent.getPaddingRight();
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
final int top = child.getBottom() + params.bottomMargin;
|
||||
final int bottom = top + mDivider.getIntrinsicHeight();
|
||||
mDivider.setBounds(left, top, right, bottom);
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
|
||||
public void drawHorizontal(Canvas c, RecyclerView parent) {
|
||||
final int top = parent.getPaddingTop();
|
||||
final int bottom = parent.getHeight() - parent.getPaddingBottom();
|
||||
|
||||
final int childCount = parent.getChildCount();
|
||||
for (int i = 0; i < childCount; i++) {
|
||||
final View child = parent.getChildAt(i);
|
||||
final RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child
|
||||
.getLayoutParams();
|
||||
final int left = child.getRight() + params.rightMargin;
|
||||
final int right = left + mDivider.getIntrinsicHeight();
|
||||
mDivider.setBounds(left, top + dpToPx(margin), right, bottom - dpToPx(margin));
|
||||
mDivider.draw(c);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
if (mOrientation == VERTICAL_LIST) {
|
||||
outRect.set(0, 0, 0, mDivider.getIntrinsicHeight());
|
||||
} else {
|
||||
outRect.set(0, 0, mDivider.getIntrinsicWidth(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
private int dpToPx(int dp) {
|
||||
Resources r = context.getResources();
|
||||
return Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, r.getDisplayMetrics()));
|
||||
}
|
||||
}
|
@ -2,18 +2,38 @@ package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.util.Log;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.uam.wmi.findmytutor.activity.SharingFragment;
|
||||
import com.auth0.android.jwt.Claim;
|
||||
import com.auth0.android.jwt.JWT;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class PrefUtils {
|
||||
|
||||
public PrefUtils() {
|
||||
}
|
||||
|
||||
private static SharedPreferences getSharedPreferences(Context context) {
|
||||
return context.getSharedPreferences("APP_PREF", Context.MODE_PRIVATE);
|
||||
public static SharedPreferences getSharedPreferences(Context context) {
|
||||
return context.getSharedPreferences("com.uam.wmi.findmytutor_preferences", Context.MODE_PRIVATE);
|
||||
}
|
||||
|
||||
public static void getAllKeys(Context context) {
|
||||
Map<String, ?> keys = getSharedPreferences(context).getAll();
|
||||
|
||||
for (Map.Entry<String, ?> entry : keys.entrySet()) {
|
||||
Log.d("map values", entry.getKey() + ": " + entry.getValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static void cleanUserLocalStorage(Context context) {
|
||||
SharedPreferences preferences = getSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.clear().apply();
|
||||
}
|
||||
|
||||
public static void storeApiKey(Context context, String apiKey) {
|
||||
@ -36,9 +56,29 @@ public class PrefUtils {
|
||||
return getSharedPreferences(context).getString("USER_ID", null);
|
||||
}
|
||||
|
||||
public static boolean isStatusEnabled(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("key_status_enabled", false);
|
||||
|
||||
}
|
||||
public static void enableStatus(Context context){
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("key_status_enabled", true);
|
||||
editor.apply();
|
||||
}
|
||||
public static void disableStatus(Context context) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("key_status_enabled", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getUserStatus(Context context) {
|
||||
return getSharedPreferences(context).getString("USER_STATUS", "Android");
|
||||
return getSharedPreferences(context).getString("status_entry", "Dostępny");
|
||||
}
|
||||
|
||||
public static void storeStatus(Context context, String status) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("status_entry", status);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void storeIsTutor(Context applicationContext, boolean isTutor) {
|
||||
@ -51,7 +91,7 @@ public class PrefUtils {
|
||||
return getSharedPreferences(context).getBoolean("IS_TUTOR", false);
|
||||
}
|
||||
|
||||
public static void isLoggedIn(Context applicationContext, boolean isLogged) {
|
||||
public static void storeIsLoggedIn(Context applicationContext, boolean isLogged) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(applicationContext).edit();
|
||||
editor.putBoolean("IS_LOGGED_IN", isLogged);
|
||||
editor.apply();
|
||||
@ -61,21 +101,155 @@ public class PrefUtils {
|
||||
return getSharedPreferences(context).getBoolean("IS_LOGGED_IN", false);
|
||||
}
|
||||
|
||||
public static void cleanUserLocalStorage(Context context) {
|
||||
SharedPreferences preferences = getSharedPreferences(context);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.clear().apply();
|
||||
public static boolean isEnableSharingLocalization(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("key_sharing_enabled", false);
|
||||
}
|
||||
|
||||
public static void storeIsServiceRunning(Context context, Boolean flag) {
|
||||
public static void disableSharing(Context context){
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("IS_SERVIS_RUNNING", flag);
|
||||
editor.putBoolean("key_sharing_enabled", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean getIsServiceRunning(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("IS_SERVIS_RUNNING", false);
|
||||
public static void storeEnableSharingLocalization(Context context, Boolean isChecked) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("key_sharing_enabled", isChecked);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getLocationLevel(Context context) {
|
||||
return getSharedPreferences(context).getString("location_mode", "exact");
|
||||
}
|
||||
|
||||
public static void storeLocationMode(Context context, String mode) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("location_mode", mode);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void storeUserFirstName(Context context, String userName) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("USER_FIRST_NAME", userName);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getUserFirstName(Context context) {
|
||||
return getSharedPreferences(context).getString("USER_FIRST_NAME", null);
|
||||
}
|
||||
|
||||
public static void storeUserLastName(Context context, String userLastName) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("USER_LAST_NAME", userLastName);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getUserLastName(Context context) {
|
||||
return getSharedPreferences(context).getString("USER_LAST_NAME", null);
|
||||
}
|
||||
|
||||
public static void storeUserName(Context context, String userName) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("USER_NAME", userName);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void storeLocale(Context context, String locale) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("LOCALE", locale);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getLocale(Context context) {
|
||||
return getSharedPreferences(context).getString("LOCALE", LocaleUtils.getCurrentLocale());
|
||||
}
|
||||
|
||||
public static Boolean isBackgroundLocationServiceRunning(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("BACKGROUND_SERVICE_STATUS", false);
|
||||
}
|
||||
|
||||
public static void storeBackgroundLocationStatus(Context context, Boolean status) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("BACKGROUND_SERVICE_STATUS", status);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void putManualLocation(Context context, LatLng latLng, String approximatedLocation) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("key_location_level","3");
|
||||
editor.putString("location_mode", "manual");
|
||||
editor.putString("approx_manual_loc", approximatedLocation);
|
||||
/*editor.putBoolean("key_sharing_enabled", true);*/
|
||||
editor.putLong("longitude_manual_location", Double.doubleToRawLongBits(latLng.getLongitude()));
|
||||
editor.putLong("latitude_manual_location", Double.doubleToRawLongBits(latLng.getLatitude()));
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static LatLng getManualLocation(Context context) {
|
||||
return new LatLng(
|
||||
Double.longBitsToDouble(getSharedPreferences(context).getLong("latitude_manual_location", 0)),
|
||||
Double.longBitsToDouble(getSharedPreferences(context).getLong("longitude_manual_location", 0))
|
||||
);
|
||||
}
|
||||
|
||||
public static String getManualLocationApproximation(Context context) {
|
||||
return getSharedPreferences(context).getString("approx_manual_loc", "unknown");
|
||||
}
|
||||
|
||||
public static void putCurrentManualLocation(Context context,String manualId) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("current_manual_location", manualId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getCurrentManualLocation(Context context) {
|
||||
return getSharedPreferences(context).getString("current_manual_location", null);
|
||||
}
|
||||
public static void putCurrentManualLocationName(Context context, String locationName) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("current_manual_location_name", locationName);
|
||||
editor.apply();
|
||||
}
|
||||
public static String getCurrentManualLocationName(Context context) {
|
||||
return getSharedPreferences(context).getString("current_manual_location_name", null);
|
||||
}
|
||||
|
||||
public static void putShowOnlyOnlineUsers(Context context, Boolean flag) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("show_only_online_users_in_list", flag);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static Boolean getShowOnlyOnlineUsers(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("show_only_online_users_in_list", true);
|
||||
}
|
||||
|
||||
public static void useBlacklist(Context context, Boolean flag) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("blacklisting", flag);
|
||||
editor.putBoolean("whitelisting", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static void useWhitelist(Context context, Boolean flag) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("whitelisting", flag);
|
||||
editor.putBoolean("blacklisting", false);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static Boolean isBlackListing(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("blacklisting", false);
|
||||
}
|
||||
public static Boolean isWhiteListing(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("whitelisting", false);
|
||||
}
|
||||
|
||||
public static Boolean shouldBatteryExclusionBeShown(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("show_battery_exclusion", false);
|
||||
}
|
||||
|
||||
public static void setBatteryExlusionInfoStatus(Context context, Boolean flag) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("show_battery_exclusion", flag);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
@ -0,0 +1,62 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.GestureDetector;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
|
||||
/**
|
||||
* Created by ravi on 21/02/18.
|
||||
*/
|
||||
|
||||
public class RecyclerTouchListener implements RecyclerView.OnItemTouchListener {
|
||||
|
||||
private ClickListener clicklistener;
|
||||
private GestureDetector gestureDetector;
|
||||
|
||||
public RecyclerTouchListener(Context context, final RecyclerView recycleView, final ClickListener clicklistener) {
|
||||
|
||||
this.clicklistener = clicklistener;
|
||||
gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
|
||||
@Override
|
||||
public boolean onSingleTapUp(MotionEvent e) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLongPress(MotionEvent e) {
|
||||
View child = recycleView.findChildViewUnder(e.getX(), e.getY());
|
||||
if (child != null && clicklistener != null) {
|
||||
clicklistener.onLongClick(child, recycleView.getChildAdapterPosition(child));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) {
|
||||
View child = rv.findChildViewUnder(e.getX(), e.getY());
|
||||
if (child != null && clicklistener != null && gestureDetector.onTouchEvent(e)) {
|
||||
clicklistener.onClick(child, rv.getChildAdapterPosition(child));
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
|
||||
|
||||
}
|
||||
|
||||
public interface ClickListener {
|
||||
void onClick(View view, int position);
|
||||
|
||||
void onLongClick(View view, int position);
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.graphics.Color;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
|
||||
public class RestApiHelper extends Activity {
|
||||
|
||||
public RestApiHelper() {
|
||||
}
|
||||
|
||||
public static String getErrorMessage(ResponseBody responseBody) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(responseBody.string());
|
||||
return jsonObject.getString("message");
|
||||
} catch (Exception e) {
|
||||
return "Something went wrong!";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void showError(Throwable e) {
|
||||
String message = e.toString();
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException) e).response().errorBody();
|
||||
message = RestApiHelper.getErrorMessage(responseBody);
|
||||
} else {
|
||||
message ="Network Error !";
|
||||
}
|
||||
|
||||
Snackbar snackbar = Snackbar.make(findViewById(R.id.activity_content), message, Snackbar.LENGTH_LONG);
|
||||
View sbView = snackbar.getView();
|
||||
TextView textView = sbView.findViewById(android.support.design.R.id.snackbar_text);
|
||||
textView.setTextColor(Color.BLUE);
|
||||
snackbar.show();
|
||||
}
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
import android.content.Context;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
public class RightButtonPreference extends Preference {
|
||||
|
||||
private Button prefButton;
|
||||
private String buttonText;
|
||||
|
||||
public RightButtonPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWidgetLayoutResource(R.layout.preference_button_widget);
|
||||
init(context, attrs);
|
||||
}
|
||||
|
||||
private void init(Context context, AttributeSet attrs){
|
||||
for (int i=0;i<attrs.getAttributeCount();i++) {
|
||||
String attr = attrs.getAttributeName(i);
|
||||
try {
|
||||
if(attr.equalsIgnoreCase("key")){
|
||||
Log.e("BUTTON_ERR",attr);
|
||||
String val = attrs.getAttributeValue(i);
|
||||
|
||||
switch (val) {
|
||||
case "remove_manual_status":
|
||||
buttonText = context.getResources().getString(R.string.preference_manual_location_button_remove);
|
||||
break;
|
||||
case "manual_location_button":
|
||||
buttonText = context.getResources().getString(R.string.preference_manual_location_button);
|
||||
break;
|
||||
case "remove_manual_location":
|
||||
buttonText = context.getResources().getString(R.string.preference_manual_location_button_remove);
|
||||
break;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
buttonText = "";
|
||||
Log.e("BUTTON_ERR", String.valueOf(e));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setText(String text){
|
||||
prefButton.setText(text);
|
||||
}
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
return super.onCreateView(parent);
|
||||
}
|
||||
@Override
|
||||
protected void onBindView(View view)
|
||||
{
|
||||
super.onBindView(view);
|
||||
prefButton = view.findViewById(R.id.button_choose_from_map);
|
||||
prefButton.setText(buttonText);
|
||||
if(prefButton != null)
|
||||
{
|
||||
prefButton.setOnClickListener(view1 -> {
|
||||
callChangeListener(null);
|
||||
notifyChanged();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.support.v7.widget.SearchView;
|
||||
|
||||
import io.reactivex.Observable;
|
||||
import io.reactivex.subjects.PublishSubject;
|
||||
|
||||
public class RxSearchObservable {
|
||||
|
||||
private RxSearchObservable() {
|
||||
}
|
||||
|
||||
public static Observable<String> fromView(SearchView searchView) {
|
||||
|
||||
final PublishSubject<String> subject = PublishSubject.create();
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String s) {
|
||||
subject.onNext(s);
|
||||
searchView.clearFocus();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String text) {
|
||||
subject.onNext(text);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
return subject;
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.ColorDrawable;
|
||||
import android.preference.Preference;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupWindow;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
public class SharingInfoPopupButtonPreference extends Preference {
|
||||
|
||||
public SharingInfoPopupButtonPreference(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWidgetLayoutResource(R.layout.preference_popup_info_button_widget);
|
||||
}
|
||||
@Override
|
||||
protected View onCreateView(ViewGroup parent) {
|
||||
View view = super.onCreateView(parent);
|
||||
// LayoutInflater li = (LayoutInflater)getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE );
|
||||
// View temp =li.inflate( R.layout.preference_button_widget, parent, false);
|
||||
return view;
|
||||
}
|
||||
@Override
|
||||
protected void onBindView(View view)
|
||||
{
|
||||
super.onBindView(view);
|
||||
ImageButton button = view.findViewById(R.id.sharingTabInfoImageButton);
|
||||
button.setOnClickListener(v-> {
|
||||
InfoHelperUtils.infoPopUp(v,R.layout.info_popup_sharing_tab);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,20 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
public enum SharingLevel {
|
||||
PRESENCE("presence"),
|
||||
APPROXIMATED("approximated"),
|
||||
EXACT("exact"),
|
||||
PREDEFINED("predefined"),
|
||||
MANUAL("manual");
|
||||
|
||||
private final String text;
|
||||
|
||||
SharingLevel(final String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return text;
|
||||
}
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.NetworkInfo;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class WifiUtils {
|
||||
|
||||
public static String getWifiName(Context context) {
|
||||
WifiManager manager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if (Objects.requireNonNull(manager).isWifiEnabled()) {
|
||||
WifiInfo wifiInfo = manager.getConnectionInfo();
|
||||
if (wifiInfo != null) {
|
||||
NetworkInfo.DetailedState state = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState());
|
||||
if (state == NetworkInfo.DetailedState.CONNECTED || state == NetworkInfo.DetailedState.OBTAINING_IPADDR) {
|
||||
return wifiInfo.getSSID();
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Boolean checkIfUserIsInRangeOfWmiWifi(Context context) {
|
||||
return Objects.equals(getWifiName(context), Const.WMI_SSID_NAME);
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
|
||||
public class WrapContentLinearLayoutManager extends LinearLayoutManager {
|
||||
public WrapContentLinearLayoutManager(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
|
||||
try {
|
||||
super.onLayoutChildren(recycler, state);
|
||||
} catch (IndexOutOfBoundsException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
BIN
app/src/main/res/drawable-hdpi/outline_info_white_18.png
Normal file
After Width: | Height: | Size: 381 B |
BIN
app/src/main/res/drawable-hdpi/outline_info_white_24.png
Normal file
After Width: | Height: | Size: 447 B |
BIN
app/src/main/res/drawable-hdpi/outline_info_white_36.png
Normal file
After Width: | Height: | Size: 660 B |
BIN
app/src/main/res/drawable-hdpi/outline_info_white_48.png
Normal file
After Width: | Height: | Size: 830 B |
BIN
app/src/main/res/drawable-mdpi/outline_info_white_18.png
Normal file
After Width: | Height: | Size: 259 B |
BIN
app/src/main/res/drawable-mdpi/outline_info_white_24.png
Normal file
After Width: | Height: | Size: 306 B |
BIN
app/src/main/res/drawable-mdpi/outline_info_white_36.png
Normal file
After Width: | Height: | Size: 447 B |
BIN
app/src/main/res/drawable-mdpi/outline_info_white_48.png
Normal file
After Width: | Height: | Size: 595 B |
12
app/src/main/res/drawable-v21/ic_menu_camera.xml
Normal file
@ -0,0 +1,12 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0" />
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9,2L7.17,4H4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2V6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2H9zm3,15c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z" />
|
||||
</vector>
|
9
app/src/main/res/drawable-v21/ic_menu_gallery.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M22,16V4c0,-1.1 -0.9,-2 -2,-2H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2zm-11,-4l2.03,2.71L16,11l4,5H8l3,-4zM2,6v14c0,1.1 0.9,2 2,2h14v-2H4V6H2z" />
|
||||
</vector>
|
9
app/src/main/res/drawable-v21/ic_menu_manage.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M22.7,19l-9.1,-9.1c0.9,-2.3 0.4,-5 -1.5,-6.9 -2,-2 -5,-2.4 -7.4,-1.3L9,6 6,9 1.6,4.7C0.4,7.1 0.9,10.1 2.9,12.1c1.9,1.9 4.6,2.4 6.9,1.5l9.1,9.1c0.4,0.4 1,0.4 1.4,0l2.3,-2.3c0.5,-0.4 0.5,-1.1 0.1,-1.4z" />
|
||||
</vector>
|
9
app/src/main/res/drawable-v21/ic_menu_send.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M2.01,21L23,12 2.01,3 2,10l15,2 -15,2z" />
|
||||
</vector>
|
9
app/src/main/res/drawable-v21/ic_menu_share.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M18,16.08c-0.76,0 -1.44,0.3 -1.96,0.77L8.91,12.7c0.05,-0.23 0.09,-0.46 0.09,-0.7s-0.04,-0.47 -0.09,-0.7l7.05,-4.11c0.54,0.5 1.25,0.81 2.04,0.81 1.66,0 3,-1.34 3,-3s-1.34,-3 -3,-3 -3,1.34 -3,3c0,0.24 0.04,0.47 0.09,0.7L8.04,9.81C7.5,9.31 6.79,9 6,9c-1.66,0 -3,1.34 -3,3s1.34,3 3,3c0.79,0 1.5,-0.31 2.04,-0.81l7.12,4.16c-0.05,0.21 -0.08,0.43 -0.08,0.65 0,1.61 1.31,2.92 2.92,2.92 1.61,0 2.92,-1.31 2.92,-2.92s-1.31,-2.92 -2.92,-2.92z" />
|
||||
</vector>
|
9
app/src/main/res/drawable-v21/ic_menu_slideshow.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportHeight="24.0"
|
||||
android:viewportWidth="24.0">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,6H2v14c0,1.1 0.9,2 2,2h14v-2H4V6zm16,-4H8c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V4c0,-1.1 -0.9,-2 -2,-2zm-8,12.5v-9l6,4.5 -6,4.5z" />
|
||||
</vector>
|
11
app/src/main/res/drawable-v24/fab_label_background.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<solid android:color="@color/black_semi_transparent"/>
|
||||
<padding
|
||||
android:left="16dp"
|
||||
android:top="4dp"
|
||||
android:right="16dp"
|
||||
android:bottom="4dp"/>
|
||||
<corners
|
||||
android:radius="2dp"/>
|
||||
</shape>
|
BIN
app/src/main/res/drawable-xhdpi/outline_info_white_18.png
Normal file
After Width: | Height: | Size: 447 B |