Made error icon when error occured (network error, etc.)

This commit is contained in:
ChronosX88 2019-01-27 21:47:15 +04:00
parent 6574df3d2f
commit 3b92ca5bd6
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
6 changed files with 145 additions and 18 deletions

View File

@ -18,7 +18,7 @@
<PersistentState> <PersistentState>
<option name="values"> <option name="values">
<map> <map>
<entry key="url" value="jar:file:/home/WORK/android-studio/plugins/android/lib/android.jar!/images/material_design_icons/action/ic_search_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/file/ic_cloud_off_black_24dp.xml" />
</map> </map>
</option> </option>
</PersistentState> </PersistentState>
@ -28,8 +28,8 @@
</option> </option>
<option name="values"> <option name="values">
<map> <map>
<entry key="color" value="ffffff" /> <entry key="color" value="a9a9a9" />
<entry key="outputName" value="ic_search_white_24dp" /> <entry key="outputName" value="ic_cloud_off_gray_24dp" />
<entry key="sourceFile" value="$USER_HOME$" /> <entry key="sourceFile" value="$USER_HOME$" />
</map> </map>
</option> </option>

View File

@ -2,5 +2,6 @@
<project version="4"> <project version="4">
<component name="VcsDirectoryMappings"> <component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" /> <mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component> </component>
</project> </project>

View File

@ -9,6 +9,7 @@ import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.view.MenuItemCompat; import android.support.v4.view.MenuItemCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBarDrawerToggle; import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
@ -16,10 +17,14 @@ import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.SearchView; import android.support.v7.widget.SearchView;
import android.support.v7.widget.Toolbar; import android.support.v7.widget.Toolbar;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
@ -39,6 +44,9 @@ public class MainActivity extends AppCompatActivity
private TreeView treeView; private TreeView treeView;
private TreeNode rootNode = TreeNode.root(); private TreeNode rootNode = TreeNode.root();
private SwipeRefreshLayout mSwipeRefreshLayout; private SwipeRefreshLayout mSwipeRefreshLayout;
private ImageView mConnectionErrorImageView;
private ViewGroup mTreeViewContainer;
private TextView mErrorTextView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -56,7 +64,7 @@ public class MainActivity extends AppCompatActivity
NavigationView navigationView = findViewById(R.id.nav_view); NavigationView navigationView = findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this); navigationView.setNavigationItemSelectedListener(this);
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); mSwipeRefreshLayout = findViewById(R.id.swipeRefreshLayout);
mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this); mSwipeRefreshLayout.setOnRefreshListener(MainActivity.this);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
@ -64,11 +72,14 @@ public class MainActivity extends AppCompatActivity
treeView = new TreeView(rootNode, MainActivity.this, new NodeViewFactory(MainActivity.this, this, this.mPresenter.getCoreModel())); treeView = new TreeView(rootNode, MainActivity.this, new NodeViewFactory(MainActivity.this, this, this.mPresenter.getCoreModel()));
treeView.setItemAnimator(new DefaultItemAnimator()); treeView.setItemAnimator(new DefaultItemAnimator());
((ViewGroup) findViewById(R.id.treeViewContainer)).addView(treeView.getView()); mTreeViewContainer = findViewById(R.id.treeViewContainer);
mTreeViewContainer.addView(treeView.getView());
mSwipeRefreshLayout.setRefreshing(true); mSwipeRefreshLayout.setRefreshing(true);
mPresenter.getFirstLevel(); mPresenter.getFirstLevel();
} }
@Override @Override
public void onBackPressed() { public void onBackPressed() {
DrawerLayout drawer = findViewById(R.id.drawer_layout); DrawerLayout drawer = findViewById(R.id.drawer_layout);
@ -111,27 +122,42 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onRefresh() { public void onRefresh() {
mConnectionErrorImageView.setVisibility(View.INVISIBLE);
mErrorTextView.setVisibility(View.INVISIBLE);
mTreeViewContainer.setVisibility(View.VISIBLE);
mPresenter.getFirstLevel(); mPresenter.getFirstLevel();
} }
public void onFailureAnswer(int errorCode) { public void onFailureAnswer(int errorCode) {
switch (errorCode) { switch (errorCode) {
case 1: { case 1: {
mErrorTextView.setText("Ошибка сети. Проверьте подключение к сети или данные подключения к API!");
Toast.makeText(MainActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show(); Toast.makeText(MainActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show();
Log.e("MainActivity", "Network Error! Re-check your connection credentials or network settings!"); Log.e("MainActivity", "Network Error! Re-check your connection credentials or network settings!");
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
case 2: { case 2: {
mErrorTextView.setText("Ответ от сервера неверен! Перепроверьте данные подключения!");
Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); Toast.makeText(MainActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
Log.e("MainActivity", "Answer of server is wrong! Re-check your connection credentials!"); Log.e("MainActivity", "Answer of server is wrong! Re-check your connection credentials!");
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
case 3: { case 3: {
mErrorTextView.setText("Вы ввели неверный URL. Пример: http://example.ru");
Toast.makeText(this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show(); Toast.makeText(this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show();
Log.e("MainActivity", "Invalid-formatted URL. Please, check URL (change his if it need) and try again."); Log.e("MainActivity", "Invalid-formatted URL. Please, check URL (change his if it need) and try again.");
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
} }

View File

@ -2,13 +2,17 @@ package ru.volgorobot.vrcatalog.view;
import android.app.SearchManager; import android.app.SearchManager;
import android.content.Intent; import android.content.Intent;
import android.support.v4.widget.NestedScrollView;
import android.support.v4.widget.SwipeRefreshLayout; import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity; import android.support.v7.app.AppCompatActivity;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.widget.DefaultItemAnimator; import android.support.v7.widget.DefaultItemAnimator;
import android.util.Log; import android.util.Log;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,6 +31,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
private String detailName; private String detailName;
private TreeView treeView; private TreeView treeView;
private TreeNode rootNode = TreeNode.root(); private TreeNode rootNode = TreeNode.root();
private ImageView mConnectionErrorImageView;
private NestedScrollView mTreeViewContainer;
private TextView mErrorTextView;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -41,6 +48,10 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mSwipeRefreshLayout.setOnRefreshListener(SearchableActivity.this); mSwipeRefreshLayout.setOnRefreshListener(SearchableActivity.this);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary); mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary);
mConnectionErrorImageView = findViewById(R.id.searchableConnectionErrorImageView);
mTreeViewContainer = findViewById(R.id.searchableTreeViewContainer);
mErrorTextView = findViewById(R.id.searchableErrorTextView);
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()); ((ViewGroup) findViewById(R.id.searchableTreeViewContainer)).addView(treeView.getView());
@ -62,20 +73,32 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
public void onFailureAnswer(int errorCode) { public void onFailureAnswer(int errorCode) {
switch (errorCode) { switch (errorCode) {
case 1: { case 1: {
Toast.makeText(SearchableActivity.this, "Ошибка сети. Проверьте подключение к сети или данные подключения к API!", Toast.LENGTH_LONG).show(); mErrorTextView.setText("Ошибка сети. Проверьте подключение к сети или данные подключения к API!");
//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"); Log.e("VRCatalog", "Network Error! Re-check your connection credentials or network settings! Technical info: null");
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
case 2: { case 2: {
Toast.makeText(SearchableActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show(); mErrorTextView.setText("Ответ от сервера неверен! Перепроверьте данные подключения!");
//Toast.makeText(SearchableActivity.this, "Ответ от сервера неверен! Перепроверьте данные подключения!", Toast.LENGTH_LONG).show();
Log.e("VRCatalog", "Answer of server is wrong! Re-check your connection credentials! Technical info: null"); Log.e("VRCatalog", "Answer of server is wrong! Re-check your connection credentials! Technical info: null");
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
case 3: { case 3: {
Toast.makeText(SearchableActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show(); mErrorTextView.setText("Вы ввели неверный URL. Пример: http://example.ru");
//Toast.makeText(SearchableActivity.this, "Вы ввели неверный URL. Пример: http://example.ru", Toast.LENGTH_LONG).show();
mSwipeRefreshLayout.setRefreshing(false); mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break; break;
} }
} }
@ -83,6 +106,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
@Override @Override
public void onRefresh() { public void onRefresh() {
mConnectionErrorImageView.setVisibility(View.INVISIBLE);
mErrorTextView.setVisibility(View.INVISIBLE);
mTreeViewContainer.setVisibility(View.VISIBLE);
searchablePresenter.fetchDetailsTreeByName(detailName); searchablePresenter.fetchDetailsTreeByName(detailName);
} }

View File

@ -10,12 +10,45 @@
android:orientation="horizontal" android:orientation="horizontal"
android:id="@+id/searchableSwipeRefreshLayout"> android:id="@+id/searchableSwipeRefreshLayout">
<android.support.v4.widget.NestedScrollView <android.support.constraint.ConstraintLayout
android:id="@+id/searchableTreeViewContainer"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:scrollbarAlwaysDrawVerticalTrack="true">
</android.support.v4.widget.NestedScrollView>
<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>
<ImageView
android:id="@+id/connectionErrorImageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="52dp"
android:src="@drawable/ic_cloud_off_gray_24dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/errorTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/errorTextView"
android:layout_width="0dp"
android:layout_height="77dp"
android:layout_marginStart="9dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="68dp"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/connectionErrorImageView" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>

View File

@ -10,12 +10,53 @@
android:orientation="horizontal" android:orientation="horizontal"
android:id="@+id/swipeRefreshLayout"> android:id="@+id/swipeRefreshLayout">
<android.support.v4.widget.NestedScrollView <android.support.constraint.ConstraintLayout
android:id="@+id/treeViewContainer" android:id="@+id/mainActivityConstraint"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:scrollbarAlwaysDrawVerticalTrack="true">
</android.support.v4.widget.NestedScrollView>
<android.support.v4.widget.NestedScrollView
android:id="@+id/treeViewContainer"
android:layout_width="0dp"
android:layout_height="0dp"
android:scrollbarAlwaysDrawVerticalTrack="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0">
</android.support.v4.widget.NestedScrollView>
<ImageView
android:id="@+id/searchableConnectionErrorImageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="70dp"
android:layout_marginBottom="52dp"
android:src="@drawable/ic_cloud_off_gray_24dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@+id/searchableErrorTextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/searchableErrorTextView"
android:layout_width="0dp"
android:layout_height="77dp"
android:layout_marginStart="9dp"
android:layout_marginEnd="9dp"
android:layout_marginBottom="68dp"
android:text=""
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/searchableConnectionErrorImageView" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.SwipeRefreshLayout> </android.support.v4.widget.SwipeRefreshLayout>