diff --git a/app/src/main/java/com/hitesh_sahu/retailapp/domain/api/ProductCategoryLoaderTask.java b/app/src/main/java/com/hitesh_sahu/retailapp/domain/api/ProductCategoryLoaderTask.java index 9bb7ed9..2f6124a 100644 --- a/app/src/main/java/com/hitesh_sahu/retailapp/domain/api/ProductCategoryLoaderTask.java +++ b/app/src/main/java/com/hitesh_sahu/retailapp/domain/api/ProductCategoryLoaderTask.java @@ -1,11 +1,3 @@ -/* - * Copyright (c) 2017. http://hiteshsahu.com- All Rights Reserved - * Unauthorized copying of this file, via any medium is strictly prohibited - * If you use or distribute this project then you MUST ADD A COPY OF LICENCE - * along with the project. - * Written by Hitesh Sahu , 2017. - */ - package com.hitesh_sahu.retailapp.domain.api; import android.content.Context; @@ -44,50 +36,53 @@ protected void onPreExecute() { super.onPreExecute(); - if (null != ((ECartHomeActivity) context).getProgressBar()) - ((ECartHomeActivity) context).getProgressBar().setVisibility( - View.VISIBLE); - + if (context instanceof ECartHomeActivity) { + ECartHomeActivity activity = (ECartHomeActivity) context; + if (activity.getProgressBar() != null) { + activity.getProgressBar().setVisibility(View.VISIBLE); + } + } } @Override protected void onPostExecute(Void result) { super.onPostExecute(result); - if (null != ((ECartHomeActivity) context).getProgressBar()) - ((ECartHomeActivity) context).getProgressBar().setVisibility( - View.GONE); + if (context instanceof ECartHomeActivity) { + ECartHomeActivity activity = (ECartHomeActivity) context; + if (activity.getProgressBar() != null) { + activity.getProgressBar().setVisibility(View.GONE); + } + } if (recyclerView != null) { - CategoryListAdapter simpleRecyclerAdapter = new CategoryListAdapter( - context); - + CategoryListAdapter simpleRecyclerAdapter = new CategoryListAdapter(context); recyclerView.setAdapter(simpleRecyclerAdapter); - simpleRecyclerAdapter - .SetOnItemClickListener(new OnItemClickListener() { - - @Override - public void onItemClick(View view, int position) { - - AppConstants.CURRENT_CATEGORY = position; - - Utils.switchFragmentWithAnimation( - R.id.frag_container, - new ProductOverviewFragment(), - ((ECartHomeActivity) context), null, - AnimationType.SLIDE_LEFT); - - } - }); + simpleRecyclerAdapter.SetOnItemClickListener(new OnItemClickListener() { + + @Override + public void onItemClick(View view, int position) { + AppConstants.CURRENT_CATEGORY = position; + + if (context instanceof ECartHomeActivity) { + Utils.switchFragmentWithAnimation( + R.id.frag_container, + new ProductOverviewFragment(), + (ECartHomeActivity) context, + null, + AnimationType.SLIDE_LEFT); + } + } + }); } - } @Override protected Void doInBackground(String... params) { try { + // Simulating network call or heavy operation Thread.sleep(3000); } catch (InterruptedException e) { e.printStackTrace(); @@ -97,5 +92,4 @@ protected Void doInBackground(String... params) { return null; } - -} \ No newline at end of file +}