diff --git a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java index 14efa9f0..d8f8fc70 100644 --- a/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java +++ b/app/src/main/java/org/shadowice/flocke/andotp/Activities/MainActivity.java @@ -34,6 +34,8 @@ import android.os.Bundle; import android.os.CountDownTimer; import android.os.Handler; import android.preference.PreferenceManager; + +import androidx.annotation.Nullable; import androidx.core.view.GravityCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.appcompat.app.ActionBarDrawerToggle; @@ -56,6 +58,7 @@ import android.widget.AdapterView; import android.widget.CheckedTextView; import android.widget.ListView; import android.widget.ProgressBar; +import android.widget.TextView; import android.widget.Toast; import com.google.zxing.integration.android.IntentIntegrator; @@ -114,6 +117,8 @@ public class MainActivity extends BaseActivity private String filterString; private CountDownTimer countDownTimer; + private ProgressBar progressBar; + private TextView emptyListView; // QR code scanning private void scanQRCode(){ @@ -245,8 +250,8 @@ public class MainActivity extends BaseActivity } }); - final ProgressBar progressBar = findViewById(R.id.progressBar); - progressBar.setVisibility(settings.isHideGlobalTimeoutEnabled() ? View.GONE : View.VISIBLE); + progressBar = findViewById(R.id.progressBar); + emptyListView = findViewById(R.id.emptyListView); RecyclerView recList = findViewById(R.id.cardList); recList.setHasFixedSize(true); @@ -256,6 +261,43 @@ public class MainActivity extends BaseActivity tagsDrawerAdapter = new TagsAdapter(this, new HashMap()); adapter = new EntriesCardAdapter(this, tagsDrawerAdapter); + adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() { + @Override + public void onChanged() { + super.onChanged(); + hideProgressBar(); + } + + @Override + public void onItemRangeChanged(int positionStart, int itemCount) { + super.onItemRangeChanged(positionStart, itemCount); + hideProgressBar(); + } + + @Override + public void onItemRangeChanged(int positionStart, int itemCount, @Nullable Object payload) { + super.onItemRangeChanged(positionStart, itemCount, payload); + hideProgressBar(); + } + + @Override + public void onItemRangeInserted(int positionStart, int itemCount) { + super.onItemRangeInserted(positionStart, itemCount); + hideProgressBar(); + } + + @Override + public void onItemRangeRemoved(int positionStart, int itemCount) { + super.onItemRangeRemoved(positionStart, itemCount); + hideProgressBar(); + } + + @Override + public void onItemRangeMoved(int fromPosition, int toPosition, int itemCount) { + super.onItemRangeMoved(fromPosition, toPosition, itemCount); + hideProgressBar(); + } + }); if (savedInstanceState != null) { byte[] encKey = savedInstanceState.getByteArray("encKey"); @@ -898,4 +940,15 @@ public class MainActivity extends BaseActivity settings.unregisterPreferenceChangeListener(this); super.onDestroy(); } -} \ No newline at end of file + + /** + * This function will hide the progress bar if the token list is empty along with + * showing a view which has instruction on how to add the tokens + * */ + private void hideProgressBar(){ + int itemCount = adapter.getItemCount(); + progressBar.setVisibility((settings.isHideGlobalTimeoutEnabled() || itemCount <= 0) ? View.GONE : View.VISIBLE); + emptyListView.setVisibility(itemCount > 0 ? View.GONE : View.VISIBLE); + + } +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index adf47974..eef7e889 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -66,7 +66,19 @@ android:paddingTop="@dimen/activity_margin_xsmall" android:paddingBottom="@dimen/fab_recyclerview_padding" android:clipToPadding="false" /> - + diff --git a/app/src/main/res/values/strings_main.xml b/app/src/main/res/values/strings_main.xml index 50a9fed1..4699dc16 100644 --- a/app/src/main/res/values/strings_main.xml +++ b/app/src/main/res/values/strings_main.xml @@ -114,4 +114,7 @@ Scan QR code Import QR code Enter details + + + Start adding your tokens by pressing \"+\" at the bottom