Skip to content

Commit

Permalink
Добавил возможность "смахнуть" сообщение об ошибке загрузки данных из…
Browse files Browse the repository at this point in the history
… Сети.
  • Loading branch information
MayMih committed Feb 27, 2023
1 parent be71ba2 commit 4be219e
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 56 deletions.
6 changes: 1 addition & 5 deletions app/src/main/java/org/mmu/tinkoffkinolab/CardActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public class CardActivity extends AppCompatActivity
private WebDataDownloadTask downloadTask;
private TextView txtHeader;
private TextView txtContent;
private View androidContentView;
private View progBar;
private boolean _isHorizontal;

Expand Down Expand Up @@ -174,7 +173,6 @@ public void onFragmentViewCreated(@NonNull FragmentManager fm, @NonNull Fragment
imgPoster = v.findViewById(R.id.poster_image_view);
txtHeader = v.findViewById(R.id.card_title);
txtContent = v.findViewById(R.id.card_content);
androidContentView = v.findViewById(android.R.id.content);
super.onFragmentViewCreated(fm, f, v, savedInstanceState);
getFilmDataAsync();
}
Expand All @@ -189,12 +187,10 @@ public void onConfigurationChanged(@NonNull Configuration newConfig)
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE)
{
_isHorizontal = true;
//Toast.makeText(this, "landscape", Toast.LENGTH_SHORT).show();
}
else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT)
{
_isHorizontal = false;
//Toast.makeText(this, "portrait", Toast.LENGTH_SHORT).show();
}
}

Expand Down Expand Up @@ -270,7 +266,7 @@ public void onError(Exception e)
*/
private void showSnackBar(String message)
{
var popup = Snackbar.make(androidContentView, message, Snackbar.LENGTH_INDEFINITE);
var popup = Snackbar.make(this.imgPoster, message, Snackbar.LENGTH_INDEFINITE);
popup.setAction(R.string.repeat_button_caption, view -> {
getFilmDataAsync();
popup.dismiss();
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/java/org/mmu/tinkoffkinolab/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentContainerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import android.annotation.SuppressLint;
Expand All @@ -26,7 +25,6 @@
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.EditorInfo;
import android.widget.ImageView;
import android.widget.LinearLayout;
Expand Down Expand Up @@ -213,7 +211,7 @@ private int downloadPopularFilmList(int pageNumber)
*/
private AsyncTask<Integer, Void, Integer> downloadTask;
private TextInputEditText txtQuery;
private View androidContentView;
private View coordinatorView;
private LinearLayout cardsContainer;
private LayoutInflater layoutInflater;
private boolean isFiltered;
Expand Down Expand Up @@ -344,7 +342,7 @@ protected void onCreate(Bundle savedInstanceState)
this.isRus = Locale.getDefault().getLanguage().equalsIgnoreCase("ru");

this.layoutInflater = getLayoutInflater();
this.androidContentView = findViewById(android.R.id.content);
this.coordinatorView = findViewById(R.id.root_container);
this.progBar = findViewById(R.id.progress_bar);
this.progBar.setVisibility(View.GONE);
this.txtQuery = findViewById(R.id.txt_input);
Expand Down Expand Up @@ -910,7 +908,7 @@ private boolean addToOrRemoveFromFavourites(String id, Map<String, String> cardD
*/
private Snackbar showErrorSnackBar(String message)
{
var popup = Snackbar.make(this.androidContentView, message, Snackbar.LENGTH_INDEFINITE);
var popup = Snackbar.make(coordinatorView, message, Snackbar.LENGTH_INDEFINITE);
popup.setAction(R.string.repeat_button_caption, view -> {
var text = Objects.requireNonNull(txtQuery.getText()).toString().replace("null", "");
this.startTopFilmsDownloadTask(_nextPageNumber);
Expand Down
1 change: 0 additions & 1 deletion app/src/main/res/layout/activity_card.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout 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"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:id="@+id/root_container"
>

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down
95 changes: 50 additions & 45 deletions app/src/main/res/layout/fragment_card.xml
Original file line number Diff line number Diff line change
@@ -1,64 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
<androidx.coordinatorlayout.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbarThumbVertical="@color/neo_light"
android:scrollbarStyle="outsideOverlay"
android:fadeScrollbars="true"
android:layout_width="wrap_content"
android:layout_height="match_parent"
>

<LinearLayout
<ScrollView
android:id="@+id/fragment_scroll"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:scrollbarThumbVertical="@color/neo_light"
android:scrollbarStyle="outsideOverlay"
android:fadeScrollbars="true"
>

<!-- Постер будет растягиваться по максимуму, а текст займёт сколько надо -->
<ImageView
android:id="@+id/poster_image_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="10dp"
android:scaleType="centerCrop"
android:contentDescription="@string/filmposter_image_alt_text"
tools:srcCompat="@tools:sample/backgrounds/scenic" />

<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/card_title"

<!-- Постер будет растягиваться по максимуму, а текст займёт сколько надо -->
<ImageView
android:id="@+id/poster_image_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_marginBottom="10dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
tools:text="CARD_TITLE_PLACEHOLDER-CARD_TITLE_PLACEHOLDER" />
android:scaleType="centerCrop"
android:contentDescription="@string/filmposter_image_alt_text"
tools:srcCompat="@tools:sample/backgrounds/scenic" />

<TextView
android:id="@+id/card_content"
<LinearLayout
android:id="@+id/text_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="10dp"
android:textSize="16sp"
android:textStyle="bold"
tools:text="CARD_CONTENT_PLACEHOLDER" />
android:orientation="vertical"
>
<TextView
android:id="@+id/card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="10dp"
android:ellipsize="end"
android:maxLines="2"
android:textColor="?colorPrimary"
android:textSize="24sp"
android:textStyle="bold"
tools:text="CARD_TITLE_PLACEHOLDER-CARD_TITLE_PLACEHOLDER" />

<TextView
android:id="@+id/card_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="15dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="15dp"
android:layout_marginBottom="10dp"
android:textSize="16sp"
android:textStyle="bold"
tools:text="CARD_CONTENT_PLACEHOLDER" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</ScrollView>
</ScrollView>
</androidx.coordinatorlayout.widget.CoordinatorLayout>

0 comments on commit 4be219e

Please sign in to comment.