finall clean up - ready to merge develop

This commit is contained in:
Adam Domagalski 2018-10-28 21:56:40 +01:00
parent 2c81359665
commit d2405d36f6
5 changed files with 259 additions and 14 deletions

View File

@ -55,9 +55,7 @@
android:enabled="true" android:enabled="true"
/> />
<activity android:name=".activity.ProfileActivity" />
<!--<activity android:name=".activity.MapActivity" />--> <!--<activity android:name=".activity.MapActivity" />-->
<activity android:name=".activity.NotificationsActivity" />
</application> </application>
</manifest> </manifest>

View File

@ -3,9 +3,13 @@ package com.uam.wmi.findmytutor.activity;
import android.app.Fragment; import android.app.Fragment;
import android.app.FragmentTransaction; import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.os.Build;
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.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
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;
@ -14,6 +18,7 @@ import android.os.Bundle;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
@ -24,6 +29,8 @@ import android.widget.Toast;
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.BackgroundLocalizationService;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.util.ArrayList; import java.util.ArrayList;
@ -43,6 +50,12 @@ public abstract class BaseActivity
private ListViewAdapter adapter; private ListViewAdapter adapter;
private SharingFragment sharingFragment; private SharingFragment sharingFragment;
private static final int REQUEST_PERMISSIONS = 100;
boolean boolean_permission;
private boolean isTutor;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -53,6 +66,10 @@ public abstract class BaseActivity
navigationView.setOnNavigationItemSelectedListener(this); navigationView.setOnNavigationItemSelectedListener(this);
sharingFragment = new SharingFragment(); sharingFragment = new SharingFragment();
isTutor = PrefUtils.getIsTutor(getApplicationContext());
if (!isTutor) {
navigationView.findViewById(R.id.nav_profile).setVisibility(View.GONE);
}
} }
@ -111,6 +128,41 @@ public abstract class BaseActivity
setUpNav(); setUpNav();
actionBarDrawerToggle.syncState(); actionBarDrawerToggle.syncState();
Log.e("erororr", "guewa!" + isTutor);
// if (isTutor && getContentViewId() == R.layout.activity_map) {
if (isTutor) {
Log.e("erororr", "taaaaaak!");
fn_permission();
}
}
private void fn_permission() {
if ((ContextCompat.checkSelfPermission(getApplicationContext(), android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)) {
if ((ActivityCompat.shouldShowRequestPermissionRationale(BaseActivity.this, android.Manifest.permission.ACCESS_FINE_LOCATION))) {
} else {
ActivityCompat.requestPermissions(BaseActivity.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 @Override
@ -154,6 +206,21 @@ public abstract class BaseActivity
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
@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 @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
@ -181,6 +248,8 @@ public abstract class BaseActivity
@Override @Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) { public boolean onNavigationItemSelected(@NonNull MenuItem item) {
navigationView.postDelayed(() -> { navigationView.postDelayed(() -> {
int itemId = item.getItemId(); int itemId = item.getItemId();
if (itemId == R.id.nav_map) { if (itemId == R.id.nav_map) {

View File

@ -1,32 +1,199 @@
package com.uam.wmi.findmytutor.activity; package com.uam.wmi.findmytutor.activity;
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.support.design.widget.FloatingActionButton;
import android.util.Log;
import com.mapbox.mapboxsdk.Mapbox; import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.annotations.Marker;
import com.mapbox.mapboxsdk.annotations.MarkerOptions;
import com.mapbox.mapboxsdk.annotations.MarkerViewOptions;
import com.mapbox.mapboxsdk.geometry.LatLng;
import com.mapbox.mapboxsdk.maps.MapView; import com.mapbox.mapboxsdk.maps.MapView;
import com.mapbox.mapboxsdk.maps.MapboxMap; import com.mapbox.mapboxsdk.maps.MapboxMap;
import com.mapbox.mapboxsdk.maps.OnMapReadyCallback; import com.mapbox.mapboxsdk.maps.OnMapReadyCallback;
import com.uam.wmi.findmytutor.R; import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.Coordinate;
import com.uam.wmi.findmytutor.network.RetrofitClientInstance;
import com.uam.wmi.findmytutor.service.CoordinateService;
import com.uam.wmi.findmytutor.utils.PrefUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableSingleObserver;
import io.reactivex.schedulers.Schedulers;
public class MapActivity extends BaseActivity
implements OnMapReadyCallback {
public class MapActivity extends BaseActivity {
private MapView mapView;
String tag = "LifeCycleEvents"; String tag = "LifeCycleEvents";
private MapView mapView;
private MapboxMap mapboxMap;
private int mInterval = 10000;
private Handler mHandler;
private Map<String,Coordinate> coordsMap = new HashMap<>();
private CoordinateService coordinateService;
private CompositeDisposable disposable = new CompositeDisposable();
private Runnable mStatusChecker;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token)); configureLogoutButton();
mapView = findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() { final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
final String authToken = sharedPref.getString("authToken",null);
mStatusChecker = new Runnable() {
@Override @Override
public void onMapReady(MapboxMap mapboxMap) { public void run() {
try{
// Customize map with markers, polylines, etc. fetchTopCoords();
} finally {
mHandler.postDelayed(mStatusChecker, mInterval);
}
} }
};
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiJhM2MxMDU1YS1kZDM0LTQ5ZWItYTFkNS0xY2E5YTE2YzY0ODgiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiI4NTA0NDA5NS00NjBkLTQzZDgtYjMxMC0xYmNiNWMxNGExZjQiLCJleHAiOjE1NDMzNTAzMzQsImlzcyI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20iLCJhdWQiOiJodHRwOi8vZmluZG15dHV0b3IuY29tIn0.xGyu6iBeq9xF0ufBd01jNzILLq1NeYa-5MeVOiPahD8");
mHandler = new Handler();
Bundle extras = getIntent().getExtras();
Mapbox.getInstance(this, getString(R.string.access_token));
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(this);
}
@Override
public void onMapReady(MapboxMap map) {
mapboxMap = map;
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.position(new LatLng(52.466782,16.927549)));
mStatusChecker.run();
mapboxMap.addOnMapClickListener(new MapboxMap.OnMapClickListener() {
@Override
public void onMapClick(@NonNull LatLng point) {
// When the user clicks on the map, we want to animate the marker to that
// location.
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), point);
markerAnimator.setDuration(2000);
markerAnimator.start();
}
});
}
private static class LatLngEvaluator implements TypeEvaluator<LatLng> {
// Method is used to interpolate the marker animation.
private LatLng latLng = new LatLng();
@Override
public LatLng evaluate(float fraction, LatLng startValue, LatLng endValue) {
latLng.setLatitude(startValue.getLatitude()
+ ((endValue.getLatitude() - startValue.getLatitude()) * fraction));
latLng.setLongitude(startValue.getLongitude()
+ ((endValue.getLongitude() - startValue.getLongitude()) * fraction));
return latLng;
}
}
private void fetchTopCoords() {
disposable.add(
// coordinateService.getTopCoordinates()
coordinateService.getOnlineCoordinates()
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
@Override
public void onSuccess(List<Coordinate> coordsList) {
for (Coordinate element : coordsList) {
String id = element.getUserId();
Coordinate cord = coordsMap.get(id);
Log.d("mapper", "a " + mapboxMap.getMarkerViewManager());
Log.d("mapper", "b " + coordsMap.size());
if (cord != null) {
if (!cord.getLongitude().equals(element.getLongitude())
) {
Log.d("mapper", " cos sie zienilo ");
Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
.title(cord.getUserId())
.position(new LatLng(cord.getLatitude(),cord.getLongitude())));
ValueAnimator markerAnimator = ObjectAnimator.ofObject(marker, "position",
new LatLngEvaluator(), marker.getPosition(), new LatLng(element.getLatitude(),element.getLongitude()));
markerAnimator.setDuration(2000);
markerAnimator.start();
coordsMap.replace(id,element);
} else if (!cord.getTimeStamp().equals(element.getTimeStamp())){
Log.d("mapper", "update");
Log.d("mapper", " "+cord.getTimeStamp());
Log.d("mapper", " "+element.getTimeStamp());
coordsMap.replace(id,element);
}
} else {
coordsMap.put(id,element);
mapboxMap.addMarker(new MarkerOptions().position(new LatLng(element.getLatitude(), element.getLongitude())));
}
}
}
@Override
public void onError(Throwable e) {
Log.e("Error",e.toString());
}
})
);
}
private void configureLogoutButton(){
// Logout button
final FloatingActionButton button = findViewById(R.id.logoutButton);
button.setOnClickListener(view -> {
PrefUtils.cleanUserLocalStorage(getApplicationContext());
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage(getBaseContext().getPackageName());
if (i != null) {
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
}
startActivity(i);
finish();
}); });
} }
@ -67,6 +234,8 @@ public class MapActivity extends BaseActivity {
protected void onDestroy() { protected void onDestroy() {
super.onDestroy(); super.onDestroy();
mapView.onDestroy(); mapView.onDestroy();
mHandler.removeCallbacks(mStatusChecker);
disposable.dispose();
} }
@Override @Override

View File

@ -31,7 +31,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
@Override @Override
public void onCreate(final Bundle savedInstanceState) { public void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_main); addPreferencesFromResource(R.layout.pref_main);
//TODO add on change listeners for preferences //TODO add on change listeners for preferences

View File

@ -18,5 +18,14 @@
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8"> mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
</com.mapbox.mapboxsdk.maps.MapView> </com.mapbox.mapboxsdk.maps.MapView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/logoutButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="@dimen/fab_margin"
android:layout_marginTop="77dp"
app:backgroundTint="@android:color/holo_red_dark"
app:srcCompat="@android:drawable/ic_lock_power_off" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>