Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
2.39
-----
* Fixed the note share sheet missing installed apps (e.g. Gmail, WhatsApp) by launching the system share sheet [#1578](https://github.com/Automattic/simplenote-android/issues/1578)

2.38
-----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,13 @@ public void onShareDismissed() {

}

@Override
public void onShareOtherClicked() {
if (mNote != null) {
showShare(mNote.getContent());
}
}

/**
* History bottom sheet listeners
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,25 @@
package com.automattic.simplenote;

import android.app.Activity;
import android.content.ComponentName;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.automattic.simplenote.models.Note;
import com.automattic.simplenote.utils.IconResizer;
import com.automattic.simplenote.utils.NetworkUtils;
import com.automattic.simplenote.utils.ShareButtonAdapter;
import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;

import java.util.ArrayList;
import java.util.List;

public class ShareBottomSheetDialog extends BottomSheetDialogBase {
public static final String TAG = ShareBottomSheetDialog.class.getSimpleName();

private static final int SHARE_SHEET_COLUMN_COUNT = 3;

private Fragment mFragment;
private Intent mShareIntent;
private List<ShareButtonAdapter.ShareButtonItem> mShareButtons;
private RecyclerView mRecyclerView;
private ShareSheetListener mListener;
private TextView mPublishButton;
private TextView mUnpublishButton;
Expand All @@ -63,6 +43,7 @@ public void onDismiss(DialogInterface dialog) {

getDialog().setContentView(R.layout.bottom_sheet_share);
TextView mCollaborateButton = getDialog().findViewById(R.id.share_collaborate_button);
TextView mShareOtherButton = getDialog().findViewById(R.id.share_other_button);
mPublishButton = getDialog().findViewById(R.id.share_publish_button);
mUnpublishButton = getDialog().findViewById(R.id.share_unpublish_button);
mWordPressButton = getDialog().findViewById(R.id.share_wp_post);
Expand Down Expand Up @@ -105,30 +86,11 @@ public void onClick(View v) {
}
});

mRecyclerView = getDialog().findViewById(R.id.share_button_recycler_view);
mRecyclerView.setHasFixedSize(true);
mRecyclerView.setLayoutManager(new GridLayoutManager(mFragment.requireActivity(), SHARE_SHEET_COLUMN_COUNT));

mShareIntent = new Intent(Intent.ACTION_SEND);
mShareIntent.setType("text/plain");

mShareButtons = getShareButtons(mFragment.requireActivity(), mShareIntent);
}

if (getDialog() != null) {
// Set peek height to half height of view (i.e. set STATE_HALF_EXPANDED) to show some of
// sharing options when bottom sheet is shown.
getDialog().setOnShowListener(new DialogInterface.OnShowListener() {
mShareOtherButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onShow(DialogInterface dialogInterface) {
BottomSheetDialog bottomSheetDialog = (BottomSheetDialog) dialogInterface;
FrameLayout bottomSheet = bottomSheetDialog.findViewById(com.google.android.material.R.id.design_bottom_sheet);

if (bottomSheet != null) {
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet);
behavior.setState(BottomSheetBehavior.STATE_HALF_EXPANDED);
behavior.setSkipCollapsed(true);
}
public void onClick(View v) {
mListener.onShareOtherClicked();
dismiss();
}
});
}
Expand All @@ -147,41 +109,13 @@ public void show(FragmentManager manager, Note note) {
mPublishButton.setVisibility(View.VISIBLE);
mUnpublishButton.setVisibility(View.GONE);
}

mShareIntent.putExtra(Intent.EXTRA_TEXT, note.getContent());

final ShareButtonAdapter.ItemListener shareListener = new ShareButtonAdapter.ItemListener() {
@Override
public void onItemClick(ShareButtonAdapter.ShareButtonItem item) {
mShareIntent.setComponent(new ComponentName(item.getPackageName(), item.getActivityName()));
mFragment.requireActivity().startActivity(Intent.createChooser(mShareIntent, mFragment.getString(R.string.share)));
dismiss();
}
};

mRecyclerView.setAdapter(new ShareButtonAdapter(mShareButtons, shareListener));
}
}

@NonNull
private List<ShareButtonAdapter.ShareButtonItem> getShareButtons(Activity activity, Intent intent) {
List<ShareButtonAdapter.ShareButtonItem> shareButtons = new ArrayList<>();
final List<ResolveInfo> matches = activity.getPackageManager().queryIntentActivities(intent, 0);
IconResizer iconResizer = new IconResizer(requireContext());

for (ResolveInfo match : matches) {
final Drawable icon = iconResizer.createIconThumbnail(match.loadIcon(activity.getPackageManager()));
final CharSequence label = match.loadLabel(activity.getPackageManager());
shareButtons.add(new ShareButtonAdapter.ShareButtonItem(icon, label,
match.activityInfo.packageName, match.activityInfo.name));
}

return shareButtons;
}

public interface ShareSheetListener {
void onShareCollaborateClicked();
void onShareDismissed();
void onShareOtherClicked();
void onSharePublishClicked();
void onShareUnpublishClicked();
void onWordPressPostClicked();
Expand Down

This file was deleted.

This file was deleted.

29 changes: 29 additions & 0 deletions Simplenote/src/main/res/drawable/ic_share_other_48dp.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>

<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">

<item
android:height="@dimen/share_icon_size"
android:width="@dimen/share_icon_size">

<shape
android:shape="oval">

<solid
android:color="@color/blue">
</solid>

</shape>

</item>

<item
android:bottom="@dimen/padding_small"
android:drawable="@drawable/ic_share_24dp"
android:end="@dimen/padding_small"
android:start="@dimen/padding_small"
android:top="@dimen/padding_small">
</item>

</layer-list>
Loading