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 23, 2019
1 parent a01331b commit 3489e5a
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
Expand All @@ -61,6 +60,7 @@
import com.example.kaushiknsanji.bookslibrary.observers.OnPagerFragmentVerticalScrollListener;
import com.example.kaushiknsanji.bookslibrary.providers.RecentBookSearchProvider;
import com.example.kaushiknsanji.bookslibrary.settings.SearchSettingsActivity;
import com.example.kaushiknsanji.bookslibrary.utils.Logger;
import com.example.kaushiknsanji.bookslibrary.utils.PreferencesObserverUtility;
import com.example.kaushiknsanji.bookslibrary.utils.TextAppearanceUtility;
import com.example.kaushiknsanji.bookslibrary.workers.BooksLoader;
Expand Down Expand Up @@ -137,7 +137,7 @@ public class BookSearchActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
Log.d(LOG_TAG, "onCreate: Started");
Logger.d(LOG_TAG, "onCreate: Started");

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Expand Down Expand Up @@ -422,7 +422,7 @@ protected void onSaveInstanceState(Bundle outState) {
//Called by the Activity when it is prepared to be shown
@Override
protected void onResume() {
Log.d(LOG_TAG, "onResume: Started");
Logger.d(LOG_TAG, "onResume: Started");
super.onResume();

//Registering the Listener on TabLayout
Expand Down Expand Up @@ -584,8 +584,8 @@ private void updatePaginationButtonsState() {
int endIndex = mPreferences.getInt(getString(R.string.pref_page_to_display_max_value_key),
startIndex);

Log.d(LOG_TAG, "updatePaginationButtonsState: startIndex " + startIndex);
Log.d(LOG_TAG, "updatePaginationButtonsState: endIndex " + endIndex);
Logger.d(LOG_TAG, "updatePaginationButtonsState: startIndex " + startIndex);
Logger.d(LOG_TAG, "updatePaginationButtonsState: endIndex " + endIndex);

if (startIndex == endIndex && startIndex != 1) {
//When the last page is reached
Expand All @@ -599,7 +599,7 @@ private void updatePaginationButtonsState() {
mPagePreviousButton.setEnabled(true);
mPageMoreButton.setEnabled(true);

Log.d(LOG_TAG, "updatePaginationButtonsState: last buttons disabled");
Logger.d(LOG_TAG, "updatePaginationButtonsState: last buttons disabled");


}
Expand All @@ -613,7 +613,7 @@ private void updatePaginationButtonsState() {
mPagePreviousButton.setEnabled(false);
mPageMoreButton.setEnabled(false);

Log.d(LOG_TAG, "updatePaginationButtonsState: all buttons disabled");
Logger.d(LOG_TAG, "updatePaginationButtonsState: all buttons disabled");


} else if (startIndex != endIndex && startIndex == 1) {
Expand All @@ -628,7 +628,7 @@ private void updatePaginationButtonsState() {
mPageLastButton.setEnabled(true);
mPageNextButton.setEnabled(true);

Log.d(LOG_TAG, "updatePaginationButtonsState: first buttons disabled");
Logger.d(LOG_TAG, "updatePaginationButtonsState: first buttons disabled");


} else if (startIndex != endIndex) {
Expand All @@ -639,7 +639,7 @@ private void updatePaginationButtonsState() {
mPageLastButton.setEnabled(true);
mPageNextButton.setEnabled(true);

Log.d(LOG_TAG, "updatePaginationButtonsState: all buttons enabled");
Logger.d(LOG_TAG, "updatePaginationButtonsState: all buttons enabled");

}

Expand Down Expand Up @@ -702,7 +702,7 @@ protected void onNewIntent(Intent intent) {
//and initializes the SearchView for Assisted Search
@Override
public boolean onCreateOptionsMenu(Menu menu) {
Log.d(LOG_TAG, "onCreateOptionsMenu: Started");
Logger.d(LOG_TAG, "onCreateOptionsMenu: Started");

//Inflating the Menu options from menu_main.xml
getMenuInflater().inflate(R.menu.menu_main, menu);
Expand Down Expand Up @@ -892,7 +892,7 @@ public void onKeywordFilterSelected(String filterValue) {
*/
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(LOG_TAG, "onTabSelected: Started");
Logger.d(LOG_TAG, "onTabSelected: Started");

//Fix added to correct the Position pointed by the ViewPager: START
//(Directly touching the tab instead of swiping can result in this)
Expand Down Expand Up @@ -926,7 +926,7 @@ public void onTabSelected(TabLayout.Tab tab) {
//Displaying the Progress Bar
toggleProgressBarVisibility(View.VISIBLE);

Log.d(LOG_TAG, "onTabSelected: reloading loader");
Logger.d(LOG_TAG, "onTabSelected: reloading loader");
//Reloading the result of the Search previously executed
getSupportLoaderManager().initLoader(BooksLoader.BOOK_SEARCH_LOADER, null, this);
}
Expand Down Expand Up @@ -1004,7 +1004,7 @@ public void onLoadFinished(@NonNull Loader<List<BookInfo>> loader, List<BookInfo
//Loading the data to the RecyclerViewFragment when present
RecyclerViewFragment fragment = getCurrentFragmentFromViewPager();
fragment.loadNewData(bookInfos);
Log.d(LOG_TAG, "onLoadFinished: data loaded by - " + fragment);
Logger.d(LOG_TAG, "onLoadFinished: data loaded by - " + fragment);
} else {
//When the data returned is NULL or Empty
BooksLoader booksLoader = (BooksLoader) loader;
Expand Down Expand Up @@ -1044,7 +1044,7 @@ public void onLoadFinished(@NonNull Loader<List<BookInfo>> loader, List<BookInfo
startIndex);

if (startIndex == 1 && endIndex == startIndex && lastViewedPageIndex == startIndex) {
Log.d(LOG_TAG, "onLoadFinished: No data, All index is currently at " + startIndex);
Logger.d(LOG_TAG, "onLoadFinished: No data, All index is currently at " + startIndex);
//When all page index says 1, it means no result has been generated for the new query executed

//Displaying the No Page Result in such cases
Expand Down Expand Up @@ -1073,7 +1073,7 @@ public void onLoadFinished(@NonNull Loader<List<BookInfo>> loader, List<BookInfo
Toast.makeText(this, getString(R.string.restoring_page_msg, lastViewedPageIndex, startIndex), Toast.LENGTH_SHORT).show();
}

Log.d(LOG_TAG, "onLoadFinished: Restoring page " + lastViewedPageIndex + " from " + startIndex);
Logger.d(LOG_TAG, "onLoadFinished: Restoring page " + lastViewedPageIndex + " from " + startIndex);

//Opening the Editor to restore the value of last viewed page index to 'Page to Display' setting
SharedPreferences.Editor prefEditor = mPreferences.edit();
Expand Down Expand Up @@ -1161,7 +1161,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
*/
@Override
public void onBottomReached(int verticalScrollAmount) {
Log.d(LOG_TAG, "onBottomReached: verticalScrollAmount: " + verticalScrollAmount);
Logger.d(LOG_TAG, "onBottomReached: verticalScrollAmount: " + verticalScrollAmount);
View paginationPanelView = findViewById(R.id.pagination_panel_id);
if (verticalScrollAmount > 0) {
//Displaying the Pagination Panel when the scroll
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand All @@ -41,6 +40,7 @@
import com.example.kaushiknsanji.bookslibrary.models.BookInfo;
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemClickListener;
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemDataSwapListener;
import com.example.kaushiknsanji.bookslibrary.utils.Logger;
import com.example.kaushiknsanji.bookslibrary.utils.TextAppearanceUtility;
import com.example.kaushiknsanji.bookslibrary.workers.BooksDiffLoader;
import com.example.kaushiknsanji.bookslibrary.workers.ImageDownloaderFragment;
Expand Down Expand Up @@ -280,7 +280,7 @@ public void swapItemData(@NonNull List<BookInfo> newBookInfos) {
* @param newBookInfos is the new list of {@link BookInfo} objects which is the Dataset of the Adapter
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, @NonNull List<BookInfo> newBookInfos) {
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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
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;
Expand All @@ -41,6 +40,7 @@
import com.example.kaushiknsanji.bookslibrary.models.BookInfo;
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemClickListener;
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemDataSwapListener;
import com.example.kaushiknsanji.bookslibrary.utils.Logger;
import com.example.kaushiknsanji.bookslibrary.utils.TextAppearanceUtility;
import com.example.kaushiknsanji.bookslibrary.workers.BooksDiffLoader;
import com.example.kaushiknsanji.bookslibrary.workers.ImageDownloaderFragment;
Expand Down Expand Up @@ -211,8 +211,6 @@ public void onBindViewHolder(@NonNull ViewHolder holder, int position, @NonNull
for (String keyStr : bundle.keySet()) {
switch (keyStr) {
case PAYLOAD_BOOK_IMAGE_LINK_STR_KEY:
Log.d(LOG_TAG, "onBindViewHolder: Payload - image: " + bundle.getString(keyStr));
Log.d(LOG_TAG, "onBindViewHolder: Payload - position: " + position);
//Updating the Image
holder.updateBookImage(bundle.getString(keyStr), position);
break;
Expand Down Expand Up @@ -315,7 +313,7 @@ public void swapItemData(@NonNull List<BookInfo> newBookInfos) {
* @param newBookInfos is the new list of {@link BookInfo} objects which is the Dataset of the Adapter
*/
private void doSwapItemData(DiffUtil.DiffResult diffResult, @NonNull List<BookInfo> newBookInfos) {
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);

Expand Down Expand Up @@ -449,7 +447,6 @@ public void onClick(View v) {
* @param bookInfo The {@link BookInfo} data of the Book item at the {@code position}
*/
void bind(int position, BookInfo bookInfo) {
Log.d(LOG_TAG, "bind: position " + position);
//Retrieving the Resources instance
Resources resources = itemView.getResources();

Expand Down Expand Up @@ -491,7 +488,6 @@ void bind(int position, BookInfo bookInfo) {
* @param position The position of the Book Item in the list
*/
void updateBookImage(String imageLinkForItemInfo, int position) {
Log.d(LOG_TAG, "updateBookImage: Link: " + imageLinkForItemInfo + " position: " + position);
ImageDownloaderFragment
.newInstance(((FragmentActivity) bookImageView.getContext()).getSupportFragmentManager(), position)
.executeAndUpdate(bookImageView,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -41,6 +40,7 @@
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemClickListener;
import com.example.kaushiknsanji.bookslibrary.observers.OnAdapterItemDataSwapListener;
import com.example.kaushiknsanji.bookslibrary.observers.OnPagerFragmentVerticalScrollListener;
import com.example.kaushiknsanji.bookslibrary.utils.Logger;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand Down Expand Up @@ -349,7 +349,7 @@ public void clearItemClickListener(int position) {
* @param bookInfos List of {@link BookInfo} objects to be loaded into the Adapter
*/
public void loadNewData(List<BookInfo> bookInfos) {
Log.d(LOG_TAG, "loadNewData: Started");
Logger.d(LOG_TAG, "loadNewData: Started");
//Calling the Adapter's method to Load the new data
swapAdapterData(bookInfos);
}
Expand All @@ -363,11 +363,11 @@ private void swapAdapterData(@NonNull List<BookInfo> bookInfos) {
RecyclerView.Adapter adapter = mRecyclerView.getAdapter();
//Calling the respective method from the Adapter to load & display the new data accordingly
if (adapter instanceof RecyclerListAdapter) {
Log.d(LOG_TAG, "swapAdapterData: Started for List");
Logger.d(LOG_TAG, "swapAdapterData: Started for List");
RecyclerListAdapter listAdapter = (RecyclerListAdapter) adapter;
listAdapter.swapItemData(bookInfos);
} else if (adapter instanceof RecyclerGridAdapter) {
Log.d(LOG_TAG, "swapAdapterData: Started for Grid");
Logger.d(LOG_TAG, "swapAdapterData: Started for Grid");
RecyclerGridAdapter gridAdapter = (RecyclerGridAdapter) adapter;
gridAdapter.swapItemData(bookInfos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.example.kaushiknsanji.bookslibrary.utils;

import android.util.Log;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
Expand Down Expand Up @@ -80,7 +78,7 @@ private static int getCalculatedLastPageIndex(URL urlObject, int itemsPerPage,
try {
jsonResponse = BookClientUtility.makeHttpGetRequest(urlObject);
} catch (IOException e) {
Log.e(LOG_TAG, "Error occurred while closing the URL Stream\n", e);
Logger.e(LOG_TAG, "Error occurred while closing the URL Stream\n", e);
}

//If the response received is null or empty, then return the value of lastPageIndex
Expand Down Expand Up @@ -136,7 +134,7 @@ private static int getCalculatedLastPageIndex(URL urlObject, int itemsPerPage,
}

} catch (JSONException e) {
Log.e(LOG_TAG, "Error occurred while parsing the JSON Response\n", e);
Logger.e(LOG_TAG, "Error occurred while parsing the JSON Response\n", e);
}

//Returning the evaluated lastPageIndex for the search query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.example.kaushiknsanji.bookslibrary.utils;

import android.util.Log;

import com.example.kaushiknsanji.bookslibrary.models.BookInfo;

import org.json.JSONArray;
Expand Down Expand Up @@ -65,7 +63,7 @@ public static List<BookInfo> searchAndExtractVolumes(URL urlObject) {
try {
jsonResponse = makeHttpGetRequest(urlObject);
} catch (IOException e) {
Log.e(LOG_TAG, "Error occurred while closing the URL Stream\n", e);
Logger.e(LOG_TAG, "Error occurred while closing the URL Stream\n", e);
}

//If the response received is null or empty, then return as NULL
Expand Down Expand Up @@ -243,7 +241,7 @@ private static List<BookInfo> extractVolumesFromResponse(String jsonResponse) {
}

} catch (JSONException e) {
Log.e(LOG_TAG, "Error occurred while parsing the JSON Response\n", e);
Logger.e(LOG_TAG, "Error occurred while parsing the JSON Response\n", e);
}

//Returning the list of {@link BookInfo} objects parsed
Expand Down Expand Up @@ -277,11 +275,11 @@ public static String makeHttpGetRequest(URL urlObject) throws IOException {
jsonResponse = readStream(urlConnectionInputStream);
} else {
//When the response is not OK(200), then log the error code
Log.e(LOG_TAG, "HTTP GET Request failed with the code " + urlConnection.getResponseCode());
Logger.e(LOG_TAG, "HTTP GET Request failed with the code " + urlConnection.getResponseCode());
}

} catch (IOException e) {
Log.e(LOG_TAG, "Error occurred while opening connection to URL\n", e);
Logger.e(LOG_TAG, "Error occurred while opening connection to URL\n", e);
} finally {

if (urlConnection != null) {
Expand Down Expand Up @@ -319,7 +317,7 @@ private static String readStream(InputStream urlConnectionInputStream) {
responseBuilder.append(readStr);
}
} catch (IOException e) {
Log.e(LOG_TAG, "Error occurred while reading the response stream\n", e);
Logger.e(LOG_TAG, "Error occurred while reading the response stream\n", e);
//resetting the StringBuilder to empty string
responseBuilder.delete(0, responseBuilder.length());
}
Expand Down

0 comments on commit 3489e5a

Please sign in to comment.