Merge pull request #10178 from osmandapp/issue_251_add_photo_button_opr

Issue 251 OPR UI Add photo button and start screen with webview
This commit is contained in:
Vitaliy 2020-11-13 15:06:28 +00:00 committed by GitHub
commit bc211b7a45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 432 additions and 33 deletions

View file

@ -66,6 +66,7 @@
<meta-data android:name="com.sec.minimode.icon.landscape.normal" android:resource="@mipmap/icon" android:value="" />
<activity android:name="net.osmand.plus.activities.HelpActivity" />
<activity android:name="net.osmand.plus.activities.ExitActivity" />
<activity android:name="net.osmand.plus.openplacereviews.OPRWebviewActivity" android:theme="@style/Theme.AppCompat.NoActionBar" />
<provider
android:name="androidx.core.content.FileProvider"

View file

@ -206,11 +206,13 @@ android {
buildTypes {
debug {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
buildConfigField "String", "OSM_OAUTH_CONSUMER_KEY", "\"Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y\""
buildConfigField "String", "OSM_OAUTH_CONSUMER_SECRET", "\"lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM\""
signingConfig signingConfigs.development
}
release {
buildConfigField "String", "OPR_BASE_URL", "\"https://test.openplacereviews.org/\""
buildConfigField "String", "OSM_OAUTH_CONSUMER_KEY", "\"Ti2qq3fo4i4Wmuox3SiWRIGq3obZisBHnxmcM05y\""
buildConfigField "String", "OSM_OAUTH_CONSUMER_SECRET", "\"lxulb3HYoMmd2cC4xxNe1dyfRMAY8dS0eNihJ0DM\""
if (gradle.startParameter.taskNames.toString().contains("huawei")) {

View file

@ -0,0 +1,36 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="72dp"
android:height="63dp"
android:viewportWidth="72"
android:viewportHeight="63">
<path
android:pathData="M49.5,0C47.0147,0 45,2.0147 45,4.5C45,6.9853 47.0147,9 49.5,9H67.5C69.9853,9 72,6.9853 72,4.5C72,2.0147 69.9853,0 67.5,0H49.5Z"
android:fillColor="#8AC826"/>
<path
android:pathData="M67.5,54C69.9853,54 72,56.0147 72,58.5C72,60.9853 69.9853,63 67.5,63H58.5C56.0147,63 54,60.9853 54,58.5C54,56.0147 56.0147,54 58.5,54H67.5Z"
android:fillColor="#8AC826"/>
<path
android:pathData="M72,22.5C72,20.0147 69.9853,18 67.5,18H54C51.5147,18 49.5,20.0147 49.5,22.5C49.5,24.9853 51.5147,27 54,27H67.5C69.9853,27 72,24.9853 72,22.5Z"
android:fillColor="#8AC826"/>
<path
android:pathData="M67.5,36C69.9853,36 72,38.0147 72,40.5C72,42.9853 69.9853,45 67.5,45H45C42.5147,45 40.5,42.9853 40.5,40.5C40.5,38.0147 42.5147,36 45,36H67.5Z"
android:fillColor="#8AC826"/>
<path
android:pathData="M22.5,4.5C22.5,2.0147 24.5147,0 27,0H36C38.4853,0 40.5,2.0147 40.5,4.5C40.5,6.9853 38.4853,9 36,9H27C24.5147,9 22.5,6.9853 22.5,4.5Z"
android:fillColor="#FFC93A"/>
<path
android:pathData="M45,22.5C45,20.0147 42.9853,18 40.5,18H31.5C29.0147,18 27,20.0147 27,22.5C27,24.9853 29.0147,27 31.5,27H40.5C42.9853,27 45,24.9853 45,22.5Z"
android:fillColor="#FFC93A"/>
<path
android:pathData="M31.5,36C33.9853,36 36,38.0147 36,40.5C36,42.9853 33.9853,45 31.5,45H18C15.5147,45 13.5,42.9853 13.5,40.5C13.5,38.0147 15.5147,36 18,36H31.5Z"
android:fillColor="#FFC93A"/>
<path
android:pathData="M0,4.5C0,2.0147 2.0147,0 4.5,0H13.5C15.9853,0 18,2.0147 18,4.5C18,6.9853 15.9853,9 13.5,9H4.5C2.0147,9 0,6.9853 0,4.5Z"
android:fillColor="#140579"/>
<path
android:pathData="M22.5,22.5C22.5,20.0147 20.4853,18 18,18H4.5C2.0147,18 0,20.0147 0,22.5C0,24.9853 2.0147,27 4.5,27H18C20.4853,27 22.5,24.9853 22.5,22.5Z"
android:fillColor="#140579"/>
<path
android:pathData="M4.5,36C6.9853,36 9,38.0147 9,40.5C9,42.9853 6.9853,45 4.5,45C2.0147,45 0,42.9853 0,40.5C0,38.0147 2.0147,36 4.5,36Z"
android:fillColor="#140579"/>
</vector>

View file

@ -0,0 +1,13 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,4C6,2.8954 6.8954,2 8,2H20C21.1046,2 22,2.8954 22,4V16C22,17.1046 21.1046,18 20,18H8C6.8954,18 6,17.1046 6,16V4ZM15,6H13V9H10V11H13V14H15V11H18V9H15V6Z"
android:fillColor="#237BFF"
android:fillType="evenOdd"/>
<path
android:pathData="M2,6H4V20H18V22H4C2.8954,22 2,21.1046 2,20V6Z"
android:fillColor="#237BFF"/>
</vector>

View file

@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:background="@color/color_white"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:background="@color/color_white"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="56dp">
<TextView
android:id="@+id/toolbar_text"
android:textSize="20sp"
tools:text="demdadao"
android:textColor="@color/color_black"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.AppBarLayout>
<WebView
android:id="@+id/printDialogWebview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

View file

@ -0,0 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:background="@color/color_white"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" android:orientation="vertical"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="56dp"
android:layout_marginTop="@dimen/dialog_content_margin">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/back_button"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:contentDescription="@string/shared_string_back"
app:tint="@color/icon_color_default_light"
app:srcCompat="@drawable/ic_arrow_back"/>
</LinearLayout>
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/opr_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:contentDescription="@string/shared_string_back"
app:srcCompat="@drawable/ic_img_logo_openplacereview"/>
<androidx.appcompat.widget.AppCompatTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:textColor="@color/color_black"
android:textSize="20sp"
android:lineSpacingExtra="5sp"
android:textAlignment="center"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginTop="@dimen/content_padding"
android:layout_marginBottom="@dimen/dashPadding"
android:text="@string/register_on_openplacereviews"
android:gravity="center_horizontal"/>
<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/start_opr_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dashPadding"
android:layout_marginLeft="@dimen/content_padding"
android:lineSpacingExtra="5sp"
android:textColor="@color/color_black"
android:textColorLink="@color/icon_color_active_light"
android:layout_marginRight="@dimen/content_padding"
android:text="@string/register_on_openplacereviews_desc"/>
<LinearLayout
android:gravity="bottom"
android:orientation="vertical"
android:layout_marginBottom="@dimen/content_padding_small"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/register_opr_create_account"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/dashPadding"
android:text="@string/register_opr_create_new_account"
android:textColor="@color/color_white"
android:layout_marginTop="@dimen/content_padding_small"
android:background="@color/icon_color_active_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/register_opr_have_account"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginTop="@dimen/dashPadding"
android:layout_gravity="bottom"
android:text="@string/register_opr_have_account"
android:textColor="@color/icon_color_active_light"
android:background="@color/activity_background_color_light"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>

View file

@ -11,6 +11,11 @@
Thx - Hardy
-->
<string name="register_opr_have_account">I already have an account</string>
<string name="register_opr_create_new_account">Create new account</string>
<string name="register_on_openplacereviews_desc">Photos are provided by open data project OpenPlaceReviews.org. In order to upload your photos you need to sign up on website.</string>
<string name="register_on_openplacereviews">Register on\nOpenPlaceReviews.org</string>
<string name="shared_string_add_photo">Add photo</string>
<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>

View file

@ -8,6 +8,7 @@ import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.net.Uri;
@ -25,26 +26,18 @@ import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.view.ContextThemeWrapper;
import androidx.core.content.ContextCompat;
import androidx.core.graphics.drawable.DrawableCompat;
import net.osmand.AndroidUtils;
import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.*;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.FontCache;
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
@ -53,6 +46,7 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.openplacereviews.OprStartFragment;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.render.RenderingIcons;
import net.osmand.plus.transport.TransportStopRoute;
@ -63,13 +57,7 @@ import net.osmand.plus.widgets.tools.ClickableSpanTouchListener;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
import static net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
@ -77,7 +65,7 @@ public class MenuBuilder {
public static final float SHADOW_HEIGHT_TOP_DP = 17f;
public static final int TITLE_LIMIT = 60;
protected static final String[] arrowChars = new String[]{"=>"," - "};
protected static final String[] arrowChars = new String[] {"=>", " - "};
protected MapActivity mapActivity;
protected MapContextMenu mapContextMenu;
@ -254,7 +242,7 @@ public class MenuBuilder {
protected boolean needBuildPlainMenuItems() {
return true;
}
protected boolean needBuildCoordinatesRow() {
return true;
}
@ -282,7 +270,7 @@ public class MenuBuilder {
protected void buildNearestWikiRow(View view) {
if (processNearestWiki() && nearestWiki.size() > 0) {
buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size()+")", 0,
buildRow(view, R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", 0,
true, getCollapsableWikiView(view.getContext(), true),
false, 0, false, null, false);
}
@ -296,7 +284,14 @@ public class MenuBuilder {
boolean needUpdateOnly = onlinePhotoCardsRow != null && onlinePhotoCardsRow.getMenuBuilder() == this;
onlinePhotoCardsRow = new CardsRowBuilder(this, view, false);
onlinePhotoCardsRow.build();
CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(), this,
LinearLayout parent = new LinearLayout(view.getContext());
parent.setLayoutParams(
new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
parent.setOrientation(LinearLayout.VERTICAL);
parent.addView(onlinePhotoCardsRow.getContentView());
parent.addView(createAddPhotoButton(view.getContext()));
CollapsableView collapsableView = new CollapsableView(parent, this,
app.getSettings().ONLINE_PHOTOS_ROW_COLLAPSED);
collapsableView.setCollapseExpandListener(new CollapseExpandListener() {
@Override
@ -316,15 +311,44 @@ public class MenuBuilder {
}
}
private View createAddPhotoButton(Context context) {
TextView b = new TextView(context);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
OprStartFragment.showInstance(mapActivity.getSupportFragmentManager());
}
});
b.setTypeface(FontCache.getRobotoRegular(context));
Drawable d = ContextCompat.getDrawable(context, R.drawable.ic_sample);
b.setCompoundDrawablesWithIntrinsicBounds(d, null, null, null);
LinearLayout.LayoutParams params = new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
int dp16 = AndroidUtils.dpToPx(context, 16f);
int dp8 = AndroidUtils.dpToPx(context, 8f);
params.setMargins(dp16, 0, dp16, dp16);
b.setPadding(dp8, dp8, dp16, dp8);
b.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
b.setLayoutParams(params);
b.setCompoundDrawablePadding(dp8);
b.setGravity(Gravity.CENTER_VERTICAL);
b.setTypeface(null, Typeface.BOLD);
b.setText(context.getResources().getString(R.string.shared_string_add_photo));
b.setBackgroundResource(R.drawable.btn_border_light);
b.setTextColor(ContextCompat.getColor(context, R.color.preference_category_title));
return b;
}
private void buildCoordinatesRow(View view) {
Map<Integer, String> locationData = PointDescription.getLocationData(mapActivity, latLon.getLatitude(), latLon.getLongitude(), true);
String title = locationData.get(PointDescription.LOCATION_LIST_HEADER);
locationData.remove(PointDescription.LOCATION_LIST_HEADER);
CollapsableView cv = getLocationCollapsableView(locationData);
buildRow(view, R.drawable.ic_action_get_my_location, null, title, 0, true, cv, false, 1,
false, null, false);
false, null, false);
}
private void startLoadingImages() {
if (onlinePhotoCardsRow == null) {
return;
@ -379,7 +403,7 @@ public class MenuBuilder {
}
}
protected void buildDescription(View view){
protected void buildDescription(View view) {
}
protected void buildAfter(View view) {
@ -395,8 +419,8 @@ public class MenuBuilder {
}
public View buildRow(View view, int iconId, String buttonText, String text, int textColor,
boolean collapsable, final CollapsableView collapsableView,
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
boolean collapsable, final CollapsableView collapsableView,
boolean needLinks, int textLinesLimit, boolean isUrl, OnClickListener onClickListener, boolean matchWidthDivider) {
return buildRow(view, iconId == 0 ? null : getRowIcon(iconId), buttonText, text, textColor, null, collapsable, collapsableView,
needLinks, textLinesLimit, isUrl, onClickListener, matchWidthDivider);
}
@ -480,7 +504,7 @@ public class MenuBuilder {
textPrefixView.setLayoutParams(llTextParams);
textPrefixView.setTypeface(FontCache.getRobotoRegular(view.getContext()));
textPrefixView.setTextSize(12);
textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark));
textPrefixView.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark));
textPrefixView.setMinLines(1);
textPrefixView.setMaxLines(1);
textPrefixView.setText(textPrefix);
@ -526,7 +550,7 @@ public class MenuBuilder {
textViewSecondary.setLayoutParams(llTextSecondaryParams);
textViewSecondary.setTypeface(FontCache.getRobotoRegular(view.getContext()));
textViewSecondary.setTextSize(14);
textViewSecondary.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light: R.color.text_color_secondary_dark));
textViewSecondary.setTextColor(app.getResources().getColor(light ? R.color.text_color_secondary_light : R.color.text_color_secondary_dark));
textViewSecondary.setText(secondaryText);
llText.addView(textViewSecondary);
}
@ -581,7 +605,7 @@ public class MenuBuilder {
}
if (collapsableView.getContentView().getParent() != null) {
((ViewGroup) collapsableView.getContentView().getParent())
.removeView(collapsableView.getContentView());
.removeView(collapsableView.getContentView());
}
baseView.addView(collapsableView.getContentView());
}
@ -682,7 +706,7 @@ public class MenuBuilder {
ssb.append("UTM: ");
} else if (line.getKey() == OsmAndFormatter.MGRS_FORMAT) {
ssb.append("MGRS: ");
} else if (line.getKey() == OsmAndFormatter.OLC_FORMAT){
} else if (line.getKey() == OsmAndFormatter.OLC_FORMAT) {
ssb.append("OLC: ");
}
ssb.setSpan(new ForegroundColorSpan(app.getResources().getColor(R.color.text_color_secondary_light)), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
@ -747,8 +771,8 @@ public class MenuBuilder {
}
public void addPlainMenuItem(int iconId, String text, boolean needLinks, boolean isUrl,
boolean collapsable, CollapsableView collapsableView,
OnClickListener onClickListener) {
boolean collapsable, CollapsableView collapsableView,
OnClickListener onClickListener) {
plainMenuItems.add(new PlainMenuItem(iconId, null, text, needLinks, isUrl, collapsable, collapsableView, onClickListener));
}
@ -970,7 +994,7 @@ public class MenuBuilder {
button.setTypeface(FontCache.getRobotoRegular(context));
int bg;
if (selected) {
bg = light ? R.drawable.context_menu_controller_bg_light_selected: R.drawable.context_menu_controller_bg_dark_selected;
bg = light ? R.drawable.context_menu_controller_bg_light_selected : R.drawable.context_menu_controller_bg_dark_selected;
} else if (showAll) {
bg = light ? R.drawable.context_menu_controller_bg_light_show_all : R.drawable.context_menu_controller_bg_dark_show_all;
} else {
@ -1027,7 +1051,7 @@ public class MenuBuilder {
private List<Amenity> getAmenities(QuadRect rect, PoiUIFilter wikiPoiFilter) {
return wikiPoiFilter.searchAmenities(rect.top, rect.left,
rect.bottom, rect.right, -1, null);
rect.bottom, rect.right, -1, null);
}
@SuppressWarnings("unchecked")

View file

@ -0,0 +1,97 @@
package net.osmand.plus.openplacereviews;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.BuildConfig;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class OPRWebviewActivity extends OsmandActionBarActivity {
public static final String KEY_LOGIN = "LOGIN_KEY";
private static final String url = BuildConfig.OPR_BASE_URL;
private static final String cookieUrl = BuildConfig.OPR_BASE_URL + "profile";
private static final String loginUrl = BuildConfig.OPR_BASE_URL + "login";
private static final String registerUrl = BuildConfig.OPR_BASE_URL + "signup";
private static final String finishUrl = cookieUrl;
public static String KEY_TITLE = "TITLE_KEY";
private WebView webView;
private boolean isLogin = false;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_opr_webview);
Bundle b = getIntent().getExtras();
setSupportActionBar(this.<Toolbar>findViewById(R.id.toolbar));
if (b != null) {
String title = b.getString(KEY_TITLE, "");
this.<TextView>findViewById(R.id.toolbar_text).setText(title);
}
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
final Drawable upArrow = getMyApplication().getUIUtilities().getIcon(AndroidUtils.getNavigationIconResId(this));
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
webView = (WebView) findViewById(R.id.printDialogWebview);
webView.setWebViewClient(new CloseOnSuccessWebViewClient());
webView.getSettings().setJavaScriptEnabled(true);
WebView.setWebContentsDebuggingEnabled(true);
if (b != null) {
isLogin = b.getBoolean(KEY_LOGIN);
if (isLogin) {
webView.loadUrl(loginUrl);
} else {
webView.loadUrl(registerUrl);
}
}
}
@Override
public boolean onSupportNavigateUp() {
onBackPressed();
return true;
}
public static String getPrivateKeyFromCookie() {
return returnCookieByKey("opr-token");
}
public static String getUsernameFromCookie() {
return returnCookieByKey("opr-nickname");
}
private static String returnCookieByKey(String key) {
String CookieValue = null;
CookieManager cookieManager = CookieManager.getInstance();
String cookies = cookieManager.getCookie(cookieUrl);
if (cookies == null || cookies.isEmpty()) {
return "";
}
String[] temp = cookies.split(";");
for (String ar1 : temp) {
if (ar1.contains(key)) {
String[] temp1 = ar1.split("=");
CookieValue = temp1[1];
break;
}
}
return CookieValue;
}
public class CloseOnSuccessWebViewClient extends WebViewClient {
@Override
public void onPageFinished(WebView view, String url) {
if (url.contains(finishUrl) && isLogin) {
finish();
}
super.onPageFinished(view, url);
}
}
}

View file

@ -0,0 +1,93 @@
package net.osmand.plus.openplacereviews;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentManager;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import org.apache.commons.logging.Log;
public class OprStartFragment extends BaseOsmAndFragment {
private static final String TAG = "fragment_oprstart";
private static final Log LOG = PlatformUtil.getLog(OprStartFragment.class);
private static final String openPlaceReviewsUrl = "OpenPlaceReviews.org";
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_opr_login, container, false);
v.findViewById(R.id.register_opr_create_account).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(requireContext(), OPRWebviewActivity.class);
i.putExtra(OPRWebviewActivity.KEY_TITLE, getString(R.string.register_opr_create_new_account));
i.putExtra(OPRWebviewActivity.KEY_LOGIN, false);
startActivity(i);
}
});
v.findViewById(R.id.back_button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
getActivity().getSupportFragmentManager().popBackStack();
}
});
v.findViewById(R.id.register_opr_have_account).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(requireContext(), OPRWebviewActivity.class);
i.putExtra(OPRWebviewActivity.KEY_TITLE, getString(R.string.user_login));
i.putExtra(OPRWebviewActivity.KEY_LOGIN, true);
startActivity(i);
}
});
setURLSpan(v);
return v;
}
private void setURLSpan(View v) {
String desc = requireContext().getString(R.string.register_on_openplacereviews_desc);
SpannableString ss = new SpannableString(desc);
ss.setSpan(new URLSpanNoUnderline("https://" + openPlaceReviewsUrl), desc.indexOf(openPlaceReviewsUrl),
desc.indexOf(openPlaceReviewsUrl) + openPlaceReviewsUrl.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
v.<TextView>findViewById(R.id.start_opr_description).setText(ss);
v.<TextView>findViewById(R.id.start_opr_description).setMovementMethod(LinkMovementMethod.getInstance());
}
private class URLSpanNoUnderline extends URLSpan {
public URLSpanNoUnderline(String url) {
super(url);
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
}
}
public static void showInstance(@NonNull FragmentManager fm) {
try {
if (fm.findFragmentByTag(OprStartFragment.TAG) == null) {
OprStartFragment fragment = new OprStartFragment();
fm.beginTransaction()
.add(R.id.fragmentContainer, fragment, OprStartFragment.TAG)
.addToBackStack(null).commit();
}
} catch (RuntimeException e) {
LOG.error("showInstance", e);
}
}
}