[android] Change sharing link mechanism, change dialog strings and activity, added new options menu

This commit is contained in:
Dmitry Donskoy 2018-11-23 15:56:49 +03:00 committed by Aleksandr Zatsepin
parent daa76bccff
commit b48a96c2e4
10 changed files with 61 additions and 44 deletions

View file

@ -451,7 +451,7 @@
android:label="@string/sharing_options"/>
<activity
android:name="com.mapswithme.maps.ugc.routes.UgcRouteEditSettingsActivity"
android:label="@string/settings"/>
android:label="@string/list_settings"/>
<activity android:name=".purchase.BookmarkPaymentActivity"/>
<activity android:name="com.mapswithme.maps.ugc.routes.SendLinkPlaceholderActivity"/>
<activity

View file

@ -1,9 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/settings"
android:title="@string/list_settings"
android:icon="@drawable/ic_24_px_settings"/>
<item android:id="@+id/show"/>
<item android:id="@+id/show_on_map"/>
<item android:id="@+id/share"
android:title="@string/share"
android:icon="@drawable/ic_share"/>

View file

@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/settings"
android:title="@string/list_settings"
android:icon="@drawable/ic_24_px_settings"/>
<item android:id="@+id/share"
android:title="@string/share"
android:icon="@drawable/ic_share"/>

View file

@ -9,7 +9,7 @@
android:title="@string/share"
android:icon="@drawable/ic_share"/>
<item
android:id="@+id/delete_list"
android:id="@+id/delete"
android:title="@string/delete"
android:icon="@drawable/ic_delete"/>
</menu>

View file

@ -42,7 +42,6 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
{
private static final int MAX_CATEGORY_NAME_LENGTH = 60;
private static final int SHOW_ON_MAP_ITEM_MENU_INDEX = 1;
@NonNull
private BookmarkCategory mSelectedCategory;
@ -171,13 +170,11 @@ public abstract class BaseBookmarkCategoriesFragment extends BaseMwmRecyclerFrag
.sheet(getCategoryMenuResId())
.listener(this);
BottomSheet bottomSheet = bs.build();
prepareBottomMenuItems(bottomSheet);
bottomSheet
.getMenu().getItem(SHOW_ON_MAP_ITEM_MENU_INDEX)
.setIcon(item.isVisible() ? R.drawable.ic_hide : R.drawable.ic_show)
.setTitle(item.isVisible() ? R.string.hide : R.string.show);
MenuItem menuItem = BottomSheetHelper.findItemById(bottomSheet, R.id.show_on_map);
menuItem.setIcon(item.isVisible() ? R.drawable.ic_hide : R.drawable.ic_show)
.setTitle(item.isVisible() ? R.string.hide : R.string.show);
BottomSheetHelper.tint(bottomSheet);
bottomSheet.show();
}

View file

@ -27,6 +27,8 @@ import com.mapswithme.maps.bookmarks.data.BookmarkManager;
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
import com.mapswithme.maps.bookmarks.data.CategoryDataSource;
import com.mapswithme.maps.bookmarks.data.Track;
import com.mapswithme.maps.ugc.routes.BaseUgcRouteActivity;
import com.mapswithme.maps.ugc.routes.UgcRouteEditSettingsActivity;
import com.mapswithme.maps.ugc.routes.UgcRouteSharingOptionsActivity;
import com.mapswithme.maps.widget.placepage.EditBookmarkFragment;
import com.mapswithme.maps.widget.placepage.Sponsored;
@ -154,7 +156,7 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
BookmarkListAdapter adapter = getAdapter();
adapter.registerAdapterDataObserver(mCategoryDataSource);
adapter.setOnClickListener(this);
adapter.setOnLongClickListener(isCategorySharingRestricted() ? null : this);
adapter.setOnLongClickListener(isDownloadedCategory() ? null : this);
}
@Override
@ -202,8 +204,8 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
case BookmarkListAdapter.TYPE_BOOKMARK:
final Bookmark bookmark = (Bookmark) adapter.getItem(mSelectedPosition);
int menuResId = isCategorySharingRestricted() ? R.menu.menu_bookmarks_catalog
: R.menu.menu_bookmarks;
int menuResId = isDownloadedCategory() ? R.menu.menu_bookmarks_catalog
: R.menu.menu_bookmarks;
BottomSheet bs = BottomSheetHelper.create(getActivity(), bookmark.getTitle())
.sheet(menuResId)
.listener(this)
@ -248,26 +250,27 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
switch (menuItem.getItemId())
{
case R.id.share:
ShareOption.ANY.shareMapObject(getActivity(), item, Sponsored.nativeGetCurrent());
break;
case R.id.share:
ShareOption.ANY.shareMapObject(getActivity(), item, Sponsored.nativeGetCurrent());
break;
case R.id.edit:
EditBookmarkFragment.editBookmark(item.getCategoryId(), item.getBookmarkId(), getActivity(),
getChildFragmentManager(), new EditBookmarkFragment.EditBookmarkListener()
{
@Override
public void onBookmarkSaved(long bookmarkId)
{
adapter.notifyDataSetChanged();
}
});
break;
case R.id.edit:
EditBookmarkFragment.editBookmark(item.getCategoryId(), item.getBookmarkId(), getActivity(),
getChildFragmentManager(),
bookmarkId -> adapter.notifyDataSetChanged());
break;
case R.id.delete:
BookmarkManager.INSTANCE.deleteBookmark(item.getBookmarkId());
adapter.notifyDataSetChanged();
break;
case R.id.delete:
BookmarkManager.INSTANCE.deleteBookmark(item.getBookmarkId());
adapter.notifyDataSetChanged();
break;
case R.id.settings:
Intent intent = new Intent(getContext(), UgcRouteEditSettingsActivity.class).putExtra(
BaseUgcRouteActivity.EXTRA_BOOKMARK_CATEGORY,
getCategoryOrThrow());
startActivityForResult(intent, UgcRouteEditSettingsActivity.REQUEST_CODE);
break;
}
return false;
}
@ -275,15 +278,26 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
if (isCategorySharingRestricted())
if (isDownloadedCategory())
return;
inflater.inflate(R.menu.option_menu_bookmarks, menu);
}
private boolean isCategorySharingRestricted()
@SuppressWarnings("ConstantConditions")
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
getAdapter().notifyDataSetChanged();
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
actionBar.setTitle(mCategoryDataSource.getData().getName());
}
private boolean isDownloadedCategory()
{
BookmarkCategory category = mCategoryDataSource.getData();
return !category.isSharingOptionsAllowed();
return category.getType() == BookmarkCategory.Type.DOWNLOADED;
}
@Override
@ -306,6 +320,6 @@ public class BookmarksListFragment extends BaseMwmRecyclerFragment<BookmarkListA
private void openSharingOptionsScreen()
{
UgcRouteSharingOptionsActivity.startForResult(getActivity(), getCategoryOrThrow());
UgcRouteSharingOptionsActivity.startForResult(getActivity(), mCategoryDataSource.getData());
}
}

View file

@ -397,8 +397,8 @@ public class BookmarkCategory implements Parcelable
public enum AccessRules
{
ACCESS_RULES_LOCAL(R.string.not_shared, R.drawable.ic_lock),
ACCESS_RULES_PUBLIC(R.string.public_access, R.drawable.ic_public_inline),
ACCESS_RULES_DIRECT_LINK(R.string.limited_access, R.drawable.ic_link_inline),
ACCESS_RULES_PUBLIC(R.string.bookmarks_public_access, R.drawable.ic_public_inline),
ACCESS_RULES_DIRECT_LINK(R.string.bookmarks_link_access, R.drawable.ic_link_inline),
ACCESS_RULES_P2P(R.string.access_rules_p_to_p, R.drawable.ic_public_inline),
ACCESS_RULES_PAID(R.string.access_rules_paid, R.drawable.ic_public_inline);

View file

@ -10,13 +10,13 @@ import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.R;
import com.mapswithme.util.sharing.TargetUtils;
import java.util.Objects;
public class SendLinkPlaceholderFragment extends Fragment
{
public static final String EXTRA_SHARED_LINK = "shared_link";
private static final String MESSAGE_RFC_FORMAT = "message/rfc822";
private static final String BODY_STRINGS_SEPARATOR = "\n\n";
@SuppressWarnings("NullableProblems")
@ -43,19 +43,20 @@ public class SendLinkPlaceholderFragment extends Fragment
View closeBtn = root.findViewById(R.id.close_btn);
closeBtn.setOnClickListener(v -> getActivity().finish());
View sendMeLinkBtn = root.findViewById(R.id.send_me_link_btn);
sendMeLinkBtn.setOnClickListener(v -> shareViaEmail());
sendMeLinkBtn.setOnClickListener(v -> shareLink());
return root;
}
private void shareViaEmail()
private void shareLink()
{
String emailBody = getString(R.string.edit_your_guide_email_body) + BODY_STRINGS_SEPARATOR +
mSharedLink;
ShareCompat.IntentBuilder.from(getActivity())
.setType(MESSAGE_RFC_FORMAT)
.setType(TargetUtils.TYPE_TEXT_PLAIN)
.setSubject(getString(R.string.edit_guide_title))
.setText(emailBody)
.setChooserTitle(getString(R.string.share_by_email))
.setChooserTitle(getString(R.string.share))
.startChooser();
}
}

View file

@ -102,7 +102,7 @@ public class UgcRouteTagsFragment extends BaseMwmFragment implements BookmarkMan
private void showErrorLoadingDialog()
{
AlertDialog dialog = new AlertDialog.Builder()
.setTitleId(R.string.discovery_button_viator_error_title)
.setTitleId(R.string.title_error_downloading_bookmarks)
.setMessageId(R.string.tags_loading_error_subtitle)
.setPositiveBtnId(R.string.try_again)
.setNegativeBtnId(R.string.cancel)

View file

@ -448,7 +448,7 @@ public class UgcSharingOptionsFragment extends BaseMwmAuthorizationFragment impl
private void showCommonErrorDialog()
{
showErrorDialog(R.string.ugc_routes_error_uploading_file_toast,
showErrorDialog(R.string.upload_error_toast,
REQ_CODE_ERROR_COMMON,
ERROR_COMMON_DIALOG_TAG);
}