{
+ public static final String TITLE = "title";
+ public static final String DATE = "date";
+ private static final String UID = "uid";
+
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+
+
+ public OneNote(String title, String date, String uid) {
+ super();
+ put(TITLE, title);
+ put(DATE, date);
+ put(UID, uid);
+ }
+
+ @NonNull
+ public String GetTitle() {
+ return this.get(TITLE);
+ }
+
+ @NonNull
+ String GetDate() {
+ return this.get(DATE);
+ }
+
+ @NonNull
+ public String GetUid() {
+ return this.get(UID);
+ }
+
+
+ public void SetDate(String date) {
+ this.put(DATE, date);
+ }
+
+ public void SetUid(String uid) {
+ this.put(UID, uid);
+ }
+
+ @NonNull
+ @Override
+ public String toString() {
+ return ("Title:" + this.GetTitle() +
+ " Date: " + this.GetDate() +
+ " Uid: " + this.GetUid());
+ }
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Security.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Security.java
new file mode 100644
index 00000000..2b6d06dd
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Security.java
@@ -0,0 +1,89 @@
+package com.Pau.ImapNotes2.Data;
+
+import android.annotation.SuppressLint;
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Created by kj on 11/1/16.
+ *
+ * Use this instead of integers in the account configuration. Store the name of the security type
+ * instead.
+ *
+ * The items annotated with @SuppressWarnings("unused") are used but only by code that calls the
+ * from method so the analyser cannot see that they are used
+ */
+public enum Security {
+ None("None", "", "imap", false),
+ @SuppressWarnings("unused")
+ SSL_TLS("SSL/TLS", "993", "imaps", false),
+ @SuppressWarnings("unused")
+ SSL_TLS_accept_all_certificates("SSL/TLS (accept all certificates)", "993", "imaps", true),
+ @SuppressWarnings("unused")
+ STARTTLS("STARTTLS", "143", "imaps", false),
+ @SuppressWarnings("unused")
+ STARTTLS_accept_all_certificates("STARTTLS (accept all certificates)", "143", "imaps", true);
+
+ @NonNull
+ static final String TAG = "IN_Security";
+ public final String proto;
+ public final boolean acceptcrt;
+
+
+ private final String printable;
+ public final String defaultPort;
+
+ Security(String printable,
+ String defaultPort,
+ String proto,
+ boolean acceptcrt) {
+ this.printable = printable;
+ this.defaultPort = defaultPort;
+ this.proto = proto;
+ this.acceptcrt = acceptcrt;
+ }
+
+ @NonNull
+ public static List Printables() {
+ List list = new ArrayList<>();
+ for (Security e : Security.values()) {
+ list.add(e.printable);
+ }
+ return list;
+ }
+
+ // Mapping from integer. See http://dan.clarke.name/2011/07/enum-in-java-with-int-conversion/
+ @SuppressLint("UseSparseArrays") // False positive, SparseArray cannot be used here.
+ private static final Map _map = new HashMap<>();
+
+ static {
+ for (Security security : Security.values())
+ _map.put(security.ordinal(), security);
+ }
+
+ @NonNull
+ public static Security from(int ordinal) {
+ return _map.get(ordinal);
+ }
+
+ @NonNull
+ public static Security from(String name) {
+ Log.d(TAG, "from: <" + name + ">");
+ for (Security security : Security.values()) {
+ if (Objects.equals(security.name(), name)) {
+ return security;
+ }
+ }
+ // Wasn't recognized, try using the ordinal instead, backwards compatibility.
+ int i = Integer.parseInt(name);
+ return from(i);
+ }
+
+
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Utilities.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Utilities.java
new file mode 100644
index 00000000..cc1ce5f8
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/Utilities.java
@@ -0,0 +1,23 @@
+package com.Pau.ImapNotes2.Data;
+
+import android.support.annotation.NonNull;
+
+import java.text.SimpleDateFormat;
+import java.util.Locale;
+
+/**
+ * Created by kj on 2016-11-12 17:21.
+ *
+ * Reduce repetition by providing static fields and methods for common operations.
+ */
+public class Utilities {
+
+ /**
+ * The notes have a time stamp associated with thme and this is stored as a string on the
+ * server so we must define a fixed format for it.
+ */
+ @NonNull
+ private static final String internalDateFormatString = "yyyy-MM-dd HH:mm:ss";
+ @NonNull
+ public static final SimpleDateFormat internalDateFormat = new SimpleDateFormat(internalDateFormatString, Locale.ROOT);
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorDb.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorDb.java
new file mode 100644
index 00000000..ca48036a
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorDb.java
@@ -0,0 +1,264 @@
+package com.Pau.ImapNotes2.Data;
+
+import android.content.ContentValues;
+import android.database.Cursor;
+import android.database.sqlite.SQLiteDatabase;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.util.Log;
+
+import java.io.File;
+
+
+/**
+ * Created by kj on 2017-01-09 10:28.
+ *
+ * This class manages the tables used for vector clocks and other data associated with automatic
+ * conflict resolution and merging.
+ */
+
+class VectorDb {
+
+
+ /**
+ * Reference to the SQLite database used for all data in this application.
+ */
+ @NonNull
+ private final Db db;
+ @NonNull
+ private final FileTable fileTable;
+ @NonNull
+ private final VectorTable vectorTable;
+
+ public VectorDb(@NonNull Db db) {
+ this.db = db;
+ vectorTable = new VectorTable();
+ fileTable = new FileTable();
+ }
+
+ void CreateTables(SQLiteDatabase db) {
+ vectorTable.CreateTable(db);
+ fileTable.CreateTable(db);
+ }
+
+/*
+ public void CreateTables(@NonNull SQLiteDatabase db) {
+ fileTable.CreateTable(db);
+ vectorTable.CreateTable(db);
+ }
+*/
+
+
+ class VectorTable {
+
+ private static final String TAG = "IN_VectorTable";
+
+ private static final String COL_FILE_PATH = "filepath";
+ private static final String COL_CLOCK = "clock";
+ private static final String COL_ACCOUNT_NAME = "accountname";
+ private static final String TABLE_NAME = "vector";
+ //private static final String DATABASE_NAME = "NotesDb";
+
+ private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS "
+ + TABLE_NAME
+ + " ("
+ + COL_FILE_PATH + " text not null, "
+ + COL_CLOCK + " text not null, "
+ + COL_ACCOUNT_NAME + " text not null, "
+ + " PRIMARY KEY (" + COL_FILE_PATH + ", " + COL_ACCOUNT_NAME + "));";
+
+
+
+ void CreateTable(@NonNull SQLiteDatabase db) {
+ db.execSQL(CREATE_TABLE);
+ }
+
+ public void Insert(@NonNull File file,
+ @NonNull String accountname,
+ int clock) {
+ ContentValues tableRow = new ContentValues();
+ tableRow.put(COL_FILE_PATH, file.getName());
+ tableRow.put(COL_ACCOUNT_NAME, accountname);
+ tableRow.put(COL_CLOCK, clock);
+ db.notesDb.insertWithOnConflict(TABLE_NAME, null, tableRow,
+ SQLiteDatabase.CONFLICT_REPLACE);
+ }
+/*
+ // TODO: Should use place holders instead of string concatenation.
+ public void Delete(@NonNull File file,
+ @NonNull String accountname) {
+ db.notesDb.execSQL("delete from " + TABLE_NAME + " where " + COL_FILE_PATH + " = '" + file.getAbsolutePath() +
+ "' and accountname = '" + accountname + "'");
+ }*/
+
+
+ void IncrementVectorClock(String relativeFile,
+ String acountName) {
+
+ }
+ }
+
+ class FileTable {
+
+ private static final String TAG = "IN_FileTable";
+
+ private static final String COL_FILE_PATH = "filepath";
+ private static final String COL_MTIME = "mtime";
+ private static final String COL_ACCOUNT_NAME = "accountname";
+ private static final String TABLE_NAME = "file";
+ //private static final String DATABASE_NAME = "NotesDb";
+
+ private static final String CREATE_FILE_TABLE = "CREATE TABLE IF NOT EXISTS "
+ + TABLE_NAME
+ + " (pk integer primary key autoincrement, "
+ + COL_FILE_PATH + " text not null, "
+ + COL_MTIME + " text not null, "
+ + COL_ACCOUNT_NAME + " text not null);";
+
+
+
+
+
+ void CreateTable(@NonNull SQLiteDatabase db) {
+ db.execSQL(CREATE_FILE_TABLE);
+ }
+
+ /**
+ * Update the mtime in the database and increment the vetor clock for this device.
+ *
+ * @param relativeFile
+ * @param lastModified
+ * @param accountName
+ */
+ private void UpdateLastModified(String relativeFile,
+ Long lastModified,
+ String accountName) {
+ ContentValues newMTime = new ContentValues();
+ newMTime.put(COL_MTIME, lastModified);
+
+ db.notesDb.update(TABLE_NAME, newMTime,
+ "? = ? and ? = ?",
+ new String[]{COL_FILE_PATH, relativeFile, COL_ACCOUNT_NAME, accountName});
+ }
+
+ public void Insert(@NonNull String relativeFile,
+ Long lastModified,
+ @NonNull String accountname,
+ @NonNull File accountDir) {
+ ContentValues tableRow = new ContentValues();
+ tableRow.put(COL_FILE_PATH, relativeFile);
+ tableRow.put(COL_MTIME, lastModified);
+ tableRow.put(COL_ACCOUNT_NAME, accountname);
+ db.notesDb.insert(TABLE_NAME, null, tableRow);
+ Log.d(TAG, "note inserted");
+ }
+
+
+
+ // TODO: Should use place holders instead of string concatenation.
+ public void Delete(@NonNull File file,
+ @NonNull String accountname) {
+ db.notesDb.execSQL("delete from " + TABLE_NAME + " where " + COL_FILE_PATH + " = '" + file.getAbsolutePath() +
+ "' and accountname = '" + accountname + "'");
+ }
+
+
+ public long GetMTime(@NonNull String relativeFilePath,
+ @NonNull String accountname) {
+ try (Cursor c = GetRecord(relativeFilePath, accountname)) {
+ return (c == null) ? 0 : c.getLong(c.getColumnIndex(COL_MTIME));
+ }
+ }
+/*
+
+ public long GetMTime(@NonNull String relativeFilePath,
+ @NonNull String accountname) {
+ String selectQuery = "select mtime from " + TABLE_NAME +
+ " where " + COL_FILE_PATH + " = '" + relativeFilePath + "' " + " " +
+ " and accountname = '" + accountname + "'";
+ try (Cursor c = db.notesDb.rawQuery(selectQuery, null)) {
+ if (c.moveToFirst()) {
+ return c.getLong(Cursor.FIELD_TYPE_NULL);
+ }
+ }
+ return 0;
+ }
+
+*/
+
+ @Nullable
+ public Cursor GetRecord(@NonNull String relativeFilePath,
+ @NonNull String accountname) {
+ String selectQuery = "select " +
+ COL_ACCOUNT_NAME + ", " + COL_FILE_PATH + ", " + COL_MTIME +
+ " from " + TABLE_NAME +
+ " where " + COL_FILE_PATH + " = '" + relativeFilePath + "' " + " " +
+ " and " + COL_ACCOUNT_NAME + " = '" + accountname + "'";
+ Cursor c = db.notesDb.rawQuery(selectQuery, null);
+ return c.moveToFirst() ? c : null;
+ }
+
+
+ }
+
+
+ /**
+ * Update the mtime in the database and increment the vetor clock for this device.
+ * TODO: Use a transaction to ensure that either the mtime and vector succeed or neither.
+ *
+ * @param relativeFile
+ * @param lastModified
+ * @param accountName
+ */
+ private void Update(String relativeFile,
+ Long lastModified,
+ String accountName) {
+ fileTable.UpdateLastModified(relativeFile, lastModified, accountName);
+ vectorTable.IncrementVectorClock(relativeFile, accountName);
+ }
+
+ /**
+ * Enumerate the file in the given directory and update the mtime and vector clock in the
+ * database.
+ *
+ * @param accountName
+ * @param accountRoot
+ */
+ public void UpdateAccount(@NonNull String accountName,
+ @NonNull File accountRoot) {
+ for (File file : accountRoot.listFiles()) {
+ UpdateFile(file, accountName, accountRoot);
+ }
+ }
+
+ public void UpdateFile(@NonNull File file,
+ @NonNull String accountName,
+ @NonNull File accountRoot) {
+
+ String relativeFile = RelativePath(accountRoot, file);
+ try (Cursor c = fileTable.GetRecord(RelativePath(accountRoot, file), accountName)) {
+ if (c == null) {
+ // Add new record
+ fileTable.Insert(relativeFile, file.lastModified(), accountName, accountRoot);
+ } else {
+ // Update existing record by incrementing the vector
+ Update(relativeFile, file.lastModified(), accountName);
+ }
+ }
+ }
+
+ /**
+ * See http://www.java2s.com/Tutorial/Java/0180__File/Getrelativepath.htm
+ *
+ * @param base
+ * @param file
+ * @return
+ */
+ @NonNull
+ public String RelativePath(@NonNull final File base, @NonNull final File file) {
+ final int rootLength = base.getAbsolutePath().length();
+ final String absFileName = file.getAbsolutePath();
+ return absFileName.substring(rootLength + 1);
+ }
+
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorNote.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorNote.java
new file mode 100644
index 00000000..2ffb74aa
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Data/VectorNote.java
@@ -0,0 +1,50 @@
+package com.Pau.ImapNotes2.Data;
+
+import android.support.annotation.NonNull;
+
+import java.util.Date;
+import java.util.HashMap;
+
+
+/**
+ * Created by kj on 2017-01-09 10:59.
+ *
+ * Represents metadata about a note in a way that can be used by a ListAdapter. The list adapter
+ * needs objects that have a map interface because it must fetch the items by string name.
+ */
+public class VectorNote extends HashMap {
+ public static final String TITLE = "title";
+ public static final String DATE = "date";
+ //private static final String UID = "uid";
+
+
+ public VectorNote(@NonNull String title,
+ long mtime) {
+ super();
+ put(TITLE, title);
+ put(DATE, new Date(mtime).toString());
+ }
+
+ @NonNull
+ public String GetTitle() {
+ return this.get(TITLE);
+ }
+
+ @NonNull
+ String GetDate() {
+ return this.get(DATE);
+ }
+
+
+ public void SetDate(@NonNull String date) {
+ this.put(DATE, date);
+ }
+
+
+ @NonNull
+ @Override
+ public String toString() {
+ return ("Title:" + this.GetTitle() +
+ " Date: " + this.GetDate());
+ }
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2.java
deleted file mode 100644
index ba693bf2..00000000
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2.java
+++ /dev/null
@@ -1,52 +0,0 @@
-package com.Pau.ImapNotes2;
-
-import java.util.ArrayList;
-
-import com.Pau.ImapNotes2.Data.ConfigurationFile;
-import com.Pau.ImapNotes2.Miscs.Imaper;
-import com.Pau.ImapNotes2.Miscs.OneNote;
-
-import android.app.Application;
-import android.content.Context;
-
-public class ImapNotes2 extends Application {
-
- private ConfigurationFile thisSessionConfigurationFile;
- private Imaper thisSessionImapFolder;
- private ArrayList noteList;
- private static Context context;
-
- public void onCreate(){
- super.onCreate();
- ImapNotes2.context = getApplicationContext();
- }
-
- public static Context getAppContext() {
- return ImapNotes2.context;
- }
-
- public void SetConfigurationFile(ConfigurationFile currentSettings){
- this.thisSessionConfigurationFile = currentSettings;
- }
-
- public ConfigurationFile GetConfigurationFile(){
- return this.thisSessionConfigurationFile;
- }
-
- public void SetImaper(Imaper currentImaper){
- this.thisSessionImapFolder = currentImaper;
- }
-
- public Imaper GetImaper(){
- return this.thisSessionImapFolder;
- }
-
- public void SetNotesList(ArrayList currentNotesList){
- this.noteList = currentNotesList;
- }
-
- public ArrayList GetNotesList(){
- return this.noteList;
- }
-
-}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2k.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2k.java
new file mode 100644
index 00000000..4458c75e
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/ImapNotes2k.java
@@ -0,0 +1,82 @@
+package com.Pau.ImapNotes2;
+
+import android.app.Application;
+import android.content.Context;
+import android.support.annotation.NonNull;
+
+import com.Pau.ImapNotes2.Miscs.Imaper;
+
+import java.io.File;
+
+
+/*
+Changed name by appending a k so that I can have this and the original installed side by side,
+perhaps.
+ */
+public class ImapNotes2k extends Application {
+
+ private Imaper thisSessionImapFolder;
+
+ private static final String configurationFileName = "ImapNotes2.conf";
+/*
+ // Called when starting the application.
+ public void onCreate() {
+ super.onCreate();
+ // Save the context in a static so that it is easy to access everywhere.
+ //ImapNotes2k.context = getApplicationContext();
+ }*/
+
+ @NonNull
+ public static String ConfigurationFilePath(@NonNull Context applicationContext) {
+ return ConfigurationDirPath(applicationContext) + "/" + configurationFileName;
+ }
+
+
+ public static String ConfigurationDirPath(@NonNull Context applicationContext) {
+
+ return ConfigurationDir(applicationContext).getPath();
+ }
+
+
+ public static File ConfigurationDir(@NonNull Context applicationContext) {
+
+ return applicationContext.getFilesDir();
+ }
+
+
+// --Commented out by Inspection START (11/26/16 11:44 PM):
+// // ?
+// public void SetConfigurationFile(ConfigurationFile currentSettings) {
+// this.thisSessionConfigurationFile = currentSettings;
+// }
+// --Commented out by Inspection STOP (11/26/16 11:44 PM)
+
+// --Commented out by Inspection START (11/26/16 11:44 PM):
+// // ?
+// public ConfigurationFile GetConfigurationFile() {
+// return this.thisSessionConfigurationFile;
+// }
+// --Commented out by Inspection STOP (11/26/16 11:44 PM)
+
+ // ?
+ public void SetImaper(Imaper currentImaper) {
+ this.thisSessionImapFolder = currentImaper;
+ }
+
+ // ?
+ public Imaper GetImaper() {
+ return this.thisSessionImapFolder;
+ }
+
+ /*// ?
+ public void SetNotesList(ArrayList currentNotesList) {
+ }
+*/
+// --Commented out by Inspection START (11/26/16 11:44 PM):
+// // ?
+// public ArrayList GetNotesList() {
+// return this.noteList;
+// }
+// --Commented out by Inspection STOP (11/26/16 11:44 PM)
+
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Listactivity.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Listactivity.java
index 31796e97..ece1e390 100644
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Listactivity.java
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Listactivity.java
@@ -1,27 +1,5 @@
package com.Pau.ImapNotes2;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.text.DateFormat;
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.List;
-import java.util.ListIterator;
-
-import org.apache.commons.io.FileUtils;
-
-import com.Pau.ImapNotes2.R;
-import com.Pau.ImapNotes2.Data.NotesDb;
-import com.Pau.ImapNotes2.Miscs.Imaper;
-import com.Pau.ImapNotes2.Miscs.OneNote;
-import com.Pau.ImapNotes2.Data.ImapNotes2Account;
-import com.Pau.ImapNotes2.Miscs.UpdateThread;
-import com.Pau.ImapNotes2.Miscs.SyncThread;
-import com.Pau.ImapNotes2.Sync.SyncService;
-import com.Pau.ImapNotes2.Sync.SyncUtils;
-
import android.accounts.Account;
import android.accounts.AccountManager;
import android.accounts.OnAccountsUpdateListener;
@@ -39,6 +17,8 @@
import android.content.PeriodicSync;
import android.content.pm.PackageInfo;
import android.os.Bundle;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -53,107 +33,157 @@
import android.widget.Filterable;
import android.widget.ListView;
import android.widget.SearchView;
-import android.widget.SimpleAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
-public class Listactivity extends Activity implements OnItemSelectedListener,Filterable {
+import com.Pau.ImapNotes2.Data.Db;
+import com.Pau.ImapNotes2.Data.ImapNotes2Account;
+import com.Pau.ImapNotes2.Data.OneNote;
+import com.Pau.ImapNotes2.Miscs.Imaper;
+import com.Pau.ImapNotes2.Miscs.SyncThread;
+import com.Pau.ImapNotes2.Miscs.UpdateThread;
+import com.Pau.ImapNotes2.Sync.SyncService;
+import com.Pau.ImapNotes2.Sync.SyncUtils;
+
+import org.apache.commons.io.FileUtils;
+
+import java.io.File;
+import java.io.IOException;
+import java.text.DateFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.ListIterator;
+
+import static com.Pau.ImapNotes2.AccountConfigurationActivity.ACTION;
+import static com.Pau.ImapNotes2.NoteDetailActivity.Colors;
+
+//import com.Pau.ImapNotes2.Data.NotesDb;
+
+//import com.Pau.ImapNotes2.R;
+//import android.widget.SimpleAdapter;
+
+
+public class Listactivity extends Activity implements OnItemSelectedListener, Filterable {
private static final int SEE_DETAIL = 2;
- private static final int DELETE_BUTTON = 3;
+ public static final int DELETE_BUTTON = 3;
private static final int NEW_BUTTON = 4;
private static final int SAVE_BUTTON = 5;
private static final int EDIT_BUTTON = 6;
-
+
+
+ //region Intent item names
+ public static final String EDIT_ITEM_NUM_IMAP = "EDIT_ITEM_NUM_IMAP";
+ public static final String EDIT_ITEM_TXT = "EDIT_ITEM_TXT";
+ public static final String EDIT_ITEM_COLOR = "EDIT_ITEM_COLOR";
+ private static final String SAVE_ITEM_COLOR = "SAVE_ITEM_COLOR";
+ private static final String SAVE_ITEM = "SAVE_ITEM";
+ private static final String DELETE_ITEM_NUM_IMAP = "DELETE_ITEM_NUM_IMAP";
+ public static final String ACCOUNTNAME = "ACCOUNTNAME";
+ public static final String SYNCINTERVAL = "SYNCINTERVAL";
+ public static final String CHANGED = "CHANGED";
+ public static final String SYNCED = "SYNCED";
+ //endregion
+
private ArrayList noteList;
private NotesListAdapter listToView;
private ArrayAdapter spinnerList;
-
- private Imaper imapFolder;
- private static NotesDb storedNotes = null;
+
+ @Nullable
+ private static Db storedNotes = null;
private Spinner accountSpinner;
public static ImapNotes2Account imapNotes2Account;
private static AccountManager accountManager;
- private static Account[] accounts;
+ // Ensure that we never have to check for null by initializing reference.
+ @NonNull
+ private static Account[] accounts = new Account[0];
private static List currentList;
- private TextView status = null;
+ //@Nullable
+ private TextView status;
private static String OldStatus;
- private Button editAccountButton=null;
- private ListView listview;
- public static final String AUTHORITY = "com.Pau.ImapNotes2.provider";
+ private static final String AUTHORITY = "com.Pau.ImapNotes2.provider";
private static final String TAG = "IN_Listactivity";
-
- private OnClickListener clickListenerEditAccount = new View.OnClickListener() {
+
+ private final OnClickListener clickListenerEditAccount = new View.OnClickListener() {
@Override
public void onClick(View v) {
- // Clic on editAccount Button
Intent res = new Intent();
String mPackage = "com.Pau.ImapNotes2";
- String mClass = ".AccontConfigurationActivity";
- res.setComponent(new ComponentName(mPackage,mPackage+mClass));
- res.putExtra("action", "EDIT_ACCOUNT");
- res.putExtra("accountname", Listactivity.imapNotes2Account.GetAccountname());
+ String mClass = ".AccountConfigurationActivity";
+ res.setComponent(new ComponentName(mPackage, mPackage + mClass));
+ res.putExtra(ACTION, AccountConfigurationActivity.Actions.EDIT_ACCOUNT);
+ res.putExtra(AccountConfigurationActivity.ACCOUNTNAME, Listactivity.imapNotes2Account.accountName);
startActivity(res);
}
};
-
- /** Called when the activity is first created. */
+
+
+ /**
+ * Called when the activity is first created.
+ */
@Override
public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
-
- // Accounts spinner
- this.accountSpinner = (Spinner) findViewById(R.id.accountSpinner);
- Listactivity.currentList = new ArrayList();
- // Spinner item selection Listener
- this.accountSpinner.setOnItemSelectedListener(this);
-
- imapNotes2Account = new ImapNotes2Account();
- Listactivity.accountManager = AccountManager.get(getApplicationContext());
- Listactivity.accountManager.addOnAccountsUpdatedListener((OnAccountsUpdateListener)
- new AccountsUpdateListener(), null, true);
-
- status = (TextView)findViewById(R.id.status);
-
- this.spinnerList = new ArrayAdapter
- (this, android.R.layout.simple_spinner_item,Listactivity.currentList);
- spinnerList.setDropDownViewResource
- (android.R.layout.simple_spinner_dropdown_item);
- this.accountSpinner.setAdapter(spinnerList);
-
- this.noteList = new ArrayList();
- ((ImapNotes2)this.getApplicationContext()).SetNotesList(this.noteList);
- this.listToView = new NotesListAdapter(
- getApplicationContext(),
- this.noteList,
- R.layout.note_element,
- new String[]{"title","date"},
- new int[]{R.id.noteTitle, R.id.noteInformation});
- listview = (ListView) findViewById(R.id.notesList);
- listview.setAdapter(this.listToView);
-
- listview.setTextFilterEnabled(true);
-
- this.imapFolder = new Imaper();
- ((ImapNotes2)this.getApplicationContext()).SetImaper(this.imapFolder);
-
- if (Listactivity.storedNotes == null)
- storedNotes = new NotesDb(getApplicationContext());
-
- // When item is clicked, we go to NoteDetailActivity
- listview.setOnItemClickListener(new OnItemClickListener() {
- public void onItemClick(AdapterView> arg0, View widget, int selectedNote, long arg3) {
- Intent toDetail = new Intent(widget.getContext(), NoteDetailActivity.class);
- toDetail.putExtra("selectedNote", (OneNote)arg0.getItemAtPosition(selectedNote));
- toDetail.putExtra("useSticky", Listactivity.imapNotes2Account.GetUsesticky());
- startActivityForResult(toDetail,SEE_DETAIL);
- }
- });
+ super.onCreate(savedInstanceState);
+ Log.d(TAG, "onCreate");
+ setContentView(R.layout.main);
+
+ this.accountSpinner = (Spinner) findViewById(R.id.accountSpinner);
+ Listactivity.currentList = new ArrayList<>();
+
+ this.accountSpinner.setOnItemSelectedListener(this);
+
+ //imapNotes2Account = new ImapNotes2Account();
+ Listactivity.accountManager = AccountManager.get(getApplicationContext());
+ Listactivity.accountManager.addOnAccountsUpdatedListener(
+ new AccountsUpdateListener(), null, true);
+
+ status = (TextView) findViewById(R.id.status);
+
+ this.spinnerList = new ArrayAdapter<>
+ (this, android.R.layout.simple_spinner_item, Listactivity.currentList);
+ spinnerList.setDropDownViewResource
+ (android.R.layout.simple_spinner_dropdown_item);
+ this.accountSpinner.setAdapter(spinnerList);
+
+ this.noteList = new ArrayList<>();
+ //((ImapNotes2k) this.getApplicationContext()).SetNotesList(this.noteList);
+ this.listToView = new NotesListAdapter(
+ getApplicationContext(),
+ this.noteList,
+ new String[]{OneNote.TITLE, OneNote.DATE},
+ new int[]{R.id.noteTitle, R.id.noteInformation});
+ ListView listview = (ListView) findViewById(R.id.notesList);
+ listview.setAdapter(this.listToView);
+
+ listview.setTextFilterEnabled(true);
+
+ Imaper imapFolder = new Imaper();
+ ((ImapNotes2k) this.getApplicationContext()).SetImaper(imapFolder);
+
+ if (Listactivity.storedNotes == null)
+ storedNotes = new Db(getApplicationContext());
+
+ // When item is clicked, we go to NoteDetailActivity
+ listview.setOnItemClickListener(new OnItemClickListener() {
+ public void onItemClick(@NonNull AdapterView> parent,
+ @NonNull View widget,
+ int selectedNote,
+ long rowId) {
+ Log.d(TAG, "onItemClick");
+ Intent toDetail = new Intent(widget.getContext(), NoteDetailActivity.class);
+ toDetail.putExtra(NoteDetailActivity.selectedNote, (OneNote) parent.getItemAtPosition(selectedNote));
+ toDetail.putExtra(NoteDetailActivity.useSticky, Listactivity.imapNotes2Account.usesticky);
+ startActivityForResult(toDetail, SEE_DETAIL);
+ Log.d(TAG, "onItemClick, back from detail.");
+
+ //TriggerSync(status);
+ }
+ });
- editAccountButton = (Button) findViewById(R.id.editAccountButton);
- editAccountButton.setOnClickListener(clickListenerEditAccount);
+ Button editAccountButton = (Button) findViewById(R.id.editAccountButton);
+ editAccountButton.setOnClickListener(clickListenerEditAccount);
}
@@ -168,10 +198,10 @@ public void onDestroy() {
public void onStart() {
super.onStart();
- int len = this.accounts == null ? 0 : this.accounts.length;
+ int len = accounts.length;
if (len > 0) updateAccountSpinner();
}
-
+
@Override
protected void onResume() {
super.onResume();
@@ -184,31 +214,38 @@ protected void onPause() {
unregisterReceiver(syncFinishedReceiver);
}
- private BroadcastReceiver syncFinishedReceiver = new BroadcastReceiver() {
- public void onReceive(Context context, Intent intent) {
- String accountname = intent.getStringExtra("ACCOUNTNAME");
- Boolean isChanged = intent.getBooleanExtra("CHANGED", false);
- Boolean isSynced = intent.getBooleanExtra("SYNCED", false);
- String syncInterval = intent.getStringExtra("SYNCINTERVAL");
- if (accountname.equals(Listactivity.imapNotes2Account.GetAccountname())) {
+ @NonNull
+ private final BroadcastReceiver syncFinishedReceiver = new BroadcastReceiver() {
+ public void onReceive(Context context, @NonNull Intent intent) {
+ Log.d(TAG, "BroadcastReceiver.onReceive");
+ String accountName = intent.getStringExtra(ACCOUNTNAME);
+ Boolean isChanged = intent.getBooleanExtra(CHANGED, false);
+ Boolean isSynced = intent.getBooleanExtra(SYNCED, false);
+ String syncInterval = intent.getStringExtra(SYNCINTERVAL);
+ Log.d(TAG, "if " + accountName + " " + Listactivity.imapNotes2Account.accountName);
+ if (accountName.equals(Listactivity.imapNotes2Account.accountName)) {
+ String statusText;
if (isSynced) {
// Display last sync date
- DateFormat dateFormat =
- android.text.format.DateFormat.getDateFormat(getApplicationContext());
+ //DateFormat dateFormat =
+ // android.text.format.DateFormat.getDateFormat(getApplicationContext());
Date date = new Date();
- String sdate = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT).format(date);
+ String sdate = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(date);
String sinterval = " (interval:" + String.valueOf(syncInterval) + " min)";
- status.setText("Last sync: " + sdate + sinterval);
+ statusText = "Last sync: " + sdate + sinterval;
} else {
- status.setText(OldStatus);
+ statusText = OldStatus;
}
+ //TextView status = (TextView) findViewById(R.id.status);
+ status.setText(statusText);
if (isChanged) {
- if (Listactivity.storedNotes == null)
- storedNotes = new NotesDb(getApplicationContext());
+ if (storedNotes == null) {
+ storedNotes = new Db(getApplicationContext());
+ }
storedNotes.OpenDb();
- storedNotes.GetStoredNotes(noteList, accountname);
+ storedNotes.notes.GetStoredNotes(noteList, accountName);
listToView.notifyDataSetChanged();
storedNotes.CloseDb();
}
@@ -216,131 +253,167 @@ public void onReceive(Context context, Intent intent) {
}
};
- public void RefreshList(){
- ProgressDialog loadingDialog = ProgressDialog.show(this, "ImapNotes2" , "Refreshing notes list... ", true);
-
- new SyncThread().execute(this.imapFolder, Listactivity.imapNotes2Account, this.noteList, this.listToView, loadingDialog, this.storedNotes, this.getApplicationContext());
- status.setText("Welcome");
+ private void RefreshList() {
+ new SyncThread(
+ noteList,
+ listToView,
+ ShowProgress(R.string.refreshing_notes_list),
+ storedNotes,
+ this.getApplicationContext()).execute();
+ //TextView status = (TextView) findViewById(R.id.status);
+ status.setText(R.string.welcome);
}
-
- public void UpdateList(String suid, String noteBody, String color, String action){
- ProgressDialog loadingDialog = ProgressDialog.show(this, "imapnote2" , "Updating notes list... ", true);
-
- new UpdateThread().execute(this.imapFolder, Listactivity.imapNotes2Account, this.noteList, this.listToView, loadingDialog, suid, noteBody, color, this.getApplicationContext(), action, this.storedNotes);
+ private void UpdateList(String suid,
+ String noteBody,
+ Colors color,
+ UpdateThread.Action action) {
+ if (Listactivity.imapNotes2Account.usesAutomaticMerge) {
+ new UpdateThread(Listactivity.imapNotes2Account,
+ noteList,
+ listToView,
+ ShowProgress(R.string.updating_notes_list),
+ suid,
+ noteBody,
+ color,
+ getApplicationContext(),
+ action,
+ storedNotes).execute();
+ } else {
+ new UpdateThread(Listactivity.imapNotes2Account,
+ noteList,
+ listToView,
+ ShowProgress(R.string.updating_notes_list),
+ suid,
+ noteBody,
+ color,
+ getApplicationContext(),
+ action,
+ storedNotes).execute();
+ }
}
-
- public boolean onCreateOptionsMenu(Menu menu){
- getMenuInflater().inflate(R.menu.list, menu);
-
- // Associate searchable configuration with the SearchView
- SearchManager searchManager =
- (SearchManager) getSystemService(Context.SEARCH_SERVICE);
- SearchView searchView =
- (SearchView) menu.findItem(R.id.search).getActionView();
- searchView.setSearchableInfo(
- searchManager.getSearchableInfo(getComponentName()));
- SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
- @Override
- public boolean onQueryTextChange(String newText) {
- // this is your adapter that will be filtered
- listToView.getFilter().filter(newText);
- return true;
- }
-
- @Override
- public boolean onQueryTextSubmit(String query) {
- // this is your adapter that will be filtered
- listToView.getFilter().filter(query);
- return true;
- }
- };
- searchView.setOnQueryTextListener(textChangeListener);
-
- return true;
+
+ private ProgressDialog ShowProgress(int detailId) {
+ return ProgressDialog.show(this, getString(R.string.app_name),
+ getString(detailId), true);
}
-
- public boolean onOptionsItemSelected (MenuItem item){
- switch (item.getItemId()){
- case R.id.login:
- Intent res = new Intent();
- String mPackage = "com.Pau.ImapNotes2";
- String mClass = ".AccontConfigurationActivity";
- res.setComponent(new ComponentName(mPackage,mPackage+mClass));
- res.putExtra("action", "CREATE_ACCOUNT");
- startActivity(res);
- return true;
- case R.id.refresh:
- this.TriggerSync(this.status);
- return true;
- case R.id.newnote:
- Intent toNew = new Intent(this, NewNoteActivity.class);
- toNew.putExtra("usesSticky", Listactivity.imapNotes2Account.GetUsesticky());
- startActivityForResult(toNew,Listactivity.NEW_BUTTON);
- return true;
- case R.id.about:
- try {
- ComponentName comp = new ComponentName(this.getApplicationContext(), Listactivity.class);
- PackageInfo pinfo = this.getApplicationContext().getPackageManager().getPackageInfo(comp.getPackageName(), 0);
- String versionName = "Version: " + pinfo.versionName;
- String versionCode = "Code: " + String.valueOf(pinfo.versionCode);
-
- new AlertDialog.Builder(this)
- .setTitle("About ImapNotes2")
- .setMessage(versionName + "\n" + versionCode)
- .setPositiveButton("OK", new DialogInterface.OnClickListener() {
- public void onClick(DialogInterface dialog, int which) {
- // Do nothing
- }
- })
- .show();
- } catch (android.content.pm.PackageManager.NameNotFoundException e) {
- Log.d("XXXXX","except");
+
+ public boolean onCreateOptionsMenu(@NonNull Menu menu) {
+ getMenuInflater().inflate(R.menu.list, menu);
+
+ // Associate searchable configuration with the SearchView
+ SearchManager searchManager =
+ (SearchManager) getSystemService(Context.SEARCH_SERVICE);
+ SearchView searchView =
+ (SearchView) menu.findItem(R.id.search).getActionView();
+ searchView.setSearchableInfo(
+ searchManager.getSearchableInfo(getComponentName()));
+ SearchView.OnQueryTextListener textChangeListener = new SearchView.OnQueryTextListener() {
+ @Override
+ public boolean onQueryTextChange(String newText) {
+ // this is your adapter that will be filtered
+ listToView.getFilter().filter(newText);
+ return true;
+ }
+
+ @Override
+ public boolean onQueryTextSubmit(String query) {
+ // this is your adapter that will be filtered
+ listToView.getFilter().filter(query);
+ return true;
}
- return true;
- default:
- return super.onOptionsItemSelected(item);
+ };
+ searchView.setOnQueryTextListener(textChangeListener);
+
+ return true;
}
+
+ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.login:
+ Intent res = new Intent();
+ String mPackage = "com.Pau.ImapNotes2";
+ String mClass = ".AccountConfigurationActivity";
+ res.setComponent(new ComponentName(mPackage, mPackage + mClass));
+ res.putExtra(ACTION, AccountConfigurationActivity.Actions.CREATE_ACCOUNT);
+ res.putExtra(ACCOUNTNAME, Listactivity.imapNotes2Account.accountName);
+ startActivity(res);
+ return true;
+ case R.id.refresh:
+ //TextView status = (TextView) findViewById(R.id.status);
+ TriggerSync(status);
+ return true;
+ case R.id.newnote:
+ Intent toNew = new Intent(this, NewNoteActivity.class);
+ toNew.putExtra(NewNoteActivity.usesSticky, Listactivity.imapNotes2Account.usesticky);
+ startActivityForResult(toNew, Listactivity.NEW_BUTTON);
+ return true;
+ case R.id.about:
+ try {
+ ComponentName comp = new ComponentName(this.getApplicationContext(), Listactivity.class);
+ PackageInfo pinfo = this.getApplicationContext().getPackageManager().getPackageInfo(comp.getPackageName(), 0);
+ String versionName = "Version: " + pinfo.versionName;
+ String versionCode = "Code: " + String.valueOf(pinfo.versionCode);
+
+ new AlertDialog.Builder(this)
+ .setTitle("About ImapNotes2")
+ .setMessage(versionName + "\n" + versionCode)
+ .setPositiveButton("OK", new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int which) {
+ // Do nothing
+ }
+ })
+ .show();
+ } catch (android.content.pm.PackageManager.NameNotFoundException e) {
+ Log.d(TAG, "except");
+ }
+ return true;
+ default:
+ return super.onOptionsItemSelected(item);
+ }
}
-
- protected void onActivityResult(int requestCode, int resultCode, Intent data){
- switch(requestCode) {
+
+ protected void onActivityResult(int requestCode, int resultCode, @NonNull Intent data) {
+ Log.d(TAG, "onActivityResult: " + requestCode + " " + resultCode);
+ switch (requestCode) {
case Listactivity.SEE_DETAIL:
- // Returning from NoteDetailActivity
- if (resultCode == Listactivity.DELETE_BUTTON) {
- // Delete Message asked for
- // String suid will contain the Message Imap UID to delete
- String suid = data.getStringExtra("DELETE_ITEM_NUM_IMAP");
- this.UpdateList(suid, null, null, "delete");
- }
- if (resultCode == Listactivity.EDIT_BUTTON) {
- String txt = data.getStringExtra("EDIT_ITEM_TXT");
- String suid = data.getStringExtra("EDIT_ITEM_NUM_IMAP");
- String color = data.getStringExtra("EDIT_ITEM_COLOR");
- //Log.d(TAG,"Received request to delete message:"+suid);
- //Log.d(TAG,"Received request to replace message with:"+txt);
- this.UpdateList(suid, txt, color, "update");
- }
+ // Returning from NoteDetailActivity
+ if (resultCode == Listactivity.DELETE_BUTTON) {
+ // Delete Message asked for
+ // String suid will contain the Message Imap UID to delete
+ String suid = data.getStringExtra(DELETE_ITEM_NUM_IMAP);
+ this.UpdateList(suid, null, null, UpdateThread.Action.Delete);
+ }
+ if (resultCode == Listactivity.EDIT_BUTTON) {
+ String txt = data.getStringExtra(EDIT_ITEM_TXT);
+ String suid = data.getStringExtra(EDIT_ITEM_NUM_IMAP);
+ Colors color = (Colors) data.getSerializableExtra(EDIT_ITEM_COLOR);
+ //Log.d(TAG,"Received request to edit message:"+suid);
+ //Log.d(TAG,"Received request to replace message with:"+txt);
+ this.UpdateList(suid, txt, color, UpdateThread.Action.Update);
+ //TextView status = (TextView) findViewById(R.id.status);
+ TriggerSync(status);
+ }
case Listactivity.NEW_BUTTON:
- // Returning from NewNoteActivity
- if (resultCode == Listactivity.SAVE_BUTTON) {
- String res = data.getStringExtra("SAVE_ITEM");
- //Log.d(TAG,"Received request to save message:"+res);
- String color = data.getStringExtra("SAVE_ITEM_COLOR");
- this.UpdateList(null, res, color, "insert");
- }
+ // Returning from NewNoteActivity
+ if (resultCode == Listactivity.SAVE_BUTTON) {
+ String res = data.getStringExtra(SAVE_ITEM);
+ //Log.d(TAG,"Received request to save message:"+res);
+ Colors color = (Colors) data.getSerializableExtra(SAVE_ITEM_COLOR);
+ UpdateList(null, res, color, UpdateThread.Action.Insert);
+ }
}
}
// Spinner item selected listener
@Override
public void onItemSelected(AdapterView> parent, View view, int pos, long id) {
- ((TextView) this.accountSpinner.getSelectedView()).setBackgroundColor(0xFFB6B6B6);
+ (this.accountSpinner.getSelectedView()).setBackgroundColor(0xFFB6B6B6);
Account account = Listactivity.accounts[pos];
// Check periodic sync. If set to 86400 (once a day), set it to 900 (15 minutes)
// this is due to bad upgrade to v4 which handles offline mode and syncing
// Remove this code after V4.0 if version no more used
- List currentSyncs = ContentResolver.getPeriodicSyncs (account, AUTHORITY);
+ List currentSyncs = ContentResolver.getPeriodicSyncs(account, AUTHORITY);
for (PeriodicSync onesync : currentSyncs) {
if (onesync.period == 86400) {
ContentResolver.setIsSyncable(account, AUTHORITY, 1);
@@ -350,86 +423,79 @@ public void onItemSelected(AdapterView> parent, View view, int pos, long id) {
Toast.LENGTH_LONG).show();
}
}
- // End of code
- Listactivity.imapNotes2Account.SetAccountname(account.name);
- Listactivity.imapNotes2Account.SetUsername(Listactivity.accountManager.getUserData (account, "username"));
- String pwd = Listactivity.accountManager.getPassword(account);
- Listactivity.imapNotes2Account.SetPassword(pwd);
- Listactivity.imapNotes2Account.SetServer(Listactivity.accountManager.getUserData (account, "server"));
- Listactivity.imapNotes2Account.SetPortnum(Listactivity.accountManager.getUserData (account, "portnum"));
- Listactivity.imapNotes2Account.SetSecurity(Listactivity.accountManager.getUserData (account, "security"));
- Listactivity.imapNotes2Account.SetUsesticky(accountManager.getUserData (account, "usesticky"));
- Listactivity.imapNotes2Account.SetSyncinterval(Listactivity.accountManager.getUserData (account, "syncinterval"));
- Listactivity.imapNotes2Account.SetaccountHasChanged();
- Listactivity.imapNotes2Account.SetAccount(account);
+
+ Listactivity.imapNotes2Account = new ImapNotes2Account(account, getApplicationContext());
this.RefreshList();
}
-
+
@Override
public void onNothingSelected(AdapterView> parent) {
// TODO Auto-generated method stub
-
+
}
- private void updateAccountSpinner () {
+ private void updateAccountSpinner() {
this.spinnerList.notifyDataSetChanged();
//this.accountSpinner.setSelection(spinnerList.getPosition(currentAccountname));
if (this.accountSpinner.getSelectedItemId() == android.widget.AdapterView.INVALID_ROW_ID) {
- this.accountSpinner.setSelection(0);
+ this.accountSpinner.setSelection(0);
}
-
+
if (Listactivity.currentList.size() == 1) {
Account account = Listactivity.accounts[0];
- Listactivity.imapNotes2Account.SetUsername(Listactivity.accountManager.getUserData (account, "username"));
+ Listactivity.imapNotes2Account = new ImapNotes2Account(account, getApplicationContext());
+/* imapNotes2Account.SetUsername(Listactivity.accountManager.getUserData(account, ConfigurationFieldNames.UserName));
String pwd = Listactivity.accountManager.getPassword(account);
- Listactivity.imapNotes2Account.SetPassword(pwd);
- Listactivity.imapNotes2Account.SetServer(Listactivity.accountManager.getUserData (account, "server"));
- Listactivity.imapNotes2Account.SetPortnum(Listactivity.accountManager.getUserData (account, "portnum"));
- Listactivity.imapNotes2Account.SetSecurity(Listactivity.accountManager.getUserData (account, "security"));
- Listactivity.imapNotes2Account.SetUsesticky(accountManager.getUserData (account, "usesticky"));
- Listactivity.imapNotes2Account.SetSyncinterval(Listactivity.accountManager.getUserData (account, "syncinterval"));
- Listactivity.imapNotes2Account.SetaccountHasChanged();
+ imapNotes2Account.SetPassword(pwd);
+ imapNotes2Account.SetServer(Listactivity.accountManager.getUserData(account, ConfigurationFieldNames.Server));
+ imapNotes2Account.SetPortnum(Listactivity.accountManager.getUserData(account, ConfigurationFieldNames.PortNumber));
+ imapNotes2Account.SetSecurity(Listactivity.accountManager.getUserData(account, ConfigurationFieldNames.Security));
+ imapNotes2Account.SetUsesticky("true".equals(accountManager.getUserData(account, ConfigurationFieldNames.UseSticky)));
+ imapNotes2Account.SetSyncinterval(Listactivity.accountManager.getUserData(account, ConfigurationFieldNames.SyncInterval));
+ //imapNotes2Account.SetaccountHasChanged();
+ */
}
}
private class AccountsUpdateListener implements OnAccountsUpdateListener {
private ArrayList newAccounts;
-
+
@Override
- public void onAccountsUpdated(Account[] accounts) {
+ public void onAccountsUpdated(@NonNull Account[] accounts) {
List newList;
- Integer newListSize = 0;
+ //Integer newListSize = 0;
//invoked when the AccountManager starts up and whenever the account set changes
- this.newAccounts = new ArrayList();
+ this.newAccounts = new ArrayList<>();
for (final Account account : accounts) {
if (account.type.equals("com.Pau.ImapNotes2")) {
this.newAccounts.add(account);
}
}
if (this.newAccounts.size() > 0) {
- Account[] imapNotes2Accounts = new Account[this.newAccounts.size()] ;
+ Account[] imapNotes2Accounts = new Account[this.newAccounts.size()];
int i = 0;
for (final Account account : this.newAccounts) {
imapNotes2Accounts[i] = account;
i++;
}
Listactivity.accounts = imapNotes2Accounts;
- newList = new ArrayList();
- for (Account account: Listactivity.accounts ) {
+ newList = new ArrayList<>();
+ for (Account account : Listactivity.accounts) {
newList.add(account.name);
}
if (newList.size() == 0) return;
-
+
Boolean equalLists = true;
ListIterator iter = Listactivity.currentList.listIterator();
- while(iter.hasNext()){
+ while (iter.hasNext()) {
String s = iter.next();
if (!(newList.contains(s))) {
iter.remove();
- String stringDir = (ImapNotes2.getAppContext()).getFilesDir() + "/" + s;
+ // Why try here?
try {
- FileUtils.deleteDirectory(new File (stringDir));
+ String stringDir = ImapNotes2k.ConfigurationDirPath(getApplicationContext()) + "/" + s;
+ FileUtils.deleteDirectory(new File(stringDir));
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -437,18 +503,18 @@ public void onAccountsUpdated(Account[] accounts) {
equalLists = false;
}
}
- for (String accountName: newList ) {
+ for (String accountName : newList) {
if (!(Listactivity.currentList.contains(accountName))) {
Listactivity.currentList.add(accountName);
- SyncUtils.CreateDirs (accountName, ImapNotes2.getAppContext());
-
+ SyncUtils.CreateLocalDirectories(accountName, getApplicationContext());
+
equalLists = false;
}
}
if (equalLists) return;
updateAccountSpinner();
} else {
- File filesDir = (ImapNotes2.getAppContext()).getFilesDir();
+ File filesDir = ImapNotes2k.ConfigurationDir(getApplicationContext());
try {
FileUtils.cleanDirectory(filesDir);
} catch (IOException e) {
@@ -457,48 +523,50 @@ public void onAccountsUpdated(Account[] accounts) {
}
Intent res = new Intent();
String mPackage = "com.Pau.ImapNotes2";
- String mClass = ".AccontConfigurationActivity";
- res.setComponent(new ComponentName(mPackage,mPackage+mClass));
+ String mClass = ".AccountConfigurationActivity";
+ res.setComponent(new ComponentName(mPackage, mPackage + mClass));
startActivity(res);
}
}
}
- // In case of neccessary debug with user approval
- // This function will be called from onDestroy
- public void SendLogcatMail(){
- String emailData="";
- try {
- Process process = Runtime.getRuntime().exec("logcat -d");
- BufferedReader bufferedReader = new BufferedReader(
- new InputStreamReader(process.getInputStream()));
-
- StringBuilder sb=new StringBuilder();
- String line;
- while ((line = bufferedReader.readLine()) != null) {
- sb.append(line + "\n");
- }
- emailData=sb.toString();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- //send file using email
- Intent emailIntent = new Intent(Intent.ACTION_SEND);
- String to[] = {"nb@dagami.org"};
- emailIntent .putExtra(Intent.EXTRA_EMAIL, to);
- // the attachment
- emailIntent .putExtra(Intent.EXTRA_TEXT, emailData);
- // the mail subject
- emailIntent .putExtra(Intent.EXTRA_SUBJECT, "Logcat content for ImapNotes2 debugging");
- emailIntent.setType("message/rfc822");
- startActivity(Intent.createChooser(emailIntent , "Send email..."));
- }
-
- public static void TriggerSync(TextView statusField) {
- OldStatus=statusField.getText().toString();
- statusField.setText("Syncing...");
+// --Commented out by Inspection START (12/2/16 8:49 PM):
+// // In case of neccessary debug with user approval
+// // This function will be called from onDestroy
+// public void SendLogcatMail() {
+// String emailData = "";
+// try {
+// Process process = Runtime.getRuntime().exec("logcat -d");
+// BufferedReader bufferedReader = new BufferedReader(
+// new InputStreamReader(process.getInputStream()));
+//
+// StringBuilder sb = new StringBuilder();
+// String line;
+// while ((line = bufferedReader.readLine()) != null) {
+// sb.append(line).append("\n");
+// }
+// emailData = sb.toString();
+// } catch (IOException e) {
+// // TODO Auto-generated catch block
+// e.printStackTrace();
+// }
+//
+// //send file using email
+// Intent emailIntent = new Intent(Intent.ACTION_SEND);
+// String to[] = {"nb@dagami.org"};
+// emailIntent.putExtra(Intent.EXTRA_EMAIL, to);
+// // the attachment
+// emailIntent.putExtra(Intent.EXTRA_TEXT, emailData);
+// // the mail subject
+// emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Logcat content for ImapNotes2 debugging");
+// emailIntent.setType("message/rfc822");
+// startActivity(Intent.createChooser(emailIntent, "Send email..."));
+// }
+// --Commented out by Inspection STOP (12/2/16 8:49 PM)
+
+ private static void TriggerSync(@NonNull TextView statusField) {
+ OldStatus = statusField.getText().toString();
+ statusField.setText(R.string.syncing);
Account mAccount = Listactivity.imapNotes2Account.GetAccount();
Bundle settingsBundle = new Bundle();
settingsBundle.putBoolean(
@@ -509,9 +577,10 @@ public static void TriggerSync(TextView statusField) {
ContentResolver.requestSync(mAccount, AUTHORITY, settingsBundle);
}
- @Override
- public Filter getFilter() {
- return null;
- }
+ @Nullable
+ @Override
+ public Filter getFilter() {
+ return null;
+ }
}
-
+
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Merge/M.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Merge/M.java
new file mode 100644
index 00000000..7e0b2289
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Merge/M.java
@@ -0,0 +1,76 @@
+package com.Pau.ImapNotes2.Merge;
+
+class M {
+
+
+ /* // takes 2 indexable objects (e.g. strings or lists)
+// returns a list of Change objects (Delete or Insert)
+// guaranteed to produce an optimal diff
+ List str_diff(String a,
+ String b) {
+ ls = len(a);
+ lf = len(b);
+ memo = emptyDictionaryOfWhat;
+
+ WhatType min_diff ( int si,
+ int fi){
+ if (si,fi)in memo:
+ return memo[(si,fi)]
+ ans =[]
+ if si == ls and fi==lf:
+ ans =[]
+ elif si 0:
+ pos_a = pos_a_old
+ range_b_0 = pos_a_old + offset_b
+ range_b_1 = pos_a_old + offset_b + length
+ changes.append(Insert(b[range_b_0:range_b_1],pos_a, (range_b_0, range_b_1)))
+ offset_b += length
+ if pos_diff >= len(diff):
+ break
+ length=0
+ pos_a_old = diff[pos_diff][0]
+ while pos_diff 0:
+ range_a_0 = pos_a_old
+ range_a_1 = pos_a_old + length
+ pos_b = pos_a_old + offset_b
+ changes.append(Delete(a[range_a_0:range_a_1],(range_a_0, range_a_1),pos_b))
+ offset_b -= length
+ }
+
+ return changes
+ }
+*/
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotes2Result.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotes2Result.java
index 8a3b7856..45fff870 100644
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotes2Result.java
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotes2Result.java
@@ -1,20 +1,38 @@
package com.Pau.ImapNotes2.Miscs;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+
import javax.mail.Folder;
public class ImapNotes2Result {
- public int returnCode;
- public String errorMessage;
- public Long UIDValidity;
- public boolean hasUIDPLUS;
- public Folder notesFolder;
-
- public ImapNotes2Result () {
- returnCode = -1;
- errorMessage = "";
- UIDValidity = (long) -1;
- hasUIDPLUS = true;
- notesFolder = null;
- }
+ public final int returnCode;
+ @NonNull
+ public final String errorMessage;
+ public final Long UIDValidity;
+ // --Commented out by Inspection (11/26/16 11:45 PM):public boolean hasUIDPLUS;
+ @Nullable
+ public final Folder notesFolder;
+
+ public ImapNotes2Result(int returnCode,
+ String errorMessage,
+ long UIDValidity,
+ Folder notesFolder) {
+ this.returnCode = returnCode;
+ this.errorMessage = errorMessage ;
+ this.UIDValidity = UIDValidity ;
+ this.notesFolder = notesFolder;
+ }
+
+/*
+ public ImapNotes2Result() {
+ returnCode = -1;
+ errorMessage = "";
+ UIDValidity = (long) -1;
+ //hasUIDPLUS = true;
+ notesFolder = null;
+ }
+*/
+
}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotesAuthenticatorService.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotesAuthenticatorService.java
deleted file mode 100644
index 6e71bd62..00000000
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/ImapNotesAuthenticatorService.java
+++ /dev/null
@@ -1,113 +0,0 @@
-package com.Pau.ImapNotes2.Miscs;
-
-import com.Pau.ImapNotes2.AccontConfigurationActivity;
-import com.Pau.ImapNotes2.Sync.SyncUtils;
-
-import android.accounts.AbstractAccountAuthenticator;
-import android.accounts.Account;
-import android.accounts.AccountAuthenticatorResponse;
-import android.accounts.AccountManager;
-import android.accounts.NetworkErrorException;
-import android.app.Service;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Bundle;
-import android.os.IBinder;
-
-public class ImapNotesAuthenticatorService extends Service{
-
- private static final String TAG = "ImapNotesAuthenticationService";
- private Authenticator imapNotesAuthenticator;
-
- @Override
- public void onCreate() {
- this.imapNotesAuthenticator = new Authenticator(this);
- }
-
- public IBinder onBind(Intent intent) {
- IBinder ret = null;
- if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT))
- ret = getAuthenticator().getIBinder();
-
- return ret;
- }
-
- private Authenticator getAuthenticator() {
- if (this.imapNotesAuthenticator == null)
- this.imapNotesAuthenticator = new Authenticator(this);
-
- return this.imapNotesAuthenticator;
- }
-
- private static class Authenticator extends AbstractAccountAuthenticator {
-
- private Context mContext;
-
- public Authenticator(Context context) {
- super(context);
- this.mContext = context;
- }
-
- @Override
- public Bundle getAccountRemovalAllowed(
- AccountAuthenticatorResponse response, Account account)
- throws NetworkErrorException {
- Bundle ret = super.getAccountRemovalAllowed(response, account);
- if (ret.getBoolean(AccountManager.KEY_BOOLEAN_RESULT))
- SyncUtils.RemoveAccount(this.mContext, account);
-/*
- mContext.getContentResolver().delete(ListProvider.getClearUri(),
- null, null);
-*/
- return ret;
- }
- @Override
- public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
-
- Intent toLoginActivity = new Intent(this.mContext, AccontConfigurationActivity.class);
- toLoginActivity.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
- Bundle bundle = new Bundle();
- bundle.putParcelable(AccountManager.KEY_INTENT, toLoginActivity);
-
- return bundle;
- }
-
- @Override
- public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) throws NetworkErrorException {
-
- return null;
- }
-
- @Override
- public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) {
-
- return null;
- }
-
- @Override
- public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
-
- return null;
- }
-
- @Override
- public String getAuthTokenLabel(String authTokenType) {
-
- return null;
- }
-
- @Override
- public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException {
-
- return null;
- }
-
- @Override
- public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
-
- return null;
- }
-
- }
-
-}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Imaper.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Imaper.java
index d6f89bfe..4825cf64 100644
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Imaper.java
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Imaper.java
@@ -1,126 +1,85 @@
package com.Pau.ImapNotes2.Miscs;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
+import android.support.annotation.NonNull;
+import android.util.Log;
+
+import com.Pau.ImapNotes2.Data.Security;
+import com.sun.mail.util.MailSSLSocketFactory;
+
import java.security.GeneralSecurityException;
-import java.util.ArrayList;
import java.util.Properties;
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.util.Log;
-import javax.mail.Folder;
-import javax.mail.Message;
+
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Store;
-import javax.mail.Flags;
-import com.sun.mail.imap.IMAPFolder;
-import com.sun.mail.imap.IMAPStore;
-import com.sun.mail.util.MailSSLSocketFactory;
-import java.util.regex.*;
-
-import com.Pau.ImapNotes2.Miscs.Sticky;
-import com.Pau.ImapNotes2.ImapNotes2;
-import com.Pau.ImapNotes2.Listactivity;
-import com.Pau.ImapNotes2.Miscs.ImapNotes2Result;
public class Imaper {
-
- private Store store;
- private Session session;
- private static final String TAG = "IN_Imaper";
- private String proto;
- private String acceptcrt;
- private static String sfolder = "Notes";
- private String folderoverride;
- private Folder notesFolder = null;
- private ImapNotes2Result res;
- private Long UIDValidity;
-private Boolean useProxy = false;
-public static final String PREFS_NAME = "PrefsFile";
-
- public ImapNotes2Result ConnectToProvider(String username, String password, String server, String portnum, String security, String usesticky, String override) throws MessagingException{
- if (this.IsConnected())
- this.store.close();
-
- res = new ImapNotes2Result();
- if (override==null) {
- this.folderoverride = "";
- } else {
- this.folderoverride = override;
- }
- this.proto = "";
- this.acceptcrt = "";
- int security_i = Integer.parseInt(security);
- switch (security_i) {
- case 0:
- // None
- this.proto = "imap";
- this.acceptcrt = "";
- break;
- case 1:
- // SSL/TLS
- this.proto = "imaps";
- this.acceptcrt = "false";
- break;
- case 2:
- // SSL/TLS/TRUST ALL
- this.proto = "imaps";
- this.acceptcrt = "true";
- break;
- case 3:
- // STARTTLS
- this.proto = "imap";
- this.acceptcrt = "false";
- break;
- case 4:
- // STARTTLS/TRUST ALL
- this.proto = "imap";
- this.acceptcrt = "true";
- break;
-////////////////////// Change this
- default: this.proto = "Invalid proto";
- break;
- }
- MailSSLSocketFactory sf = null;
- try {
- sf = new MailSSLSocketFactory();
- } catch (GeneralSecurityException e) {
- e.printStackTrace();
- this.res.errorMessage = "Can't connect to server";
- this.res.returnCode = -1;
- return this.res;
- }
- Properties props = new Properties();
-
- props.setProperty(String.format("mail.%s.host", this.proto), server);
- props.setProperty(String.format("mail.%s.port", this.proto), portnum);
- props.setProperty("mail.store.protocol", this.proto);
-
- if ((this.acceptcrt.equals("true"))) {
- sf.setTrustedHosts(new String[] {server});
- if (this.proto.equals("imap")) {
- props.put("mail.imap.ssl.socketFactory", sf);
- props.put("mail.imap.starttls.enable", "true");
- }
- } else if (this.acceptcrt.equals("false")) {
- props.put(String.format("mail.%s.ssl.checkserveridentity", this.proto), "true");
- if (this.proto.equals("imap")) {
- props.put("mail.imap.starttls.enable", "true");
- }
- }
+ private Store store;
+ private static final String TAG = "IN_Imaper";
- if (this.proto.equals("imaps")) {
- props.put("mail.imaps.socketFactory", sf);
- }
+ // --Commented out by Inspection (11/26/16 11:43 PM):public static final String PREFS_NAME = "PrefsFile";
+
+ public static final int ResultCodeSuccess = 0;
+ public static final int ResultCodeException = -2;
+ public static final int ResultCodeCantConnect = -1;
- props.setProperty("mail.imap.connectiontimeout","1000");
- if (this.useProxy) {
- props.put("mail.imap.socks.host","10.0.2.2");
- props.put("mail.imap.socks.port","1080");
+
+
+ @NonNull
+ public ImapNotes2Result ConnectToProvider(String username,
+ String password,
+ String server,
+ String portnum,
+ @NonNull Security security) throws MessagingException {
+ if (IsConnected()) {
+ store.close();
+ }
+
+ MailSSLSocketFactory sf;
+ try {
+ sf = new MailSSLSocketFactory();
+ } catch (GeneralSecurityException e) {
+ e.printStackTrace();
+ return new ImapNotes2Result(-1,
+ "Can't connect to server",
+ -1,
+ null);
+ }
+
+ String proto = security.proto;
+
+ Properties props = new Properties();
+
+ props.setProperty(String.format("mail.%s.host", proto), server);
+ props.setProperty(String.format("mail.%s.port", proto), portnum);
+ props.setProperty("mail.store.protocol", proto);
+
+ if (security.acceptcrt) {
+ sf.setTrustedHosts(new String[]{server});
+ if (proto.equals("imap")) {
+ props.put("mail.imap.ssl.socketFactory", sf);
+ props.put("mail.imap.starttls.enable", "true");
+ }
+ } else if (security != Security.None) {
+ props.put(String.format("mail.%s.ssl.checkserveridentity", proto), "true");
+ if (proto.equals("imap")) {
+ props.put("mail.imap.starttls.enable", "true");
+ }
+ }
+
+ if (proto.equals("imaps")) {
+ props.put("mail.imaps.socketFactory", sf);
+ }
+
+ props.setProperty("mail.imap.connectiontimeout", "1000");
+ Boolean useProxy = false;
+ //noinspection ConstantConditions
+ // TODO: implement proxy handling properly.
+ //noinspection ConstantConditions,ConstantConditions
+ if (useProxy) {
+ props.put("mail.imap.socks.host", "10.0.2.2");
+ props.put("mail.imap.socks.port", "1080");
/*
props.put("proxySet","true");
props.put("socksProxyHost","10.0.2.2");
@@ -128,58 +87,29 @@ public ImapNotes2Result ConnectToProvider(String username, String password, Stri
props.put("sun.net.spi.nameservice.provider.1", "dns,sun");
props.put("sun.net.spi.nameservice.nameservers", "192.168.0.99");
*/
- }
- this.session = Session.getInstance(props, null);
-//this.session.setDebug(true);
- this.store = this.session.getStore(this.proto);
- try {
- this.store.connect(server, username, password);
-Boolean hasUIDPLUS = ((IMAPStore) this.store).hasCapability("UIDPLUS");
-//Log.d(TAG, "has UIDPLUS="+hasUIDPLUS);
-
- Folder[] folders = store.getPersonalNamespaces();
- Folder folder = folders[0];
-//Log.d(TAG,"Personal Namespaces="+folder.getFullName());
- if (this.folderoverride.length() > 0) {
- Imaper.sfolder = this.folderoverride;
- } else if (folder.getFullName().length() == 0) {
- Imaper.sfolder = "Notes";
- } else {
- char separator = folder.getSeparator();
- Imaper.sfolder = folder.getFullName() + separator + "Notes";
- }
- this.res.errorMessage = "";
- this.res.returnCode = 0;
- return this.res;
- } catch (Exception e) {
- e.printStackTrace();
- Log.d(TAG, e.getMessage());
- this.res.errorMessage = e.getMessage();
- this.res.returnCode = -2;
- return this.res;
+ }
+ Session session = Session.getInstance(props, null);
+//session.setDebug(true);
+ store = session.getStore(proto);
+ try {
+ store.connect(server, username, password);
+
+ return new ImapNotes2Result(ResultCodeSuccess,
+ "",
+ -1,
+ null);
+ } catch (Exception e) {
+ e.printStackTrace();
+ Log.d(TAG, e.getMessage());
+ return new ImapNotes2Result(ResultCodeException,
+ e.getMessage(),
+ -1,
+ null);
+ }
}
- }
-
- public boolean IsConnected(){
- return this.store!=null && this.store.isConnected();
- }
-
- // Put values in shared preferences:
- public void SetPrefs() {
- SharedPreferences preferences = ImapNotes2.getAppContext().getSharedPreferences(Listactivity.imapNotes2Account.GetAccountname(), Context.MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- editor.putString("Name","valid_data");
- editor.putLong("UIDValidity", this.UIDValidity);
- editor.apply();
- }
-
- // Retrieve values from shared preferences:
- public void GetPrefs() {
- SharedPreferences preferences = (ImapNotes2.getAppContext()).getSharedPreferences(Listactivity.imapNotes2Account.GetAccountname(), Context.MODE_PRIVATE);
- String name = preferences.getString("Name", "");
- if(!name.equalsIgnoreCase("")) {
- this.UIDValidity = preferences.getLong("UIDValidity", -1);
+ private boolean IsConnected() {
+ return store != null && store.isConnected();
}
- }
+
}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/OneNote.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/OneNote.java
deleted file mode 100644
index 144fd431..00000000
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/OneNote.java
+++ /dev/null
@@ -1,58 +0,0 @@
-package com.Pau.ImapNotes2.Miscs;
-
-import java.util.HashMap;
-
-public class OneNote extends HashMap{
-
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- public OneNote(){
- super();
- this.put("title", "No Title");
- this.put("date", "No Date");
- this.put("uid", "0");
-
- }
-
- public OneNote(String title, String date, String uid){
- super();
- this.put("title", title);
- this.put("date", date);
- this.put("uid", uid);
-
- }
-
- public String GetTitle(){
- return this.get("title");
- }
-
- public String GetDate(){
- return this.get("date");
- }
-
- public String GetUid(){
- return this.get("uid");
- }
-
- public void SetTitle(String title){
- this.put("title", title);
- }
-
- public void SetDate(String date){
- this.put("date", date);
- }
-
- public void SetUid(String uid){
- this.put("uid", uid);
- }
-
- @Override
- public String toString() {
- return ("Title:"+this.GetTitle()+
- " Date: "+ this.GetDate() +
- " Uid: "+ this.GetUid());
- }
-}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Result.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Result.java
new file mode 100644
index 00000000..b2232de6
--- /dev/null
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Result.java
@@ -0,0 +1,24 @@
+package com.Pau.ImapNotes2.Miscs;
+
+/**
+ * Created by kj on 2017-02-15 10:12.
+ * Simple class to allow functions to return a value and a status as a single object.
+ * @param the type parameter
+ */
+public class Result {
+ /**
+ * The result can be any type, usually a String or number.
+ */
+ public final T result;
+ /**
+ * True if the result is valid, else false.
+ */
+ public final boolean succeeded;
+
+
+ public Result(T result,
+ boolean succeeded){
+ this.result = result;
+ this.succeeded = succeeded;
+ }
+}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Sticky.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Sticky.java
index 346ad5f4..5c0f986b 100644
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Sticky.java
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/Sticky.java
@@ -1,44 +1,44 @@
package com.Pau.ImapNotes2.Miscs;
+import android.support.annotation.NonNull;
+
+import static com.Pau.ImapNotes2.NoteDetailActivity.Colors;
+
public class Sticky {
- private static String text;
- private static String position;
- private static String color;
-
- public Sticky() {
- Sticky.text = "";
- Sticky.position = "0 0 0 0";
- Sticky.color = "YELLOW";
- }
-
- public Sticky(String text, String position, String color) {
- Sticky.text = text;
- Sticky.position = position;
- Sticky.color = color;
- }
-
- public String GetPosition(){
- return Sticky.position;
- }
-
- public String GetText(){
- return Sticky.text;
- }
-
- public String GetColor(){
- return Sticky.color;
- }
-
- public void SetText(String text){
- Sticky.text = text;
- }
-
- public void SetPosition(String position){
- Sticky.position = position;
- }
-
- public void SetColor(String color){
- Sticky.color = color;
- }
+ public final String text;
+ // --Commented out by Inspection (11/26/16 11:50 PM):private final String position;
+ @NonNull
+ public final Colors color;
+
+ public Sticky(String text,
+ @NonNull Colors color) {
+ this.text = text;
+ // this.position = position;
+ this.color = color;
+ }
+/*
+ public String GetPosition() {
+ return Sticky.position;
+ }
+
+ public String GetText() {
+ return Sticky.text;
+ }
+
+ public Colors GetColor() {
+ return Sticky.color;
+ }
+
+ public void SetText(String text) {
+ Sticky.text = text;
+ }
+
+ public void SetPosition(String position) {
+ Sticky.position = position;
+ }
+
+ public void SetColor(Colors color) {
+ Sticky.color = color;
+ }*/
}
diff --git a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/SyncThread.java b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/SyncThread.java
index c1096fbc..5f9616ff 100644
--- a/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/SyncThread.java
+++ b/ImapNote2/src/main/java/com/Pau/ImapNotes2/Miscs/SyncThread.java
@@ -1,58 +1,88 @@
package com.Pau.ImapNotes2.Miscs;
-import java.util.ArrayList;
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.os.AsyncTask;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import com.Pau.ImapNotes2.Data.Db;
+import com.Pau.ImapNotes2.Data.OneNote;
import com.Pau.ImapNotes2.Listactivity;
import com.Pau.ImapNotes2.NotesListAdapter;
-import com.Pau.ImapNotes2.Data.ImapNotes2Account;
-import com.Pau.ImapNotes2.Data.NotesDb;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.os.AsyncTask;
-import android.util.Log;
-import android.widget.SimpleAdapter;
-import android.widget.Toast;
+import java.util.ArrayList;
+
+//import com.Pau.ImapNotes2.Data.NotesDb;
public class SyncThread extends AsyncTask