code cleanup cont
This commit is contained in:
parent
5dab4eaf4b
commit
b1af9f6798
@ -185,13 +185,15 @@ public abstract class BaseActivity
|
||||
int itemId = item.getItemId();
|
||||
if (itemId == R.id.nav_map) {
|
||||
removeFragment(sharingFragment);
|
||||
|
||||
// startActivity(new Intent(this, MapActivity.class));
|
||||
} else if (itemId == R.id.nav_profile) {
|
||||
// startActivity(new Intent(this, ProfileActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
|
||||
} else if (itemId == R.id.nav_notif) {
|
||||
startActivity(new Intent(this, NotificationsActivity.class));
|
||||
//startActivity(new Intent(this, NotificationsActivity.class));
|
||||
setFragment(sharingFragment);
|
||||
}
|
||||
//finish();
|
||||
}, 300);
|
||||
|
@ -67,10 +67,7 @@ public class MainActivity extends AppCompatActivity implements
|
||||
private BottomNavigationView mMainNav;
|
||||
private FrameLayout mMainFrame;
|
||||
private boolean isTutor;
|
||||
private MapFragment mapFragment;
|
||||
private SharingFragment sharingFragment;
|
||||
private NotificationFragment notificationFragment;
|
||||
private ProfileFragment profileFragment;;
|
||||
|
||||
private static final int REQUEST_PERMISSIONS = 100;
|
||||
boolean boolean_permission;
|
||||
@ -121,7 +118,6 @@ public class MainActivity extends AppCompatActivity implements
|
||||
mapView.getMapAsync(this);
|
||||
|
||||
configureconfigureNavigationDrawer();
|
||||
configureBottomNavigationView();
|
||||
configureLogoutButton();
|
||||
|
||||
}
|
||||
@ -172,43 +168,7 @@ public class MainActivity extends AppCompatActivity implements
|
||||
fragmentTransaction.commit();
|
||||
}
|
||||
|
||||
private void configureBottomNavigationView(){
|
||||
|
||||
mMainFrame = findViewById(R.id.main_frame);
|
||||
mMainNav = findViewById(R.id.main_nav);
|
||||
isTutor = PrefUtils.getIsTutor(getApplicationContext());
|
||||
|
||||
if (!isTutor) {
|
||||
mMainNav.findViewById(R.id.nav_profile).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
mapFragment = new MapFragment();
|
||||
sharingFragment = new SharingFragment();
|
||||
notificationFragment = new NotificationFragment();
|
||||
profileFragment = new ProfileFragment();
|
||||
|
||||
// Default frag here
|
||||
// setFragment(mapFragment);
|
||||
mMainNav.setSelectedItemId(R.id.nav_map);
|
||||
|
||||
/* code below is resposible for changing colours of tabs in main tab menu */
|
||||
mMainNav.setOnNavigationItemSelectedListener(item -> {
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.nav_map:
|
||||
// setFragment(mapFragment);
|
||||
return true;
|
||||
case R.id.nav_notif:
|
||||
setFragment(notificationFragment);
|
||||
return true;
|
||||
case R.id.nav_profile:
|
||||
setFragment(sharingFragment);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void configureLogoutButton(){
|
||||
// Logout button
|
||||
|
@ -1,98 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.mapbox.mapboxsdk.maps.MapView;
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
import com.uam.wmi.findmytutor.network.ApiClient;
|
||||
import com.uam.wmi.findmytutor.service.CoordinateService;
|
||||
|
||||
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class MapFragment extends Fragment {
|
||||
private MapView mapView;
|
||||
|
||||
|
||||
public MapFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_map, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mapView = (MapView) view.findViewById(R.id.mapView);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
CoordinateService service = ApiClient.getClient(getApplicationContext())
|
||||
.create(CoordinateService.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
mapView.onDestroy();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void onDestroy() {
|
||||
// super.onDestroy();
|
||||
// mapView.onDestroy();
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class NotificationFragment extends Fragment {
|
||||
|
||||
|
||||
public NotificationFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_notification, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -32,144 +32,49 @@ import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
public class NotificationsActivity extends BaseActivity {
|
||||
|
||||
private MapView mapView;
|
||||
private CoordinateService coordinateService;
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
private List<Coordinate> coordinatesList = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mapInit(savedInstanceState);
|
||||
|
||||
// coordinateService = ApiClient.getClient(getApplicationContext())
|
||||
// .create(CoordinateService.class);
|
||||
final SharedPreferences sharedPref = getSharedPreferences("fmtPrefs", Context.MODE_PRIVATE);
|
||||
final String authToken = sharedPref.getString("authToken",null);
|
||||
|
||||
coordinateService = RetrofitClientInstance.createService(CoordinateService.class,"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1laWQiOiI2YjhmNzFiMS00NDM2LTQxZGQtYjg3MC1mNzZlNjdkNDM4NDMiLCJzdWIiOiJzdHJpbmciLCJqdGkiOiJiZGRjZTAwMC0xN2U4LTQwNDUtYWZiNS1kY2RkOWNhNDFiNmQiLCJodHRwOi8vc2NoZW1hcy5taWNyb3NvZnQuY29tL3dzLzIwMDgvMDYvaWRlbnRpdHkvY2xhaW1zL3JvbGUiOiJUdXRvciIsImV4cCI6MTU0MTcxNzk2MywiaXNzIjoiaHR0cDovL2ZpbmRteXR1dG9yLmNvbSIsImF1ZCI6Imh0dHA6Ly9maW5kbXl0dXRvci5jb20ifQ.JJVNeMAwwla6DJk6X8qZUgPFKJp-Epx55W9V_fIwpgg");
|
||||
|
||||
fetchTopCoords();
|
||||
}
|
||||
|
||||
private void mapInit(Bundle savedInstanceState) {
|
||||
// Mapbox access token is configured here. This needs to be called either in your application
|
||||
// object or in the same activity which contains the mapview.
|
||||
Mapbox.getInstance(this, getString(R.string.access_token));
|
||||
// This contains the MapView in XML and needs to be called after the access token is configured.
|
||||
// setContentView(R.layout.activity_notifications);
|
||||
|
||||
mapView = (MapView) findViewById(R.id.mapView2);
|
||||
mapView.onCreate(savedInstanceState);
|
||||
mapView.getMapAsync(new OnMapReadyCallback() {
|
||||
@Override
|
||||
public void onMapReady(MapboxMap mapboxMap) {
|
||||
|
||||
final Marker marker = mapboxMap.addMarker(new MarkerViewOptions()
|
||||
.position(new LatLng(64.900932, -18.167040)));
|
||||
|
||||
mapboxMap.setOnMapClickListener(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 void fetchTopCoords() {
|
||||
disposable.add(
|
||||
coordinateService.getTopCoordinates()
|
||||
.subscribeOn(Schedulers.io())
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribeWith(new DisposableSingleObserver<List<Coordinate>>() {
|
||||
@Override
|
||||
public void onSuccess(List<Coordinate> coordsList) {
|
||||
|
||||
Log.d("mapTag", "co?");
|
||||
for (Coordinate element:
|
||||
coordsList) {
|
||||
Log.d("mapTag", element.getUserId());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Throwable e) {
|
||||
Log.e("Error",e.toString());
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
mapView.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
mapView.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
mapView.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
mapView.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLowMemory() {
|
||||
super.onLowMemory();
|
||||
mapView.onLowMemory();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
mapView.onDestroy();
|
||||
disposable.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
mapView.onSaveInstanceState(outState);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getContentViewId() { return R.layout.activity_notifications; }
|
||||
|
@ -1,31 +0,0 @@
|
||||
package com.uam.wmi.findmytutor.activity;
|
||||
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.uam.wmi.findmytutor.R;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
*/
|
||||
public class ProfileFragment extends Fragment {
|
||||
|
||||
|
||||
public ProfileFragment() {
|
||||
// Required empty public constructor
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
return inflater.inflate(R.layout.fragment_profile, container, false);
|
||||
}
|
||||
|
||||
}
|
@ -9,24 +9,4 @@
|
||||
tools:context=".activity.NotificationsActivity">
|
||||
<!--tools:context=".examples.annotations.AnimatedMarkerActivity">-->
|
||||
|
||||
<com.mapbox.mapboxsdk.maps.MapView
|
||||
android:id="@+id/mapView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:visibility="visible"
|
||||
mapbox:mapbox_cameraTargetLat="52.466799"
|
||||
mapbox:mapbox_cameraTargetLng="16.927002"
|
||||
mapbox:mapbox_cameraZoom="17"
|
||||
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
|
||||
</com.mapbox.mapboxsdk.maps.MapView>
|
||||
|
||||
<include
|
||||
android:id="@+id/navigation"
|
||||
layout="@layout/element_bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent" />
|
||||
|
||||
</RelativeLayout>
|
@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".activity.ProfileFragment">
|
||||
|
||||
<!-- TODO: Update blank fragment layout -->
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Profile Frag" />
|
||||
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue
Block a user