forked from organicmaps/organicmaps
android: move phone view to own fragment
Signed-off-by: Arnaud Vergnet <arnaud.vergnet@mailo.com>
This commit is contained in:
parent
8eaa8347bd
commit
98677ed587
4 changed files with 100 additions and 24 deletions
|
@ -4,7 +4,6 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:background="?windowBackgroundForced"
|
||||
android:orientation="vertical">
|
||||
|
||||
|
@ -43,12 +42,11 @@
|
|||
|
||||
<include layout="@layout/place_page_entrance"/>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rw__phone"
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/place_page_phone_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?cardBackground"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"/>
|
||||
tools:layout="@layout/place_page_phone_fragment" />
|
||||
|
||||
<include layout="@layout/place_page_operator"/>
|
||||
|
||||
|
|
13
android/res/layout/place_page_phone_fragment.xml
Normal file
13
android/res/layout/place_page_phone_fragment.xml
Normal file
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rw__phone"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?cardBackground"
|
||||
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
|
||||
</LinearLayout>
|
|
@ -0,0 +1,58 @@
|
|||
package app.organicmaps.widget.placepage;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.lifecycle.Observer;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import app.organicmaps.R;
|
||||
import app.organicmaps.bookmarks.data.MapObject;
|
||||
import app.organicmaps.bookmarks.data.Metadata;
|
||||
|
||||
public class PlacePagePhoneFragment extends Fragment implements Observer<MapObject>
|
||||
{
|
||||
private PlacePhoneAdapter mPhoneAdapter;
|
||||
|
||||
private PlacePageViewModel viewModel;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
return inflater.inflate(R.layout.place_page_phone_fragment, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState)
|
||||
{
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
RecyclerView phoneRecycler = view.findViewById(R.id.rw__phone);
|
||||
mPhoneAdapter = new PlacePhoneAdapter();
|
||||
phoneRecycler.setAdapter(mPhoneAdapter);
|
||||
|
||||
viewModel = new ViewModelProvider(requireActivity()).get(PlacePageViewModel.class);
|
||||
viewModel.getMapObject().observe(requireActivity(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy()
|
||||
{
|
||||
super.onDestroy();
|
||||
viewModel.getMapObject().removeObserver(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChanged(MapObject mapObject)
|
||||
{
|
||||
if (mapObject != null)
|
||||
{
|
||||
mPhoneAdapter.refreshPhones(mapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -83,6 +83,8 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
private static final String PREF_COORDINATES_FORMAT = "coordinates_format";
|
||||
private static final String BOOKMARK_FRAGMENT_TAG = "BOOKMARK_FRAGMENT_TAG";
|
||||
private static final String PHONE_FRAGMENT_TAG = "PHONE_FRAGMENT_TAG";
|
||||
|
||||
private static final List<CoordinatesFormat> visibleCoordsFormat =
|
||||
Arrays.asList(CoordinatesFormat.LatLonDMS,
|
||||
CoordinatesFormat.LatLonDecimal,
|
||||
|
@ -101,8 +103,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
private TextView mTvAddress;
|
||||
// Details.
|
||||
private ViewGroup mDetails;
|
||||
private RecyclerView mPhoneRecycler;
|
||||
private PlacePhoneAdapter mPhoneAdapter;
|
||||
private View mWebsite;
|
||||
private TextView mTvWebsite;
|
||||
private TextView mTvLatlon;
|
||||
|
@ -307,9 +307,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
|
||||
mDetails = mFrame.findViewById(R.id.pp__details_frame);
|
||||
RelativeLayout address = mFrame.findViewById(R.id.ll__place_name);
|
||||
mPhoneRecycler = mFrame.findViewById(R.id.rw__phone);
|
||||
mPhoneAdapter = new PlacePhoneAdapter();
|
||||
mPhoneRecycler.setAdapter(mPhoneAdapter);
|
||||
mWebsite = mFrame.findViewById(R.id.ll__place_website);
|
||||
mWebsite.setOnClickListener(this);
|
||||
mTvWebsite = mFrame.findViewById(R.id.tv__place_website);
|
||||
|
@ -601,6 +598,8 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
refreshPreview(mapObject);
|
||||
refreshDetails(mapObject);
|
||||
refreshViewsInternal(mapObject);
|
||||
updateBookmarkView();
|
||||
updatePhoneView();
|
||||
}
|
||||
|
||||
private void refreshViewsInternal(@NonNull MapObject mapObject)
|
||||
|
@ -627,14 +626,30 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
showRoutingButton = false;
|
||||
break;
|
||||
}
|
||||
final boolean hasNumber = mapObject.hasPhoneNumber();
|
||||
if (hasNumber)
|
||||
mPhoneRecycler.setVisibility(VISIBLE);
|
||||
else
|
||||
mPhoneRecycler.setVisibility(GONE);
|
||||
updateButtons(mapObject, showBackButton, showRoutingButton);
|
||||
}
|
||||
|
||||
private void updatePhoneView()
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
if (mapObject == null)
|
||||
return;
|
||||
final FragmentManager fManager = getChildFragmentManager();
|
||||
final PlacePagePhoneFragment fragment = (PlacePagePhoneFragment) fManager.findFragmentByTag(PHONE_FRAGMENT_TAG);
|
||||
if (mapObject.hasPhoneNumber() && fragment == null)
|
||||
{
|
||||
fManager.beginTransaction()
|
||||
.add(R.id.place_page_phone_fragment, PlacePagePhoneFragment.class, null, PHONE_FRAGMENT_TAG)
|
||||
.commit();
|
||||
}
|
||||
else if (!mapObject.hasPhoneNumber() && fragment != null)
|
||||
{
|
||||
fManager.beginTransaction()
|
||||
.remove(fragment)
|
||||
.commit();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBookmarkView()
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
|
@ -729,7 +744,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
String wikimedia_commons = mapObject.getMetadata(Metadata.MetadataType.FMD_WIKIMEDIA_COMMONS);
|
||||
String wikimedia_commons_text = TextUtils.isEmpty(wikimedia_commons) ? "" : getResources().getString(R.string.wikimedia_commons);
|
||||
refreshMetadataOrHide(wikimedia_commons_text, mWikimedia, mTvWikimedia);
|
||||
refreshPhoneNumberList(mapObject.getMetadata(Metadata.MetadataType.FMD_PHONE_NUMBER));
|
||||
refreshMetadataOrHide(mapObject.getMetadata(Metadata.MetadataType.FMD_EMAIL), mEmail, mTvEmail);
|
||||
refreshMetadataOrHide(mapObject.getMetadata(Metadata.MetadataType.FMD_OPERATOR), mOperator, mTvOperator);
|
||||
/// @todo I don't like it when we take all data from mapObject, but for cuisines, we should
|
||||
|
@ -935,12 +949,6 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
mTodayOpenTime.setTextColor(color);
|
||||
}
|
||||
|
||||
private void refreshPhoneNumberList(String phones)
|
||||
{
|
||||
mPhoneAdapter.refreshPhones(phones);
|
||||
}
|
||||
|
||||
|
||||
private void updateBookmarkButton()
|
||||
{
|
||||
final MapObject mapObject = getMapObject();
|
||||
|
@ -1356,9 +1364,8 @@ public class PlacePageView extends Fragment implements View.OnClickListener,
|
|||
{
|
||||
setCurrentCountry();
|
||||
updateBookmarkButton();
|
||||
updateBookmarkView();
|
||||
refreshViews();
|
||||
}
|
||||
refreshViews();
|
||||
mPlacePageViewListener.onPlacePageContentChanged(mPreview.getHeight());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue