Merge pull request #10174 from osmandapp/upload-poi-note

Upload poi, note
This commit is contained in:
Vitaliy 2020-11-13 14:47:21 +00:00 committed by GitHub
commit 01a5b8d554
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
33 changed files with 1189 additions and 213 deletions

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#CCCCCC" />
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<stroke android:width="1dp" android:color="#2F3030" />
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#2F3030"/>
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F0F0F0"/>
<corners android:radius="6dp"/>
<padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

View file

@ -0,0 +1,169 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/note_hint"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin"
android:hint="@string/osn_bug_name">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/note_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/upload_anonymously_switch"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:layout_marginBottom="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small"
android:paddingTop="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:text="@string/upload_anonymously"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
android:letterSpacing="@dimen/text_button_letter_spacing"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<LinearLayout
android:id="@+id/account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/text_margin_small"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/content_padding_half"
android:minHeight="@dimen/context_menu_buttons_bottom_height">
<androidx.appcompat.widget.AppCompatImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
osmand:srcCompat="@drawable/ic_action_user_account"
android:tint="@color/active_buttons_and_links_text_disabled_light"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/account_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:singleLine="true"
android:text="@string/login_account"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/sign_in_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/text_margin_small"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier"
android:textColor="?android:textColorPrimary"
android:paddingTop="@dimen/content_padding_small"
android:paddingLeft="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding"
android:paddingBottom="@dimen/content_padding_small"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
android:text="@string/osm_login_descr" />
<include
android:id="@+id/sign_in_button"
layout="@layout/bottom_sheet_dialog_button"
android:layout_marginBottom="@dimen/content_padding_half"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height" />
<include
android:id="@+id/login_button"
layout="@layout/bottom_sheet_dialog_button"
android:layout_marginTop="@dimen/content_padding_small"
android:layout_marginBottom="@dimen/content_padding"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_width="match_parent"
android:layout_height="@dimen/dialog_button_height" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,123 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingTop="@dimen/bottom_sheet_content_margin"
android:paddingEnd="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:text="@string/upload_poi"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
android:letterSpacing="@dimen/text_button_letter_spacing"/>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/message_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/bottom_sheet_content_margin"
android:hint="@string/shared_string_message">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/message_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/close_change_set_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/content_padding"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
android:text="@string/close_changeset"
android:paddingLeft="@dimen/content_padding_small"
android:paddingRight="@dimen/content_padding_small"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular"
android:letterSpacing="@dimen/text_button_letter_spacing" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider" />
<LinearLayout
android:id="@+id/account_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/context_menu_buttons_bottom_height"
tools:background="?android:attr/selectableItemBackground">
<androidx.appcompat.widget.AppCompatImageView
android:id="@android:id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin_large"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin"
osmand:srcCompat="@drawable/ic_action_user_account"
android:tint="@color/active_buttons_and_links_text_disabled_light"
android:layout_marginEnd="@dimen/content_padding"
android:layout_marginStart="@dimen/content_padding" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/account_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:singleLine="true"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:text="@string/login_account"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/user_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -23,7 +23,8 @@
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/name_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:lineSpacingMultiplier="@dimen/bottom_sheet_text_spacing_multiplier" />
</com.google.android.material.textfield.TextInputLayout>

View file

@ -3942,7 +3942,6 @@
<string name="subscription_on_hold_title">اشتراك OsmAnd Live معلق</string>
<string name="login_open_street_map">تسجيل الدخول إلى خريطة الشارع المفتوح</string>
<string name="login_open_street_map_org">تسجيل الدخول إلى OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">تسجيل الخروج</string>
<string name="open_street_map_login_mode">تحتاج إلى تسجيل الدخول لرفع التغييرات الجديدة أو المعدلة.
\n
\nيمكنك تسجيل الدخول باستخدام طريقة التفويض الآمنة أو استخدام تسجيل الدخول وكلمة المرور.</string>

View file

@ -3957,7 +3957,6 @@
<string name="subscription_expired_title">La suscripción a OsmAnd Live ha caducado</string>
<string name="subscription_paused_title">La suscripción a OsmAnd Live se ha pausado</string>
<string name="subscription_on_hold_title">La suscripción a OsmAnd Live está en espera</string>
<string name="sing_in_with_open_street_map">Ingresar con OpenStreetMap</string>
<string name="login_open_street_map">Iniciar sesión en OpenStreetMap</string>
<string name="login_open_street_map_org">Ingresar a OpenStreetMap.org</string>
<string name="open_street_map_login_mode">Necesitas iniciar sesión para subir cambios nuevos o modificados.

View file

@ -3804,7 +3804,7 @@
<string name="subscription_expired_title">OsmAnd Live tellimus on aegunud</string>
<string name="subscription_payment_issue_title">Sinu tellimusega on üks pisikene segadus. Selleks et Google Play seadistuses makseviisi parandada, palun klõpsi seda nuppu.</string>
<string name="manage_subscription">Halda tellimusi</string>
<string name="sing_in_with_open_street_map">Logi sisse OpenStreetMapi kasutajakontoga</string>
<string name="sign_in_with_open_street_map">Logi sisse OpenStreetMapi kasutajakontoga</string>
<string name="user_login">Kasutajanimi</string>
<string name="use_login_password">Pruugi kasutajanime ja salasõna</string>
<string name="open_street_map_login_mode">Täienduste või muudatuste üleslaadimiseks pead sisse logima.

View file

@ -3932,7 +3932,6 @@
<string name="subscription_paused_title">L\'abonnement OsmAnd Live a été suspendu</string>
<string name="login_open_street_map">Se connecter à OpenStreetMap</string>
<string name="login_open_street_map_org">Se connecter à OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">Se connecter avec OpenStreetMap</string>
<string name="user_login">Identifiant</string>
<string name="use_login_password">Utiliser un identifiant et un mot de passe</string>
<string name="login_account">Compte</string>

View file

@ -3954,7 +3954,7 @@
<string name="message_you_need_add_two_points_to_show_graphs">עליך להוסיף שתי נקודות לפחות.</string>
<string name="login_open_street_map">כניסה ל־OpenStreetMap</string>
<string name="login_open_street_map_org">כניסה ל־OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">כניסה עם OpenStreetMap</string>
<string name="sign_in_with_open_street_map">כניסה עם OpenStreetMap</string>
<string name="use_login_password">להשתמש בשם כניסה וססמה</string>
<string name="login_account">חשבון</string>
<string name="user_login">כניסה</string>

View file

@ -3961,7 +3961,7 @@
<string name="user_login">Login</string>
<string name="login_open_street_map">Zaloguj się do OpenStreetMap</string>
<string name="login_open_street_map_org">Zaloguj się do OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">Zaloguj się za pomocą OpenStreetMap</string>
<string name="sign_in_with_open_street_map">Zaloguj się za pomocą OpenStreetMap</string>
<string name="open_street_map_login_mode">Musisz się zalogować, aby przesłać nowe lub zmodyfikowane zmiany.
\n
\nMożesz zalogować się za pomocą bezpiecznej metody autoryzacji OAuth lub użyć swojego loginu i hasła.</string>

View file

@ -3950,7 +3950,6 @@
<string name="app_mode_gap">Diferença</string>
<string name="login_open_street_map">Entrar para OpenStreetMap</string>
<string name="login_open_street_map_org">Entrar com OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">Entrar com OpenStreetMap</string>
<string name="open_street_map_login_mode">Você precisa entrar para enviar alterações novas ou modificadas.
\n
\nVocê pode entrar usando o método OAuth seguro ou usar sua entrada e senha.</string>

View file

@ -3960,7 +3960,7 @@
\nPode entrar a usar o método seguro OAuth ou usar o seu nome de utilizador e a sua palavra-passe.</string>
<string name="login_open_street_map">Fazer login ao OpenStreetMap</string>
<string name="login_open_street_map_org">Entrar com OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">Entrar com OpenStreetMap</string>
<string name="sign_in_with_open_street_map">Entrar com OpenStreetMap</string>
<string name="use_login_password">Usar nome do utilizador e palavra-passe</string>
<string name="login_account">Conta</string>
<string name="user_login">Entrar</string>

View file

@ -3905,7 +3905,6 @@
<string name="message_you_need_add_two_points_to_show_graphs">En az iki nokta eklemelisiniz</string>
<string name="login_open_street_map">OpenStreetMap\'te oturum aç</string>
<string name="login_open_street_map_org">OpenStreetMap.org\'da oturum aç</string>
<string name="sing_in_with_open_street_map">OpenStreetMap ile giriş yap</string>
<string name="open_street_map_login_mode">Yenilikleri veya değişiklikleri karşıya yüklemek için oturum açmanız gerekir.
\n
\nGüvenli OAuth yöntemini kullanarak oturum açabilir veya kullanıcı adı ve parolanızı kullanabilirsiniz.</string>

View file

@ -3951,7 +3951,6 @@
<string name="subscription_on_hold_title">Передплата OsmAnd Live на утриманні</string>
<string name="login_open_street_map">Увійти до OpenStreetMap.org</string>
<string name="login_open_street_map_org">Увійти до OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">Увійти за допомогою OpenStreetMap</string>
<string name="open_street_map_login_mode">Увійдіть, щоб вивантажити нові або внесені зміни.
\n
\nВи можете увійти, за допомогою безпечного методу OAuth, або скористатися своїм ім\'ям та паролем.</string>

View file

@ -3950,7 +3950,6 @@
<string name="subscription_on_hold_title">OsmAnd Live 訂閱已暫停</string>
<string name="login_open_street_map">登入到 OpenStreetMap</string>
<string name="login_open_street_map_org">登入到 OpenStreetMap.org</string>
<string name="sing_in_with_open_street_map">以 OpenStreetMap 登入</string>
<string name="open_street_map_login_mode">您必須登入以上傳新的或修正過的變更。
\n
\n您可以使用安全的 OAuth 方法或使用您的登入與密碼來登入。</string>

View file

@ -11,6 +11,9 @@
Thx - Hardy
-->
<string name="osm_login_descr">You can log in using the safe OAuth method or use your login and password.</string>
<string name="osm_edit_comment_note">Comment OSM Note</string>
<string name="osm_edit_close_note">Close OSM Note</string>
<string name="gpx_upload_trackable_visibility_descr">Trackable means that the trace will not show up in any public listings but trackpoints from it will still be available through the public GPS API with timestamps. Other users will only be able to download processed trackpoints from your trace which can\'t be associated with you directly.</string>
<string name="gpx_upload_identifiable_visibility_descr">Identifiable means that the trace will be shown publicly in Your GPS traces and in public GPS trace listings, i.e. other users will be able to download the raw trace and associate it with your username. Data served via the trackpoints API will reference your original trace page. Timestamps of the trace points are available through the public GPS API.</string>
<string name="gpx_upload_private_visibility_descr">Private means that the trace will not show up in any public listings, but trackpoints from it will still be available through the public GPS API without timestamps but will not be chronologically ordered.</string>

View file

@ -44,6 +44,7 @@ import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.render.MapRenderRepositories;
@ -455,7 +456,7 @@ public class AppInitializer implements IProgress {
app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class);
app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class);
app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
app.travelDbHelper = new TravelDbHelper(app);
if (app.getSettings().SELECTED_TRAVEL_BOOK.get() != null) {
app.travelDbHelper.initTravelBooks();
@ -464,7 +465,7 @@ public class AppInitializer implements IProgress {
app.lockHelper = startupInit(new LockHelper(app), LockHelper.class);
app.settingsHelper = startupInit(new SettingsHelper(app), SettingsHelper.class);
app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
initOpeningHoursParser();
}

View file

@ -43,7 +43,6 @@ import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.access.AccessibilityMode;
import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.activities.ExitActivity;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.SavingTrackHelper;
@ -57,14 +56,16 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadService;
import net.osmand.plus.download.IndexItem;
import net.osmand.plus.helpers.AvoidSpecificRoads;
import net.osmand.plus.helpers.enums.DrivingRegion;
import net.osmand.plus.helpers.DayNightHelper;
import net.osmand.plus.helpers.LockHelper;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.helpers.WaypointHelper;
import net.osmand.plus.helpers.enums.DrivingRegion;
import net.osmand.plus.helpers.enums.MetricsConstants;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.mapmarkers.MapMarkersDbHelper;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.monitoring.LiveMonitoringHelper;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.render.RendererRegistry;
@ -154,6 +155,7 @@ public class OsmandApplication extends MultiDexApplication {
SettingsHelper settingsHelper;
GpxDbHelper gpxDbHelper;
QuickActionRegistry quickActionRegistry;
OsmOAuthHelper osmOAuthHelper;
private Resources localizedResources;
private Map<String, Builder> customRoutingConfigs = new ConcurrentHashMap<>();
@ -366,8 +368,12 @@ public class OsmandApplication extends MultiDexApplication {
return settingsHelper;
}
public OsmOAuthHelper getOsmOAuthHelper() {
return osmOAuthHelper;
}
public synchronized DownloadIndexesThread getDownloadThread() {
if(downloadIndexesThread == null) {
if (downloadIndexesThread == null) {
downloadIndexesThread = new DownloadIndexesThread(this);
}
return downloadIndexesThread;

View file

@ -4,6 +4,8 @@ import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import androidx.fragment.app.Fragment;
import net.osmand.AndroidNetworkUtils;
import net.osmand.CallbackWithObject;
import net.osmand.IndexConstants;
@ -19,7 +21,6 @@ import net.osmand.plus.activities.PluginsFragment;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapsource.EditMapSourceDialogFragment;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.backend.OsmandSettings;
@ -35,6 +36,8 @@ import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
public class IntentHelper {
private static final Log LOG = PlatformUtil.getLog(IntentHelper.class);
@ -293,13 +296,15 @@ public class IntentHelper {
if (intent != null && intent.getData() != null) {
Uri uri = intent.getData();
if (uri.toString().startsWith("osmand-oauth")) {
LoginBottomSheetFragment fragment = mapActivity.getLoginBottomSheetFragment();
if (fragment != null) {
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
fragment.authorize(oauthVerifier);
mapActivity.setIntent(null);
return true;
String oauthVerifier = uri.getQueryParameter("oauth_verifier");
app.getOsmOAuthHelper().authorize(oauthVerifier);
for (Fragment fragment : mapActivity.getSupportFragmentManager().getFragments()) {
if (fragment instanceof OsmAuthorizationListener) {
((OsmAuthorizationListener) fragment).authorizationCompleted();
}
}
mapActivity.setIntent(null);
return true;
}
}
return false;

View file

@ -18,31 +18,32 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper;
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
import static net.osmand.plus.osmedit.oauth.OsmOAuthHelper.*;
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment implements OsmAuthorizationListener {
public static final String TAG = LoginBottomSheetFragment.class.getSimpleName();
private static final Log log = PlatformUtil.getLog(LoginBottomSheetFragment.class);
private static final String OSM_LOGIN_DATA = "osm_login_data";
private static final Log LOG = PlatformUtil.getLog(LoginBottomSheetFragment.class);
private OsmOAuthAuthorizationAdapter authorizationAdapter;
private OsmOAuthHelper osmOAuthHelper;
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = requiredMyApplication();
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create());
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
OsmandApplication app = requiredMyApplication();
osmOAuthHelper = app.getOsmOAuthHelper();
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
items.add(new SimpleBottomSheetItem.Builder().setLayoutId(R.layout.bottom_sheet_login).create());
}
@Override
protected int getDismissButtonTextId() {
@ -88,7 +89,7 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
protected void onThirdBottomButtonClick() {
View view = getView();
if (view != null) {
authorizationAdapter.startOAuth((ViewGroup) view);
osmOAuthHelper.startOAuth((ViewGroup) view);
}
}
@ -98,45 +99,19 @@ public class LoginBottomSheetFragment extends MenuBottomSheetDialogFragment {
}
public static void showInstance(@NonNull FragmentManager fragmentManager, @Nullable Fragment targetFragment) {
if (!fragmentManager.isStateSaved()) {
LoginBottomSheetFragment fragment = new LoginBottomSheetFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fragmentManager, TAG);
try {
if (!fragmentManager.isStateSaved()) {
LoginBottomSheetFragment fragment = new LoginBottomSheetFragment();
fragment.setTargetFragment(targetFragment, 0);
fragment.show(fragmentManager, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
public void authorize(String oauthVerifier) {
if (authorizationAdapter != null) {
authorizationAdapter.authorize(oauthVerifier);
updateUserName();
}
Fragment target = getTargetFragment();
if (target instanceof OsmAuthorizationListener) {
((OsmAuthorizationListener) target).authorizationCompleted();
}
@Override
public void authorizationCompleted() {
dismiss();
}
private void updateUserName() {
OsmandApplication app = getMyApplication();
if (app != null) {
String userName = "";
try {
userName = authorizationAdapter.getUserName();
} catch (InterruptedException e) {
log.error(e);
} catch (ExecutionException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
} catch (XmlPullParserException e) {
log.error(e);
}
app.getSettings().USER_DISPLAY_NAME.set(userName);
}
}
public interface OsmAuthorizationListener {
void authorizationCompleted();
}
}

View file

@ -15,7 +15,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuController;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.SimpleProgressDialogPoiUploader;
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.settings.backend.OsmandSettings;
@ -45,16 +46,24 @@ public class EditPOIMenuController extends MenuController {
public void buttonPressed() {
MapActivity activity = getMapActivity();
if (plugin != null && activity != null) {
OsmPoint point = getOsmPoint();
OsmandApplication app = activity.getMyApplication();
OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter client = new OsmOAuthAuthorizationAdapter(app);
if (client.isValidToken()
boolean isLogged = client.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get())) {
SimpleProgressDialogPoiUploader poiDialogUploader = new SimpleProgressDialogPoiUploader(activity);
poiDialogUploader.showProgressDialog(new OsmPoint[] {getOsmPoint()}, false, false);
} else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
if (point instanceof OpenstreetmapPoint) {
if (isLogged) {
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
new OsmPoint[]{getOsmPoint()});
} else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), null);
}
} else if (point instanceof OsmNotesPoint) {
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(),
new OsmPoint[]{getOsmPoint()});
}
}
}

View file

@ -0,0 +1,59 @@
package net.osmand.plus.osmedit;
import android.os.AsyncTask;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.plus.osmedit.OsmPoint.Action;
import static net.osmand.plus.osmedit.OsmBugsLayer.*;
import static net.osmand.plus.osmedit.OsmBugsUtil.*;
public class HandleOsmNoteAsyncTask extends AsyncTask<Void, Void, OsmBugResult> {
private OsmBugsUtil osmbugsUtil;
private final OsmBugsUtil local;
private final OpenStreetNote bug;
private final OsmNotesPoint point;
private final String text;
private final Action action;
private final HandleBugListener handleBugListener;
public HandleOsmNoteAsyncTask(@NonNull OsmBugsUtil osmbugsUtil, @NonNull OsmBugsUtil local,
@Nullable OpenStreetNote bug, @Nullable OsmNotesPoint point,
String text, Action action,
@Nullable HandleBugListener handleBugListener) {
this.osmbugsUtil = osmbugsUtil;
this.local = local;
this.bug = bug;
this.point = point;
this.text = text;
this.action = action;
this.handleBugListener = handleBugListener;
}
@Override
protected OsmBugResult doInBackground(Void... params) {
if (bug != null) {
OsmNotesPoint pnt = new OsmNotesPoint();
pnt.setId(bug.getId());
pnt.setLatitude(bug.getLatitude());
pnt.setLongitude(bug.getLongitude());
return osmbugsUtil.commit(pnt, text, action);
} else if (point != null) {
osmbugsUtil = local;
return osmbugsUtil.modify(point, text);
}
return null;
}
protected void onPostExecute(OsmBugResult obj) {
handleBugListener.onOsmBugHandled(obj, action, bug, point, text);
}
public interface HandleBugListener {
void onOsmBugHandled(OsmBugResult obj, Action action, OpenStreetNote bug,
OsmNotesPoint point, String text);
}
}

View file

@ -4,7 +4,6 @@ import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View;
@ -25,10 +24,10 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.osmedit.dialogs.BugBottomSheetDialog;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.OsmBugsUtil.OsmBugResult;
import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.views.layers.ContextMenuLayer.IContextMenuProvider;
import net.osmand.plus.views.OsmandMapLayer;
@ -47,6 +46,8 @@ import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import static net.osmand.plus.osmedit.OsmBugsUtil.*;
public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider {
private static final Log log = PlatformUtil.getLog(OsmBugsLayer.class);
@ -67,7 +68,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
public OsmBugsUtil getOsmbugsUtil(OpenStreetNote bug) {
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
OsmandSettings settings = activity.getMyApplication().getSettings();
if ((bug != null && bug.isLocal()) || settings.OFFLINE_EDITION.get()
|| !settings.isInternetConnectionAvailable(true)) {
return local;
@ -246,7 +247,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
return text;
}
protected List<OpenStreetNote> loadingBugs(double topLatitude, double leftLongitude, double bottomLatitude, double rightLongitude) {
final int deviceApiVersion = android.os.Build.VERSION.SDK_INT;
@ -311,89 +311,16 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
return bugs;
}
private void asyncActionTask(final OpenStreetNote bug, final OsmNotesPoint point, final String text, final Action action) {
AsyncTask<Void, Void, OsmBugResult> task = new AsyncTask<Void, Void, OsmBugResult>() {
private OsmBugsUtil osmbugsUtil;
@Override
protected OsmBugResult doInBackground(Void... params) {
if (bug != null) {
osmbugsUtil = getOsmbugsUtil(bug);
OsmNotesPoint pnt = new OsmNotesPoint();
pnt.setId(bug.getId());
pnt.setLatitude(bug.getLatitude());
pnt.setLongitude(bug.getLongitude());
return osmbugsUtil.commit(pnt, text, action);
} else if (point != null) {
osmbugsUtil = local;
return osmbugsUtil.modify(point, text);
}
return null;
}
protected void onPostExecute(OsmBugResult obj) {
if (activity == null || activity.isFinishing() || activity.isActivityDestroyed()) {
return;
}
if (obj != null && obj.warning == null) {
if (local == osmbugsUtil) {
Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show();
if (obj.local != null) {
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText());
activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()), pd, obj.local);
}
} else {
if (action == Action.REOPEN) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.MODIFY) {
Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.DELETE) {
Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.CREATE) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
}
}
clearCache();
} else {
int r = R.string.osb_comment_dialog_error;
if (action == Action.REOPEN) {
r = R.string.osn_add_dialog_error;
reopenBug(bug, text);
} else if (action == Action.DELETE) {
r = R.string.osn_close_dialog_error;
closeBug(bug, text);
} else if (action == Action.CREATE) {
r = R.string.osn_add_dialog_error;
openBug(bug.getLatitude(), bug.getLongitude(), text);
} else if (action == null) {
r = R.string.osn_modify_dialog_error;
modifyBug(point);
} else {
commentBug(bug, text);
}
Toast.makeText(activity, activity.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show();
}
}
};
executeTaskInBackground(task);
}
public void openBug(final double latitude, final double longitude, String message) {
OpenStreetNote bug = new OpenStreetNote();
bug.setLatitude(latitude);
bug.setLongitude(longitude);
showBugDialog(bug, Action.CREATE, message);
}
public void openBug(final double latitude, final double longitude, String message, boolean autofill) {
OpenStreetNote bug = new OpenStreetNote();
bug.setLatitude(latitude);
bug.setLongitude(longitude);
if (autofill) asyncActionTask(bug, null, message, Action.CREATE);
else showBugDialog(bug, Action.CREATE, message);
if (autofill) {
executeTaskInBackground(new HandleOsmNoteAsyncTask(getOsmbugsUtil(bug), local, bug, null, message,
Action.CREATE, getHandleBugListener()));
} else {
showBugDialog(bug, Action.CREATE, message);
}
}
public void closeBug(final OpenStreetNote bug, String txt) {
@ -414,38 +341,45 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
private void showBugDialog(final OsmNotesPoint point) {
String text = point.getText();
createBugDialog(true, text, R.string.osn_modify_dialog_title, null, null, point);
createBugDialog(true, text, R.string.context_menu_item_modify_note, R.string.osn_modify_dialog_title,
null, null, point);
}
private void showBugDialog(final OpenStreetNote bug, final Action action, String text) {
int title;
int posButtonTextId;
int titleTextId;
if (action == Action.DELETE) {
title = R.string.osn_close_dialog_title;
posButtonTextId = R.string.osn_close_dialog_title;
titleTextId = R.string.osm_edit_close_note;
} else if (action == Action.MODIFY) {
title = R.string.osn_comment_dialog_title;
posButtonTextId = R.string.osn_comment_dialog_title;
titleTextId = R.string.osm_edit_comment_note;
} else if (action == Action.REOPEN) {
title = R.string.osn_reopen_dialog_title;
posButtonTextId = R.string.osn_reopen_dialog_title;
titleTextId = R.string.osn_reopen_dialog_title;
} else {
title = R.string.osn_add_dialog_title;
posButtonTextId = R.string.osn_add_dialog_title;
titleTextId = R.string.context_menu_item_open_note;
}
OsmBugsUtil util = getOsmbugsUtil(bug);
final boolean offline = util instanceof OsmBugsLocalUtil;
createBugDialog(offline, text, title, action, bug, null);
createBugDialog(offline, text, titleTextId, posButtonTextId, action, bug, null);
}
private void createBugDialog(final boolean offline, String text, int posButtonTitleRes, final Action action, final OpenStreetNote bug, final OsmNotesPoint point) {
@SuppressLint("InflateParams")
final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
private void createBugDialog(final boolean offline, String text, int titleTextId, int posButtonTextId,
final Action action, final OpenStreetNote bug, final OsmNotesPoint point) {
@SuppressLint("InflateParams") final View view = LayoutInflater.from(activity).inflate(R.layout.open_bug, null);
if (offline) {
view.findViewById(R.id.user_name_field).setVisibility(View.GONE);
view.findViewById(R.id.userNameEditTextLabel).setVisibility(View.GONE);
view.findViewById(R.id.password_field).setVisibility(View.GONE);
view.findViewById(R.id.passwordEditTextLabel).setVisibility(View.GONE);
activity.getContextMenu().close();
BugBottomSheetDialog.showInstance(activity.getSupportFragmentManager(), getOsmbugsUtil(bug), local, text,
titleTextId, posButtonTextId, action, bug, point, getHandleBugListener());
return;
} else {
((EditText) view.findViewById(R.id.user_name_field)).setText(getUserName());
((EditText) view.findViewById(R.id.password_field)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
((EditText) view.findViewById(R.id.password_field)).setText(
activity.getMyApplication().getSettings().USER_PASSWORD.get());
}
if (!Algorithms.isEmpty(text)) {
((EditText) view.findViewById(R.id.message_field)).setText(text);
@ -456,22 +390,76 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
builder.setTitle(R.string.shared_string_commit);
builder.setView(view);
builder.setPositiveButton(posButtonTitleRes, new DialogInterface.OnClickListener() {
builder.setPositiveButton(posButtonTextId, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String text = offline ? getMessageText(view) : getTextAndUpdateUserPwd(view);
activity.getContextMenu().close();
if (bug != null) {
asyncActionTask(bug, null, text, action);
} else if (point != null) {
asyncActionTask(null, point, text, null);
}
handleBug(text, bug, action, point);
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.create().show();
}
private void handleBug(String text, OpenStreetNote bug, Action action, OsmNotesPoint point) {
if (bug != null || point != null) {
executeTaskInBackground(new HandleOsmNoteAsyncTask(getOsmbugsUtil(bug), local, bug, point, text, action,
getHandleBugListener()));
}
}
HandleOsmNoteAsyncTask.HandleBugListener getHandleBugListener() {
return new HandleOsmNoteAsyncTask.HandleBugListener() {
@Override
public void onOsmBugHandled(OsmBugResult obj, Action action, OpenStreetNote bug,
OsmNotesPoint point, String text) {
if (activity == null || activity.isFinishing()) {
return;
}
if (obj != null && obj.warning == null) {
if (local == getOsmbugsUtil(bug)) {
Toast.makeText(activity, R.string.osm_changes_added_to_local_edits, Toast.LENGTH_LONG).show();
if (obj.local != null) {
PointDescription pd = new PointDescription(PointDescription.POINT_TYPE_OSM_BUG, obj.local.getText());
activity.getContextMenu().show(new LatLon(obj.local.getLatitude(), obj.local.getLongitude()),
pd, obj.local);
}
} else {
if (action == Action.REOPEN) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.MODIFY) {
Toast.makeText(activity, R.string.osb_comment_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.DELETE) {
Toast.makeText(activity, R.string.osn_close_dialog_success, Toast.LENGTH_LONG).show();
} else if (action == Action.CREATE) {
Toast.makeText(activity, R.string.osn_add_dialog_success, Toast.LENGTH_LONG).show();
}
}
clearCache();
} else {
int r = R.string.osb_comment_dialog_error;
if (action == Action.REOPEN) {
r = R.string.osn_add_dialog_error;
reopenBug(bug, text);
} else if (action == Action.DELETE) {
r = R.string.osn_close_dialog_error;
closeBug(bug, text);
} else if (action == Action.CREATE) {
r = R.string.osn_add_dialog_error;
openBug(bug.getLatitude(), bug.getLongitude(), text, false);
} else if (action == null) {
r = R.string.osn_modify_dialog_error;
modifyBug(point);
} else {
commentBug(bug, text);
}
Toast.makeText(activity, activity.getResources().getString(r) + "\n" + obj, Toast.LENGTH_LONG).show();
}
}
};
}
private String getUserName() {
return ((OsmandApplication) activity.getApplication()).getSettings().USER_NAME.get();
}
@ -495,8 +483,6 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
}
@Override
public PointDescription getObjectName(Object o) {
if (o instanceof OpenStreetNote) {

View file

@ -19,9 +19,9 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment.OsmAuthorizationListener;
import net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.ValidateOsmLoginListener;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
import net.osmand.plus.settings.backend.OsmAndAppCustomization;
import net.osmand.plus.settings.fragments.BaseSettingsFragment;
import net.osmand.plus.settings.fragments.OnPreferenceChanged;
@ -34,13 +34,14 @@ import org.apache.commons.logging.Log;
import static net.osmand.plus.myplaces.FavoritesActivity.TAB_ID;
import static net.osmand.plus.osmedit.OsmEditingPlugin.OSM_EDIT_TAB;
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener, OsmAuthorizationListener {
public class OsmEditingFragment extends BaseSettingsFragment implements OnPreferenceChanged, ValidateOsmLoginListener,
OsmAuthorizationListener {
private static final Log log = PlatformUtil.getLog(OsmEditingFragment.class);
private static final String OSM_LOGOUT = "osm_logout";
private static final String OPEN_OSM_EDITS = "open_osm_edits";
private static final String OSM_LOGIN_DATA = "osm_login_data";
public static final String OSM_LOGIN_DATA = "osm_login_data";
private static final String OSM_EDITING_INFO = "osm_editing_info";
private OsmOAuthAuthorizationAdapter authorizationAdapter;
@ -48,7 +49,7 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
}
@Override
@ -176,7 +177,6 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
settings.USER_ACCESS_TOKEN_SECRET.resetToDefault();
authorizationAdapter.resetToken();
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
} else {
settings.USER_NAME.resetToDefault();
settings.USER_PASSWORD.resetToDefault();
@ -195,7 +195,6 @@ public class OsmEditingFragment extends BaseSettingsFragment implements OnPrefer
@Override
public void authorizationCompleted() {
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
updateAllSettings();
}
}

View file

@ -224,7 +224,7 @@ public class OsmEditingPlugin extends OsmandPlugin {
editPoiDialogFragment.show(mapActivity.getSupportFragmentManager(),
EditPoiDialogFragment.TAG);
} else if (resId == R.string.context_menu_item_open_note) {
openOsmNote(mapActivity, latitude, longitude);
openOsmNote(mapActivity, latitude, longitude, "", false);
} else if (resId == R.string.context_menu_item_modify_note) {
modifyOsmNote(mapActivity, (OsmNotesPoint) selectedObj);
} else if (resId == R.string.poi_context_menu_modify) {
@ -295,13 +295,6 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
}
public void openOsmNote(MapActivity mapActivity, double latitude, double longitude) {
if (osmBugsLayer == null) {
registerLayers(mapActivity);
}
osmBugsLayer.openBug(latitude, longitude, "");
}
public void openOsmNote(MapActivity mapActivity, double latitude, double longitude, String message, boolean autofill) {
if (osmBugsLayer == null) {
registerLayers(mapActivity);

View file

@ -43,6 +43,8 @@ import net.osmand.osm.edit.Node;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.measurementtool.LoginBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendOsmNoteBottomSheetFragment;
import net.osmand.plus.osmedit.dialogs.SendPoiBottomSheetFragment;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
@ -621,28 +623,42 @@ public class OsmEditsFragment extends OsmAndListFragment implements SendPoiDialo
return info;
}
public OsmandApplication getMyApplication() {
return (OsmandApplication) getActivity().getApplication();
}
private void uploadItems(final OsmPoint[] items) {
private void uploadItems(final OsmPoint[] points) {
FragmentActivity activity = getActivity();
if (activity != null) {
OsmandApplication app = getMyApplication();
OsmandSettings settings = app.getSettings();
OsmOAuthAuthorizationAdapter authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
if (authorizationAdapter.isValidToken()
OsmOAuthAuthorizationAdapter authorizationAdapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
boolean isLogged = authorizationAdapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get())) {
SendPoiDialogFragment.createInstance(items, PoiUploaderType.FRAGMENT)
.show(getChildFragmentManager(), SendPoiDialogFragment.TAG);
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
if (hasPoiGroup(points)) {
if (isLogged) {
SendPoiBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points);
} else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
}
} else {
LoginBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), this);
SendOsmNoteBottomSheetFragment.showInstance(activity.getSupportFragmentManager(), points);
}
}
}
boolean hasPoiGroup(OsmPoint[] points) {
boolean hasPoiGroup = false;
for (OsmPoint p : points) {
if (p.getGroup() == OsmPoint.Group.POI) {
hasPoiGroup = true;
break;
}
}
return hasPoiGroup;
}
public void showProgressDialog(OsmPoint[] points, boolean closeChangeSet, boolean anonymously) {
ProgressDialogFragment dialog = ProgressDialogFragment.createInstance(
R.string.uploading,

View file

@ -0,0 +1,117 @@
package net.osmand.plus.osmedit.dialogs;
import android.content.res.ColorStateList;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.textfield.TextInputEditText;
import com.google.android.material.textfield.TextInputLayout;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerSpaceItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.osmedit.HandleOsmNoteAsyncTask;
import net.osmand.plus.osmedit.OsmBugsLayer;
import net.osmand.plus.osmedit.OsmBugsUtil;
import net.osmand.plus.osmedit.OsmNotesPoint;
import net.osmand.plus.osmedit.OsmPoint;
import org.apache.commons.logging.Log;
public class BugBottomSheetDialog extends MenuBottomSheetDialogFragment {
public static final String TAG = BugBottomSheetDialog.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(BugBottomSheetDialog.class);
private OsmBugsUtil osmBugsUtil;
private OsmBugsUtil local;
private String text;
private int titleTextId;
private int posButtonTextId;
private OsmPoint.Action action;
private OsmBugsLayer.OpenStreetNote bug;
private OsmNotesPoint point;
private HandleOsmNoteAsyncTask.HandleBugListener handleBugListener;
private TextInputEditText noteText;
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
items.add(new TitleItem(getString(titleTextId)));
View osmNoteView = View.inflate(UiUtilities.getThemedContext(app, nightMode),
R.layout.track_name_edit_text, null);
TextInputLayout textBox = osmNoteView.findViewById(R.id.name_text_box);
int highlightColorId = nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light;
textBox.setBoxBackgroundColorResource(highlightColorId);
textBox.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
ColorStateList colorStateList = ColorStateList.valueOf(ContextCompat
.getColor(app, nightMode ? R.color.text_color_secondary_dark : R.color.text_color_secondary_light));
textBox.setDefaultHintTextColor(colorStateList);
noteText = osmNoteView.findViewById(R.id.name_edit_text);
noteText.setText(text);
BaseBottomSheetItem editOsmNote = new BaseBottomSheetItem.Builder()
.setCustomView(osmNoteView)
.create();
items.add(editOsmNote);
items.add(new DividerSpaceItem(app, app.getResources().getDimensionPixelSize(R.dimen.content_padding_small)));
}
@Override
protected int getRightBottomButtonTextId() {
return posButtonTextId;
}
@Override
protected void onRightBottomButtonClick() {
new HandleOsmNoteAsyncTask(osmBugsUtil, local, bug, point, noteText.getText().toString(), action,
handleBugListener).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
dismiss();
}
@Override
protected int getBgColorId() {
return nightMode ? R.color.activity_background_color_dark : R.color.list_background_color_light;
}
public static void showInstance(@NonNull FragmentManager fm, OsmBugsUtil osmBugsUtil, OsmBugsUtil local,
String text, int titleTextId, int posButtonTextId, final OsmPoint.Action action,
final OsmBugsLayer.OpenStreetNote bug, final OsmNotesPoint point,
HandleOsmNoteAsyncTask.HandleBugListener handleBugListener) {
try {
if (!fm.isStateSaved()) {
BugBottomSheetDialog fragment = new BugBottomSheetDialog();
fragment.setRetainInstance(true);
fragment.osmBugsUtil = osmBugsUtil;
fragment.local = local;
fragment.text = text;
fragment.titleTextId = titleTextId;
fragment.posButtonTextId = posButtonTextId;
fragment.action = action;
fragment.bug = bug;
fragment.point = point;
fragment.handleBugListener = handleBugListener;
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}

View file

@ -0,0 +1,201 @@
package net.osmand.plus.osmedit.dialogs;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentManager;
import com.google.android.material.textfield.TextInputLayout;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.DialogButtonType;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.osmedit.OsmNotesPoint;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.oauth.OsmOAuthAuthorizationAdapter;
import net.osmand.plus.osmedit.oauth.OsmOAuthHelper.OsmAuthorizationListener;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.bottomsheets.OsmLoginDataBottomSheet;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import static net.osmand.plus.UiUtilities.setupDialogButton;
import static net.osmand.plus.osmedit.OsmEditingFragment.OSM_LOGIN_DATA;
import static net.osmand.plus.osmedit.ValidateOsmLoginDetailsTask.*;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*;
public class SendOsmNoteBottomSheetFragment extends MenuBottomSheetDialogFragment implements ValidateOsmLoginListener,
OsmAuthorizationListener {
public static final String TAG = SendOsmNoteBottomSheetFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SendOsmNoteBottomSheetFragment.class);
private OsmPoint[] poi;
protected OsmandSettings settings;
private TextView accountName;
private LinearLayout accountBlockView;
private LinearLayout signInView;
private SwitchCompat uploadAnonymously;
private OsmandApplication app;
private boolean isLoginOAuth() {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
app = getMyApplication();
if (app == null) {
return;
}
settings = app.getSettings();
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
items.add(new TitleItem(getString(R.string.upload_osm_note)));
final View sendOsmNoteView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_osm_note_fragment, null);
TextView noteText = sendOsmNoteView.findViewById(R.id.note_text);
noteText.setText(((OsmNotesPoint) poi[0]).getText());
TextInputLayout noteHint = sendOsmNoteView.findViewById(R.id.note_hint);
noteHint.setHint(AndroidUtils.addColon(app, R.string.osn_bug_name));
accountBlockView = sendOsmNoteView.findViewById(R.id.account_container);
signInView = sendOsmNoteView.findViewById(R.id.sign_in_container);
uploadAnonymously = sendOsmNoteView.findViewById(R.id.upload_anonymously_switch);
accountName = sendOsmNoteView.findViewById(R.id.user_name);
updateAccountName();
View signInButton = sendOsmNoteView.findViewById(R.id.sign_in_button);
setupButton(signInButton, R.string.sign_in_with_open_street_map, DialogButtonType.PRIMARY,
R.drawable.ic_action_openstreetmap_logo);
signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = requiredMyApplication();
app.getOsmOAuthHelper().startOAuth((ViewGroup) v);
}
});
View loginButton = sendOsmNoteView.findViewById(R.id.login_button);
setupButton(loginButton, R.string.use_login_password, DialogButtonType.SECONDARY, -1);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
OsmLoginDataBottomSheet.showInstance(fragmentManager, OSM_LOGIN_DATA,
SendOsmNoteBottomSheetFragment.this, usedOnMap, null);
}
}
});
updateSignIn(uploadAnonymously.isChecked());
uploadAnonymously.setBackgroundResource(nightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0);
uploadAnonymously.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
updateSignIn(isChecked);
if (nightMode) {
uploadAnonymously.setBackgroundResource(
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
} else {
uploadAnonymously.setBackgroundResource(
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
uploadAnonymously.setPadding(paddingSmall, 0, paddingSmall, 0);
}
});
final SimpleBottomSheetItem bottomSheetItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmNoteView)
.create();
items.add(bottomSheetItem);
}
private void updateAccountName() {
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userName = isLoginOAuth() ? userNameOAuth : userNameOpenID;
accountName.setText(userName);
updateSignIn(uploadAnonymously.isChecked());
}
private void updateSignIn(boolean isChecked) {
boolean isLogged = isLogged();
accountBlockView.setVisibility(isChecked || !isLogged ? View.GONE : View.VISIBLE);
signInView.setVisibility(isChecked || isLogged ? View.GONE : View.VISIBLE);
}
private void setupButton(View buttonView, int buttonTextId, DialogButtonType buttonType, int drawableId) {
Drawable icon = null;
if (drawableId != -1) {
icon = app.getUIUtilities().getIcon(drawableId, R.color.popup_text_color);
}
TextView buttonText = buttonView.findViewById(R.id.button_text);
AndroidUtils.setCompoundDrawablesWithIntrinsicBounds(buttonText, icon, null, null, null);
setupDialogButton(nightMode, buttonView, buttonType, buttonTextId);
}
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
try {
if (!fm.isStateSaved()) {
SendOsmNoteBottomSheetFragment fragment = new SendOsmNoteBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points);
fragment.setArguments(bundle);
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
@Override
protected DialogButtonType getRightBottomButtonType() {
return (DialogButtonType.PRIMARY);
}
@Override
protected void onRightBottomButtonClick() {
ProgressDialogPoiUploader progressDialogPoiUploader;
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity());
progressDialogPoiUploader.showProgressDialog(poi, false, uploadAnonymously.isChecked());
dismiss();
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_upload;
}
@Override
public void authorizationCompleted() {
updateAccountName();
}
@Override
public void loginValidationFinished(String warning) {
updateAccountName();
}
private boolean isLogged() {
OsmOAuthAuthorizationAdapter adapter = app.getOsmOAuthHelper().getAuthorizationAdapter();
return adapter.isValidToken()
|| !Algorithms.isEmpty(settings.USER_NAME.get())
&& !Algorithms.isEmpty(settings.USER_PASSWORD.get());
}
}

View file

@ -0,0 +1,235 @@
package net.osmand.plus.osmedit.dialogs;
import android.os.Bundle;
import android.view.ContextThemeWrapper;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.widget.SwitchCompat;
import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.Entity;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.util.HashMap;
import java.util.Map;
import static net.osmand.plus.osmedit.dialogs.SendPoiDialogFragment.*;
public class SendPoiBottomSheetFragment extends MenuBottomSheetDialogFragment {
public static final String TAG = SendPoiBottomSheetFragment.class.getSimpleName();
private static final Log LOG = PlatformUtil.getLog(SendPoiBottomSheetFragment.class);
private OsmPoint[] poi;
private SwitchCompat closeChangeSet;
private EditText messageEditText;
private boolean isLoginOAuth(OsmandSettings settings) {
return !Algorithms.isEmpty(settings.USER_DISPLAY_NAME.get());
}
@Override
public void createMenuItems(Bundle savedInstanceState) {
OsmandApplication app = getMyApplication();
if (app == null) {
return;
}
poi = (OsmPoint[]) getArguments().getSerializable(OPENSTREETMAP_POINT);
final boolean isNightMode = app.getDaynightHelper().isNightModeForMapControls();
final View sendOsmPoiView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.send_poi_fragment, null);
closeChangeSet = sendOsmPoiView.findViewById(R.id.close_change_set_checkbox);
messageEditText = sendOsmPoiView.findViewById(R.id.message_field);
String defaultChangeSet = createDefaultChangeSet(app);
messageEditText.setText(defaultChangeSet);
final TextView accountName = sendOsmPoiView.findViewById(R.id.user_name);
OsmandSettings settings = app.getSettings();
String userNameOAuth = settings.USER_DISPLAY_NAME.get();
String userNameOpenID = settings.USER_NAME.get();
String userName = isLoginOAuth(settings) ? userNameOAuth : userNameOpenID;
accountName.setText(userName);
closeChangeSet.setBackgroundResource(isNightMode ? R.drawable.layout_bg_dark : R.drawable.layout_bg);
final int paddingSmall = app.getResources().getDimensionPixelSize(R.dimen.content_padding_small);
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
closeChangeSet.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isNightMode) {
closeChangeSet.setBackgroundResource(
isChecked ? R.drawable.layout_bg_dark_solid : R.drawable.layout_bg_dark);
} else {
closeChangeSet.setBackgroundResource(
isChecked ? R.drawable.layout_bg_solid : R.drawable.layout_bg);
}
closeChangeSet.setPadding(paddingSmall, 0, paddingSmall, 0);
}
});
final SimpleBottomSheetItem titleItem = (SimpleBottomSheetItem) new SimpleBottomSheetItem.Builder()
.setCustomView(sendOsmPoiView)
.create();
items.add(titleItem);
}
public static void showInstance(@NonNull FragmentManager fm, @NonNull OsmPoint[] points) {
try {
if (!fm.isStateSaved()) {
SendPoiBottomSheetFragment fragment = new SendPoiBottomSheetFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, points);
fragment.setArguments(bundle);
fragment.show(fm, TAG);
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
@Override
protected UiUtilities.DialogButtonType getRightBottomButtonType() {
return (UiUtilities.DialogButtonType.PRIMARY);
}
@Override
protected void onRightBottomButtonClick() {
final ProgressDialogPoiUploader progressDialogPoiUploader;
progressDialogPoiUploader = new SimpleProgressDialogPoiUploader((MapActivity) getActivity());
String comment = messageEditText.getText().toString();
if (comment.length() > 0) {
for (OsmPoint osmPoint : poi) {
if (osmPoint.getGroup() == OsmPoint.Group.POI) {
((OpenstreetmapPoint) osmPoint).setComment(comment);
break;
}
}
}
progressDialogPoiUploader.showProgressDialog(poi, closeChangeSet.isChecked(), false);
dismiss();
}
@Override
protected int getRightBottomButtonTextId() {
return R.string.shared_string_upload;
}
private String createDefaultChangeSet(OsmandApplication app) {
Map<String, PoiType> allTranslatedSubTypes = app.getPoiTypes().getAllTranslatedNames(true);
if (allTranslatedSubTypes == null) {
return "";
}
Map<String, Integer> addGroup = new HashMap<>();
Map<String, Integer> editGroup = new HashMap<>();
Map<String, Integer> deleteGroup = new HashMap<>();
Map<String, Integer> reopenGroup = new HashMap<>();
String comment = "";
for (OsmPoint p : poi) {
if (p.getGroup() == OsmPoint.Group.POI) {
OsmPoint.Action action = p.getAction();
String type = ((OpenstreetmapPoint) p).getEntity().getTag(Entity.POI_TYPE_TAG);
if (type == null) {
continue;
}
PoiType localizedPoiType = allTranslatedSubTypes.get(type.toLowerCase().trim());
if (localizedPoiType != null) {
type = Algorithms.capitalizeFirstLetter(localizedPoiType.getKeyName().replace('_', ' '));
}
if (action == OsmPoint.Action.CREATE) {
if (!addGroup.containsKey(type)) {
addGroup.put(type, 1);
} else {
addGroup.put(type, addGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.MODIFY) {
if (!editGroup.containsKey(type)) {
editGroup.put(type, 1);
} else {
editGroup.put(type, editGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.DELETE) {
if (!deleteGroup.containsKey(type)) {
deleteGroup.put(type, 1);
} else {
deleteGroup.put(type, deleteGroup.get(type) + 1);
}
} else if (action == OsmPoint.Action.REOPEN) {
if (!reopenGroup.containsKey(type)) {
reopenGroup.put(type, 1);
} else {
reopenGroup.put(type, reopenGroup.get(type) + 1);
}
}
}
}
int modifiedItemsOutOfLimit = 0;
for (int i = 0; i < 4; i++) {
String action;
Map<String, Integer> group;
switch (i) {
case 0:
action = getString(R.string.default_changeset_add);
group = addGroup;
break;
case 1:
action = getString(R.string.default_changeset_edit);
group = editGroup;
break;
case 2:
action = getString(R.string.default_changeset_delete);
group = deleteGroup;
break;
case 3:
action = getString(R.string.default_changeset_reopen);
group = reopenGroup;
break;
default:
action = "";
group = new HashMap<>();
}
if (!group.isEmpty()) {
int pos = 0;
for (Map.Entry<String, Integer> entry : group.entrySet()) {
String type = entry.getKey();
int quantity = entry.getValue();
if (comment.length() > 200) {
modifiedItemsOutOfLimit += quantity;
} else {
if (pos == 0) {
comment = comment.concat(comment.length() == 0 ? "" : "; ").concat(action).concat(" ")
.concat(quantity == 1 ? "" : quantity + " ").concat(type);
} else {
comment = comment.concat(", ").concat(quantity == 1 ? "" : quantity + " ").concat(type);
}
}
pos++;
}
}
}
if (modifiedItemsOutOfLimit != 0) {
comment = comment.concat("; ").concat(modifiedItemsOutOfLimit + " ")
.concat(getString(R.string.items_modified)).concat(".");
} else if (!comment.equals("")) {
comment = comment.concat(".");
}
return comment;
}
}

View file

@ -0,0 +1,61 @@
package net.osmand.plus.osmedit.oauth;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.util.concurrent.ExecutionException;
public class OsmOAuthHelper {
private static final Log log = PlatformUtil.getLog(OsmOAuthHelper.class);
private final OsmandApplication app;
private final OsmOAuthAuthorizationAdapter authorizationAdapter;
public OsmOAuthHelper(@NonNull OsmandApplication app) {
this.app = app;
authorizationAdapter = new OsmOAuthAuthorizationAdapter(app);
}
public void startOAuth(ViewGroup view) {
authorizationAdapter.startOAuth(view);
}
public void authorize(String oauthVerifier) {
authorizationAdapter.authorize(oauthVerifier);
updateUserName();
}
public OsmOAuthAuthorizationAdapter getAuthorizationAdapter() {
return authorizationAdapter;
}
private void updateUserName() {
String userName = "";
try {
userName = authorizationAdapter.getUserName();
} catch (InterruptedException e) {
log.error(e);
} catch (ExecutionException e) {
log.error(e);
} catch (IOException e) {
log.error(e);
} catch (XmlPullParserException e) {
log.error(e);
}
app.getSettings().USER_DISPLAY_NAME.set(userName);
}
public interface OsmAuthorizationListener {
void authorizationCompleted();
}
}