forked from organicmaps/organicmaps-tmp
android: move place page bookmark in fragment
Also reworked the peek height to work better with lazy loading of webview Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
parent
8b5afb461a
commit
f59ff13283
10 changed files with 316 additions and 242 deletions
|
@ -54,7 +54,7 @@
|
|||
<androidx.core.widget.NestedScrollViewClickFixed
|
||||
android:id="@+id/placepage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
style="?attr/bottomSheetStyle"
|
||||
android:fillViewport="true"
|
||||
app:layout_behavior="@string/placepage_behavior" >
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:descendantFocusability="blocksDescendants"
|
||||
android:orientation="vertical">
|
||||
<include
|
||||
|
@ -14,6 +14,6 @@
|
|||
android:id="@+id/pp__details_frame"
|
||||
layout="@layout/place_page_details"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?panel" />
|
||||
</LinearLayout>
|
||||
|
|
|
@ -2,17 +2,20 @@
|
|||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/bookmark_frame"
|
||||
android:id="@+id/place_page_bookmark_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:visibility="invisible"
|
||||
tools:visibility="visible">
|
||||
android:orientation="vertical">
|
||||
|
||||
<WebView
|
||||
android:id="@+id/wv__bookmark_notes"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/tv__bookmark_edit"
|
||||
style="@style/PlacePageMetadataText.Button"
|
||||
android:gravity="center"
|
||||
android:layout_height="@dimen/height_block_base"
|
||||
android:background="?clickableBackground"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:text="@string/placepage_edit_bookmark_button"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__bookmark_notes"
|
||||
|
@ -25,16 +28,6 @@
|
|||
android:textAppearance="?android:attr/textAppearance"
|
||||
tools:text="Long, long text Long, long text Long, long text Long, long text Long, long text Long, long text "/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv__bookmark_edit"
|
||||
style="@style/PlacePageMetadataText.Button"
|
||||
android:gravity="center"
|
||||
android:layout_height="@dimen/height_block_base"
|
||||
android:background="?clickableBackground"
|
||||
android:paddingEnd="@dimen/margin_base"
|
||||
android:paddingStart="@dimen/margin_base"
|
||||
android:text="@string/placepage_edit_bookmark_button"/>
|
||||
|
||||
<include
|
||||
layout="@layout/divider_horizontal"/>
|
||||
</LinearLayout>
|
|
@ -22,11 +22,11 @@
|
|||
android:visibility="gone"
|
||||
android:layout_height="wrap_content"/>
|
||||
|
||||
<include
|
||||
layout="@layout/place_page_bookmark_details"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:visibility="visible"/>
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/place_page_bookmark_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
tools:layout="@layout/place_page_bookmark_fragment" />
|
||||
|
||||
<include
|
||||
layout="@layout/place_page_description_layout"
|
||||
|
|
|
@ -1825,9 +1825,9 @@ public class MwmActivity extends BaseMwmFragmentActivity
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlacePageHeightChange(int previewHeight)
|
||||
public void onPlacePageContentChanged(int previewHeight)
|
||||
{
|
||||
mPlacePageController.onPlacePageHeightChange(previewHeight);
|
||||
mPlacePageController.onPlacePageContentChanged(previewHeight);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -40,7 +40,10 @@ public class DefaultBottomSheetCallback extends BottomSheetBehavior.BottomSheetC
|
|||
return;
|
||||
}
|
||||
|
||||
mSheetChangedListener.onSheetCollapsed();
|
||||
if (PlacePageUtils.isCollapsedState(newState))
|
||||
{
|
||||
mSheetChangedListener.onSheetCollapsed();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,178 @@
|
|||
package app.organicmaps.widget.placepage;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Base64;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.bookmarks.data.Bookmark;
|
||||
import app.organicmaps.bookmarks.data.BookmarkManager;
|
||||
import app.organicmaps.bookmarks.data.MapObject;
|
||||
import app.organicmaps.util.StringUtils;
|
||||
import app.organicmaps.util.UiUtils;
|
||||
import app.organicmaps.util.Utils;
|
||||
import app.organicmaps.util.log.Logger;
|
||||
|
||||
public class PlacePageBookmarkFragment extends Fragment implements View.OnClickListener,
|
||||
View.OnLongClickListener,
|
||||
Observer<MapObject>,
|
||||
EditBookmarkFragment.EditBookmarkListener
|
||||
{
|
||||
private static final String TAG = PlacePageBookmarkFragment.class.getSimpleName();
|
||||
|
||||
private View mFrame;
|
||||
private TextView mTvBookmarkNote;
|
||||
@Nullable
|
||||
private WebView mWvBookmarkNote;
|
||||
|
||||
private PlacePageViewModel viewModel;
|
||||
|
||||
// TODO description header is not shown
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.place_page_bookmark_fragment, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
mFrame = view;
|
||||
mTvBookmarkNote = mFrame.findViewById(R.id.tv__bookmark_notes);
|
||||
mTvBookmarkNote.setOnLongClickListener(this);
|
||||
final View editBookmarkBtn = mFrame.findViewById(R.id.tv__bookmark_edit);
|
||||
editBookmarkBtn.setOnClickListener(this);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(PlacePageViewModel.class);
|
||||
viewModel.getMapObject().observe(requireActivity(), this);
|
||||
}
|
||||
|
||||
private void initWebView()
|
||||
{
|
||||
if (mWvBookmarkNote != null)
|
||||
return;
|
||||
mWvBookmarkNote = new WebView(requireContext());
|
||||
final WebSettings settings = mWvBookmarkNote.getSettings();
|
||||
settings.setJavaScriptEnabled(false);
|
||||
settings.setDefaultTextEncodingName("UTF-8");
|
||||
final LinearLayout linearLayout = mFrame.findViewById(R.id.place_page_bookmark_layout);
|
||||
// Add the webview in last position
|
||||
linearLayout.addView(mWvBookmarkNote, linearLayout.getChildCount() - 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private MapObject getMapObject()
|
||||
{
|
||||
if (viewModel != null)
|
||||
return viewModel.getMapObject().getValue();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
viewModel.getMapObject().removeObserver(this);
|
||||
}
|
||||
|
||||
private void updateBookmarkDetails(@NonNull MapObject mapObject)
|
||||
{
|
||||
if (mapObject.getMapObjectType() != MapObject.BOOKMARK)
|
||||
return;
|
||||
|
||||
final String notes = ((Bookmark) mapObject).getBookmarkDescription();
|
||||
if (TextUtils.isEmpty(notes))
|
||||
{
|
||||
UiUtils.hide(mTvBookmarkNote);
|
||||
if (mWvBookmarkNote != null)
|
||||
UiUtils.hide(mWvBookmarkNote);
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtils.nativeIsHtml(notes))
|
||||
{
|
||||
// According to loadData documentation, HTML should be either base64 or percent encoded.
|
||||
// Default UTF-8 encoding for all content is set above in WebSettings.
|
||||
initWebView();
|
||||
if (mWvBookmarkNote != null)
|
||||
{
|
||||
final String b64encoded = Base64.encodeToString(notes.getBytes(), Base64.DEFAULT);
|
||||
mWvBookmarkNote.loadData(b64encoded, Utils.TEXT_HTML, "base64");
|
||||
UiUtils.show(mWvBookmarkNote);
|
||||
UiUtils.hide(mTvBookmarkNote);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mTvBookmarkNote.setText(notes);
|
||||
Linkify.addLinks(mTvBookmarkNote, Linkify.ALL);
|
||||
UiUtils.show(mTvBookmarkNote);
|
||||
if (mWvBookmarkNote != null)
|
||||
UiUtils.hide(mWvBookmarkNote);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
{
|
||||
Logger.e(TAG, "A bookmark cannot be edited, mMapObject is null!");
|
||||
return;
|
||||
}
|
||||
Bookmark bookmark = (Bookmark) mapObject;
|
||||
EditBookmarkFragment.editBookmark(bookmark.getCategoryId(),
|
||||
bookmark.getBookmarkId(),
|
||||
requireActivity(),
|
||||
requireActivity().getSupportFragmentManager(),
|
||||
PlacePageBookmarkFragment.this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onLongClick(View v)
|
||||
{
|
||||
final String notes = mTvBookmarkNote.getText().toString();
|
||||
|
||||
final Context ctx = requireContext();
|
||||
Utils.copyTextToClipboard(ctx, notes);
|
||||
Utils.showSnackbarAbove(mFrame,
|
||||
mFrame.getRootView().findViewById(R.id.pp_buttons_layout),
|
||||
ctx.getString(R.string.copied_to_clipboard, notes));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(MapObject mapObject)
|
||||
{
|
||||
if (mapObject != null)
|
||||
updateBookmarkDetails(mapObject);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarkSaved(long bookmarkId, boolean movedFromCategory)
|
||||
{
|
||||
Bookmark updatedBookmark = BookmarkManager.INSTANCE.updateBookmarkPlacePage(bookmarkId);
|
||||
if (updatedBookmark == null)
|
||||
return;
|
||||
viewModel.setMapObject(updatedBookmark);
|
||||
}
|
||||
}
|
|
@ -23,7 +23,6 @@ import app.organicmaps.settings.RoadType;
|
|||
import app.organicmaps.util.UiUtils;
|
||||
import app.organicmaps.util.bottomsheet.MenuBottomSheetFragment;
|
||||
import app.organicmaps.util.bottomsheet.MenuBottomSheetItem;
|
||||
import app.organicmaps.util.log.Logger;
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
@ -55,40 +54,8 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
private final PlacePageViewModel viewModel;
|
||||
private int mPreviewHeight;
|
||||
private boolean mDeactivateMapSelection = true;
|
||||
@NonNull
|
||||
private final BottomSheetChangedListener mBottomSheetChangedListener = new BottomSheetChangedListener()
|
||||
{
|
||||
@Override
|
||||
public void onSheetHidden()
|
||||
{
|
||||
onHiddenInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetDetailsOpened()
|
||||
{
|
||||
// No op.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetCollapsed()
|
||||
{
|
||||
// No op.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetSliding(int top)
|
||||
{
|
||||
mSlideListener.onPlacePageSlide(top);
|
||||
// mPlacePageTracker.onMove();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetSlideFinish()
|
||||
{
|
||||
PlacePageUtils.moveViewportUp(mPlacePage, mViewportMinHeight);
|
||||
}
|
||||
};
|
||||
@Nullable
|
||||
private MapObject mMapObject;
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
public PlacePageController(@Nullable Activity activity,
|
||||
|
@ -102,10 +69,43 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
mViewportMinHeight = res.getDimensionPixelSize(R.dimen.viewport_min_height);
|
||||
mPlacePage = activity.findViewById(R.id.placepage);
|
||||
mPlacePageBehavior = BottomSheetBehavior.from(mPlacePage);
|
||||
BottomSheetBehavior.BottomSheetCallback sheetCallback = new DefaultBottomSheetCallback(mBottomSheetChangedListener);
|
||||
BottomSheetChangedListener bottomSheetChangedListener = new BottomSheetChangedListener()
|
||||
{
|
||||
@Override
|
||||
public void onSheetHidden()
|
||||
{
|
||||
onHiddenInternal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetDetailsOpened()
|
||||
{
|
||||
// No op.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetCollapsed()
|
||||
{
|
||||
disableHalfExpandedState();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetSliding(int top)
|
||||
{
|
||||
mSlideListener.onPlacePageSlide(top);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSheetSlideFinish()
|
||||
{
|
||||
PlacePageUtils.moveViewportUp(mPlacePage, mViewportMinHeight);
|
||||
}
|
||||
};
|
||||
BottomSheetBehavior.BottomSheetCallback sheetCallback = new DefaultBottomSheetCallback(bottomSheetChangedListener);
|
||||
mPlacePageBehavior.addBottomSheetCallback(sheetCallback);
|
||||
mPlacePageBehavior.setHideable(true);
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_HIDDEN);
|
||||
disableHalfExpandedState();
|
||||
|
||||
UiUtils.bringViewToFrontOf(activity.findViewById(R.id.pp_buttons_fragment), mPlacePage);
|
||||
|
||||
|
@ -116,6 +116,12 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
viewModel = new ViewModelProvider(mMwmActivity).get(PlacePageViewModel.class);
|
||||
}
|
||||
|
||||
private void disableHalfExpandedState()
|
||||
{
|
||||
// Use a very low value so that is less than the collapsed value and this state is skipped
|
||||
mPlacePageBehavior.setHalfExpandedRatio(0.001f);
|
||||
}
|
||||
|
||||
private void onHiddenInternal()
|
||||
{
|
||||
if (mDeactivateMapSelection)
|
||||
|
@ -123,6 +129,7 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
mDeactivateMapSelection = true;
|
||||
PlacePageUtils.moveViewportUp(mPlacePage, mViewportMinHeight);
|
||||
viewModel.setMapObject(null);
|
||||
disableHalfExpandedState();
|
||||
}
|
||||
|
||||
public int getPlacePageWidth()
|
||||
|
@ -170,21 +177,7 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
|
||||
private int calculatePeekHeight()
|
||||
{
|
||||
final int organicPeekHeight = (int) (mPreviewHeight + mButtonsHeight);
|
||||
final MapObject mapObject = viewModel.getMapObject().getValue();
|
||||
if (mapObject != null)
|
||||
{
|
||||
@MapObject.OpeningMode
|
||||
int mode = mapObject.getOpeningMode();
|
||||
if (mode == MapObject.OPENING_MODE_PREVIEW_PLUS)
|
||||
{
|
||||
View parent = (View) mPlacePage.getParent();
|
||||
int promoPeekHeight = (int) (parent.getHeight() * PREVIEW_PLUS_RATIO);
|
||||
return Math.max(promoPeekHeight, organicPeekHeight);
|
||||
}
|
||||
}
|
||||
|
||||
return organicPeekHeight;
|
||||
return (int) (mPreviewHeight + mButtonsHeight);
|
||||
}
|
||||
|
||||
public void close(boolean deactivateMapSelection)
|
||||
|
@ -214,17 +207,21 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void onPlacePageHeightChange(int previewHeight)
|
||||
public void onPlacePageContentChanged(int previewHeight)
|
||||
{
|
||||
mPreviewHeight = previewHeight;
|
||||
// Using .post() makes sure the peek height animation plays
|
||||
mPlacePage.post(() -> {
|
||||
setPeekHeight();
|
||||
// Only show the place page if it was hidden
|
||||
@BottomSheetBehavior.State
|
||||
int state = mPlacePageBehavior.getState();
|
||||
if (PlacePageUtils.isHiddenState(state))
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
if (mMapObject != null)
|
||||
{
|
||||
if (mMapObject.getOpeningMode() == MapObject.OPENING_MODE_PREVIEW_PLUS)
|
||||
{
|
||||
mPlacePageBehavior.setHalfExpandedRatio(PREVIEW_PLUS_RATIO);
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_HALF_EXPANDED);
|
||||
}
|
||||
else if (!PlacePageUtils.isCollapsedState(mPlacePageBehavior.getState()))
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -239,7 +236,7 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
{
|
||||
@BottomSheetBehavior.State
|
||||
int state = mPlacePageBehavior.getState();
|
||||
if (PlacePageUtils.isCollapsedState(state))
|
||||
if (PlacePageUtils.isCollapsedState(state) || PlacePageUtils.isHalfExpandedState(state))
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
else if (PlacePageUtils.isExpandedState(state))
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
|
@ -262,10 +259,11 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
|
||||
private void onMapObjectChange(@Nullable MapObject mapObject)
|
||||
{
|
||||
if (mapObject == null)
|
||||
mMapObject = mapObject;
|
||||
if (mMapObject == null)
|
||||
{
|
||||
Fragment placePageButtonsFragment = mMwmActivity.getSupportFragmentManager()
|
||||
.findFragmentByTag(PLACE_PAGE_BUTTONS_FRAGMENT_TAG);
|
||||
.findFragmentByTag(PLACE_PAGE_BUTTONS_FRAGMENT_TAG);
|
||||
if (placePageButtonsFragment != null)
|
||||
{
|
||||
mMwmActivity.getSupportFragmentManager().beginTransaction()
|
||||
|
@ -283,11 +281,6 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
}
|
||||
else
|
||||
{
|
||||
if (mapObject.getOpeningMode() == MapObject.OPENING_MODE_DETAILS)
|
||||
{
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
return;
|
||||
}
|
||||
if (mMwmActivity.getSupportFragmentManager()
|
||||
.findFragmentByTag(PLACE_PAGE_FRAGMENT_TAG) == null)
|
||||
{
|
||||
|
@ -304,12 +297,6 @@ public class PlacePageController implements Initializable<Activity>,
|
|||
PlacePageButtons.class, null, PLACE_PAGE_BUTTONS_FRAGMENT_TAG)
|
||||
.commit();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Only collapse the place page if it was already open
|
||||
// If we are creating it, wait for the peek height to be available
|
||||
mPlacePageBehavior.setState(BottomSheetBehavior.STATE_COLLAPSED);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -73,6 +73,12 @@ class PlacePageUtils
|
|||
return state == BottomSheetBehavior.STATE_COLLAPSED;
|
||||
}
|
||||
|
||||
static boolean isHalfExpandedState(@BottomSheetBehavior.State int state)
|
||||
{
|
||||
return state == BottomSheetBehavior.STATE_HALF_EXPANDED;
|
||||
}
|
||||
|
||||
|
||||
static boolean isExpandedState(@BottomSheetBehavior.State int state)
|
||||
{
|
||||
return state == BottomSheetBehavior.STATE_EXPANDED;
|
||||
|
|
|
@ -11,14 +11,10 @@ import android.text.SpannableStringBuilder;
|
|||
import android.text.Spanned;
|
||||
import android.text.TextUtils;
|
||||
import android.text.style.ForegroundColorSpan;
|
||||
import android.text.util.Linkify;
|
||||
import android.util.Base64;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.RelativeLayout;
|
||||
|
@ -39,7 +35,6 @@ import app.organicmaps.MwmApplication;
|
|||
import app.organicmaps.R;
|
||||
import app.organicmaps.api.Const;
|
||||
import app.organicmaps.api.ParsedMwmRequest;
|
||||
import app.organicmaps.bookmarks.data.Bookmark;
|
||||
import app.organicmaps.bookmarks.data.BookmarkManager;
|
||||
import app.organicmaps.bookmarks.data.DistanceAndAzimut;
|
||||
import app.organicmaps.bookmarks.data.MapObject;
|
||||
|
@ -79,7 +74,6 @@ import static android.view.View.VISIBLE;
|
|||
|
||||
public class PlacePageView extends Fragment implements View.OnClickListener,
|
||||
View.OnLongClickListener,
|
||||
EditBookmarkFragment.EditBookmarkListener,
|
||||
PlacePageButtons.PlacePageButtonClickListener,
|
||||
LocationListener,
|
||||
Observer<MapObject>
|
||||
|
@ -88,13 +82,12 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
private static final String TAG = PlacePageView.class.getSimpleName();
|
||||
|
||||
private static final String PREF_COORDINATES_FORMAT = "coordinates_format";
|
||||
private static final String BOOKMARK_FRAGMENT_TAG = "BOOKMARK_FRAGMENT_TAG";
|
||||
private static final List<CoordinatesFormat> visibleCoordsFormat =
|
||||
Arrays.asList(CoordinatesFormat.LatLonDMS,
|
||||
CoordinatesFormat.LatLonDecimal,
|
||||
CoordinatesFormat.OLCFull,
|
||||
CoordinatesFormat.OSMLink);
|
||||
@NonNull
|
||||
private final EditBookmarkClickListener mEditBookmarkClickListener = new EditBookmarkClickListener();
|
||||
private int mDescriptionMaxLength;
|
||||
private View mFrame;
|
||||
// Preview.
|
||||
|
@ -149,11 +142,7 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
private View mAddOrganisation;
|
||||
private View mAddPlace;
|
||||
private View mEditTopSpace;
|
||||
// Bookmark
|
||||
private View mBookmarkFrame;
|
||||
private WebView mWvBookmarkNote;
|
||||
private TextView mTvBookmarkNote;
|
||||
private boolean mBookmarkSet;
|
||||
|
||||
@SuppressWarnings("NullableProblems")
|
||||
@NonNull
|
||||
private View mPlaceDescriptionContainer;
|
||||
|
@ -294,7 +283,7 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
final int oldHeight = oldBottom - oldTop;
|
||||
final int newHeight = bottom - top;
|
||||
if (oldHeight != newHeight)
|
||||
mPlacePageViewListener.onPlacePageHeightChange(newHeight);
|
||||
mPlacePageViewListener.onPlacePageContentChanged(newHeight);
|
||||
});
|
||||
mTvTitle = mPreview.findViewById(R.id.tv__title);
|
||||
mTvTitle.setOnLongClickListener(this);
|
||||
|
@ -396,15 +385,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
mLevel.setOnLongClickListener(this);
|
||||
mWiki.setOnLongClickListener(this);
|
||||
|
||||
mBookmarkFrame = mFrame.findViewById(R.id.bookmark_frame);
|
||||
mWvBookmarkNote = mBookmarkFrame.findViewById(R.id.wv__bookmark_notes);
|
||||
final WebSettings settings = mWvBookmarkNote.getSettings();
|
||||
settings.setJavaScriptEnabled(false);
|
||||
settings.setDefaultTextEncodingName("UTF-8");
|
||||
mTvBookmarkNote = mBookmarkFrame.findViewById(R.id.tv__bookmark_notes);
|
||||
mTvBookmarkNote.setOnLongClickListener(this);
|
||||
initEditMapObjectBtn();
|
||||
|
||||
mDownloaderIcon = new DownloaderStatusIcon(mPreview.findViewById(R.id.downloader_status_frame));
|
||||
|
||||
mDownloaderInfo = mPreview.findViewById(R.id.tv__downloader_details);
|
||||
|
@ -601,24 +581,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
PlaceDescriptionActivity.start(context, description);
|
||||
}
|
||||
|
||||
private void initEditMapObjectBtn()
|
||||
{
|
||||
final View editBookmarkBtn = mBookmarkFrame.findViewById(R.id.tv__bookmark_edit);
|
||||
editBookmarkBtn.setVisibility(VISIBLE);
|
||||
editBookmarkBtn.setOnClickListener(mEditBookmarkClickListener);
|
||||
}
|
||||
|
||||
private void onMapObjectChange(MapObject mapObject)
|
||||
{
|
||||
detachCountry();
|
||||
if (mapObject != null)
|
||||
{
|
||||
initEditMapObjectBtn();
|
||||
setCurrentCountry();
|
||||
}
|
||||
refreshViews();
|
||||
}
|
||||
|
||||
private void setCurrentCountry()
|
||||
{
|
||||
if (mCurrentCountry != null)
|
||||
|
@ -650,23 +612,18 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
{
|
||||
case MapObject.BOOKMARK:
|
||||
refreshDistanceToObject(mapObject, loc);
|
||||
showBookmarkDetails(mapObject);
|
||||
updateBookmarkButton();
|
||||
break;
|
||||
case MapObject.POI:
|
||||
case MapObject.SEARCH:
|
||||
refreshDistanceToObject(mapObject, loc);
|
||||
hideBookmarkDetails();
|
||||
setPlaceDescription(mapObject);
|
||||
break;
|
||||
case MapObject.API_POINT:
|
||||
refreshDistanceToObject(mapObject, loc);
|
||||
hideBookmarkDetails();
|
||||
showBackButton = true;
|
||||
break;
|
||||
case MapObject.MY_POSITION:
|
||||
refreshMyPosition(mapObject, loc);
|
||||
hideBookmarkDetails();
|
||||
showRoutingButton = false;
|
||||
break;
|
||||
}
|
||||
|
@ -678,6 +635,27 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
updateButtons(mapObject, showBackButton, showRoutingButton);
|
||||
}
|
||||
|
||||
private void updateBookmarkView()
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
return;
|
||||
final FragmentManager fManager = getChildFragmentManager();
|
||||
final PlacePageBookmarkFragment fragment = (PlacePageBookmarkFragment) fManager.findFragmentByTag(BOOKMARK_FRAGMENT_TAG);
|
||||
if (mapObject.getMapObjectType() == MapObject.BOOKMARK && fragment == null)
|
||||
{
|
||||
fManager.beginTransaction()
|
||||
.add(R.id.place_page_bookmark_fragment, PlacePageBookmarkFragment.class, null, BOOKMARK_FRAGMENT_TAG)
|
||||
.commit();
|
||||
}
|
||||
else if (mapObject.getMapObjectType() != MapObject.BOOKMARK && fragment != null)
|
||||
{
|
||||
fManager.beginTransaction()
|
||||
.remove(fragment)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private Spanned getShortDescription(@NonNull MapObject mapObject)
|
||||
{
|
||||
String htmlDescription = mapObject.getDescription();
|
||||
|
@ -699,22 +677,15 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
private void setPlaceDescription(@NonNull MapObject mapObject)
|
||||
{
|
||||
boolean isBookmark = MapObject.isOfType(MapObject.BOOKMARK, mapObject);
|
||||
if (TextUtils.isEmpty(mapObject.getDescription()) && !isBookmark)
|
||||
if (TextUtils.isEmpty(mapObject.getDescription()))
|
||||
{
|
||||
UiUtils.hide(mPlaceDescriptionContainer, mPlaceDescriptionHeaderContainer);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBookmark)
|
||||
else
|
||||
{
|
||||
final Bookmark bmk = (Bookmark) mapObject;
|
||||
UiUtils.showIf(!TextUtils.isEmpty(bmk.getBookmarkDescription()), mPlaceDescriptionHeaderContainer);
|
||||
UiUtils.hide(mPlaceDescriptionContainer);
|
||||
return;
|
||||
UiUtils.show(mPlaceDescriptionContainer, mPlaceDescriptionHeaderContainer);
|
||||
mPlaceDescriptionView.setText(getShortDescription(mapObject));
|
||||
}
|
||||
UiUtils.show(mPlaceDescriptionContainer, mPlaceDescriptionHeaderContainer);
|
||||
mPlaceDescriptionView.setText(getShortDescription(mapObject));
|
||||
}
|
||||
|
||||
private void setTextAndColorizeSubtitle(@NonNull MapObject mapObject)
|
||||
|
@ -969,13 +940,17 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
mPhoneAdapter.refreshPhones(phones);
|
||||
}
|
||||
|
||||
|
||||
private void updateBookmarkButton()
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
return;
|
||||
final List<PlacePageButtons.ButtonType> currentButtons = viewModel.getCurrentButtons()
|
||||
.getValue();
|
||||
PlacePageButtons.ButtonType oldType = PlacePageButtons.ButtonType.BOOKMARK_DELETE;
|
||||
PlacePageButtons.ButtonType newType = PlacePageButtons.ButtonType.BOOKMARK_SAVE;
|
||||
if (mBookmarkSet)
|
||||
if (mapObject.getMapObjectType() == MapObject.BOOKMARK)
|
||||
{
|
||||
oldType = PlacePageButtons.ButtonType.BOOKMARK_SAVE;
|
||||
newType = PlacePageButtons.ButtonType.BOOKMARK_DELETE;
|
||||
|
@ -992,44 +967,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
}
|
||||
}
|
||||
|
||||
private void hideBookmarkDetails()
|
||||
{
|
||||
mBookmarkSet = false;
|
||||
UiUtils.hide(mBookmarkFrame);
|
||||
updateBookmarkButton();
|
||||
}
|
||||
|
||||
private void showBookmarkDetails(@NonNull MapObject mapObject)
|
||||
{
|
||||
mBookmarkSet = true;
|
||||
UiUtils.show(mBookmarkFrame);
|
||||
|
||||
final String notes = ((Bookmark) mapObject).getBookmarkDescription();
|
||||
|
||||
if (TextUtils.isEmpty(notes))
|
||||
{
|
||||
UiUtils.hide(mTvBookmarkNote, mWvBookmarkNote);
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtils.nativeIsHtml(notes))
|
||||
{
|
||||
// According to loadData documentation, HTML should be either base64 or percent encoded.
|
||||
// Default UTF-8 encoding for all content is set above in WebSettings.
|
||||
final String b64encoded = Base64.encodeToString(notes.getBytes(), Base64.DEFAULT);
|
||||
mWvBookmarkNote.loadData(b64encoded, Utils.TEXT_HTML, "base64");
|
||||
UiUtils.show(mWvBookmarkNote);
|
||||
UiUtils.hide(mTvBookmarkNote);
|
||||
}
|
||||
else
|
||||
{
|
||||
mTvBookmarkNote.setText(notes);
|
||||
Linkify.addLinks(mTvBookmarkNote, Linkify.ALL);
|
||||
UiUtils.show(mTvBookmarkNote);
|
||||
UiUtils.hide(mWvBookmarkNote);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateButtons(@NonNull MapObject mapObject, boolean showBackButton, boolean showRoutingButton)
|
||||
{
|
||||
List<PlacePageButtons.ButtonType> buttons = new ArrayList<>();
|
||||
|
@ -1218,10 +1155,11 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
private void toggleIsBookmark(@NonNull MapObject mapObject)
|
||||
{
|
||||
// No need to call setMapObject here as the native methods will reopen the place page
|
||||
if (MapObject.isOfType(MapObject.BOOKMARK, mapObject))
|
||||
viewModel.setMapObject(Framework.nativeDeleteBookmarkFromMapObject());
|
||||
Framework.nativeDeleteBookmarkFromMapObject();
|
||||
else
|
||||
viewModel.setMapObject(BookmarkManager.INSTANCE.addNewBookmark(mapObject.getLat(), mapObject.getLon()));
|
||||
BookmarkManager.INSTANCE.addNewBookmark(mapObject.getLat(), mapObject.getLon());
|
||||
}
|
||||
|
||||
private void showBigDirection()
|
||||
|
@ -1248,8 +1186,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
items.add(mTvSecondaryTitle.getText().toString());
|
||||
else if (id == R.id.tv__address)
|
||||
items.add(mTvAddress.getText().toString());
|
||||
else if (id == R.id.tv__bookmark_notes)
|
||||
items.add(mTvBookmarkNote.getText().toString());
|
||||
else if (id == R.id.poi_description)
|
||||
items.add(mPlaceDescriptionView.getText().toString());
|
||||
else if (id == R.id.ll__place_latlon)
|
||||
|
@ -1412,27 +1348,18 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
UiUtils.hide(mDownloaderInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBookmarkSaved(long bookmarkId, boolean movedFromCategory)
|
||||
{
|
||||
Bookmark updatedBookmark = BookmarkManager.INSTANCE.updateBookmarkPlacePage(bookmarkId);
|
||||
if (updatedBookmark == null)
|
||||
return;
|
||||
|
||||
viewModel.setMapObject(updatedBookmark);
|
||||
refreshViews();
|
||||
mPlacePageViewListener.onPlacePageHeightChange(getPreviewHeight());
|
||||
}
|
||||
|
||||
private int getPreviewHeight()
|
||||
{
|
||||
return mPreview.getHeight();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(MapObject mapObject)
|
||||
{
|
||||
onMapObjectChange(mapObject);
|
||||
detachCountry();
|
||||
if (mapObject != null)
|
||||
{
|
||||
setCurrentCountry();
|
||||
updateBookmarkButton();
|
||||
updateBookmarkView();
|
||||
}
|
||||
refreshViews();
|
||||
mPlacePageViewListener.onPlacePageContentChanged(mPreview.getHeight());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1441,8 +1368,7 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
{
|
||||
// TODO: This method is constantly called even when nothing is selected on the map.
|
||||
//Logger.e(TAG, "A location cannot be refreshed, mMapObject is null!");
|
||||
Logger.e(TAG, "A location cannot be refreshed, mMapObject is null!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1489,7 +1415,8 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
public interface PlacePageViewListener
|
||||
{
|
||||
void onPlacePageHeightChange(int previewHeight);
|
||||
// Called when the content has actually changed and we are ready to compute the peek height
|
||||
void onPlacePageContentChanged(int previewHeight);
|
||||
|
||||
void onPlacePageRequestClose();
|
||||
|
||||
|
@ -1497,24 +1424,4 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
void onPlacePageRequestToggleRouteSettings(@NonNull RoadType roadType);
|
||||
}
|
||||
|
||||
private class EditBookmarkClickListener implements View.OnClickListener
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
{
|
||||
Logger.e(TAG, "A bookmark cannot be edited, mMapObject is null!");
|
||||
return;
|
||||
}
|
||||
Bookmark bookmark = (Bookmark) mapObject;
|
||||
EditBookmarkFragment.editBookmark(bookmark.getCategoryId(),
|
||||
bookmark.getBookmarkId(),
|
||||
requireActivity(),
|
||||
requireActivity().getSupportFragmentManager(),
|
||||
PlacePageView.this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue