[android] Add a workaround for broken PlacePageView after Search/Edit

Steps to reproduce:

1. Open the app
2. Click the magnifying glass icon to search
3. **TYPE IN** search query string, then press `return` key on keyboard
4. As usually there will be no results shown on map in current viewport (would be great if it will automatically zoom out to show at least some result), click `Lists` in the bottom toolbar to bring up result list
5. Select specific result (doesn't matter which one)
6. Tara! Bottom toolbar empty.

Follow up 1f8c0667b "fix for place page layout breakdown".

Closes #722
Closes #1065

Signed-off-by: Roman Tsisyk <roman@tsisyk.com>
This commit is contained in:
Roman Tsisyk 2021-09-06 11:18:59 +03:00
parent 20fe7d4bb4
commit 58dcdc6334
4 changed files with 36 additions and 7 deletions

View file

@ -293,6 +293,11 @@ public final class PlacePageButtons
mMaxButtons = mPlacePage.getContext().getResources().getInteger(R.integer.pp_buttons_max);
}
ViewGroup getFrame()
{
return mFrame;
}
private @NonNull List<PlacePageButtons.PlacePageButton> collectButtons(List<PlacePageButtons.PlacePageButton> items)
{
List<PlacePageButtons.PlacePageButton> res = new ArrayList<>(items);

View file

@ -31,8 +31,8 @@ import androidx.annotation.Nullable;
import androidx.appcompat.widget.Toolbar;
import androidx.core.widget.NestedScrollViewClickFixed;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.RecyclerView;
import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmActivity;
import com.mapswithme.maps.MwmApplication;
@ -85,6 +85,9 @@ public class PlacePageView extends NestedScrollViewClickFixed
private boolean mIsDocked;
private boolean mIsFloating;
// See refreshView().
private boolean mIsAndroid11HackApplied = false;
// Preview.
private ViewGroup mPreview;
private Toolbar mToolbar;
@ -94,6 +97,9 @@ public class PlacePageView extends NestedScrollViewClickFixed
private ArrowView mAvDirection;
private TextView mTvDistance;
private TextView mTvAddress;
// Details.
private ViewGroup mDetails;
private RecyclerView mPhoneRecycler;
private PlacePhoneAdapter mPhoneAdapter;
private View mWebsite;
@ -288,6 +294,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
mTvAddress = mPreview.findViewById(R.id.tv__address);
mDetails = findViewById(R.id.pp__details_frame);
RelativeLayout address = findViewById(R.id.ll__place_name);
mPhoneRecycler = findViewById(R.id.rw__phone);
mPhoneAdapter = new PlacePhoneAdapter();
@ -703,6 +710,22 @@ public class PlacePageView extends NestedScrollViewClickFixed
refreshPreview(mMapObject);
refreshDetails(mMapObject);
refreshViewsInternal(mMapObject);
//
// The view is completely broken after the first call to refreshView():
// https://github.com/organicmaps/organicmaps/issues/722
// https://github.com/organicmaps/organicmaps/issues/1065
//
// Force re-layout explicitly on the next event loop after the first call to refreshView().
//
if (!mIsAndroid11HackApplied && Utils.isAndroid11OrLater()) {
mIsAndroid11HackApplied = true;
post(() -> {
mPreview.requestLayout();
mDetails.requestLayout();
mButtons.getFrame().requestLayout();
});
}
}
private void refreshViewsInternal(@NonNull MapObject mapObject)
@ -1243,7 +1266,7 @@ public class PlacePageView extends NestedScrollViewClickFixed
final int id = item.getItemId();
final Context ctx = getContext();
Utils.copyTextToClipboard(ctx, items.get(id));
Utils.showSnackbarAbove(findViewById(R.id.pp__details_frame),
Utils.showSnackbarAbove(mDetails,
getRootView().findViewById(R.id.menu_frame),
ctx.getString(R.string.copied_to_clipboard, items.get(id)));
return true;

View file

@ -6,7 +6,6 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.res.Resources;
import android.location.Location;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
@ -380,10 +379,7 @@ public class RichPlacePageController implements PlacePageController, LocationLis
@Override
public void onActivityResumed(Activity activity)
{
// workaround for https://github.com/organicmaps/organicmaps/issues/722
if (Build.VERSION.SDK_INT >= 30) {
mPlacePage.requestLayout();
}
// No op.
}
@Override

View file

@ -78,6 +78,11 @@ public class Utils
return isTargetOrLater(Build.VERSION_CODES.O);
}
public static boolean isAndroid11OrLater()
{
return isTargetOrLater(Build.VERSION_CODES.R);
}
private static boolean isTargetOrLater(int target)
{
return Build.VERSION.SDK_INT >= target;