Added show wikivoyage pictures first time dialog

This commit is contained in:
Alexey Kulish 2018-04-15 17:50:10 +03:00
parent 3a1b3e50f2
commit 1019d10b5b
7 changed files with 234 additions and 22 deletions

View file

@ -0,0 +1,109 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_weight="1"
android:paddingTop="22dp"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:text="@string/wikivoyage_download_pics"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
android:textSize="@dimen/dialog_header_text_size"/>
</LinearLayout>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="fill_horizontal"
android:layout_marginBottom="@dimen/dialog_content_margin"
android:layout_marginTop="@dimen/list_header_padding"
android:paddingLeft="@dimen/list_content_padding"
android:paddingStart="@dimen/list_content_padding"
android:paddingRight="@dimen/list_content_padding"
android:paddingEnd="@dimen/list_content_padding"
android:text="@string/wikivoyage_download_pics_descr"
android:textSize="16sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="@dimen/list_header_padding"
android:paddingStart="@dimen/list_header_padding"
android:paddingRight="@dimen/list_header_padding"
android:paddingEnd="@dimen/list_header_padding"
android:paddingBottom="@dimen/list_header_padding"
android:orientation="horizontal">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_no"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_dont"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_wifi"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
android:layout_marginRight="@dimen/list_header_padding"
android:layout_marginEnd="@dimen/list_header_padding"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_only_with_wifi"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/button_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/ctx_menu_controller_bg"
android:gravity="center"
android:padding="@dimen/context_menu_button_padding_x"
osmand:typeface="@string/font_roboto_regular"
android:textSize="@dimen/default_list_text_size"
android:textColor="?attr/ctx_menu_controller_text_color"
android:text="@string/shared_string_do"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -9,6 +9,12 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
-->
<string name="shared_string_dont">Don\'t</string>
<string name="shared_string_do">Do</string>
<string name="shared_string_only_with_wifi">Only with WiFi</string>
<string name="wikivoyage_download_pics">Download Pictures</string>
<string name="wikivoyage_download_pics_descr">We can download &amp; show images in the articles and store them on device, so you will access them while offline.
You can always change the setting in Explore > Options.</string>
<string name="shared_string_wifi_only">Only WiFi</string>
<string name="select_travel_book">Select travel book</string>
<string name="shared_string_travel_book">Travel book</string>

View file

@ -717,6 +717,7 @@ public class OsmandSettings {
public final CommonPreference<Boolean> SHOW_LINES_TO_FIRST_MARKERS = new BooleanPreference("show_lines_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> SHOW_ARROWS_TO_FIRST_MARKERS = new BooleanPreference("show_arrows_to_first_markers", false).makeProfile();
public final CommonPreference<Boolean> WIKIVOYAGE_SHOW_IMAGES_ASKED = new BooleanPreference("wikivoyage_show_images_asked", false).makeGlobal();
public final CommonPreference<WikivoyageShowImages> WIKIVOYAGE_SHOW_IMAGES = new EnumIntPreference<>("wikivoyage_show_imgs", WikivoyageShowImages.OFF, WikivoyageShowImages.values()).makeGlobal();
public final CommonPreference<Boolean> SELECT_MARKER_ON_SINGLE_TAP = new BooleanPreference("select_marker_on_single_tap", false).makeProfile();

View file

@ -17,6 +17,7 @@ import android.view.View;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsBaseActivity;
import net.osmand.plus.activities.actions.AppModeDialog;
@ -70,10 +71,13 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
@Override
public boolean onPreferenceClick(Preference preference) {
getMyApplication().getAppInitializer().resetFirstTimeRun();
getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false);
getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
getMyApplication().getSettings().WEBGL_SUPPORTED.set(true);
getMyApplication().getSettings().METRIC_SYSTEM_CHANGED_MANUALLY.set(false);
OsmandSettings settings = getMyApplication().getSettings();
settings.FIRST_MAP_IS_DOWNLOADED.set(false);
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
settings.WEBGL_SUPPORTED.set(true);
settings.METRIC_SYSTEM_CHANGED_MANUALLY.set(false);
settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(false);
getMyApplication().showToastMessage(R.string.shared_string_ok);
return true;
}

View file

@ -0,0 +1,66 @@
package net.osmand.plus.wikivoyage;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
public class WikivoyageShowPicturesDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = WikivoyageShowPicturesDialogFragment.class.getSimpleName();
public static final int SHOW_PICTURES_CHANGED = 1;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_wikivoyage_show_images_first_time, container, false);
view.findViewById(R.id.button_no).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.OFF);
}
sendResult();
dismiss();
}
});
view.findViewById(R.id.button_wifi).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.WIFI);
}
sendResult();
dismiss();
}
});
view.findViewById(R.id.button_yes).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OsmandApplication app = getMyApplication();
if (app != null) {
app.getSettings().WIKIVOYAGE_SHOW_IMAGES.set(WikivoyageShowImages.ON);
}
sendResult();
dismiss();
}
});
return view;
}
private void sendResult() {
Fragment fragment = getTargetFragment();
if (fragment != null) {
fragment.onActivityResult(getTargetRequestCode(), SHOW_PICTURES_CHANGED, null);
}
}
}

View file

@ -76,7 +76,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
String name = wikivoyageContentItem.getLink().substring(1);
sendResults(link, name);
dismiss();
return false;
return true;
}
});
expListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
@ -87,7 +87,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
String name = wikivoyageContentItem.getLink().substring(1);
sendResults(link, name);
dismiss();
return false;
return true;
}
});
LinearLayout container = new LinearLayout(getContext());
@ -161,7 +161,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
}
TextView txtListChild = (TextView) convertView.findViewById(R.id.item_label);
txtListChild.setText(childText);
txtListChild.setTextColor(getResolvedColor(nightMode
txtListChild.setTextColor(ContextCompat.getColor(context, nightMode
? R.color.wikivoyage_contents_parent_icon_dark
: R.color.wikivoyage_contents_parent_icon_light));
txtListChild.setCompoundDrawablesWithIntrinsicBounds(itemChildIcon, null, null, null);
@ -208,7 +208,7 @@ public class WikivoyageArticleContentsFragment extends MenuBottomSheetDialogFrag
}
TextView lblListHeader = (TextView) convertView.findViewById(R.id.item_label);
lblListHeader.setText(headerTitle);
lblListHeader.setTextColor(getResolvedColor(nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
lblListHeader.setTextColor(ContextCompat.getColor(context, nightMode ? R.color.wikivoyage_contents_parent_icon_dark : R.color.wikivoyage_contents_parent_icon_light));
lblListHeader.setCompoundDrawablesWithIntrinsicBounds(itemGroupIcon, null, null, null);
adjustIndicator(getMyApplication(), groupPosition, isExpanded, convertView, !nightMode);

View file

@ -8,6 +8,7 @@ import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
@ -25,9 +26,11 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.OsmandSettings.WikivoyageShowImages;
import net.osmand.plus.R;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageShowPicturesDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageWebViewClient;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
@ -150,29 +153,17 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
WikivoyageArticleContentsFragment fragment = new WikivoyageArticleContentsFragment();
fragment.setUsedOnMap(false);
fragment.setArguments(args);
fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, 0);
fragment.setTargetFragment(WikivoyageArticleDialogFragment.this, WikivoyageArticleContentsFragment.REQUEST_LINK_CODE);
fragment.show(fm, WikivoyageArticleContentsFragment.TAG);
}
});
saveBtn = (TextView) mainView.findViewById(R.id.save_button);
OsmandSettings.WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
WebSettings webSettings = contentWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
switch (showImages) {
case ON:
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
break;
case OFF:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
break;
case WIFI:
webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ?
WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY);
break;
}
updateWebSettings();
contentWebView.setWebViewClient(new WikivoyageWebViewClient(getActivity(), getFragmentManager()));
return mainView;
@ -196,6 +187,24 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
String link = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_LINK_KEY);
String title = data.getStringExtra(WikivoyageArticleContentsFragment.CONTENTS_TITLE_KEY);
moveToAnchor(link, title);
} else if (requestCode == WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED) {
updateWebSettings();
populateArticle();
}
}
@Override
public void onResume() {
super.onResume();
OsmandSettings settings = getMyApplication().getSettings();
if (!settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.get()) {
FragmentActivity activity = getActivity();
if (activity != null) {
WikivoyageShowPicturesDialogFragment fragment = new WikivoyageShowPicturesDialogFragment();
fragment.setTargetFragment(this, WikivoyageShowPicturesDialogFragment.SHOW_PICTURES_CHANGED);
fragment.show(activity.getSupportFragmentManager(), WikivoyageShowPicturesDialogFragment.TAG);
settings.WIKIVOYAGE_SHOW_IMAGES_ASKED.set(true);
}
}
}
@ -204,6 +213,23 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
return nightMode ? R.color.status_bar_wikivoyage_article_dark : R.color.status_bar_wikivoyage_article_light;
}
private void updateWebSettings() {
WikivoyageShowImages showImages = getSettings().WIKIVOYAGE_SHOW_IMAGES.get();
WebSettings webSettings = contentWebView.getSettings();
switch (showImages) {
case ON:
webSettings.setCacheMode(WebSettings.LOAD_DEFAULT);
break;
case OFF:
webSettings.setCacheMode(WebSettings.LOAD_CACHE_ONLY);
break;
case WIFI:
webSettings.setCacheMode(getMyApplication().getSettings().isWifiConnected() ?
WebSettings.LOAD_DEFAULT : WebSettings.LOAD_CACHE_ONLY);
break;
}
}
private void updateSaveButton() {
if (article != null) {
final WikivoyageLocalDataHelper helper = getMyApplication().getWikivoyageDbHelper().getLocalDataHelper();