Skip to content

Commit

Permalink
refactor: Log statements only for debuggable build types
Browse files Browse the repository at this point in the history
  • Loading branch information
kaushiknsanji committed Oct 26, 2019
1 parent 3687cdc commit 7122e6f
Show file tree
Hide file tree
Showing 15 changed files with 250 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.MenuItem;

import com.example.kaushiknsanji.novalines.adapters.NavRecyclerAdapter;
Expand All @@ -43,6 +42,7 @@
import com.example.kaushiknsanji.novalines.drawerviews.RandomNewsFragment;
import com.example.kaushiknsanji.novalines.models.NavDrawerItem;
import com.example.kaushiknsanji.novalines.settings.SettingsActivity;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.PreferencesUtility;

import java.util.ArrayList;
Expand Down Expand Up @@ -271,7 +271,7 @@ protected void onPause() {
* @param toolbar is the {@link Toolbar} to which the Drawer Toggle needs to be setup with
*/
private void setupDrawerToggle(Toolbar toolbar) {
Log.d(LOG_TAG, "setupDrawerToggle: Started");
Logger.d(LOG_TAG, "setupDrawerToggle: Started");
if (mDrawerToggle != null) {
//Removing any old Drawer Listener if present
mDrawerLayout.removeDrawerListener(mDrawerToggle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.support.v7.widget.RecyclerView;
import android.text.Layout;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -45,6 +44,7 @@

import com.example.kaushiknsanji.novalines.R;
import com.example.kaushiknsanji.novalines.models.NewsArticleInfo;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.NewsArticleInfoDiffUtility;
import com.example.kaushiknsanji.novalines.utils.TextAppearanceUtility;
import com.example.kaushiknsanji.novalines.workers.ImageDownloaderFragment;
Expand Down Expand Up @@ -456,7 +456,7 @@ public void swapItemData(@NonNull List<NewsArticleInfo> newArticleInfos) {
* @param newArticleInfoList is the new list of {@link NewsArticleInfo} objects which is the Dataset of the Adapter
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, List<NewsArticleInfo> newArticleInfoList) {
Log.d(LOG_TAG + "_" + mNewsTopicId, "doSwapItemData: Started");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "doSwapItemData: Started");

//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);
Expand Down Expand Up @@ -779,7 +779,7 @@ public boolean onMenuItemClick(MenuItem item) {
break;
default:
//For the entire Item View
Log.d(LOG_TAG, "onClick: mItemClickListener " + mItemClickListener);
Logger.d(LOG_TAG, "onClick: mItemClickListener " + mItemClickListener);
//Propagating the call to the listener with the selected item's data
if (mItemClickListener != null) {
mItemClickListener.onItemClick(newsArticleInfo);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@
import android.support.v7.util.DiffUtil;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.kaushiknsanji.novalines.R;
import com.example.kaushiknsanji.novalines.models.NewsSectionInfo;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.NewsSectionInfoDiffUtility;
import com.example.kaushiknsanji.novalines.workers.NewsHighlightsDiffLoader;

Expand Down Expand Up @@ -248,15 +248,15 @@ public void swapItemData(@NonNull List<NewsSectionInfo> newSectionInfos) {
* @param newSectionInfoList is the new list of {@link NewsSectionInfo} objects which is the Dataset of the Adapter
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, @NonNull List<NewsSectionInfo> newSectionInfoList) {
Log.d(LOG_TAG, "doSwapItemData: Started");
Logger.d(LOG_TAG, "doSwapItemData: Started");
//Informing the adapter about the changes required, so that it triggers the notify accordingly
diffResult.dispatchUpdatesTo(this);

//Clearing the Adapter's data to load the new list of NewsSectionInfo objects
mNewsSectionInfoList.clear();
mNewsSectionInfoList.addAll(newSectionInfoList);

Log.d(LOG_TAG, "doSwapItemData: mItemDataSwapListener " + mItemDataSwapListener);
Logger.d(LOG_TAG, "doSwapItemData: mItemDataSwapListener " + mItemDataSwapListener);
//Dispatching the Item Data Swap event to the listener
if (mItemDataSwapListener != null) {
mItemDataSwapListener.onItemDataSwapped();
Expand Down Expand Up @@ -383,7 +383,7 @@ public void onClick(View v) {
if (adapterPosition > RecyclerView.NO_POSITION) {
//Verifying the validity of the position before proceeding

Log.d(LOG_TAG, "onClick: mItemClickListener " + mItemClickListener);
Logger.d(LOG_TAG, "onClick: mItemClickListener " + mItemClickListener);
//Propagating the call to the listener with the selected item's data
if (mItemClickListener != null) {
mItemClickListener.onItemClick(mNewsSectionInfoList.get(adapterPosition));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -52,6 +51,7 @@
import com.example.kaushiknsanji.novalines.presenters.BookmarkActionPresenter;
import com.example.kaushiknsanji.novalines.presenters.FavoriteActionPresenter;
import com.example.kaushiknsanji.novalines.utils.IntentUtility;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.NewsURLGenerator;
import com.example.kaushiknsanji.novalines.utils.PreferencesObserverUtility;
import com.example.kaushiknsanji.novalines.utils.PreferencesUtility;
Expand Down Expand Up @@ -552,7 +552,7 @@ public void scrollToItemPosition(int position, boolean scrollImmediate) {
//Updating the item position reference
mVisibleItemViewPosition = position;

Log.d(LOG_TAG + "_" + mNewsTopicId, "scrollToItemPosition: Updating to position " + mVisibleItemViewPosition);
Logger.d(LOG_TAG + "_" + mNewsTopicId, "scrollToItemPosition: Updating to position " + mVisibleItemViewPosition);

if (scrollImmediate) {
//Scrolling to the item position immediately
Expand Down Expand Up @@ -617,7 +617,7 @@ public Loader<List<NewsArticleInfo>> onCreateLoader(int id, Bundle args) {
if (id == mLoaderIds[0]) {
//Returning the Instance of NewsArticlesLoader
URL sectionURL = mUrlGenerator.createSectionURL(mNewsTopicId);
Log.d(LOG_TAG + "_" + mNewsTopicId, "onCreateLoader: SectionURL " + sectionURL);
Logger.d(LOG_TAG + "_" + mNewsTopicId, "onCreateLoader: SectionURL " + sectionURL);
return new NewsArticlesLoader(getActivity(), sectionURL);
}

Expand Down Expand Up @@ -658,12 +658,12 @@ public void onLoadFinished(@NonNull Loader<List<NewsArticleInfo>> loader, List<N

if (!newsArticlesLoader.getNetworkConnectivityStatus()) {
//Reporting Network Failure when False
Log.d(LOG_TAG + "_" + mNewsTopicId, "onLoadFinished: Network Failure");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "onLoadFinished: Network Failure");
//Displaying the "Network Error Layout"
showNetworkErrorLayout();
} else {
//When there is NO network issue and the current page has no data to be shown
Log.d(LOG_TAG + "_" + mNewsTopicId, "onLoadFinished: NO DATA RETURNED");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "onLoadFinished: NO DATA RETURNED");

//Retrying for Paginated Results if the current page is not the first page
if (mIsPaginatedView && PreferencesUtility.getStartPageIndex(getContext(), mPreferences) > 1) {
Expand Down Expand Up @@ -765,7 +765,7 @@ private void enableDefaultComponents(boolean visibility) {
* and takes care of setting the dependent view visibility flags to false
*/
private void hideErrorView() {
Log.d(LOG_TAG + "_" + mNewsTopicId, "hideErrorView: Started");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "hideErrorView: Started");
//Hiding the "Error View"
mErrorView.setVisibility(View.GONE);
//Setting the "No Feed Layout" visibility flag to false
Expand Down Expand Up @@ -828,7 +828,7 @@ public void onRefresh() {
*/
@Override
public void onItemDataSwapped() {
Log.d(LOG_TAG + "_" + mNewsTopicId, "onItemDataSwapped: News Articles data loaded successfully for " + mNewsTopicId);
Logger.d(LOG_TAG + "_" + mNewsTopicId, "onItemDataSwapped: News Articles data loaded successfully for " + mNewsTopicId);
//Ensuring the "Error View" is hidden
hideErrorView();

Expand Down Expand Up @@ -928,7 +928,7 @@ public void onOpenNewsSectionRequest(NewsArticleInfo newsArticleInfo) {
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (!mKeysToExclude.contains(key)) {
Log.d(LOG_TAG + "_" + mNewsTopicId, "onSharedPreferenceChanged: key " + key);
Logger.d(LOG_TAG + "_" + mNewsTopicId, "onSharedPreferenceChanged: key " + key);
mVisibleItemViewPosition = 0;

if (getUserVisibleHint()) {
Expand All @@ -954,7 +954,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
public void checkAndReloadData() {
if (getActivity() != null && getUserVisibleHint()) {
//When attached to an Activity and the current fragment is the one viewed by the user
Log.d(LOG_TAG + "_" + mNewsTopicId, "checkAndReloadData: Started");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "checkAndReloadData: Started");
//Retrieving the current loader of the Fragment
LoaderManager loaderManager = getLoaderManager();
Loader<List<NewsArticleInfo>> loader = loaderManager.getLoader(mLoaderIds[0]);
Expand All @@ -969,7 +969,7 @@ public void checkAndReloadData() {
String newRequestURLStr = mUrlGenerator.createSectionURL(mNewsTopicId).toExternalForm();
if (!newRequestURLStr.equals(requestURLStr)) {
//When the URLs are different, reload the data
Log.d(LOG_TAG + "_" + mNewsTopicId, "checkAndReloadData: Reloading data");
Logger.d(LOG_TAG + "_" + mNewsTopicId, "checkAndReloadData: Reloading data");
triggerLoad(true);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import android.support.v7.preference.PreferenceManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -49,6 +48,7 @@
import com.example.kaushiknsanji.novalines.models.NewsSectionInfo;
import com.example.kaushiknsanji.novalines.utils.DateUtility;
import com.example.kaushiknsanji.novalines.utils.IntentUtility;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.PreferencesUtility;
import com.example.kaushiknsanji.novalines.utils.RecyclerViewUtility;
import com.example.kaushiknsanji.novalines.workers.NewsHighlightsLoader;
Expand Down Expand Up @@ -153,7 +153,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.d(LOG_TAG, "onCreateView: Started");
Logger.d(LOG_TAG, "onCreateView: Started");
//Inflating the layout 'R.layout.highlights_layout'
View rootView = inflater.inflate(R.layout.highlights_layout, container, false);

Expand Down Expand Up @@ -244,7 +244,7 @@ public void onResume() {
@Override
public void onPause() {
super.onPause();
Log.d(LOG_TAG, "onPause: Started");
Logger.d(LOG_TAG, "onPause: Started");

//UnRegistering the Preference Change Listener
mPreferences.unregisterOnSharedPreferenceChangeListener(this);
Expand Down Expand Up @@ -331,7 +331,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
* and triggers the re-calculation of Start Date for the News if in Preset mode (False condition)
*/
private void enforceDateSetting() {
Log.d(LOG_TAG, "enforceDateSetting: Started");
Logger.d(LOG_TAG, "enforceDateSetting: Started");

if (!PreferencesUtility.getStartPeriodOverrideValue(getContext(), mPreferences)) {
//When in Preset mode (False condition)
Expand Down Expand Up @@ -379,7 +379,7 @@ private void enforceDateSetting() {
//Updating the above value in the 'from-date' setting
PreferencesUtility.updateStartPeriodValue(getContext(), mPreferences, dateCalendar.getTimeInMillis());

Log.d(LOG_TAG, "enforceDateSetting: Reapplied");
Logger.d(LOG_TAG, "enforceDateSetting: Reapplied");

//Updating the 'date-today' setting to reflect the current day's date
PreferencesUtility.updateCurrentDayDateValue(getContext(), mPreferences, todayCalendar.getTimeInMillis());
Expand Down Expand Up @@ -580,7 +580,7 @@ public void onLoadFinished(@NonNull Loader<List<NewsSectionInfo>> loader, List<N

if (!highlightsLoader.getNetworkConnectivityStatus()) {
//Reporting Network Failure when False
Log.d(LOG_TAG, "onLoadFinished: Network Failure");
Logger.d(LOG_TAG, "onLoadFinished: Network Failure");
//Displaying the "Network Error Layout"
showNetworkErrorLayout();
}
Expand Down Expand Up @@ -694,7 +694,7 @@ public void onRefresh() {
*/
@Override
public void onItemDataSwapped() {
Log.d(LOG_TAG, "onItemDataSwapped: News Highlights data loaded successfully");
Logger.d(LOG_TAG, "onItemDataSwapped: News Highlights data loaded successfully");
//Ensuring the "Error View" is hidden
hideErrorView();

Expand All @@ -718,7 +718,7 @@ public void run() {
*/
@Override
public void onItemClick(NewsSectionInfo newsSectionInfo) {
Log.d(LOG_TAG, "onItemClick: Started");
Logger.d(LOG_TAG, "onItemClick: Started");
//Opening the News Category Tab for the News Section Title retrieved from the Item selected
if (getParentFragment() != null) {
((HeadlinesFragment) getParentFragment()).openNewsCategoryTabByTitle(newsSectionInfo.getSectionName(), newsSectionInfo.getSectionId());
Expand All @@ -737,7 +737,7 @@ public void onItemClick(NewsSectionInfo newsSectionInfo) {
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (key.equals(PreferencesUtility.getStartPeriodKey(requireContext()))) {
//When the Start Date of the News is changed
Log.d(LOG_TAG, "onSharedPreferenceChanged: Updating " + key);
Logger.d(LOG_TAG, "onSharedPreferenceChanged: Updating " + key);

//Triggering a new data load only if the Start date value has changed
//(This also prevents duplicate triggers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import android.support.v4.content.ContextCompat;
import android.support.v4.content.res.ResourcesCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
Expand All @@ -36,6 +35,7 @@
import com.example.kaushiknsanji.novalines.R;
import com.example.kaushiknsanji.novalines.drawerviews.HeadlinesFragment;
import com.example.kaushiknsanji.novalines.utils.IntentUtility;
import com.example.kaushiknsanji.novalines.utils.Logger;
import com.example.kaushiknsanji.novalines.utils.TextAppearanceUtility;

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Log.d(LOG_TAG, "onCreateView: Started with savedInstanceState as " + savedInstanceState);
Logger.d(LOG_TAG, "onCreateView: Started with savedInstanceState as " + savedInstanceState);
//Inflating the layout 'R.layout.more_news_layout'
View rootView = inflater.inflate(R.layout.more_news_layout, container, false);

Expand Down
Loading

0 comments on commit 7122e6f

Please sign in to comment.