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>
<option name="values">
<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>
</option>
</PersistentState>
@ -28,8 +28,8 @@
</option>
<option name="values">
<map>
<entry key="color" value="ffffff" />
<entry key="outputName" value="ic_search_white_24dp" />
<entry key="color" value="a9a9a9" />
<entry key="outputName" value="ic_cloud_off_gray_24dp" />
<entry key="sourceFile" value="$USER_HOME$" />
</map>
</option>

View File

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

View File

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

View File

@ -2,13 +2,17 @@ package ru.volgorobot.vrcatalog.view;
import android.app.SearchManager;
import android.content.Intent;
import android.support.v4.widget.NestedScrollView;
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.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
@ -27,6 +31,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
private String detailName;
private TreeView treeView;
private TreeNode rootNode = TreeNode.root();
private ImageView mConnectionErrorImageView;
private NestedScrollView mTreeViewContainer;
private TextView mErrorTextView;
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -41,6 +48,10 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
mSwipeRefreshLayout.setOnRefreshListener(SearchableActivity.this);
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.setItemAnimator(new DefaultItemAnimator());
((ViewGroup) findViewById(R.id.searchableTreeViewContainer)).addView(treeView.getView());
@ -62,20 +73,32 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
public void onFailureAnswer(int errorCode) {
switch (errorCode) {
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");
mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break;
}
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");
mSwipeRefreshLayout.setRefreshing(false);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break;
}
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);
mTreeViewContainer.setVisibility(View.GONE);
mConnectionErrorImageView.setVisibility(View.VISIBLE);
mErrorTextView.setVisibility(View.VISIBLE);
break;
}
}
@ -83,6 +106,9 @@ public class SearchableActivity extends AppCompatActivity implements MainContrac
@Override
public void onRefresh() {
mConnectionErrorImageView.setVisibility(View.INVISIBLE);
mErrorTextView.setVisibility(View.INVISIBLE);
mTreeViewContainer.setVisibility(View.VISIBLE);
searchablePresenter.fetchDetailsTreeByName(detailName);
}

View File

@ -10,6 +10,10 @@
android:orientation="horizontal"
android:id="@+id/searchableSwipeRefreshLayout">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/searchableTreeViewContainer"
android:layout_width="match_parent"
@ -17,5 +21,34 @@
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>

View File

@ -10,12 +10,53 @@
android:orientation="horizontal"
android:id="@+id/swipeRefreshLayout">
<android.support.constraint.ConstraintLayout
android:id="@+id/mainActivityConstraint"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.NestedScrollView
android:id="@+id/treeViewContainer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true">
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>