Added empty screen when no search results.

This commit is contained in:
ChronosX88 2019-02-25 18:46:43 +04:00
parent f29121ac7c
commit 72f37f4549
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
5 changed files with 59 additions and 3 deletions

View File

@ -147,7 +147,7 @@
<PersistentState> <PersistentState>
<option name="values"> <option name="values">
<map> <map>
<entry key="url" value="jar:file:/home/chronosx/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%8B/bin/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/action/ic_favorite_black_24dp.xml" /> <entry key="url" value="jar:file:/home/chronosx/%D0%94%D0%BE%D0%BA%D1%83%D0%BC%D0%B5%D0%BD%D1%82%D1%8B/bin/Android%20Studio/plugins/android/lib/android.jar!/images/material_design_icons/content/ic_clear_black_24dp.xml" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
@ -157,7 +157,8 @@
</option> </option>
<option name="values"> <option name="values">
<map> <map>
<entry key="outputName" value="ic_favorite_black_24dp" /> <entry key="color" value="d3d3d3" />
<entry key="outputName" value="ic_clear_gray_24dp" />
<entry key="sourceFile" value="$USER_HOME$" /> <entry key="sourceFile" value="$USER_HOME$" />
</map> </map>
</option> </option>

View File

@ -35,6 +35,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
private ImageView mConnectionErrorImageView; private ImageView mConnectionErrorImageView;
private NestedScrollView mTreeViewContainer; private NestedScrollView mTreeViewContainer;
private TextView mErrorTextView; private TextView mErrorTextView;
private ImageView mEmptySearchImageView;
private TextView mEmptySearchTextView;
private boolean isInErrorState = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -53,9 +56,12 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mTreeViewContainer = findViewById(R.id.searchableTreeViewContainer); mTreeViewContainer = findViewById(R.id.searchableTreeViewContainer);
mErrorTextView = findViewById(R.id.searchableErrorTextView); 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 = new TreeView(rootNode, SearchableActivity.this, new SearchableNodeViewFactory(SearchableActivity.this, this));
treeView.setItemAnimator(new DefaultItemAnimator()); treeView.setItemAnimator(new DefaultItemAnimator());
((ViewGroup) findViewById(R.id.searchableTreeViewContainer)).addView(treeView.getView()); mTreeViewContainer.addView(treeView.getView());
Intent intent = getIntent(); Intent intent = getIntent();
if (Intent.ACTION_SEARCH.equals(intent.getAction())) { if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
detailName = intent.getStringExtra(SearchManager.QUERY); detailName = intent.getStringExtra(SearchManager.QUERY);
@ -72,6 +78,15 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
rootNode.setChildren(children); rootNode.setChildren(children);
treeView.expandAll(); treeView.expandAll();
treeView.refreshTreeView(); 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) { public void onFailureAnswer(int errorCode) {
@ -84,6 +99,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mTreeViewContainer.setVisibility(View.GONE); mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE); mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE);
isInErrorState = true;
break; break;
} }
case 2: { case 2: {
@ -94,6 +110,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mTreeViewContainer.setVisibility(View.GONE); mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE); mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE);
isInErrorState = true;
break; break;
} }
case 3: { case 3: {
@ -103,6 +120,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mTreeViewContainer.setVisibility(View.GONE); mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE); mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE); mErrorTextView.setVisibility(View.VISIBLE);
isInErrorState = true;
break; break;
} }
} }
@ -116,6 +134,7 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
rootNode.setChildren(new ArrayList<TreeNode>()); rootNode.setChildren(new ArrayList<TreeNode>());
treeView.refreshTreeView(); treeView.refreshTreeView();
searchablePresenter.fetchDetailsTreeByName(detailName); searchablePresenter.fetchDetailsTreeByName(detailName);
isInErrorState = false;
} }
@Override @Override

View File

@ -0,0 +1,5 @@
<vector android:height="24dp" android:tint="#D3D3D3"
android:viewportHeight="24.0" android:viewportWidth="24.0"
android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="#FF000000" android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>

View File

@ -49,6 +49,36 @@
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchableConnectionErrorImageView" /> app:layout_constraintTop_toBottomOf="@+id/searchableConnectionErrorImageView" />
<ImageView
android:id="@+id/emptySearchImage"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="52dp"
android:src="@drawable/ic_clear_gray_24dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/emptySearchText"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/emptySearchText"
android:layout_width="0dp"
android:layout_height="77dp"
android:layout_marginStart="9dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="68dp"
android:text="@string/empty_search"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:visibility="invisible"
android:textSize="18sp"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/emptySearchImage" />
</android.support.constraint.ConstraintLayout> </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>

View File

@ -3,4 +3,5 @@
<string name="navigation_drawer_open">Open navigation drawer</string> <string name="navigation_drawer_open">Open navigation drawer</string>
<string name="navigation_drawer_close">Close navigation drawer</string> <string name="navigation_drawer_close">Close navigation drawer</string>
<string name="favorites_empty">Ваш список избранного пуст</string> <string name="favorites_empty">Ваш список избранного пуст</string>
<string name="empty_search">По вашему запросу ничего не найдено.</string>
</resources> </resources>