Skip to content
Snippets Groups Projects
Commit d22216c5 authored by John Carlson's avatar John Carlson
Browse files

Yeah lets try this

parent aa41166e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -19,10 +19,7 @@
android:name=".activity.LaunchActivity"
android:noHistory="true"
android:theme="@android:style/Theme.NoDisplay">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
 
<activity
Loading
Loading
@@ -52,7 +49,13 @@
<activity android:name=".activity.BuildActivity"/>
<activity android:name=".activity.LoadSomeInfoActivity"
android:theme="@style/Activity.Translucent"/>
<activity android:name=".activity.WebviewLoginActivity">
 
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".activity.RoutingActivity"
android:launchMode="singleTask"
Loading
Loading
package com.commit451.gitlab.activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.commit451.gitlab.R;
import java.io.IOException;
import butterknife.Bind;
import butterknife.ButterKnife;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import timber.log.Timber;
/**
* Shows user a WebView for login and intercepts the headers to get the private token. Hmmmm
*/
public class WebviewLoginActivity extends BaseActivity {
@Bind(R.id.webview)
WebView mWebView;
OkHttpClient mOkHttpClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_webview_login);
ButterKnife.bind(this);
WebSettings settings = mWebView.getSettings();
settings.setJavaScriptEnabled(true);
mWebView.setWebViewClient(new YourWebClient());
mOkHttpClient = new OkHttpClient();
mWebView.loadUrl("https://gitlab.com/users/sign_in");
}
// this will be the webclient that will manage the webview
private class YourWebClient extends WebViewClient {
// you want to catch when an URL is going to be loaded
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if(url.contains("/profile/account")) {
Request request = new Request.Builder()
.url(url)
.build();
mOkHttpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Timber.e(e, null);
}
@Override
public void onResponse(Call call, final Response response) {
try {
final String body = response.body().string();
if (body.contains(""))
mWebView.post(new Runnable() {
@Override
public void run() {
mWebView.loadData(body, "text/html", "utf-8");
}
});
} catch (Exception e) {
Timber.e(e, null);
}
}
});
return true;
}
return true;
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"/>
</android.support.design.widget.AppBarLayout>
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment