Use Timber for logging

This commit is contained in:
veyndan 2017-04-17 16:24:50 +01:00
parent 052d0c9c8e
commit d33935c70f
35 changed files with 238 additions and 259 deletions

View file

@ -16,6 +16,7 @@ dependencies {
compile 'com.google.code.gson:gson:2.7'
compile "com.jakewharton:butterknife:$BUTTERKNIFE_VERSION"
annotationProcessor "com.jakewharton:butterknife-compiler:$BUTTERKNIFE_VERSION"
compile 'com.jakewharton.timber:timber:4.5.1'
testCompile 'junit:junit:4.12'
}

View file

@ -9,7 +9,6 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.Build;
import android.support.v4.util.LruCache;
import android.util.Log;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.BasicNetwork;
@ -39,6 +38,7 @@ import java.io.IOException;
import fr.free.nrw.commons.auth.WikiAccountAuthenticator;
import fr.free.nrw.commons.caching.CacheController;
import timber.log.Timber;
// TODO: Use ProGuard to rip out reporting when publishing
@ReportsCrashes(
@ -92,6 +92,9 @@ public class CommonsApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
Timber.plant(new Timber.DebugTree());
if (!BuildConfig.DEBUG) {
ACRA.init(this);
}
@ -112,11 +115,11 @@ public class CommonsApplication extends Application {
long maxMem = Runtime.getRuntime().maxMemory();
if (maxMem < 48L * 1024L * 1024L) {
// Cache only one bitmap if VM memory is too small (such as Nexus One);
Log.d("Commons", "Skipping bitmap cache; max mem is: " + maxMem);
Timber.d("Skipping bitmap cache; max mem is: %d", maxMem);
imageCache = new LruCache<>(1);
} else {
int cacheSize = (int) (maxMem / (1024 * 8));
Log.d("Commons", "Bitmap cache size " + cacheSize + " from max mem " + maxMem);
Timber.d("Bitmap cache size %d from max mem %d", cacheSize, maxMem);
imageCache = new LruCache<String, Bitmap>(cacheSize) {
@Override
protected int sizeOf(String key, Bitmap bitmap) {

View file

@ -4,7 +4,6 @@ import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Build;
import android.preference.PreferenceManager;
import android.util.Log;
import org.apache.http.HttpResponse;
import org.json.JSONException;
@ -17,6 +16,7 @@ import java.net.URL;
import fr.free.nrw.commons.settings.Prefs;
import in.yuvi.http.fluent.Http;
import timber.log.Timber;
public class EventLog {
@ -38,11 +38,11 @@ public class EventLog {
if(response.getStatusLine().getStatusCode() != 204) {
allSuccess = false;
}
Log.d("Commons", "EventLog hit " + url.toString());
Timber.d("EventLog hit %s", url);
} catch (IOException e) {
// Probably just ignore for now. Can be much more robust with a service, etc later on.
Log.d("Commons", "IO Error, EventLog hit skipped");
Timber.d("IO Error, EventLog hit skipped");
}
}

View file

@ -1,7 +1,5 @@
package fr.free.nrw.commons;
import android.util.Log;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
import org.w3c.dom.Document;
@ -23,6 +21,8 @@ import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import timber.log.Timber;
/**
* Fetch additional media data from the network that we don't store locally.
*
@ -131,20 +131,20 @@ public class MediaDataExtractor {
* look for 'self' template and check its first parameter
* if none, look for any of the known templates
*/
Log.d("Commons", "MediaDataExtractor searching for license");
Timber.d("MediaDataExtractor searching for license");
Node selfLicenseNode = findTemplate(doc.getDocumentElement(), "self");
if (selfLicenseNode != null) {
Node firstNode = findTemplateParameter(selfLicenseNode, 1);
String licenseTemplate = getFlatText(firstNode);
License license = licenseList.licenseForTemplate(licenseTemplate);
if (license == null) {
Log.d("Commons", "MediaDataExtractor found no matching license for self parameter: " + licenseTemplate + "; faking it");
Timber.d("MediaDataExtractor found no matching license for self parameter: %s; faking it", licenseTemplate);
this.license = licenseTemplate; // hack hack! For non-selectable licenses that are still in the system.
} else {
// fixme: record the self-ness in here too... sigh
// all this needs better server-side metadata
this.license = license.getKey();
Log.d("Commons", "MediaDataExtractor found self-license " + this.license);
Timber.d("MediaDataExtractor found self-license %s", this.license);
}
} else {
for (License license : licenseList.values()) {
@ -153,7 +153,7 @@ public class MediaDataExtractor {
if (template != null) {
// Found!
this.license = license.getKey();
Log.d("Commons", "MediaDataExtractor found non-self license " + this.license);
Timber.d("MediaDataExtractor found non-self license %s", this.license);
break;
}
}

View file

@ -2,13 +2,13 @@ package fr.free.nrw.commons;
import android.net.Uri;
import android.os.Build;
import android.util.Log;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
import fr.free.nrw.commons.settings.Prefs;
import timber.log.Timber;
import java.io.BufferedInputStream;
import java.io.IOException;
@ -44,8 +44,6 @@ import org.xmlpull.v1.XmlPullParserException;
public class Utils {
private static final String TAG = Utils.class.getName();
// Get SHA1 of file from input stream
public static String getSHA1(InputStream is) {
@ -53,7 +51,7 @@ public class Utils {
try {
digest = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
Log.e(TAG, "Exception while getting Digest", e);
Timber.e(e, "Exception while getting Digest");
return "";
}
@ -68,17 +66,17 @@ public class Utils {
String output = bigInt.toString(16);
// Fill to 40 chars
output = String.format("%40s", output).replace(' ', '0');
Log.i(TAG, "File SHA1: " + output);
Timber.i("File SHA1: %s", output);
return output;
} catch (IOException e) {
Log.e(TAG, "IO Exception", e);
Timber.e(e, "IO Exception");
return "";
} finally {
try {
is.close();
} catch (IOException e) {
Log.e(TAG, "Exception on closing MD5 input stream", e);
Timber.e(e, "Exception on closing MD5 input stream");
}
}
}

View file

@ -14,9 +14,7 @@ import android.os.Bundle;
import android.support.v4.app.NavUtils;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
@ -26,7 +24,6 @@ import android.widget.TextView;
import android.widget.Toast;
import java.io.IOException;
import java.util.Locale;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.EventLog;
@ -36,6 +33,7 @@ import fr.free.nrw.commons.WelcomeActivity;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import timber.log.Timber;
public class LoginActivity extends AccountAuthenticatorActivity {
@ -61,7 +59,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
Log.d("Commons", "Login done!");
Timber.d("Login done!");
EventLog.schema(CommonsApplication.EVENT_LOGIN_ATTEMPT)
.param("username", username)
@ -80,7 +78,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
Bundle extras = context.getIntent().getExtras();
if (extras != null) {
Log.d("LoginActivity", "Bundle of extras: " + extras.toString());
Timber.d("Bundle of extras: %s", extras);
if (accountCreated) { // Pass the new account back to the account manager
AccountAuthenticatorResponse response = extras.getParcelable(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE);
Bundle authResult = new Bundle();
@ -116,7 +114,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
response = R.string.login_failed_blocked;
} else {
// Should never really happen
Log.d("Commons", "Login failed with reason: " + result);
Timber.d("Login failed with reason: %s", result);
response = R.string.login_failed_generic;
}
Toast.makeText(getApplicationContext(), response, Toast.LENGTH_LONG).show();
@ -242,7 +240,7 @@ public class LoginActivity extends AccountAuthenticatorActivity {
String password = passwordEdit.getText().toString();
Log.d("Commons", "Login to start!");
Timber.d("Login to start!");
LoginTask task = new LoginTask(this);
task.execute(canonicalUsername, password);
}

View file

@ -2,13 +2,13 @@ package fr.free.nrw.commons.auth;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;
import fr.free.nrw.commons.theme.BaseActivity;
import timber.log.Timber;
public class SignupActivity extends BaseActivity {
@ -17,7 +17,7 @@ public class SignupActivity extends BaseActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("SignupActivity", "Signup Activity started");
Timber.d("Signup Activity started");
getSupportActionBar().hide();
@ -37,7 +37,7 @@ public class SignupActivity extends BaseActivity {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.equals("https://commons.m.wikimedia.org/w/index.php?title=Main_Page&welcome=yes")) {
//Signup success, so clear cookies, notify user, and load LoginActivity again
Log.d("SignupActivity", "Overriding URL" + url);
Timber.d("Overriding URL %s", url);
Toast toast = Toast.makeText(getApplicationContext(), "Account created!", Toast.LENGTH_LONG);
toast.show();
@ -47,7 +47,7 @@ public class SignupActivity extends BaseActivity {
return true;
} else {
//If user clicks any other links in the webview
Log.d("SignupActivity", "Not overriding URL, URL is: " + url);
Timber.d("Not overriding URL, URL is: %s", url);
return false;
}
}

View file

@ -1,7 +1,5 @@
package fr.free.nrw.commons.caching;
import android.util.Log;
import com.github.varunpant.quadtree.Point;
import com.github.varunpant.quadtree.QuadTree;
@ -10,6 +8,7 @@ import java.util.Arrays;
import java.util.List;
import fr.free.nrw.commons.upload.MwVolleyApi;
import timber.log.Timber;
public class CacheController {
@ -18,7 +17,6 @@ public class CacheController {
private Point<List<String>>[] pointsFound;
private double xMinus, xPlus, yMinus, yPlus;
private static final String TAG = CacheController.class.getName();
private static final int EARTH_RADIUS = 6378137;
public CacheController() {
@ -28,17 +26,17 @@ public class CacheController {
public void setQtPoint(double decLongitude, double decLatitude) {
x = decLongitude;
y = decLatitude;
Log.d(TAG, "New QuadTree created");
Log.d(TAG, "X (longitude) value: " + x + ", Y (latitude) value: " + y);
Timber.d("New QuadTree created");
Timber.d("X (longitude) value: %f, Y (latitude) value: %f", x, y);
}
public void cacheCategory() {
List<String> pointCatList = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists() == true) {
pointCatList.addAll(MwVolleyApi.getGpsCat());
Log.d(TAG, "Categories being cached: " + pointCatList);
Timber.d("Categories being cached: %s", pointCatList);
} else {
Log.d(TAG, "No categories found, so no categories cached");
Timber.d("No categories found, so no categories cached");
}
quadTree.set(x, y, pointCatList);
}
@ -48,20 +46,20 @@ public class CacheController {
convertCoordRange();
pointsFound = quadTree.searchWithin(xMinus, yMinus, xPlus, yPlus);
List<String> displayCatList = new ArrayList<>();
Log.d(TAG, "Points found in quadtree: " + Arrays.asList(pointsFound));
Timber.d("Points found in quadtree: %s", Arrays.toString(pointsFound));
if (pointsFound.length != 0) {
Log.d(TAG, "Entering for loop");
Timber.d("Entering for loop");
for (Point<List<String>> point : pointsFound) {
Log.d(TAG, "Nearby point: " + point.toString());
Timber.d("Nearby point: %s", point);
displayCatList = point.getValue();
Log.d(TAG, "Nearby cat: " + point.getValue());
Timber.d("Nearby cat: %s", point.getValue());
}
Log.d(TAG, "Categories found in cache: " + displayCatList.toString());
Timber.d("Categories found in cache: %s", displayCatList);
} else {
Log.d(TAG, "No categories found in cache");
Timber.d("No categories found in cache");
}
return displayCatList;
}
@ -84,6 +82,7 @@ public class CacheController {
yMinus = lat - dLat * 180/Math.PI;
xPlus = lon + dLon * 180/Math.PI;
xMinus = lon - dLon * 180/Math.PI;
Log.d(TAG, "Search within: xMinus=" + xMinus + ", yMinus=" + yMinus + ", xPlus=" + xPlus + ", yPlus=" + yPlus);
Timber.d("Search within: xMinus=%s, yMinus=%s, xPlus=%s, yPlus=%s",
xMinus, yMinus, xPlus, yPlus);
}
}

View file

@ -16,7 +16,6 @@ import android.support.v7.app.AlertDialog;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.Menu;
@ -44,6 +43,7 @@ import java.util.concurrent.TimeUnit;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.upload.MwVolleyApi;
import timber.log.Timber;
/**
* Displays the category suggestion and selection screen. Category search is initiated here.
@ -79,7 +79,6 @@ public class CategorizationFragment extends Fragment {
private ContentProviderClient client;
protected final static int SEARCH_CATS_LIMIT = 25;
private static final String TAG = CategorizationFragment.class.getName();
public static class CategoryItem implements Parcelable {
public String name;
@ -130,28 +129,28 @@ public class CategorizationFragment extends Fragment {
//Retrieve the title that was saved when user tapped submit icon
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
String title = titleDesc.getString("Title", "");
Log.d(TAG, "Title: " + title);
Timber.d("Title: %s", title);
//Override onPostExecute to access the results of async API call
titleCategoriesSub = new TitleCategories(title) {
@Override
protected void onPostExecute(ArrayList<String> result) {
super.onPostExecute(result);
Log.d(TAG, "Results in onPostExecute: " + result);
Timber.d("Results in onPostExecute: %s", result);
titleCatItems.addAll(result);
Log.d(TAG, "TitleCatItems in onPostExecute: " + titleCatItems);
Timber.d("TitleCatItems in onPostExecute: %s", titleCatItems);
mergeLatch.countDown();
}
};
titleCategoriesSub.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
Log.d(TAG, "TitleCatItems in titleCatQuery: " + titleCatItems);
Timber.d("TitleCatItems in titleCatQuery: %s", titleCatItems);
//Only return titleCatItems after API call has finished
try {
mergeLatch.await(5L, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Log.e(TAG, "Interrupted exception: ", e);
Timber.e(e, "Interrupted exception: ");
}
return titleCatItems;
}
@ -191,7 +190,7 @@ public class CategorizationFragment extends Fragment {
Set<String> mergedItems = new LinkedHashSet<>();
Log.d(TAG, "Calling APIs for GPS cats, title cats and recent cats...");
Timber.d("Calling APIs for GPS cats, title cats and recent cats...");
List<String> gpsItems = new ArrayList<>();
if (MwVolleyApi.GpsCatExists.getGpsCatExists()) {
@ -203,22 +202,22 @@ public class CategorizationFragment extends Fragment {
//Await results of titleItems, which is likely to come in last
try {
mergeLatch.await(5L, TimeUnit.SECONDS);
Log.d(TAG, "Waited for merge");
Timber.d("Waited for merge");
} catch (InterruptedException e) {
Log.e(TAG, "Interrupted Exception: ", e);
Timber.e(e, "Interrupted Exception: ");
}
mergedItems.addAll(gpsItems);
Log.d(TAG, "Adding GPS items: " + gpsItems);
Timber.d("Adding GPS items: %s", gpsItems);
mergedItems.addAll(titleItems);
Log.d(TAG, "Adding title items: " + titleItems);
Timber.d("Adding title items: %s", titleItems);
mergedItems.addAll(recentItems);
Log.d(TAG, "Adding recent items: " + recentItems);
Timber.d("Adding recent items: %s", recentItems);
//Needs to be an ArrayList and not a List unless we want to modify a big portion of preexisting code
ArrayList<String> mergedItemsList = new ArrayList<>(mergedItems);
Log.d(TAG, "Merged item list: " + mergedItemsList);
Timber.d("Merged item list: %s", mergedItemsList);
return mergedItemsList;
}
@ -261,7 +260,7 @@ public class CategorizationFragment extends Fragment {
}
}
else {
Log.e(TAG, "Error: Fragment is null");
Timber.e("Error: Fragment is null");
}
}
@ -285,7 +284,7 @@ public class CategorizationFragment extends Fragment {
latch.await();
}
catch (InterruptedException e) {
Log.w(TAG, e);
Timber.w(e);
//Thread.currentThread().interrupt();
}
return result;
@ -296,12 +295,12 @@ public class CategorizationFragment extends Fragment {
super.onPostExecute(result);
results.addAll(result);
Log.d(TAG, "Prefix result: " + result);
Timber.d("Prefix result: %s", result);
String filter = categoriesFilter.getText().toString();
ArrayList<String> resultsList = new ArrayList<>(results);
categoriesCache.put(filter, resultsList);
Log.d(TAG, "Final results List: " + resultsList);
Timber.d("Final results List: %s", resultsList);
categoriesAdapter.notifyDataSetChanged();
setCatsAfterAsync(resultsList, filter);
@ -315,7 +314,7 @@ public class CategorizationFragment extends Fragment {
super.onPostExecute(result);
results.addAll(result);
Log.d(TAG, "Method A result: " + result);
Timber.d("Method A result: %s", result);
categoriesAdapter.notifyDataSetChanged();
latch.countDown();

View file

@ -8,9 +8,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import fr.free.nrw.commons.data.DBOpenHelper;
import timber.log.Timber;
public class CategoryContentProvider extends ContentProvider {
@ -101,14 +101,14 @@ public class CategoryContentProvider extends ContentProvider {
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
Log.d("Commons", "Hello, bulk insert! (CategoryContentProvider)");
Timber.d("Hello, bulk insert! (CategoryContentProvider)");
int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
sqlDB.beginTransaction();
switch (uriType) {
case CATEGORIES:
for(ContentValues value: values) {
Log.d("Commons", "Inserting! " + value.toString());
Timber.d("Inserting! %s", value);
sqlDB.insert(Category.Table.TABLE_NAME, null, value);
}
break;

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.category;
import android.os.AsyncTask;
import android.util.Log;
import android.view.View;
import org.mediawiki.api.ApiResult;
@ -13,6 +12,7 @@ import java.util.Calendar;
import java.util.Iterator;
import fr.free.nrw.commons.CommonsApplication;
import timber.log.Timber;
/**
* Sends asynchronous queries to the Commons MediaWiki API to retrieve categories that are close to
@ -22,7 +22,6 @@ import fr.free.nrw.commons.CommonsApplication;
public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
private String filter;
private static final String TAG = MethodAUpdater.class.getName();
CategorizationFragment catFragment;
public MethodAUpdater(CategorizationFragment catFragment) {
@ -54,11 +53,11 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
String yearInString = String.valueOf(year);
Log.d(TAG, "Year: " + yearInString);
Timber.d("Year: %s", yearInString);
int prevYear = year - 1;
String prevYearInString = String.valueOf(prevYear);
Log.d(TAG, "Previous year: " + prevYearInString);
Timber.d("Previous year: %s", prevYearInString);
//Copy to Iterator to prevent ConcurrentModificationException when removing item
for(iterator = items.iterator(); iterator.hasNext();) {
@ -67,12 +66,12 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
//And that s does not equal the current year or previous year
if(s.matches(".*(19|20)\\d{2}.*") && !s.contains(yearInString) && !s.contains(prevYearInString)) {
Log.d(TAG, "Filtering out year " + s);
Timber.d("Filtering out year %s", s);
iterator.remove();
}
}
Log.d(TAG, "Items: " + items.toString());
Timber.d("Items: %s", items);
return items;
}
@ -94,9 +93,9 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
.param("srlimit", catFragment.SEARCH_CATS_LIMIT)
.param("srsearch", filter)
.get();
Log.d(TAG, "Method A URL filter" + result.toString());
Timber.d("Method A URL filter %s", result);
} catch (IOException e) {
Log.e(TAG, "IO Exception: ", e);
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return categories;
}
@ -108,7 +107,7 @@ public class MethodAUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
categories.add(catString);
}
Log.d(TAG, "Found categories from Method A search, waiting for filter");
Timber.d("Found categories from Method A search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
}

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.category;
import android.os.AsyncTask;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import org.mediawiki.api.ApiResult;
@ -14,6 +13,7 @@ import java.util.Calendar;
import java.util.Iterator;
import fr.free.nrw.commons.CommonsApplication;
import timber.log.Timber;
/**
* Sends asynchronous queries to the Commons MediaWiki API to retrieve categories that share the
@ -24,7 +24,6 @@ import fr.free.nrw.commons.CommonsApplication;
public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
private String filter;
private static final String TAG = PrefixUpdater.class.getName();
private CategorizationFragment catFragment;
public PrefixUpdater(CategorizationFragment catFragment) {
@ -56,11 +55,11 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
Calendar now = Calendar.getInstance();
int year = now.get(Calendar.YEAR);
String yearInString = String.valueOf(year);
Log.d(TAG, "Year: " + yearInString);
Timber.d("Year: %s", yearInString);
int prevYear = year - 1;
String prevYearInString = String.valueOf(prevYear);
Log.d(TAG, "Previous year: " + prevYearInString);
Timber.d("Previous year: %s", prevYearInString);
//Copy to Iterator to prevent ConcurrentModificationException when removing item
for(iterator = items.iterator(); iterator.hasNext();) {
@ -69,12 +68,12 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//Check if s contains a 4-digit word anywhere within the string (.* is wildcard)
//And that s does not equal the current year or previous year
if(s.matches(".*(19|20)\\d{2}.*") && !s.contains(yearInString) && !s.contains(prevYearInString)) {
Log.d(TAG, "Filtering out year " + s);
Timber.d("Filtering out year %s", s);
iterator.remove();
}
}
Log.d(TAG, "Items: " + items.toString());
Timber.d("Items: %s", items);
return items;
}
@ -83,7 +82,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//If user hasn't typed anything in yet, get GPS and recent items
if(TextUtils.isEmpty(filter)) {
ArrayList<String> mergedItems = new ArrayList<>(catFragment.mergeItems());
Log.d(TAG, "Merged items, waiting for filter");
Timber.d("Merged items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(mergedItems));
return filteredItems;
}
@ -91,7 +90,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
//if user types in something that is in cache, return cached category
if(catFragment.categoriesCache.containsKey(filter)) {
ArrayList<String> cachedItems = new ArrayList<>(catFragment.categoriesCache.get(filter));
Log.d(TAG, "Found cache items, waiting for filter");
Timber.d("Found cache items, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(cachedItems));
return filteredItems;
}
@ -107,9 +106,9 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
.param("acprefix", filter)
.param("aclimit", catFragment.SEARCH_CATS_LIMIT)
.get();
Log.d(TAG, "Prefix URL filter" + result.toString());
Timber.d("Prefix URL filter %s", result);
} catch (IOException e) {
Log.e(TAG, "IO Exception: ", e);
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return categories;
}
@ -119,7 +118,7 @@ public class PrefixUpdater extends AsyncTask<Void, Void, ArrayList<String>> {
categories.add(categoryNode.getDocument().getTextContent());
}
Log.d(TAG, "Found categories from Prefix search, waiting for filter");
Timber.d("Found categories from Prefix search, waiting for filter");
ArrayList<String> filteredItems = new ArrayList<>(filterYears(categories));
return filteredItems;
}

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.category;
import android.os.AsyncTask;
import android.util.Log;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
@ -10,6 +9,7 @@ import java.io.IOException;
import java.util.ArrayList;
import fr.free.nrw.commons.CommonsApplication;
import timber.log.Timber;
/**
* Sends asynchronous queries to the Commons MediaWiki API to retrieve categories that are related to
@ -19,7 +19,7 @@ import fr.free.nrw.commons.CommonsApplication;
public class TitleCategories extends AsyncTask<Void, Void, ArrayList<String>> {
private final static int SEARCH_CATS_LIMIT = 25;
private static final String TAG = TitleCategories.class.getName();
private String title;
public TitleCategories(String title) {
@ -48,9 +48,9 @@ public class TitleCategories extends AsyncTask<Void, Void, ArrayList<String>> {
.param("srlimit", SEARCH_CATS_LIMIT)
.param("srsearch", title)
.get();
Log.d(TAG, "Searching for cats for title: " + result.toString());
Timber.d("Searching for cats for title: %s", result);
} catch (IOException e) {
Log.e(TAG, "IO Exception: ", e);
Timber.e(e, "IO Exception: ");
//Return empty arraylist
return items;
}
@ -62,7 +62,7 @@ public class TitleCategories extends AsyncTask<Void, Void, ArrayList<String>> {
items.add(catString);
}
Log.d(TAG, "Title cat query results: " + items);
Timber.d("Title cat query results: %s", items);
return items;
}

View file

@ -44,8 +44,6 @@ public class Contribution extends Media {
public static final String SOURCE_GALLERY = "gallery";
public static final String SOURCE_EXTERNAL = "external";
private static final String TAG = "Contribution";
private ContentProviderClient client;
private Uri contentUri;
private String source;

View file

@ -7,7 +7,6 @@ import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.support.v4.app.Fragment;
import android.util.Log;
import java.io.File;
import java.io.IOException;
@ -15,6 +14,7 @@ import java.util.Date;
import fr.free.nrw.commons.upload.ShareActivity;
import fr.free.nrw.commons.upload.UploadService;
import timber.log.Timber;
public class ContributionController {
private Fragment fragment;
@ -44,7 +44,7 @@ public class ContributionController {
}
} catch (IOException e) {
Log.e("Commons", "Could not create file: " + path, e);
Timber.e(e, "Could not create file: %s", path);
}
return Uri.fromFile(_photoFile);
@ -84,11 +84,11 @@ public class ContributionController {
shareIntent.putExtra(UploadService.EXTRA_SOURCE, Contribution.SOURCE_CAMERA);
break;
}
Log.i("Image", "Image selected");
Timber.i("Image selected");
try {
activity.startActivity(shareIntent);
} catch (SecurityException e) {
Log.e("ContributionController", "Security Exception", e);
Timber.e(e, "Security Exception");
}
}

View file

@ -14,7 +14,6 @@ import android.support.v4.app.LoaderManager;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.support.v4.widget.CursorAdapter;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
@ -22,7 +21,6 @@ import android.widget.Adapter;
import android.widget.AdapterView;
import java.util.ArrayList;
import java.util.Objects;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.HandlerService;
@ -32,6 +30,7 @@ import fr.free.nrw.commons.auth.AuthenticatedActivity;
import fr.free.nrw.commons.auth.WikiAccountAuthenticator;
import fr.free.nrw.commons.media.MediaDetailPagerFragment;
import fr.free.nrw.commons.upload.UploadService;
import timber.log.Timber;
public class ContributionsActivity
extends AuthenticatedActivity
@ -158,9 +157,9 @@ public class ContributionsActivity
Contribution c = Contribution.fromCursor(allContributions);
if(c.getState() == Contribution.STATE_FAILED) {
uploadService.queue(UploadService.ACTION_UPLOAD_FILE, c);
Log.d("Commons", "Restarting for" + c.toContentValues().toString());
Timber.d("Restarting for %s", c.toContentValues());
} else {
Log.d("Commons", "Skipping re-upload for non-failed " + c.toContentValues().toString());
Timber.d("Skipping re-upload for non-failed %s", c.toContentValues());
}
}
@ -168,11 +167,11 @@ public class ContributionsActivity
allContributions.moveToPosition(i);
Contribution c = Contribution.fromCursor(allContributions);
if(c.getState() == Contribution.STATE_FAILED) {
Log.d("Commons", "Deleting failed contrib " + c.toContentValues().toString());
Timber.d("Deleting failed contrib %s", c.toContentValues());
c.setContentProviderClient(getContentResolver().acquireContentProviderClient(ContributionsContentProvider.AUTHORITY));
c.delete();
} else {
Log.d("Commons", "Skipping deletion for non-failed contrib " + c.toContentValues().toString());
Timber.d("Skipping deletion for non-failed contrib %s", c.toContentValues());
}
}

View file

@ -8,9 +8,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import fr.free.nrw.commons.data.DBOpenHelper;
import timber.log.Timber;
public class ContributionsContentProvider extends ContentProvider{
@ -102,7 +102,7 @@ public class ContributionsContentProvider extends ContentProvider{
switch(uriType) {
case CONTRIBUTIONS_ID:
Log.d("Commons", "Deleting contribution id " + uri.getLastPathSegment());
Timber.d("Deleting contribution id %s", uri.getLastPathSegment());
rows = db.delete(Contribution.Table.TABLE_NAME,
"_id = ?",
new String[] { uri.getLastPathSegment() }
@ -117,14 +117,14 @@ public class ContributionsContentProvider extends ContentProvider{
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
Log.d("Commons", "Hello, bulk insert! (ContributionsContentProvider)");
Timber.d("Hello, bulk insert! (ContributionsContentProvider)");
int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
sqlDB.beginTransaction();
switch (uriType) {
case CONTRIBUTIONS:
for(ContentValues value: values) {
Log.d("Commons", "Inserting! " + value.toString());
Timber.d("Inserting! %s", value);
sqlDB.insert(Contribution.Table.TABLE_NAME, null, value);
}
break;

View file

@ -10,7 +10,6 @@ import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -29,8 +28,9 @@ import fr.free.nrw.commons.AboutActivity;
import fr.free.nrw.commons.BuildConfig;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.settings.SettingsActivity;
import fr.free.nrw.commons.nearby.NearbyActivity;
import fr.free.nrw.commons.settings.SettingsActivity;
import timber.log.Timber;
import static android.app.Activity.RESULT_OK;
@ -45,7 +45,6 @@ public class ContributionsListFragment extends Fragment {
@BindView(R.id.emptyMessage) TextView emptyMessage;
private ContributionController controller;
private static final String TAG = "ContributionsList";
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -54,14 +53,14 @@ public class ContributionsListFragment extends Fragment {
contributionsList.setOnItemClickListener((AdapterView.OnItemClickListener)getActivity());
if(savedInstanceState != null) {
Log.d(TAG, "Scrolling to " + savedInstanceState.getInt("grid-position"));
Timber.d("Scrolling to %d", savedInstanceState.getInt("grid-position"));
contributionsList.setSelection(savedInstanceState.getInt("grid-position"));
}
//TODO: Should this be in onResume?
SharedPreferences prefs = this.getActivity().getSharedPreferences("prefs", Context.MODE_PRIVATE);
String lastModified = prefs.getString("lastSyncTimestamp", "");
Log.d(TAG, "Last Sync Timestamp: " + lastModified);
Timber.d("Last Sync Timestamp: %s", lastModified);
if (lastModified.equals("")) {
waitingMessage.setVisibility(View.VISIBLE);
@ -96,10 +95,12 @@ public class ContributionsListFragment extends Fragment {
super.onActivityResult(requestCode, resultCode, data);
if ( resultCode == RESULT_OK ) {
Log.d("Contributions", "OnActivityResult() parameters: Req code: " + requestCode + " Result code: " + resultCode + " Data: " + data);
Timber.d("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
controller.handleImagePicked(requestCode, data);
} else {
Log.e("Contributions", "OnActivityResult() parameters: Req code: " + requestCode + " Result code: " + resultCode + " Data: " + data);
Timber.e("OnActivityResult() parameters: Req code: %d Result code: %d Data: %s",
requestCode, resultCode, data);
}
}
@ -176,7 +177,7 @@ public class ContributionsListFragment extends Fragment {
// 1 = Storage allowed when gallery selected
case 1: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("ContributionsList", "Call controller.startGalleryPick()");
Timber.d("Call controller.startGalleryPick()");
controller.startGalleryPick();
}
}
@ -184,7 +185,7 @@ public class ContributionsListFragment extends Fragment {
// 2 = Location allowed when 'nearby places' selected
case 2: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Log.d("ContributionsList", "Location permission granted");
Timber.d("Location permission granted");
Intent nearbyIntent = new Intent(getActivity(), NearbyActivity.class);
startActivity(nearbyIntent);
}

View file

@ -11,7 +11,6 @@ import android.database.Cursor;
import android.os.Bundle;
import android.os.RemoteException;
import android.text.TextUtils;
import android.util.Log;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
@ -22,6 +21,7 @@ import java.util.Date;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Utils;
import timber.log.Timber;
public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
private static int COMMIT_THRESHOLD = 10;
@ -85,18 +85,18 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
// There isn't really much we can do, eh?
// FIXME: Perhaps add EventLogging?
syncResult.stats.numIoExceptions += 1; // Not sure if this does anything. Shitty docs
Log.d("Commons", "Syncing failed due to " + e.toString());
Timber.d("Syncing failed due to %s", e);
return;
}
Log.d("Commons", "Last modified at " + lastModified);
Timber.d("Last modified at %s", lastModified);
ArrayList<ApiResult> uploads = result.getNodes("/api/query/logevents/item");
Log.d("Commons", uploads.size() + " results!");
Timber.d("%d results!", uploads.size());
ArrayList<ContentValues> imageValues = new ArrayList<>();
for(ApiResult image: uploads) {
String filename = image.getString("@title");
if(fileExists(contentProviderClient, filename)) {
Log.d("Commons", "Skipping " + filename);
Timber.d("Skipping %s", filename);
continue;
}
String thumbUrl = Utils.makeThumbBaseUrl(filename);
@ -128,6 +128,6 @@ public class ContributionsSyncAdapter extends AbstractThreadedSyncAdapter {
}
}
prefs.edit().putString("lastSyncTimestamp", Utils.toMWDate(curTime)).apply();
Log.d("Commons", "Oh hai, everyone! Look, a kitty!");
Timber.d("Oh hai, everyone! Look, a kitty!");
}
}

View file

@ -6,10 +6,11 @@ import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import timber.log.Timber;
public class LocationServiceManager implements LocationListener {
public static final String TAG = "LocationServiceManager";
private String provider;
private LocationManager locationManager;
private LatLng latestLocation;
@ -31,14 +32,14 @@ public class LocationServiceManager implements LocationListener {
Location location = locationManager.getLastKnownLocation(provider);
//Location works, just need to 'send' GPS coords
// via emulator extended controls if testing on emulator
Log.d(TAG, "Checking for location...");
Timber.d("Checking for location...");
if (location != null) {
this.onLocationChanged(location);
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "Illegal argument exception", e);
Timber.e(e, "Illegal argument exception");
} catch (SecurityException e) {
Log.e(TAG, "Security exception", e);
Timber.e(e, "Security exception");
}
}
@ -48,7 +49,7 @@ public class LocationServiceManager implements LocationListener {
try {
locationManager.removeUpdates(this);
} catch (SecurityException e) {
Log.e(TAG, "Security exception", e);
Timber.e(e, "Security exception");
}
}
@ -56,24 +57,23 @@ public class LocationServiceManager implements LocationListener {
public void onLocationChanged(Location location) {
double currentLatitude = location.getLatitude();
double currentLongitude = location.getLongitude();
Log.d(TAG, "Latitude: " + String.valueOf(currentLatitude)
+ " Longitude: " + String.valueOf(currentLongitude));
Timber.d("Latitude: %f Longitude: %f", currentLatitude, currentLongitude);
latestLocation = new LatLng(currentLatitude, currentLongitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, provider + "'s status changed to " + status);
Timber.d("%s's status changed to %d", provider, status);
}
@Override
public void onProviderEnabled(String provider) {
Log.d(TAG, "Provider " + provider + " enabled");
Timber.d("Provider %s enabled", provider);
}
@Override
public void onProviderDisabled(String provider) {
Log.d(TAG, "Provider " + provider + " disabled");
Timber.d("Provider %s disabled", provider);
}
}

View file

@ -6,7 +6,6 @@ import android.graphics.Bitmap;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@ -34,6 +33,7 @@ import fr.free.nrw.commons.MediaDataExtractor;
import fr.free.nrw.commons.MediaWikiImageView;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import timber.log.Timber;
public class MediaDetailFragment extends Fragment {
@ -130,11 +130,11 @@ public class MediaDetailFragment extends Fragment {
Media media = detailProvider.getMediaAtPosition(index);
if (media == null) {
// Ask the detail provider to ping us when we're ready
Log.d("Commons", "MediaDetailFragment not yet ready to display details; registering observer");
Timber.d("MediaDetailFragment not yet ready to display details; registering observer");
dataObserver = new DataSetObserver() {
@Override
public void onChanged() {
Log.d("Commons", "MediaDetailFragment ready to display delayed details!");
Timber.d("MediaDetailFragment ready to display delayed details!");
detailProvider.unregisterDataSetObserver(dataObserver);
dataObserver = null;
displayMediaDetails(detailProvider.getMediaAtPosition(index));
@ -142,7 +142,7 @@ public class MediaDetailFragment extends Fragment {
};
detailProvider.registerDataSetObserver(dataObserver);
} else {
Log.d("Commons", "MediaDetailFragment ready to display details");
Timber.d("MediaDetailFragment ready to display details");
displayMediaDetails(media);
}
@ -186,7 +186,7 @@ public class MediaDetailFragment extends Fragment {
//Always load image from Internet to allow viewing the desc, license, and cats
String actualUrl = media.getThumbnailUrl(640);
if(actualUrl.startsWith("http")) {
Log.d("Volley", "Actual URL starts with http and is: " + actualUrl);
Timber.d("Actual URL starts with http and is: %s", actualUrl);
ImageLoader loader = ((CommonsApplication)getActivity().getApplicationContext()).getImageLoader();
MediaWikiImageView mwImage = (MediaWikiImageView)image;
@ -238,7 +238,7 @@ public class MediaDetailFragment extends Fragment {
}
rebuildCatList();
} else {
Log.d("Commons", "Failed to load photo details.");
Timber.d("Failed to load photo details.");
}
}
};
@ -246,7 +246,7 @@ public class MediaDetailFragment extends Fragment {
} else {
//This should not usually happen, image along with associated details should always be loaded from Internet, but keeping this for now for backup.
//Even if image is loaded from device storage, it will display, albeit with empty desc and cat.
Log.d("Volley", "Actual URL does not start with http and is: " + actualUrl);
Timber.d("Actual URL does not start with http and is: %s", actualUrl);
com.nostra13.universalimageloader.core.ImageLoader.getInstance().displayImage(actualUrl, image, displayOptions, new ImageLoadingListener() {
@Override
public void onLoadingStarted(String s, View view) {
@ -286,7 +286,7 @@ public class MediaDetailFragment extends Fragment {
@Override
public void onLoadingCancelled(String s, View view) {
Log.e("Volley", "Image loading cancelled. But why?");
Timber.e("Image loading cancelled. But why?");
}
});
}
@ -377,7 +377,7 @@ public class MediaDetailFragment extends Fragment {
private String prettyLicense(Media media) {
String licenseKey = media.getLicense();
Log.d("Commons", "Media license is: " + licenseKey);
Timber.d("Media license is: %s", licenseKey);
if (licenseKey == null || licenseKey.equals("")) {
return getString(R.string.detail_license_empty);
}

View file

@ -8,9 +8,9 @@ import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteQueryBuilder;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;
import fr.free.nrw.commons.data.DBOpenHelper;
import timber.log.Timber;
public class ModificationsContentProvider extends ContentProvider{
@ -101,14 +101,14 @@ public class ModificationsContentProvider extends ContentProvider{
@Override
public int bulkInsert(Uri uri, ContentValues[] values) {
Log.d("Commons", "Hello, bulk insert! (ModificationsContentProvider)");
Timber.d("Hello, bulk insert! (ModificationsContentProvider)");
int uriType = uriMatcher.match(uri);
SQLiteDatabase sqlDB = dbOpenHelper.getWritableDatabase();
sqlDB.beginTransaction();
switch (uriType) {
case MODIFICATIONS:
for(ContentValues value: values) {
Log.d("Commons", "Inserting! " + value.toString());
Timber.d("Inserting! %s", value);
sqlDB.insert(ModifierSequence.Table.TABLE_NAME, null, value);
}
break;

View file

@ -11,7 +11,6 @@ import android.content.SyncResult;
import android.database.Cursor;
import android.os.Bundle;
import android.os.RemoteException;
import android.util.Log;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
@ -22,6 +21,7 @@ import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.contributions.Contribution;
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
import timber.log.Timber;
public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
@ -42,7 +42,7 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
// Exit early if nothing to do
if(allModifications == null || allModifications.getCount() == 0) {
Log.d("Commons", "No modifications to perform");
Timber.d("No modifications to perform");
return;
}
@ -52,12 +52,12 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
} catch (OperationCanceledException | AuthenticatorException e) {
throw new RuntimeException(e);
} catch (IOException e) {
Log.d("Commons", "Could not authenticate :(");
Timber.d("Could not authenticate :(");
return;
}
if(Utils.isNullOrWhiteSpace(authCookie)) {
Log.d("Commons", "Could not authenticate :(");
Timber.d("Could not authenticate :(");
return;
}
@ -69,13 +69,13 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
try {
editToken = api.getEditToken();
} catch (IOException e) {
Log.d("Commons", "Can not retreive edit token!");
Timber.d("Can not retreive edit token!");
return;
}
allModifications.moveToFirst();
Log.d("Commons", "Found " + allModifications.getCount() + " modifications to execute");
Timber.d("Found %d modifications to execute", allModifications.getCount());
ContentProviderClient contributionsClient = null;
try {
@ -104,11 +104,11 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
.param("titles", contrib.getFilename())
.get();
} catch (IOException e) {
Log.d("Commons", "Network fuckup on modifications sync!");
Timber.d("Network fuckup on modifications sync!");
continue;
}
Log.d("Commons", "Page content is " + Utils.getStringFromDOM(requestResult.getDocument()));
Timber.d("Page content is %s", Utils.getStringFromDOM(requestResult.getDocument()));
String pageContent = requestResult.getString("/api/query/pages/page/revisions/rev");
String processedPageContent = sequence.executeModifications(contrib.getFilename(), pageContent);
@ -120,16 +120,16 @@ public class ModificationsSyncAdapter extends AbstractThreadedSyncAdapter {
.param("summary", sequence.getEditSummary())
.post();
} catch (IOException e) {
Log.d("Commons", "Network fuckup on modifications sync!");
Timber.d("Network fuckup on modifications sync!");
continue;
}
Log.d("Commons", "Response is" + Utils.getStringFromDOM(responseResult.getDocument()));
Timber.d("Response is %s", Utils.getStringFromDOM(responseResult.getDocument()));
String result = responseResult.getString("/api/edit/@result");
if(!result.equals("Success")) {
// FIXME: Log this somewhere else
Log.d("Commons", "Non success result!" + result);
Timber.d("Non success result! %s", result);
} else {
sequence.delete();
}

View file

@ -14,8 +14,6 @@ public class NearbyActivity extends BaseActivity {
private LocationServiceManager locationManager;
private static final String TAG = NearbyActivity.class.getName();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

View file

@ -1,7 +1,6 @@
package fr.free.nrw.commons.nearby;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -11,6 +10,8 @@ import fr.free.nrw.commons.R;
import java.util.List;
import timber.log.Timber;
public class NearbyAdapter extends ArrayAdapter<Place> {
private List<Place> placesList;
private Context context;
@ -33,7 +34,7 @@ public class NearbyAdapter extends ArrayAdapter<Place> {
public View getView(int position, View convertView, ViewGroup parent) {
// Get the data item for this position
Place place = getItem(position);
Log.v("NearbyAdapter", "" + place);
Timber.v(String.valueOf(place));
// Check if an existing view is being reused, otherwise inflate the view
if (convertView == null) {

View file

@ -10,7 +10,6 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -22,6 +21,7 @@ import butterknife.ButterKnife;
import butterknife.OnItemClick;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.location.LatLng;
import timber.log.Timber;
import java.util.Collections;
import java.util.Comparator;
@ -40,8 +40,6 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
private boolean isTaskRunning = false;
private static final String TAG = NearbyListFragment.class.getName();
public NearbyListFragment() {
}
@ -55,7 +53,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.d(TAG, "NearbyListFragment created");
Timber.d("NearbyListFragment created");
View view = inflater.inflate(R.layout.fragment_nearby, container, false);
ButterKnife.bind(this, view);
return view;
@ -69,7 +67,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
nearbyAsyncTask = new NearbyAsyncTask(this);
nearbyAsyncTask.execute();
progressBar.setVisibility(View.VISIBLE);
Log.d(TAG, "Saved instance state is null, populating ListView");
Timber.d("Saved instance state is null, populating ListView");
} else {
progressBar.setVisibility(View.GONE);
}
@ -174,10 +172,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
double latitude = placeLatLng.latitude;
double longitude = placeLatLng.longitude;
Log.d(TAG, "Item at position "
+ position + " has coords: Lat: "
+ latitude + " Long: "
+ longitude);
Timber.d("Item at position %d has coords: Lat: %f Long: %f", position, latitude, longitude);
//Open map app at given position
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + latitude + "," + longitude);
@ -189,7 +184,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
}
private List<Place> loadAttractionsFromLocation(LatLng curLatLng) {
Log.d(TAG, "Loading attractions near " + curLatLng);
Timber.d("Loading attractions near %s", curLatLng);
if (curLatLng == null) {
return Collections.emptyList();
}
@ -199,7 +194,7 @@ public class NearbyListFragment extends ListFragment implements TaskListener {
curLatLng, Locale.getDefault().getLanguage())
: NearbyPlaces.getInstance().getFromWikiNeedsPictures();
if (curLatLng != null) {
Log.d(TAG, "Sorting places by distance...");
Timber.d("Sorting places by distance...");
final Map<Place, Double> distances = new HashMap<>();
for (Place place: places) {
distances.put(place, computeDistanceBetween(place.location, curLatLng));

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.nearby;
import android.net.Uri;
import android.os.StrictMode;
import android.util.Log;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.location.LatLng;
@ -20,10 +19,10 @@ import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import timber.log.Timber;
public class NearbyPlaces {
private static final String TAG = NearbyPlaces.class.getName();
private static final int MIN_RESULTS = 40;
private static final double INITIAL_RADIUS = 1.0;
private static final double MAX_RADIUS = 300.0;
@ -81,7 +80,7 @@ public class NearbyPlaces {
// increase the radius gradually to find a satisfactory number of nearby places
while (radius < MAX_RADIUS) {
places = getFromWikidataQuery(curLatLng, lang, radius);
Log.d(TAG, places.size() + " results at radius: " + radius);
Timber.d("%d results at radius: %f", places.size(), radius);
if (places.size() >= MIN_RESULTS) {
break;
} else {
@ -89,10 +88,10 @@ public class NearbyPlaces {
}
}
} catch (IOException e) {
Log.d(TAG, "" + e.toString());
Timber.d(e.toString());
// errors tend to be caused by too many results (and time out)
// try a small radius next time
Log.d(TAG, "back to initial radius: " + radius);
Timber.d("back to initial radius: %f", radius);
radius = INITIAL_RADIUS;
}
return places;
@ -107,15 +106,15 @@ public class NearbyPlaces {
.replace("${LANG}", "" + lang);
query = URLEncoder.encode(query, "utf-8").replace("+", "%20");
String url = WIKIDATA_QUERY_URL.replace("${QUERY}", query);
Log.d(TAG, url);
Timber.d(url);
URLConnection conn = new URL(url).openConnection();
conn.setRequestProperty("Accept", "text/tab-separated-values");
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
Log.d(TAG, "Reading from query result...");
Timber.d("Reading from query result...");
while ((line = in.readLine()) != null) {
Log.v(TAG, line);
Timber.v(line);
line = line + "\n"; // to pad columns and make fields a fixed size
if (!line.startsWith("\"Point")) {
continue;
@ -170,7 +169,7 @@ public class NearbyPlaces {
boolean firstLine = true;
String line;
Log.d(TAG, "Reading from CSV file...");
Timber.d("Reading from CSV file...");
while ((line = in.readLine()) != null) {
@ -209,7 +208,7 @@ public class NearbyPlaces {
in.close();
} catch (IOException e) {
Log.d(TAG, e.toString());
Timber.d(e.toString());
}
}
return places;

View file

@ -4,7 +4,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.AsyncTask;
import android.util.Log;
import android.support.v7.app.AlertDialog;
import org.mediawiki.api.ApiResult;
import org.mediawiki.api.MWApi;
@ -12,11 +12,10 @@ import org.mediawiki.api.MWApi;
import java.io.IOException;
import java.util.ArrayList;
import android.support.v7.app.AlertDialog;
import fr.free.nrw.commons.CommonsApplication;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.contributions.ContributionsActivity;
import timber.log.Timber;
/**
* Sends asynchronous queries to the Commons MediaWiki API to check that file doesn't already exist
@ -24,8 +23,6 @@ import fr.free.nrw.commons.contributions.ContributionsActivity;
*/
public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
private static final String TAG = ExistingFileAsync.class.getName();
private String fileSHA1;
private Context context;
@ -51,14 +48,14 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
.param("list", "allimages")
.param("aisha1", fileSHA1)
.get();
Log.d(TAG, "Searching Commons API for existing file: " + result.toString());
Timber.d("Searching Commons API for existing file: %s", result);
} catch (IOException e) {
Log.e(TAG, "IO Exception: ", e);
Timber.e(e, "IO Exception: ");
return false;
}
ArrayList<ApiResult> resultNodes = result.getNodes("/api/query/allimages/img");
Log.d(TAG, "Result nodes: " + resultNodes);
Timber.d("Result nodes: %s", resultNodes);
boolean fileExists;
if (!resultNodes.isEmpty()) {
@ -67,7 +64,7 @@ public class ExistingFileAsync extends AsyncTask<Void, Void, Boolean> {
fileExists = false;
}
Log.d(TAG, "File already exists in Commons:" + fileExists);
Timber.d("File already exists in Commons: %s", fileExists);
return fileExists;
}

View file

@ -10,10 +10,11 @@ import android.media.ExifInterface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
import android.util.Log;
import java.io.IOException;
import timber.log.Timber;
/**
* Extracts geolocation to be passed to API for category suggestions. If a picture with geolocation
* is uploaded, extract latitude and longitude from EXIF data of image. If a picture without
@ -21,8 +22,6 @@ import java.io.IOException;
*/
public class GPSExtractor {
private static final String TAG = GPSExtractor.class.getName();
private String filePath;
private double decLatitude, decLongitude;
private Double currentLatitude = null;
@ -46,7 +45,7 @@ public class GPSExtractor {
private boolean gpsPreferenceEnabled() {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
boolean gpsPref = sharedPref.getBoolean("allowGps", false);
Log.d(TAG, "Gps pref set to: " + gpsPref);
Timber.d("Gps pref set to: %b", gpsPref);
return gpsPref;
}
@ -66,9 +65,9 @@ public class GPSExtractor {
myLocationListener.onLocationChanged(location);
}
} catch (IllegalArgumentException e) {
Log.e(TAG, "Illegal argument exception", e);
Timber.e(e, "Illegal argument exception");
} catch (SecurityException e) {
Log.e(TAG, "Security exception", e);
Timber.e(e, "Security exception");
}
}
@ -76,7 +75,7 @@ public class GPSExtractor {
try {
locationManager.removeUpdates(myLocationListener);
} catch (SecurityException e) {
Log.e(TAG, "Security exception", e);
Timber.e(e, "Security exception");
}
}
@ -98,10 +97,10 @@ public class GPSExtractor {
try {
exif = new ExifInterface(filePath);
} catch (IOException e) {
Log.w(TAG, e);
Timber.w(e);
return null;
} catch (IllegalArgumentException e) {
Log.w(TAG, e);
Timber.w(e);
return null;
}
@ -110,14 +109,15 @@ public class GPSExtractor {
registerLocationManager();
imageCoordsExists = false;
Log.d(TAG, "EXIF data has no location info");
Timber.d("EXIF data has no location info");
//Check what user's preference is for automatic location detection
boolean gpsPrefEnabled = gpsPreferenceEnabled();
//Check that currentLatitude and currentLongitude have been explicitly set by MyLocationListener and do not default to (0.0,0.0)
if (gpsPrefEnabled && currentLatitude != null && currentLongitude != null) {
Log.d(TAG, "Current location values: Lat = " + currentLatitude + " Long = " + currentLongitude);
Timber.d("Current location values: Lat = %f Long = %f",
currentLatitude, currentLongitude);
return String.valueOf(currentLatitude) + "|" + String.valueOf(currentLongitude);
} else {
// No coords found
@ -128,7 +128,7 @@ public class GPSExtractor {
} else {
//If image has EXIF data, extract image coords
imageCoordsExists = true;
Log.d(TAG, "EXIF data has location info");
Timber.d("EXIF data has location info");
latitude = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE);
latitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE_REF);
@ -136,8 +136,8 @@ public class GPSExtractor {
longitude_ref = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF);
if (latitude!=null && latitude_ref!=null && longitude!=null && longitude_ref!=null) {
Log.d(TAG, "Latitude: " + latitude + " " + latitude_ref);
Log.d(TAG, "Longitude: " + longitude + " " + longitude_ref);
Timber.d("Latitude: %s %s", latitude, latitude_ref);
Timber.d("Longitude: %s %s", longitude, longitude_ref);
decimalCoords = getDecimalCoords(latitude, latitude_ref, longitude, longitude_ref);
return decimalCoords;
@ -160,17 +160,17 @@ public class GPSExtractor {
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Log.d(TAG, provider + "'s status changed to " + status);
Timber.d("%s's status changed to %d", provider, status);
}
@Override
public void onProviderEnabled(String provider) {
Log.d(TAG, "Provider " + provider + " enabled");
Timber.d("Provider %s enabled", provider);
}
@Override
public void onProviderDisabled(String provider) {
Log.d(TAG, "Provider " + provider + " disabled");
Timber.d("Provider %s disabled", provider);
}
}
@ -201,7 +201,7 @@ public class GPSExtractor {
}
String decimalCoords = String.valueOf(decLatitude) + "|" + String.valueOf(decLongitude);
Log.d(TAG, "Latitude and Longitude are " + decimalCoords);
Timber.d("Latitude and Longitude are %s", decimalCoords);
return decimalCoords;
}

View file

@ -14,7 +14,6 @@ import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
@ -36,6 +35,7 @@ import fr.free.nrw.commons.modifications.CategoryModifier;
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import fr.free.nrw.commons.modifications.ModifierSequence;
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
import timber.log.Timber;
public class MultipleShareActivity
extends AuthenticatedActivity
@ -116,7 +116,7 @@ public class MultipleShareActivity
private void multipleUploadBegins() {
Log.d("MultipleShareActivity", "Multiple upload begins");
Timber.d("Multiple upload begins");
final ProgressDialog dialog = new ProgressDialog(MultipleShareActivity.this);
dialog.setIndeterminate(false);

View file

@ -2,7 +2,6 @@ package fr.free.nrw.commons.upload;
import android.content.Context;
import android.net.Uri;
import android.util.Log;
import com.android.volley.Cache;
import com.android.volley.NetworkResponse;
@ -22,6 +21,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import timber.log.Timber;
/**
* Uses the Volley library to implement asynchronous calls to the Commons MediaWiki API to match
* GPS coordinates with nearby Commons categories. Parses the results using GSON to obtain a list
@ -38,7 +39,6 @@ public class MwVolleyApi {
private static List<String> categoryList;
private static final String MWURL = "https://commons.wikimedia.org/";
private static final String TAG = MwVolleyApi.class.getName();
public MwVolleyApi(Context context) {
this.context = context;
@ -52,13 +52,13 @@ public class MwVolleyApi {
public static void setGpsCat(List<String> cachedList) {
categoryList = new ArrayList<>();
categoryList.addAll(cachedList);
Log.d(TAG, "Setting GPS cats from cache: " + categoryList.toString());
Timber.d("Setting GPS cats from cache: %s", categoryList);
}
public void request(String coords) {
coordsLog = coords;
String apiUrl = buildUrl(coords);
Log.d(TAG, "URL: " + apiUrl);
Timber.d("URL: %s", apiUrl);
JsonRequest<QueryResponse> request = new QueryRequest(apiUrl,
new LogResponseListener<QueryResponse>(), new LogResponseErrorListener());
@ -110,7 +110,7 @@ public class MwVolleyApi {
@Override
public void onResponse(T response) {
Log.d(TAG, response.toString());
Timber.d(response.toString());
}
}
@ -118,12 +118,11 @@ public class MwVolleyApi {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, error.toString());
Timber.e(error.toString());
}
}
private static class QueryRequest extends JsonRequest<QueryResponse> {
private static final String TAG = QueryRequest.class.getName();
public QueryRequest(String url,
Response.Listener<QueryResponse> listener,
@ -169,11 +168,11 @@ public class MwVolleyApi {
private String printSet() {
if (categorySet == null || categorySet.isEmpty()) {
GpsCatExists.setGpsCatExists(false);
Log.d(TAG, "gpsCatExists=" + GpsCatExists.getGpsCatExists());
Timber.d("gpsCatExists=%b", GpsCatExists.getGpsCatExists());
return "No collection of categories";
} else {
GpsCatExists.setGpsCatExists(true);
Log.d(TAG, "gpsCatExists=" + GpsCatExists.getGpsCatExists());
Timber.d("gpsCatExists=%b", GpsCatExists.getGpsCatExists());
return "CATEGORIES FOUND" + categorySet.toString();
}

View file

@ -12,7 +12,6 @@ import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.NavUtils;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
@ -38,6 +37,7 @@ import fr.free.nrw.commons.modifications.CategoryModifier;
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import fr.free.nrw.commons.modifications.ModifierSequence;
import fr.free.nrw.commons.modifications.TemplateRemoveModifier;
import timber.log.Timber;
/**
* Activity for the title/desc screen after image is selected. Also starts processing image
@ -48,8 +48,6 @@ public class ShareActivity
implements SingleUploadFragment.OnUploadActionInitiated,
CategorizationFragment.OnCategoriesSaveHandler {
private static final String TAG = ShareActivity.class.getName();
private SingleUploadFragment shareView;
private CategorizationFragment categorizationFragment;
@ -118,7 +116,7 @@ public class ShareActivity
if (cacheFound == false) {
//Has to be called after apiCall.request()
app.cacheData.cacheCategory();
Log.d(TAG, "Cache the categories found");
Timber.d("Cache the categories found");
}
uploadController.startUpload(title, mediaUri, description, mimeType, source, decimalCoords, new UploadController.ContributionUploadProgress() {
@ -245,15 +243,15 @@ public class ShareActivity
//Test SHA1 of image to see if it matches SHA1 of a file on Commons
try {
InputStream inputStream = getContentResolver().openInputStream(mediaUri);
Log.d(TAG, "Input stream created from " + mediaUriString);
Timber.d("Input stream created from %s", mediaUriString);
String fileSHA1 = Utils.getSHA1(inputStream);
Log.d(TAG, "File SHA1 is: " + fileSHA1);
Timber.d("File SHA1 is: %s", fileSHA1);
ExistingFileAsync fileAsyncTask = new ExistingFileAsync(fileSHA1, this);
fileAsyncTask.execute();
} catch (IOException e) {
Log.d(TAG, "IO Exception: ", e);
Timber.d(e, "IO Exception: ");
}
}
@ -263,8 +261,8 @@ public class ShareActivity
requestAuthToken();
Log.d(TAG, "Uri: " + mediaUriString);
Log.d(TAG, "Ext storage dir: " + Environment.getExternalStorageDirectory());
Timber.d("Uri: %s", mediaUriString);
Timber.d("Ext storage dir: %s", Environment.getExternalStorageDirectory());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
useNewPermissions = true;
@ -378,8 +376,8 @@ public class ShareActivity
*/
public void getFileMetadata(boolean gpsEnabled) {
filePath = FileUtils.getPath(this, mediaUri);
Log.d(TAG, "Filepath: " + filePath);
Log.d(TAG, "Calling GPSExtractor");
Timber.d("Filepath: %s", filePath);
Timber.d("Calling GPSExtractor");
if(imageObj == null) {
imageObj = new GPSExtractor(filePath, this);
}
@ -397,7 +395,7 @@ public class ShareActivity
*/
public void useImageCoords() {
if(decimalCoords != null) {
Log.d(TAG, "Decimal coords of image: " + decimalCoords);
Timber.d("Decimal coords of image: %s", decimalCoords);
// Only set cache for this point if image has coords
if (imageObj.imageCoordsExists) {
@ -415,10 +413,10 @@ public class ShareActivity
if (catListEmpty) {
cacheFound = false;
apiCall.request(decimalCoords);
Log.d(TAG, "displayCatList size 0, calling MWAPI" + displayCatList.toString());
Timber.d("displayCatList size 0, calling MWAPI %s", displayCatList);
} else {
cacheFound = true;
Log.d(TAG, "Cache found, setting categoryList in MwVolleyApi to " + displayCatList.toString());
Timber.d("Cache found, setting categoryList in MwVolleyApi to %s", displayCatList);
MwVolleyApi.setGpsCat(displayCatList);
}
}
@ -429,10 +427,10 @@ public class ShareActivity
super.onPause();
try {
imageObj.unregisterLocationManager();
Log.d(TAG, "Unregistered locationManager");
Timber.d("Unregistered locationManager");
}
catch (NullPointerException e) {
Log.d(TAG, "locationManager does not exist, not unregistered");
Timber.d("locationManager does not exist, not unregistered");
}
}

View file

@ -11,7 +11,6 @@ import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -37,6 +36,7 @@ import butterknife.OnTouch;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.R;
import fr.free.nrw.commons.Utils;
import timber.log.Timber;
public class SingleUploadFragment extends Fragment {
private SharedPreferences prefs;
@ -54,8 +54,6 @@ public class SingleUploadFragment extends Fragment {
private OnUploadActionInitiated uploadActionInitiatedHandler;
private static final String TAG = SingleUploadFragment.class.getName();
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.activity_share, menu);
@ -103,7 +101,7 @@ public class SingleUploadFragment extends Fragment {
prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
license = prefs.getString(Prefs.DEFAULT_LICENSE, Prefs.Licenses.CC_BY_SA_3);
Log.d("Single Upload fragment", license);
Timber.d(license);
ArrayAdapter<String> adapter;
if (PreferenceManager.getDefaultSharedPreferences(getActivity()).getBoolean("theme",true)) {
@ -117,7 +115,7 @@ public class SingleUploadFragment extends Fragment {
licenseSpinner.setAdapter(adapter);
int position = licenseItems.indexOf(getString(Utils.licenseNameFor(license)));
Log.d("Single Upload fragment", "Position:"+position+" "+getString(Utils.licenseNameFor(license)));
Timber.d("Position: %d %s", position, getString(Utils.licenseNameFor(license)));
licenseSpinner.setSelection(position);
TextWatcher uploadEnabler = new TextWatcher() {
@ -190,7 +188,7 @@ public class SingleUploadFragment extends Fragment {
SharedPreferences titleDesc = PreferenceManager.getDefaultSharedPreferences(getActivity());
String title = titleDesc.getString("Title", "");
String desc = titleDesc.getString("Desc", "");
Log.d(TAG, "Title: " + title + ", Desc: " + desc);
Timber.d("Title: %s, Desc: %s", title, desc);
titleEdit.setText(title);
descEdit.setText(desc);

View file

@ -13,7 +13,6 @@ import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.MediaStore;
import android.text.TextUtils;
import android.util.Log;
import java.io.IOException;
import java.util.Date;
@ -23,6 +22,7 @@ import fr.free.nrw.commons.HandlerService;
import fr.free.nrw.commons.settings.Prefs;
import fr.free.nrw.commons.Utils;
import fr.free.nrw.commons.contributions.Contribution;
import timber.log.Timber;
public class UploadController {
private UploadService uploadService;
@ -115,11 +115,11 @@ public class UploadController {
contribution.setDataLength(length);
}
} catch(IOException e) {
Log.e("UploadController", "IO Exception: ", e);
Timber.e(e, "IO Exception: ");
} catch(NullPointerException e) {
Log.e("UploadController", "Null Pointer Exception: ", e);
Timber.e(e, "Null Pointer Exception: ");
} catch(SecurityException e) {
Log.e("UploadController", "Security Exception: ", e);
Timber.e(e, "Security Exception: ");
}
String mimeType = (String)contribution.getTag("mimeType");
@ -132,7 +132,7 @@ public class UploadController {
if(mimeType != null) {
contribution.setTag("mimeType", mimeType);
imagePrefix = mimeType.startsWith("image/");
Log.d("UploadController", "MimeType is: " + mimeType);
Timber.d("MimeType is: %s", mimeType);
}
if(imagePrefix && contribution.getDateCreated() == null) {

View file

@ -10,7 +10,6 @@ import android.content.Intent;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.webkit.MimeTypeMap;
import android.widget.Toast;
@ -36,6 +35,7 @@ import fr.free.nrw.commons.contributions.ContributionsActivity;
import fr.free.nrw.commons.contributions.ContributionsContentProvider;
import fr.free.nrw.commons.modifications.ModificationsContentProvider;
import in.yuvi.http.fluent.ProgressListener;
import timber.log.Timber;
public class UploadService extends HandlerService<Contribution> {
@ -87,7 +87,7 @@ public class UploadService extends HandlerService<Contribution> {
@Override
public void onProgress(long transferred, long total) {
Log.d("Commons", String.format("Uploaded %d of %d", transferred, total));
Timber.d("Uploaded %d of %d", transferred, total);
if(!notificationTitleChanged) {
curProgressNotification.setContentTitle(notificationProgressTitle);
notificationTitleChanged = true;
@ -112,7 +112,7 @@ public class UploadService extends HandlerService<Contribution> {
public void onDestroy() {
super.onDestroy();
contributionsProviderClient.release();
Log.d("Commons", "UploadService.onDestroy; " + unfinishedUploads + " are yet to be uploaded");
Timber.d("UploadService.onDestroy; %s are yet to be uploaded", unfinishedUploads);
}
@Override
@ -149,7 +149,7 @@ public class UploadService extends HandlerService<Contribution> {
toUpload++;
if (curProgressNotification != null && toUpload != 1) {
curProgressNotification.setContentText(getResources().getQuantityString(R.plurals.uploads_pending_notification_indicator, toUpload, toUpload));
Log.d("Commons", String.format("%d uploads left", toUpload));
Timber.d("%d uploads left", toUpload);
this.startForeground(NOTIFICATION_UPLOAD_IN_PROGRESS, curProgressNotification.build());
}
@ -173,8 +173,8 @@ public class UploadService extends HandlerService<Contribution> {
Contribution.Table.COLUMN_STATE + " = ? OR " + Contribution.Table.COLUMN_STATE + " = ?",
new String[]{ String.valueOf(Contribution.STATE_QUEUED), String.valueOf(Contribution.STATE_IN_PROGRESS) }
);
Log.d("Commons", "Set " + updated + " uploads to failed");
Log.d("Commons", "Flags is" + flags + " id is" + startId);
Timber.d("Set %d uploads to failed", updated);
Timber.d("Flags is %d id is %d", flags, startId);
freshStart = false;
}
return START_REDELIVER_INTENT;
@ -192,12 +192,12 @@ public class UploadService extends HandlerService<Contribution> {
//FIXME: Google Photos bug
file = this.getContentResolver().openInputStream(contribution.getLocalUri());
} catch(FileNotFoundException e) {
Log.d("Exception", "File not found");
Timber.d("File not found");
Toast fileNotFound = Toast.makeText(this, R.string.upload_failed, Toast.LENGTH_LONG);
fileNotFound.show();
}
Log.d("Commons", "Before execution!");
Timber.d("Before execution!");
curProgressNotification = new NotificationCompat.Builder(this).setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
@ -218,16 +218,16 @@ public class UploadService extends HandlerService<Contribution> {
MimeTypeMap.getSingleton().getExtensionFromMimeType((String)contribution.getTag("mimeType")));
synchronized (unfinishedUploads) {
Log.d("Commons", "making sure of uniqueness of name: " + filename);
Timber.d("making sure of uniqueness of name: %s", filename);
filename = findUniqueFilename(filename);
unfinishedUploads.add(filename);
}
if(!api.validateLogin()) {
// Need to revalidate!
if(app.revalidateAuthToken()) {
Log.d("Commons", "Successfully revalidated token!");
Timber.d("Successfully revalidated token!");
} else {
Log.d("Commons", "Unable to revalidate :(");
Timber.d("Unable to revalidate :(");
// TODO: Put up a new notification, ask them to re-login
stopForeground(true);
Toast failureToast = Toast.makeText(this, R.string.authentication_failed, Toast.LENGTH_LONG);
@ -242,7 +242,7 @@ public class UploadService extends HandlerService<Contribution> {
);
result = api.upload(filename, file, contribution.getDataLength(), contribution.getPageContents(), contribution.getEditSummary(), notificationUpdater);
Log.d("Commons", "Response is" + Utils.getStringFromDOM(result.getDocument()));
Timber.d("Response is %s", Utils.getStringFromDOM(result.getDocument()));
curProgressNotification = null;
@ -277,7 +277,7 @@ public class UploadService extends HandlerService<Contribution> {
.log();
}
} catch(IOException e) {
Log.d("Commons", "I have a network fuckup");
Timber.d("I have a network fuckup");
showFailedNotification(contribution);
return;
} finally {