Skip to content

Commit

Permalink
- add exclude package names
Browse files Browse the repository at this point in the history
  • Loading branch information
jboxx committed Sep 30, 2018
1 parent a7943a0 commit 2516497
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MainActivity : AppCompatActivity() {
edtCopy.setText("")
val shareBottomSheet = ShareBottomSheetDialog.Builder(supportFragmentManager)
shareBottomSheet.setUrl("https://code.tutsplus.com/articles/coding-functional-android-apps-in-kotlin-lambdas-null-safety-more--cms-27964")
shareBottomSheet.excludePackageNames("com.google.android.gm", "com.facebook")
shareBottomSheet.addParameter(UTMConstants.UTM_CONTENT,"carousel")
shareBottomSheet.show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
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;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -39,6 +39,7 @@ class ShareBottomSheetController {
private String extraSubject;
private String url;
private LinkedHashMap<String, ShareBottomSheetDialogInterface.OnCustomParameter> listOfListener = new LinkedHashMap<>();
private List<String> excludePackageNames = new ArrayList<>();
private ShareBottomSheetDialogInterface.OnCustomMessage customMessageCallback;
private ShareBottomSheetDialogInterface.OnCustomMessage customExtraSubjectCallback;
private CustomOnDismissListener dismissListener;
Expand Down Expand Up @@ -114,6 +115,10 @@ private void setDismissListener(CustomOnDismissListener dismissListener) {
this.dismissListener = dismissListener;
}

private void setExcludePackageNames(List<String> excludePackageNames) {
this.excludePackageNames = excludePackageNames;
}

private void setListOfListener(LinkedHashMap<String, ShareBottomSheetDialogInterface.OnCustomParameter> listOfListener) {
this.listOfListener = listOfListener;
}
Expand Down Expand Up @@ -155,13 +160,26 @@ private void setUrl(String url) {
}

private List<ResolveInfo> showAllShareApp() {
java.util.List<ResolveInfo> mApps;
List<ResolveInfo> mAllShareApps;
List<ResolveInfo> targetedShareIntents = new ArrayList<>();
Intent intent = new Intent(Intent.ACTION_SEND, null);
intent.setType("text/plain");
PackageManager pManager = mContext.getPackageManager();
mApps = pManager.queryIntentActivities(intent,
mAllShareApps = pManager.queryIntentActivities(intent,
PackageManager.GET_SHARED_LIBRARY_FILES);
return mApps;
if (!excludePackageNames.isEmpty()) {
if (!mAllShareApps.isEmpty()) {
for (ResolveInfo resolveInfo : mAllShareApps) {
if (excludePackageNames.contains(resolveInfo.activityInfo.packageName)) {
targetedShareIntents.add(resolveInfo);
}
}
}
} else {
targetedShareIntents.addAll(mAllShareApps);
}

return targetedShareIntents;
}

private float dpFromPx(float px) {
Expand Down Expand Up @@ -226,6 +244,7 @@ protected static class ShareDialogParam {
private ShareBottomSheetDialogInterface.OnCustomMessage mCustomMessageListener;
private ShareBottomSheetDialogInterface.OnCustomMessage mCustomExtraSubjectListener;
private LinkedHashMap<String, ShareBottomSheetDialogInterface.OnCustomParameter> listOfListener = new LinkedHashMap<>();
private List<String> excludePackageNames = new ArrayList<>();

private String extraString;
private String extraSubject;
Expand All @@ -239,6 +258,10 @@ protected void apply(ShareBottomSheetController dialog) {
dialog.setTitle(title);
}

if (!excludePackageNames.isEmpty()) {
dialog.setExcludePackageNames(excludePackageNames);
}

if (!TextUtils.isEmpty(extraSubject)) {
dialog.setExtraSubject(extraSubject);
}
Expand Down Expand Up @@ -339,5 +362,9 @@ protected void setUrl(String url) {
protected void setAnotherParam(String param, String value) {
this.anotherParam.put(param, value);
}

protected void setExcludePackageNames(List<String> excludePackageNames) {
this.excludePackageNames = excludePackageNames;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
import android.view.ViewGroup;
import android.widget.FrameLayout;

import java.util.Arrays;
import java.util.List;

/**
* Created by Rifqi @jboxxpradhana
*/
Expand Down Expand Up @@ -237,6 +240,15 @@ public Builder addParameter(@NonNull String param, @NonNull String value) {
return this;
}

/**
* fill package names which you wants to exclude in your share intent
* @param excludePackageNames can contain array of String package name
*/
public Builder excludePackageNames(String... excludePackageNames) {
this.param.setExcludePackageNames(Arrays.asList(excludePackageNames));
return this;
}

/**
* Creates an {@link ShareBottomSheetDialog} with the arguments supplied to this
* builder.
Expand Down

0 comments on commit 2516497

Please sign in to comment.