From 6d5b0a2b6251ceff2ccc9de60456fee5484f2360 Mon Sep 17 00:00:00 2001 From: ChronosX88 Date: Sun, 24 Feb 2019 15:32:03 +0400 Subject: [PATCH] Added a blank screen when the favorites list is empty, the color of the icons is changed to black on the ActionBar in the ItemActivity, centered blank screen text in MainActivity. --- .../adapters/FavoritesListAdapter.java | 4 ++ .../vrcatalog/view/FavoritesActivity.java | 36 ++++++++++++++-- ....xml => ic_favorite_border_black_24dp.xml} | 2 +- .../drawable/ic_favorite_border_grey_24dp.xml | 5 +++ ...hite_24dp.xml => ic_favorite_red_24dp.xml} | 2 +- .../main/res/layout/activity_favorites.xml | 41 +++++++++++++++++-- app/src/main/res/layout/content_main.xml | 2 + .../main/res/menu/activity_main_drawer.xml | 2 +- app/src/main/res/menu/item_activity_menu.xml | 4 +- app/src/main/res/values-v21/styles.xml | 4 +- app/src/main/res/values/strings.xml | 3 +- app/src/main/res/values/styles.xml | 23 +++++++---- 12 files changed, 104 insertions(+), 24 deletions(-) rename app/src/main/res/drawable/{ic_favorite_border_white_24dp.xml => ic_favorite_border_black_24dp.xml} (91%) create mode 100644 app/src/main/res/drawable/ic_favorite_border_grey_24dp.xml rename app/src/main/res/drawable/{ic_favorite_white_24dp.xml => ic_favorite_red_24dp.xml} (88%) diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java index 49395d5..9216b1d 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/additional/adapters/FavoritesListAdapter.java @@ -20,4 +20,8 @@ public class FavoritesListAdapter extends ArrayAdapter { super.clear(); super.addAll(db.selectAll()); } + + public int getArraySize() { + return db.selectAll().size(); + } } diff --git a/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java b/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java index e0fc419..290b069 100644 --- a/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java +++ b/app/src/main/java/ru/volgorobot/vrcatalog/view/FavoritesActivity.java @@ -1,6 +1,7 @@ package ru.volgorobot.vrcatalog.view; import android.content.Intent; +import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.util.Log; @@ -8,7 +9,9 @@ import android.view.ContextMenu; import android.view.MenuItem; import android.view.View; import android.widget.AdapterView; +import android.widget.ImageView; import android.widget.ListView; +import android.widget.TextView; import android.widget.Toast; import java.util.ArrayList; @@ -22,10 +25,13 @@ import ru.volgorobot.vrcatalog.presenters.FavoritesPresenter; public class FavoritesActivity extends AppCompatActivity implements MainContract.FavoritesActivityView { private FavoritesDBPresenter db; - private ListView listView; private FavoritesListAdapter adapter; private MainContract.FavoritesPresenter mPresenter; + private ListView listView; + private ImageView favoritesEmptyImage; + private TextView favoritesEmptyText; + @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -33,10 +39,17 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract mPresenter = new FavoritesPresenter(FavoritesActivity.this, this); - getSupportActionBar().setDisplayHomeAsUpEnabled(true); - getSupportActionBar().setHomeButtonEnabled(true); + ActionBar actionBar = getSupportActionBar(); + actionBar.setDisplayHomeAsUpEnabled(true); + actionBar.setHomeButtonEnabled(true); + actionBar.setTitle("Избранное"); db = new FavoritesDBPresenter(FavoritesActivity.this); + + initViews(); + } + + public void initViews() { listView = findViewById(R.id.favorites_list_view); registerForContextMenu(listView); listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @@ -46,10 +59,24 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract mPresenter.fetchItem(model.getItemID()); } }); - + favoritesEmptyImage = findViewById(R.id.favorites_empty_image); + favoritesEmptyText = findViewById(R.id.favorites_empty_text); ArrayList models = db.selectAll(); adapter = new FavoritesListAdapter(FavoritesActivity.this, android.R.layout.simple_list_item_1, models); listView.setAdapter(adapter); + checkForEmptyContent(); + } + + public void checkForEmptyContent() { + if(adapter.getArraySize() == 0) { + listView.setVisibility(View.GONE); + favoritesEmptyImage.setVisibility(View.VISIBLE); + favoritesEmptyText.setVisibility(View.VISIBLE); + } else { + listView.setVisibility(View.VISIBLE); + favoritesEmptyImage.setVisibility(View.INVISIBLE); + favoritesEmptyText.setVisibility(View.INVISIBLE); + } } @Override @@ -117,5 +144,6 @@ public class FavoritesActivity extends AppCompatActivity implements MainContract protected void onResume() { super.onResume(); updateListView(); + checkForEmptyContent(); } } diff --git a/app/src/main/res/drawable/ic_favorite_border_white_24dp.xml b/app/src/main/res/drawable/ic_favorite_border_black_24dp.xml similarity index 91% rename from app/src/main/res/drawable/ic_favorite_border_white_24dp.xml rename to app/src/main/res/drawable/ic_favorite_border_black_24dp.xml index 63fb576..445b826 100644 --- a/app/src/main/res/drawable/ic_favorite_border_white_24dp.xml +++ b/app/src/main/res/drawable/ic_favorite_border_black_24dp.xml @@ -1,4 +1,4 @@ - diff --git a/app/src/main/res/drawable/ic_favorite_border_grey_24dp.xml b/app/src/main/res/drawable/ic_favorite_border_grey_24dp.xml new file mode 100644 index 0000000..628eb96 --- /dev/null +++ b/app/src/main/res/drawable/ic_favorite_border_grey_24dp.xml @@ -0,0 +1,5 @@ + + + diff --git a/app/src/main/res/drawable/ic_favorite_white_24dp.xml b/app/src/main/res/drawable/ic_favorite_red_24dp.xml similarity index 88% rename from app/src/main/res/drawable/ic_favorite_white_24dp.xml rename to app/src/main/res/drawable/ic_favorite_red_24dp.xml index 67a25e7..6ab8ad7 100644 --- a/app/src/main/res/drawable/ic_favorite_white_24dp.xml +++ b/app/src/main/res/drawable/ic_favorite_red_24dp.xml @@ -1,4 +1,4 @@ - diff --git a/app/src/main/res/layout/activity_favorites.xml b/app/src/main/res/layout/activity_favorites.xml index 14f501e..798f0e0 100644 --- a/app/src/main/res/layout/activity_favorites.xml +++ b/app/src/main/res/layout/activity_favorites.xml @@ -1,14 +1,47 @@ - + android:layout_width="wrap_content" + android:layout_height="wrap_content" + app:layout_constraintStart_toStartOf="parent" + app:layout_constraintTop_toTopOf="parent" /> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/content_main.xml b/app/src/main/res/layout/content_main.xml index e3e2877..fb7d24c 100644 --- a/app/src/main/res/layout/content_main.xml +++ b/app/src/main/res/layout/content_main.xml @@ -52,6 +52,8 @@ android:text="" 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" diff --git a/app/src/main/res/menu/activity_main_drawer.xml b/app/src/main/res/menu/activity_main_drawer.xml index 4bcd925..d0aa46a 100644 --- a/app/src/main/res/menu/activity_main_drawer.xml +++ b/app/src/main/res/menu/activity_main_drawer.xml @@ -11,7 +11,7 @@ + android:title="Избранное" /> diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 40a0aa5..f6e076e 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -22,7 +22,7 @@ @android:color/transparent diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index bf5947c..7b2619f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1,5 +1,6 @@ - VRCatalog + uCatalog Open navigation drawer Close navigation drawer + Ваш список избранного пуст diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 78f61cf..147937c 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -1,8 +1,5 @@ - - + + + -