Skip to content

Commit

Permalink
- redirect mobile facebook web page for login in mobile well
Browse files Browse the repository at this point in the history
  • Loading branch information
kshdreams committed Apr 4, 2019
1 parent c88d3ff commit 2695995
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public void onItemClick(final View view, final int i) {
InstagramLogin.with(getFragmentManager())
.withStartUrl("https://www.instagram.com/accounts/login/")
.withFullScreenMode(true)
.withFullScreenStyle(R.style.AppTheme_FullScreenDialog)
.withClientInfo(InstagramClientInfo.CLIENT_ID,
InstagramClientInfo.REDIRECT_URI)
// .withMinWidth(getActivity().getWindowManager().getDefaultDisplay().getWidth())
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,10 @@
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="AppTheme.FullScreenDialog" parent="Theme.AppCompat.Dialog">
<item name="android:windowIsFloating">false</item>
<item name="android:windowBackground">@android:color/white</item>
</style>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,10 @@ public void onReceiveValue(final Boolean value) {
}
});
instance.flush();
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setTextZoom(100);
webView.getSettings().setJavaScriptEnabled(true);
webView.setBackgroundColor(-1);

webView.setWebViewClient(new WebViewClient() {
public void onPageFinished(WebView webView, String str) {
super.onPageFinished(webView, str);
Expand All @@ -90,6 +90,7 @@ public boolean shouldOverrideUrlLoading(WebView webView, String url) {
return super.shouldOverrideUrlLoading(webView, url);
}
});

webView.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(final View v, final int keyCode, final KeyEvent event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.util.Log;
Expand All @@ -27,6 +29,8 @@ public class InstagramAuthDialogFragment extends AuthDialogFragment<String> {

private static final String EXTRA_FULL_SCREEN_MODE = "full_screen_mode";

private static final String EXTRA_FULL_SCREEN_STYLE_RES = "full_screen_style_res";

private String mClientId;

private String mRedirectUrl;
Expand All @@ -47,6 +51,7 @@ public static InstagramAuthDialogFragment show(FragmentManager fragmentManager,
args.putInt(ARGS_HEIGHT, builder.minHeight);
args.putString(EXTRA_START_URL, builder.startUrl);
args.putBoolean(EXTRA_FULL_SCREEN_MODE, builder.fullScreenMode);
args.putInt(EXTRA_FULL_SCREEN_STYLE_RES, builder.fullScreenStyle);
newDialog.setArguments(args);
newDialog.show(fragmentManager, "auth");
return newDialog;
Expand Down Expand Up @@ -79,6 +84,12 @@ public void onCreate(@Nullable final Bundle savedInstanceState) {
mRedirectUrl = getArguments().getString(EXTRA_REDIRECT_URL);
mStartUrl = getArguments().getString(EXTRA_START_URL);
mFullScreenMode = getArguments().getBoolean(EXTRA_FULL_SCREEN_MODE);
if (mFullScreenMode) {
@StyleRes int fullScreenStyle = getArguments().getInt(EXTRA_FULL_SCREEN_STYLE_RES);
if (fullScreenStyle != -1) {
setStyle(DialogFragment.STYLE_NORMAL, fullScreenStyle);
}
}
}

@Override
Expand Down Expand Up @@ -116,6 +127,11 @@ protected boolean shouldOverrideUrlLoading(final WebView webView, final String u
if (url == null) {
return false;
}
if (url.startsWith("https://www.facebook.com")) {
String newUrl = url.replace("www.facebook.com", "m.facebook.com");
webView.loadUrl(newUrl);
return true;
}
Uri uri = Uri.parse(url);
if (uri.getPathSegments().isEmpty()) {
Log.i(LOG_TAG, "shouldOverrideUrlLoading. instagram home page.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.android.sebiya.net.social.instagram;

import android.support.annotation.StyleRes;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.FragmentManager;
import com.android.sebiya.net.social.AuthCallbacks;
Expand All @@ -26,6 +27,8 @@ public static class Builder {

boolean fullScreenMode;

@StyleRes int fullScreenStyle = -1;

private AuthCallbacks<String> authCallback;

private Builder(FragmentManager fragmentManager) {
Expand Down Expand Up @@ -58,6 +61,11 @@ public Builder withFullScreenMode(boolean fullScreenMode) {
return this;
}

public Builder withFullScreenStyle(@StyleRes int styleRes) {
fullScreenStyle = styleRes;
return this;
}

public DialogFragment show() {
return InstagramAuthDialogFragment.show(fragmentManager, this);
}
Expand Down

0 comments on commit 2695995

Please sign in to comment.