diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-07-01 08:12:58 +0200 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-07-01 08:12:58 +0200 |
commit | 226d45a136d84ac8a95d25aa0c083c4fc471f1f4 (patch) | |
tree | 33e6c499120575ccda9b9f329bc114fa1c03096c | |
parent | 6d24ce7a1869a20c674771b37f8fc8b65db765ed (diff) |
code cleanup & small fixes
22 files changed, 42 insertions, 49 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java index e280d2527..e67519180 100644 --- a/src/main/java/de/pixart/messenger/entities/Message.java +++ b/src/main/java/de/pixart/messenger/entities/Message.java @@ -792,7 +792,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable if (this.transferable != null) { fileParams.size = this.transferable.getFileSize(); } - String parts[] = body == null ? new String[0] : body.split("\\|"); + String[] parts = body == null ? new String[0] : body.split("\\|"); switch (parts.length) { case 1: try { diff --git a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java index ba0f7927d..afffa388f 100644 --- a/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/DatabaseBackend.java @@ -601,7 +601,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { continue; } - String updateArgs[] = { + String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Conversation.UUID)), }; @@ -624,7 +624,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { continue; } - String updateArgs[] = { + String[] updateArgs = { newJid, cursor.getString(cursor.getColumnIndex(Contact.ACCOUNT)), cursor.getString(cursor.getColumnIndex(Contact.JID)), @@ -653,7 +653,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { continue; } - String updateArgs[] = { + String[] updateArgs = { newServer, cursor.getString(cursor.getColumnIndex(Account.UUID)), }; @@ -1052,7 +1052,7 @@ public class DatabaseBackend extends SQLiteOpenHelper { public void readRoster(Roster roster) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor; - String args[] = {roster.getAccount().getUuid()}; + String[] args = {roster.getAccount().getUuid()}; cursor = db.query(Contact.TABLENAME, null, Contact.ACCOUNT + "=?", args, null, null, null); while (cursor.moveToNext()) { roster.initContact(Contact.fromCursor(cursor)); diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 39c743185..9386deca4 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -310,26 +310,26 @@ public class FileBackend { public static String getConversationsDirectory(final String type) { if (type.equalsIgnoreCase("null")) { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/"; + return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Pix-Art Messenger" + File.separator; } else { - return getAppMediaDirectory() + "Pix-Art Messenger" + " " + type + "/"; + return getAppMediaDirectory() + "Pix-Art Messenger" + " " + type + File.separator; } } public static String getAppMediaDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/Media/"; + return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Pix-Art Messenger" + File.separator + "Media" + File.separator; } public static String getBackupDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/Database/"; + return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Pix-Art Messenger" + File.separator + "Database" + File.separator; } public static String getAppLogsDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/Chats/"; + return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Pix-Art Messenger" + File.separator + "Chats" + File.separator; } public static String getAppUpdateDirectory() { - return Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + "Pix-Art Messenger" + "/Update/"; + return Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "Pix-Art Messenger" + File.separator + "Update" + File.separator; } private Bitmap resize(final Bitmap originalBitmap, int size) throws IOException { @@ -731,7 +731,7 @@ public class FileBackend { } public Uri getTakePhotoUri() { - File file = new File(getTakeFromCameraPath() + "IMG_" + this.fileDateFormat.format(new Date()) + ".jpg"); + File file = new File(getTakeFromCameraPath() + "IMG_" + fileDateFormat.format(new Date()) + ".jpg"); file.getParentFile().mkdirs(); return getUriForFile(mXmppConnectionService, file); } @@ -757,7 +757,7 @@ public class FileBackend { } public Uri getTakeVideoUri() { - File file = new File(getTakeFromCameraPath() + "VID_" + this.fileDateFormat.format(new Date()) + ".mp4"); + File file = new File(getTakeFromCameraPath() + "VID_" + fileDateFormat.format(new Date()) + ".mp4"); file.getParentFile().mkdirs(); return getUriForFile(mXmppConnectionService, file); } @@ -897,7 +897,7 @@ public class FileBackend { file = new File(getAvatarPath(avatar.getFilename())); avatar.size = file.length(); } else { - file = new File(mXmppConnectionService.getCacheDir().getAbsolutePath() + "/" + UUID.randomUUID().toString()); + file = new File(mXmppConnectionService.getCacheDir().getAbsolutePath() + File.separator + UUID.randomUUID().toString()); if (file.getParentFile().mkdirs()) { Log.d(Config.LOGTAG, "created cache directory"); } diff --git a/src/main/java/de/pixart/messenger/persistance/OnPhoneContactsMerged.java b/src/main/java/de/pixart/messenger/persistance/OnPhoneContactsMerged.java index d5253f227..6c7b0e52c 100644 --- a/src/main/java/de/pixart/messenger/persistance/OnPhoneContactsMerged.java +++ b/src/main/java/de/pixart/messenger/persistance/OnPhoneContactsMerged.java @@ -1,5 +1,5 @@ package de.pixart.messenger.persistance; public interface OnPhoneContactsMerged { - public void phoneContactsMerged(); + void phoneContactsMerged(); } diff --git a/src/main/java/de/pixart/messenger/services/ImportBackupService.java b/src/main/java/de/pixart/messenger/services/ImportBackupService.java index 1b28640e5..9a1ddece2 100644 --- a/src/main/java/de/pixart/messenger/services/ImportBackupService.java +++ b/src/main/java/de/pixart/messenger/services/ImportBackupService.java @@ -197,11 +197,7 @@ public class ImportBackupService extends Service { } catch (Exception e) { Throwable throwable = e.getCause(); final boolean reasonWasCrypto; - if (throwable instanceof BadPaddingException) { - reasonWasCrypto = true; - } else { - reasonWasCrypto = false; - } + reasonWasCrypto = throwable instanceof BadPaddingException; synchronized (mOnBackupProcessedListeners) { for (OnBackupProcessed l : mOnBackupProcessedListeners) { if (reasonWasCrypto) { diff --git a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java index 09739530d..bad55aed9 100644 --- a/src/main/java/de/pixart/messenger/services/XmppConnectionService.java +++ b/src/main/java/de/pixart/messenger/services/XmppConnectionService.java @@ -768,7 +768,7 @@ public class XmppConnectionService extends Service { private void deleteWebpreviewCache() { long start = SystemClock.elapsedRealtime(); try { - final String path = getApplicationContext().getCacheDir() + "/" + RICH_LINK_METADATA; + final String path = getApplicationContext().getCacheDir() + File.separator + RICH_LINK_METADATA; final Calendar time = Calendar.getInstance(); time.add(Calendar.DAY_OF_YEAR, -7); final File directory = new File(path); @@ -776,18 +776,17 @@ public class XmppConnectionService extends Service { return; } final File[] files = directory.listFiles(); - if (files == null) { - return; - } - int count = 0; - for (File file : files) { - Date lastModified = new Date(file.lastModified()); - if (lastModified.before(time.getTime())) { - file.delete(); - count++; + if (files != null) { + int count = 0; + for (File file : files) { + Date lastModified = new Date(file.lastModified()); + if (lastModified.before(time.getTime())) { + file.delete(); + count++; + } } + Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); } - Log.d(Config.LOGTAG, "Deleted " + count + " expired webpreview cache files in " + (SystemClock.elapsedRealtime() - start) + "ms"); } catch (Exception e) { Log.d(Config.LOGTAG, "Deleted no expired webpreview cache files because of " + e + " in " + (SystemClock.elapsedRealtime() - start) + "ms"); } diff --git a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java index 6d407c326..7f1869e9f 100644 --- a/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ChooseContactActivity.java @@ -377,7 +377,7 @@ public class ChooseContactActivity extends AbstractSearchableListItemActivity im } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); } diff --git a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java index bd127d443..ad5b15894 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationFragment.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationFragment.java @@ -1583,7 +1583,7 @@ public class ConversationFragment extends XmppFragment implements EditMessage.Ke } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (grantResults.length > 0) { if (allGranted(grantResults)) { switch (requestCode) { diff --git a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java index 56d347f1c..d391f34d3 100644 --- a/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ConversationsActivity.java @@ -337,7 +337,7 @@ public class ConversationsActivity extends XmppActivity implements OnConversatio } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { UriHandlerActivity.onRequestPermissionResult(this, requestCode, grantResults); if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { diff --git a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java index 666c7b96d..6f4f00bce 100644 --- a/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/EditAccountActivity.java @@ -1497,7 +1497,7 @@ public class EditAccountActivity extends OmemoActivity implements OnAccountUpdat } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (grantResults.length > 0) { if (allGranted(grantResults)) { switch (requestCode) { diff --git a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java index 449e3871b..e632f4e92 100644 --- a/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ManageAccountActivity.java @@ -210,7 +210,7 @@ public class ManageAccountActivity extends XmppActivity implements OnAccountUpda } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (grantResults.length > 0) { if (allGranted(grantResults)) { switch (requestCode) { diff --git a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java index 338647be8..25a791e10 100644 --- a/src/main/java/de/pixart/messenger/ui/OmemoActivity.java +++ b/src/main/java/de/pixart/messenger/ui/OmemoActivity.java @@ -204,7 +204,7 @@ public abstract class OmemoActivity extends XmppActivity { } @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); } }
\ No newline at end of file diff --git a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java index fedd2b60d..fae741587 100644 --- a/src/main/java/de/pixart/messenger/ui/SettingsActivity.java +++ b/src/main/java/de/pixart/messenger/ui/SettingsActivity.java @@ -367,7 +367,7 @@ public class SettingsActivity extends XmppActivity implements private void cleanPrivateFiles(final String type) { try { - File dir = new File(getFilesDir().getAbsolutePath(), "/" + type + "/"); + File dir = new File(getFilesDir().getAbsolutePath(), File.separator + type + File.separator); File[] array = dir.listFiles(); if (array != null) { for (int b = 0; b < array.length; b++) { diff --git a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java index 2ae46dac8..11c98d2b7 100644 --- a/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShareWithActivity.java @@ -52,7 +52,7 @@ public class ShareWithActivity extends XmppActivity implements XmppConnectionSer } @Override - public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) { if (grantResults.length > 0) if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (requestCode == REQUEST_STORAGE_PERMISSION) { diff --git a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java index 1cf01283c..4689add0a 100644 --- a/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java +++ b/src/main/java/de/pixart/messenger/ui/StartConversationActivity.java @@ -739,7 +739,7 @@ public class StartConversationActivity extends XmppActivity implements XmppConne } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (grantResults.length > 0) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { ScanActivity.onRequestPermissionResult(this, requestCode, grantResults); diff --git a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java index 5c8b105a2..cc075b6aa 100644 --- a/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java +++ b/src/main/java/de/pixart/messenger/ui/UpdaterActivity.java @@ -360,7 +360,7 @@ public class UpdaterActivity extends XmppActivity { is = connection.getInputStream(); os = new FileOutputStream(file); - byte data[] = new byte[4096]; + byte[] data = new byte[4096]; long total = 0; int count; while ((count = is.read(data)) != -1) { diff --git a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java index 472684316..0ca7d5351 100644 --- a/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java +++ b/src/main/java/de/pixart/messenger/ui/WelcomeActivity.java @@ -109,7 +109,7 @@ public class WelcomeActivity extends XmppActivity { } @Override - public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) { + public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (grantResults.length > 0) { if (allGranted(grantResults)) { switch (requestCode) { diff --git a/src/main/java/de/pixart/messenger/utils/GeoHelper.java b/src/main/java/de/pixart/messenger/utils/GeoHelper.java index 87620ee8b..75605ac7f 100644 --- a/src/main/java/de/pixart/messenger/utils/GeoHelper.java +++ b/src/main/java/de/pixart/messenger/utils/GeoHelper.java @@ -47,7 +47,6 @@ public class GeoHelper { private static GeoPoint parseGeoPoint(String body) throws IllegalArgumentException { Matcher matcher = GEO_URI.matcher(body); - ; if (!matcher.matches()) { throw new IllegalArgumentException("Invalid geo uri"); } diff --git a/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java b/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java index 3cd715a4c..bf4013e47 100644 --- a/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java +++ b/src/main/java/de/pixart/messenger/utils/IrregularUnicodeDetector.java @@ -198,7 +198,6 @@ public class IrregularUnicodeDetector { if (pattern != null) { return pattern; } - ; pattern = PatternTuple.of(jid); CACHE.put(jid, pattern); return pattern; diff --git a/src/main/java/de/pixart/messenger/utils/RichPreview.java b/src/main/java/de/pixart/messenger/utils/RichPreview.java index 1f9c58b80..7a2d2d723 100644 --- a/src/main/java/de/pixart/messenger/utils/RichPreview.java +++ b/src/main/java/de/pixart/messenger/utils/RichPreview.java @@ -56,7 +56,7 @@ public class RichPreview { protected Void doInBackground(Void... params) { FileInputStream fis = null; ObjectInputStream is = null; - final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + "/" + filename); + final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + File.separator + filename); try { fis = new FileInputStream(file); InputStreamReader isr = new InputStreamReader(fis); @@ -134,7 +134,7 @@ public class RichPreview { } private void saveMeta(MetaData metaData, Context context) { - final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + "/" + filename); + final File file = new File(context.getCacheDir(), RICH_LINK_METADATA + File.separator + filename); file.getParentFile().mkdirs(); FileOutputStream fos = null; ObjectOutputStream oos = null; diff --git a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java index 3a7e41c9a..9493b260d 100644 --- a/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/XmppConnection.java @@ -1570,8 +1570,8 @@ public class XmppConnection implements Runnable { if (socket != null) { try { socket.close(); - } catch (IOException e) { - Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": io exception " + e.getMessage() + " during force close"); + } catch (Exception e) { + Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": exception " + e.getMessage() + " during force close"); } } else { Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": socket was null during force close"); diff --git a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java index 8e005cc60..2a409fedc 100644 --- a/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java +++ b/src/main/java/de/pixart/messenger/xmpp/jingle/JingleConnection.java @@ -448,7 +448,7 @@ public class JingleConnection implements Transferable { if (message.getType() == Message.TYPE_FILE) { String suffix = ""; if (!fileNameElement.getContent().isEmpty()) { - String parts[] = fileNameElement.getContent().split("/"); + String[] parts = fileNameElement.getContent().split("/"); suffix = parts[parts.length - 1]; if (message.getEncryption() == Message.ENCRYPTION_OTR && suffix.endsWith(".otr")) { suffix = suffix.substring(0, suffix.length() - 4); |