SharingActivity and SettingsActivity #15
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="WizardSettings">
|
||||
<option name="children">
|
||||
<map>
|
||||
<entry key="imageWizard">
|
||||
<value>
|
||||
<PersistentState />
|
||||
</value>
|
||||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
@ -8,7 +8,7 @@ android {
|
||||
}
|
||||
defaultConfig {
|
||||
applicationId "com.uam.wmi.findmytutor"
|
||||
minSdkVersion 19
|
||||
minSdkVersion 23
|
||||
targetSdkVersion 27
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
@ -33,9 +33,10 @@ dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||
implementation 'com.android.support:design:27.1.1'
|
||||
implementation 'com.android.support.constraint:constraint-layout:1.1.2'
|
||||
|
||||
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'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
@ -55,5 +56,6 @@ dependencies {
|
||||
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'
|
||||
|
||||
}
|
||||
|
@ -1,15 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.uam.wmi.findmytutor">
|
||||
|
||||
<!-- To auto-complete the email text field in the login form with the user's emails -->
|
||||
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
|
||||
<uses-permission android:name="android.permission.READ_PROFILE" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
||||
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
|
||||
<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" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@ -17,9 +22,12 @@
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name=".activity.StartupActivity"
|
||||
|
||||
android:theme="@style/AppTheme"
|
||||
tools:ignore="GoogleAppIndexingWarning">
|
||||
|
||||
<activity android:name=".activity.StartupActivity"
|
||||
|
||||
android:label="@string/title_activity_startup"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
@ -45,6 +53,17 @@
|
||||
<activity
|
||||
android:name=".activity.SharingActivity"
|
||||
android:label="@string/title_activity_sharing" />
|
||||
|
||||
|
||||
|
||||
|
||||
<service
|
||||
android:name=".service.BackgroundLocalizationService"
|
||||
android:exported="false"
|
||||
android:launchMode="singleTop"
|
||||
android:enabled="true"
|
||||
/>
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
</manifest>
|
||||
|
@ -31,6 +31,8 @@ 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.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
||||
@ -209,7 +211,7 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
// 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 = new UserLoginTask(email, password, loginOption);
|
||||
mAuthTask.execute((Void) null);
|
||||
}
|
||||
}
|
||||
@ -307,7 +309,7 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
private interface ProfileQuery {
|
||||
String[] PROJECTION = {
|
||||
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||
};
|
||||
|
||||
int ADDRESS = 0;
|
||||
@ -331,16 +333,18 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
UserLoginTask(String email, String password, Boolean loginOption) {
|
||||
mEmail = email;
|
||||
mPassword = password;
|
||||
isTutor=loginOption;
|
||||
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("string",mPassword,"string",(isTutor)?"tutor":"student","string","string",mEmail);
|
||||
Log.d("LoginRole","Login role is : " + user.getTitle());
|
||||
LdapUser user = new LdapUser(mEmail,mPassword,"admin",(isTutor)?"Tutor":"Student","string","string",mEmail);
|
||||
|
||||
disposable.add(
|
||||
ldapService
|
||||
.fakeValidate(user)
|
||||
@ -349,7 +353,15 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
.subscribeWith(new DisposableSingleObserver<JwtToken>() {
|
||||
@Override
|
||||
public void onSuccess(JwtToken jwtToken) {
|
||||
PrefUtils.storeApiKey(getApplicationContext(), jwtToken.getToken());
|
||||
String token = jwtToken.getToken();
|
||||
|
||||
JWT jwt = new JWT(token);
|
||||
Claim role = jwt.getClaim("nameid");
|
||||
|
||||
PrefUtils.storeIsLoggedIn(getApplicationContext(), true);
|
||||
PrefUtils.storeApiKey(getApplicationContext(), token);
|
||||
PrefUtils.storeUserId(getApplicationContext(), role.asString());
|
||||
|
||||
onPostExecute(true);
|
||||
}
|
||||
|
||||
@ -368,9 +380,9 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
||||
showProgress(false);
|
||||
|
||||
if (success) {
|
||||
// DONE: returns the role of signed user and return code
|
||||
Intent data = new Intent();
|
||||
data.putExtra("is_tutor", isTutor);
|
||||
String txt = "Main Activity";
|
||||
data.setData(Uri.parse(txt));
|
||||
setResult(RESULT_OK, data);
|
||||
finish();
|
||||
} else {
|
||||
|
@ -2,42 +2,46 @@ package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.app.FragmentTransaction;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.location.Geocoder;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.design.widget.BottomNavigationView;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.NavigationView;
|
||||
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
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.text.TextUtils;
|
||||
import android.view.Menu;
|
||||
|
||||
import android.view.MenuItem;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.mapbox.mapboxsdk.Mapbox;
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
@ -48,16 +52,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
private NotificationFragment notificationFragment;
|
||||
private ProfileFragment profileFragment;
|
||||
|
||||
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
boolean boolean_permission;
|
||||
SharedPreferences mPref;
|
||||
SharedPreferences.Editor medit;
|
||||
Double latitude, longitude;
|
||||
Geocoder geocoder;
|
||||
|
||||
private DrawerLayout drawerLayout;
|
||||
private ActionBarDrawerToggle actionBarDrawerToggle;
|
||||
|
||||
public List<Coordinate> coordinates;
|
||||
public List<Coordinate> getCoordinates() {
|
||||
return this.coordinates;
|
||||
}
|
||||
public void setCoordinates(List<Coordinate> coordinates) {
|
||||
this.coordinates = coordinates;
|
||||
}
|
||||
|
||||
// 4 search
|
||||
private ListView listView;
|
||||
@ -68,6 +73,8 @@ public class MainActivity extends AppCompatActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
|
||||
configureconfigureNavigationDrawer();
|
||||
@ -80,8 +87,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
Toolbar toolbar = findViewById(R.id.toolbar_main);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
//***/
|
||||
|
||||
setData();
|
||||
adapter = new ListViewAdapter(this, R.layout.item_listview, stringArrayList);
|
||||
listView.setAdapter(adapter);
|
||||
@ -94,8 +99,6 @@ public class MainActivity extends AppCompatActivity {
|
||||
});
|
||||
|
||||
|
||||
//***/
|
||||
|
||||
drawerLayout = findViewById(R.id.drawer_layout);
|
||||
|
||||
actionBarDrawerToggle = new ActionBarDrawerToggle(this, drawerLayout, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
@ -121,10 +124,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
|
||||
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
|
||||
mMainNav = (BottomNavigationView) findViewById(R.id.main_nav);
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
Bundle extras = getIntent().getExtras();
|
||||
isTutor = (boolean) extras.get("is_tutor");
|
||||
if (!isTutor){
|
||||
if (!isTutor) {
|
||||
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@ -161,16 +163,17 @@ public class MainActivity extends AppCompatActivity {
|
||||
private void configureLogoutButton(){
|
||||
// Logout button
|
||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||
button.setOnClickListener(new View.OnClickListener(){
|
||||
|
||||
button.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
SharedPreferences preferences = getSharedPreferences("fmtPrefs",Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = preferences.edit();
|
||||
editor.clear().commit();
|
||||
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||
|
||||
Intent i = getBaseContext().getPackageManager()
|
||||
.getLaunchIntentForPackage( getBaseContext().getPackageName() );
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||
if (i != null) {
|
||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
}
|
||||
startActivity(i);
|
||||
finish();
|
||||
}
|
||||
@ -220,14 +223,22 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostCreate(Bundle savedInstanceState) {
|
||||
super.onPostCreate(savedInstanceState);
|
||||
|
||||
|
||||
// Sync the toggle state after onRestoreInstanceState has occurred.
|
||||
actionBarDrawerToggle.syncState();
|
||||
|
||||
if (isTutor) {
|
||||
fn_permission();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -236,12 +247,73 @@ public class MainActivity extends AppCompatActivity {
|
||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||
return true;
|
||||
}
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
startForegroundService(intent);
|
||||
} else {
|
||||
startService(intent);
|
||||
}
|
||||
|
||||
} else {
|
||||
Toast.makeText(getApplicationContext(), "Please enable the gps", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, String[] permissions, 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();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,20 +1,22 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
|
||||
public class StartupActivity extends AppCompatActivity {
|
||||
private static final int AUTHENTICATION_REQUEST_CODE = 666;
|
||||
private static final int AUTHENTICATION_REQUEST_CODE = 666;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
||||
|
||||
if (isLoggedIn()){
|
||||
|
||||
Intent startupIntent = new Intent(this, MainActivity.class);
|
||||
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(startupIntent);
|
||||
@ -25,20 +27,17 @@ public class StartupActivity extends AppCompatActivity {
|
||||
}
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
//to nie ma miec layoutu wiec elo
|
||||
// setContentView(R.layout.activity_startup);
|
||||
}
|
||||
|
||||
private boolean isLoggedIn() {
|
||||
return this.getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE).getBoolean("loggedIn",false);
|
||||
return PrefUtils.isLoggedIn(getApplicationContext());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data){
|
||||
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);
|
||||
startupIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startupIntent.putExtra("is_tutor",(boolean) data.getExtras().get("is_tutor"));
|
||||
startActivity(startupIntent);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.uam.wmi.findmytutor.model;
|
||||
|
||||
import android.util.Range;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.Objects;
|
||||
@ -11,18 +13,21 @@ import io.swagger.annotations.ApiModelProperty;
|
||||
* Coordinate
|
||||
*/
|
||||
|
||||
public class Coordinate extends BaseResponse{
|
||||
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;
|
||||
|
||||
@SerializedName("latitude")
|
||||
private Float latitude = null;
|
||||
private Double latitude;
|
||||
|
||||
@SerializedName("longitude")
|
||||
private Float longitude = null;
|
||||
private Double longitude = null;
|
||||
|
||||
@SerializedName("altitude")
|
||||
private Float altitude = null;
|
||||
private Double altitude = null;
|
||||
|
||||
@SerializedName("userId")
|
||||
private String userId = null;
|
||||
@ -37,7 +42,21 @@ public class Coordinate extends BaseResponse{
|
||||
private Long timeStamp = null;
|
||||
|
||||
@SerializedName("label")
|
||||
private String label = null;
|
||||
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);
|
||||
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.userId = userId;
|
||||
this.label = label;
|
||||
}
|
||||
|
||||
public Coordinate (Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Coordinate coordinateId(UUID coordinateId) {
|
||||
this.coordinateId = coordinateId;
|
||||
@ -57,7 +76,7 @@ public class Coordinate extends BaseResponse{
|
||||
this.coordinateId = coordinateId;
|
||||
}
|
||||
|
||||
public Coordinate latitude(Float latitude) {
|
||||
public Coordinate latitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
return this;
|
||||
}
|
||||
@ -67,15 +86,15 @@ public class Coordinate extends BaseResponse{
|
||||
* @return latitude
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Float getLatitude() {
|
||||
public Double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Float latitude) {
|
||||
public void setLatitude(Double latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Coordinate longitude(Float longitude) {
|
||||
public Coordinate longitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
return this;
|
||||
}
|
||||
@ -85,15 +104,15 @@ public class Coordinate extends BaseResponse{
|
||||
* @return longitude
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Float getLongitude() {
|
||||
public Double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Float longitude) {
|
||||
public void setLongitude(Double longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Coordinate altitude(Float altitude) {
|
||||
public Coordinate altitude(Double altitude) {
|
||||
this.altitude = altitude;
|
||||
return this;
|
||||
}
|
||||
@ -103,11 +122,11 @@ public class Coordinate extends BaseResponse{
|
||||
* @return altitude
|
||||
**/
|
||||
@ApiModelProperty(required = true, value = "")
|
||||
public Float getAltitude() {
|
||||
public Double getAltitude() {
|
||||
return altitude;
|
||||
}
|
||||
|
||||
public void setAltitude(Float altitude) {
|
||||
public void setAltitude(Double altitude) {
|
||||
this.altitude = altitude;
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class ApiClient {
|
||||
// Adding Authorization token (API Key)
|
||||
// Requests will be denied without API key
|
||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||
requestBuilder.addHeader("Authorization", PrefUtils.getApiKey(context));
|
||||
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||
}
|
||||
|
||||
Request request = requestBuilder.build();
|
||||
|
@ -0,0 +1,365 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Notification;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.location.Location;
|
||||
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.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.jakewharton.retrofit2.adapter.rxjava2.HttpException;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
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;
|
||||
|
||||
public class BackgroundLocalizationService extends Service {
|
||||
|
||||
public static String str_receiver = "background.location.broadcast";
|
||||
private static final String TAG = "MyLocationService";
|
||||
private LocationManager mLocationManager = null;
|
||||
private static final int LOCATION_INTERVAL = 1000;
|
||||
private static final float LOCATION_DISTANCE = 10f;
|
||||
private Handler mHandler = new Handler();
|
||||
private static long notify_interval = 10000;
|
||||
|
||||
double latitude, longitude;
|
||||
boolean isGPSEnable = false;
|
||||
boolean isNetworkEnable = false;
|
||||
|
||||
Location mLastLocation;
|
||||
Intent intent;
|
||||
LocationManager locationManager;
|
||||
Location location;
|
||||
|
||||
|
||||
private class LocationListener implements android.location.LocationListener {
|
||||
|
||||
public LocationListener(String provider) {
|
||||
Log.e(TAG, "LocationListener " + provider);
|
||||
mLastLocation = new Location(provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
Log.e(TAG, "onLocationChanged: " + location);
|
||||
mLastLocation.set(location);
|
||||
fn_update(mLastLocation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
Log.e(TAG, "onProviderDisabled: " + provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
Log.e(TAG, "onProviderEnabled: " + provider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
||||
Log.e(TAG, "onStatusChanged: " + provider);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
Log.e(TAG, "onStartCommand");
|
||||
super.onStartCommand(intent, flags, startId);
|
||||
|
||||
return START_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
|
||||
Log.e(TAG, "onCreate");
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
initializeLocationManager();
|
||||
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(
|
||||
LocationManager.PASSIVE_PROVIDER,
|
||||
LOCATION_INTERVAL,
|
||||
LOCATION_DISTANCE,
|
||||
mLocationListeners[0]
|
||||
);
|
||||
} catch (java.lang.SecurityException ex) {
|
||||
Log.i(TAG, "fail to request location update, ignore", ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Log.d(TAG, "network provider does not exist, " + ex.getMessage());
|
||||
}
|
||||
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(
|
||||
LocationManager.GPS_PROVIDER,
|
||||
LOCATION_INTERVAL,
|
||||
LOCATION_DISTANCE,
|
||||
mLocationListeners[1]
|
||||
);
|
||||
} catch (java.lang.SecurityException ex) {
|
||||
Log.i(TAG, "fail to request location update, ignore", ex);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
Log.d(TAG, "gps provider does not exist " + ex.getMessage());
|
||||
}
|
||||
Timer mTimer = new Timer();
|
||||
mTimer.schedule(new TimerTaskToGetLocation(), 5, notify_interval);
|
||||
intent = new Intent(str_receiver);
|
||||
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
private void startMyOwnForeground() {
|
||||
|
||||
String NOTIFICATION_CHANNEL_ID = "com.example.simpleapp";
|
||||
String channelName = "My Background Service";
|
||||
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
||||
chan.setLightColor(Color.BLUE);
|
||||
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
||||
NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
|
||||
assert manager != null;
|
||||
manager.createNotificationChannel(chan);
|
||||
|
||||
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, NOTIFICATION_CHANNEL_ID);
|
||||
Notification notification = notificationBuilder.setOngoing(true)
|
||||
.setContentTitle("App is running in background")
|
||||
.setPriority(NotificationManager.IMPORTANCE_MIN)
|
||||
.setCategory(Notification.CATEGORY_SERVICE)
|
||||
.build();
|
||||
startForeground(2, notification);
|
||||
}
|
||||
|
||||
|
||||
private void fn_getlocation() {
|
||||
locationManager = (LocationManager) getApplicationContext().getSystemService(LOCATION_SERVICE);
|
||||
isGPSEnable = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
|
||||
isNetworkEnable = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
|
||||
|
||||
if (!isGPSEnable && !isNetworkEnable) {
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
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();
|
||||
|
||||
fn_update(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();
|
||||
fn_update(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());
|
||||
Log.e(TAG, String.valueOf(location));
|
||||
new Task(location).execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.e(TAG, "onDestroy");
|
||||
super.onDestroy();
|
||||
if (mLocationManager != null) {
|
||||
for (int i = 0; i < mLocationListeners.length; i++) {
|
||||
try {
|
||||
if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
return;
|
||||
}
|
||||
mLocationManager.removeUpdates(mLocationListeners[i]);
|
||||
} catch (Exception ex) {
|
||||
Log.i(TAG, "fail to remove location listener, ignore", ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initializeLocationManager() {
|
||||
Log.e(TAG, "initializeLocationManager - LOCATION_INTERVAL: " + LOCATION_INTERVAL + " LOCATION_DISTANCE: " + LOCATION_DISTANCE);
|
||||
if (mLocationManager == null) {
|
||||
mLocationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE);
|
||||
}
|
||||
}
|
||||
|
||||
private 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(Location location) {
|
||||
this.latitude = location.getLatitude();
|
||||
this.longitude = location.getLongitude();
|
||||
}
|
||||
|
||||
|
||||
@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));
|
||||
}
|
||||
|
||||
@SuppressLint("LongLogTag")
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
((HttpException) e).code();
|
||||
Log.e("CoordinateService onError", e.getMessage());
|
||||
|
||||
if (e instanceof HttpException) {
|
||||
ResponseBody responseBody = ((HttpException)e).response().errorBody();
|
||||
Log.e("CoordinateService onError", getErrorMessage(responseBody));
|
||||
}
|
||||
|
||||
}
|
||||
}));
|
||||
} catch (IllegalArgumentException e) {
|
||||
Timber.e(String.valueOf(e));
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getErrorMessage(ResponseBody responseBody) {
|
||||
try {
|
||||
JSONObject jsonObject = new JSONObject(responseBody.string());
|
||||
return jsonObject.getString("message");
|
||||
} catch (Exception e) {
|
||||
return e.getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -1,13 +1,12 @@
|
||||
package com.uam.wmi.findmytutor.service;
|
||||
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import io.reactivex.Single;
|
||||
import retrofit2.http.Body;
|
||||
import retrofit2.http.DELETE;
|
||||
|
||||
import retrofit2.http.GET;
|
||||
import retrofit2.http.POST;
|
||||
import retrofit2.http.PUT;
|
||||
@ -16,31 +15,31 @@ import retrofit2.http.Path;
|
||||
public interface CoordinateService {
|
||||
|
||||
@GET("api/coordinates")
|
||||
Call<List<Coordinate>> getAllCoordinates();
|
||||
Single<List<Coordinate>> getAllCoordinates();
|
||||
|
||||
@GET("api/coordinates/{id}")
|
||||
Call<Coordinate> getCoordinatesById(@Path("id") String id);
|
||||
Single<Coordinate> getCoordinatesById(@Path("id") String id);
|
||||
|
||||
@GET("api/coordinates/user/{userId}")
|
||||
Call<List<Coordinate>> getCoordinatesByUserId(@Path("userId") String userId);
|
||||
Single<List<Coordinate>> getCoordinatesByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/userTop/{userId}")
|
||||
Call<List<Coordinate>> getTopCoordinatesByUserId(@Path("userId") String userId);
|
||||
Single<List<Coordinate>> getTopCoordinatesByUserId(@Path("userId") String userId);
|
||||
|
||||
@GET("api/coordinates/top")
|
||||
Call<List<Coordinate>> getTopCoordinates();
|
||||
Single<List<Coordinate>> getTopCoordinates();
|
||||
|
||||
@GET("api/coordinates/top/online")
|
||||
Call<List<Coordinate>> getOnlineCoordinates();
|
||||
Single<List<Coordinate>> getOnlineCoordinates();
|
||||
|
||||
@POST("api/coordinates")
|
||||
Call<ResponseBody> postCoordinate(@Body Coordinate coordinate);
|
||||
Single <Coordinate> postCoordinate(@Body Coordinate coordinate);
|
||||
|
||||
@PUT("api/coordinates/{id}")
|
||||
Call<Coordinate> putCoordinatesById(@Path("id") String id);
|
||||
Single<Coordinate> putCoordinatesById(@Path("id") String id);
|
||||
|
||||
@DELETE("api/coordinates/{id}")
|
||||
Call<Coordinate> deleteCoordinatesById(@Path("id") String id);
|
||||
Single<Coordinate> deleteCoordinatesById(@Path("id") String id);
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,104 @@
|
||||
package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.AsyncTask;
|
||||
import android.support.v4.content.LocalBroadcastManager;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.Log;
|
||||
|
||||
import com.auth0.android.jwt.Claim;
|
||||
import com.auth0.android.jwt.JWT;
|
||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
import com.uam.wmi.findmytutor.service.LdapService;
|
||||
|
||||
import org.json.JSONObject;
|
||||
import org.reactivestreams.Subscriber;
|
||||
import org.reactivestreams.Subscription;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.observers.DisposableObserver;
|
||||
import io.reactivex.observers.DisposableSingleObserver;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import timber.log.Timber;
|
||||
|
||||
import static android.content.ContentValues.TAG;
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -1,98 +0,0 @@
|
||||
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 + dpToPx(margin), top, right - dpToPx(margin), 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,12 +2,13 @@ package com.uam.wmi.findmytutor.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import com.auth0.android.jwt.Claim;
|
||||
import com.auth0.android.jwt.JWT;
|
||||
|
||||
public class PrefUtils {
|
||||
/**
|
||||
* Storing API Key in shared preferences to
|
||||
* add it in header part of every retrofit request
|
||||
*/
|
||||
|
||||
public PrefUtils() {
|
||||
}
|
||||
|
||||
@ -18,10 +19,63 @@ public class PrefUtils {
|
||||
public static void storeApiKey(Context context, String apiKey) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putString("API_KEY", apiKey);
|
||||
editor.commit();
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getApiKey(Context context) {
|
||||
return getSharedPreferences(context).getString("API_KEY", null);
|
||||
}
|
||||
|
||||
public static void storeUserId(Context applicationContext, String userId) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(applicationContext).edit();
|
||||
editor.putString("USER_ID", userId);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static String getUserId(Context context) {
|
||||
return getSharedPreferences(context).getString("USER_ID", null);
|
||||
}
|
||||
|
||||
|
||||
public static String getUserStatus(Context context) {
|
||||
return getSharedPreferences(context).getString("USER_STATUS", "Android");
|
||||
}
|
||||
|
||||
public static void storeIsTutor(Context applicationContext, boolean isTutor) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(applicationContext).edit();
|
||||
editor.putBoolean("IS_TUTOR", isTutor);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean getIsTutor(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("IS_TUTOR", false);
|
||||
}
|
||||
|
||||
public static void storeIsLoggedIn(Context applicationContext, boolean isLogged) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(applicationContext).edit();
|
||||
editor.putBoolean("IS_LOGGED_IN", isLogged);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean isLoggedIn(Context context) {
|
||||
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 void storeIsServiceRunning(Context context, Boolean flag) {
|
||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||
editor.putBoolean("IS_SERVIS_RUNNING", flag);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public static boolean getIsServiceRunning(Context context) {
|
||||
return getSharedPreferences(context).getBoolean("IS_SERVIS_RUNNING", false);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
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;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -80,6 +80,8 @@
|
||||
android:text="@string/action_sign_in"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
</LinearLayout>
|
@ -18,6 +18,7 @@
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer">
|
||||
|
||||
|
||||
</android.support.design.widget.NavigationView>
|
||||
|
||||
<android.support.design.widget.CoordinatorLayout
|
||||
@ -29,6 +30,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/logoutButton"
|
||||
android:layout_width="wrap_content"
|
||||
|
@ -11,6 +11,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_renderTextureMode="true"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
mapbox:mapbox_cameraZoom="17"
|
||||
|
@ -17,4 +17,6 @@
|
||||
<dimen name="dot_text_size">40sp</dimen>
|
||||
<dimen name="timestamp">14sp</dimen>
|
||||
<dimen name="note_list_text">13sp</dimen>
|
||||
<dimen name="default_margin">12dp</dimen>
|
||||
<dimen name="text_large">10dp</dimen>
|
||||
</resources>
|
||||
|
@ -33,10 +33,14 @@
|
||||
<string name="permission_rationale">"Contacts permissions are needed for providing email
|
||||
completions."
|
||||
</string>
|
||||
<string name="permission_denied_explanation">Permission was denied, but is needed for core
|
||||
functionality.</string>
|
||||
<string name="title_activity_main" translatable="false">MainActivity</string>
|
||||
<string name="access_token" translatable="false">pk.eyJ1IjoiZG9tYWdhbHNreSIsImEiOiJjamd4am4zazYwNXo1MzBxeDZtYjA4d2s4In0.KzNdhc9V_-SYe14AZ-q3Ew</string>
|
||||
|
||||
<string name="action_black_list">Black List</string>
|
||||
<string name="action_white_list">White List</string>
|
||||
|
||||
<string name="title_activity_settings">Settings</string>
|
||||
|
||||
|
||||
@ -175,4 +179,21 @@
|
||||
<string name="pref_ringtone_silent">Silent</string>
|
||||
|
||||
<string name="pref_title_vibrate">Vibrate</string>
|
||||
|
||||
|
||||
<string name="settings">Settings</string>
|
||||
<string name="ok">OK</string>
|
||||
|
||||
<string name="request_updates">Request updates</string>
|
||||
<string name="remove_updates">Remove updates</string>
|
||||
<string name="unknown_location">Unknown location</string>
|
||||
|
||||
<string name="batched_location_updates">Batched location updates</string>
|
||||
|
||||
<plurals name="num_locations_reported">
|
||||
<item quantity="zero">No location reported</item>
|
||||
<item quantity="one">One location reported</item>
|
||||
<item quantity="other">%d locations reported</item>
|
||||
</plurals>
|
||||
|
||||
</resources>
|
||||
|
@ -7,8 +7,8 @@ buildscript {
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath 'com.android.tools.build:gradle:3.1.4'
|
||||
|
||||
classpath 'com.android.tools.build:gradle:3.2.0'
|
||||
|
||||
|
||||
// NOTE: Do not place your application dependencies here; they belong
|
||||
// in the individual module build.gradle files
|
||||
|
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
#Sun Aug 12 23:17:46 CEST 2018
|
||||
#Sat Sep 29 16:56:56 CEST 2018
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||
|
Loading…
Reference in New Issue
Block a user