Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-04-28 19:54:39 +02:00
commit c23533ba33
22 changed files with 353 additions and 220 deletions

View file

@ -62,7 +62,15 @@
</android.support.v7.widget.Toolbar>
<ProgressBar
android:id="@+id/progress_bar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:indeterminate="true"/>
<FrameLayout
android:id="@+id/search_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/text_margin_small"

View file

@ -155,6 +155,7 @@
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/regionHeaderTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"

View file

@ -6,8 +6,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_header_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding"
android:background="@drawable/dialog_active_card_bg"
android:orientation="vertical">
@ -43,7 +43,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/list_content_padding">
android:layout_margin="@dimen/card_padding">
<include layout="@layout/purchase_dialog_card_button"/>

View file

@ -5,8 +5,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_header_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding"
android:background="@drawable/dialog_card_bg"
android:orientation="vertical">
@ -40,7 +40,7 @@
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/list_content_padding">
android:layout_margin="@dimen/card_padding">
<include layout="@layout/purchase_dialog_card_button"/>

View file

@ -84,9 +84,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:layout_marginTop="@dimen/list_header_padding"
android:layout_marginLeft="@dimen/card_padding"
android:layout_marginRight="@dimen/card_padding"
android:layout_marginTop="4dp"
android:background="@drawable/wikivoyage_search_card_bg">
<net.osmand.plus.widgets.TextViewEx

View file

@ -46,13 +46,4 @@
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/wikivoyage_card_bg_color"
android:indeterminate="true"
android:visibility="gone" />
</LinearLayout>

View file

@ -9,6 +9,7 @@
<dimen name="card_row_min_height">48dp</dimen>
<dimen name="card_button_min_size">58dp</dimen>
<dimen name="card_button_progress_size">32dp</dimen>
<dimen name="card_padding">12dp</dimen>
<dimen name="widget_turn_lane_size">36dp</dimen>
<dimen name="widget_turn_lane_border">6dp</dimen>

View file

@ -9,6 +9,7 @@
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="osmand_team">OsmAnd team</string>
<string name="popular_destinations">Popular destinations</string>
<string name="paid_app">Paid app</string>
<string name="paid_plugin">Paid plugin</string>

View file

@ -2,5 +2,6 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<Preference android:key="general_settings" android:title="@string/general_settings_2" android:summary="@string/general_settings_descr"/>
<Preference android:key="routing_settings" android:title="@string/routing_settings_2" android:summary="@string/routing_settings_descr"/>
<Preference android:key="subscription_settings" android:title="@string/osm_live_subscription" android:summary="@string/osm_live_subscription_desc"/>
<PreferenceCategory android:key="plugin_settings" android:title="@string/plugin_settings" />
</PreferenceScreen>

View file

@ -1,30 +1,19 @@
package net.osmand.plus.activities;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.development.OsmandDevelopmentPlugin;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceScreen;
import android.preference.Preference.OnPreferenceClickListener;
import android.support.v7.widget.Toolbar;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.view.View;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import net.osmand.plus.liveupdates.OsmLiveActivity;
public class SettingsActivity extends SettingsBaseActivity {
@ -38,6 +27,7 @@ public class SettingsActivity extends SettingsBaseActivity {
private Preference general;
private Preference routing;
private Preference subscription;
@Override
@ -49,8 +39,10 @@ public class SettingsActivity extends SettingsBaseActivity {
general = (Preference) screen.findPreference("general_settings");
general.setOnPreferenceClickListener(this);
routing = (Preference) screen.findPreference("routing_settings");
routing .setOnPreferenceClickListener(this);
routing.setOnPreferenceClickListener(this);
subscription = (Preference) screen.findPreference("subscription_settings");
subscription.setOnPreferenceClickListener(this);
getToolbar().setTitle(Version.getFullVersion(getMyApplication()));
Intent intent = getIntent();
@ -99,6 +91,11 @@ public class SettingsActivity extends SettingsBaseActivity {
} else if (preference == routing) {
startActivity(new Intent(this, SettingsNavigationActivity.class));
return true;
} else if (preference == subscription) {
Intent intent = new Intent(this, OsmLiveActivity.class);
intent.putExtra(OsmLiveActivity.SHOW_SETTINGS_ONLY_INTENT_PARAM, true);
startActivity(intent);
return true;
} else {
super.onPreferenceClick(preference);
}

View file

@ -11,6 +11,7 @@ import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
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.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
@ -36,6 +37,7 @@ import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseListener;
import net.osmand.plus.inapp.InAppPurchaseHelper.InAppPurchaseTaskType;
import net.osmand.plus.liveupdates.OsmLiveActivity;
import net.osmand.plus.liveupdates.SubscriptionFragment;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.widgets.TextViewEx;
@ -53,6 +55,10 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
private View osmLiveCardButton;
private View planTypeCardButton;
public interface ChoosePlanDialogListener {
void onChoosePlanDialogDismissed();
}
public enum OsmAndFeature {
WIKIVOYAGE_OFFLINE(R.string.wikivoyage_offline),
DAILY_MAP_UPDATES(R.string.daily_map_updates),
@ -132,15 +138,16 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Activity ctx = requireActivity();
int themeId = nightMode ? R.style.OsmandDarkTheme_DarkActionbar : R.style.OsmandLightTheme_DarkActionbar_LightStatusBar;
Dialog dialog = new Dialog(getContext(), themeId);
Dialog dialog = new Dialog(ctx, themeId);
Window window = dialog.getWindow();
if (window != null) {
if (!getSettings().DO_NOT_USE_ANIMATIONS.get()) {
window.getAttributes().windowAnimations = R.style.Animations_Alpha;
}
if (Build.VERSION.SDK_INT >= 21) {
window.setStatusBarColor(ContextCompat.getColor(getContext(), getStatusBarColor()));
window.setStatusBarColor(ContextCompat.getColor(ctx, getStatusBarColor()));
}
}
return dialog;
@ -190,6 +197,15 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
return nightMode ? R.color.status_bar_wikivoyage_dark : R.color.status_bar_wikivoyage_light;
}
@Override
public void dismiss() {
super.dismiss();
Activity activity = getActivity();
if (activity != null && activity instanceof ChoosePlanDialogListener) {
((ChoosePlanDialogListener) activity).onChoosePlanDialogDismissed();
}
}
public OsmandApplication getOsmandApplication() {
return app;
}
@ -298,13 +314,17 @@ public abstract class ChoosePlanDialogFragment extends BaseOsmAndDialogFragment
}
private void subscript() {
Activity ctx = getActivity();
FragmentActivity ctx = getActivity();
if (ctx != null) {
app.logEvent(ctx, "click_subscribe_live_osm");
Intent intent = new Intent(ctx, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(OsmLiveActivity.OPEN_SUBSCRIPTION_INTENT_PARAM, true);
ctx.startActivity(intent);
if (ctx instanceof OsmLiveActivity) {
SubscriptionFragment subscriptionFragment = new SubscriptionFragment();
subscriptionFragment.show(ctx.getSupportFragmentManager(), SubscriptionFragment.TAG);
} else {
Intent intent = new Intent(ctx, OsmLiveActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
intent.putExtra(OsmLiveActivity.OPEN_SUBSCRIPTION_INTENT_PARAM, true);
ctx.startActivity(intent);
}
}
}

View file

@ -88,6 +88,7 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
private ExpandableListView listView;
private LocalIndexesAdapter adapter;
private AsyncTask<Void, LocalIndexInfo, List<LocalIndexInfo>> loadLocalIndexesTask;
private boolean showSettingsOnly;
private ProgressBar progressBar;
private boolean processing;
@ -110,6 +111,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
if (getActivity() instanceof OsmLiveActivity) {
showSettingsOnly = ((OsmLiveActivity) getActivity()).isShowSettingOnly();
}
}
@Override
@ -119,7 +123,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
listView = (ExpandableListView) view.findViewById(android.R.id.list);
View bottomShadowView = inflater.inflate(R.layout.card_bottom_divider, listView, false);
listView.addFooterView(bottomShadowView);
if (!showSettingsOnly) {
listView.addFooterView(bottomShadowView);
}
adapter = new LocalIndexesAdapter(this);
listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
@Override
@ -158,7 +164,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
}
listView.setAdapter(adapter);
loadLocalIndexesTask = new LoadLocalIndexTask(adapter, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (!showSettingsOnly) {
loadLocalIndexesTask = new LoadLocalIndexTask(adapter, this).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
return view;
}
@ -169,14 +177,20 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
if (getSettings().LIVE_UPDATES_PURCHASED.get()) {
ImageView statusIcon = (ImageView) subscriptionHeader.findViewById(R.id.statusIcon);
TextView statusTextView = (TextView) subscriptionHeader.findViewById(R.id.statusTextView);
TextView regionNameHeaderTextView = (TextView) subscriptionHeader.findViewById(R.id.regionHeaderTextView);
TextView regionNameTextView = (TextView) subscriptionHeader.findViewById(R.id.regionTextView);
statusTextView.setText(getString(R.string.osm_live_active));
statusIcon.setImageDrawable(getMyApplication().getIconsCache().getThemedIcon(R.drawable.ic_action_done));
regionNameHeaderTextView.setText(R.string.osm_live_support_region);
String countryName = getSettings().BILLING_USER_COUNTRY.get();
if (Algorithms.isEmpty(countryName)) {
WorldRegion world = getMyApplication().getRegions().getWorldRegion();
countryName = world.getLocaleName();
if (getSettings().BILLING_USER_COUNTRY_DOWNLOAD_NAME.get().equals(OsmandSettings.BILLING_USER_DONATION_NONE_PARAMETER)) {
regionNameHeaderTextView.setText(R.string.default_buttons_support);
countryName = getString(R.string.osmand_team);
} else {
WorldRegion world = getMyApplication().getRegions().getWorldRegion();
countryName = world.getLocaleName();
}
}
regionNameTextView.setText(countryName);
@ -228,7 +242,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public void onDestroyView() {
super.onDestroyView();
loadLocalIndexesTask.cancel(true);
if (loadLocalIndexesTask != null) {
loadLocalIndexesTask.cancel(true);
}
}
@Override
@ -461,7 +477,9 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public int getChildrenCount(int groupPosition) {
if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
if (showSettingsOnly) {
return 0;
}else if (groupPosition == SHOULD_UPDATE_GROUP_POSITION) {
return dataShouldUpdate.size();
} else if (groupPosition == SHOULD_NOT_UPDATE_GROUP_POSITION) {
return dataShouldNotUpdate.size();
@ -483,7 +501,11 @@ public class LiveUpdatesFragment extends BaseOsmAndFragment implements InAppPurc
@Override
public int getGroupCount() {
return dataShouldNotUpdate.size() == 0 ? 1 : 2;
if (showSettingsOnly) {
return 0;
} else {
return dataShouldNotUpdate.size() == 0 ? 1 : 2;
}
}
@Override

View file

@ -11,27 +11,36 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar;
import android.view.MenuItem;
import android.view.View;
import net.osmand.AndroidNetworkUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment;
import net.osmand.plus.chooseplan.ChoosePlanDialogFragment.ChoosePlanDialogListener;
import net.osmand.plus.download.AbstractDownloadActivity;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import org.apache.commons.logging.Log;
import java.lang.ref.WeakReference;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.TimeZone;
public class OsmLiveActivity extends AbstractDownloadActivity implements DownloadEvents {
public class OsmLiveActivity extends AbstractDownloadActivity implements DownloadEvents, ChoosePlanDialogListener {
private final static Log LOG = PlatformUtil.getLog(OsmLiveActivity.class);
public final static String OPEN_SUBSCRIPTION_INTENT_PARAM = "open_subscription_intent_param";
public final static String SHOW_SETTINGS_ONLY_INTENT_PARAM = "show_settings_only_intent_param";
public final static String CHOOSE_PLAN_DIALOG_DISMISSED_KEY = "choose_plan_dialog_dismissed_key";
private LiveUpdatesFragmentPagerAdapter pagerAdapter;
private boolean openSubscription;
private boolean showSettingOnly;
private boolean choosePlanDialogDismissed;
private GetLastUpdateDateTask getLastUpdateDateTask;
private static final String URL = "https://osmand.net/api/osmlive_status";
@ -44,18 +53,26 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
Intent intent = getIntent();
if (intent != null && intent.getExtras() != null) {
openSubscription = intent.getExtras().getBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, false);
showSettingOnly = intent.getExtras().getBoolean(SHOW_SETTINGS_ONLY_INTENT_PARAM, false);
} else if (savedInstanceState != null) {
openSubscription = savedInstanceState.getBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, false);
showSettingOnly = savedInstanceState.getBoolean(SHOW_SETTINGS_ONLY_INTENT_PARAM, false);
choosePlanDialogDismissed = savedInstanceState.getBoolean(CHOOSE_PLAN_DIALOG_DISMISSED_KEY, false);
}
ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager);
pagerAdapter = new LiveUpdatesFragmentPagerAdapter(getSupportFragmentManager(), getResources());
pagerAdapter = new LiveUpdatesFragmentPagerAdapter(getSupportFragmentManager(), getResources(), showSettingOnly);
viewPager.setAdapter(pagerAdapter);
final TabLayout tabLayout = (TabLayout) findViewById(R.id.tab_layout);
tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);
tabLayout.setupWithViewPager(viewPager);
getLastUpdateDateTask = new GetLastUpdateDateTask();
getLastUpdateDateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
if (showSettingOnly) {
tabLayout.setVisibility(View.GONE);
} else {
getLastUpdateDateTask = new GetLastUpdateDateTask(this);
getLastUpdateDateTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
@Override
@ -69,6 +86,15 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
return super.onOptionsItemSelected(item);
}
@Override
protected void onResume() {
super.onResume();
if (!getMyApplication().getSettings().LIVE_UPDATES_PURCHASED.get() && showSettingOnly
&& !choosePlanDialogDismissed) {
ChoosePlanDialogFragment.showOsmLiveInstance(getSupportFragmentManager());
}
}
@Override
protected void onPause() {
super.onPause();
@ -83,6 +109,23 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putBoolean(OPEN_SUBSCRIPTION_INTENT_PARAM, openSubscription);
outState.putBoolean(SHOW_SETTINGS_ONLY_INTENT_PARAM, showSettingOnly);
outState.putBoolean(CHOOSE_PLAN_DIALOG_DISMISSED_KEY, choosePlanDialogDismissed);
}
@Override
public void onChoosePlanDialogDismissed() {
choosePlanDialogDismissed = true;
}
public boolean isShowSettingOnly() {
return showSettingOnly;
}
public boolean isInAppPurchaseAllowed() {
return true;
}
@ -105,12 +148,20 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
return openSubscription;
}
private class GetLastUpdateDateTask extends AsyncTask<Void, Void, String> {
private static class GetLastUpdateDateTask extends AsyncTask<Void, Void, String> {
private OsmandApplication app;
private WeakReference<OsmLiveActivity> activity;
GetLastUpdateDateTask(OsmLiveActivity activity) {
this.activity = new WeakReference<>(activity);
app = activity.getMyApplication();
}
@Override
protected String doInBackground(Void... params) {
try {
return AndroidNetworkUtils.sendRequest(getMyApplication(), URL, null, "Requesting map updates info...", false, false);
return AndroidNetworkUtils.sendRequest(app, URL, null, "Requesting map updates info...", false, false);
} catch (Exception e) {
LOG.error("Error: " + "Requesting map updates info error", e);
return null;
@ -119,8 +170,9 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
@Override
protected void onPostExecute(String response) {
if (response != null) {
ActionBar actionBar = getSupportActionBar();
OsmLiveActivity a = activity.get();
if (response != null && a != null) {
ActionBar actionBar = a.getSupportActionBar();
if (actionBar != null) {
SimpleDateFormat source = new SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.US);
source.setTimeZone(TimeZone.getTimeZone("UTC"));
@ -141,9 +193,11 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
private final Fragment[] fragments = new Fragment[] { new LiveUpdatesFragment(), new ReportsFragment() };
private static final int[] titleIds = new int[] { LiveUpdatesFragment.TITLE, ReportsFragment.TITLE };
private final String[] titles;
private final boolean showSettingsOnly;
public LiveUpdatesFragmentPagerAdapter(FragmentManager fm, Resources res) {
LiveUpdatesFragmentPagerAdapter(FragmentManager fm, Resources res, boolean showSettingsOnly) {
super(fm);
this.showSettingsOnly = showSettingsOnly;
titles = new String[titleIds.length];
for (int i = 0; i < titleIds.length; i++) {
titles[i] = res.getString(titleIds[i]);
@ -152,7 +206,7 @@ public class OsmLiveActivity extends AbstractDownloadActivity implements Downloa
@Override
public int getCount() {
return fragments.length;
return showSettingsOnly ? 1 : fragments.length;
}
@Override

View file

@ -22,6 +22,7 @@ import android.view.Window;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment;
public class WikivoyageBaseDialogFragment extends BaseOsmAndDialogFragment {
@ -89,8 +90,12 @@ public class WikivoyageBaseDialogFragment extends BaseOsmAndDialogFragment {
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
closeFragment();
}
});
}
protected void closeFragment() {
dismiss();
}
}

View file

@ -10,6 +10,7 @@ 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.v4.app.FragmentManager.BackStackEntry;
import android.support.v7.widget.PopupMenu;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
@ -22,7 +23,6 @@ import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.IndexConstants;
import net.osmand.plus.OsmandApplication;
@ -37,6 +37,7 @@ import net.osmand.plus.wikivoyage.WikivoyageWebViewClient;
import net.osmand.plus.wikivoyage.data.TravelArticle;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.data.TravelLocalDataHelper;
import net.osmand.plus.wikivoyage.explore.WikivoyageExploreDialogFragment;
import net.osmand.util.Algorithms;
import java.io.File;
@ -491,4 +492,22 @@ public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragmen
WikivoyageArticleDialogFragment.this, cityId, selectedLang);
}
}
@Override
protected void closeFragment() {
int backStackEntryCount = getFragmentManager().getBackStackEntryCount();
int pop = -1;
for(int i = backStackEntryCount - 1; i >= 0; i--) {
BackStackEntry entry = getFragmentManager().getBackStackEntryAt(i);
if(!TAG.equals(entry.getName())) {
pop = i;
break;
}
}
if(pop == -1) {
dismiss();
} else {
getFragmentManager().popBackStackImmediate(pop, 0);
}
}
}

View file

@ -147,13 +147,7 @@ public class WikivoyageArticleNavigationFragment extends MenuBottomSheetDialogFr
}
private void sendResults(long cityId) {
Fragment fragment = getTargetFragment();
if (fragment != null) {
Intent intent = new Intent();
intent.putExtra(CITY_ID_KEY, cityId);
intent.putExtra(SELECTED_LANG_KEY, selectedLang);
fragment.onActivityResult(getTargetRequestCode(), OPEN_ARTICLE_REQUEST_CODE, intent);
}
WikivoyageArticleDialogFragment.showInstance(getMyApplication(), getFragmentManager(), cityId, selectedLang);
}
public static boolean showInstance(@NonNull FragmentManager fm,

View file

@ -90,6 +90,7 @@ public class TravelDbHelper {
private File selectedTravelBook = null;
private List<File> existingTravelBooks = new ArrayList<>();
private List<TravelArticle> popularArticles = new ArrayList<TravelArticle>();
public TravelDbHelper(OsmandApplication application) {
this.application = application;
@ -119,7 +120,11 @@ public class TravelDbHelper {
} else {
selectedTravelBook = null;
}
}
public void loadDataForSelectedTravelBook() {
localDataHelper.refreshCachedData();
loadPopularArticles();
}
public File getSelectedTravelBook() {
@ -145,7 +150,6 @@ public class TravelDbHelper {
connection = application.getSQLiteAPI().openByAbsolutePath(f.getAbsolutePath(), true);
selectedTravelBook = f;
application.getSettings().SELECTED_TRAVEL_BOOK.set(selectedTravelBook.getName());
localDataHelper.refreshCachedData();
}
}
@ -205,7 +209,12 @@ public class TravelDbHelper {
}
@NonNull
public List<TravelArticle> searchPopular() {
public List<TravelArticle> getPopularArticles() {
return popularArticles;
}
@NonNull
public List<TravelArticle> loadPopularArticles() {
List<TravelArticle> res = new ArrayList<>();
SQLiteConnection conn = openConnection();
if (conn != null) {
@ -214,7 +223,7 @@ public class TravelDbHelper {
+ ARTICLES_TABLE_NAME
+ " WHERE article_id IN (SELECT article_id FROM "
+ ARTICLES_TABLE_NAME
+ " ORDER BY RANDOM() LIMIT 100) LIMIT 100", null);
+ " ORDER BY RANDOM() LIMIT 20) LIMIT 20", null);
if (cursor.moveToFirst()) {
do {
travelArticle = readArticle(cursor);
@ -223,9 +232,8 @@ public class TravelDbHelper {
}
cursor.close();
}
sortArticlesByDistance(res);
popularArticles = res;
return res;
}
@ -362,22 +370,23 @@ public class TravelDbHelper {
cursor.close();
}
LinkedHashMap<WikivoyageSearchResult, List<WikivoyageSearchResult>> res = new LinkedHashMap<>();
parts = parts == null ? new String[]{} : parts;
for (String header : parts) {
WikivoyageSearchResult searchResult = headerObjs.get(header);
List<WikivoyageSearchResult> results = navMap.get(header);
if (results != null) {
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
@Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
}
});
WikivoyageSearchResult emptyResult = new WikivoyageSearchResult();
emptyResult.articleTitles.add(header);
emptyResult.cityId = -1;
searchResult = searchResult != null ? searchResult : emptyResult;
res.put(searchResult, results);
if (parts != null) {
for (String header : parts) {
WikivoyageSearchResult searchResult = headerObjs.get(header);
List<WikivoyageSearchResult> results = navMap.get(header);
if (results != null) {
Collections.sort(results, new Comparator<WikivoyageSearchResult>() {
@Override
public int compare(WikivoyageSearchResult o1, WikivoyageSearchResult o2) {
return collator.compare(o1.articleTitles.get(0), o2.articleTitles.get(0));
}
});
WikivoyageSearchResult emptyResult = new WikivoyageSearchResult();
emptyResult.articleTitles.add(header);
emptyResult.cityId = -1;
searchResult = searchResult != null ? searchResult : emptyResult;
res.put(searchResult, results);
}
}
}
return res;

View file

@ -34,10 +34,9 @@ public class TravelLocalDataHelper {
dbHelper = new WikivoyageLocalDataDbHelper(app);
}
public void refreshCachedData() {
void refreshCachedData() {
historyMap = dbHelper.getAllHistoryMap();
savedArticles = dbHelper.getSavedArticles();
notifySavedUpdated();
savedArticles = dbHelper.readSavedArticles();
}
public List<WikivoyageSearchHistoryItem> getAllHistory() {
@ -115,7 +114,7 @@ public class TravelLocalDataHelper {
savedArticles.add(article);
dbHelper.addSavedArticle(article);
notifySavedUpdated();
}
}
}
public void removeArticleFromSaved(@NonNull TravelArticle article) {
@ -357,7 +356,7 @@ public class TravelLocalDataHelper {
}
@NonNull
List<TravelArticle> getSavedArticles() {
List<TravelArticle> readSavedArticles() {
List<TravelArticle> res = new ArrayList<>();
String travelBook = getSelectedTravelBookName();
if (travelBook == null) {

View file

@ -1,9 +1,10 @@
package net.osmand.plus.wikivoyage.explore;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -14,7 +15,6 @@ import android.widget.Toast;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.Version;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadValidationManager;
@ -29,12 +29,13 @@ import net.osmand.plus.wikivoyage.explore.travelcards.StartEditingTravelCard;
import net.osmand.plus.wikivoyage.explore.travelcards.TravelDownloadUpdateCard;
import java.io.File;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIndexesThread.DownloadEvents {
private static final String WORLD_WIKIVOYAGE_FILE_NAME = "World_wikivoyage.sqlite";
private ExploreRvAdapter adapter = new ExploreRvAdapter();
private StartEditingTravelCard startEditingTravelCard;
@ -44,9 +45,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
private IndexItem indexItem;
private File selectedTravelBook;
private boolean downloadIndexesRequested;
private boolean downloadUpdateCardAdded;
@Nullable
@Override
@ -56,7 +55,7 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
final View mainView = inflater.inflate(R.layout.fragment_explore_tab, container, false);
final RecyclerView rv = (RecyclerView) mainView.findViewById(R.id.recycler_view);
adapter.setItems(generateItems());
populateData();
rv.setLayoutManager(new LinearLayoutManager(getContext()));
rv.setAdapter(adapter);
@ -64,15 +63,53 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
return mainView;
}
public void populateData() {
final List<BaseTravelCard> items = new ArrayList<>();
final OsmandApplication app = getMyApplication();
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
addOpenBetaTravelCard(items, nightMode);
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
List<TravelArticle> popularArticles = app.getTravelDbHelper().getPopularArticles();
FragmentActivity activity = getActivity();
if (activity != null) {
for (TravelArticle article : popularArticles) {
items.add(new ArticleTravelCard(getMyApplication(), nightMode, article,
activity.getSupportFragmentManager()));
}
}
}
items.add(startEditingTravelCard);
adapter.setItems(items);
checkToAddDownloadTravelCard();
}
private void checkToAddDownloadTravelCard() {
final OsmandApplication app = getMyApplication();
final DownloadIndexesThread downloadThread = app.getDownloadThread();
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
downloadIndexesRequested = true;
downloadThread.runReloadIndexFilesSilent();
} else {
indexItem = downloadThread.getIndexes().getWikivoyageItem(getWikivoyageFileName());
IndexItem current = downloadThread.getCurrentDownloadingItem();
boolean loadingInProgress = current != null && indexItem != null && current == indexItem;
addDownloadUpdateCard(loadingInProgress);
}
}
@Override
public void newDownloadIndexes() {
if (downloadIndexesRequested) {
downloadIndexesRequested = false;
if (selectedTravelBook != null) {
indexItem = getMyApplication().getDownloadThread().getIndexes()
.getWikivoyageItem(selectedTravelBook.getName());
indexItem = getMyApplication().getDownloadThread().getIndexes()
.getWikivoyageItem(getWikivoyageFileName());
if (downloadUpdateCard == null) {
addDownloadUpdateCard(false);
}
addDownloadUpdateCard(false);
}
}
@ -80,14 +117,11 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
public void downloadInProgress() {
DownloadIndexesThread downloadThread = getMyApplication().getDownloadThread();
IndexItem current = downloadThread.getCurrentDownloadingItem();
if (selectedTravelBook != null) {
indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
}
if (current != null
indexItem = downloadThread.getIndexes().getWikivoyageItem(getWikivoyageFileName());
if (current != null && downloadUpdateCard != null
&& indexItem != null
&& current == indexItem
&& (!current.isDownloaded() || current.isOutdated())) {
addDownloadUpdateCard(true);
downloadUpdateCard.setProgress(downloadThread.getCurrentDownloadingItemProgress());
adapter.updateDownloadUpdateCard();
}
@ -95,22 +129,26 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
@Override
public void downloadHasFinished() {
IndexItem current = getMyApplication().getDownloadThread().getCurrentDownloadingItem();
if (downloadUpdateCard != null && current != null && indexItem != null && current == indexItem) {
final OsmandApplication app = getMyApplication();
File targetFile = indexItem.getTargetFile(app);
if (downloadUpdateCard != null && indexItem != null && targetFile.exists()) {
downloadUpdateCard.setLoadingInProgress(false);
removeDownloadUpdateCard();
TravelDbHelper travelDbHelper = app.getTravelDbHelper();
travelDbHelper.initTravelBooks();
travelDbHelper.selectTravelBook(targetFile);
Fragment parent = getParentFragment();
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
((WikivoyageExploreDialogFragment) parent).populateData();
}
}
}
private void addDownloadUpdateCard(boolean loadingInProgress) {
if (downloadUpdateCardAdded) {
return;
}
final OsmandApplication app = getMyApplication();
boolean outdated = indexItem != null && indexItem.isOutdated();
File selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
if (selectedTravelBook == null || outdated) {
downloadUpdateCard = new TravelDownloadUpdateCard(app, nightMode, !outdated);
downloadUpdateCard.setLoadingInProgress(loadingInProgress);
@ -139,54 +177,18 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
});
downloadUpdateCard.setIndexItem(indexItem);
adapter.setDownloadUpdateCard(downloadUpdateCard);
downloadUpdateCardAdded = true;
}
}
@NonNull
private String getWikivoyageFileName() {
File selectedTravelBook = getMyApplication().getTravelDbHelper().getSelectedTravelBook();
return selectedTravelBook == null ? WORLD_WIKIVOYAGE_FILE_NAME : selectedTravelBook.getName();
}
private void removeDownloadUpdateCard() {
adapter.removeDownloadUpdateCard();
downloadUpdateCardAdded = false;
}
private List<BaseTravelCard> generateItems() {
final List<BaseTravelCard> items = new ArrayList<>();
final OsmandApplication app = getMyApplication();
checkSelectedTravelBook();
startEditingTravelCard = new StartEditingTravelCard(app, nightMode);
addOpenBetaTravelCard(items, nightMode);
items.add(startEditingTravelCard);
if (app.getTravelDbHelper().getSelectedTravelBook() != null) {
items.add(new HeaderTravelCard(app, nightMode, getString(R.string.popular_destinations)));
addPopularDestinations(app);
}
return items;
}
private void checkSelectedTravelBook() {
final OsmandApplication app = getMyApplication();
final DownloadIndexesThread downloadThread = app.getDownloadThread();
selectedTravelBook = app.getTravelDbHelper().getSelectedTravelBook();
if (!downloadThread.getIndexes().isDownloadedFromInternet) {
downloadIndexesRequested = true;
downloadThread.runReloadIndexFilesSilent();
} else {
if (selectedTravelBook != null) {
indexItem = downloadThread.getIndexes().getWikivoyageItem(selectedTravelBook.getName());
}
IndexItem current = downloadThread.getCurrentDownloadingItem();
boolean loadingInProgress = current != null && indexItem != null && current == indexItem;
addDownloadUpdateCard(loadingInProgress);
}
}
private void addPopularDestinations(OsmandApplication app) {
PopularDestinationsSearchTask popularDestinationsSearchTask = new PopularDestinationsSearchTask(
app.getTravelDbHelper(), getMyActivity(), adapter, nightMode, startEditingTravelCard);
popularDestinationsSearchTask.execute();
downloadUpdateCard = null;
}
private void addOpenBetaTravelCard(List<BaseTravelCard> items, final boolean nightMode) {
@ -195,48 +197,4 @@ public class ExploreTabFragment extends BaseOsmAndFragment implements DownloadIn
items.add(new OpenBetaTravelCard(app, nightMode, getFragmentManager()));
}
}
private static class PopularDestinationsSearchTask extends AsyncTask<Void, TravelDbHelper, List<TravelArticle>> {
private TravelDbHelper travelDbHelper;
private WeakReference<OsmandActionBarActivity> weakContext;
private WeakReference<ExploreRvAdapter> weakAdapter;
private WeakReference<StartEditingTravelCard> weakStartEditingTravelCard;
private boolean nightMode;
PopularDestinationsSearchTask(TravelDbHelper travelDbHelper,
OsmandActionBarActivity context, ExploreRvAdapter adapter, boolean nightMode, StartEditingTravelCard startEditingTravelCard) {
this.travelDbHelper = travelDbHelper;
weakContext = new WeakReference<>(context);
weakAdapter = new WeakReference<>(adapter);
weakStartEditingTravelCard = new WeakReference<>(startEditingTravelCard);
this.nightMode = nightMode;
}
@Override
protected List<TravelArticle> doInBackground(Void... voids) {
return travelDbHelper.searchPopular();
}
@Override
protected void onPostExecute(List<TravelArticle> items) {
OsmandActionBarActivity activity = weakContext.get();
ExploreRvAdapter adapter = weakAdapter.get();
StartEditingTravelCard startEditingTravelCard = weakStartEditingTravelCard.get();
if (activity != null && adapter != null && startEditingTravelCard != null) {
List<BaseTravelCard> adapterItems = adapter.getItems();
if (adapterItems.contains(startEditingTravelCard)) {
adapterItems.remove(startEditingTravelCard);
}
for (TravelArticle article : items) {
adapterItems.add(new ArticleTravelCard(activity.getMyApplication(), nightMode, article, activity.getSupportFragmentManager()));
}
adapterItems.add(startEditingTravelCard);
adapter.notifyDataSetChanged();
}
}
}
}
}

View file

@ -3,6 +3,7 @@ package net.osmand.plus.wikivoyage.explore;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -26,11 +27,14 @@ import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.data.TravelDbHelper;
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.List;
public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragment implements DownloadIndexesThread.DownloadEvents {
public static final String TAG = "WikivoyageExploreDialogFragment";
@ -41,6 +45,8 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
private ExploreTabFragment exploreTabFragment;
private SavedArticlesTabFragment savedArticlesTabFragment;
private View mainView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -71,7 +77,7 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
savedArticlesTabFragment = new SavedArticlesTabFragment();
}
final View mainView = inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
this.mainView = inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
@ -131,9 +137,34 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
}
});
updateSearchVisibility();
populateData();
return mainView;
}
protected void onDataLoaded() {
mainView.findViewById(R.id.progress_bar).setVisibility(View.GONE);
updateSearchVisibility();
if (exploreTabFragment != null) {
exploreTabFragment.populateData();
}
if (savedArticlesTabFragment != null) {
savedArticlesTabFragment.savedArticlesUpdated();
}
}
private void updateSearchVisibility() {
mainView.findViewById(R.id.search_box).setVisibility(
getMyApplication().getTravelDbHelper().getSelectedTravelBook() == null ? View.GONE : View.VISIBLE
);
}
public void populateData() {
mainView.findViewById(R.id.progress_bar).setVisibility(View.VISIBLE);
new LoadWikivoyageData(this).execute();
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
@ -184,6 +215,31 @@ public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragmen
}
}
private static class LoadWikivoyageData extends AsyncTask<Void, Void, Void> {
private WeakReference<WikivoyageExploreDialogFragment> weakReference;
private TravelDbHelper travelDbHelper;
LoadWikivoyageData(WikivoyageExploreDialogFragment fragment) {
travelDbHelper = fragment.getMyApplication().getTravelDbHelper();
weakReference = new WeakReference<>(fragment);
}
@Override
protected Void doInBackground(Void... params) {
travelDbHelper.loadDataForSelectedTravelBook();
return null;
}
@Override
protected void onPostExecute(Void result) {
WikivoyageExploreDialogFragment fragment = weakReference.get();
if (fragment != null && fragment.isResumed()) {
fragment.onDataLoaded();
}
}
}
private class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<BaseOsmAndFragment> fragments = Arrays.asList(exploreTabFragment, savedArticlesTabFragment);

View file

@ -154,6 +154,10 @@ public class WikivoyageOptionsBottomSheetDialogFragment extends MenuBottomSheetD
@Override
public void onClick(DialogInterface dialog, int which) {
dbHelper.selectTravelBook(list.get(which));
Fragment parent = getParentFragment();
if (parent != null && parent instanceof WikivoyageExploreDialogFragment) {
((WikivoyageExploreDialogFragment) parent).populateData();
}
}
})
.setNegativeButton(R.string.shared_string_dismiss, null)

View file

@ -3,7 +3,6 @@ package net.osmand.plus.wikivoyage.explore.travelcards;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.plus.OsmandApplication;
@ -16,7 +15,6 @@ public class HeaderTravelCard extends BaseTravelCard {
private int articleItemCount;
private String title;
public HeaderTravelCard(OsmandApplication app, boolean nightMode, String title) {
super(app, nightMode);
this.title = title;
@ -30,9 +28,7 @@ public class HeaderTravelCard extends BaseTravelCard {
if (articleItemCount > 0) {
holder.description.setText(String.valueOf(articleItemCount));
holder.description.setVisibility(View.VISIBLE);
holder.progressBar.setVisibility(View.GONE);
} else {
holder.progressBar.setVisibility(View.VISIBLE);
holder.description.setVisibility(View.INVISIBLE);
}
}
@ -42,13 +38,11 @@ public class HeaderTravelCard extends BaseTravelCard {
final TextView title;
final TextView description;
final ProgressBar progressBar;
public HeaderTravelVH(View itemView) {
super(itemView);
title = (TextView) itemView.findViewById(R.id.title);
description = (TextView) itemView.findViewById(R.id.description);
progressBar = (ProgressBar) itemView.findViewById(R.id.progressBar);
}
}
@ -61,4 +55,3 @@ public class HeaderTravelCard extends BaseTravelCard {
return TYPE;
}
}