diff --git a/sample/src/main/java/com/jboxx/bottomsheetdialog/JavaActivity.java b/sample/src/main/java/com/jboxx/bottomsheetdialog/JavaActivity.java index aa0924c..b0fa8eb 100644 --- a/sample/src/main/java/com/jboxx/bottomsheetdialog/JavaActivity.java +++ b/sample/src/main/java/com/jboxx/bottomsheetdialog/JavaActivity.java @@ -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; @@ -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"; @@ -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!"; @@ -158,6 +162,7 @@ public void onDismiss(DialogInterface dialog, String content) { }); if (!shareBottomSheetDialog.isAdded()) { shareBottomSheetDialog.show(); + Log.d(JavaActivity.class.getSimpleName(), "" + shareBottomSheetDialog.isAdded()); } } }); diff --git a/sample/src/main/java/com/jboxx/bottomsheetdialog/MainActivity.kt b/sample/src/main/java/com/jboxx/bottomsheetdialog/MainActivity.kt index 84d724f..2971409 100644 --- a/sample/src/main/java/com/jboxx/bottomsheetdialog/MainActivity.kt +++ b/sample/src/main/java/com/jboxx/bottomsheetdialog/MainActivity.kt @@ -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 /** @@ -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() } diff --git a/sharebottomsheetdialog/build.gradle b/sharebottomsheetdialog/build.gradle index 32c05a5..1d59e85 100644 --- a/sharebottomsheetdialog/build.gradle +++ b/sharebottomsheetdialog/build.gradle @@ -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 -> diff --git a/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetController.java b/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetController.java index 193583c..efd1095 100644 --- a/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetController.java +++ b/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetController.java @@ -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; @@ -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 listOfListener = new LinkedHashMap<>(); private ShareBottomSheetDialogInterface.OnCustomMessage customMessageCallback; + private ShareBottomSheetDialogInterface.OnCustomMessage customExtraSubjectCallback; private CustomOnDismissListener dismissListener; protected ShareBottomSheetController() {} @@ -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()); } }); @@ -110,6 +118,18 @@ private void setListOfListener(LinkedHashMap listOfListener = new LinkedHashMap<>(); private String extraString; + private String extraSubject; private String url; private HashMap anotherParam = new LinkedHashMap<>(); @@ -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); } @@ -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; } @@ -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; } diff --git a/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetDialog.java b/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetDialog.java index 79874a0..9a9bc54 100644 --- a/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetDialog.java +++ b/sharebottomsheetdialog/src/main/java/com/jboxx/sharebottomsheetdialog/ShareBottomSheetDialog.java @@ -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); } } } @@ -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 @@ -248,7 +266,7 @@ private ShareBottomSheetDialog create() { */ public ShareBottomSheetDialog show() { if (!this.isAdded()) { - shareBottomSheetDialog = create(); + shareBottomSheetDialog = create(); fragmentManager.executePendingTransactions(); shareBottomSheetDialog.show(fragmentManager, TAG); } @@ -257,7 +275,7 @@ public ShareBottomSheetDialog show() { public ShareBottomSheetDialog showAllowingStateLoss() { if (!this.isAdded()) { - shareBottomSheetDialog = create(); + shareBottomSheetDialog = create(); shareBottomSheetDialog.showDialogAllowingStateLoss(fragmentManager, TAG); } return shareBottomSheetDialog;