From 72f37f454995915cda4cd8d55cc0ed4c5fb0ec93 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Mon, 25 Feb 2019 18:46:43 +0400 Subject: [PATCH] Added empty screen when no search results. --- .idea/assetWizardSettings.xml | 5 ++-- .../vrcatalog/view/SearchableActivity.java | 21 ++++++++++++- .../main/res/drawable/ic_clear_gray_24dp.xml | 5 ++++ .../main/res/layout/activity_searchable.xml | 30 +++++++++++++++++++ app/src/main/res/values/strings.xml | 1 + 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 app/src/main/res/drawable/ic_clear_gray_24dp.xml diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index 0f9fbd3..91edac6 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -147,7 +147,7 @@ @@ -157,7 +157,8 @@ diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java index f411fcd..814facc 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/SearchableActivity.java @@ -35,6 +35,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac private ImageView mConnectionErrorImageView; private NestedScrollView mTreeViewContainer; private TextView mErrorTextView; + private ImageView mEmptySearchImageView; + private TextView mEmptySearchTextView; + private boolean isInErrorState = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -53,9 +56,12 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac mTreeViewContainer = findViewById(R.id.searchableTreeViewContainer); mErrorTextView = findViewById(R.id.searchableErrorTextView); + mEmptySearchImageView = findViewById(R.id.emptySearchImage); + mEmptySearchTextView = findViewById(R.id.emptySearchText); + treeView = new TreeView(rootNode, SearchableActivity.this, new SearchableNodeViewFactory(SearchableActivity.this, this)); treeView.setItemAnimator(new DefaultItemAnimator()); - ((ViewGroup) findViewById(R.id.searchableTreeViewContainer)).addView(treeView.getView()); + mTreeViewContainer.addView(treeView.getView()); Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { detailName = intent.getStringExtra(SearchManager.QUERY); @@ -72,6 +78,15 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac rootNode.setChildren(children); treeView.expandAll(); treeView.refreshTreeView(); + if(children.size() == 0 && !isInErrorState) { + mEmptySearchImageView.setVisibility(View.VISIBLE); + mEmptySearchTextView.setVisibility(View.VISIBLE); + mTreeViewContainer.setVisibility(View.GONE); + } else { + mEmptySearchImageView.setVisibility(View.INVISIBLE); + mEmptySearchTextView.setVisibility(View.INVISIBLE); + mTreeViewContainer.setVisibility(View.VISIBLE); + } } public void onFailureAnswer(int errorCode) { @@ -84,6 +99,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac mTreeViewContainer.setVisibility(View.GONE); mConnectionErrorImageView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE); + isInErrorState = true; break; } case 2: { @@ -94,6 +110,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac mTreeViewContainer.setVisibility(View.GONE); mConnectionErrorImageView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE); + isInErrorState = true; break; } case 3: { @@ -103,6 +120,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac mTreeViewContainer.setVisibility(View.GONE); mConnectionErrorImageView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE); + isInErrorState = true; break; } } @@ -116,6 +134,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac rootNode.setChildren(new ArrayList()); treeView.refreshTreeView(); searchablePresenter.fetchDetailsTreeByName(detailName); + isInErrorState = false; } @Override diff --git a/app/src/main/res/drawable/ic_clear_gray_24dp.xml b/app/src/main/res/drawable/ic_clear_gray_24dp.xml new file mode 100644 index 0000000..184f32a --- /dev/null +++ b/app/src/main/res/drawable/ic_clear_gray_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/layout/activity_searchable.xml b/app/src/main/res/layout/activity_searchable.xml index 4bdcf45..693b0bc 100644 --- a/app/src/main/res/layout/activity_searchable.xml +++ b/app/src/main/res/layout/activity_searchable.xml @@ -49,6 +49,36 @@ app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toBottomOf="@+id/searchableConnectionErrorImageView" /> + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7b2619f..46dadf7 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -3,4 +3,5 @@ Open navigation drawer Close navigation drawer Ваш список избранного пуст + По вашему запросу ничего не найдено.