Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham-jain2 committed Dec 18, 2019
1 parent 5fb80c7 commit b44d236
Show file tree
Hide file tree
Showing 44 changed files with 1,578 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
.idea/vcs.xml
.idea/
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
40 changes: 40 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion 28
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.crinoid.socialloginhelper"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'


implementation 'com.squareup.retrofit2:retrofit:2.4.0'
implementation 'com.google.code.gson:gson:2.8.6'
implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
}
21 changes: 21 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.crinoid.socialloginhelper

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.crinoid.socialloginhelper", appContext.packageName)
}
}
23 changes: 23 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.crinoid.socialloginhelper">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:ignore="GoogleAppIndexingWarning">
<activity
android:name=".instagram.SampleLoginActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
43 changes: 43 additions & 0 deletions app/src/main/java/com/crinoid/retrofit/MyRetrofitApiInterface.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.crinoid.retrofit

import com.crinoid.socialloginhelper.instagram.basicdisplay.AccessTokenRefreshResponseData
import com.crinoid.socialloginhelper.instagram.basicdisplay.AccessTokenWithCodeResponseData
import com.crinoid.socialloginhelper.instagram.basicdisplay.BDInstagramHelper
import com.crinoid.socialloginhelper.instagram.basicdisplay.InstagramBDUserData
import retrofit2.Call
import retrofit2.http.*

interface MyRetrofitApiInterface {

//Instagram Basic Display APIs
@GET(BDInstagramHelper.SELF_USER_API_END_POINT)
fun getSelfBDInstagramProfile(@Query("access_token") accessToken: String, @Query("fields") fields: String)
: Call<InstagramBDUserData>

@GET(BDInstagramHelper.REFRESH_ACCESS_TOKEN_API_END_POINT)
fun refreshIGBDAccessToken(
@Query("access_token") accessToken: String, @Query("client_secret") clientsecret: String, @Query(
"grant_type"
) grantType: String
)
: Call<AccessTokenRefreshResponseData>

@GET(BDInstagramHelper.EXCHANGE_ACCESS_TOKEN_API_END_POINT)
fun exchangeIGBDAccessToken(
@Query("access_token") accessToken: String, @Query("client_secret") clientsecret: String, @Query(
"grant_type"
) grantType: String
)
: Call<AccessTokenRefreshResponseData>

@FormUrlEncoded
@POST(BDInstagramHelper.GET_ACCESS_TOKEN_FROM_CODE_API_END_POINT)
fun getIGAccessTokenFromCode(
@Field("app_id") appId: String
, @Field("app_secret") appSecret: String
, @Field("grant_type") grantType: String
, @Field("redirect_uri") redirectUri: String
, @Field("code") code: String
): Call<AccessTokenWithCodeResponseData>

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.crinoid.socialloginhelper.instagram;

import android.annotation.SuppressLint;
import android.content.DialogInterface;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;

import com.crinoid.pesopie.R;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

import static com.crinoid.pesopie.instagram.Globals.INSTAGRAM_REDIRECT_URL;

@SuppressLint("ValidFragment")
public class AuthenticationDialog extends DialogFragment {

private final String redirect_url;
private final String request_url;
private AuthenticationListener listener;

WebViewClient webViewClient = new WebViewClient() {

@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith(redirect_url)) {
AuthenticationDialog.this.dismiss();
return true;
}
return false;
}

@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {

url = java.net.URLDecoder.decode(url, StandardCharsets.UTF_8.name());

} else {
url = java.net.URLDecoder.decode(url);

}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}

if (url.contains("access_token=")) {
String access_token = url.split("access_token=")[1];
if (listener != null) {
listener.onTokenReceived(access_token);
}
} else if (url.contains("?code=")) {
// Uri uri = Uri.parse(url);
// String accessCode = uri.getEncodedFragment();
String accessCode = url.split("\\?code=")[1].split("#")[0];
if (listener != null) {
listener.onCodeReceived(accessCode);
}
}
}


@Override
public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) {
super.onReceivedHttpError(view, request, errorResponse);
if (listener != null) {
if (errorResponse != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (!TextUtils.isEmpty(errorResponse.getReasonPhrase())) {
Toast.makeText(view.getContext(), errorResponse.getReasonPhrase(), Toast.LENGTH_SHORT).show();
}
} else {
// Toast.makeText(view.getContext(),errorResponse.getReasonPhrase(),Toast.LENGTH_SHORT).show();
}
}
}
}
};

public AuthenticationDialog(AuthenticationListener listener, String requestUrl, String languageCode) {
super();
this.listener = listener;
this.redirect_url = INSTAGRAM_REDIRECT_URL;//context.getResources().getString(R.string.redirect_url);
this.request_url = requestUrl;
Log.d("AuthenticationDialog", "AuthenticationDialog() = [" + request_url + "]");
}

@Override
public void onDetach() {
super.onDetach();
if (this.listener != null) {
listener.onComplete();
}
}


@Override
public void onCancel(@NonNull DialogInterface dialog) {
super.onCancel(dialog);
if (listener != null) {
listener.onError("Cancelled");
}
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
return inflater.inflate(R.layout.auth_dialog, container, false);

}

@SuppressLint("SetJavaScriptEnabled")
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
WebView webView = view.findViewById(R.id.webView);
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(webViewClient);
webView.clearCache(true);
webView.getSettings().setAppCacheEnabled(false);
CookieSyncManager.createInstance(getContext());
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
cookieManager.flush();
}
webView.loadUrl(request_url);
// view.findViewById(R.id.iv_close_ad).setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// dismiss();
// if (listener != null) {
// listener.onError("Cancelled");
// }
// }
// });

}

public interface AuthenticationListener {
/**
* @deprecated use onCodeReceived instead
*/
void onTokenReceived(String authToken);

void onCodeReceived(String code);

void onError(String error);

void onComplete();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.crinoid.socialloginhelper.instagram;

public class Globals {
public static final String INSTAGRAM_REDIRECT_URL = "https://www.pesopie.com/";
public static final String INSTAGRAM_BASE_URL = "https://api.instagram.com/";
/**
* @deprecated using INSTAGRAM_APP_ID instead
*/
public static final String INSTAGRAM_CLIENT_ID = "XXXXX";

//Basic display IG fields
public static final String INSTAGRAM_APP_ID = "XXXXXX";
public static final String INSTAGRAM_APP_SECRET = "XXXXX";
public static final String INSTAGRAM_USER_FIELDS = "id,username,account_type";
public static final String IGBD_GRANT_TYPE_EXCHANGE = "ig_exchange_token";
public static final String IGBD_GRANT_TYPE_REFRESH = "ig_refresh_token";
public static final String INSTAGRAM_LOGIN_SCOPES = "user_profile,user_media";
}
Loading

0 comments on commit b44d236

Please sign in to comment.