Skip to content

Instantly share code, notes, and snippets.

@followthemoney1
Last active May 4, 2019 18:49
Show Gist options
  • Save followthemoney1/5b25d1283cce7303941205932824a45c to your computer and use it in GitHub Desktop.
Save followthemoney1/5b25d1283cce7303941205932824a45c to your computer and use it in GitHub Desktop.
rarare - ShareDialogManager - branch
package com.quayback.rarare.ui.invite;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;
import com.facebook.FacebookSdk;
import com.facebook.share.model.AppInviteContent;
import com.facebook.share.model.ShareLinkContent;
import com.facebook.share.widget.AppInviteDialog;
import com.facebook.share.widget.ShareDialog;
import com.orhanobut.dialogplus.DialogPlus;
import com.orhanobut.dialogplus.ViewHolder;
import com.quayback.rarare.R;
import com.quayback.rarare.ui.event.EventDetailsActivity;
import io.branch.indexing.BranchUniversalObject;
import io.branch.referral.Branch;
import io.branch.referral.BranchError;
import io.branch.referral.SharingHelper;
import io.branch.referral.util.LinkProperties;
import io.branch.referral.util.ShareSheetStyle;
/**
* Created by User on 5/10/2016.
*/
public class ShareDialogManager {
private Context context;
private Activity activity;
private DialogPlus dialog;
private boolean isFirstTime;
private String msg;
private String title;
public ShareDialogManager(Activity context, String msg, String title) {
this.context = context;
this.activity = context;
this.msg = msg;
this.title = title;
}
public void show() {
LinkProperties linkProperties = new LinkProperties()
.setChannel("facebook")
.setFeature("sharing")
.addControlParameter("$ios_url", "https://itunes.apple.com/us/app/rarare/id1242296834?ls=1&mt=8")
.addControlParameter("$android_url", "https://play.google.com/store/apps/details?id=com.quayback.rarare&hl=en");
BranchUniversalObject branchUniversalObject = new BranchUniversalObject()
.setCanonicalIdentifier("monster/12345")
.setTitle("")
.setContentType("RaRaRe")
.setContentDescription("Turning debates into actionable requests.");
ShareSheetStyle shareSheetStyle = new ShareSheetStyle(activity, "RaRaRe", msg)
.setCopyUrlStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_send), "Copy", "Added to clipboard")
.setMoreOptionStyle(activity.getResources().getDrawable(android.R.drawable.ic_menu_search), "Show more")
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.EMAIL)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.MESSAGE)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.FACEBOOK_MESSENGER)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.WHATS_APP)
.addPreferredSharingOption(SharingHelper.SHARE_WITH.INSTAGRAM)
.setAsFullWidthStyle(true)
.setSharingTitle("Share With");
branchUniversalObject.showShareSheet(activity,
linkProperties,
shareSheetStyle,
new Branch.BranchLinkShareListener() {
@Override
public void onShareLinkDialogLaunched() {
}
@Override
public void onShareLinkDialogDismissed() {
}
@Override
public void onLinkShareResponse(String sharedLink, String sharedChannel, BranchError error) {
}
@Override
public void onChannelSelected(String channelName) {
}
});
// LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// View view = inflater.inflate(R.layout.dialog_invite_friends, null);
// final DialogPlus dialog = DialogPlus.newDialog(context)
// .setContentHolder(new ViewHolder(view))
// .setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
// .setGravity(Gravity.BOTTOM)
// .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT) // or any custom width ie: 300
// .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
// .create();
// dialog.show();
//
// LinearLayout llFacebook = (LinearLayout) dialog.findViewById(R.id.llFacebook);
// LinearLayout llWhatsapp = (LinearLayout) dialog.findViewById(R.id.llWhatsapp);
// LinearLayout llEmail = (LinearLayout) dialog.findViewById(R.id.llEmail);
//
// llFacebook.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// ShareDialog shareDialog;
// FacebookSdk.sdkInitialize(activity);
// shareDialog = new ShareDialog(activity);
//
//
// if (ShareDialog.canShow(ShareLinkContent.class)) {
// ShareLinkContent linkContent = new ShareLinkContent.Builder()
// .setContentTitle("Rarare- new"+title)
// .setImageUrl(Uri.parse("http://i.hmp.me/m/c5f0b498761c6e11827eb8692a08d6fc.png"))
// .setContentDescription(msg)
//
//// .setContentUrl(Uri.parse("http://i.hmp.me/m/c5f0b498761c6e11827eb8692a08d6fc.png"))
// .build();
//
// shareDialog.show(linkContent);
// }
//
// dialog.dismiss();
// activity.finish();
// }
// });
// llWhatsapp.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
// whatsappIntent.setType("text/plain");
// whatsappIntent.setPackage("com.whatsapp");
// whatsappIntent.putExtra(Intent.EXTRA_TEXT,
// msg);
// try {
// activity.startActivity(whatsappIntent);
// } catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(context, "Whatsapp have not been installed.", Toast.LENGTH_LONG).show();
// }
// dialog.dismiss();
// activity.finish();
// }
// });
// llEmail.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
// emailIntent.setType("text/plain");
// emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Hello There");
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, msg);
// emailIntent.setType("message/rfc822");
//
// try {
// activity.startActivity(Intent.createChooser(emailIntent,
// "Send email using..."));
// } catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(context,
// "No email clients installed.",
// Toast.LENGTH_SHORT).show();
// }
// dialog.dismiss();
// activity.finish();
// }
// });
}
// public ShareDialogManager(Activity activity) {
// this.context = context;
// this.activity = activity;
// this.msg = msg;
//// this.title = title;
// }
//
//
//
//
// public void show() {
// LayoutInflater inflater = (LayoutInflater) activity.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
// View view = inflater.inflate(R.layout.dialog_invite_friends, null);
// final DialogPlus dialog = DialogPlus.newDialog(activity)
// .setContentHolder(new ViewHolder(view))
// .setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
// .setGravity(Gravity.BOTTOM)
// .setContentWidth(ViewGroup.LayoutParams.MATCH_PARENT) // or any custom width ie: 300
// .setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
// .create();
// dialog.show();
//
// LinearLayout llFacebook = (LinearLayout) dialog.findViewById(R.id.llFacebook);
// LinearLayout llWhatsapp = (LinearLayout) dialog.findViewById(R.id.llWhatsapp);
// LinearLayout llEmail = (LinearLayout) dialog.findViewById(R.id.llEmail);
//
// llFacebook.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//// ShareDialog shareDialog;
// FacebookSdk.sdkInitialize(activity);
//// shareDialog = new ShareDialog(activity);
//
// String appLinkUrl, previewImageUrl;
//// appLinkUrl = "https://fb.me/316024655432771";
// appLinkUrl = "http://rarare.com/";
// previewImageUrl = "https://www.mydomain.com/my_invite_image.jpg";
//
// if (AppInviteDialog.canShow()) {
// AppInviteContent content = new AppInviteContent.Builder()
// .setApplinkUrl(appLinkUrl)
// .setPreviewImageUrl(previewImageUrl)
// .build();
// AppInviteDialog.show(activity, content);
// }
//// if (ShareDialog.canShow(ShareLinkContent.class)) {
//// ShareLinkContent linkContent = new ShareLinkContent.Builder()
//// .setContentTitle("Rarare- new"+title)
//// .setImageUrl(Uri.parse("http://i.hmp.me/m/c5f0b498761c6e11827eb8692a08d6fc.png"))
//// .setContentDescription(msg)
////
////// .setContentUrl(Uri.parse("http://i.hmp.me/m/c5f0b498761c6e11827eb8692a08d6fc.png"))
//// .build();
////
//// shareDialog.show(linkContent);
//// }
////
//// dialog.dismiss();
// }
// });
// llWhatsapp.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
//// Uri imageUri = Uri.parse("android.resource:com.quayback.rarare/drawable/logo");
//
// Intent whatsappIntent = new Intent(Intent.ACTION_SEND);
// whatsappIntent.setType("text/plain");
// whatsappIntent.setPackage("com.whatsapp");
// whatsappIntent.putExtra(Intent.EXTRA_TEXT,
// "Hey!!\n" +
// "Check out this free, cool community app that will revolutionise the way we all help take care of our community"
// + "\n" + "http://rarare.com/");
// try {
// activity.startActivity(whatsappIntent);
// } catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(context, "Whatsapp have not been installed.", Toast.LENGTH_LONG).show();
// }
// dialog.dismiss();
// }
// });
// llEmail.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
//// Uri imageUri = Uri.parse("file//res/mipmap-hdpi/logowhite");
// emailIntent.setType("text/plain");
// emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "RaRaRe");
//// emailIntent.putExtra(Intent.EXTRA_STREAM, imageUri);
// emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Hey!!\n" +
// "Check out this free, cool community app that will revolutionise the way we all help take care of our community"
// + "\n" + "http://rarare.com/");
// emailIntent.setType("message/rfc822");
//
// try {
// activity.startActivity(Intent.createChooser(emailIntent,
// "Send email using..."));
// } catch (android.content.ActivityNotFoundException ex) {
// Toast.makeText(context,
// "No email clients installed.",
// Toast.LENGTH_SHORT).show();
// }
// dialog.dismiss();
// }
// });
// }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment