diff --git a/app/src/main/java/com/AbdAllahAbdElFattah13/linkedin/login/MainActivity.java b/app/src/main/java/com/AbdAllahAbdElFattah13/linkedin/login/MainActivity.java index 9618e11..ebcfdda 100644 --- a/app/src/main/java/com/AbdAllahAbdElFattah13/linkedin/login/MainActivity.java +++ b/app/src/main/java/com/AbdAllahAbdElFattah13/linkedin/login/MainActivity.java @@ -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; @@ -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; @@ -38,12 +31,8 @@ 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); @@ -51,7 +40,6 @@ protected void onCreate(Bundle savedInstanceState) { getCredentials(); - ivUserPic = findViewById(R.id.iv_user_pic); btnLogin = findViewById(R.id.btn_login); tvFName = findViewById(R.id.tv_first_name); @@ -70,41 +58,12 @@ 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()); @@ -112,18 +71,14 @@ private void setUserData(LinkedInUser user) { 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) { @@ -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")); @@ -146,11 +99,8 @@ protected void onActivityResult(int requestCode, int resultCode, @Nullable Inten //some error occured Toast.makeText(this, "Failed", Toast.LENGTH_SHORT).show(); } - - } } - } @@ -188,7 +138,6 @@ protected void onPostExecute(Bitmap result) { super.onPostExecute(result); imageView.setImageBitmap(result); } - } @@ -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(); - } + + // 77uzd83rv05qdd +// 11jwfr3Jh1g6Vldb +// 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); +//// 77uzd83rv05qdd +//// 11jwfr3Jh1g6Vldb +//// 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(); +// } } } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 04a989b..d659d34 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -37,8 +37,6 @@ android:layout_height="wrap_content" /> - -