[android] Ui to select feature category.

This commit is contained in:
Dmitry Yunitsky 2016-03-14 10:27:55 +03:00 committed by Sergey Yershov
parent 2cbca40214
commit 1b5170344a
8 changed files with 231 additions and 6 deletions

View file

@ -249,6 +249,16 @@
android:value="com.mapswithme.maps.settings.SettingsActivity"/>
</activity>
<activity
android:name="com.mapswithme.maps.editor.FeatureCategoryActivity"
android:parentActivityName="com.mapswithme.maps.MwmActivity">
<!-- The meta-data element is needed for versions lower than 4.1 -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mapswithme.maps.settings.SettingsActivity"/>
</activity>
<!-- facebook -->
<activity
android:name="com.facebook.FacebookActivity"

View file

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/height_item_oneline"
android:background="?clickableBackground"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="@dimen/margin_base">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:singleLine="true"
android:textAppearance="@style/MwmTextAppearance.Body1"/>
<ImageView
android:id="@+id/selected"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/margin_base"
android:layout_marginRight="@dimen/margin_base"
android:src="@drawable/ic_checkmark"
android:tint="?iconTint"/>
</LinearLayout>

View file

@ -46,6 +46,7 @@ import com.mapswithme.maps.editor.AuthFragment;
import com.mapswithme.maps.editor.Editor;
import com.mapswithme.maps.editor.EditorActivity;
import com.mapswithme.maps.editor.EditorHostFragment;
import com.mapswithme.maps.editor.FeatureCategoryActivity;
import com.mapswithme.maps.location.LocationHelper;
import com.mapswithme.maps.location.LocationPredictor;
import com.mapswithme.maps.news.FirstStartFragment;
@ -382,9 +383,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
showPositionChooser(false);
if (Framework.nativeIsScreenCenterDownloaded())
{
// TODO create feature and display edit featureType dialog
}
FeatureCategoryActivity.pickFeatureCategory(MwmActivity.this, Framework.nativeGetScreenRectCenter());
else
// UiUtils.showAlertDialog(getActivity(), R.string.message_invalid_feature_position);
UiUtils.showAlertDialog(getActivity(), R.string.invalid_username_or_password);

View file

@ -6,10 +6,11 @@ import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
import com.mapswithme.maps.bookmarks.data.MapObject;
public class EditorActivity extends BaseMwmFragmentActivity
{
public static final String EXTRA_NEW_OBJECT = "ExtraNewMapObject";
@Override
protected Class<? extends Fragment> getFragmentClass()
{

View file

@ -2,6 +2,7 @@ package com.mapswithme.maps.editor;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.annotation.StringRes;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
@ -20,6 +21,7 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
implements OnBackPressListener, View.OnClickListener
{
private static final String PREF_LAST_AUTH_DISPLAY_TIMESTAMP = "LastAuth";
private boolean mIsNewObject;
enum Mode
{
@ -52,6 +54,17 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
onBackPressed();
}
});
if (getArguments() != null)
mIsNewObject = getArguments().getBoolean(EditorActivity.EXTRA_NEW_OBJECT, false);
mToolbarController.setTitle(getTitle());
}
@StringRes
private int getTitle()
{
// TODO return other resid for add place mode
return mIsNewObject ? R.string.edit_place : R.string.edit_place;
}
@Override
@ -80,13 +93,12 @@ public class EditorHostFragment extends BaseMwmToolbarFragment
protected void editMapObject()
{
mMode = Mode.MAP_OBJECT;
mToolbarController.setTitle(R.string.edit_place);
mToolbarController.setTitle(getTitle());
final Fragment editorFragment = Fragment.instantiate(getActivity(), EditorFragment.class.getName());
getChildFragmentManager().beginTransaction()
.replace(R.id.fragment_container, editorFragment, EditorFragment.class.getName())
.commit();
}
protected void editTimetable()
{
temporaryStoreEdits();

View file

@ -0,0 +1,55 @@
package com.mapswithme.maps.editor;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Size;
import android.support.v4.app.Fragment;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.base.BaseToolbarActivity;
import com.mapswithme.maps.editor.data.FeatureCategory;
public class FeatureCategoryActivity extends BaseToolbarActivity implements FeatureCategoryFragment.FeatureCategoryListener
{
public static final String EXTRA_FEATURE_CATEGORY = "FeatureCategory";
public static final String EXTRA_LAT_LON = "LatLon";
private double[] mLatLon;
public static void pickFeatureCategory(MwmActivity parent, @Size(2) double[] rect)
{
final Intent intent = new Intent(parent, FeatureCategoryActivity.class);
intent.putExtra(EXTRA_LAT_LON, rect);
parent.startActivity(intent);
}
@Override
protected void onCreate(Bundle state)
{
super.onCreate(state);
mLatLon = getIntent().getDoubleArrayExtra(EXTRA_LAT_LON);
}
@Override
protected Class<? extends Fragment> getFragmentClass()
{
return FeatureCategoryFragment.class;
}
@Override
protected int getToolbarTitle()
{
// TODO set correct text
return super.getToolbarTitle();
}
@Override
public void onFeatureCategorySelected(FeatureCategory category)
{
Editor.createMapObject(category, mLatLon);
final Intent intent = new Intent(this, EditorActivity.class);
intent.putExtra(EXTRA_FEATURE_CATEGORY, category);
intent.putExtra(EditorActivity.EXTRA_NEW_OBJECT, true);
startActivity(intent);
}
}

View file

@ -0,0 +1,78 @@
package com.mapswithme.maps.editor;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import com.mapswithme.maps.R;
import com.mapswithme.maps.editor.data.FeatureCategory;
import com.mapswithme.util.UiUtils;
public class FeatureCategoryAdapter extends RecyclerView.Adapter<FeatureCategoryAdapter.FeatureViewHolder>
{
private final FeatureCategory[] mCategories;
private final FeatureCategoryFragment mFragment;
private FeatureCategory mSelectedCategory;
public FeatureCategoryAdapter(@NonNull FeatureCategoryFragment host, @NonNull FeatureCategory[] categories, @Nullable FeatureCategory category)
{
mFragment = host;
mCategories = categories;
mSelectedCategory = category;
}
@Override
public FeatureViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
{
return new FeatureViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.item_feature_category, parent, false));
}
@Override
public void onBindViewHolder(FeatureViewHolder holder, int position)
{
holder.bind(position);
}
@Override
public int getItemCount()
{
return mCategories.length;
}
protected class FeatureViewHolder extends RecyclerView.ViewHolder
{
TextView name;
View selected;
public FeatureViewHolder(View itemView)
{
super(itemView);
name = (TextView) itemView.findViewById(R.id.name);
selected = itemView.findViewById(R.id.selected);
UiUtils.hide(selected);
itemView.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
onCategorySelected(getAdapterPosition());
}
});
}
public void bind(int position)
{
name.setText(mCategories[position].name);
UiUtils.showIf(mSelectedCategory != null && mCategories[position].category == mSelectedCategory.category);
}
}
private void onCategorySelected(int adapterPosition)
{
mFragment.selectCategory(mCategories[adapterPosition]);
}
}

View file

@ -0,0 +1,42 @@
package com.mapswithme.maps.editor;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
import com.mapswithme.maps.editor.data.FeatureCategory;
public class FeatureCategoryFragment extends BaseMwmRecyclerFragment
{
private FeatureCategory mSelectedCategory;
public interface FeatureCategoryListener
{
void onFeatureCategorySelected(FeatureCategory category);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
if (getArguments() != null && getArguments().containsKey(FeatureCategoryActivity.EXTRA_FEATURE_CATEGORY))
mSelectedCategory = getArguments().getParcelable(FeatureCategoryActivity.EXTRA_FEATURE_CATEGORY);
return super.onCreateView(inflater, container, savedInstanceState);
}
@Override
protected RecyclerView.Adapter createAdapter()
{
return new FeatureCategoryAdapter(this, Editor.nativeGetNewFeatureCategories(), mSelectedCategory);
}
public void selectCategory(FeatureCategory category)
{
if (getActivity() instanceof FeatureCategoryListener)
((FeatureCategoryListener) getActivity()).onFeatureCategorySelected(category);
else if (getParentFragment() instanceof FeatureCategoryListener)
((FeatureCategoryListener) getParentFragment()).onFeatureCategorySelected(category);
}
}