Skip to content

Commit

Permalink
- add extra subject
Browse files Browse the repository at this point in the history
  • Loading branch information
jboxx committed Sep 30, 2018
1 parent a63ab9a commit a7943a0
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Expand Down Expand Up @@ -82,6 +83,7 @@ public String onChooseApps(ResolveInfo resolveInfo) {
.addParameterWithCallback(UTMConstants.UTM_SOURCE, new ShareBottomSheetDialogInterface.OnCustomParameter() {
@Override
public String onChooseApps(ResolveInfo resolveInfo) {
Log.d(JavaActivity.class.getSimpleName(), "packageName " + resolveInfo.activityInfo.packageName + " name " + resolveInfo.activityInfo.name);
String utmSource = "";
if (resolveInfo.activityInfo.packageName.contains("com.whatsapp")) {
utmSource = "from whatsapp";
Expand Down Expand Up @@ -134,9 +136,11 @@ public void onClick(View view) {
shareBottomSheetDialog.setFullScreen(true);
shareBottomSheetDialog.setCancelable(false);
shareBottomSheetDialog.setTitle("Share");
shareBottomSheetDialog.setExtraSubject("This is subject");
shareBottomSheetDialog.setMessage(new ShareBottomSheetDialogInterface.OnCustomMessage() {
@Override
public String onChooseApps(ResolveInfo resolveInfo) {
Log.d(JavaActivity.class.getSimpleName(), "packageName " + resolveInfo.activityInfo.packageName + " name " + resolveInfo.activityInfo.name);
String message = "Share this link!";
if (resolveInfo.activityInfo.packageName.contains("com.whatsapp")) {
message = "Share this link via whatsapp!";
Expand All @@ -158,6 +162,7 @@ public void onDismiss(DialogInterface dialog, String content) {
});
if (!shareBottomSheetDialog.isAdded()) {
shareBottomSheetDialog.show();
Log.d(JavaActivity.class.getSimpleName(), "" + shareBottomSheetDialog.isAdded());
}
}
});
Expand Down
13 changes: 12 additions & 1 deletion sample/src/main/java/com/jboxx/bottomsheetdialog/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.jboxx.sharebottomsheetdialog.ShareBottomSheetDialogInterface
import com.jboxx.sharebottomsheetdialog.UTMConstants
import android.app.Activity
import android.content.Intent

import android.content.pm.ResolveInfo


/**
Expand Down Expand Up @@ -55,6 +55,17 @@ class MainActivity : AppCompatActivity() {
.setFullScreen(true)
.setCancelable(true)
.setUrl("https://www.youtube.com/watch?v=QBGaO89cBMI&")
.setExtraSubject({resolveInfo: ResolveInfo -> String
var extraSubject = "Subject for All"
if (resolveInfo.activityInfo.packageName.contains("android.gm")) {
extraSubject = "Subject for Gmail";
} else if (resolveInfo.activityInfo.packageName.contains("android.email")) {
extraSubject = "Subject for Android mail";
} else if (resolveInfo.activityInfo.packageName.contains("android.apps.inbox")) {
extraSubject = "Subject for Inbox by Gmail";
}
return@setExtraSubject extraSubject
})
.addParameterWithCallback(UTMConstants.UTM_SOURCE, ShareBottomSheetDialogInterface.OnCustomParameter { resolveInfo -> "everywhere" })
.show()
}
Expand Down
3 changes: 3 additions & 0 deletions sharebottomsheetdialog/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ dependencies {
api "com.android.support:design:$androidSupportLibraryVersion"

testImplementation "junit:junit:$junitVersion"

androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.2'
androidTestCompile 'com.android.support.test:testing-support-lib:0.1'
}

gradle.taskGraph.beforeTask { Task task ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

Expand All @@ -35,9 +36,11 @@ class ShareBottomSheetController {
private StringBuilder populateParam = new StringBuilder();
private StringBuilder message = new StringBuilder();
private String extraString;
private String extraSubject;
private String url;
private LinkedHashMap<String, ShareBottomSheetDialogInterface.OnCustomParameter> listOfListener = new LinkedHashMap<>();
private ShareBottomSheetDialogInterface.OnCustomMessage customMessageCallback;
private ShareBottomSheetDialogInterface.OnCustomMessage customExtraSubjectCallback;
private CustomOnDismissListener dismissListener;

protected ShareBottomSheetController() {}
Expand Down Expand Up @@ -69,10 +72,15 @@ protected void initiateView(Context context, final ShareBottomSheetDialog dialog
}
}
if (customMessageCallback != null) {
if(!TextUtils.isEmpty(customMessageCallback.onChooseApps(resolveInfo))){
if (!TextUtils.isEmpty(customMessageCallback.onChooseApps(resolveInfo))) {
setMessage(customMessageCallback.onChooseApps(resolveInfo));
}
}
if (customExtraSubjectCallback != null) {
if (!TextUtils.isEmpty(customExtraSubjectCallback.onChooseApps(resolveInfo))) {
setExtraSubject(customExtraSubjectCallback.onChooseApps(resolveInfo));
}
}
doShare(resolveInfo, populateMessage().toString());
}
});
Expand Down Expand Up @@ -110,6 +118,18 @@ private void setListOfListener(LinkedHashMap<String, ShareBottomSheetDialogInter
this.listOfListener = listOfListener;
}

private void setExtraSubject(String extraSubject) {
if (!TextUtils.isEmpty(extraSubject)) {
this.extraSubject = extraSubject;
}
}

private void setExtraSubject(ShareBottomSheetDialogInterface.OnCustomMessage listenerCustomExtraSubject) {
if (listenerCustomExtraSubject != null) {
this.customExtraSubjectCallback = listenerCustomExtraSubject;
}
}

private void setMessage(String extraString) {
if (!TextUtils.isEmpty(extraString)) {
this.extraString = extraString;
Expand Down Expand Up @@ -151,6 +171,9 @@ private float dpFromPx(float px) {
private void doShare(ResolveInfo resolveInfo, String message) {
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
if (!TextUtils.isEmpty(extraSubject)) {
sendIntent.putExtra(Intent.EXTRA_SUBJECT, extraSubject);
}
sendIntent.putExtra(Intent.EXTRA_TEXT, message);

if (resolveInfo != null) {
Expand Down Expand Up @@ -201,9 +224,11 @@ protected static class ShareDialogParam {

private String title;
private ShareBottomSheetDialogInterface.OnCustomMessage mCustomMessageListener;
private ShareBottomSheetDialogInterface.OnCustomMessage mCustomExtraSubjectListener;
private LinkedHashMap<String, ShareBottomSheetDialogInterface.OnCustomParameter> listOfListener = new LinkedHashMap<>();

private String extraString;
private String extraSubject;
private String url;
private HashMap<String, String> anotherParam = new LinkedHashMap<>();

Expand All @@ -214,6 +239,14 @@ protected void apply(ShareBottomSheetController dialog) {
dialog.setTitle(title);
}

if (!TextUtils.isEmpty(extraSubject)) {
dialog.setExtraSubject(extraSubject);
}

if (mCustomExtraSubjectListener != null) {
dialog.setExtraSubject(mCustomExtraSubjectListener);
}

if(!TextUtils.isEmpty(extraString)) {
dialog.setMessage(extraString);
}
Expand Down Expand Up @@ -279,6 +312,10 @@ protected void setTitle(String title) {
this.title = title;
}

protected void setmCustomExtraTitleListener(ShareBottomSheetDialogInterface.OnCustomMessage mCustomExtraSubjectListener) {
this.mCustomExtraSubjectListener = mCustomExtraSubjectListener;
}

protected void setmCustomMessageListener(ShareBottomSheetDialogInterface.OnCustomMessage mCustomMessageListener) {
this.mCustomMessageListener = mCustomMessageListener;
}
Expand All @@ -287,6 +324,10 @@ protected void setListOfListener(String param, ShareBottomSheetDialogInterface.O
this.listOfListener.put(param, listener);
}

protected void setExtraSubject(String extraSubject) {
this.extraSubject = extraSubject;
}

protected void setExtraString(String extraString) {
this.extraString = extraString;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void onShow(DialogInterface dialog) {
final BottomSheetBehavior bottomSheetBehavior = BottomSheetBehavior.from(bottomSheetLayout);
if(isFullScreen) {
bottomSheetBehavior.setPeekHeight(bottomSheetLayout.getHeight());
//bottomSheetBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
}
}
}
Expand Down Expand Up @@ -166,6 +165,25 @@ public Builder setTitle(@NonNull String title) {
return this;
}

/**
* @param extraSubject fill subject if you want to give subject into subject of messages
* don't set the subject if you don't want to give subject to your messages
*/
public Builder setExtraSubject(@NonNull String extraSubject) {
this.param.setExtraSubject(extraSubject);
return this;
}

/**
* set listener if you want to give callback and set your content messages
* @param mCustomExtraSubjectListener that can give u callback `Resolve Info` object so you can manipulate subject
* depends on user selection
*/
public Builder setExtraSubject(@NonNull ShareBottomSheetDialogInterface.OnCustomMessage mCustomExtraSubjectListener) {
this.param.setmCustomExtraTitleListener(mCustomExtraSubjectListener);
return this;
}

/**
* @param extraString fill message if you want to give messages into content
* don't set the message if you don't want to give string content
Expand Down Expand Up @@ -248,7 +266,7 @@ private ShareBottomSheetDialog create() {
*/
public ShareBottomSheetDialog show() {
if (!this.isAdded()) {
shareBottomSheetDialog = create();
shareBottomSheetDialog = create();
fragmentManager.executePendingTransactions();
shareBottomSheetDialog.show(fragmentManager, TAG);
}
Expand All @@ -257,7 +275,7 @@ public ShareBottomSheetDialog show() {

public ShareBottomSheetDialog showAllowingStateLoss() {
if (!this.isAdded()) {
shareBottomSheetDialog = create();
shareBottomSheetDialog = create();
shareBottomSheetDialog.showDialogAllowingStateLoss(fragmentManager, TAG);
}
return shareBottomSheetDialog;
Expand Down

0 comments on commit a7943a0

Please sign in to comment.