Skip to content

Commit

Permalink
fixed facebook app open
Browse files Browse the repository at this point in the history
  • Loading branch information
p32929 committed Aug 10, 2019
1 parent d9c7a04 commit a6801bb
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ allprojects {
Add the dependency
```
dependencies {
implementation 'com.github.p32929:OfficeAbout:1.0.0.4'
implementation 'com.github.p32929:OfficeAbout:1.0.0.5'
}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ public void onClick(View view) {
@Override
public void onClick(View view) {
if (GlobalMethods.isAvailable(officeInfo.getFacebookUrl())) {
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(officeInfo.getFacebookUrl()));
startActivity(browse);
startActivity(GlobalMethods.getFacebookIntent(OfficeAboutActivity.this, officeInfo.getFacebookUrl()));
} else {
Toast.makeText(OfficeAboutActivity.this, "URL is not provided yet", Toast.LENGTH_SHORT).show();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.ArrayList;

import p32929.officeaboutlib.Models.Member;
import p32929.officeaboutlib.Others.GlobalMethods;
import p32929.officeaboutlib.R;

public class AboutRecyclerviewAdapter extends RecyclerView.Adapter<AboutRecyclerviewAdapter.ViewHolder> {
Expand Down Expand Up @@ -50,11 +51,14 @@ public void onBindViewHolder(@NonNull AboutRecyclerviewAdapter.ViewHolder holder
@Override
public void onClick(View view) {
if (member.getContactUrl().isEmpty()) {
Toast.makeText(context, "" + member.getName() + " has no contact info", Toast.LENGTH_SHORT).show();
}
else {
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(member.getContactUrl()));
context.startActivity(browse);
Toast.makeText(context, "" + member.getName() + " has added no contact info", Toast.LENGTH_SHORT).show();
} else {
if (member.getContactUrl().contains("facebook")) {
context.startActivity(GlobalMethods.getFacebookIntent(context, member.getContactUrl()));
} else {
Intent browse = new Intent(Intent.ACTION_VIEW, Uri.parse(member.getContactUrl()));
context.startActivity(browse);
}
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,11 @@

import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.net.Uri;

public class GlobalMethods {
public static Intent openFacebookUrl(Context context, String id) {
try {
context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/" + id));
} catch (Exception e) {
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/" + id));
}
}

public static boolean isAvailable(String something) {
if (something == null) {
return false;
Expand All @@ -25,4 +18,19 @@ public static boolean isAvailable(String something) {
}
}
}

public static Intent getFacebookIntent(Context context, String url) {
PackageManager pm = context.getPackageManager();
Uri uri = Uri.parse(url);
try {
ApplicationInfo applicationInfo = pm.getApplicationInfo("com.facebook.katana", 0);
if (applicationInfo.enabled) {
uri = Uri.parse("fb://facewebmodal/f?href=" + url);
}
} catch (Exception e) {

}

return new Intent(Intent.ACTION_VIEW, uri);
}
}

0 comments on commit a6801bb

Please sign in to comment.