forked from organicmaps/organicmaps
[android] Added handling the bookmark sharing errors
This commit is contained in:
parent
9366bbb282
commit
af125ebee6
3 changed files with 51 additions and 27 deletions
|
@ -6,7 +6,6 @@ import android.support.annotation.CallSuper;
|
|||
import android.support.annotation.LayoutRes;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
|
@ -160,23 +159,15 @@ public class BookmarkCategoriesFragment extends BaseMwmRecyclerFragment
|
|||
{
|
||||
if (TextUtils.isEmpty(text))
|
||||
{
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setTitle(R.string.bookmarks_error_title_empty_list_name)
|
||||
.setMessage(R.string.bookmarks_error_message_empty_list_name)
|
||||
.show();
|
||||
UiUtils.showAlertDialog(getActivity(), R.string.bookmarks_error_title_empty_list_name,
|
||||
R.string.bookmarks_error_message_empty_list_name);
|
||||
return;
|
||||
}
|
||||
|
||||
if (BookmarkManager.INSTANCE.isUsedCategoryName(text))
|
||||
{
|
||||
new AlertDialog.Builder(getActivity())
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(R.string.ok, null)
|
||||
.setTitle(R.string.bookmarks_error_title_list_name_already_taken)
|
||||
.setMessage(R.string.bookmarks_error_message_list_name_already_taken)
|
||||
.show();
|
||||
UiUtils.showAlertDialog(getActivity(), R.string.bookmarks_error_title_list_name_already_taken,
|
||||
R.string.bookmarks_error_message_list_name_already_taken);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -255,7 +255,7 @@ public final class UiUtils
|
|||
{
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setCancelable(false)
|
||||
.setMessage(titleId)
|
||||
.setTitle(titleId)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dlg, int which) { dlg.dismiss(); }
|
||||
|
@ -263,12 +263,30 @@ public final class UiUtils
|
|||
.create();
|
||||
}
|
||||
|
||||
public static void showAlertDialog(Activity activity, int titleId)
|
||||
public static AlertDialog buildAlertDialog(Activity activity, int titleId, @StringRes int msgId)
|
||||
{
|
||||
return new AlertDialog.Builder(activity)
|
||||
.setCancelable(false)
|
||||
.setTitle(titleId)
|
||||
.setMessage(msgId)
|
||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dlg, int which) { dlg.dismiss(); }
|
||||
})
|
||||
.create();
|
||||
}
|
||||
|
||||
public static void showAlertDialog(@NonNull Activity activity, @StringRes int titleId,
|
||||
@StringRes int msgId)
|
||||
{
|
||||
buildAlertDialog(activity, titleId, msgId).show();
|
||||
}
|
||||
|
||||
public static void showAlertDialog(@NonNull Activity activity, @StringRes int titleId)
|
||||
{
|
||||
buildAlertDialog(activity, titleId).show();
|
||||
}
|
||||
|
||||
|
||||
public static String deviceOrientationAsString(Activity activity)
|
||||
{
|
||||
String rotation = activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? "|" : "-";
|
||||
|
|
|
@ -20,11 +20,13 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkSharingResult;
|
||||
import com.mapswithme.util.BottomSheetHelper;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.concurrency.ThreadPool;
|
||||
import com.mapswithme.util.concurrency.UiThread;
|
||||
import com.mapswithme.util.log.Logger;
|
||||
import com.mapswithme.util.log.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
|
@ -215,19 +217,32 @@ public final class SharingHelper
|
|||
public static void shareBookmarksCategory(@NonNull Activity context,
|
||||
@NonNull BookmarkSharingResult result)
|
||||
{
|
||||
//TODO: show error dialog in this case.
|
||||
String name = BookmarkManager.INSTANCE.getCategoryName(result.getCategoryId());
|
||||
if (result.getCode() != BookmarkSharingResult.SUCCESS)
|
||||
switch (result.getCode())
|
||||
{
|
||||
LOGGER.e(TAG, "Failed to share bookmark category '" + name + "', error code: "
|
||||
+ result.getCode());
|
||||
return;
|
||||
case BookmarkSharingResult.SUCCESS:
|
||||
String name = new File(result.getSharingPath()).getName();
|
||||
shareOutside(new LocalFileShareable(context, result.getSharingPath(),
|
||||
"application/vnd.google-earth.kmz")
|
||||
// TODO fix translation for some languages, that doesn't contain holder
|
||||
// for filename
|
||||
.setText(context.getString(R.string.share_bookmarks_email_body, name))
|
||||
.setSubject(R.string.share_bookmarks_email_subject));
|
||||
break;
|
||||
case BookmarkSharingResult.EMPTY_CATEGORY:
|
||||
UiUtils.showAlertDialog(context, R.string.bookmarks_error_title_share_empty,
|
||||
R.string.bookmarks_error_message_share_empty);
|
||||
break;
|
||||
case BookmarkSharingResult.ARCHIVE_ERROR:
|
||||
case BookmarkSharingResult.FILE_ERROR:
|
||||
UiUtils.showAlertDialog(context, R.string.dialog_routing_system_error,
|
||||
R.string.bookmarks_error_message_share_general);
|
||||
String catName = BookmarkManager.INSTANCE.getCategoryName(result.getCategoryId());
|
||||
LOGGER.e(TAG, "Failed to share bookmark category '" + catName + "', error code: "
|
||||
+ result.getCode());
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unsupported bookmark sharing code: " + result.getCode());
|
||||
}
|
||||
|
||||
shareOutside(new LocalFileShareable(context, result.getSharingPath(), "application/vnd.google-earth.kmz")
|
||||
// TODO fix translation for some languages, that doesn't contain holder for filename
|
||||
.setText(context.getString(R.string.share_bookmarks_email_body, name))
|
||||
.setSubject(R.string.share_bookmarks_email_subject));
|
||||
}
|
||||
|
||||
public static void shareViralEditor(Activity context, @DrawableRes int imageId, @StringRes int subject, @StringRes int text)
|
||||
|
|
Loading…
Add table
Reference in a new issue