From a7454223008c78dcf5e0ff727bca64241f99daa1 Mon Sep 17 00:00:00 2001 From: steckbrief Date: Thu, 10 Dec 2015 20:01:50 +0100 Subject: Moved logcat to a module, increased error robustness for loading last messages --- README.md | 6 +- build.gradle | 1 + libs/SwipyRefreshLayout/build.gradle | 2 +- libs/thedevstacklogcat/.gitignore | 1 + libs/thedevstacklogcat/build.gradle | 25 ++++ libs/thedevstacklogcat/proguard-rules.pro | 17 +++ .../android/logcat/ApplicationTest.java | 13 ++ .../thedevstacklogcat/src/main/AndroidManifest.xml | 4 + .../de/thedevstack/android/logcat/Logging.java | 148 +++++++++++++++++++++ .../logcat/adapters/LogCatArrayAdapter.java | 122 +++++++++++++++++ .../android/logcat/tasks/ReadLogCatAsyncTask.java | 105 +++++++++++++++ .../logcat/ui/LogCatOutputCopyOnClickListener.java | 42 ++++++ .../src/main/res/values/strings.xml | 3 + .../android/logcat/ExampleUnitTest.java | 15 +++ settings.gradle | 2 +- src/main/AndroidManifest.xml | 2 +- .../logcat/adapters/LogCatArrayAdapter.java | 122 ----------------- .../android/logcat/tasks/ReadLogCatAsyncTask.java | 67 ---------- .../android/logcat/ui/LogCatOutputActivity.java | 27 ---- .../logcat/ui/LogCatOutputCopyOnClickListener.java | 42 ------ .../conversationsplus/crypto/OtrService.java | 2 +- .../entities/DownloadableFile.java | 3 +- .../http/HttpDownloadConnection.java | 2 +- .../http/HttpUploadConnection.java | 2 +- .../conversationsplus/parser/IqParser.java | 3 +- .../conversationsplus/parser/MessageParser.java | 2 +- .../persistance/DatabaseBackend.java | 2 +- .../conversationsplus/persistance/FileBackend.java | 2 +- .../services/MessageArchiveService.java | 3 +- .../services/XmppConnectionService.java | 3 +- .../conversationsplus/ui/LogCatOutputActivity.java | 28 ++++ .../ui/StartConversationActivity.java | 2 +- .../conversationsplus/ui/XmppActivity.java | 2 +- .../ui/adapter/ConversationAdapter.java | 2 +- .../ui/dialogs/MessageDetailsDialog.java | 2 +- .../ConversationSwipeRefreshListener.java | 48 +++++-- .../ui/preferences/LogInformationPreference.java | 2 +- .../conversationsplus/utils/AvatarUtil.java | 2 +- .../conversationsplus/utils/DNSHelper.java | 7 +- .../conversationsplus/utils/ExceptionHelper.java | 2 +- .../conversationsplus/utils/ExifHelper.java | 2 +- .../conversationsplus/utils/ImageUtil.java | 2 +- .../conversationsplus/utils/Logging.java | 124 ----------------- .../conversationsplus/utils/PRNGFixes.java | 3 +- .../thedevstack/conversationsplus/xml/Element.java | 3 +- .../conversationsplus/xml/XmlReader.java | 2 +- .../conversationsplus/xmpp/XmppConnection.java | 2 +- .../xmpp/jingle/JingleConnection.java | 3 +- .../xmpp/jingle/JingleConnectionManager.java | 3 +- .../xmpp/jingle/JingleInbandTransport.java | 2 +- .../xmpp/jingle/JingleSocks5Transport.java | 3 +- src/main/java/de/tzur/conversations/Settings.java | 2 +- 52 files changed, 602 insertions(+), 436 deletions(-) create mode 100644 libs/thedevstacklogcat/.gitignore create mode 100644 libs/thedevstacklogcat/build.gradle create mode 100644 libs/thedevstacklogcat/proguard-rules.pro create mode 100644 libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java create mode 100644 libs/thedevstacklogcat/src/main/AndroidManifest.xml create mode 100644 libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java create mode 100644 libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java create mode 100644 libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java create mode 100644 libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java create mode 100644 libs/thedevstacklogcat/src/main/res/values/strings.xml create mode 100644 libs/thedevstacklogcat/src/test/java/de/thedevstack/android/logcat/ExampleUnitTest.java delete mode 100644 src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java delete mode 100644 src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java delete mode 100644 src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java delete mode 100644 src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java create mode 100644 src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java delete mode 100644 src/main/java/de/thedevstack/conversationsplus/utils/Logging.java diff --git a/README.md b/README.md index 459903ea..d1a37a6c 100644 --- a/README.md +++ b/README.md @@ -9,14 +9,18 @@ Of course Conversations+ supports [all features of Conversations](https://github * smileys like Whatsapp * change of LED notification color * online status in contact and conversation list +* Manual loading of last messages from MAM +* Sending of original images ## Modifications * unread count badges take care of setting "Conference notifications" * swipe to end conversation only in one direction * replace ASCII-smileys +* Swipe to refresh for loading archived messages using MAM * settings * confirmation for received and/or read messages * automatically download picture links * automatically download only when wifi enabled -* bugfixes and code improvements + * sending original or resized images +* bugfixes and code improvements \ No newline at end of file diff --git a/build.gradle b/build.gradle index 6d29e517..b79f91e2 100644 --- a/build.gradle +++ b/build.gradle @@ -39,6 +39,7 @@ dependencies { compile project(':libs:emojicon') compile project(':libs:colorpicker') compile project(':libs:SwipyRefreshLayout') + compile project(':libs:thedevstacklogcat') } android { diff --git a/libs/SwipyRefreshLayout/build.gradle b/libs/SwipyRefreshLayout/build.gradle index 68a75ec9..79f47d55 100644 --- a/libs/SwipyRefreshLayout/build.gradle +++ b/libs/SwipyRefreshLayout/build.gradle @@ -20,5 +20,5 @@ android { dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) - compile 'com.android.support:appcompat-v7:22.0.+' + compile 'com.android.support:appcompat-v7:22.2.1' } diff --git a/libs/thedevstacklogcat/.gitignore b/libs/thedevstacklogcat/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/libs/thedevstacklogcat/.gitignore @@ -0,0 +1 @@ +/build diff --git a/libs/thedevstacklogcat/build.gradle b/libs/thedevstacklogcat/build.gradle new file mode 100644 index 00000000..27db48ea --- /dev/null +++ b/libs/thedevstacklogcat/build.gradle @@ -0,0 +1,25 @@ +apply plugin: 'com.android.library' + +android { + compileSdkVersion 22 + buildToolsVersion "22.0.1" + + defaultConfig { + minSdkVersion 14 + targetSdkVersion 22 + versionCode 1 + versionName "1.0" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + testCompile 'junit:junit:4.12' + compile 'com.android.support:appcompat-v7:22.2.1' +} diff --git a/libs/thedevstacklogcat/proguard-rules.pro b/libs/thedevstacklogcat/proguard-rules.pro new file mode 100644 index 00000000..077398be --- /dev/null +++ b/libs/thedevstacklogcat/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in C:\Users\tzur\AppData\Local\Android\Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java b/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java new file mode 100644 index 00000000..2e381ee7 --- /dev/null +++ b/libs/thedevstacklogcat/src/androidTest/java/de/thedevstack/android/logcat/ApplicationTest.java @@ -0,0 +1,13 @@ +package de.thedevstack.android.logcat; + +import android.app.Application; +import android.test.ApplicationTestCase; + +/** + * Testing Fundamentals + */ +public class ApplicationTest extends ApplicationTestCase { + public ApplicationTest() { + super(Application.class); + } +} \ No newline at end of file diff --git a/libs/thedevstacklogcat/src/main/AndroidManifest.xml b/libs/thedevstacklogcat/src/main/AndroidManifest.xml new file mode 100644 index 00000000..59448708 --- /dev/null +++ b/libs/thedevstacklogcat/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java new file mode 100644 index 00000000..6af7a70e --- /dev/null +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/Logging.java @@ -0,0 +1,148 @@ +package de.thedevstack.android.logcat; + +import android.util.Log; + +/** + * Utility class to prefix every log tag. + * This can be used for better filtering in the log cat output activity. + */ +public class Logging { + /** + * The prefix for every log tag. + */ + protected static String LOG_TAG_PREFIX = "thedevstack."; + + /** + * Changes the default log tag prefix. + * The default value is thedevstack. + * @param logTagPrefix the new log tag prefix to use + */ + public static void initLogTagPrefix(String logTagPrefix) { + if (null != logTagPrefix) { + LOG_TAG_PREFIX = logTagPrefix; + } + } + + /** + * Returns the current log tag prefix. + * @return value of Logging.LOG_TAG_PREFIX + */ + public static String getLogTagPrefix() { + return LOG_TAG_PREFIX; + } + + /** + * Send a {@link Log#VERBOSE} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int v(String tag, String msg) { + return Log.v(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#VERBOSE} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int v(String tag, String msg, Throwable tr) { + return Log.v(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send a {@link Log#DEBUG} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int d(String tag, String msg) { + return Log.d(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#DEBUG} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int d(String tag, String msg, Throwable tr) { + return Log.d(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send an {@link Log#INFO} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int i(String tag, String msg) { + return Log.i(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#INFO} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int i(String tag, String msg, Throwable tr) { + return Log.i(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /** + * Send a {@link Log#WARN} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int w(String tag, String msg) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int w(String tag, String msg, Throwable tr) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } + + /* + * Send a {@link #WARN} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param tr An exception to log + */ + public static int w(String tag, Throwable tr) { + return Log.w(Logging.LOG_TAG_PREFIX + tag, Log.getStackTraceString(tr)); + } + + /** + * Send an {@link Log#ERROR} log message. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + */ + public static int e(String tag, String msg) { + return Log.e(Logging.LOG_TAG_PREFIX + tag, msg); + } + + /** + * Send a {@link Log#ERROR} log message and log the exception. + * @param tag Used to identify the source of a log message. It usually identifies + * the class or activity where the log call occurs. + * @param msg The message you would like logged. + * @param tr An exception to log + */ + public static int e(String tag, String msg, Throwable tr) { + return Log.e(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); + } +} diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java new file mode 100644 index 00000000..c8a96ea3 --- /dev/null +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/adapters/LogCatArrayAdapter.java @@ -0,0 +1,122 @@ +package de.thedevstack.android.logcat.adapters; + +import android.content.Context; +import android.widget.ArrayAdapter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; + +/** + * Created by tzur on 20.11.2015. + */ +public class LogCatArrayAdapter extends ArrayAdapter { + private ArrayList logcatItems = new ArrayList<>(); + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a TextView to use when + */ + public LogCatArrayAdapter(Context context, int resource) { + super(context, resource); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a layout to use when + * instantiating views. + * @param textViewResourceId The id of the TextView within the layout resource to be populated + */ + public LogCatArrayAdapter(Context context, int resource, int textViewResourceId) { + super(context, resource, textViewResourceId); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a TextView to use when + * instantiating views. + * @param objects The objects to represent in the ListView. + */ + public LogCatArrayAdapter(Context context, int resource, String[] objects) { + super(context, resource, objects); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a layout to use when + * instantiating views. + * @param textViewResourceId The id of the TextView within the layout resource to be populated + * @param objects The objects to represent in the ListView. + */ + public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) { + super(context, resource, textViewResourceId, objects); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a TextView to use when + * instantiating views. + * @param objects The objects to represent in the ListView. + */ + public LogCatArrayAdapter(Context context, int resource, List objects) { + super(context, resource, objects); + } + + /** + * Constructor + * + * @param context The current context. + * @param resource The resource ID for a layout file containing a layout to use when + * instantiating views. + * @param textViewResourceId The id of the TextView within the layout resource to be populated + * @param objects The objects to represent in the ListView. + */ + public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, List objects) { + super(context, resource, textViewResourceId, objects); + } + + @Override + public void add(String object) { + super.add(object); + logcatItems.add(object); + } + + @Override + public void addAll(Collection collection) { + super.addAll(collection); + logcatItems.addAll(collection); + } + + @Override + public void addAll(String... items) { + super.addAll(items); + Collections.addAll(logcatItems, items); + } + + @Override + public void clear() { + super.clear(); + logcatItems.clear(); + } + + @Override + public void remove(String object) { + super.remove(object); + logcatItems.remove(object); + } + + public ArrayList getItems() { + return this.logcatItems; + } +} diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java new file mode 100644 index 00000000..1136faf8 --- /dev/null +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java @@ -0,0 +1,105 @@ +package de.thedevstack.android.logcat.tasks; + +import android.os.AsyncTask; +import android.widget.ArrayAdapter; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +import de.thedevstack.android.logcat.Logging; + +/** + * Task to read the logcat of the App. + * The command logcat -d -v time is used to load the logs. + * This reader uses a white list to restrict the messages to display, otherwise it might be flooded with useless log messages. + * The white list checks if a log messages contains one of the following strings: + *
    + *
  • {@value Logging#LOG_TAG_PREFIX}
  • + *
  • E/ - for every error message
  • + *
  • W/ - for every warning message
  • + *
+ */ +public class ReadLogCatAsyncTask extends AsyncTask { + /** + * The array adapter to publish the log messages to. + */ + private final ArrayAdapter arrayAdapter; + /** + * The command to execute logcat. + */ + private static final String[] LOG_CAT_CMD = { "logcat", "-d", "-v", "time"}; + /** + * The white list to filter log messages. + */ + private static final String[] WHITE_LIST = { Logging.getLogTagPrefix(), "E/", "W/" }; + + /** + * Initializes the Task with the array adapter to publish the log messages to. + * @param arrayAdapter the array adapter + */ + public ReadLogCatAsyncTask(ArrayAdapter arrayAdapter) { + this.arrayAdapter = arrayAdapter; + } + + /** + * Executes the logcat command, reads the output of the command and returns all log messages. + * @param params no params will be passed. (interface compliance) + * @return the array of log messages + */ + @Override + protected String[] doInBackground(Void... params) { + ArrayList logCatOutput = new ArrayList<>(); + BufferedReader bufferedReader = null; + try { + Process process = Runtime.getRuntime().exec(ReadLogCatAsyncTask.LOG_CAT_CMD); + bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); + String line = ""; + while ((line = bufferedReader.readLine()) != null) { + logCatOutput.add(line); + } + } catch (IOException e) { + Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e); + } finally { + if (null != bufferedReader) { + try { + bufferedReader.close(); + } catch (IOException e) { + } + } + } + logCatOutput.trimToSize(); + return logCatOutput.toArray(new String[0]); + } + + /** + * Clears the array adapter and adds the filtered log messages. + * @param items all log messages + */ + @Override + protected void onPostExecute(String[] items) { + this.arrayAdapter.clear(); + if (null != items && items.length > 0) { + for (String item : items) { + if (!filter(item)) { + this.arrayAdapter.add(item); + } + } + } + } + + /** + * Checks whether a log message contains a white listed string or not. + * @param item the item to filter + * @return true if the string should be filtered (removed from the list) false otherwise. + */ + protected boolean filter(String item) { + for (String whiteListed : ReadLogCatAsyncTask.WHITE_LIST) { + if (item.contains(whiteListed)) { + return false; + } + } + return true; + } +} diff --git a/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java new file mode 100644 index 00000000..6568a2c5 --- /dev/null +++ b/libs/thedevstacklogcat/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java @@ -0,0 +1,42 @@ +package de.thedevstack.android.logcat.ui; + +import android.content.ClipData; +import android.content.ClipboardManager; +import android.content.Context; +import android.view.View; +import android.widget.Toast; + +import java.util.ArrayList; + +import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; + +/** + * Created by tzur on 20.11.2015. + */ +public class LogCatOutputCopyOnClickListener implements View.OnClickListener { + private final LogCatArrayAdapter logCatOutputAdapter; + private final Context context; + private final int resIdForToast; + + public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter, int resIdForToast) { + this.logCatOutputAdapter = logCatOutputAdapter; + this.context = context; + this.resIdForToast = resIdForToast; + } + + @Override + public void onClick(View v) { + ArrayList items = this.logCatOutputAdapter.getItems(); + if (null != items && !items.isEmpty()) { + StringBuilder sb = new StringBuilder(); + for (String item : items) { + sb.append(item); + sb.append("\n"); + } + ClipboardManager clipboard = (ClipboardManager) this.context.getSystemService(Context.CLIPBOARD_SERVICE); + ClipData clip = ClipData.newPlainText("c+logcat", sb.toString()); + clipboard.setPrimaryClip(clip); + Toast.makeText(this.context, this.context.getText(this.resIdForToast), Toast.LENGTH_LONG).show(); + } + } +} diff --git a/libs/thedevstacklogcat/src/main/res/values/strings.xml b/libs/thedevstacklogcat/src/main/res/values/strings.xml new file mode 100644 index 00000000..45f5e7fd --- /dev/null +++ b/libs/thedevstacklogcat/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + Copy + diff --git a/libs/thedevstacklogcat/src/test/java/de/thedevstack/android/logcat/ExampleUnitTest.java b/libs/thedevstacklogcat/src/test/java/de/thedevstack/android/logcat/ExampleUnitTest.java new file mode 100644 index 00000000..1d2bc545 --- /dev/null +++ b/libs/thedevstacklogcat/src/test/java/de/thedevstack/android/logcat/ExampleUnitTest.java @@ -0,0 +1,15 @@ +package de.thedevstack.android.logcat; + +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * To work on unit tests, switch the Test Artifact in the Build Variants view. + */ +public class ExampleUnitTest { + @Test + public void addition_isCorrect() throws Exception { + assertEquals(4, 2 + 2); + } +} \ No newline at end of file diff --git a/settings.gradle b/settings.gradle index 8a0916ed..f2ffef35 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,4 +1,4 @@ -include ':libs:MemorizingTrustManager', ':libs:emojicon', ':libs:colorpicker', ':libs:SwipyRefreshLayout' +include ':libs:MemorizingTrustManager', ':libs:emojicon', ':libs:colorpicker', ':libs:SwipyRefreshLayout', ':libs:thedevstacklogcat' include ':libs:openpgp-api-lib' rootProject.name = 'Conversations' diff --git a/src/main/AndroidManifest.xml b/src/main/AndroidManifest.xml index 2d7a913c..5ef50e48 100644 --- a/src/main/AndroidManifest.xml +++ b/src/main/AndroidManifest.xml @@ -145,7 +145,7 @@ android:value="de.thedevstack.conversationsplus.ui.SettingsActivity" /> { - private ArrayList logcatItems = new ArrayList<>(); - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a TextView to use when - */ - public LogCatArrayAdapter(Context context, int resource) { - super(context, resource); - } - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a layout to use when - * instantiating views. - * @param textViewResourceId The id of the TextView within the layout resource to be populated - */ - public LogCatArrayAdapter(Context context, int resource, int textViewResourceId) { - super(context, resource, textViewResourceId); - } - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a TextView to use when - * instantiating views. - * @param objects The objects to represent in the ListView. - */ - public LogCatArrayAdapter(Context context, int resource, String[] objects) { - super(context, resource, objects); - } - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a layout to use when - * instantiating views. - * @param textViewResourceId The id of the TextView within the layout resource to be populated - * @param objects The objects to represent in the ListView. - */ - public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, String[] objects) { - super(context, resource, textViewResourceId, objects); - } - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a TextView to use when - * instantiating views. - * @param objects The objects to represent in the ListView. - */ - public LogCatArrayAdapter(Context context, int resource, List objects) { - super(context, resource, objects); - } - - /** - * Constructor - * - * @param context The current context. - * @param resource The resource ID for a layout file containing a layout to use when - * instantiating views. - * @param textViewResourceId The id of the TextView within the layout resource to be populated - * @param objects The objects to represent in the ListView. - */ - public LogCatArrayAdapter(Context context, int resource, int textViewResourceId, List objects) { - super(context, resource, textViewResourceId, objects); - } - - @Override - public void add(String object) { - super.add(object); - logcatItems.add(object); - } - - @Override - public void addAll(Collection collection) { - super.addAll(collection); - logcatItems.addAll(collection); - } - - @Override - public void addAll(String... items) { - super.addAll(items); - Collections.addAll(logcatItems, items); - } - - @Override - public void clear() { - super.clear(); - logcatItems.clear(); - } - - @Override - public void remove(String object) { - super.remove(object); - logcatItems.remove(object); - } - - public ArrayList getItems() { - return this.logcatItems; - } -} diff --git a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java b/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java deleted file mode 100644 index b9fa450b..00000000 --- a/src/main/java/de/thedevstack/android/logcat/tasks/ReadLogCatAsyncTask.java +++ /dev/null @@ -1,67 +0,0 @@ -package de.thedevstack.android.logcat.tasks; - -import android.os.AsyncTask; -import de.thedevstack.conversationsplus.utils.Logging; -import android.widget.ArrayAdapter; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.util.ArrayList; - -import de.thedevstack.conversationsplus.utils.StreamUtil; - -/** - * Created by tzur on 20.11.2015. - */ -public class ReadLogCatAsyncTask extends AsyncTask { - private final ArrayAdapter arrayAdapter; - private static final String[] LOG_CAT_CMD = { "logcat", "-d", "-v", "time"}; - private static final String[] WHITE_LIST = { "thedevstack.", "E/", "W/" }; - private static final String[] BLACK_LIST = { "D/TextLayoutCache" }; - - public ReadLogCatAsyncTask(ArrayAdapter arrayAdapter) { - this.arrayAdapter = arrayAdapter; - } - @Override - protected String[] doInBackground(Void... params) { - ArrayList logCatOutput = new ArrayList<>(); - BufferedReader bufferedReader = null; - try { - Process process = Runtime.getRuntime().exec(ReadLogCatAsyncTask.LOG_CAT_CMD); - bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream())); - String line = ""; - while ((line = bufferedReader.readLine()) != null) { - logCatOutput.add(line); - } - bufferedReader.close(); - } catch (IOException e) { - Logging.e("ReadLogCat", "error while retrieving information from logcat: " + e.getMessage(), e); - } finally { - StreamUtil.close(bufferedReader); - } - logCatOutput.trimToSize(); - return logCatOutput.toArray(new String[0]); - } - - @Override - protected void onPostExecute(String[] items) { - this.arrayAdapter.clear(); - if (null != items && items.length > 0) { - for (String item : items) { - if (!filter(item)) { - this.arrayAdapter.add(item); - } - } - } - } - - protected boolean filter(String item) { - for (String whiteListed : ReadLogCatAsyncTask.WHITE_LIST) { - if (item.contains(whiteListed)) { - return false; - } - } - return true; - } -} diff --git a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java b/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java deleted file mode 100644 index bb49c54d..00000000 --- a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputActivity.java +++ /dev/null @@ -1,27 +0,0 @@ -package de.thedevstack.android.logcat.ui; - -import android.app.Activity; -import android.os.Bundle; -import android.widget.Button; -import android.widget.ListView; - -import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; -import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask; -import de.thedevstack.conversationsplus.R; - -/** - * Created by tzur on 07.10.2015. - */ -public class LogCatOutputActivity extends Activity { - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.activity_logcatoutput); - ListView lv = (ListView)findViewById(R.id.actLogInfoOutput); - LogCatArrayAdapter logCatOutputAdapter = new LogCatArrayAdapter(this, R.layout.list_item_logcatoutput); - lv.setAdapter(logCatOutputAdapter); - new ReadLogCatAsyncTask(logCatOutputAdapter).execute(); - Button copyButton = (Button) findViewById(R.id.actLogOutputCopyButton); - copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter)); - } -} diff --git a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java b/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java deleted file mode 100644 index da82fc7f..00000000 --- a/src/main/java/de/thedevstack/android/logcat/ui/LogCatOutputCopyOnClickListener.java +++ /dev/null @@ -1,42 +0,0 @@ -package de.thedevstack.android.logcat.ui; - -import android.content.ClipData; -import android.content.ClipboardManager; -import android.content.Context; -import android.view.View; -import android.widget.Toast; - -import java.util.ArrayList; - -import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; -import de.thedevstack.conversationsplus.ConversationsPlusApplication; -import de.thedevstack.conversationsplus.R; - -/** - * Created by tzur on 20.11.2015. - */ -public class LogCatOutputCopyOnClickListener implements View.OnClickListener { - private final LogCatArrayAdapter logCatOutputAdapter; - private final Context context; - - public LogCatOutputCopyOnClickListener(Context context, LogCatArrayAdapter logCatOutputAdapter) { - this.logCatOutputAdapter = logCatOutputAdapter; - this.context = context; - } - - @Override - public void onClick(View v) { - ArrayList items = this.logCatOutputAdapter.getItems(); - if (null != items && !items.isEmpty()) { - StringBuilder sb = new StringBuilder(); - for (String item : items) { - sb.append(item); - sb.append("\n"); - } - ClipboardManager clipboard = (ClipboardManager) ConversationsPlusApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE); - ClipData clip = ClipData.newPlainText("c+logcat", sb.toString()); - clipboard.setPrimaryClip(clip); - Toast.makeText(this.context, R.string.cplus_copied_to_clipboard, Toast.LENGTH_LONG).show(); - } - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java index 11091c9f..e70e8e43 100644 --- a/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java +++ b/src/main/java/de/thedevstack/conversationsplus/crypto/OtrService.java @@ -14,7 +14,7 @@ import java.security.spec.InvalidKeySpecException; import org.json.JSONException; import org.json.JSONObject; -import de.thedevstack.conversationsplus.utils.Logging; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; diff --git a/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java b/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java index 8d608ae7..4031e546 100644 --- a/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java +++ b/src/main/java/de/thedevstack/conversationsplus/entities/DownloadableFile.java @@ -19,11 +19,10 @@ import javax.crypto.NoSuchPaddingException; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.utils.MimeUtils; -import de.thedevstack.conversationsplus.utils.Logging; - public class DownloadableFile extends File { private static final long serialVersionUID = 2247012619505115863L; diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java index c0a169ee..c76ed6d7 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpDownloadConnection.java @@ -3,7 +3,6 @@ package de.thedevstack.conversationsplus.http; import android.content.Intent; import android.net.Uri; import android.os.SystemClock; -import de.thedevstack.conversationsplus.utils.Logging; import java.io.BufferedInputStream; import java.io.IOException; @@ -16,6 +15,7 @@ import java.util.Arrays; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLHandshakeException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.R; diff --git a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java index 3d12681f..d5d7ad02 100644 --- a/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/http/HttpUploadConnection.java @@ -1,7 +1,6 @@ package de.thedevstack.conversationsplus.http; import android.app.PendingIntent; -import de.thedevstack.conversationsplus.utils.Logging; import java.io.IOException; import java.io.InputStream; @@ -12,6 +11,7 @@ import java.net.URL; import javax.net.ssl.HttpsURLConnection; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Transferable; diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java index 88091366..9df70c1e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java +++ b/src/main/java/de/thedevstack/conversationsplus/parser/IqParser.java @@ -1,10 +1,9 @@ package de.thedevstack.conversationsplus.parser; -import de.thedevstack.conversationsplus.utils.Logging; - import java.util.ArrayList; import java.util.Collection; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Contact; diff --git a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java index 6f8ad2fe..721f1a23 100644 --- a/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java +++ b/src/main/java/de/thedevstack/conversationsplus/parser/MessageParser.java @@ -1,11 +1,11 @@ package de.thedevstack.conversationsplus.parser; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.Pair; import net.java.otr4j.session.Session; import net.java.otr4j.session.SessionStatus; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java index cfd00b1b..5b09fe2e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/DatabaseBackend.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Contact; @@ -18,7 +19,6 @@ import android.database.Cursor; import android.database.sqlite.SQLiteCantOpenDatabaseException; import android.database.sqlite.SQLiteDatabase; import android.database.sqlite.SQLiteOpenHelper; -import de.thedevstack.conversationsplus.utils.Logging; public class DatabaseBackend extends SQLiteOpenHelper { diff --git a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java index 5cc63065..d442abe2 100644 --- a/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java +++ b/src/main/java/de/thedevstack/conversationsplus/persistance/FileBackend.java @@ -16,9 +16,9 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.os.Environment; -import de.thedevstack.conversationsplus.utils.Logging; import android.webkit.MimeTypeMap; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.R; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/MessageArchiveService.java b/src/main/java/de/thedevstack/conversationsplus/services/MessageArchiveService.java index ec1d5da1..1e0abec1 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/MessageArchiveService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/MessageArchiveService.java @@ -1,13 +1,12 @@ package de.thedevstack.conversationsplus.services; -import de.thedevstack.conversationsplus.utils.Logging; - import java.math.BigInteger; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Account; diff --git a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java index 30fae7cc..159fcf44 100644 --- a/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java +++ b/src/main/java/de/thedevstack/conversationsplus/services/XmppConnectionService.java @@ -21,7 +21,6 @@ import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.SystemClock; import android.provider.ContactsContract; -import de.thedevstack.conversationsplus.utils.Logging; import net.java.otr4j.OtrException; import net.java.otr4j.session.Session; @@ -50,6 +49,8 @@ import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import de.duenndns.ssl.MemorizingTrustManager; + +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.exceptions.FileCopyException; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java new file mode 100644 index 00000000..e75c1f63 --- /dev/null +++ b/src/main/java/de/thedevstack/conversationsplus/ui/LogCatOutputActivity.java @@ -0,0 +1,28 @@ +package de.thedevstack.conversationsplus.ui; + +import android.app.Activity; +import android.os.Bundle; +import android.widget.Button; +import android.widget.ListView; + +import de.thedevstack.android.logcat.adapters.LogCatArrayAdapter; +import de.thedevstack.android.logcat.tasks.ReadLogCatAsyncTask; +import de.thedevstack.android.logcat.ui.LogCatOutputCopyOnClickListener; +import de.thedevstack.conversationsplus.R; + +/** + * Created by tzur on 07.10.2015. + */ +public class LogCatOutputActivity extends Activity { + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_logcatoutput); + ListView lv = (ListView)findViewById(R.id.actLogInfoOutput); + LogCatArrayAdapter logCatOutputAdapter = new LogCatArrayAdapter(this, R.layout.list_item_logcatoutput); + lv.setAdapter(logCatOutputAdapter); + new ReadLogCatAsyncTask(logCatOutputAdapter).execute(); + Button copyButton = (Button) findViewById(R.id.actLogOutputCopyButton); + copyButton.setOnClickListener(new LogCatOutputCopyOnClickListener(this, logCatOutputAdapter, R.string.cplus_copied_to_clipboard)); + } +} diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java index 6a5d47c2..8ad23e6e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/StartConversationActivity.java @@ -24,7 +24,6 @@ import android.support.v13.app.FragmentPagerAdapter; import android.support.v4.view.ViewPager; import android.text.Editable; import android.text.TextWatcher; -import de.thedevstack.conversationsplus.utils.Logging; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.KeyEvent; @@ -52,6 +51,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.R; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java index 312c4223..23278bfb 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/XmppActivity.java @@ -37,7 +37,6 @@ import android.os.IBinder; import android.os.SystemClock; import android.text.InputType; import android.util.DisplayMetrics; -import de.thedevstack.conversationsplus.utils.Logging; import android.view.MenuItem; import android.view.View; import android.view.inputmethod.InputMethodManager; @@ -62,6 +61,7 @@ import java.util.Hashtable; import java.util.List; import java.util.concurrent.RejectedExecutionException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.R; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java index abb77993..4e361c67 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/adapter/ConversationAdapter.java @@ -8,7 +8,6 @@ import android.graphics.Typeface; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.Drawable; import android.os.AsyncTask; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.Pair; import android.view.LayoutInflater; import android.view.View; @@ -21,6 +20,7 @@ import java.lang.ref.WeakReference; import java.util.List; import java.util.concurrent.RejectedExecutionException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.ui.listeners.ShowResourcesListDialogListener; import de.tzur.conversations.Settings; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java index a6ee21e6..56297f6c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/dialogs/MessageDetailsDialog.java @@ -2,12 +2,12 @@ package de.thedevstack.conversationsplus.ui.dialogs; import android.app.Activity; import android.text.format.DateFormat; -import de.thedevstack.conversationsplus.utils.Logging; import android.view.View; import android.widget.TextView; import java.util.Date; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Conversation; import de.thedevstack.conversationsplus.entities.Message; diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java index bd616691..30b7bf73 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/listeners/ConversationSwipeRefreshListener.java @@ -1,8 +1,5 @@ package de.thedevstack.conversationsplus.ui.listeners; -import de.thedevstack.conversationsplus.R; -import de.thedevstack.conversationsplus.services.MessageArchiveService; -import de.thedevstack.conversationsplus.utils.Logging; import android.widget.ListView; import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout; @@ -10,6 +7,10 @@ import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutD import java.util.List; +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.R; +import de.thedevstack.conversationsplus.entities.Conversation; +import de.thedevstack.conversationsplus.services.MessageArchiveService; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.ui.ConversationActivity; @@ -36,7 +37,7 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe Logging.d(Config.LOGTAG, "Refresh direction " + direction); synchronized (this.messageList) { long timestamp; - if (SwipyRefreshLayoutDirection.TOP == direction) { + if (SwipyRefreshLayoutDirection.TOP == direction) { // Load history -> messages sent/received before first message in database if (messageList.isEmpty()) { timestamp = System.currentTimeMillis(); } else { @@ -45,28 +46,47 @@ public class ConversationSwipeRefreshListener implements SwipyRefreshLayout.OnRe ConversationActivity activity = (ConversationActivity) fragment.getActivity(); this.listener.setLoadHistory(true); activity.xmppConnectionService.loadMoreMessages(activity.getSelectedConversation(), timestamp, this.listener); - } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { + } else if (SwipyRefreshLayoutDirection.BOTTOM == direction) { // load messages sent/received between last received or last session establishment and now Logging.d("mam", "loading missing messages from mam (last session establishing or last received message)"); final ConversationActivity activity = (ConversationActivity) fragment.getActivity(); - long lastSessionEstablished = activity.getSelectedConversation().getAccount().getXmppConnection().getLastSessionEstablished(); - int lastMessageIndex = this.messageList.size() - 1; - long lastReceivedMessage = (0 <= lastMessageIndex) ? this.messageList.get(lastMessageIndex).getTimeSent() : Long.MAX_VALUE; + long lastSessionEstablished = this.getTimestampOfLastSessionEstablished(activity.getSelectedConversation()); + long lastReceivedMessage = this.getTimestampOfLastReceivedOrTransmittedMessage(); long startTimestamp = Math.min(lastSessionEstablished, lastReceivedMessage); MessageArchiveService.Query query = activity.xmppConnectionService.getMessageArchiveService().query(activity.getSelectedConversation(), startTimestamp, System.currentTimeMillis()); if (query != null) { this.listener.setLoadHistory(false); query.setCallback(this.listener); } else { - activity.runOnUiThread(new Runnable() { - @Override - public void run() { - listener.onMoreMessagesLoaded(0, activity.getSelectedConversation()); - } - }); + Logging.d("mam", "no query built - no messages loaded"); + this.listener.onMoreMessagesLoaded(0, activity.getSelectedConversation()); + this.listener.informUser(R.string.no_more_history_on_server); } this.listener.informUser(R.string.fetching_history_from_server); } } Logging.d(Config.LOGTAG, "End Refresh swipe container"); } + + private long getTimestampOfLastReceivedOrTransmittedMessage() { + long lastReceivedOrTransmittedMessage = Long.MAX_VALUE; + if (null != this.messageList + && !this.messageList.isEmpty()) { + int lastMessageIndex = this.messageList.size() - 1; + if (0 <= lastMessageIndex && this.messageList.size() > lastMessageIndex) { + lastReceivedOrTransmittedMessage = this.messageList.get(lastMessageIndex).getTimeSent(); + } + } + + return lastReceivedOrTransmittedMessage; + } + + private long getTimestampOfLastSessionEstablished(Conversation conversation) { + long lastSessionEstablished = Long.MAX_VALUE; + if (null != conversation + && null != conversation.getAccount() + && null != conversation.getAccount().getXmppConnection()) { + lastSessionEstablished = conversation.getAccount().getXmppConnection().getLastSessionEstablished(); + } + return lastSessionEstablished; + } } diff --git a/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java index 65b3b1b3..5dcfc607 100644 --- a/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java +++ b/src/main/java/de/thedevstack/conversationsplus/ui/preferences/LogInformationPreference.java @@ -5,7 +5,7 @@ import android.content.Intent; import android.preference.Preference; import android.util.AttributeSet; -import de.thedevstack.android.logcat.ui.LogCatOutputActivity; +import de.thedevstack.conversationsplus.ui.LogCatOutputActivity; /** * Created by tzur on 07.10.2015. diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java index 87b9eb32..660100a3 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/AvatarUtil.java @@ -4,7 +4,6 @@ import android.graphics.Bitmap; import android.net.Uri; import android.util.Base64; import android.util.Base64OutputStream; -import de.thedevstack.conversationsplus.utils.Logging; import java.io.ByteArrayOutputStream; import java.io.File; @@ -16,6 +15,7 @@ import java.security.DigestOutputStream; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusApplication; import de.thedevstack.conversationsplus.xmpp.pep.Avatar; diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java index bd7a6623..aa16b06b 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/DNSHelper.java @@ -10,8 +10,6 @@ import de.measite.minidns.record.A; import de.measite.minidns.record.AAAA; import de.measite.minidns.record.Data; import de.measite.minidns.util.NameUtil; -import de.thedevstack.conversationsplus.Config; -import de.thedevstack.conversationsplus.xmpp.jid.Jid; import java.io.IOException; import java.net.InetAddress; @@ -23,7 +21,10 @@ import java.util.TreeMap; import java.util.regex.Pattern; import android.os.Bundle; -import de.thedevstack.conversationsplus.utils.Logging; + +import de.thedevstack.android.logcat.Logging; +import de.thedevstack.conversationsplus.Config; +import de.thedevstack.conversationsplus.xmpp.jid.Jid; public class DNSHelper { diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java index dc8ca40d..32f45127 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExceptionHelper.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.util.List; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.R; @@ -26,7 +27,6 @@ import android.content.pm.PackageManager; import android.content.pm.PackageManager.NameNotFoundException; import android.preference.PreferenceManager; import android.text.format.DateUtils; -import de.thedevstack.conversationsplus.utils.Logging; public class ExceptionHelper { public static void init(Context context) { diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java b/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java index 7aaf8b0b..576698ce 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ExifHelper.java @@ -16,7 +16,7 @@ package de.thedevstack.conversationsplus.utils; -import de.thedevstack.conversationsplus.utils.Logging; +import de.thedevstack.android.logcat.Logging; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java index 1d126db5..7e8cacd0 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/ImageUtil.java @@ -7,7 +7,6 @@ import android.graphics.Matrix; import android.graphics.RectF; import android.media.ExifInterface; import android.net.Uri; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.LruCache; import java.io.File; @@ -15,6 +14,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.persistance.FileBackend; diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java b/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java deleted file mode 100644 index 40ec66a0..00000000 --- a/src/main/java/de/thedevstack/conversationsplus/utils/Logging.java +++ /dev/null @@ -1,124 +0,0 @@ -package de.thedevstack.conversationsplus.utils; - -import android.util.Log; - -/** - * Created by tzur on 20.11.2015. - */ -public class Logging { - protected static final String LOG_TAG_PREFIX = "thedevstack."; - /** - * Send a {@link Log#VERBOSE} log message. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - */ - public static int v(String tag, String msg) { - return Log.v(Logging.LOG_TAG_PREFIX + tag, msg); - } - - /** - * Send a {@link Log#VERBOSE} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - * @param tr An exception to log - */ - public static int v(String tag, String msg, Throwable tr) { - return Log.v(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); - } - - /** - * Send a {@link Log#DEBUG} log message. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - */ - public static int d(String tag, String msg) { - return Log.d(Logging.LOG_TAG_PREFIX + tag, msg); - } - - /** - * Send a {@link Log#DEBUG} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - * @param tr An exception to log - */ - public static int d(String tag, String msg, Throwable tr) { - return Log.d(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); - } - - /** - * Send an {@link Log#INFO} log message. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - */ - public static int i(String tag, String msg) { - return Log.i(Logging.LOG_TAG_PREFIX + tag, msg); - } - - /** - * Send a {@link Log#INFO} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - * @param tr An exception to log - */ - public static int i(String tag, String msg, Throwable tr) { - return Log.i(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); - } - - /** - * Send a {@link Log#WARN} log message. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - */ - public static int w(String tag, String msg) { - return Log.w(Logging.LOG_TAG_PREFIX + tag, msg); - } - - /** - * Send a {@link Log#WARN} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - * @param tr An exception to log - */ - public static int w(String tag, String msg, Throwable tr) { - return Log.w(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); - } - - /* - * Send a {@link #WARN} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param tr An exception to log - */ - public static int w(String tag, Throwable tr) { - return Log.w(Logging.LOG_TAG_PREFIX + tag, Log.getStackTraceString(tr)); - } - - /** - * Send an {@link Log#ERROR} log message. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - */ - public static int e(String tag, String msg) { - return Log.e(Logging.LOG_TAG_PREFIX + tag, msg); - } - - /** - * Send a {@link Log#ERROR} log message and log the exception. - * @param tag Used to identify the source of a log message. It usually identifies - * the class or activity where the log call occurs. - * @param msg The message you would like logged. - * @param tr An exception to log - */ - public static int e(String tag, String msg, Throwable tr) { - return Log.e(Logging.LOG_TAG_PREFIX + tag, msg + '\n' + Log.getStackTraceString(tr)); - } -} diff --git a/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java b/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java index ca4d65ff..0751809c 100644 --- a/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java +++ b/src/main/java/de/thedevstack/conversationsplus/utils/PRNGFixes.java @@ -2,7 +2,6 @@ package de.thedevstack.conversationsplus.utils; import android.os.Build; import android.os.Process; -import de.thedevstack.conversationsplus.utils.Logging; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -19,6 +18,8 @@ import java.security.SecureRandom; import java.security.SecureRandomSpi; import java.security.Security; +import de.thedevstack.android.logcat.Logging; + /** * Fixes for the output of the default PRNG having low entropy. * diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java index 88b20e14..3d2c75b0 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xml/Element.java +++ b/src/main/java/de/thedevstack/conversationsplus/xml/Element.java @@ -1,11 +1,10 @@ package de.thedevstack.conversationsplus.xml; -import de.thedevstack.conversationsplus.utils.Logging; - import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.utils.XmlHelper; import de.thedevstack.conversationsplus.xmpp.jid.InvalidJidException; diff --git a/src/main/java/de/thedevstack/conversationsplus/xml/XmlReader.java b/src/main/java/de/thedevstack/conversationsplus/xml/XmlReader.java index 2eea0571..35425816 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xml/XmlReader.java +++ b/src/main/java/de/thedevstack/conversationsplus/xml/XmlReader.java @@ -7,11 +7,11 @@ import java.io.InputStreamReader; import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParserException; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import android.os.PowerManager; import android.os.PowerManager.WakeLock; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.Xml; public class XmlReader { diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java index 2b084d4b..37137eb3 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/XmppConnection.java @@ -6,7 +6,6 @@ import android.os.Parcelable; import android.os.PowerManager; import android.os.PowerManager.WakeLock; import android.os.SystemClock; -import de.thedevstack.conversationsplus.utils.Logging; import android.util.Pair; import android.util.SparseArray; @@ -43,6 +42,7 @@ import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.X509TrustManager; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.crypto.sasl.DigestMd5; import de.thedevstack.conversationsplus.crypto.sasl.Plain; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java index e3a599d7..6ddf99b8 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnection.java @@ -11,7 +11,8 @@ import java.util.concurrent.ConcurrentHashMap; import android.content.Intent; import android.net.Uri; import android.os.SystemClock; -import de.thedevstack.conversationsplus.utils.Logging; + +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.ConversationsPlusPreferences; import de.thedevstack.conversationsplus.entities.Account; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnectionManager.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnectionManager.java index f10d7c7e..861082d8 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnectionManager.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleConnectionManager.java @@ -6,7 +6,8 @@ import java.util.HashMap; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; import android.annotation.SuppressLint; -import de.thedevstack.conversationsplus.utils.Logging; + +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.Transferable; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleInbandTransport.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleInbandTransport.java index db22f8c3..84d40b3e 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleInbandTransport.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleInbandTransport.java @@ -8,8 +8,8 @@ import java.security.NoSuchAlgorithmException; import java.util.Arrays; import android.util.Base64; -import de.thedevstack.conversationsplus.utils.Logging; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.Account; import de.thedevstack.conversationsplus.entities.DownloadableFile; diff --git a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleSocks5Transport.java b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleSocks5Transport.java index 20f2b45a..999180c5 100644 --- a/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleSocks5Transport.java +++ b/src/main/java/de/thedevstack/conversationsplus/xmpp/jingle/JingleSocks5Transport.java @@ -1,7 +1,5 @@ package de.thedevstack.conversationsplus.xmpp.jingle; -import de.thedevstack.conversationsplus.utils.Logging; - import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -14,6 +12,7 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Arrays; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.Config; import de.thedevstack.conversationsplus.entities.DownloadableFile; import de.thedevstack.conversationsplus.persistance.FileBackend; diff --git a/src/main/java/de/tzur/conversations/Settings.java b/src/main/java/de/tzur/conversations/Settings.java index b8922f0a..2484a88f 100644 --- a/src/main/java/de/tzur/conversations/Settings.java +++ b/src/main/java/de/tzur/conversations/Settings.java @@ -1,8 +1,8 @@ package de.tzur.conversations; import android.content.SharedPreferences; -import de.thedevstack.conversationsplus.utils.Logging; +import de.thedevstack.android.logcat.Logging; import de.thedevstack.conversationsplus.ConversationsPlusApplication; /** -- cgit v1.2.3