Update UI of Description in Overview Tab in GPX context menu
This commit is contained in:
parent
92217cba9f
commit
b249fdbab6
6 changed files with 262 additions and 118 deletions
|
@ -42,14 +42,19 @@
|
|||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_save"
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/content_padding_half"
|
||||
android:layout_marginEnd="@dimen/content_padding_half"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:background="@drawable/btn_border_active"
|
||||
android:background="@drawable/btn_border_active">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_save"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/selectableItemBackground"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/content_padding_half"
|
||||
|
@ -61,6 +66,7 @@
|
|||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
@ -69,17 +75,26 @@
|
|||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color" />
|
||||
|
||||
<ScrollView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<net.osmand.plus.widgets.EditTextEx
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="@dimen/content_padding"
|
||||
android:layout_marginStart="@dimen/content_padding"
|
||||
android:layout_marginLeft="@dimen/content_padding"
|
||||
android:layout_marginTop="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding"
|
||||
android:layout_marginEnd="@dimen/content_padding"
|
||||
android:layout_marginBottom="@dimen/content_padding_half"
|
||||
android:background="?attr/card_and_list_background_basic"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_regular"
|
||||
tools:text="Amsterdam is the Netherlands' capital and financial, cultural and creative centre with more than 850,000 inhabitants. Amsterdam is known for the canals that criss-cross the city, its impressive architecture and more than 1,500 bridges. The city has a heritage dating back to the Dutch Golden Age in the 17th century as well as a diverse art scene and a bustling nightlife." />
|
||||
|
||||
</ScrollView>
|
||||
|
||||
</LinearLayout>
|
|
@ -56,19 +56,25 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:background="?attr/divider_color"
|
||||
android:background="?attr/ctx_menu_info_divider"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_edit"
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="@dimen/content_padding"
|
||||
android:layout_marginStart="@dimen/content_padding"
|
||||
android:layout_marginTop="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginBottom="@dimen/context_menu_padding_margin_small"
|
||||
android:background="@drawable/rounded_background_3dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/context_menu_padding_margin_small"
|
||||
android:paddingStart="@dimen/context_menu_padding_margin_small"
|
||||
android:paddingEnd="@dimen/context_menu_padding_margin_small"
|
||||
|
@ -83,6 +89,8 @@
|
|||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:visibility="visible" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/bottom_empty_space"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -40,6 +40,12 @@
|
|||
tools:visibility="visible"
|
||||
tools:src="@drawable/img_help_announcement_time_day"/>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@id/description_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/description"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -59,23 +65,25 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginBottom="@dimen/context_menu_padding_margin_small"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
|
||||
android:background="@drawable/rounded_background_3dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_read_full"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginLeft="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_gravity="start"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingLeft="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingTop="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingRight="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small"
|
||||
android:drawablePadding="@dimen/bottom_sheet_content_padding_small"
|
||||
osmand:drawableStartCompat="@drawable/ic_action_read_article"
|
||||
osmand:drawableLeftCompat="@drawable/ic_action_read_article"
|
||||
|
@ -85,14 +93,22 @@
|
|||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_edit"
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_marginEnd="@dimen/context_menu_padding_margin_small"
|
||||
android:layout_gravity="end"
|
||||
android:background="@drawable/rounded_background_3dp">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/btn_edit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding_small"
|
||||
|
@ -107,9 +123,44 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/btn_add"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="@dimen/card_padding"
|
||||
android:layout_marginLeft="@dimen/card_padding"
|
||||
android:layout_marginTop="@dimen/content_padding"
|
||||
android:background="@drawable/rounded_background_3dp"
|
||||
android:visibility="gone"
|
||||
tools:visibility="visible">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:padding="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingStart="@dimen/bottom_sheet_content_padding_small"
|
||||
android:paddingEnd="@dimen/bottom_sheet_content_padding_small"
|
||||
android:drawablePadding="@dimen/dialog_button_height"
|
||||
osmand:drawableStartCompat="@drawable/ic_action_add"
|
||||
osmand:drawableLeftCompat="@drawable/ic_action_add"
|
||||
osmand:drawableTint="?attr/wikivoyage_active_color"
|
||||
android:text="@string/add_description"
|
||||
android:textColor="?attr/wikivoyage_active_color"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/context_menu_padding_margin_small"
|
||||
android:background="?attr/activity_background_basic">
|
||||
|
||||
<include
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
package net.osmand.plus.track;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.squareup.picasso.RequestCreator;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.PicassoUtils;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -19,6 +19,9 @@ import net.osmand.plus.widgets.TextViewEx;
|
|||
import net.osmand.plus.wikipedia.WikiArticleHelper;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
|
||||
import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.getMetadataImageLink;
|
||||
|
||||
public class DescriptionCard extends BaseCard {
|
||||
|
@ -37,11 +40,8 @@ public class DescriptionCard extends BaseCard {
|
|||
|
||||
@Override
|
||||
protected void updateContent() {
|
||||
if (gpxFile.metadata == null || gpxFile.metadata.getDescription() == null) {
|
||||
AndroidUiHelper.updateVisibility(view, false);
|
||||
return;
|
||||
} else {
|
||||
AndroidUiHelper.updateVisibility(view, true);
|
||||
if (gpxFile.metadata == null) {
|
||||
gpxFile.metadata = new GPXUtilities.Metadata();
|
||||
}
|
||||
|
||||
final String title = gpxFile.metadata.getArticleTitle();
|
||||
|
@ -50,6 +50,31 @@ public class DescriptionCard extends BaseCard {
|
|||
|
||||
setupImage(imageUrl);
|
||||
|
||||
if (descriptionHtml == null || Algorithms.isEmpty(descriptionHtml.trim())) {
|
||||
showAddBtn();
|
||||
} else {
|
||||
showDescription(title, imageUrl, descriptionHtml);
|
||||
}
|
||||
}
|
||||
|
||||
private void showAddBtn() {
|
||||
LinearLayout descriptionContainer = view.findViewById(R.id.description_container);
|
||||
FrameLayout addBtn = view.findViewById(R.id.btn_add);
|
||||
|
||||
addBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
GpxEditDescriptionDialogFragment.showInstance(getMapActivity(), "", null);
|
||||
}
|
||||
});
|
||||
AndroidUiHelper.updateVisibility(descriptionContainer, false);
|
||||
AndroidUiHelper.updateVisibility(addBtn, true);
|
||||
}
|
||||
|
||||
private void showDescription(final String title, final String imageUrl, final String descriptionHtml) {
|
||||
LinearLayout descriptionContainer = view.findViewById(R.id.description_container);
|
||||
AndroidUiHelper.updateVisibility(descriptionContainer, true);
|
||||
|
||||
TextViewEx tvDescription = view.findViewById(R.id.description);
|
||||
tvDescription.setText(getFirstParagraph(descriptionHtml));
|
||||
|
||||
|
@ -60,6 +85,7 @@ public class DescriptionCard extends BaseCard {
|
|||
GpxReadDescriptionDialogFragment.showInstance(mapActivity, title, imageUrl, descriptionHtml);
|
||||
}
|
||||
});
|
||||
|
||||
TextViewEx editBtn = view.findViewById(R.id.btn_edit);
|
||||
editBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package net.osmand.plus.track;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
|
@ -7,12 +9,6 @@ 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.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
|
@ -22,12 +18,18 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.base.BaseOsmAndDialogFragment;
|
||||
import net.osmand.plus.track.SaveGpxAsyncTask.SaveGpxListener;
|
||||
import net.osmand.plus.widgets.EditTextEx;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = GpxEditDescriptionDialogFragment.class.getSimpleName();
|
||||
|
@ -37,6 +39,8 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
|||
|
||||
private EditTextEx editableHtml;
|
||||
|
||||
private String htmlCode;
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
|
||||
|
@ -46,11 +50,16 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
|||
View view = themedInflater.inflate(R.layout.dialog_edit_gpx_description, container, false);
|
||||
|
||||
editableHtml = view.findViewById(R.id.description);
|
||||
editableHtml.requestFocus();
|
||||
|
||||
view.findViewById(R.id.btn_close).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (shouldClose()) {
|
||||
dismiss();
|
||||
} else {
|
||||
showDismissDialog();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -58,7 +67,7 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
|||
@Override
|
||||
public void onClick(View v) {
|
||||
Editable editable = editableHtml.getText();
|
||||
if (!Algorithms.isEmpty(editable) && !saveGpx(editable.toString())) {
|
||||
if (editable != null && !saveGpx(editable.toString())) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
@ -66,15 +75,43 @@ public class GpxEditDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
|||
|
||||
Bundle args = getArguments();
|
||||
if (args != null) {
|
||||
String html = args.getString(CONTENT_KEY);
|
||||
if (html != null) {
|
||||
editableHtml.setText(html);
|
||||
htmlCode = args.getString(CONTENT_KEY);
|
||||
if (htmlCode != null) {
|
||||
editableHtml.setText(htmlCode);
|
||||
}
|
||||
}
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean shouldClose() {
|
||||
Editable editable = editableHtml.getText();
|
||||
if (htmlCode == null || editable == null || editable.toString() == null) {
|
||||
return true;
|
||||
}
|
||||
if (htmlCode.equals(editable.toString())) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void showDismissDialog() {
|
||||
Context themedContext = UiUtilities.getThemedContext(getMapActivity(), isNightMode(false));
|
||||
AlertDialog.Builder dismissDialog = new AlertDialog.Builder(themedContext);
|
||||
dismissDialog.setTitle(getString(R.string.shared_string_dismiss));
|
||||
dismissDialog.setMessage(getString(R.string.exit_without_saving));
|
||||
dismissDialog.setNegativeButton(R.string.shared_string_cancel, null);
|
||||
dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
dismissDialog.show();
|
||||
}
|
||||
|
||||
private boolean saveGpx(final String html) {
|
||||
MapActivity mapActivity = getMapActivity();
|
||||
if (mapActivity == null || mapActivity.getTrackMenuFragment() == null) {
|
||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.plus.track;
|
|||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.util.Base64;
|
||||
import android.view.LayoutInflater;
|
||||
|
@ -15,14 +16,6 @@ import android.webkit.WebSettings;
|
|||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.squareup.picasso.Callback;
|
||||
import com.squareup.picasso.Picasso;
|
||||
import com.squareup.picasso.RequestCreator;
|
||||
|
@ -39,6 +32,14 @@ import net.osmand.plus.widgets.WebViewEx;
|
|||
import net.osmand.plus.wikivoyage.WikivoyageUtils;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatImageView;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
||||
|
||||
public static final String TAG = GpxReadDescriptionDialogFragment.class.getSimpleName();
|
||||
|
@ -181,10 +182,16 @@ public class GpxReadDescriptionDialogFragment extends BaseOsmAndDialogFragment {
|
|||
|
||||
private void setupWebView(final View view) {
|
||||
webView = view.findViewById(R.id.content);
|
||||
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
webView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
}
|
||||
else {
|
||||
webView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
|
||||
}
|
||||
webView.setScrollbarFadingEnabled(true);
|
||||
webView.setVerticalScrollBarEnabled(false);
|
||||
webView.setBackgroundColor(Color.TRANSPARENT);
|
||||
webView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
|
||||
webView.getSettings().setTextZoom((int) (getResources().getConfiguration().fontScale * 100f));
|
||||
webView.getSettings().setDomStorageEnabled(true);
|
||||
webView.getSettings().setLoadWithOverviewMode(true);
|
||||
|
|
Loading…
Reference in a new issue