Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2018-03-29 17:15:56 +02:00
commit 5d70abe007
12 changed files with 178 additions and 130 deletions

View file

@ -17,15 +17,9 @@
</android.support.v7.widget.Toolbar>
<ScrollView
<WebView
android:id="@+id/content_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/content_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
android:layout_height="match_parent"/>
</LinearLayout>

View file

@ -142,6 +142,8 @@
<color name="status_bar_dim_light">#8a4e00</color>
<color name="status_bar_dim_dark">#13171a</color>
<color name="status_bar_coordinate_input_dark">#0d0f0f</color>
<color name="status_bar_wikivoyage_light">#f2f2f2</color>
<color name="status_bar_wikivoyage_dark">#222526</color>
<color name="color_transparent">#0000</color>
@ -384,4 +386,15 @@
<color name="grid_menu_icon_dark">#808080</color>
<color name="wikivoyage_bg_light">#f0f0f0</color>
<color name="wikivoyage_bg_dark">#17191a</color>
<color name="wikivoyage_card_bg_light">#ffffff</color>
<color name="wikivoyage_card_bg_dark">#222526</color>
<color name="wikivoyage_card_divider_light">#f0f0f0</color>
<color name="wikivoyage_card_divider_dark">#2d3133</color>
<color name="wikivoyage_active_light">#237bff</color>
<color name="wikivoyage_active_dark">#d28521</color>
<color name="wikivoyage_app_bar_light">#f2f2f2</color>
<color name="wikivoyage_app_bar_dark">#222526</color>
</resources>

View file

@ -61,4 +61,11 @@ public class BaseOsmAndDialogFragment extends DialogFragment {
protected OsmandSettings getSettings() {
return getMyApplication().getSettings();
}
protected boolean isNightMode(boolean usedOnMap) {
if (usedOnMap) {
return getMyApplication().getDaynightHelper().isNightModeForMapControls();
}
return !getSettings().isLightContent();
}
}

View file

@ -637,7 +637,7 @@ public class GpxUiHelper {
}
});
}
dlg.getListView().addFooterView(footerView);
dlg.getListView().addFooterView(footerView, null, false);
}
dlg.getListView().setOnItemClickListener(new OnItemClickListener() {
@Override

View file

@ -323,7 +323,9 @@ public class ExtendedBottomSheetBehavior<V extends View> extends CoordinatorLayo
if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) {
return true;
}
mViewDragHelper.processTouchEvent(event);
if (mViewDragHelper != null) {
mViewDragHelper.processTouchEvent(event);
}
// Record the velocity
if (action == MotionEvent.ACTION_DOWN) {
reset();

View file

@ -1,58 +1,48 @@
package net.osmand.plus.wikivoyage;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.webkit.WebView;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageArticle;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
public class WikivoyageArticleDialogFragment extends BaseOsmAndDialogFragment {
public class WikivoyageArticleDialogFragment extends WikivoyageBaseDialogFragment {
public static final String TAG = "WikivoyageArticleDialogFragment";
private WikivoyageSearchResult searchResult;
public void setSearchResult(WikivoyageSearchResult searchResult) {
this.searchResult = searchResult;
}
private static final String SEARCH_RESULT_KEY = "search_result_key";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_article_dialog, container);
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mainView = inflate(R.layout.fragment_wikivoyage_article_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
TextView contentTv = (TextView) mainView.findViewById(R.id.content_text_view);
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper().getArticle(searchResult.getCityId(),
searchResult.getLang().get(0));
contentTv.setText(new SpannableString(Html.fromHtml(article.getContent())));
WikivoyageSearchResult searchResult = (WikivoyageSearchResult) getArguments().getParcelable(SEARCH_RESULT_KEY);
WikivoyageArticle article = getMyApplication().getWikivoyageDbHelper()
.getArticle(searchResult.getCityId(), searchResult.getLang().get(0));
WebView contentWebView = (WebView) mainView.findViewById(R.id.content_web_view);
contentWebView.loadData(article.getContent(), "text/html", "UTF-8");
return mainView;
}
public static boolean showInstance(FragmentManager fm, WikivoyageSearchResult searchResult) {
try {
Bundle args = new Bundle();
args.putParcelable(SEARCH_RESULT_KEY, searchResult);
WikivoyageArticleDialogFragment fragment = new WikivoyageArticleDialogFragment();
fragment.setSearchResult(searchResult);
fragment.setArguments(args);
fragment.show(fm, TAG);
return true;
} catch (RuntimeException e) {

View file

@ -0,0 +1,47 @@
package net.osmand.plus.wikivoyage;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.support.annotation.Nullable;
import android.support.v7.widget.Toolbar;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
public class WikivoyageBaseDialogFragment extends BaseOsmAndDialogFragment {
protected boolean nightMode;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
nightMode = isNightMode(false);
}
@Override
protected Drawable getContentIcon(int id) {
return getIcon(id, R.color.icon_color);
}
protected View inflate(@LayoutRes int layoutId, @Nullable ViewGroup container) {
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
return LayoutInflater.from(new ContextThemeWrapper(getContext(), themeRes))
.inflate(layoutId, container, false);
}
protected void setupToolbar(Toolbar toolbar) {
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.wikivoyage;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.Toolbar;
@ -10,27 +11,18 @@ import android.view.ViewGroup;
import android.widget.ImageView;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.search.WikivoyageSearchDialogFragment;
public class WikivoyageExploreDialogFragment extends BaseOsmAndDialogFragment {
public class WikivoyageExploreDialogFragment extends WikivoyageBaseDialogFragment {
public static final String TAG = "WikivoyageExploreDialogFragment";
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mainView = inflater.inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final View mainView = inflate(R.layout.fragment_wikivoyage_explore_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
setupToolbar((Toolbar) mainView.findViewById(R.id.toolbar));
((ImageView) mainView.findViewById(R.id.search_icon))
.setImageDrawable(getContentIcon(R.drawable.ic_action_search_dark));

View file

@ -1,15 +1,29 @@
package net.osmand.plus.wikivoyage.data;
import android.os.Parcel;
import android.os.Parcelable;
import java.util.ArrayList;
import java.util.List;
public class WikivoyageSearchResult {
public class WikivoyageSearchResult implements Parcelable {
List<String> searchTerm = new ArrayList<>();
long cityId;
List<String> articleTitle = new ArrayList<>();
List<String> langs = new ArrayList<>();
WikivoyageSearchResult() {
}
private WikivoyageSearchResult(Parcel in) {
searchTerm = in.createStringArrayList();
cityId = in.readLong();
articleTitle = in.createStringArrayList();
langs = in.createStringArrayList();
}
public List<String> getSearchTerm() {
return searchTerm;
}
@ -25,4 +39,29 @@ public class WikivoyageSearchResult {
public List<String> getLang() {
return langs;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeStringList(searchTerm);
dest.writeLong(cityId);
dest.writeStringList(articleTitle);
dest.writeStringList(langs);
}
public static final Creator<WikivoyageSearchResult> CREATOR = new Creator<WikivoyageSearchResult>() {
@Override
public WikivoyageSearchResult createFromParcel(Parcel in) {
return new WikivoyageSearchResult(in);
}
@Override
public WikivoyageSearchResult[] newArray(int size) {
return new WikivoyageSearchResult[size];
}
};
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.wikivoyage.search;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
@ -23,8 +24,9 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
this.onItemClickListener = onItemClickListener;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
public ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View itemView = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.wikivoyage_search_list_item, viewGroup, false);
itemView.setOnClickListener(onItemClickListener);
@ -32,7 +34,7 @@ public class SearchRecyclerViewAdapter extends RecyclerView.Adapter<SearchRecycl
}
@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
public void onBindViewHolder(@NonNull ViewHolder viewHolder, int i) {
WikivoyageSearchResult item = items.get(i);
// FIXME
viewHolder.searchTerm.setText(item.getSearchTerm().toString());

View file

@ -1,6 +1,7 @@
package net.osmand.plus.wikivoyage.search;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v7.widget.LinearLayoutManager;
@ -8,7 +9,6 @@ import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -17,16 +17,14 @@ import android.widget.ImageButton;
import android.widget.ProgressBar;
import net.osmand.ResultMatcher;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageArticleDialogFragment;
import net.osmand.plus.wikivoyage.WikivoyageBaseDialogFragment;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import net.osmand.plus.wikivoyage.search.WikivoyageSearchHelper.SearchListener;
import java.util.List;
public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment implements SearchListener {
public class WikivoyageSearchDialogFragment extends WikivoyageBaseDialogFragment {
public static final String TAG = "WikivoyageSearchDialogFragment";
@ -34,7 +32,7 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
private String searchQuery = "";
private boolean paused;
private boolean cancelPrev;
private boolean cancelled;
private SearchRecyclerViewAdapter adapter;
@ -44,24 +42,13 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
final OsmandApplication app = getMyApplication();
searchHelper = new WikivoyageSearchHelper(app);
final boolean nightMode = !app.getSettings().isLightContent();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
searchHelper = new WikivoyageSearchHelper(getMyApplication());
final View mainView = LayoutInflater.from(new ContextThemeWrapper(app, themeRes))
.inflate(R.layout.fragment_wikivoyage_search_dialog, container, false);
final View mainView = inflate(R.layout.fragment_wikivoyage_search_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.toolbar);
toolbar.setNavigationIcon(getContentIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
setupToolbar(toolbar);
searchEt = (EditText) toolbar.findViewById(R.id.searchEditText);
searchEt.setHint(R.string.shared_string_search);
@ -123,7 +110,6 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
public void onResume() {
super.onResume();
paused = false;
searchHelper.registerListener(this);
searchEt.requestFocus();
}
@ -131,47 +117,35 @@ public class WikivoyageSearchDialogFragment extends BaseOsmAndDialogFragment imp
public void onPause() {
super.onPause();
paused = true;
searchHelper.unregisterListener();
}
@Override
public void onSearchStarted() {
getMyApplication().runInUIThread(new Runnable() {
public void run() {
switchProgressBarVisibility(true);
}
});
}
@Override
public void onSearchFinished(@Nullable final List<WikivoyageSearchResult> results) {
getMyApplication().runInUIThread(new Runnable() {
public void run() {
adapter.setItems(results);
switchProgressBarVisibility(false);
}
});
}
private void cancelSearch() {
cancelPrev = true;
cancelled = true;
if (!paused) {
switchProgressBarVisibility(false);
}
}
private void runSearch() {
cancelPrev = true;
searchHelper.search(searchQuery, new ResultMatcher<WikivoyageSearchResult>() {
switchProgressBarVisibility(true);
cancelled = false;
searchHelper.search(searchQuery, new ResultMatcher<List<WikivoyageSearchResult>>() {
@Override
public boolean publish(WikivoyageSearchResult object) {
cancelPrev = false;
public boolean publish(final List<WikivoyageSearchResult> results) {
getMyApplication().runInUIThread(new Runnable() {
public void run() {
if (!isCancelled()) {
adapter.setItems(results);
switchProgressBarVisibility(false);
}
}
});
return true;
}
@Override
public boolean isCancelled() {
return paused || cancelPrev;
return paused || cancelled;
}
});
}

View file

@ -1,7 +1,5 @@
package net.osmand.plus.wikivoyage.search;
import android.support.annotation.Nullable;
import net.osmand.ResultMatcher;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
@ -9,6 +7,7 @@ import net.osmand.plus.wikivoyage.data.WikivoyageSearchResult;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
public class WikivoyageSearchHelper {
@ -18,55 +17,44 @@ public class WikivoyageSearchHelper {
private ExecutorService singleThreadExecutor = Executors.newSingleThreadExecutor();
private OsmandApplication application;
private SearchListener listener;
private AtomicInteger requestNumber = new AtomicInteger();
WikivoyageSearchHelper(OsmandApplication application) {
this.application = application;
}
public void registerListener(SearchListener listener) {
this.listener = listener;
}
public void search(final String query, final ResultMatcher<List<WikivoyageSearchResult>> rm) {
final int req = requestNumber.incrementAndGet();
public void unregisterListener() {
this.listener = null;
}
public void search(final String query, final ResultMatcher<WikivoyageSearchResult> rm) {
singleThreadExecutor.submit(new Runnable() {
final int request = req;
@Override
public void run() {
try {
if (listener != null) {
listener.onSearchStarted();
}
rm.publish(null);
long startTime = System.currentTimeMillis();
while (System.currentTimeMillis() - startTime <= TIMEOUT_BETWEEN_CHARS) {
if (rm.isCancelled()) {
if (isCancelled()) {
return;
}
Thread.sleep(SLEEP_TIME);
}
final List<WikivoyageSearchResult> results = application.getWikivoyageDbHelper().search(query);
if (listener != null) {
listener.onSearchFinished(results);
if (!isCancelled()) {
List<WikivoyageSearchResult> results = application.getWikivoyageDbHelper().search(query);
if (!isCancelled()) {
rm.publish(results);
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
private boolean isCancelled() {
return requestNumber.get() != request || rm.isCancelled();
}
});
}
public interface SearchListener {
void onSearchStarted();
void onSearchFinished(@Nullable List<WikivoyageSearchResult> results);
}
}