opr start page

This commit is contained in:
simon 2020-11-12 15:42:46 +02:00
parent 221d28567f
commit 1a9e5b13c0
6 changed files with 159 additions and 2 deletions

View file

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

View file

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

View file

@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
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

@ -8,7 +8,8 @@
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="56dp"> android:layout_height="56dp"
android:layout_marginTop="24dp">
<ImageView <ImageView
android:id="@+id/back_button" android:id="@+id/back_button"
@ -47,6 +48,7 @@
<androidx.appcompat.widget.AppCompatTextView <androidx.appcompat.widget.AppCompatTextView
android:id="@+id/start_opr_description"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="6dp" android:layout_marginTop="6dp"
@ -56,7 +58,6 @@
android:textColorLink="@color/icon_color_active_light" android:textColorLink="@color/icon_color_active_light"
android:layout_marginRight="16dp" android:layout_marginRight="16dp"
android:autoLink="all" android:autoLink="all"
android:text="@string/register_on_openplacereviews_desc"/> android:text="@string/register_on_openplacereviews_desc"/>
<LinearLayout <LinearLayout

View file

@ -0,0 +1,94 @@
package net.osmand.plus.openplacereviews;
import android.content.Context;
import android.graphics.PorterDuff;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.widget.Toolbar;
import androidx.core.content.ContextCompat;
import net.osmand.PlatformUtil;
import net.osmand.plus.BuildConfig;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
import org.apache.commons.logging.Log;
public class OPRWebviewActivity extends OsmandActionBarActivity {
public static final String KEY_LOGIN = "LOGIN_KEY";
private WebView webView;
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";
public static String KEY_TITLE = "TITLE_KEY";
private final Log log = PlatformUtil.getLog(OPRWebviewActivity.class);
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 = ContextCompat.getDrawable(this, R.drawable.ic_arrow_back);
upArrow.setColorFilter(ContextCompat.getColor(this, R.color.color_favorite_gray), PorterDuff.Mode.SRC_ATOP);
getSupportActionBar().setHomeAsUpIndicator(upArrow);
webView = (WebView) findViewById(R.id.printDialogWebview);
webView.getSettings().setJavaScriptEnabled(true);
WebView.setWebContentsDebuggingEnabled(true);
if (b != null){
if (b.getBoolean(KEY_LOGIN)){
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;
}
@Override
protected void onDestroy() {
super.onDestroy();
}
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.openplacereviews; package net.osmand.plus.openplacereviews;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -14,6 +15,30 @@ public class OprStartFragment extends BaseOsmAndFragment {
@Override @Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_opr_login, container, false); 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);
}
});
return v; return v;
} }
} }