Add modal to ask for BG

This commit is contained in:
Mieszko Wrzeszczyński 2018-12-15 21:49:08 +01:00
parent 39da105bc8
commit 41288f000b
8 changed files with 135 additions and 45 deletions

View File

@ -52,6 +52,7 @@ import com.uam.wmi.findmytutor.service.CoordinateService;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService; import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.service.UserService; import com.uam.wmi.findmytutor.service.UserService;
import com.uam.wmi.findmytutor.utils.ApproximatedLocalization; import com.uam.wmi.findmytutor.utils.ApproximatedLocalization;
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
import com.uam.wmi.findmytutor.utils.InfoHelperUtils; import com.uam.wmi.findmytutor.utils.InfoHelperUtils;
import com.uam.wmi.findmytutor.utils.ManualLocationUtils; import com.uam.wmi.findmytutor.utils.ManualLocationUtils;
import com.uam.wmi.findmytutor.utils.MapMarker; import com.uam.wmi.findmytutor.utils.MapMarker;
@ -291,6 +292,11 @@ public class MapActivity extends BaseActivity
PrefUtils.getLocationLevel(getApplicationContext()) PrefUtils.getLocationLevel(getApplicationContext())
); );
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
EnableSharingDialog sharingDialog = new EnableSharingDialog();
sharingDialog.show(getFragmentManager(), "Sharing");
}
PrefUtils.putManualLocation(this, latLng, approximatedLocation); PrefUtils.putManualLocation(this, latLng, approximatedLocation);
handleBackgroundTaskLifeCycle(); handleBackgroundTaskLifeCycle();

View File

@ -20,6 +20,7 @@ import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel; import com.uam.wmi.findmytutor.model.PredefinedCoordViewModel;
import com.uam.wmi.findmytutor.network.ApiClient; import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.PredefinedStatusesService; import com.uam.wmi.findmytutor.service.PredefinedStatusesService;
import com.uam.wmi.findmytutor.utils.EnableSharingDialog;
import com.uam.wmi.findmytutor.utils.PrefUtils; import com.uam.wmi.findmytutor.utils.PrefUtils;
import com.uam.wmi.findmytutor.utils.RestApiHelper; import com.uam.wmi.findmytutor.utils.RestApiHelper;
import com.uam.wmi.findmytutor.utils.RightButtonPreference; import com.uam.wmi.findmytutor.utils.RightButtonPreference;
@ -149,7 +150,8 @@ public class SharingFragment extends PreferenceFragment {
locationMode.setOnPreferenceChangeListener((preference, newValue) -> { locationMode.setOnPreferenceChangeListener((preference, newValue) -> {
PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue))); PrefUtils.storeLocationMode(getApplicationContext(), locationLevelMapping.get(Integer.parseInt((String) newValue)));
if (PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
if (PrefUtils.getLocationLevel(getApplicationContext()).equals(SharingLevel.MANUAL.toString())) {
if (!predefinedCoordsList.isEmpty()) { if (!predefinedCoordsList.isEmpty()) {
preferenceCategory.addPreference(manualLocationList); preferenceCategory.addPreference(manualLocationList);
} }
@ -167,24 +169,29 @@ public class SharingFragment extends PreferenceFragment {
if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) { if (!PrefUtils.getLocationLevel(getApplicationContext()).equals("manual")) {
preferenceCategory.removePreference(manualLocationList); preferenceCategory.removePreference(manualLocationList);
preferenceCategory.removePreference(manualLocationButton); preferenceCategory.removePreference(manualLocationButton);
}else{
// if(predefinedCoordsList.isEmpty()){
//// preferenceCategory.removePreference(manualLocationList);
//
//
// }
} }
/** Custom manual location list change listener **/ /** Custom manual location list change listener **/
manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> { manualLocationList.setOnPreferenceChangeListener((preference, newValue) -> {
Log.e("Change on manualList", (String) newValue);
ListPreference lp = (ListPreference) preference; ListPreference lp = (ListPreference) preference;
CharSequence[] entries = lp.getEntries(); CharSequence[] entries = lp.getEntries();
PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0); PredefinedCoordViewModel temp = Stream.of(predefinedCoordsList).filter(p -> p.getName().equals(lp.getEntries()[Integer.parseInt((String) newValue)].toString())).toList().get(0);
if (!PrefUtils.isEnableSharingLocalization(getApplicationContext())) {
EnableSharingDialog sharingDialog = new EnableSharingDialog();
sharingDialog.show(getFragmentManager(), "Sharing");
//refresh view -> get new values from xml
}
PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation()); PrefUtils.putManualLocation(getApplicationContext(), temp.getGeoData(), temp.getApproximatedLocation());
PrefUtils.putCurrentManualLocation(getApplicationContext(), temp.getPredefinedCoordinateId()); PrefUtils.putCurrentManualLocation(getApplicationContext(), temp.getPredefinedCoordinateId());
PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String) lp.getEntries()[Integer.parseInt((String) newValue)]); PrefUtils.putCurrentManualLocationName(getApplicationContext(), (String) lp.getEntries()[Integer.parseInt((String) newValue)]);
lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]); lp.setSummary(lp.getEntries()[Integer.parseInt((String) newValue)]);
getPreferenceScreen().removeAll();
addPreferencesFromResource(R.layout.pref_sharing);
return true; return true;
}); });
@ -204,6 +211,7 @@ public class SharingFragment extends PreferenceFragment {
lp.setSummary(entries[Integer.parseInt((String) newValue)]); lp.setSummary(entries[Integer.parseInt((String) newValue)]);
return true; return true;
}); });
/** Custom status list change listener **/ /** Custom status list change listener **/
manualStatus.setOnPreferenceChangeListener((preference, newValue) -> { manualStatus.setOnPreferenceChangeListener((preference, newValue) -> {
@ -212,18 +220,15 @@ public class SharingFragment extends PreferenceFragment {
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.subscribe(this::handleResponse, this::handleError)); .subscribe(this::handleResponse, this::handleError));
return true; return true;
}); });
} }
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = super.onCreateView(inflater, container, savedInstanceState); View view = super.onCreateView(inflater, container, savedInstanceState);
Objects.requireNonNull(view).setBackgroundColor(getResources().getColor(android.R.color.white)); Objects.requireNonNull(view).setBackgroundColor(getResources().getColor(android.R.color.white));
;
return view; return view;
} }
@ -247,7 +252,9 @@ public class SharingFragment extends PreferenceFragment {
Log.e("Failed to set listPref", e.getMessage()); Log.e("Failed to set listPref", e.getMessage());
} }
}; }
;
private void handleResponse(List<String> resp) { private void handleResponse(List<String> resp) {
String[] statusesArray = resp.toArray(new String[resp.size()]); String[] statusesArray = resp.toArray(new String[resp.size()]);
@ -257,8 +264,6 @@ public class SharingFragment extends PreferenceFragment {
statusList.setValueIndex(resp.size() - 1); statusList.setValueIndex(resp.size() - 1);
PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1)); PrefUtils.storeStatus(getApplicationContext(), resp.get(resp.size() - 1));
statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext())); statusList.setSummary(PrefUtils.getUserStatus(getApplicationContext()));
} }
private void handleError(Throwable error) { private void handleError(Throwable error) {

View File

@ -27,7 +27,6 @@ public class ApiClient {
private static Retrofit retrofit = null; private static Retrofit retrofit = null;
private static int REQUEST_TIMEOUT = 60; private static int REQUEST_TIMEOUT = 60;
private static OkHttpClient okHttpClient; private static OkHttpClient okHttpClient;
// private static final String BASE_URL = "https://s416084.projektstudencki.pl/master/";
public static Retrofit getClient(Context context) { public static Retrofit getClient(Context context) {

View File

@ -7,7 +7,7 @@ import java.util.List;
public class Const { public class Const {
public final static String BASE_URL = "https://s416084.projektstudencki.pl/master/"; public final static String BASE_URL = "https://s416084.projektstudencki.pl/master/";
public final static Integer onlineBackgroundLocationInterval = 15000; public final static Integer onlineBackgroundLocationInterval = 7000;
public final static Integer offlineBackgroundLocationInterval = 36000; public final static Integer offlineBackgroundLocationInterval = 36000;
public final static Integer defaultMapZoom = 17; public final static Integer defaultMapZoom = 17;
public final static Integer searchMapZoom = 13; public final static Integer searchMapZoom = 13;

View File

@ -0,0 +1,71 @@
package com.uam.wmi.findmytutor.utils;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AlertDialog;
import android.widget.Toast;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.activity.MapActivity;
/*public class EnableSharingDialog extends DialogFragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_sample_dialog, container, false);
getDialog().setTitle("Simple Dialog");
return rootView;
}
public void createSharingDialog(Context context) {
LayoutInflater layoutInflaterAndroid = LayoutInflater.from(getActivity().getApplicationContext());
View view = layoutInflaterAndroid.inflate(R.layout.user_list_modal, null);
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity());
dialogBuilder.setView(view);
dialogBuilder.setMessage(R.string.enable_sharing_question);
dialogBuilder.setCancelable(true);
dialogBuilder.setPositiveButton(R.string.possitive_dialog_button,
(dialog, id) -> {
dialogPositiveAnswer(context);
dialog.cancel();
}
);
dialogBuilder.setNegativeButton(
R.string.negative_dialog_button,
(dialog, id) ->
dialog.cancel());
AlertDialog alert11 = dialogBuilder.create();
alert11.show();
}
private void dialogPositiveAnswer(Context context) {
PrefUtils.storeBackgroundLocationStatus(context, true);
}
}
*/
public class EnableSharingDialog extends DialogFragment {
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new AlertDialog.Builder(getActivity())
.setTitle(R.string.sharing_modal_title)
.setMessage(R.string.enable_sharing_question)
.setPositiveButton(R.string.possitive_dialog_button, (dialog, which) ->
dialogPositiveAnswer(getActivity())
)
.setNegativeButton(R.string.negative_dialog_button, (dialog, which) -> dialog.cancel()).create();
}
private void dialogPositiveAnswer(Context context) {
PrefUtils.storeEnableSharingLocalization(context, true);
((MapActivity) getActivity()).handleBackgroundTaskLifeCycle();
}
}

View File

@ -162,7 +162,7 @@ public class PrefUtils {
editor.putString("key_location_level","3"); editor.putString("key_location_level","3");
editor.putString("location_mode", "manual"); editor.putString("location_mode", "manual");
editor.putString("approx_manual_loc", approximatedLocation); editor.putString("approx_manual_loc", approximatedLocation);
editor.putBoolean("key_sharing_enabled", true); /*editor.putBoolean("key_sharing_enabled", true);*/
editor.putLong("longitude_manual_location", Double.doubleToRawLongBits(latLng.getLongitude())); editor.putLong("longitude_manual_location", Double.doubleToRawLongBits(latLng.getLongitude()));
editor.putLong("latitude_manual_location", Double.doubleToRawLongBits(latLng.getLatitude())); editor.putLong("latitude_manual_location", Double.doubleToRawLongBits(latLng.getLatitude()));
editor.apply(); editor.apply();

View File

@ -213,6 +213,11 @@
<string name="info_icon_userlist_tab_level_status_inactive">- użytkownik jest nieaktywny</string> <string name="info_icon_userlist_tab_level_status_inactive">- użytkownik jest nieaktywny</string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(nie udostępnił żadnych danych o lokalizacji od conajmniej tygodnia)</string> <string name="info_icon_userlist_tab_level_status_inactive_tip">(nie udostępnił żadnych danych o lokalizacji od conajmniej tygodnia)</string>
<string name="possitive_dialog_button">Tak</string>
<string name="negative_dialog_button">Nie</string>
<string name="enable_sharing_question">Aby skorzystać z tej funkcji musisz pozwolić na udostępnianie lokalizacji. Zgadzasz sie?</string>
<string name="sharing_modal_title">Udostępnianie</string>
</resources> </resources>

View File

@ -293,5 +293,9 @@
<string name="info_icon_userlist_tab_level_status_offline">- user is currently offline</string> <string name="info_icon_userlist_tab_level_status_offline">- user is currently offline</string>
<string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string> <string name="info_icon_userlist_tab_level_status_inactive">- user is inactive </string>
<string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string> <string name="info_icon_userlist_tab_level_status_inactive_tip">(didnt share any localization data since 7 days)</string>
<string name="possitive_dialog_button">yes</string>
<string name="negative_dialog_button">No</string>
<string name="enable_sharing_question">In order to use this function, you have to enable localization sharing. May I do it for you?</string>
<string name="sharing_modal_title">Sharing</string>
</resources> </resources>