From 6540df4fc9db8ad9f431079cf2eb7b8b4d7286b0 Mon Sep 17 00:00:00 2001 From: Christian Basler Date: Sun, 7 May 2017 16:13:20 +0200 Subject: [PATCH] Some improvements suggested by Codacy --- .../apps/abit/AddressDetailFragment.java | 1 + .../ch/dissem/apps/abit/SettingsFragment.java | 1 - .../repository/AndroidMessageRepository.java | 26 +++++-------------- .../abit/repository/AndroidNodeRegistry.java | 1 - 4 files changed, 8 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.java b/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.java index dae54bb..9dec757 100644 --- a/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/AddressDetailFragment.java @@ -160,6 +160,7 @@ public class AddressDetailFragment extends Fragment { shareIntent.setType("text/plain"); shareIntent.putExtra(Intent.EXTRA_TEXT, item.getAddress()); startActivity(Intent.createChooser(shareIntent, null)); + return true; } default: return false; diff --git a/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java b/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java index a92cc47..c198485 100644 --- a/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java +++ b/app/src/main/java/ch/dissem/apps/abit/SettingsFragment.java @@ -29,7 +29,6 @@ import android.widget.Toast; import com.mikepenz.aboutlibraries.Libs; import com.mikepenz.aboutlibraries.LibsBuilder; -import ch.dissem.apps.abit.repository.AndroidNodeRegistry; import ch.dissem.apps.abit.service.Singleton; import ch.dissem.apps.abit.synchronization.SyncAdapter; import ch.dissem.bitmessage.BitmessageContext; diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java index f305ffb..d869ee8 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidMessageRepository.java @@ -337,7 +337,7 @@ public class AndroidMessageRepository extends AbstractMessageRepository { } } - private void insert(SQLiteDatabase db, Plaintext message) { + private ContentValues getValues(Plaintext message) { ContentValues values = new ContentValues(); values.put(COLUMN_IV, message.getInventoryVector() == null ? null : message .getInventoryVector().getHash()); @@ -354,28 +354,16 @@ public class AndroidMessageRepository extends AbstractMessageRepository { values.put(COLUMN_RETRIES, message.getRetries()); values.put(COLUMN_NEXT_TRY, message.getNextTry()); values.put(COLUMN_CONVERSATION, UuidUtils.asBytes(message.getConversationId())); - long id = db.insertOrThrow(TABLE_NAME, null, values); + return values; + } + + private void insert(SQLiteDatabase db, Plaintext message) { + long id = db.insertOrThrow(TABLE_NAME, null, getValues(message)); message.setId(id); } private void update(SQLiteDatabase db, Plaintext message) { - ContentValues values = new ContentValues(); - values.put(COLUMN_IV, message.getInventoryVector() == null ? null : message - .getInventoryVector().getHash()); - values.put(COLUMN_TYPE, message.getType().name()); - values.put(COLUMN_SENDER, message.getFrom().getAddress()); - values.put(COLUMN_RECIPIENT, message.getTo() == null ? null : message.getTo().getAddress()); - values.put(COLUMN_DATA, Encode.bytes(message)); - values.put(COLUMN_ACK_DATA, message.getAckData()); - values.put(COLUMN_SENT, message.getSent()); - values.put(COLUMN_RECEIVED, message.getReceived()); - values.put(COLUMN_STATUS, message.getStatus() == null ? null : message.getStatus().name()); - values.put(COLUMN_INITIAL_HASH, message.getInitialHash()); - values.put(COLUMN_TTL, message.getTTL()); - values.put(COLUMN_RETRIES, message.getRetries()); - values.put(COLUMN_NEXT_TRY, message.getNextTry()); - values.put(COLUMN_CONVERSATION, UuidUtils.asBytes(message.getConversationId())); - db.update(TABLE_NAME, values, "id = " + message.getId(), null); + db.update(TABLE_NAME, getValues(message), "id = " + message.getId(), null); } @Override diff --git a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidNodeRegistry.java b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidNodeRegistry.java index 2183fcb..1ab7d5c 100644 --- a/app/src/main/java/ch/dissem/apps/abit/repository/AndroidNodeRegistry.java +++ b/app/src/main/java/ch/dissem/apps/abit/repository/AndroidNodeRegistry.java @@ -10,7 +10,6 @@ import android.database.sqlite.SQLiteStatement; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.ArrayList; import java.util.LinkedList; import java.util.List; import java.util.Map;