Merge background task into develop #14
@ -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 {
|
defaultConfig {
|
||||||
applicationId "com.uam.wmi.findmytutor"
|
applicationId "com.uam.wmi.findmytutor"
|
||||||
minSdkVersion 19
|
minSdkVersion 23
|
||||||
targetSdkVersion 27
|
targetSdkVersion 27
|
||||||
versionCode 1
|
versionCode 1
|
||||||
versionName "1.0"
|
versionName "1.0"
|
||||||
@ -32,7 +32,7 @@ dependencies {
|
|||||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||||
implementation 'com.android.support:appcompat-v7:27.1.1'
|
implementation 'com.android.support:appcompat-v7:27.1.1'
|
||||||
implementation 'com.android.support:design: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.constraint:constraint-layout:1.1.3'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||||
@ -52,5 +52,6 @@ dependencies {
|
|||||||
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
|
implementation "com.squareup.okhttp3:okhttp-urlconnection:3.10.0"
|
||||||
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
|
implementation "com.squareup.okhttp3:logging-interceptor:3.11.0"
|
||||||
implementation 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
|
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"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
package="com.uam.wmi.findmytutor">
|
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.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_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
|
<application
|
||||||
@ -18,7 +23,8 @@
|
|||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme"
|
||||||
|
tools:ignore="GoogleAppIndexingWarning">
|
||||||
|
|
||||||
<activity android:name=".activity.StartupActivity"
|
<activity android:name=".activity.StartupActivity"
|
||||||
android:label="@string/title_activity_startup"
|
android:label="@string/title_activity_startup"
|
||||||
@ -43,9 +49,15 @@
|
|||||||
android:label="@string/title_activity_login"
|
android:label="@string/title_activity_login"
|
||||||
android:noHistory="true">
|
android:noHistory="true">
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
|
||||||
<service
|
<service
|
||||||
android:name=".service.GoogleService"
|
android:name=".service.BackgroundLocalizationService"
|
||||||
android:exported="false" />
|
android:exported="false"
|
||||||
|
android:launchMode="singleTop"
|
||||||
|
android:enabled="true"
|
||||||
|
/>
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
@ -31,6 +31,8 @@ import android.widget.Switch;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.ToggleButton;
|
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.R;
|
||||||
import com.uam.wmi.findmytutor.model.JwtToken;
|
import com.uam.wmi.findmytutor.model.JwtToken;
|
||||||
import com.uam.wmi.findmytutor.model.LdapUser;
|
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
|
// Show a progress spinner, and kick off a background task to
|
||||||
// perform the user login attempt.
|
// perform the user login attempt.
|
||||||
showProgress(true);
|
showProgress(true);
|
||||||
mAuthTask = new UserLoginTask(email, password,loginOption);
|
mAuthTask = new UserLoginTask(email, password, loginOption);
|
||||||
mAuthTask.execute((Void) null);
|
mAuthTask.execute((Void) null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -307,7 +309,7 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
|||||||
private interface ProfileQuery {
|
private interface ProfileQuery {
|
||||||
String[] PROJECTION = {
|
String[] PROJECTION = {
|
||||||
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||||
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||||
};
|
};
|
||||||
|
|
||||||
int ADDRESS = 0;
|
int ADDRESS = 0;
|
||||||
@ -331,16 +333,18 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
|||||||
UserLoginTask(String email, String password, Boolean loginOption) {
|
UserLoginTask(String email, String password, Boolean loginOption) {
|
||||||
mEmail = email;
|
mEmail = email;
|
||||||
mPassword = password;
|
mPassword = password;
|
||||||
isTutor=loginOption;
|
isTutor = loginOption;
|
||||||
this.ldapService = ApiClient.getClient(getApplicationContext())
|
this.ldapService = ApiClient.getClient(getApplicationContext())
|
||||||
.create(LdapService.class);
|
.create(LdapService.class);
|
||||||
this.isAuthorizate = false;
|
this.isAuthorizate = false;
|
||||||
|
|
||||||
|
PrefUtils.storeIsTutor(getApplicationContext(), this.isTutor);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Boolean doInBackground(Void... params) {
|
protected Boolean doInBackground(Void... params) {
|
||||||
LdapUser user = new LdapUser("string",mPassword,"string",(isTutor)?"tutor":"student","string","string",mEmail);
|
LdapUser user = new LdapUser(mEmail,mPassword,"admin",(isTutor)?"Tutor":"Student","string","string",mEmail);
|
||||||
Log.d("LoginRole","Login role is : " + user.getTitle());
|
|
||||||
disposable.add(
|
disposable.add(
|
||||||
ldapService
|
ldapService
|
||||||
.fakeValidate(user)
|
.fakeValidate(user)
|
||||||
@ -349,7 +353,15 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
|||||||
.subscribeWith(new DisposableSingleObserver<JwtToken>() {
|
.subscribeWith(new DisposableSingleObserver<JwtToken>() {
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(JwtToken jwtToken) {
|
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);
|
onPostExecute(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -368,9 +380,9 @@ public class LoginActivity extends AppCompatActivity implements LoaderCallbacks<
|
|||||||
showProgress(false);
|
showProgress(false);
|
||||||
|
|
||||||
if (success) {
|
if (success) {
|
||||||
// DONE: returns the role of signed user and return code
|
|
||||||
Intent data = new Intent();
|
Intent data = new Intent();
|
||||||
data.putExtra("is_tutor", isTutor);
|
String txt = "Main Activity";
|
||||||
|
data.setData(Uri.parse(txt));
|
||||||
setResult(RESULT_OK, data);
|
setResult(RESULT_OK, data);
|
||||||
finish();
|
finish();
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,16 +1,13 @@
|
|||||||
package com.uam.wmi.findmytutor.activity;
|
package com.uam.wmi.findmytutor.activity;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
|
||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.location.Geocoder;
|
import android.location.Geocoder;
|
||||||
|
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceManager;
|
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.design.widget.BottomNavigationView;
|
import android.support.design.widget.BottomNavigationView;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
@ -18,45 +15,33 @@ import android.support.design.widget.FloatingActionButton;
|
|||||||
import android.support.v4.app.ActivityCompat;
|
import android.support.v4.app.ActivityCompat;
|
||||||
import android.support.v4.content.ContextCompat;
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
|
|
||||||
import android.support.v7.widget.SearchView;
|
import android.support.v7.widget.SearchView;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
|
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
|
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.mapbox.mapboxsdk.Mapbox;
|
import com.mapbox.mapboxsdk.Mapbox;
|
||||||
|
|
||||||
import com.mapbox.mapboxsdk.maps.MapView;
|
|
||||||
import com.uam.wmi.findmytutor.ListViewAdapter;
|
import com.uam.wmi.findmytutor.ListViewAdapter;
|
||||||
import com.uam.wmi.findmytutor.R;
|
import com.uam.wmi.findmytutor.R;
|
||||||
import com.uam.wmi.findmytutor.service.GoogleService;
|
|
||||||
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.content.pm.PackageManager;
|
import com.uam.wmi.findmytutor.service.BackgroundLocalizationService;
|
||||||
import android.location.Address;
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@ -84,7 +69,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private ArrayList<String> stringArrayList;
|
private ArrayList<String> stringArrayList;
|
||||||
private ListViewAdapter adapter;
|
private ListViewAdapter adapter;
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@ -140,13 +124,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
|
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
|
||||||
mMainNav = (BottomNavigationView) findViewById(R.id.main_nav);
|
mMainNav = (BottomNavigationView) findViewById(R.id.main_nav);
|
||||||
|
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||||
Bundle extras = getIntent().getExtras();
|
|
||||||
isTutor = (boolean) extras.get("is_tutor");
|
|
||||||
|
|
||||||
geocoder = new Geocoder(this, Locale.getDefault());
|
|
||||||
mPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
|
||||||
medit = mPref.edit();
|
|
||||||
|
|
||||||
if (!isTutor) {
|
if (!isTutor) {
|
||||||
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||||
@ -185,16 +163,17 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
private void configureLogoutButton(){
|
private void configureLogoutButton(){
|
||||||
// Logout button
|
// Logout button
|
||||||
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
final FloatingActionButton button = findViewById(R.id.logoutButton);
|
||||||
|
|
||||||
button.setOnClickListener(new View.OnClickListener() {
|
button.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View view) {
|
public void onClick(View view) {
|
||||||
SharedPreferences preferences = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
PrefUtils.cleanUserLocalStorage(getApplicationContext());
|
||||||
SharedPreferences.Editor editor = preferences.edit();
|
|
||||||
editor.clear().commit();
|
|
||||||
|
|
||||||
Intent i = getBaseContext().getPackageManager()
|
Intent i = getBaseContext().getPackageManager()
|
||||||
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
.getLaunchIntentForPackage(getBaseContext().getPackageName());
|
||||||
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
if (i != null) {
|
||||||
|
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
}
|
||||||
startActivity(i);
|
startActivity(i);
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
@ -251,8 +230,15 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onPostCreate(Bundle savedInstanceState) {
|
protected void onPostCreate(Bundle savedInstanceState) {
|
||||||
super.onPostCreate(savedInstanceState);
|
super.onPostCreate(savedInstanceState);
|
||||||
|
|
||||||
|
|
||||||
// Sync the toggle state after onRestoreInstanceState has occurred.
|
// Sync the toggle state after onRestoreInstanceState has occurred.
|
||||||
actionBarDrawerToggle.syncState();
|
actionBarDrawerToggle.syncState();
|
||||||
|
|
||||||
|
if (isTutor) {
|
||||||
|
fn_permission();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -261,6 +247,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
actionBarDrawerToggle.onConfigurationChanged(newConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
if (actionBarDrawerToggle.onOptionsItemSelected(item)) {
|
||||||
@ -270,5 +257,63 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
|
||||||
|
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,19 +1,20 @@
|
|||||||
package com.uam.wmi.findmytutor.activity;
|
package com.uam.wmi.findmytutor.activity;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
||||||
|
|
||||||
|
|
||||||
public class StartupActivity extends AppCompatActivity {
|
public class StartupActivity extends AppCompatActivity {
|
||||||
private static final int AUTHENTICATION_REQUEST_CODE = 666;
|
private static final int AUTHENTICATION_REQUEST_CODE = 666;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (isLoggedIn()){
|
if (isLoggedIn()) {
|
||||||
Intent startupIntent = new Intent(this, MainActivity.class);
|
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.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
startActivity(startupIntent);
|
startActivity(startupIntent);
|
||||||
@ -25,20 +26,17 @@ public class StartupActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
//to nie ma miec layoutu wiec elo
|
|
||||||
// setContentView(R.layout.activity_startup);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isLoggedIn() {
|
private boolean isLoggedIn() {
|
||||||
return this.getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE).getBoolean("loggedIn",false);
|
return PrefUtils.isLoggedIn(getApplicationContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
if (requestCode == AUTHENTICATION_REQUEST_CODE && resultCode == Activity.RESULT_OK) {
|
||||||
Intent startupIntent = new Intent(this, MainActivity.class);
|
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.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);
|
startActivity(startupIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.uam.wmi.findmytutor.model;
|
package com.uam.wmi.findmytutor.model;
|
||||||
|
|
||||||
|
import android.util.Range;
|
||||||
|
|
||||||
import com.google.gson.annotations.SerializedName;
|
import com.google.gson.annotations.SerializedName;
|
||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -11,18 +13,21 @@ import io.swagger.annotations.ApiModelProperty;
|
|||||||
* Coordinate
|
* 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")
|
@SerializedName("coordinateId")
|
||||||
private UUID coordinateId = null;
|
private UUID coordinateId = null;
|
||||||
|
|
||||||
@SerializedName("latitude")
|
@SerializedName("latitude")
|
||||||
private Float latitude = null;
|
private Double latitude;
|
||||||
|
|
||||||
@SerializedName("longitude")
|
@SerializedName("longitude")
|
||||||
private Float longitude = null;
|
private Double longitude = null;
|
||||||
|
|
||||||
@SerializedName("altitude")
|
@SerializedName("altitude")
|
||||||
private Float altitude = null;
|
private Double altitude = null;
|
||||||
|
|
||||||
@SerializedName("userId")
|
@SerializedName("userId")
|
||||||
private String userId = null;
|
private String userId = null;
|
||||||
@ -37,7 +42,21 @@ public class Coordinate extends BaseResponse{
|
|||||||
private Long timeStamp = null;
|
private Long timeStamp = null;
|
||||||
|
|
||||||
@SerializedName("label")
|
@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) {
|
public Coordinate coordinateId(UUID coordinateId) {
|
||||||
this.coordinateId = coordinateId;
|
this.coordinateId = coordinateId;
|
||||||
@ -57,7 +76,7 @@ public class Coordinate extends BaseResponse{
|
|||||||
this.coordinateId = coordinateId;
|
this.coordinateId = coordinateId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinate latitude(Float latitude) {
|
public Coordinate latitude(Double latitude) {
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -67,15 +86,15 @@ public class Coordinate extends BaseResponse{
|
|||||||
* @return latitude
|
* @return latitude
|
||||||
**/
|
**/
|
||||||
@ApiModelProperty(required = true, value = "")
|
@ApiModelProperty(required = true, value = "")
|
||||||
public Float getLatitude() {
|
public Double getLatitude() {
|
||||||
return latitude;
|
return latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLatitude(Float latitude) {
|
public void setLatitude(Double latitude) {
|
||||||
this.latitude = latitude;
|
this.latitude = latitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinate longitude(Float longitude) {
|
public Coordinate longitude(Double longitude) {
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -85,15 +104,15 @@ public class Coordinate extends BaseResponse{
|
|||||||
* @return longitude
|
* @return longitude
|
||||||
**/
|
**/
|
||||||
@ApiModelProperty(required = true, value = "")
|
@ApiModelProperty(required = true, value = "")
|
||||||
public Float getLongitude() {
|
public Double getLongitude() {
|
||||||
return longitude;
|
return longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLongitude(Float longitude) {
|
public void setLongitude(Double longitude) {
|
||||||
this.longitude = longitude;
|
this.longitude = longitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Coordinate altitude(Float altitude) {
|
public Coordinate altitude(Double altitude) {
|
||||||
this.altitude = altitude;
|
this.altitude = altitude;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -103,11 +122,11 @@ public class Coordinate extends BaseResponse{
|
|||||||
* @return altitude
|
* @return altitude
|
||||||
**/
|
**/
|
||||||
@ApiModelProperty(required = true, value = "")
|
@ApiModelProperty(required = true, value = "")
|
||||||
public Float getAltitude() {
|
public Double getAltitude() {
|
||||||
return altitude;
|
return altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAltitude(Float altitude) {
|
public void setAltitude(Double altitude) {
|
||||||
this.altitude = altitude;
|
this.altitude = altitude;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,7 +62,7 @@ public class ApiClient {
|
|||||||
// Adding Authorization token (API Key)
|
// Adding Authorization token (API Key)
|
||||||
// Requests will be denied without API key
|
// Requests will be denied without API key
|
||||||
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
if (!TextUtils.isEmpty(PrefUtils.getApiKey(context))) {
|
||||||
requestBuilder.addHeader("Authorization", PrefUtils.getApiKey(context));
|
requestBuilder.addHeader("Authorization", "Bearer " + PrefUtils.getApiKey(context));
|
||||||
}
|
}
|
||||||
|
|
||||||
Request request = requestBuilder.build();
|
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,17 +1,12 @@
|
|||||||
package com.uam.wmi.findmytutor.service;
|
package com.uam.wmi.findmytutor.service;
|
||||||
|
|
||||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
import com.uam.wmi.findmytutor.model.Coordinate;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import io.reactivex.Observable;
|
|
||||||
import io.reactivex.Single;
|
import io.reactivex.Single;
|
||||||
import okhttp3.ResponseBody;
|
|
||||||
import retrofit2.Call;
|
|
||||||
import retrofit2.http.Body;
|
import retrofit2.http.Body;
|
||||||
import retrofit2.http.DELETE;
|
import retrofit2.http.DELETE;
|
||||||
import retrofit2.http.Field;
|
|
||||||
import retrofit2.http.FormUrlEncoded;
|
|
||||||
import retrofit2.http.GET;
|
import retrofit2.http.GET;
|
||||||
import retrofit2.http.POST;
|
import retrofit2.http.POST;
|
||||||
import retrofit2.http.PUT;
|
import retrofit2.http.PUT;
|
||||||
@ -20,40 +15,31 @@ import retrofit2.http.Path;
|
|||||||
public interface CoordinateService {
|
public interface CoordinateService {
|
||||||
|
|
||||||
@GET("api/coordinates")
|
@GET("api/coordinates")
|
||||||
Call<List<Coordinate>> getAllCoordinates();
|
Single<List<Coordinate>> getAllCoordinates();
|
||||||
|
|
||||||
@GET("api/coordinates/{id}")
|
@GET("api/coordinates/{id}")
|
||||||
Call<Coordinate> getCoordinatesById(@Path("id") String id);
|
Single<Coordinate> getCoordinatesById(@Path("id") String id);
|
||||||
|
|
||||||
@GET("api/coordinates/user/{userId}")
|
@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}")
|
@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")
|
@GET("api/coordinates/top")
|
||||||
Call<List<Coordinate>> getTopCoordinates();
|
Single<List<Coordinate>> getTopCoordinates();
|
||||||
|
|
||||||
@GET("api/coordinates/top/online")
|
@GET("api/coordinates/top/online")
|
||||||
Call<List<Coordinate>> getOnlineCoordinates();
|
Single<List<Coordinate>> getOnlineCoordinates();
|
||||||
|
|
||||||
/* @POST("api/coordinates")
|
@POST("api/coordinates")
|
||||||
Call<Coordinate> postCoordinate(@Body Coordinate coordinate);*/
|
Single <Coordinate> postCoordinate(@Body Coordinate coordinate);
|
||||||
|
|
||||||
@POST("postCoordinate")
|
|
||||||
@FormUrlEncoded
|
|
||||||
Single<Coordinate> postCoordinate(
|
|
||||||
@Field("longitude") Float longitude,
|
|
||||||
@Field("latitude") Float latitude,
|
|
||||||
@Field("label") String label,
|
|
||||||
@Field("userId") String userId
|
|
||||||
);
|
|
||||||
|
|
||||||
@PUT("api/coordinates/{id}")
|
@PUT("api/coordinates/{id}")
|
||||||
Call<Coordinate> putCoordinatesById(@Path("id") String id);
|
Single<Coordinate> putCoordinatesById(@Path("id") String id);
|
||||||
|
|
||||||
@DELETE("api/coordinates/{id}")
|
@DELETE("api/coordinates/{id}")
|
||||||
Call<Coordinate> deleteCoordinatesById(@Path("id") String id);
|
Single<Coordinate> deleteCoordinatesById(@Path("id") String id);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,170 +0,0 @@
|
|||||||
package com.uam.wmi.findmytutor.service;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.annotation.SuppressLint;
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.location.Location;
|
|
||||||
import android.location.LocationListener;
|
|
||||||
import android.location.LocationManager;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
import android.support.v4.app.ActivityCompat;
|
|
||||||
import android.util.Log;
|
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.uam.wmi.findmytutor.model.Coordinate;
|
|
||||||
import com.uam.wmi.findmytutor.model.User;
|
|
||||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
|
||||||
import com.uam.wmi.findmytutor.utils.PrefUtils;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class GoogleService extends Service implements LocationListener {
|
|
||||||
|
|
||||||
boolean isGPSEnable = false;
|
|
||||||
boolean isNetworkEnable = false;
|
|
||||||
double latitude, longitude;
|
|
||||||
LocationManager locationManager;
|
|
||||||
Location location;
|
|
||||||
private Handler mHandler = new Handler();
|
|
||||||
private Timer mTimer = null;
|
|
||||||
long notify_interval = 1000;
|
|
||||||
public static String str_receiver = "servicetutorial.service.receiver";
|
|
||||||
Intent intent;
|
|
||||||
|
|
||||||
private CoordinateService apiService;
|
|
||||||
private CompositeDisposable disposable = new CompositeDisposable();
|
|
||||||
|
|
||||||
|
|
||||||
public GoogleService() {
|
|
||||||
apiService = ApiClient.getClient(getApplicationContext()).create(CoordinateService.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
|
|
||||||
mTimer = new Timer();
|
|
||||||
mTimer.schedule(new TimerTaskToGetLocation(), 5, notify_interval);
|
|
||||||
intent = new Intent(str_receiver);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("LongLogTag")
|
|
||||||
@Override
|
|
||||||
public void onLocationChanged(Location location) {
|
|
||||||
Log.e("Background location has changed", String.valueOf(location));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStatusChanged(String provider, int status, Bundle extras) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderEnabled(String provider) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onProviderDisabled(String provider) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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 (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, this);
|
|
||||||
if (locationManager!=null){
|
|
||||||
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
|
|
||||||
if (location!=null){
|
|
||||||
|
|
||||||
Log.e("latitude",location.getLatitude()+"");
|
|
||||||
Log.e("longitude",location.getLongitude()+"");
|
|
||||||
|
|
||||||
latitude = location.getLatitude();
|
|
||||||
longitude = location.getLongitude();
|
|
||||||
fn_update(location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
if (isGPSEnable){
|
|
||||||
location = null;
|
|
||||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,0,this);
|
|
||||||
if (locationManager!=null){
|
|
||||||
location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
|
|
||||||
if (location!=null){
|
|
||||||
Log.e("latitude",location.getLatitude()+"");
|
|
||||||
Log.e("longitude",location.getLongitude()+"");
|
|
||||||
latitude = location.getLatitude();
|
|
||||||
longitude = location.getLongitude();
|
|
||||||
fn_update(location);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TimerTaskToGetLocation extends TimerTask{
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
mHandler.post(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
fn_getlocation();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fn_update(Location location){
|
|
||||||
|
|
||||||
intent.putExtra("latutide",location.getLatitude()+"");
|
|
||||||
intent.putExtra("longitude",location.getLongitude()+"");
|
|
||||||
sendBroadcast(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -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.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.auth0.android.jwt.Claim;
|
||||||
|
import com.auth0.android.jwt.JWT;
|
||||||
|
|
||||||
public class PrefUtils {
|
public class PrefUtils {
|
||||||
/**
|
|
||||||
* Storing API Key in shared preferences to
|
|
||||||
* add it in header part of every retrofit request
|
|
||||||
*/
|
|
||||||
public PrefUtils() {
|
public PrefUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,10 +19,63 @@ public class PrefUtils {
|
|||||||
public static void storeApiKey(Context context, String apiKey) {
|
public static void storeApiKey(Context context, String apiKey) {
|
||||||
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
SharedPreferences.Editor editor = getSharedPreferences(context).edit();
|
||||||
editor.putString("API_KEY", apiKey);
|
editor.putString("API_KEY", apiKey);
|
||||||
editor.commit();
|
editor.apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getApiKey(Context context) {
|
public static String getApiKey(Context context) {
|
||||||
return getSharedPreferences(context).getString("API_KEY", null);
|
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:text="@string/action_sign_in"
|
||||||
android:textStyle="bold" />
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
@ -18,6 +18,7 @@
|
|||||||
app:headerLayout="@layout/nav_header_main"
|
app:headerLayout="@layout/nav_header_main"
|
||||||
app:menu="@menu/activity_main_drawer">
|
app:menu="@menu/activity_main_drawer">
|
||||||
|
|
||||||
|
|
||||||
</android.support.design.widget.NavigationView>
|
</android.support.design.widget.NavigationView>
|
||||||
|
|
||||||
<android.support.design.widget.CoordinatorLayout
|
<android.support.design.widget.CoordinatorLayout
|
||||||
@ -29,6 +30,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
|
|
||||||
|
|
||||||
<android.support.design.widget.FloatingActionButton
|
<android.support.design.widget.FloatingActionButton
|
||||||
android:id="@+id/logoutButton"
|
android:id="@+id/logoutButton"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:visibility="visible"
|
android:visibility="visible"
|
||||||
|
mapbox:mapbox_renderTextureMode="true"
|
||||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||||
mapbox:mapbox_cameraZoom="17"
|
mapbox:mapbox_cameraZoom="17"
|
||||||
|
@ -17,4 +17,6 @@
|
|||||||
<dimen name="dot_text_size">40sp</dimen>
|
<dimen name="dot_text_size">40sp</dimen>
|
||||||
<dimen name="timestamp">14sp</dimen>
|
<dimen name="timestamp">14sp</dimen>
|
||||||
<dimen name="note_list_text">13sp</dimen>
|
<dimen name="note_list_text">13sp</dimen>
|
||||||
|
<dimen name="default_margin">12dp</dimen>
|
||||||
|
<dimen name="text_large">10dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -33,8 +33,27 @@
|
|||||||
<string name="permission_rationale">"Contacts permissions are needed for providing email
|
<string name="permission_rationale">"Contacts permissions are needed for providing email
|
||||||
completions."
|
completions."
|
||||||
</string>
|
</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="title_activity_main" translatable="false">MainActivity</string>
|
||||||
<string name="access_token" translatable="false">pk.eyJ1IjoiZG9tYWdhbHNreSIsImEiOiJjamd4am4zazYwNXo1MzBxeDZtYjA4d2s4In0.KzNdhc9V_-SYe14AZ-q3Ew</string>
|
<string name="access_token" translatable="false">pk.eyJ1IjoiZG9tYWdhbHNreSIsImEiOiJjamd4am4zazYwNXo1MzBxeDZtYjA4d2s4In0.KzNdhc9V_-SYe14AZ-q3Ew</string>
|
||||||
|
|
||||||
<string name="action_black_list">Black List</string>
|
<string name="action_black_list">Black List</string>
|
||||||
<string name="action_white_list">White List</string>
|
<string name="action_white_list">White List</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>
|
||||||
|
<string name="default_channel">Default channel</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -7,8 +7,8 @@ buildscript {
|
|||||||
jcenter()
|
jcenter()
|
||||||
}
|
}
|
||||||
dependencies {
|
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
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// 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
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
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