forked from organicmaps/organicmaps
[new downloader][android] refactor: SearchToolbarController fixes.
This commit is contained in:
parent
0c3af7ea88
commit
87936569d6
5 changed files with 90 additions and 37 deletions
|
@ -37,8 +37,7 @@
|
|||
android:background="?attr/selectableItemBackgroundBorderless"
|
||||
android:contentDescription="@null"
|
||||
android:scaleType="center"
|
||||
android:src="@drawable/ic_cancel"
|
||||
android:tint="?iconTint"/>
|
||||
android:src="@drawable/ic_cancel"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/voice_input"
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package com.mapswithme.maps.downloader;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
|
@ -12,6 +13,9 @@ import android.widget.TextView;
|
|||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmRecyclerFragment;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.search.NativeSearchListener;
|
||||
import com.mapswithme.maps.search.SearchEngine;
|
||||
import com.mapswithme.maps.search.SearchResult;
|
||||
import com.mapswithme.maps.widget.SearchToolbarController;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
|
@ -37,6 +41,21 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
}
|
||||
};
|
||||
|
||||
private final NativeSearchListener mSearchListener = new NativeSearchListener()
|
||||
{
|
||||
@Override
|
||||
public void onResultsUpdate(SearchResult[] results, long timestamp)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResultsEnd(long timestamp)
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
private class ToolbarController extends SearchToolbarController
|
||||
{
|
||||
private final View mDownloadAll;
|
||||
|
@ -113,6 +132,12 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
UiUtils.showIf(download, mDownloadAll);
|
||||
UiUtils.showIf(onTop, mQuery);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startVoiceRecognition(Intent intent, int code)
|
||||
{
|
||||
startActivityForResult(intent, code);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateBottomPanel()
|
||||
|
@ -152,6 +177,8 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
@Override
|
||||
public void onProgress(String countryId, long localSize, long remoteSize) {}
|
||||
});
|
||||
|
||||
SearchEngine.INSTANCE.addListener(mSearchListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -163,6 +190,9 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
MapManager.nativeUnsubscribe(mSubscriberSlot);
|
||||
mSubscriberSlot = 0;
|
||||
}
|
||||
|
||||
SearchEngine.INSTANCE.removeListener(mSearchListener);
|
||||
SearchEngine.cancelSearch();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -230,4 +260,11 @@ public class DownloaderFragment extends BaseMwmRecyclerFragment
|
|||
|
||||
return mAdapter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
mToolbarController.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ public enum SearchEngine implements NativeSearchListener
|
|||
{
|
||||
for (NativeSearchListener listener : mListeners)
|
||||
listener.onResultsUpdate(results, timestamp);
|
||||
mListeners.finishIterate();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.mapswithme.maps.search;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.location.Location;
|
||||
import android.os.Build;
|
||||
|
@ -24,19 +22,15 @@ import com.mapswithme.maps.Framework;
|
|||
import com.mapswithme.maps.MwmActivity;
|
||||
import com.mapswithme.maps.R;
|
||||
import com.mapswithme.maps.base.BaseMwmFragment;
|
||||
import com.mapswithme.maps.base.BaseMwmFragmentActivity;
|
||||
import com.mapswithme.maps.base.OnBackPressListener;
|
||||
import com.mapswithme.maps.bookmarks.data.MapObject;
|
||||
import com.mapswithme.maps.downloader.CountrySuggestFragment;
|
||||
import com.mapswithme.maps.downloader.DownloaderFragment;
|
||||
import com.mapswithme.maps.downloader.MapManager;
|
||||
import com.mapswithme.maps.location.LocationHelper;
|
||||
import com.mapswithme.maps.routing.RoutingController;
|
||||
import com.mapswithme.maps.widget.SearchToolbarController;
|
||||
import com.mapswithme.util.InputUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.Utils;
|
||||
import com.mapswithme.util.statistics.AlohaHelper;
|
||||
import com.mapswithme.util.statistics.Statistics;
|
||||
|
||||
|
||||
|
@ -46,7 +40,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
SearchToolbarController.Container,
|
||||
CategoriesAdapter.OnCategorySelectedListener
|
||||
{
|
||||
private static final int RC_VOICE_RECOGNITION = 0xCA11;
|
||||
private long mLastQueryTimestamp;
|
||||
|
||||
private static class LastPosition
|
||||
|
@ -99,15 +92,15 @@ public class SearchFragment extends BaseMwmFragment
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void onVoiceInputClick()
|
||||
protected int getVoiceInputPrompt()
|
||||
{
|
||||
try
|
||||
{
|
||||
startActivityForResult(InputUtils.createIntentForVoiceRecognition(getString(R.string.search_map)), RC_VOICE_RECOGNITION);
|
||||
} catch (ActivityNotFoundException e)
|
||||
{
|
||||
AlohaHelper.logException(e);
|
||||
}
|
||||
return R.string.search_map;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void startVoiceRecognition(Intent intent, int code)
|
||||
{
|
||||
startActivityForResult(intent, code);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -184,12 +177,6 @@ public class SearchFragment extends BaseMwmFragment
|
|||
.commit();
|
||||
}
|
||||
|
||||
public void showDownloader()
|
||||
{
|
||||
((BaseMwmFragmentActivity)getActivity()).replaceFragment(DownloaderFragment.class, null, null);
|
||||
UiUtils.hide(mResultsFrame, mResultsPlaceholder, mTabFrame);
|
||||
}
|
||||
|
||||
private void updateFrames()
|
||||
{
|
||||
final boolean active = searchActive();
|
||||
|
@ -462,13 +449,7 @@ public class SearchFragment extends BaseMwmFragment
|
|||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
if (requestCode == RC_VOICE_RECOGNITION && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
String result = InputUtils.getBestRecognitionResult(data);
|
||||
if (!TextUtils.isEmpty(result))
|
||||
setQuery(result);
|
||||
}
|
||||
mToolbarController.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package com.mapswithme.maps.widget;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
|
@ -13,14 +16,12 @@ import com.mapswithme.maps.R;
|
|||
import com.mapswithme.util.InputUtils;
|
||||
import com.mapswithme.util.StringUtils;
|
||||
import com.mapswithme.util.UiUtils;
|
||||
import com.mapswithme.util.statistics.AlohaHelper;
|
||||
|
||||
public class SearchToolbarController extends ToolbarController
|
||||
implements View.OnClickListener
|
||||
implements View.OnClickListener
|
||||
{
|
||||
public interface Container
|
||||
{
|
||||
SearchToolbarController getController();
|
||||
}
|
||||
private static final int REQUEST_VOICE_RECOGNITION = 0xCA11;
|
||||
|
||||
protected final View mContainer;
|
||||
protected final EditText mQuery;
|
||||
|
@ -40,6 +41,11 @@ public class SearchToolbarController extends ToolbarController
|
|||
}
|
||||
};
|
||||
|
||||
public interface Container
|
||||
{
|
||||
SearchToolbarController getController();
|
||||
}
|
||||
|
||||
public SearchToolbarController(View root, Activity activity)
|
||||
{
|
||||
super(root, activity);
|
||||
|
@ -96,11 +102,30 @@ public class SearchToolbarController extends ToolbarController
|
|||
clear();
|
||||
}
|
||||
|
||||
protected void onVoiceInputClick() {}
|
||||
protected void startVoiceRecognition(Intent intent, int code)
|
||||
{
|
||||
throw new RuntimeException("To be used startVoiceRecognition() must be implemented by descendant class");
|
||||
}
|
||||
|
||||
private void onVoiceInputClick()
|
||||
{
|
||||
try
|
||||
{
|
||||
startVoiceRecognition(InputUtils.createIntentForVoiceRecognition(mActivity.getString(getVoiceInputPrompt())), REQUEST_VOICE_RECOGNITION);
|
||||
} catch (ActivityNotFoundException e)
|
||||
{
|
||||
AlohaHelper.logException(e);
|
||||
}
|
||||
}
|
||||
|
||||
protected @StringRes int getVoiceInputPrompt()
|
||||
{
|
||||
return R.string.search;
|
||||
}
|
||||
|
||||
public String getQuery()
|
||||
{
|
||||
return mQuery.getText().toString();
|
||||
return (UiUtils.isVisible(mContainer) ? mQuery.getText().toString() : "");
|
||||
}
|
||||
|
||||
public void setQuery(CharSequence query)
|
||||
|
@ -155,4 +180,14 @@ public class SearchToolbarController extends ToolbarController
|
|||
{
|
||||
UiUtils.showIf(show, mContainer);
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data)
|
||||
{
|
||||
if (requestCode == REQUEST_VOICE_RECOGNITION && resultCode == Activity.RESULT_OK)
|
||||
{
|
||||
String result = InputUtils.getBestRecognitionResult(data);
|
||||
if (!TextUtils.isEmpty(result))
|
||||
setQuery(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue