Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions AndroidClient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ dependencies {

implementation libs.core

implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'


/*TESTS*/

Expand Down
8 changes: 3 additions & 5 deletions AndroidClient/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,7 @@
</activity>
<activity
android:name=".context.profile.component.activity.ProfileActivity"
android:label="@string/profile_activity_label"
android:parentActivityName=".context.auth.activity.LoginActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".context.auth.activity.LoginActivity" />
android:label="@string/profile_activity_label">
</activity>
<activity
android:name=".context.auth.activity.RegistrationActivity"
Expand Down Expand Up @@ -98,6 +94,8 @@
<activity android:name=".context.image.activity.UploadUserImageActivity" />
<activity android:name=".context.image.activity.UploadEventImageActivity" />
<activity android:name=".context.profile.component.activity.NewEventOnMapActivity" />
<activity android:name=".context.event.activity.PublishEventActivity" />
<activity android:name=".context.event.activity.ScheduleEventActivity" />

<meta-data
android:name="com.google.android.gms.version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.accounts.AuthenticatorException;
import android.accounts.OperationCanceledException;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand Down Expand Up @@ -50,6 +51,11 @@ public static String getUserUuid(AccountManager am) {
return am.getUserData(getSingleAccount(am), USER_UUID_KEY);
}

public static String getUserUuid(Context ctx) {
AccountManager am = AccountManager.get(ctx);
return am.getUserData(getSingleAccount(am), USER_UUID_KEY);
}

public static void setToken(AccountManager am, String token) {
am.setAuthToken(getSingleAccount(am), AccountAuthenticator.AUTH_TYPE, token);
}
Expand All @@ -68,7 +74,8 @@ public static Account getSingleAccount(AccountManager am) {

public static void checkToken(
Consumer<String> onToken, Runnable onCancelledAuth,
AccountManager am, Activity activity, TokenService tokenService) {
Activity activity, TokenService tokenService) {
AccountManager am = AccountManager.get(activity);
Account account = getSingleAccount(am);
String token = am.peekAuthToken(account, AUTH_TYPE);
if (token != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.tom.meeter.context.event.activity.EventLocationMapActivity;
import com.tom.meeter.context.event.activity.EventOnMapActivity;
import com.tom.meeter.context.event.activity.ProfileEventActivity;
import com.tom.meeter.context.event.activity.PublishEventActivity;
import com.tom.meeter.context.event.activity.ScheduleEventActivity;
import com.tom.meeter.context.event.activity.UserEventActivity;

import dagger.BindsInstance;
Expand All @@ -29,13 +31,18 @@ interface Builder {
EventComponent build();
}

void inject(EventDispatcherActivity eventDispatcherActivity);
void inject(EventDispatcherActivity activity);

void inject(ProfileEventActivity profileEventActivity);
void inject(ProfileEventActivity activity);

void inject(UserEventActivity userEventActivity);
void inject(UserEventActivity activity);

void inject(EventOnMapActivity eventOnMapActivity);
void inject(EventOnMapActivity activity);

void inject(EventLocationMapActivity activity);

void inject(PublishEventActivity activity);

void inject(ScheduleEventActivity activity);

void inject(EventLocationMapActivity eventLocationMapActivity);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static com.tom.meeter.infrastructure.common.InfrastructureHelper.logMethod;

import android.accounts.AccountManager;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
Expand All @@ -30,41 +31,30 @@ public class EventDispatcherActivity extends AppCompatActivity {
public static final String EVENT_ID_KEY = "event_id";

private static final String TAG = EventDispatcherActivity.class.getCanonicalName();

@Inject
TokenService tokenService;
@Inject
EventService eventService;
private AccountManager accountManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

logMethod(TAG, this);

Bundle extras = getIntent().getExtras();
if (extras == null) {
Log.d(TAG, "Unable to create event activity without extras.");
finish();
return;
}
String eventId = extras.getString(EVENT_ID_KEY);
if (eventId == null) {
Log.d(TAG, "Unable to create event activity without 'event_id' provided.");
finish();
if (EventDispatcherActivity.isIncorrect(this)) {
return;
}

((App) getApplication()).getEventComponent().inject(this);

accountManager = AccountManager.get(this);

//setToken(accountManager, Launcher.EXPIRED);
checkToken((token) -> onInit(token, eventId), this::finish,
accountManager, this, tokenService);
checkToken(this::onInit, this::finish, this, tokenService);
}

private void onInit(String token, String eventId) {
private void onInit(String token) {
String eventId = getEventId(this);
eventService.amICreator(Globals.getAuthHeader(token), eventId)
.enqueue(new BaseOnNotAuthenticatedCallback<>(this, this::recreate) {
@Override
Expand All @@ -81,6 +71,28 @@ public void onResponse(Call<Boolean> call, Response<Boolean> resp) {
});
}

public static boolean isIncorrect(Activity activity) {
Bundle extras = activity.getIntent().getExtras();
if (extras == null) {
Log.e(TAG, "Unable to create ["
+ activity.getClass().getCanonicalName()
+ "] without extras.");
activity.finish();
return true;
}
if (extras.getString(EVENT_ID_KEY) == null) {
Log.e(TAG, "Unable to create ["
+ activity.getClass().getCanonicalName()
+ "] without [" + EVENT_ID_KEY + "] provided.");
activity.finish();
return true;
}
return false;
}

public static String getEventId(Activity activity) {
return activity.getIntent().getExtras().getString(EVENT_ID_KEY);
}

public static void dispatchToEventActivity(Context ctx, String eventId) {
ctx.startActivity(createEventActivityIntent(ctx, eventId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.tom.meeter.context.event.activity;

import static com.tom.meeter.context.auth.infrastructure.AuthHelper.getAuthHeader;
import static com.tom.meeter.context.profile.component.fragment.GoogleMapsFragment.ZOOM_VALUE;
import static com.tom.meeter.infrastructure.common.InfrastructureHelper.logMethod;
import static com.tom.meeter.infrastructure.common.InfrastructureHelper.showMessage;

import android.accounts.AccountManager;
import android.content.ComponentName;
Expand All @@ -30,6 +28,7 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.tom.meeter.App;
import com.tom.meeter.R;
import com.tom.meeter.context.auth.infrastructure.AuthHelper;
import com.tom.meeter.context.event.service.EventService;
import com.tom.meeter.context.gps.domain.LocationTrackerListener;
import com.tom.meeter.context.gps.service.LocationTrackerService;
Expand All @@ -52,40 +51,29 @@ public class EventLocationMapActivity extends AppCompatActivity
public static final String EXTRA_LNG = "extra_lng";

private static final String TAG = EventLocationMapActivity.class.getCanonicalName();
private Marker eventMarker;
private GoogleMap gmap;
private ActivityEventPositionBinding binding;

private ServiceConnection locationServiceConn;
private LocationTrackerService locationService;
private boolean cameraMoved = false;
@Inject
EventService service;
@Inject
ImageDownloader imgDownloader;

private ActivityEventPositionBinding binding;
private LocationTrackerService locationService;
private ServiceConnection sConn;
private LocationTrackerListener singleLocationUpdateListener;
private String eventId;
private final Runnable onNotAuthenticated = this::finish;
private GoogleMap gmap;

@Inject
EventService eventService;
@Inject
ImageDownloader imageDownloader;
private AccountManager accountManager;
private Marker eventMarker;
private boolean cameraMoved = false;
private LatLng userLocation;

private final Runnable onNotAuthenticated = this::finish;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Bundle extras = getIntent().getExtras();
if (extras == null) {
showMessage(this, "Unable to show map without extras provided.");
finish();
return;
}
eventId = extras.getString(EventDispatcherActivity.EVENT_ID_KEY);
if (eventId == null) {
showMessage(this, "Unable to show map without event_id provided.");
finish();
if (EventDispatcherActivity.isIncorrect(this)) {
return;
}

Expand All @@ -94,13 +82,14 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(view);

((App) getApplication()).getEventComponent().inject(this);
accountManager = AccountManager.get(this);

SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.eventSelectPosition);
if (mapFragment != null) {
mapFragment.getMapAsync(this);
if (mapFragment == null) {
return;
}
mapFragment.getMapAsync(this);

binding.btnConfirm.setOnClickListener(v -> {
if (eventMarker != null) {
Intent resultIntent = new Intent();
Expand All @@ -127,13 +116,13 @@ public void onLocationChanged(Location location) {
cameraMoved = true;
locationService.removeLocationTrackerListener(this);
singleLocationUpdateListener = null;
unbindService(locationServiceConn);
unbindService(sConn);
locationService = null;
locationServiceConn = null;
sConn = null;
}
}
};
locationServiceConn = new ServiceConnection() {
sConn = new ServiceConnection() {
public void onServiceConnected(ComponentName name, IBinder binder) {
logMethod(TAG, this);
locationService = ((LocationTrackerService.ServiceBinder) binder).getService();
Expand All @@ -143,11 +132,12 @@ public void onServiceConnected(ComponentName name, IBinder binder) {
public void onServiceDisconnected(ComponentName name) {
logMethod(TAG, this);
locationService = null;
locationServiceConn = null;
sConn = null;
}
};
Intent service = new Intent(this, LocationTrackerService.class);
bindService(service, locationServiceConn, BIND_AUTO_CREATE);
bindService(
new Intent(this, LocationTrackerService.class),
sConn, BIND_AUTO_CREATE);
}

@Override
Expand All @@ -156,7 +146,9 @@ public void onMapReady(GoogleMap googleMap) {
UiSettings uiSettings = gmap.getUiSettings();
uiSettings.setZoomControlsEnabled(true);

eventService.getEvent(getAuthHeader(accountManager), eventId).enqueue(
service.getEvent(
AuthHelper.getAuthHeader(AccountManager.get(this)),
EventDispatcherActivity.getEventId(this)).enqueue(
new BaseOnNotAuthenticatedCallback<>(this, onNotAuthenticated) {
@Override
public void onResponse(Call<EventDTO> call, Response<EventDTO> resp) {
Expand Down Expand Up @@ -199,7 +191,7 @@ private void setupEventMarker(LatLng latLng, EventDTO event) {
if (photoPath == null) {
return;
}
imageDownloader.downloadEventImage(
imgDownloader.downloadEventImage(
photoPath, this, ImagesHelper::circleImage,
(photo) -> eventMarker.setIcon(BitmapDescriptorFactory.fromBitmap(photo)),
onNotAuthenticated);
Expand All @@ -212,8 +204,8 @@ protected void onDestroy() {
if (locationService != null && singleLocationUpdateListener != null) {
locationService.removeLocationTrackerListener(singleLocationUpdateListener);
}
if (locationServiceConn != null) {
unbindService(locationServiceConn);
if (sConn != null) {
unbindService(sConn);
}
}

Expand Down
Loading