forked from organicmaps/organicmaps
[android] Added edit screens - boomkmark category content
This commit is contained in:
parent
fa2f6aeae6
commit
6988249795
11 changed files with 428 additions and 24 deletions
|
@ -463,6 +463,14 @@
|
|||
<activity
|
||||
android:name="com.mapswithme.maps.bookmarks.PlaceDescriptionActivity"
|
||||
android:label="@string/place_description_title"/>
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.ugc.routes.EditCategoryNameActivity"
|
||||
android:label="@string/name"/>
|
||||
|
||||
<activity
|
||||
android:name="com.mapswithme.maps.ugc.routes.EditCategoryDescriptionActivity"
|
||||
android:label="@string/name"/>
|
||||
|
||||
<service
|
||||
android:name="com.mapswithme.maps.background.WorkerService"
|
||||
android:permission="android.permission.BIND_JOB_SERVICE"
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
style="@style/MwmWidget.ToolbarStyle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?colorPrimary"
|
||||
android:gravity="end|center_vertical"
|
||||
android:theme="@style/MwmWidget.ToolbarTheme"
|
||||
tools:ignore="UnusedAttribute">
|
||||
</android.support.v7.widget.Toolbar>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:minHeight="@dimen/height_block_base"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingBottom="@dimen/bookmark_hide_btn_padding_top"
|
||||
android:paddingTop="@dimen/margin_half_plus"
|
||||
android:background="?attr/cardBackground"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<EditText
|
||||
android:id="@+id/edit_text_field"
|
||||
android:layout_weight="1"
|
||||
android:layout_width="match_parent"
|
||||
android:background="@null"
|
||||
android:layout_height="0dp"/>
|
||||
<View
|
||||
android:background="?attr/iconTintDisabled"
|
||||
android:layout_marginTop="@dimen/margin_half"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="@dimen/divider_height"/>
|
||||
<TextView
|
||||
android:id="@+id/characters_amount"
|
||||
android:layout_gravity="end"
|
||||
android:gravity="end"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"/>
|
||||
</LinearLayout>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<TextView
|
||||
android:id="@+id/summary"
|
||||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingTop="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
android:paddingBottom="@dimen/margin_base"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
|
@ -34,11 +34,13 @@
|
|||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:text="@string/limited_access"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"/>
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<RelativeLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
@ -146,11 +148,13 @@
|
|||
android:gravity="center_vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:fontFamily="@string/robotoMedium"
|
||||
android:text="@string/public_access"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:paddingRight="@dimen/margin_base"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingLeft="@dimen/margin_base"/>
|
||||
android:paddingLeft="@dimen/margin_base"
|
||||
tools:ignore="UnusedAttribute"/>
|
||||
<include layout="@layout/list_divider"/>
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
10
android/res/menu/menu_bookmark_category_restriction.xml
Normal file
10
android/res/menu/menu_bookmark_category_restriction.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
app:showAsAction="always"
|
||||
android:id="@+id/done"
|
||||
android:title="@string/done"
|
||||
android:icon="@drawable/ic_done"/>
|
||||
</menu>
|
|
@ -0,0 +1,171 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.text.Editable;
|
||||
import android.text.InputFilter;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmToolbarFragment;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkCategory;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public abstract class BaseEditUserBookmarkCategoryFragment extends BaseMwmToolbarFragment
|
||||
{
|
||||
public static final String FORMAT_TEMPLATE = "%d / %d";
|
||||
public static final String BUNDLE_BOOKMARK_CATEGORY = "category";
|
||||
public static final String TEXT_LENGTH_LIMIT = "text_length_limit";
|
||||
private static final int DEFAULT_TEXT_LENGTH_LIMIT = 42;
|
||||
public static final String BREAK_LINE_CHAR = "\n";
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private EditText mEditText;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private TextView mCharactersAmountText;
|
||||
private int mTextLimit;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private BookmarkCategory mCategory;
|
||||
|
||||
@Override
|
||||
public void onCreate(@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Bundle args = Objects.requireNonNull(getArguments());
|
||||
mCategory = Objects.requireNonNull(args.getParcelable(BUNDLE_BOOKMARK_CATEGORY));
|
||||
mTextLimit = args.getInt(TEXT_LENGTH_LIMIT, getDefaultTextLengthLimit());
|
||||
}
|
||||
|
||||
protected int getDefaultTextLengthLimit()
|
||||
{
|
||||
return DEFAULT_TEXT_LENGTH_LIMIT;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
|
||||
@Nullable Bundle savedInstanceState)
|
||||
{
|
||||
View root = inflater.inflate(R.layout.fragment_bookmark_category_restriction, container,
|
||||
false);
|
||||
setHasOptionsMenu(true);
|
||||
mEditText = root.findViewById(R.id.edit_text_field);
|
||||
InputFilter[] inputFilters = { new InputFilter.LengthFilter(mTextLimit) };
|
||||
mEditText.setFilters(inputFilters);
|
||||
mEditText.setText(getEditableText());
|
||||
mEditText.addTextChangedListener(new TextRestrictionWatcher());
|
||||
mCharactersAmountText = root.findViewById(R.id.characters_amount);
|
||||
mCharactersAmountText.setText(makeFormattedCharsAmount(getEditableText(), mTextLimit));
|
||||
TextView titleView = root.findViewById(R.id.title);
|
||||
titleView.setText(getTitleText());
|
||||
TextView summaryView = root.findViewById(R.id.summary);
|
||||
summaryView.setText(getTopSummaryText());
|
||||
summaryView.append(BREAK_LINE_CHAR);
|
||||
summaryView.append(getBottomSummaryText());
|
||||
return root;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract CharSequence getTopSummaryText();
|
||||
|
||||
@NonNull
|
||||
protected abstract CharSequence getBottomSummaryText();
|
||||
|
||||
@StringRes
|
||||
protected abstract int getTitleText();
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
inflater.inflate(R.menu.menu_bookmark_category_restriction, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == Activity.RESULT_OK)
|
||||
getActivity().setResult(Activity.RESULT_OK, data);
|
||||
|
||||
getActivity().finish();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == R.id.done)
|
||||
{
|
||||
onDoneOptionItemClicked();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected BookmarkCategory getCategory()
|
||||
{
|
||||
return mCategory;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected EditText getEditText()
|
||||
{
|
||||
return mEditText;
|
||||
}
|
||||
|
||||
protected abstract void onDoneOptionItemClicked();
|
||||
|
||||
@NonNull
|
||||
protected abstract CharSequence getEditableText();
|
||||
|
||||
@NonNull
|
||||
private static String makeFormattedCharsAmount(CharSequence s, int limit)
|
||||
{
|
||||
return String.format(Locale.US, FORMAT_TEMPLATE, Math.min(s.length(), limit), limit);
|
||||
}
|
||||
|
||||
private class TextRestrictionWatcher implements TextWatcher
|
||||
{
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
if (before + s.length() == 1)
|
||||
ActivityCompat.invalidateOptionsMenu(getActivity());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
String src = makeFormattedCharsAmount(s, mTextLimit);
|
||||
mCharactersAmountText.setText(src);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
|
||||
public class EditCategoryDescriptionActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return EditCategoryDescriptionFragment.class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public class EditCategoryDescriptionFragment extends BaseEditUserBookmarkCategoryFragment
|
||||
{
|
||||
|
||||
public static final int REQUEST_CODE_CUSTOM_PROPS = 100;
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CharSequence getTopSummaryText()
|
||||
{
|
||||
return getString(R.string.description_comment1);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CharSequence getBottomSummaryText()
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getTitleText()
|
||||
{
|
||||
return R.string.description_title;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDoneOptionItemClicked()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setCategoryDescription(getCategory().getId(),
|
||||
getEditText().getText().toString().trim());
|
||||
Intent intent = new Intent(getContext(), UgcRoutePropertiesActivity.class);
|
||||
startActivityForResult(intent, REQUEST_CODE_CUSTOM_PROPS);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CharSequence getEditableText()
|
||||
{
|
||||
return getCategory().getDescription();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,14 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.support.v4.app.Fragment;
|
||||
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
|
||||
public class EditCategoryNameActivity extends BaseMwmFragmentActivity
|
||||
{
|
||||
@Override
|
||||
protected Class<? extends Fragment> getFragmentClass()
|
||||
{
|
||||
return EditCategoryNameFragment.class;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,54 @@
|
|||
package com.mapswithme.maps.ugc.routes;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.NonNull;
|
||||
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.bookmarks.data.BookmarkManager;
|
||||
|
||||
public class EditCategoryNameFragment extends BaseEditUserBookmarkCategoryFragment
|
||||
{
|
||||
public static final int REQ_CODE_EDIT_DESCRIPTION = 75;
|
||||
|
||||
@Override
|
||||
protected int getTitleText()
|
||||
{
|
||||
return R.string.name_title;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
protected CharSequence getTopSummaryText()
|
||||
{
|
||||
return getString(R.string.name_comment2);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CharSequence getBottomSummaryText()
|
||||
{
|
||||
return getString(R.string.name_comment2);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDoneOptionItemClicked()
|
||||
{
|
||||
BookmarkManager.INSTANCE.setCategoryName(getCategory().getId(),
|
||||
getEditText().getText().toString().trim());
|
||||
openNextScreen();
|
||||
}
|
||||
|
||||
private void openNextScreen()
|
||||
{
|
||||
Intent intent = new Intent(getContext(), EditCategoryDescriptionActivity.class);
|
||||
intent.putExtra(BaseEditUserBookmarkCategoryFragment.BUNDLE_BOOKMARK_CATEGORY, getCategory());
|
||||
startActivityForResult(intent, REQ_CODE_EDIT_DESCRIPTION);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected CharSequence getEditableText()
|
||||
{
|
||||
return getCategory().getName();
|
||||
}
|
||||
}
|
|
@ -96,12 +96,6 @@ public class UgcRouteEditSettingsFragment extends BaseMwmToolbarFragment
|
|||
UgcRouteSharingOptionsActivity.startForResult(getActivity(), mCategory);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
|
||||
{
|
||||
|
|
|
@ -276,7 +276,8 @@ public class UgcSharingOptionsFragment extends BaseToolbarAuthFragment implement
|
|||
|
||||
private void openTagsScreen()
|
||||
{
|
||||
Intent intent = new Intent(getContext(), UgcRoutePropertiesActivity.class);
|
||||
Intent intent = new Intent(getContext(), EditCategoryNameActivity.class);
|
||||
intent.putExtra(EditCategoryNameFragment.BUNDLE_BOOKMARK_CATEGORY, mCategory);
|
||||
startActivityForResult(intent, REQ_CODE_CUSTOM_PROPERTIES);
|
||||
}
|
||||
|
||||
|
@ -558,9 +559,10 @@ public class UgcSharingOptionsFragment extends BaseToolbarAuthFragment implement
|
|||
|
||||
}
|
||||
|
||||
private void showConfirmationDialog(int reqCode, String tag, @StringRes int acceptBtn,
|
||||
@StringRes int declineBtn, @StringRes int title,
|
||||
@StringRes int description)
|
||||
private void showConfirmationDialog(@StringRes int title, @StringRes int description,
|
||||
@StringRes int acceptBtn,
|
||||
@StringRes int declineBtn,
|
||||
String tag, int reqCode)
|
||||
{
|
||||
AlertDialog dialog = new AlertDialog.Builder()
|
||||
.setTitleId(title)
|
||||
|
@ -578,26 +580,32 @@ public class UgcSharingOptionsFragment extends BaseToolbarAuthFragment implement
|
|||
|
||||
private void showHtmlFormattingError()
|
||||
{
|
||||
showConfirmationDialog(REQ_CODE_ERROR_HTML_FORMATTING_DIALOG,
|
||||
ERROR_HTML_FORMATTING_DIALOG_TAG, R.string.html_format_error_title,
|
||||
R.string.html_format_error_title,
|
||||
R.string.edit_on_web, R.string.cancel);
|
||||
showConfirmationDialog(R.string.html_format_error_title,
|
||||
R.string.html_format_error_subtitle,
|
||||
R.string.edit_on_web,
|
||||
R.string.cancel,
|
||||
ERROR_HTML_FORMATTING_DIALOG_TAG,
|
||||
REQ_CODE_ERROR_HTML_FORMATTING_DIALOG
|
||||
);
|
||||
}
|
||||
|
||||
private void showUploadCatalogConfirmationDialog()
|
||||
{
|
||||
showConfirmationDialog(REQ_CODE_UPLOAD_CONFIRMATION_DIALOG,
|
||||
UPLOAD_CONFIRMATION_DIALOG_TAG, R.string.bookmark_public_upload_alert_title,
|
||||
showConfirmationDialog(R.string.bookmark_public_upload_alert_title,
|
||||
R.string.bookmark_public_upload_alert_subtitle,
|
||||
R.string.bookmark_public_upload_alert_ok_button, R.string.cancel);
|
||||
R.string.bookmark_public_upload_alert_ok_button,
|
||||
R.string.cancel,
|
||||
UPLOAD_CONFIRMATION_DIALOG_TAG, REQ_CODE_UPLOAD_CONFIRMATION_DIALOG
|
||||
);
|
||||
}
|
||||
|
||||
private void showUnresolvedConflictsErrorDialog()
|
||||
{
|
||||
showConfirmationDialog(REQ_CODE_UPLOAD_CONFIRMATION_DIALOG,
|
||||
UPLOAD_CONFIRMATION_DIALOG_TAG,
|
||||
R.string.public_or_limited_access_after_edit_online_error_title,
|
||||
R.string.public_or_limited_access_after_edit_online_error_title,
|
||||
R.string.edit_on_web, R.string.cancel);
|
||||
showConfirmationDialog(R.string.public_or_limited_access_after_edit_online_error_title,
|
||||
R.string.public_or_limited_access_after_edit_online_error_message,
|
||||
R.string.edit_on_web,
|
||||
R.string.cancel,
|
||||
UPLOAD_CONFIRMATION_DIALOG_TAG, REQ_CODE_UPLOAD_CONFIRMATION_DIALOG
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue