Added search.

This commit is contained in:
ChronosX88 2019-01-15 22:08:09 +04:00
parent c6b4cafb05
commit 4fb99782d4
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
24 changed files with 620 additions and 22 deletions

Binary file not shown.

View File

@ -3,6 +3,9 @@
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<compositeConfiguration>
<compositeBuild compositeDefinitionSource="SCRIPT" />
</compositeConfiguration>
<option name="distributionType" value="DEFAULT_WRAPPED" />
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RenderSettings">
<option name="showDecorations" value="true" />
</component>
</project>

View File

@ -23,7 +23,22 @@
</activity>
<activity android:name=".view.SettingsActivity" />
<activity android:name=".view.AboutActivity" />
<activity android:name=".view.DetailActivity"></activity>
<activity android:name=".view.DetailActivity" />
<activity
android:name=".view.SearchableActivity"
android:label="Поиск"
android:parentActivityName="ru.volgorobot.vrcatalog.view.MainActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="ru.volgorobot.vrcatalog.view.MainActivity" />
<!-- meta tag and intent filter go into results activity -->
<meta-data android:name="android.app.searchable"
android:resource="@xml/searchable" />
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>
</activity>
</application>
</manifest>

View File

@ -43,5 +43,18 @@ public interface MainContract {
ArrayList<DetailModel> fetchDetailByID(int detailID) throws NetworkErrorException, NullPointerException;
void reinitializeApi() throws IllegalStateException;
boolean getApiState();
ArrayList<ThirdLevelModel> fetchDetailsByName(String name) throws NetworkErrorException, NullPointerException;
ArrayList<FirstLevelModel> fetchCategoryByID(int id) throws NetworkErrorException, NullPointerException;
ArrayList<SecondLevelModel> fetchSubCategoryByID(int id) throws NetworkErrorException, NullPointerException;
}
interface SearchablePresenter {
void fetchDetailsTreeByName(String name);
}
interface SearchableActivityView {
void setTreeViewChildren(ArrayList<TreeNode> children);
void onFailureAnswer(int errorCode);
void swipeLayoutSetRefreshing(boolean state);
}
}

View File

@ -0,0 +1,219 @@
package ru.volgorobot.vrcatalog;
import android.content.Context;
import android.os.AsyncTask;
import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import me.texy.treeview.TreeNode;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.FirstLevelModel;
import ru.volgorobot.vrcatalog.model.SecondLevelModel;
import ru.volgorobot.vrcatalog.model.ThirdLevelModel;
public class SearchablePresenter implements MainContract.SearchablePresenter {
private MainContract.SearchableActivityView mView;
private MainContract.MainModel coreModel;
public SearchablePresenter(MainContract.SearchableActivityView mView, Context context) {
this.mView = mView;
this.coreModel = new CoreModel(context);
}
@Override
public void fetchDetailsTreeByName(String name) {
ArrayList<FirstLevelModel> categories = new ArrayList<>();
ArrayList<SecondLevelModel> subcategories = new ArrayList<>();
ArrayList<ThirdLevelModel> details = new ArrayList<>();
try {
FetchDetailsByNameTask fetchDetailsByNameTask = new FetchDetailsByNameTask();
FetchCategoryByIDTask fetchCategoryByIDTask = new FetchCategoryByIDTask();
FetchSubCategoryByIDTask fetchSubCategoryByIDTask = new FetchSubCategoryByIDTask();
details.addAll(new FetchDetailsByNameTask().execute(name).get().getData());
for (int i = 0; i < details.size(); i++) {
subcategories.add(new FetchSubCategoryByIDTask().execute(details.get(i).getDetailSubTypeId()).get().getData());
}
for (int i = 0; i < subcategories.size(); i++) {
categories.add(new FetchCategoryByIDTask().execute(subcategories.get(i).getDetailTypeId()).get().getData());
}
} catch (ExecutionException e) {
//
} catch (InterruptedException e) {
//
}
new AsyncTask<Void, Void, ArrayList<TreeNode>>() {
@Override
protected ArrayList<TreeNode> doInBackground(Void... voids) {
ArrayList<TreeNode> treeNodes = new ArrayList<>();
for (int i = 0; i < categories.size(); i++) {
treeNodes.add(new TreeNode(categories.get(i)));
ArrayList<SecondLevelModel> secondLevelModels = getSecondModelsByCategoryID(subcategories, categories.get(i).getID());
for (int j = 0; j < secondLevelModels.size(); j++) {
treeNodes.get(i).addChild(new TreeNode(secondLevelModels.get(j)));
}
ArrayList<TreeNode> subnodes = (ArrayList<TreeNode>) treeNodes.get(i).getChildren();
for (int j = 0; j < subnodes.size(); j++) {
ArrayList<ThirdLevelModel> thirdLevelModels = getDetailsByCategoryID(details, ((SecondLevelModel) subnodes.get(j).getValue()).getID());
for (int k = 0; k < thirdLevelModels.size(); k++) {
subnodes.get(j).addChild(new TreeNode(thirdLevelModels.get(k)));
}
}
}
return treeNodes;
}
@Override
protected void onPostExecute(ArrayList<TreeNode> treeNodes) {
super.onPostExecute(treeNodes);
mView.setTreeViewChildren(treeNodes);
mView.swipeLayoutSetRefreshing(false);
}
}.execute();
}
private ArrayList<SecondLevelModel> getSecondModelsByCategoryID(ArrayList<SecondLevelModel> secondLevelModels, int id) {
ArrayList<SecondLevelModel> secondLevelModelsByCategoryID = new ArrayList<>();
for (int i = 0; i < secondLevelModels.size(); i++) {
if(secondLevelModels.get(i).getDetailTypeId() == id)
secondLevelModelsByCategoryID.add(secondLevelModels.get(i));
}
return secondLevelModelsByCategoryID;
}
private ArrayList<ThirdLevelModel> getDetailsByCategoryID(ArrayList<ThirdLevelModel> thirdLevelModels, int id) {
ArrayList<ThirdLevelModel> thirdLevelModelsBySubcategoryID = new ArrayList<>();
for (int i = 0; i < thirdLevelModels.size(); i++) {
if(thirdLevelModels.get(i).getDetailSubTypeId() == id)
thirdLevelModelsBySubcategoryID.add(thirdLevelModels.get(i));
}
return thirdLevelModelsBySubcategoryID;
}
class FetchDetailsByNameTask extends AsyncTask<String, Void, ResultWithErrorCode<ArrayList<ThirdLevelModel>>> {
@Override
protected void onPreExecute() {
super.onPreExecute();
mView.swipeLayoutSetRefreshing(true);
}
@Override
protected ResultWithErrorCode<ArrayList<ThirdLevelModel>> doInBackground(String... strings) {
ArrayList<ThirdLevelModel> details = new ArrayList<>();
try {
details.addAll(coreModel.fetchDetailsByName(strings[0]));
} catch (NetworkErrorException networkErrorException) {
return new ResultWithErrorCode<>(details, networkErrorException.getErrorCode());
} catch (NullPointerException nullPointerException) {
return new ResultWithErrorCode<>(details, 3);
}
return new ResultWithErrorCode<>(details, 0);
}
@Override
protected void onPostExecute(ResultWithErrorCode<ArrayList<ThirdLevelModel>> result) {
super.onPostExecute(result);
switch (result.getErrorCode()) {
case 0: {
//
break;
}
case 1: {
mView.onFailureAnswer(1);
break;
}
case 2: {
mView.onFailureAnswer(2);
break;
}
case 3: {
mView.onFailureAnswer(3);
break;
}
}
}
}
class FetchCategoryByIDTask extends AsyncTask<Integer, Void, ResultWithErrorCode<FirstLevelModel>> {
@Override
protected ResultWithErrorCode<FirstLevelModel> doInBackground(Integer... integers) {
FirstLevelModel firstLevelModel;
try {
firstLevelModel = coreModel.fetchCategoryByID(integers[0]).get(0);
} catch (NetworkErrorException networkErrorException) {
return new ResultWithErrorCode<>(null, networkErrorException.getErrorCode());
} catch (NullPointerException nullPointerException) {
return new ResultWithErrorCode<>(null, 3);
}
return new ResultWithErrorCode<>(firstLevelModel, 0);
}
@Override
protected void onPostExecute(ResultWithErrorCode<FirstLevelModel> result) {
super.onPostExecute(result);
switch (result.getErrorCode()) {
case 0: {
// Nothing to do.
break;
}
case 1: {
mView.onFailureAnswer(1);
break;
}
case 2: {
mView.onFailureAnswer(2);
break;
}
case 3: {
mView.onFailureAnswer(3);
break;
}
}
}
}
class FetchSubCategoryByIDTask extends AsyncTask<Integer, Void, ResultWithErrorCode<SecondLevelModel>> {
@Override
protected ResultWithErrorCode<SecondLevelModel> doInBackground(Integer... integers) {
SecondLevelModel secondLevelModel;
try {
secondLevelModel = coreModel.fetchSubCategoryByID(integers[0]).get(0);
} catch (NetworkErrorException networkErrorException) {
return new ResultWithErrorCode<>(null, networkErrorException.getErrorCode());
} catch (NullPointerException nullPointerException) {
return new ResultWithErrorCode<>(null, 3);
}
return new ResultWithErrorCode<>(secondLevelModel, 0);
}
@Override
protected void onPostExecute(ResultWithErrorCode<SecondLevelModel> result) {
super.onPostExecute(result);
switch (result.getErrorCode()) {
case 0: {
// Nothing to do.
break;
}
case 1: {
mView.onFailureAnswer(1);
break;
}
case 2: {
mView.onFailureAnswer(2);
break;
}
case 3: {
mView.onFailureAnswer(3);
break;
}
}
}
}
}

View File

@ -9,6 +9,7 @@ import java.util.ArrayList;
import me.texy.treeview.TreeNode;
import ru.volgorobot.vrcatalog.additional.NetworkErrorException;
import ru.volgorobot.vrcatalog.additional.ResultWithErrorCode;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.DetailModel;
import ru.volgorobot.vrcatalog.model.FirstLevelModel;
import ru.volgorobot.vrcatalog.model.SecondLevelModel;
@ -21,15 +22,9 @@ public class ViewBinderPresenter implements MainContract.ViewBinderPresenter {
private MainContract.ViewBinder viewBinder;
private Context context;
public ViewBinderPresenter(MainContract.MainActivityView mView, MainContract.MainModel coreModel, MainContract.ViewBinder viewBinder) {
public ViewBinderPresenter(MainContract.MainActivityView mView, MainContract.ViewBinder viewBinder, Context context) {
this.mView = mView;
this.coreModel = coreModel;
this.viewBinder = viewBinder;
}
public ViewBinderPresenter(MainContract.MainActivityView mView, MainContract.MainModel coreModel, MainContract.ViewBinder viewBinder, Context context) {
this.mView = mView;
this.coreModel = coreModel;
this.coreModel = new CoreModel(context);
this.viewBinder = viewBinder;
this.context = context;
}

View File

@ -26,11 +26,11 @@ public class NodeViewFactory extends BaseNodeViewFactory {
public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
switch (level) {
case 0:
return new FirstLevelNodeViewBinder(view, context, mView, coreModel);
return new FirstLevelNodeViewBinder(view, mView, context);
case 1:
return new SecondLevelNodeViewBinder(view, context, mView, coreModel);
return new SecondLevelNodeViewBinder(view, mView, context);
case 2:
return new ThirdLevelNodeViewBinder(view, context, mView, coreModel);
return new ThirdLevelNodeViewBinder(view, context, mView);
default:
return null;
}

View File

@ -0,0 +1,35 @@
package ru.volgorobot.vrcatalog.additional;
import android.content.Context;
import android.view.View;
import me.texy.treeview.base.BaseNodeViewBinder;
import me.texy.treeview.base.BaseNodeViewFactory;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.nodeViewBinders.ThirdLevelNodeViewBinder;
import ru.volgorobot.vrcatalog.searchNodeViewBinders.SecondLevelNodeViewBinder;
import ru.volgorobot.vrcatalog.searchNodeViewBinders.FirstLevelNodeViewBinder;
public class SearchableNodeViewFactory extends BaseNodeViewFactory {
private Context context;
private MainContract.MainActivityView mView;
public SearchableNodeViewFactory(Context context, MainContract.MainActivityView mView) {
this.context = context;
this.mView = mView;
}
@Override
public BaseNodeViewBinder getNodeViewBinder(View view, int level) {
switch (level) {
case 0:
return new FirstLevelNodeViewBinder(view);
case 1:
return new SecondLevelNodeViewBinder(view);
case 2:
return new ThirdLevelNodeViewBinder(view, context, mView);
default:
return null;
}
}
}

View File

@ -23,4 +23,13 @@ public interface VRApi {
@GET("/API/Api.php?action=getDetailByID")
Call<List<DetailModel>> getDetailByID(@Query("detailID") int detailID);
@GET("/API/Api.php?action=getCategoryByID")
Call<List<FirstLevelModel>> getCategoryByID(@Query("id") int id);
@GET("/API/Api.php?action=getSubCategoryByID")
Call<List<SecondLevelModel>> getSubCategoryByID(@Query("id") int id);
@GET("/API/Api.php?action=getDetailsByName")
Call<List<ThirdLevelModel>> getDetailsByName(@Query("name") String name);
}

View File

@ -125,4 +125,61 @@ public class CoreModel implements MainContract.MainModel {
return false;
}
}
@Override
public ArrayList<ThirdLevelModel> fetchDetailsByName(String name) throws NetworkErrorException, NullPointerException {
if(vrApi == null) {
throw new NullPointerException();
}
final ArrayList<ThirdLevelModel> thirdLevelModels = new ArrayList<>();
try {
Response<List<ThirdLevelModel>> response = vrApi.getDetailsByName(name).execute();
if(response.isSuccessful()) {
thirdLevelModels.addAll(response.body());
} else {
throw new NetworkErrorException(2);
}
} catch (IOException e) {
throw new NetworkErrorException(1);
}
return thirdLevelModels;
}
@Override
public ArrayList<FirstLevelModel> fetchCategoryByID(int id) throws NetworkErrorException, NullPointerException {
if(vrApi == null) {
throw new NullPointerException();
}
final ArrayList<FirstLevelModel> firstLevelModels = new ArrayList<>();
try {
Response<List<FirstLevelModel>> response = vrApi.getCategoryByID(id).execute();
if(response.isSuccessful()) {
firstLevelModels.addAll(response.body());
} else {
throw new NetworkErrorException(2);
}
} catch (IOException e) {
throw new NetworkErrorException(1);
}
return firstLevelModels;
}
@Override
public ArrayList<SecondLevelModel> fetchSubCategoryByID(int id) throws NetworkErrorException, NullPointerException {
if(vrApi == null) {
throw new NullPointerException();
}
final ArrayList<SecondLevelModel> secondLevelModels = new ArrayList<>();
try {
Response<List<SecondLevelModel>> response = vrApi.getSubCategoryByID(id).execute();
if(response.isSuccessful()) {
secondLevelModels.addAll(response.body());
} else {
throw new NetworkErrorException(2);
}
} catch (IOException e) {
throw new NetworkErrorException(1);
}
return secondLevelModels;
}
}

View File

@ -17,11 +17,11 @@ public class FirstLevelNodeViewBinder extends BaseNodeViewBinder implements Main
ImageView imageView;
ViewBinderPresenter viewBinderPresenter;
public FirstLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView, MainContract.MainModel coreModel) {
public FirstLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView, Context context) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
viewBinderPresenter = new ViewBinderPresenter(mView, coreModel, this);
viewBinderPresenter = new ViewBinderPresenter(mView, this, context);
}
@Override

View File

@ -10,7 +10,6 @@ import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R;
import ru.volgorobot.vrcatalog.ViewBinderPresenter;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.SecondLevelModel;
public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder {
@ -19,11 +18,11 @@ public class SecondLevelNodeViewBinder extends BaseNodeViewBinder implements Mai
MainContract.ViewBinderPresenter viewBinderPresenter;
public SecondLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView, CoreModel coreModel) {
public SecondLevelNodeViewBinder(View itemView, MainContract.MainActivityView mView, Context context) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
viewBinderPresenter = new ViewBinderPresenter(mView, coreModel, this);
viewBinderPresenter = new ViewBinderPresenter(mView, this, context);
}
@Override

View File

@ -9,16 +9,15 @@ import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R;
import ru.volgorobot.vrcatalog.ViewBinderPresenter;
import ru.volgorobot.vrcatalog.model.CoreModel;
import ru.volgorobot.vrcatalog.model.ThirdLevelModel;
public class ThirdLevelNodeViewBinder extends BaseNodeViewBinder implements MainContract.ViewBinder {
TextView textView;
MainContract.ViewBinderPresenter viewBinderPresenter;
public ThirdLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView, CoreModel coreModel) {
public ThirdLevelNodeViewBinder(View itemView, Context context, MainContract.MainActivityView mView) {
super(itemView);
viewBinderPresenter = new ViewBinderPresenter(mView, coreModel, this, context);
viewBinderPresenter = new ViewBinderPresenter(mView, this, context);
textView = itemView.findViewById(R.id.node_name_view);
}

View File

@ -0,0 +1,39 @@
package ru.volgorobot.vrcatalog.searchNodeViewBinders;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.R;
public class FirstLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView;
ImageView imageView;
public FirstLevelNodeViewBinder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
}
@Override
public int getLayoutId() {
return R.layout.first_level_item;
}
@Override
public void bindView(TreeNode treeNode) {
textView.setText(treeNode.getValue().toString());
}
@Override
public void onNodeToggled(TreeNode treeNode, boolean expand) {
if(expand) {
imageView.animate().rotation(90).setDuration(200).start();
} else {
imageView.animate().rotation(0).setDuration(200).start();
}
}
}

View File

@ -0,0 +1,39 @@
package ru.volgorobot.vrcatalog.searchNodeViewBinders;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import me.texy.treeview.TreeNode;
import me.texy.treeview.base.BaseNodeViewBinder;
import ru.volgorobot.vrcatalog.R;
public class SecondLevelNodeViewBinder extends BaseNodeViewBinder {
TextView textView;
ImageView imageView;
public SecondLevelNodeViewBinder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.node_name_view);
imageView = (ImageView) itemView.findViewById(R.id.arrow_img);
}
@Override
public int getLayoutId() {
return R.layout.second_level_item;
}
@Override
public void bindView(TreeNode treeNode) {
textView.setText(treeNode.getValue().toString());
}
@Override
public void onNodeToggled(TreeNode treeNode, boolean expand) {
if(expand) {
imageView.animate().rotation(90).setDuration(200).start();
} else {
imageView.animate().rotation(0).setDuration(200).start();
}
}
}

View File

@ -1,16 +1,23 @@
package ru.volgorobot.vrcatalog.view;
import android.app.SearchManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.Toast;
@ -155,6 +162,19 @@ public class MainActivity extends AppCompatActivity
public void startActivityByIntent(Intent intent) {
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
SearchView search = (SearchView) MenuItemCompat.getActionView(menu.findItem(R.id.action_search));
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
search.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchableActivity.class)));
search.setQueryHint("Имя детали");
return true;
}
}

View File

@ -0,0 +1,117 @@
package ru.volgorobot.vrcatalog.view;
import android.app.SearchManager;
import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator;
import android.util.Log;
import android.view.MenuItem;
import android.view.ViewGroup;
import android.widget.Toast;
import java.util.ArrayList;
import me.texy.treeview.TreeNode;
import me.texy.treeview.TreeView;
import ru.volgorobot.vrcatalog.MainContract;
import ru.volgorobot.vrcatalog.R;
import ru.volgorobot.vrcatalog.SearchablePresenter;
import ru.volgorobot.vrcatalog.additional.NodeViewFactory;
import ru.volgorobot.vrcatalog.additional.SearchableNodeViewFactory;
import ru.volgorobot.vrcatalog.model.FirstLevelModel;
public class SearchableActivity extends AppCompatActivity implements MainContract.SearchableActivityView, MainContract.MainActivityView, SwipeRefreshLayout.OnRefreshListener {
private SearchablePresenter searchablePresenter;
private SwipeRefreshLayout mSwipeRefreshLayout;
private String detailName;
private TreeView treeView;
private TreeNode rootNode = TreeNode.root();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_searchable);
searchablePresenter = new SearchablePresenter(this, SearchableActivity.this);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mSwipeRefreshLayout = findViewById(R.id.searchableSwipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(SearchableActivity.this);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
treeView = new TreeView(rootNode, SearchableActivity.this, new SearchableNodeViewFactory(SearchableActivity.this, this));
treeView.setItemAnimator(new DefaultItemAnimator());
((ViewGroup) findViewById(R.id.searchableTreeViewContainer)).addView(treeView.getView());
Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
detailName = intent.getStringExtra(SearchManager.QUERY);
searchablePresenter.fetchDetailsTreeByName(detailName);
}
}
@Override
public void setTreeViewChildren(ArrayList<TreeNode> children) {
rootNode.setChildren(children);
treeView.refreshTreeView();
}
public void onFailureAnswer(int errorCode) {
switch (errorCode) {
case 1: {
Toast.makeText(SearchableActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show();
Log.e("VRCatalog", "Network Error! Re-check your connection credentials or network settings! Technical info: null");
mSwipeRefreshLayout.setRefreshing(false);
break;
}
case 2: {
Toast.makeText(SearchableActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
Log.e("VRCatalog", "Answer of server is wrong! Re-check your connection credentials! Technical info: null");
mSwipeRefreshLayout.setRefreshing(false);
break;
}
case 3: {
Toast.makeText(SearchableActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show();
mSwipeRefreshLayout.setRefreshing(false);
break;
}
}
}
@Override
public void onRefresh() {
searchablePresenter.fetchDetailsTreeByName(detailName);
}
@Override
public void swipeLayoutSetRefreshing(boolean state) {
mSwipeRefreshLayout.setRefreshing(state);
}
@Override
public void refreshTree() {
treeView.refreshTreeView();
}
@Override
public void startActivityByIntent(Intent intent) {
startActivity(intent);
}
@Override
public void buildFirstLevelTree(ArrayList<FirstLevelModel> firstLevelModels) {
// This is for compatibility. Nothing to implement.
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case android.R.id.home:
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
}

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".view.MainActivity"
tools:showIn="@layout/app_bar_main"
android:orientation="horizontal"
android:id="@+id/searchableSwipeRefreshLayout">
<android.support.v4.widget.NestedScrollView
android:id="@+id/searchableTreeViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true">
</android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>

View File

@ -1,4 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_search"
android:icon="@android:drawable/ic_menu_search"
app:showAsAction="always|collapseActionView"
app:actionViewClass="android.support.v7.widget.SearchView"
android:title="Поиск"/>
</menu>

View File

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:label="@string/app_name"
android:hint="Поиск деталей по имени" >
</searchable>

View File

@ -8,7 +8,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong

View File

@ -1,5 +1,6 @@
#Tue Jan 15 18:33:56 MSK 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip