Skip to content

Commit

Permalink
Merge branch 'development'
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdAllahAbdElFattah13 committed May 10, 2020
2 parents 140a96f + 54e66c6 commit 259e38a
Show file tree
Hide file tree
Showing 29 changed files with 744 additions and 669 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package com.AbdAllahAbdElFattah13.linkedin.login;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
Expand All @@ -15,17 +12,13 @@
import android.widget.TextView;
import android.widget.Toast;

import com.AbdAllahAbdElFattah13.linkedin.login.R;
import com.AbdAllahAbdElFattah13.linkedinsdk.helpers.LinkedInUser;
import com.AbdAllahAbdElFattah13.linkedinsdk.helpers.OnBasicProfileListener;
import com.AbdAllahAbdElFattah13.linkedinsdk.linkedin_builder.LinkedInFromActivityBuilder;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import org.json.JSONException;
import org.json.JSONObject;
import com.AbdAllahAbdElFattah13.linkedinsdk.ui.LinkedInUser;
import com.AbdAllahAbdElFattah13.linkedinsdk.ui.linkedin_builder.LinkedInFromActivityBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;

Expand All @@ -38,20 +31,15 @@ public class MainActivity extends AppCompatActivity {

private ImageView ivUserPic;
private Button btnLogin;
private Button btnGetUpdatedInfo;
private TextView tvFName, tvLName, tvEmail;

private String accessToken;
private long accessTokenExpiry;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

getCredentials();


ivUserPic = findViewById(R.id.iv_user_pic);
btnLogin = findViewById(R.id.btn_login);
tvFName = findViewById(R.id.tv_first_name);
Expand All @@ -70,60 +58,27 @@ public void onClick(View v) {

}
});

btnGetUpdatedInfo = findViewById(R.id.btn_get_update);
btnGetUpdatedInfo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

LinkedInFromActivityBuilder.retrieveBasicProfile(accessToken, accessTokenExpiry, new OnBasicProfileListener() {
@Override
public void onDataRetrievalStart() {

}

@Override
public void onDataSuccess(LinkedInUser user) {
setUserData(user);
}

@Override
public void onDataFailed(int errCode, String errMessage) {

Toast.makeText(MainActivity.this, "Failed", Toast.LENGTH_SHORT).show();
}
});

}
});

}

/**
* Sets data to UI
*/
private void setUserData(LinkedInUser user) {
accessToken = user.getAccessToken();
accessTokenExpiry = user.getAccessTokenExpiry();

Log.wtf("LINKEDIN ID", user.getId());

tvFName.setText(user.getFirstName());
tvLName.setText(user.getLastName());
tvEmail.setText(user.getEmail());

btnGetUpdatedInfo.setVisibility(View.VISIBLE);

if(user.getProfileUrl()!= null && !user.getProfileUrl().isEmpty()){
new ImageLoadTask(user.getProfileUrl(), ivUserPic).execute();
if (user.getProfilePictureUrl() != null && !user.getProfilePictureUrl().isEmpty()) {
new ImageLoadTask(user.getProfilePictureUrl(), ivUserPic).execute();
}
}


@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {


super.onActivityResult(requestCode, resultCode, data);

if (requestCode == LINKEDIN_REQUEST && data != null) {
Expand All @@ -134,8 +89,6 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
setUserData(user);

} else {


//print the error
Log.wtf("LINKEDIN ERR", data.getStringExtra("err_message"));

Expand All @@ -146,11 +99,8 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten
//some error occured
Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show();
}


}
}

}


Expand Down Expand Up @@ -188,7 +138,6 @@ protected void onPostExecute(Bitmap result) {
super.onPostExecute(result);
imageView.setImageBitmap(result);
}

}


Expand All @@ -199,25 +148,38 @@ protected void onPostExecute(Bitmap result) {
* Make sure to update your linkedin credentials in the said file
*/
private void getCredentials() {
try {

InputStream is = getAssets().open("linkedin-credentials.json");
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
String json = new String(buffer, "UTF-8");
JSONObject linkedinCred = new JSONObject(json);
clientID = linkedinCred.getString("client_id");
clientSecret = linkedinCred.getString("client_secret");
redirectUrl = linkedinCred.getString("redirect_url");

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

// <string name="linkedin_client_id" translatable="false">77uzd83rv05qdd</string>
// <string name="linkedin_client_secret" translatable="false">11jwfr3Jh1g6Vldb</string>
// private const val REDIRECT_URI = "https://www.cuju.io/android"

clientID = "77uzd83rv05qdd";
clientSecret = "11jwfr3Jh1g6Vldb";
redirectUrl = "https://www.cuju.io/android";

// try {
//
// InputStream is = getAssets().open("linkedin-credentials.json");
// int size = is.available();
// byte[] buffer = new byte[size];
// is.read(buffer);
// is.close();
// String json = new String(buffer, "UTF-8");
// JSONObject linkedinCred = new JSONObject(json);
//// <string name="linkedin_client_id" translatable="false">77uzd83rv05qdd</string>
//// <string name="linkedin_client_secret" translatable="false">11jwfr3Jh1g6Vldb</string>
//// private const val REDIRECT_URI = "https://www.cuju.io/android"
//
// clientID = "77uzd83rv05qdd";
// clientSecret = "11jwfr3Jh1g6Vldb";
// redirectUrl = "https://www.cuju.io/android";
//
// } catch (UnsupportedEncodingException e) {
// e.printStackTrace();
// } catch (IOException e) {
// e.printStackTrace();
// } catch (JSONException e) {
// e.printStackTrace();
// }
}
}
17 changes: 0 additions & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@
android:layout_height="wrap_content" />
</LinearLayout>



<Button
android:layout_margin="8dp"
android:id="@+id/btn_login"
Expand All @@ -49,19 +47,4 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />


<Button
android:visibility="gone"
android:layout_margin="8dp"
android:id="@+id/btn_get_update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Updated Info"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.598" />

</LinearLayout>
6 changes: 6 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.71'
repositories {
google()
jcenter()
Expand All @@ -12,6 +13,7 @@ buildscript {
// Required plugins added to classpath to facilitate pushing to JCenter/Bintray
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.7.3'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand All @@ -29,6 +31,10 @@ ext {
testRunnerVersion = "1.2.0"
espressoCoreVersion = "3.2.0"

//arch components
lifecycle_version = "2.2.0"
arch_version = "2.1.0"

// LinkedIn SDK Library Info
libVersionCode = 1
libVersionName = '1.0.0'
Expand Down
14 changes: 14 additions & 0 deletions linkedinsdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
apply plugin: 'com.android.library'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

repositories {
mavenCentral()
}

android {

Expand Down Expand Up @@ -29,9 +35,17 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.appcompat:appcompat:$rootProject.ext.androidxVersion"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation "androidx.core:core-ktx:1.2.0"

implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:$rootProject.ext.lifecycle_version"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:$rootProject.ext.lifecycle_version"

testImplementation "junit:junit:$rootProject.ext.junitVersion"
testImplementation "androidx.arch.core:core-testing:$rootProject.ext.arch_version"

androidTestImplementation "androidx.test:runner:$rootProject.ext.testRunnerVersion"
androidTestImplementation "androidx.test.espresso:espresso-core:$rootProject.ext.espressoCoreVersion"
}
Expand Down
2 changes: 1 addition & 1 deletion linkedinsdk/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="com.AbdAllahAbdElFattah13.linkedinsdk">

<application>
<activity android:name="com.AbdAllahAbdElFattah13.linkedinsdk.LinkedInAuthenticationActivity" />
<activity android:name="com.AbdAllahAbdElFattah13.linkedinsdk.ui.LinkedInAuthenticationActivity" />
</application>

</manifest>
Loading

0 comments on commit 259e38a

Please sign in to comment.