forked from organicmaps/organicmaps
[android] Fix editing category/bookmark params without saving category on every letter input.
This commit is contained in:
parent
f4ab0a6827
commit
5ac4f5ff02
3 changed files with 60 additions and 74 deletions
|
@ -236,7 +236,8 @@ public class DownloadResourcesActivity extends Activity implements LocationServi
|
|||
Intent mwmActivityIntent = new Intent(this, MWMActivity.class);
|
||||
|
||||
// Disable animation because MWMActivity should appear exactly over this one
|
||||
mwmActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
|
||||
// Intent.FLAG_ACTIVITY_REORDER_TO_FRONT
|
||||
mwmActivityIntent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||
startActivity(mwmActivityIntent);
|
||||
|
||||
finish();
|
||||
|
|
|
@ -41,11 +41,8 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
private int mCurrentCategoryId = -1;
|
||||
private List<Icon> mIcons;
|
||||
private ImageView mChooserImage;
|
||||
private IconsAdapter mIconsAdapter;
|
||||
private EditText mDescr;
|
||||
|
||||
private TextWatcher mNameWatcher;
|
||||
private TextWatcher mDescrWatcher;
|
||||
private Icon m_icon = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
|
@ -64,15 +61,15 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
setUpViews();
|
||||
}
|
||||
|
||||
private void updateColorChooser(int position)
|
||||
private void updateColorChooser(Icon icon)
|
||||
{
|
||||
mChooserImage.setImageBitmap(mIcons.get(position).getIcon());
|
||||
//mChooserName.setText(mIcons.get(position).getName());
|
||||
m_icon = icon;
|
||||
mChooserImage.setImageBitmap(m_icon.getIcon());
|
||||
}
|
||||
|
||||
private void refreshValuesInViews()
|
||||
{
|
||||
updateColorChooser(mIcons.indexOf(mPin.getIcon()));
|
||||
updateColorChooser(mPin.getIcon());
|
||||
|
||||
mSetName.setText(mPin.getCategoryName());
|
||||
|
||||
|
@ -90,7 +87,6 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
colorChooser.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
|
@ -100,7 +96,6 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
findViewById(R.id.pin_sets).setOnClickListener(new OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
|
@ -117,14 +112,15 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
refreshValuesInViews();
|
||||
|
||||
mNameWatcher = new TextWatcher()
|
||||
mName.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
final String str = s.toString();
|
||||
mPin.setName(str);
|
||||
setTitle(str);
|
||||
setTitle(s.toString());
|
||||
|
||||
// Note! Do not set actual name here - saving process may be too long
|
||||
// see assignPinParams() instead.
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
|
@ -134,52 +130,32 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
mDescrWatcher = new TextWatcher()
|
||||
private void assignPinParams()
|
||||
{
|
||||
if (mPin != null)
|
||||
{
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
mPin.setDescription(s.toString());
|
||||
}
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{
|
||||
}
|
||||
@Override
|
||||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
}
|
||||
};
|
||||
String s = mName.getText().toString();
|
||||
if (!s.equals(mPin.getName()))
|
||||
mPin.setName(s);
|
||||
|
||||
// Set up text watchers only after filling text fields
|
||||
}
|
||||
s = mDescr.getText().toString();
|
||||
if (!s.equals(mPin.getBookmarkDescription()))
|
||||
mPin.setDescription(s);
|
||||
|
||||
private void setUpWatchers()
|
||||
{
|
||||
mName.addTextChangedListener(mNameWatcher);
|
||||
mDescr.addTextChangedListener(mDescrWatcher);
|
||||
}
|
||||
|
||||
private void removeWatchers()
|
||||
{
|
||||
mName.removeTextChangedListener(mNameWatcher);
|
||||
mDescr.removeTextChangedListener(mDescrWatcher);
|
||||
if (m_icon != null && m_icon != mPin.getIcon())
|
||||
mPin.setIcon(m_icon);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
protected void onPause()
|
||||
{
|
||||
super.onStart();
|
||||
setUpWatchers();
|
||||
}
|
||||
assignPinParams();
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
removeWatchers();
|
||||
super.onStop();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -191,7 +167,6 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
AlertDialog.Builder builder = new Builder(this);
|
||||
builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
|
@ -200,11 +175,11 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
});
|
||||
builder.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
mManager.deleteBookmark(mPin);
|
||||
mPin = null;
|
||||
dialog.dismiss();
|
||||
finish();
|
||||
}
|
||||
|
@ -224,19 +199,17 @@ public class BookmarkActivity extends AbstractBookmarkActivity
|
|||
|
||||
private Dialog createColorChooser()
|
||||
{
|
||||
mIconsAdapter = new IconsAdapter(this, mIcons);
|
||||
mIconsAdapter.chooseItem(mIcons.indexOf(mPin.getIcon()));
|
||||
final IconsAdapter adapter = new IconsAdapter(this, mIcons);
|
||||
adapter.chooseItem(mIcons.indexOf(mPin.getIcon()));
|
||||
|
||||
return new AlertDialog.Builder(this)
|
||||
.setTitle(R.string.bookmark_color)
|
||||
.setSingleChoiceItems(mIconsAdapter, mIconsAdapter.getCheckedItemPosition(), new DialogInterface.OnClickListener()
|
||||
.setSingleChoiceItems(adapter, adapter.getCheckedItemPosition(), new DialogInterface.OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which)
|
||||
{
|
||||
mPin.setIcon(mIcons.get(which));
|
||||
mIconsAdapter.chooseItem(which);
|
||||
updateColorChooser(which);
|
||||
updateColorChooser(mIcons.get(which));
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
|
|
|
@ -14,8 +14,6 @@ import android.view.View;
|
|||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.CompoundButton.OnCheckedChangeListener;
|
||||
import android.widget.EditText;
|
||||
|
||||
import com.mapswithme.maps.MWMActivity;
|
||||
|
@ -42,6 +40,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.bookmarks_list);
|
||||
final int setIndex = getIntent().getIntExtra(BookmarkActivity.PIN_SET, -1);
|
||||
mEditContent = getIntent().getBooleanExtra(EDIT_CONTENT, true);
|
||||
|
@ -82,6 +81,20 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
mPinAdapter.startLocationUpdate();
|
||||
}
|
||||
|
||||
private void assignCategoryParams()
|
||||
{
|
||||
if (mEditedSet != null)
|
||||
{
|
||||
final String name = mSetName.getText().toString();
|
||||
if (!name.equals(mEditedSet.getName()))
|
||||
mManager.setCategoryName(mEditedSet, name);
|
||||
|
||||
final boolean visible = mIsVisible.isChecked();
|
||||
if (visible != mEditedSet.isVisible())
|
||||
mEditedSet.setVisibility(mIsVisible.isChecked());
|
||||
}
|
||||
}
|
||||
|
||||
private void setUpViews()
|
||||
{
|
||||
mSetName = (EditText) findViewById(R.id.pin_set_name);
|
||||
|
@ -93,9 +106,10 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
final String name = s.toString();
|
||||
mManager.setCategoryName(mEditedSet, name);
|
||||
setTitle(name);
|
||||
setTitle(s.toString());
|
||||
|
||||
// Note! Do not set actual name here - saving process may be too long
|
||||
// see assignCategoryParams() instead.
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -112,15 +126,6 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
mIsVisible = (CheckBox) findViewById(R.id.pin_set_visible);
|
||||
if (mEditedSet != null)
|
||||
mIsVisible.setChecked(mEditedSet.isVisible());
|
||||
mIsVisible.setOnCheckedChangeListener(new OnCheckedChangeListener()
|
||||
{
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked)
|
||||
{
|
||||
if (mEditedSet != null)
|
||||
mEditedSet.setVisibility(isChecked);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -128,6 +133,8 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
{
|
||||
if (mEditContent)
|
||||
{
|
||||
assignCategoryParams();
|
||||
|
||||
if (menuInfo instanceof AdapterView.AdapterContextMenuInfo)
|
||||
{
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
|
@ -136,6 +143,7 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
inflater.inflate(R.menu.pin_sets_context_menu, menu);
|
||||
menu.setHeaderTitle(mManager.getBookmark(mEditedSet.getId(), mSelectedPosition).getName());
|
||||
}
|
||||
|
||||
super.onCreateContextMenu(menu, v, menuInfo);
|
||||
}
|
||||
}
|
||||
|
@ -174,6 +182,8 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
assignCategoryParams();
|
||||
|
||||
if (mPinAdapter != null)
|
||||
mPinAdapter.stopLocationUpdate();
|
||||
|
||||
|
@ -191,6 +201,8 @@ public class BookmarkListActivity extends AbstractBookmarkListActivity
|
|||
|
||||
public void onSendEMail(View v)
|
||||
{
|
||||
assignCategoryParams();
|
||||
|
||||
String path = ((MWMApplication) getApplication()).getExtAppDirectoryPath("tmp");
|
||||
final String name = mManager.saveToKMZFile(mEditedSet.getId(), path);
|
||||
if (name == null)
|
||||
|
|
Loading…
Add table
Reference in a new issue