Harmonize logging tag

This commit is contained in:
stefan-niedermann 2019-10-11 10:46:36 +02:00
parent bd0b374ed6
commit 877dcfb64c
11 changed files with 87 additions and 64 deletions

View file

@ -1,16 +1,19 @@
package it.niedermann.owncloud.notes.android; package it.niedermann.owncloud.notes.android;
import android.content.Context; import android.content.Context;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
/** /**
* Extension of the {@link AppCompatAutoCompleteTextView}, but this one is always open, i.e. you can see the list of suggestions even the TextView is empty. * Extension of the {@link AppCompatAutoCompleteTextView}, but this one is always open, i.e. you can see the list of suggestions even the TextView is empty.
*/ */
public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView { public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {
private static final String TAG = AlwaysAutoCompleteTextView.class.getSimpleName();
private int myThreshold; private int myThreshold;
public AlwaysAutoCompleteTextView(Context context) { public AlwaysAutoCompleteTextView(Context context) {
@ -50,7 +53,7 @@ public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {
} catch (WindowManager.BadTokenException e) { } catch (WindowManager.BadTokenException e) {
// https://github.com/stefan-niedermann/nextcloud-notes/issues/366 // https://github.com/stefan-niedermann/nextcloud-notes/issues/366
e.printStackTrace(); e.printStackTrace();
Log.e(AlwaysAutoCompleteTextView.class.getSimpleName(), "Exception", e); Log.e(TAG, "Exception", e);
} }
} }
} }

View file

@ -27,6 +27,8 @@ import it.niedermann.owncloud.notes.util.NoteUtil;
public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragment.NoteFragmentListener { public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragment.NoteFragmentListener {
private static final String TAG = EditNoteActivity.class.getSimpleName();
public static final String ACTION_SHORTCUT = "it.niedermann.owncloud.notes.shortcut"; public static final String ACTION_SHORTCUT = "it.niedermann.owncloud.notes.shortcut";
private static final String INTENT_GOOGLE_ASSISTANT = "com.google.android.gm.action.AUTO_SEND"; private static final String INTENT_GOOGLE_ASSISTANT = "com.google.android.gm.action.AUTO_SEND";
private static final String MIMETYPE_TEXT_PLAIN = "text/plain"; private static final String MIMETYPE_TEXT_PLAIN = "text/plain";
@ -55,7 +57,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
Log.d(getClass().getSimpleName(), "onNewIntent: " + intent.getLongExtra(PARAM_NOTE_ID, 0)); Log.d(TAG, "onNewIntent: " + intent.getLongExtra(PARAM_NOTE_ID, 0));
setIntent(intent); setIntent(intent);
if (fragment != null) { if (fragment != null) {
getFragmentManager().beginTransaction().detach(fragment).commit(); getFragmentManager().beginTransaction().detach(fragment).commit();
@ -220,7 +222,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
} }
} else { } else {
// Maybe account is not authenticated -> note == null // Maybe account is not authenticated -> note == null
Log.e(getClass().getSimpleName(), "note is null, start NotesListViewActivity"); Log.e(TAG, "note is null, start NotesListViewActivity");
startActivity(new Intent(this, NotesListViewActivity.class)); startActivity(new Intent(this, NotesListViewActivity.class));
finish(); finish();
} }

View file

@ -76,6 +76,8 @@ import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;
public class NotesListViewActivity extends AppCompatActivity implements ItemAdapter.NoteClickListener { public class NotesListViewActivity extends AppCompatActivity implements ItemAdapter.NoteClickListener {
private static final String TAG = NotesListViewActivity.class.getSimpleName();
public static final String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes"; public static final String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes";
public static final String ADAPTER_KEY_RECENT = "recent"; public static final String ADAPTER_KEY_RECENT = "recent";
public static final String ADAPTER_KEY_STARRED = "starred"; public static final String ADAPTER_KEY_STARRED = "starred";
@ -155,7 +157,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
.setIntent(intent) .setIntent(intent)
.build()); .build());
} }
Log.d(getClass().getSimpleName(), "Update dynamic shortcuts"); Log.d(TAG, "Update dynamic shortcuts");
shortcutManager.removeAllDynamicShortcuts(); shortcutManager.removeAllDynamicShortcuts();
shortcutManager.addDynamicShortcuts(newShortcuts); shortcutManager.addDynamicShortcuts(newShortcuts);
} }
@ -595,7 +597,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
db.deleteNoteAndSync((dbNote).getId()); db.deleteNoteAndSync((dbNote).getId());
adapter.remove(dbNote); adapter.remove(dbNote);
refreshLists(); refreshLists();
Log.v(getClass().getSimpleName(), "Item deleted through swipe ----------------------------------------------"); Log.v(TAG, "Item deleted through swipe ----------------------------------------------");
Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG) Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG)
.setAction(R.string.action_undo, (View v) -> { .setAction(R.string.action_undo, (View v) -> {
db.addNoteAndSync(dbNote.getAccountId(), dbNote); db.addNoteAndSync(dbNote.getAccountId(), dbNote);
@ -762,10 +764,10 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
if (createdNote != null) { if (createdNote != null) {
adapter.add(createdNote); adapter.add(createdNote);
} else { } else {
Log.w(NotesListViewActivity.class.getSimpleName(), "createdNote is null"); Log.w(TAG, "createdNote is null");
} }
} else { } else {
Log.w(NotesListViewActivity.class.getSimpleName(), "bundle is null"); Log.w(TAG, "bundle is null");
} }
} }
listView.scrollToPosition(0); listView.scrollToPosition(0);
@ -775,7 +777,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
recreate(); recreate();
} else { } else {
AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> { AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> {
Log.v(getClass().getSimpleName(), "Added account: " + "name:" + account.name + ", " + account.url + ", userId" + account.userId); Log.v(TAG, "Added account: " + "name:" + account.name + ", " + account.url + ", userId" + account.userId);
try { try {
db.addAccount(account.url, account.userId, account.name); db.addAccount(account.url, account.userId, account.name);
} catch(SQLiteConstraintException e) { } catch(SQLiteConstraintException e) {
@ -802,7 +804,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
.apply(RequestOptions.circleCropTransform()) .apply(RequestOptions.circleCropTransform())
.into(this.currentAccountImage); .into(this.currentAccountImage);
} else { } else {
Log.w(NotesListViewActivity.class.getSimpleName(), "url is null"); Log.w(TAG, "url is null");
} }
} catch (NullPointerException e) { // No local account - show generic header } catch (NullPointerException e) { // No local account - show generic header
this.account.setText(R.string.app_name_long); this.account.setText(R.string.app_name_long);
@ -811,7 +813,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
.load(R.mipmap.ic_launcher) .load(R.mipmap.ic_launcher)
.apply(RequestOptions.circleCropTransform()) .apply(RequestOptions.circleCropTransform())
.into(this.currentAccountImage); .into(this.currentAccountImage);
Log.w(getClass().getSimpleName(), "Tried to update username in drawer, but localAccount was null"); Log.w(TAG, "Tried to update username in drawer, but localAccount was null");
} }
} }

View file

@ -17,6 +17,7 @@ import it.niedermann.owncloud.notes.android.activity.EditNoteActivity;
import it.niedermann.owncloud.notes.android.activity.NotesListViewActivity; import it.niedermann.owncloud.notes.android.activity.NotesListViewActivity;
public class NoteListWidget extends AppWidgetProvider { public class NoteListWidget extends AppWidgetProvider {
private static final String TAG = NoteListWidget.class.getSimpleName();
public static final String WIDGET_MODE_KEY = "NLW_mode"; public static final String WIDGET_MODE_KEY = "NLW_mode";
public static final String WIDGET_CATEGORY_KEY = "NLW_cat"; public static final String WIDGET_CATEGORY_KEY = "NLW_cat";
public static final String DARK_THEME_KEY = "NLW_darkTheme"; public static final String DARK_THEME_KEY = "NLW_darkTheme";
@ -111,14 +112,14 @@ public class NoteListWidget extends AppWidgetProvider {
if (intent.getExtras() != null) { if (intent.getExtras() != null) {
updateAppWidget(context, awm, new int[]{intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)}); updateAppWidget(context, awm, new int[]{intent.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)});
} else { } else {
Log.w(NoteListWidget.class.getSimpleName(), "intent.getExtras() is null"); Log.w(TAG, "intent.getExtras() is null");
} }
} else { } else {
updateAppWidget(context, awm, awm.getAppWidgetIds(new ComponentName(context, NoteListWidget.class))); updateAppWidget(context, awm, awm.getAppWidgetIds(new ComponentName(context, NoteListWidget.class)));
} }
} }
} else { } else {
Log.w(NoteListWidget.class.getSimpleName(), "intent.getAction() is null"); Log.w(TAG, "intent.getAction() is null");
} }
} }

View file

@ -46,6 +46,8 @@ import static it.niedermann.owncloud.notes.android.activity.EditNoteActivity.ACT
public abstract class BaseNoteFragment extends Fragment implements CategoryDialogFragment.CategoryDialogListener { public abstract class BaseNoteFragment extends Fragment implements CategoryDialogFragment.CategoryDialogListener {
private static final String TAG = BaseNoteFragment.class.getSimpleName();
public interface NoteFragmentListener { public interface NoteFragmentListener {
void close(); void close();
@ -335,17 +337,17 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
* @param callback Observer which is called after save/synchronization * @param callback Observer which is called after save/synchronization
*/ */
protected void saveNote(@Nullable ICallback callback) { protected void saveNote(@Nullable ICallback callback) {
Log.d(getClass().getSimpleName(), "saveData()"); Log.d(TAG, "saveData()");
if(note != null) { if(note != null) {
String newContent = getContent(); String newContent = getContent();
if (note.getContent().equals(newContent)) { if (note.getContent().equals(newContent)) {
Log.v(getClass().getSimpleName(), "... not saving, since nothing has changed"); Log.v(TAG, "... not saving, since nothing has changed");
} else { } else {
note = db.updateNoteAndSync(localAccount.getId(), note, newContent, callback); note = db.updateNoteAndSync(localAccount.getId(), note, newContent, callback);
listener.onNoteUpdated(note); listener.onNoteUpdated(note);
} }
} else { } else {
Log.e(getClass().getSimpleName(), "note is null"); Log.e(TAG, "note is null");
} }
} }

View file

@ -32,6 +32,8 @@ import it.niedermann.owncloud.notes.persistence.NoteSQLiteOpenHelper;
*/ */
public class CategoryDialogFragment extends DialogFragment { public class CategoryDialogFragment extends DialogFragment {
private static final String TAG = CategoryDialogFragment.class.getSimpleName();
/** /**
* Interface that must be implemented by the calling Activity. * Interface that must be implemented by the calling Activity.
*/ */
@ -91,7 +93,7 @@ public class CategoryDialogFragment extends DialogFragment {
if (getDialog().getWindow() != null) { if (getDialog().getWindow() != null) {
getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE); getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
} else { } else {
Log.w(CategoryDialogFragment.class.getSimpleName(), "can not set SOFT_INPUT_STATE_ALWAYAS_VISIBLE because getWindow() == null"); Log.w(TAG, "can not set SOFT_INPUT_STATE_ALWAYAS_VISIBLE because getWindow() == null");
} }
} }

View file

@ -29,6 +29,8 @@ import rx.schedulers.Schedulers;
public class NotePreviewFragment extends BaseNoteFragment { public class NotePreviewFragment extends BaseNoteFragment {
private static final String TAG = NotePreviewFragment.class.getSimpleName();
@BindView(R.id.single_note_content) @BindView(R.id.single_note_content)
RxMDTextView noteContent; RxMDTextView noteContent;
@ -91,7 +93,7 @@ public class NotePreviewFragment extends BaseNoteFragment {
@Override @Override
public void onError(Throwable e) { public void onError(Throwable e) {
Log.v(getClass().getSimpleName(), "RxMarkdown error", e); Log.v(TAG, "RxMarkdown error", e);
} }
@Override @Override

View file

@ -14,6 +14,9 @@ import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.util.Notes; import it.niedermann.owncloud.notes.util.Notes;
public class PreferencesFragment extends PreferenceFragment { public class PreferencesFragment extends PreferenceFragment {
private static final String TAG = PreferencesFragment.class.getSimpleName();
@Override @Override
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -37,7 +40,7 @@ public class PreferencesFragment extends PreferenceFragment {
final SwitchPreference wifiOnlyPref = (SwitchPreference) findPreference(getString(R.string.pref_key_wifi_only)); final SwitchPreference wifiOnlyPref = (SwitchPreference) findPreference(getString(R.string.pref_key_wifi_only));
wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> { wifiOnlyPref.setOnPreferenceChangeListener((Preference preference, Object newValue) -> {
Boolean syncOnWifiOnly = (Boolean) newValue; Boolean syncOnWifiOnly = (Boolean) newValue;
Log.v(getClass().getSimpleName(), "syncOnWifiOnly: " + syncOnWifiOnly); Log.v(TAG, "syncOnWifiOnly: " + syncOnWifiOnly);
return true; return true;
}); });
} }

View file

@ -44,6 +44,8 @@ import it.niedermann.owncloud.notes.util.NoteUtil;
*/ */
public class NoteSQLiteOpenHelper extends SQLiteOpenHelper { public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
private static final String TAG = NoteSQLiteOpenHelper.class.getSimpleName();
private static final int database_version = 9; private static final int database_version = 9;
private static final String database_name = "OWNCLOUD_NOTES"; private static final String database_name = "OWNCLOUD_NOTES";
private static final String table_notes = "NOTES"; private static final String table_notes = "NOTES";
@ -204,12 +206,12 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
editor.remove("settingsPassword"); editor.remove("settingsPassword");
editor.apply(); editor.apply();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
Log.e(getClass().getSimpleName(), "Previous URL could not be parsed. Recreating database..."); Log.e(TAG, "Previous URL could not be parsed. Recreating database...");
e.printStackTrace(); e.printStackTrace();
recreateDatabase(db); recreateDatabase(db);
} }
} else { } else {
Log.e(getClass().getSimpleName(), "Previous URL is null. Recreating database..."); Log.e(TAG, "Previous URL is null. Recreating database...");
recreateDatabase(db); recreateDatabase(db);
} }
} }
@ -339,7 +341,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
private List<DBNote> getNotesCustom(long accountId, @NonNull String selection, @NonNull String[] selectionArgs, @Nullable String orderBy, @Nullable String limit) { private List<DBNote> getNotesCustom(long accountId, @NonNull String selection, @NonNull String[] selectionArgs, @Nullable String orderBy, @Nullable String limit) {
SQLiteDatabase db = getReadableDatabase(); SQLiteDatabase db = getReadableDatabase();
if (selectionArgs.length > 2) { if (selectionArgs.length > 2) {
Log.v(getClass().getSimpleName(), selection + " ---- " + selectionArgs[0] + " " + selectionArgs[1] + " " + selectionArgs[2]); Log.v(TAG, selection + " ---- " + selectionArgs[0] + " " + selectionArgs[1] + " " + selectionArgs[2]);
} }
Cursor cursor = db.query(table_notes, columns, selection, selectionArgs, null, null, orderBy, limit); Cursor cursor = db.query(table_notes, columns, selection, selectionArgs, null, null, orderBy, limit);
List<DBNote> notes = new ArrayList<>(); List<DBNote> notes = new ArrayList<>();
@ -365,9 +367,9 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
public void debugPrintFullDB(long accountId) { public void debugPrintFullDB(long accountId) {
List<DBNote> notes = getNotesCustom(accountId, "", new String[]{}, default_order); List<DBNote> notes = getNotesCustom(accountId, "", new String[]{}, default_order);
Log.v(getClass().getSimpleName(), "Full Database (" + notes.size() + " notes):"); Log.v(TAG, "Full Database (" + notes.size() + " notes):");
for (DBNote note : notes) { for (DBNote note : notes) {
Log.v(getClass().getSimpleName(), " " + note); Log.v(TAG, " " + note);
} }
} }
@ -617,7 +619,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
whereArgs = new String[]{String.valueOf(id), DBStatus.VOID.getTitle(), Long.toString(remoteNote.getModified().getTimeInMillis() / 1000), remoteNote.getTitle(), remoteNote.isFavorite() ? "1" : "0", remoteNote.getCategory(), remoteNote.getEtag(), remoteNote.getContent()}; whereArgs = new String[]{String.valueOf(id), DBStatus.VOID.getTitle(), Long.toString(remoteNote.getModified().getTimeInMillis() / 1000), remoteNote.getTitle(), remoteNote.isFavorite() ? "1" : "0", remoteNote.getCategory(), remoteNote.getEtag(), remoteNote.getContent()};
} }
int i = db.update(table_notes, values, whereClause, whereArgs); int i = db.update(table_notes, values, whereClause, whereArgs);
Log.d(getClass().getSimpleName(), "updateNote: " + remoteNote + " || forceUnchangedDBNoteState: " + forceUnchangedDBNoteState + " => " + i + " rows updated"); Log.d(TAG, "updateNote: " + remoteNote + " || forceUnchangedDBNoteState: " + forceUnchangedDBNoteState + " => " + i + " rows updated");
return i; return i;
} }
@ -645,7 +647,7 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
shortcutManager.getPinnedShortcuts().forEach((shortcut) -> { shortcutManager.getPinnedShortcuts().forEach((shortcut) -> {
String shortcutId = id + ""; String shortcutId = id + "";
if (shortcut.getId().equals(shortcutId)) { if (shortcut.getId().equals(shortcutId)) {
Log.v(NoteSQLiteOpenHelper.class.getSimpleName(), "Removing shortcut for " + shortcutId); Log.v(TAG, "Removing shortcut for " + shortcutId);
shortcutManager.disableShortcuts(Collections.singletonList(shortcutId), context.getResources().getString(R.string.note_has_been_deleted)); shortcutManager.disableShortcuts(Collections.singletonList(shortcutId), context.getResources().getString(R.string.note_has_been_deleted));
} }
}); });
@ -765,10 +767,10 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
if (deletedAccounts < 1) { if (deletedAccounts < 1) {
throw new IllegalArgumentException("The given accountId does not delete any row"); throw new IllegalArgumentException("The given accountId does not delete any row");
} else if (deletedAccounts > 1) { } else if (deletedAccounts > 1) {
Log.e(getClass().getSimpleName(), "AccountId '" + accountId + "' deleted unexpectedly '" + deletedAccounts + "' accounts"); Log.e(TAG, "AccountId '" + accountId + "' deleted unexpectedly '" + deletedAccounts + "' accounts");
} }
final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{accountId + ""}); final int deletedNotes = db.delete(table_notes, key_account_id + " = ?", new String[]{accountId + ""});
Log.v(getClass().getSimpleName(), "Deleted " + deletedNotes + " notes from account " + accountId); Log.v(TAG, "Deleted " + deletedNotes + " notes from account " + accountId);
} }
void updateETag(long accountId, String etag) { void updateETag(long accountId, String etag) {
@ -777,9 +779,9 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
values.put(key_etag, etag); values.put(key_etag, etag);
final int updatedRows = db.update(table_accounts, values, key_id + " = ?", new String[]{accountId + ""}); final int updatedRows = db.update(table_accounts, values, key_id + " = ?", new String[]{accountId + ""});
if (updatedRows == 1) { if (updatedRows == 1) {
Log.v(getClass().getSimpleName(), "Updated etag to " + etag + " for accountId = " + accountId); Log.v(TAG, "Updated etag to " + etag + " for accountId = " + accountId);
} else { } else {
Log.e(getClass().getSimpleName(), "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and etag = " + etag); Log.e(TAG, "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and etag = " + etag);
} }
} }
@ -789,9 +791,9 @@ public class NoteSQLiteOpenHelper extends SQLiteOpenHelper {
values.put(key_modified, modified); values.put(key_modified, modified);
final int updatedRows = db.update(table_accounts, values, key_id + " = ?", new String[]{accountId + ""}); final int updatedRows = db.update(table_accounts, values, key_id + " = ?", new String[]{accountId + ""});
if (updatedRows == 1) { if (updatedRows == 1) {
Log.v(getClass().getSimpleName(), "Updated modified to " + modified + " for accountId = " + accountId); Log.v(TAG, "Updated modified to " + modified + " for accountId = " + accountId);
} else { } else {
Log.e(getClass().getSimpleName(), "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and modified = " + modified); Log.e(TAG, "Updated " + updatedRows + " but expected only 1 for accountId = " + accountId + " and modified = " + modified);
} }
} }
} }

View file

@ -39,6 +39,8 @@ import it.niedermann.owncloud.notes.util.ServerResponse;
*/ */
public class NoteServerSyncHelper { public class NoteServerSyncHelper {
private static final String TAG = NoteServerSyncHelper.class.getSimpleName();
private static NoteServerSyncHelper instance; private static NoteServerSyncHelper instance;
/** /**
@ -125,11 +127,11 @@ public class NoteServerSyncHelper {
} else { } else {
notesClient.updateAccount(); notesClient.updateAccount();
} }
Log.v(getClass().getSimpleName(), "NextcloudRequest account: " + localAccount); Log.v(TAG, "NextcloudRequest account: " + localAccount);
} catch (NoCurrentAccountSelectedException e) { } catch (NoCurrentAccountSelectedException e) {
e.printStackTrace(); e.printStackTrace();
} }
Log.v(getClass().getSimpleName(), "Reinstanziation NotesClient because of SSO acc changed"); Log.v(TAG, "Reinstanziation NotesClient because of SSO acc changed");
} }
@Override @Override
@ -193,9 +195,9 @@ public class NoteServerSyncHelper {
* @param onlyLocalChanges Whether to only push local changes to the server or to also load the whole list of notes from the server. * @param onlyLocalChanges Whether to only push local changes to the server or to also load the whole list of notes from the server.
*/ */
public void scheduleSync(boolean onlyLocalChanges) { public void scheduleSync(boolean onlyLocalChanges) {
Log.d(getClass().getSimpleName(), "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (syncActive ? "sync active" : "sync NOT active") + ") ..."); Log.d(TAG, "Sync requested (" + (onlyLocalChanges ? "onlyLocalChanges" : "full") + "; " + (syncActive ? "sync active" : "sync NOT active") + ") ...");
if (isSyncPossible() && (!syncActive || onlyLocalChanges)) { if (isSyncPossible() && (!syncActive || onlyLocalChanges)) {
Log.d(getClass().getSimpleName(), "... starting now"); Log.d(TAG, "... starting now");
SyncTask syncTask = new SyncTask(onlyLocalChanges); SyncTask syncTask = new SyncTask(onlyLocalChanges);
syncTask.addCallbacks(callbacksPush); syncTask.addCallbacks(callbacksPush);
callbacksPush = new ArrayList<>(); callbacksPush = new ArrayList<>();
@ -205,13 +207,13 @@ public class NoteServerSyncHelper {
} }
syncTask.execute(); syncTask.execute();
} else if (!onlyLocalChanges) { } else if (!onlyLocalChanges) {
Log.d(getClass().getSimpleName(), "... scheduled"); Log.d(TAG, "... scheduled");
syncScheduled = true; syncScheduled = true;
for (ICallback callback : callbacksPush) { for (ICallback callback : callbacksPush) {
callback.onScheduled(); callback.onScheduled();
} }
} else { } else {
Log.d(getClass().getSimpleName(), "... do nothing"); Log.d(TAG, "... do nothing");
for (ICallback callback : callbacksPush) { for (ICallback callback : callbacksPush) {
callback.onScheduled(); callback.onScheduled();
} }
@ -229,13 +231,13 @@ public class NoteServerSyncHelper {
.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected(); .getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
if (networkConnected) { if (networkConnected) {
Log.d(NoteServerSyncHelper.class.getSimpleName(), "Network connection established."); Log.d(TAG, "Network connection established.");
} else { } else {
Log.d(NoteServerSyncHelper.class.getSimpleName(), "Network connected, but not used because only synced on wifi."); Log.d(TAG, "Network connected, but not used because only synced on wifi.");
} }
} else { } else {
networkConnected = false; networkConnected = false;
Log.d(NoteServerSyncHelper.class.getSimpleName(), "No network connection."); Log.d(TAG, "No network connection.");
} }
} }
@ -267,7 +269,7 @@ public class NoteServerSyncHelper {
@Override @Override
protected LoginStatus doInBackground(Void... voids) { protected LoginStatus doInBackground(Void... voids) {
Log.i(getClass().getSimpleName(), "STARTING SYNCHRONIZATION"); Log.i(TAG, "STARTING SYNCHRONIZATION");
//dbHelper.debugPrintFullDB(); //dbHelper.debugPrintFullDB();
LoginStatus status = LoginStatus.OK; LoginStatus status = LoginStatus.OK;
pushLocalChanges(); pushLocalChanges();
@ -275,7 +277,7 @@ public class NoteServerSyncHelper {
status = pullRemoteChanges(); status = pullRemoteChanges();
} }
//dbHelper.debugPrintFullDB(); //dbHelper.debugPrintFullDB();
Log.i(getClass().getSimpleName(), "SYNCHRONIZATION FINISHED"); Log.i(TAG, "SYNCHRONIZATION FINISHED");
return status; return status;
} }
@ -286,34 +288,34 @@ public class NoteServerSyncHelper {
if (localAccount == null) { if (localAccount == null) {
return; return;
} }
Log.d(getClass().getSimpleName(), "pushLocalChanges()"); Log.d(TAG, "pushLocalChanges()");
List<DBNote> notes = dbHelper.getLocalModifiedNotes(localAccount.getId()); List<DBNote> notes = dbHelper.getLocalModifiedNotes(localAccount.getId());
for (DBNote note : notes) { for (DBNote note : notes) {
Log.d(getClass().getSimpleName(), " Process Local Note: " + note); Log.d(TAG, " Process Local Note: " + note);
try { try {
CloudNote remoteNote = null; CloudNote remoteNote = null;
switch (note.getStatus()) { switch (note.getStatus()) {
case LOCAL_EDITED: case LOCAL_EDITED:
Log.v(getClass().getSimpleName(), " ...create/edit"); Log.v(TAG, " ...create/edit");
// if note is not new, try to edit it. // if note is not new, try to edit it.
if (note.getRemoteId() > 0) { if (note.getRemoteId() > 0) {
Log.v(getClass().getSimpleName(), " ...try to edit"); Log.v(TAG, " ...try to edit");
remoteNote = notesClient.editNote(note).getNote(); remoteNote = notesClient.editNote(note).getNote();
} }
// However, the note may be deleted on the server meanwhile; or was never synchronized -> (re)create // However, the note may be deleted on the server meanwhile; or was never synchronized -> (re)create
// Please note, thas dbHelper.updateNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI. // Please note, thas dbHelper.updateNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
if (remoteNote == null) { if (remoteNote == null) {
Log.v(getClass().getSimpleName(), " ...Note does not exist on server -> (re)create"); Log.v(TAG, " ...Note does not exist on server -> (re)create");
remoteNote = notesClient.createNote(note).getNote(); remoteNote = notesClient.createNote(note).getNote();
} }
dbHelper.updateNote(note.getId(), remoteNote, note); dbHelper.updateNote(note.getId(), remoteNote, note);
break; break;
case LOCAL_DELETED: case LOCAL_DELETED:
if (note.getRemoteId() > 0) { if (note.getRemoteId() > 0) {
Log.v(getClass().getSimpleName(), " ...delete (from server and local)"); Log.v(TAG, " ...delete (from server and local)");
notesClient.deleteNote(note.getRemoteId()); notesClient.deleteNote(note.getRemoteId());
} else { } else {
Log.v(getClass().getSimpleName(), " ...delete (only local, since it was not synchronized)"); Log.v(TAG, " ...delete (only local, since it was not synchronized)");
} }
// Please note, thas dbHelper.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI. // Please note, thas dbHelper.deleteNote() realizes an optimistic conflict resolution, which is required for parallel changes of this Note from the UI.
dbHelper.deleteNote(note.getId(), DBStatus.LOCAL_DELETED); dbHelper.deleteNote(note.getId(), DBStatus.LOCAL_DELETED);
@ -322,7 +324,7 @@ public class NoteServerSyncHelper {
throw new IllegalStateException("Unknown State of Note: " + note); throw new IllegalStateException("Unknown State of Note: " + note);
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.e(getClass().getSimpleName(), "Exception", e); Log.e(TAG, "Exception", e);
exceptions.add(e); exceptions.add(e);
} }
} }
@ -335,7 +337,7 @@ public class NoteServerSyncHelper {
if (localAccount == null) { if (localAccount == null) {
return LoginStatus.NO_NETWORK; return LoginStatus.NO_NETWORK;
} }
Log.d(getClass().getSimpleName(), "pullRemoteChanges() for account " + localAccount.getAccountName()); Log.d(TAG, "pullRemoteChanges() for account " + localAccount.getAccountName());
LoginStatus status; LoginStatus status;
try { try {
Map<Long, Long> idMap = dbHelper.getIdMap(localAccount.getId()); Map<Long, Long> idMap = dbHelper.getIdMap(localAccount.getId());
@ -344,23 +346,23 @@ public class NoteServerSyncHelper {
Set<Long> remoteIDs = new HashSet<>(); Set<Long> remoteIDs = new HashSet<>();
// pull remote changes: update or create each remote note // pull remote changes: update or create each remote note
for (CloudNote remoteNote : remoteNotes) { for (CloudNote remoteNote : remoteNotes) {
Log.v(getClass().getSimpleName(), " Process Remote Note: " + remoteNote); Log.v(TAG, " Process Remote Note: " + remoteNote);
remoteIDs.add(remoteNote.getRemoteId()); remoteIDs.add(remoteNote.getRemoteId());
if (remoteNote.getModified() == null) { if (remoteNote.getModified() == null) {
Log.v(getClass().getSimpleName(), " ... unchanged"); Log.v(TAG, " ... unchanged");
} else if (idMap.containsKey(remoteNote.getRemoteId())) { } else if (idMap.containsKey(remoteNote.getRemoteId())) {
Log.v(getClass().getSimpleName(), " ... found -> Update"); Log.v(TAG, " ... found -> Update");
dbHelper.updateNote(idMap.get(remoteNote.getRemoteId()), remoteNote, null); dbHelper.updateNote(idMap.get(remoteNote.getRemoteId()), remoteNote, null);
} else { } else {
Log.v(getClass().getSimpleName(), " ... create"); Log.v(TAG, " ... create");
dbHelper.addNote(localAccount.getId(), remoteNote); dbHelper.addNote(localAccount.getId(), remoteNote);
} }
} }
Log.d(getClass().getSimpleName(), " Remove remotely deleted Notes (only those without local changes)"); Log.d(TAG, " Remove remotely deleted Notes (only those without local changes)");
// remove remotely deleted notes (only those without local changes) // remove remotely deleted notes (only those without local changes)
for (Map.Entry<Long, Long> entry : idMap.entrySet()) { for (Map.Entry<Long, Long> entry : idMap.entrySet()) {
if (!remoteIDs.contains(entry.getKey())) { if (!remoteIDs.contains(entry.getKey())) {
Log.v(getClass().getSimpleName(), " ... remove " + entry.getValue()); Log.v(TAG, " ... remove " + entry.getValue());
dbHelper.deleteNote(entry.getValue(), DBStatus.VOID); dbHelper.deleteNote(entry.getValue(), DBStatus.VOID);
} }
} }
@ -372,7 +374,7 @@ public class NoteServerSyncHelper {
dbHelper.updateModified(localAccount.getId(), localAccount.getModified()); dbHelper.updateModified(localAccount.getId(), localAccount.getModified());
return LoginStatus.OK; return LoginStatus.OK;
} catch (JSONException e) { } catch (JSONException e) {
Log.e(getClass().getSimpleName(), "Exception", e); Log.e(TAG, "Exception", e);
exceptions.add(e); exceptions.add(e);
status = LoginStatus.JSON_FAILED; status = LoginStatus.JSON_FAILED;
} }

View file

@ -31,6 +31,8 @@ import it.niedermann.owncloud.notes.util.ServerResponse.NotesResponse;
@WorkerThread @WorkerThread
public class NotesClient { public class NotesClient {
private static final String TAG = NotesClient.class.getSimpleName();
private final Context context; private final Context context;
private NextcloudAPI mNextcloudAPI; private NextcloudAPI mNextcloudAPI;
@ -85,11 +87,11 @@ public class NotesClient {
} }
try { try {
SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context); SingleSignOnAccount ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(context);
Log.v(getClass().getSimpleName(), "NextcloudRequest account: " + ssoAccount.name); Log.v(TAG, "NextcloudRequest account: " + ssoAccount.name);
mNextcloudAPI = new NextcloudAPI(context, ssoAccount, new GsonBuilder().create(), new NextcloudAPI.ApiConnectedListener() { mNextcloudAPI = new NextcloudAPI(context, ssoAccount, new GsonBuilder().create(), new NextcloudAPI.ApiConnectedListener() {
@Override @Override
public void onConnected() { public void onConnected() {
Log.v(getClass().getSimpleName(), "SSO API connected"); Log.v(TAG, "SSO API connected");
} }
@Override @Override
@ -178,9 +180,9 @@ public class NotesClient {
StringBuilder result = new StringBuilder(); StringBuilder result = new StringBuilder();
try { try {
Log.v(getClass().getSimpleName(), "NextcloudRequest: " + nextcloudRequest.toString()); Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString());
InputStream inputStream = mNextcloudAPI.performNetworkRequest(nextcloudRequest); InputStream inputStream = mNextcloudAPI.performNetworkRequest(nextcloudRequest);
Log.v(getClass().getSimpleName(), "NextcloudRequest: " + nextcloudRequest.toString()); Log.v(TAG, "NextcloudRequest: " + nextcloudRequest.toString());
BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream)); BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
String line; String line;
while ((line = rd.readLine()) != null) { while ((line = rd.readLine()) != null) {
@ -197,7 +199,7 @@ public class NotesClient {
long lastModified = 0; long lastModified = 0;
if (nextcloudRequest.getHeader().get("Last-Modified") != null) if (nextcloudRequest.getHeader().get("Last-Modified") != null)
lastModified = Long.parseLong(nextcloudRequest.getHeader().get("Last-Modified").get(0)) / 1000; lastModified = Long.parseLong(nextcloudRequest.getHeader().get("Last-Modified").get(0)) / 1000;
Log.d(getClass().getSimpleName(), "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")"); Log.d(TAG, "ETag: " + etag + "; Last-Modified: " + lastModified + " (" + lastModified + ")");
// return these header fields since they should only be saved after successful processing the result! // return these header fields since they should only be saved after successful processing the result!
return new ResponseData(result.toString(), etag, lastModified); return new ResponseData(result.toString(), etag, lastModified);
} }