Receiving almost works, unfortunately, JDBC doesn't so I have to rewrite the whole damn repository code.
This commit is contained in:
@ -0,0 +1,28 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
/**
|
||||
* Compose a new message.
|
||||
*/
|
||||
public class ComposeMessageActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.toolbar_layout);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
getSupportActionBar().setHomeAsUpIndicator(R.drawable.ic_action_close);
|
||||
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
|
||||
getSupportActionBar().setHomeButtonEnabled(false);
|
||||
|
||||
// Display the fragment as the main content.
|
||||
getSupportFragmentManager().beginTransaction()
|
||||
.replace(R.id.content, new ComposeMessageFragment())
|
||||
.commit();
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.*;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Toast;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
|
||||
/**
|
||||
* Compose a new message.
|
||||
*/
|
||||
public class ComposeMessageFragment extends Fragment {
|
||||
/**
|
||||
* The fragment argument representing the sender identity.
|
||||
*/
|
||||
public static final String ARG_IDENTITY = "from";
|
||||
/**
|
||||
* The fragment argument representing the recipient.
|
||||
*/
|
||||
public static final String ARG_RECIPIENT = "to";
|
||||
|
||||
private BitmessageContext bmCtx;
|
||||
private BitmessageAddress identity;
|
||||
private BitmessageAddress recipient;
|
||||
|
||||
/**
|
||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||
* fragment (e.g. upon screen orientation changes).
|
||||
*/
|
||||
public ComposeMessageFragment() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
if (getArguments().containsKey(ARG_IDENTITY)) {
|
||||
identity = (BitmessageAddress) getArguments().getSerializable(ARG_IDENTITY);
|
||||
}
|
||||
if (getArguments().containsKey(ARG_RECIPIENT)) {
|
||||
recipient = (BitmessageAddress) getArguments().getSerializable(ARG_RECIPIENT);
|
||||
}
|
||||
}
|
||||
setHasOptionsMenu(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View rootView = inflater.inflate(R.layout.fragment_compose_message, container, false);
|
||||
EditText body = (EditText) rootView.findViewById(R.id.body);
|
||||
body.setInputType(EditorInfo.TYPE_TEXT_VARIATION_SHORT_MESSAGE | EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE);
|
||||
body.setImeOptions(EditorInfo.IME_ACTION_SEND | EditorInfo.IME_FLAG_NO_ENTER_ACTION);
|
||||
return rootView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.compose, menu);
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.send:
|
||||
Toast.makeText(getActivity(), "TODO: Send", Toast.LENGTH_SHORT).show();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
102
app/src/main/java/ch/dissem/apps/abit/Identicon.java
Normal file
102
app/src/main/java/ch/dissem/apps/abit/Identicon.java
Normal file
@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright 2015 Christian Basler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
|
||||
import android.graphics.*;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class Identicon extends Drawable {
|
||||
private static final int SIZE = 9;
|
||||
private static final int CENTER_COLUMN = 5;
|
||||
|
||||
private final Paint paint;
|
||||
private float cellWidth;
|
||||
private float cellHeight;
|
||||
private byte[] hash;
|
||||
private int color;
|
||||
private int background;
|
||||
private boolean[][] fields;
|
||||
|
||||
public Identicon(BitmessageAddress input) {
|
||||
paint = new Paint();
|
||||
paint.setStyle(Paint.Style.FILL);
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
hash = input.getRipe();
|
||||
|
||||
fields = new boolean[SIZE][SIZE];
|
||||
color = Color.HSVToColor(new float[]{Math.abs(hash[0] * hash[1] + hash[2]) % 360, 0.8f, 1.0f});
|
||||
background = Color.HSVToColor(new float[]{Math.abs(hash[1] * hash[2] + hash[0]) % 360, 0.8f, 1.0f});
|
||||
|
||||
for (int row = 0; row < SIZE; row++) {
|
||||
for (int column = 0; column < SIZE; column++) {
|
||||
fields[row][column] = hash[(row * (column < CENTER_COLUMN ? column : SIZE - column - 1)) % hash.length] >= 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected byte getByte(int index) {
|
||||
return hash[index % hash.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
float x, y;
|
||||
paint.setColor(background);
|
||||
canvas.drawPaint(paint);
|
||||
paint.setColor(color);
|
||||
for (int row = 0; row < SIZE; row++) {
|
||||
for (int column = 0; column < SIZE; column++) {
|
||||
if (fields[row][column]) {
|
||||
x = cellWidth * column;
|
||||
y = cellHeight * row;
|
||||
|
||||
canvas.drawCircle(x + cellWidth / 2, y + cellHeight / 2, cellHeight / 2, paint);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setAlpha(int alpha) {
|
||||
paint.setAlpha(alpha);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setColorFilter(ColorFilter cf) {
|
||||
paint.setColorFilter(cf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOpacity() {
|
||||
return PixelFormat.OPAQUE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBoundsChange(Rect bounds) {
|
||||
super.onBoundsChange(bounds);
|
||||
|
||||
cellWidth = bounds.width() / (float) SIZE;
|
||||
cellHeight = bounds.height() / (float) SIZE;
|
||||
}
|
||||
|
||||
}
|
@ -5,13 +5,16 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.Toast;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label;
|
||||
import com.mikepenz.community_material_typeface_library.CommunityMaterial;
|
||||
import com.mikepenz.google_material_typeface_library.GoogleMaterial;
|
||||
import com.mikepenz.iconics.IconicsDrawable;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
@ -59,6 +62,7 @@ public class MessageListActivity extends AppCompatActivity
|
||||
private AccountHeader accountHeader;
|
||||
private BitmessageContext bmc;
|
||||
private Label selectedLabel;
|
||||
private Menu menu;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
@ -68,7 +72,7 @@ public class MessageListActivity extends AppCompatActivity
|
||||
|
||||
setContentView(R.layout.activity_message_list);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
if (findViewById(R.id.message_detail_container) != null) {
|
||||
@ -109,7 +113,7 @@ public class MessageListActivity extends AppCompatActivity
|
||||
.withIdentifier(ADD_IDENTITY)
|
||||
);
|
||||
profiles.add(new ProfileSettingDrawerItem()
|
||||
.withName("Manage Account")
|
||||
.withName(getString(R.string.manage_identity))
|
||||
.withIcon(GoogleMaterial.Icon.gmd_settings)
|
||||
);
|
||||
// Create the AccountHeader
|
||||
@ -150,6 +154,9 @@ public class MessageListActivity extends AppCompatActivity
|
||||
.withAccountHeader(accountHeader)
|
||||
.withDrawerItems(drawerItems)
|
||||
.addStickyDrawerItems(
|
||||
new SecondaryDrawerItem()
|
||||
.withName(getString(R.string.subscriptions))
|
||||
.withIcon(CommunityMaterial.Icon.cmd_rss),
|
||||
new SecondaryDrawerItem()
|
||||
.withName(R.string.settings)
|
||||
.withIcon(GoogleMaterial.Icon.gmd_settings)
|
||||
@ -162,6 +169,9 @@ public class MessageListActivity extends AppCompatActivity
|
||||
} else if (item instanceof Nameable<?>) {
|
||||
Nameable<?> ni = (Nameable<?>) item;
|
||||
switch (ni.getNameRes()) {
|
||||
case R.string.subscriptions:
|
||||
// TODO
|
||||
break;
|
||||
case R.string.settings:
|
||||
startActivity(new Intent(MessageListActivity.this, SettingsActivity.class));
|
||||
break;
|
||||
@ -176,10 +186,37 @@ public class MessageListActivity extends AppCompatActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
this.menu = menu;
|
||||
updateMenu();
|
||||
return true;
|
||||
}
|
||||
|
||||
private void updateMenu() {
|
||||
boolean running = bmc.isRunning();
|
||||
menu.findItem(R.id.sync_enabled).setVisible(running);
|
||||
menu.findItem(R.id.sync_disabled).setVisible(!running);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.sync_disabled:
|
||||
bmc.startup(new BitmessageContext.Listener() {
|
||||
@Override
|
||||
public void receive(Plaintext plaintext) {
|
||||
// TODO
|
||||
Toast.makeText(MessageListActivity.this, plaintext.getSubject(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
updateMenu();
|
||||
return true;
|
||||
case R.id.sync_enabled:
|
||||
bmc.shutdown();
|
||||
updateMenu();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1,6 +1,7 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.v4.app.ListFragment;
|
||||
@ -9,8 +10,6 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.Plaintext;
|
||||
@ -97,7 +96,7 @@ public class MessageListFragment extends ListFragment {
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Toast.makeText(MessageListFragment.this.getActivity(), "TODO", Toast.LENGTH_SHORT).show();
|
||||
startActivity(new Intent(getActivity().getApplicationContext(), ComposeMessageActivity.class));
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -0,0 +1,113 @@
|
||||
/*
|
||||
* Copyright 2015 Christian Basler
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.Switch;
|
||||
import android.widget.TextView;
|
||||
import ch.dissem.apps.abit.service.Singleton;
|
||||
import ch.dissem.bitmessage.BitmessageContext;
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress;
|
||||
|
||||
public class OpenBitmessageLinkActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_open_bitmessage_link);
|
||||
|
||||
final TextView addressView = (TextView) findViewById(R.id.address);
|
||||
final EditText label = (EditText) findViewById(R.id.label);
|
||||
final Switch importContact = (Switch) findViewById(R.id.import_contact);
|
||||
final Switch subscribe = (Switch) findViewById(R.id.subscribe);
|
||||
|
||||
Uri uri = getIntent().getData();
|
||||
final String address = getAddress(uri);
|
||||
String[] parameters = getParameters(uri);
|
||||
for (String parameter : parameters) {
|
||||
String name = parameter.substring(0, 6).toLowerCase();
|
||||
if (name.startsWith("label")) {
|
||||
label.setText(parameter.substring(parameter.indexOf('=') + 1).trim());
|
||||
} else if (name.startsWith("action")) {
|
||||
parameter = parameter.toLowerCase();
|
||||
importContact.setChecked(parameter.contains("add"));
|
||||
subscribe.setChecked(parameter.contains("subscribe"));
|
||||
}
|
||||
}
|
||||
|
||||
addressView.setText(address);
|
||||
|
||||
|
||||
final Button cancel = (Button) findViewById(R.id.cancel);
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
setResult(Activity.RESULT_CANCELED);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
final Button ok = (Button) findViewById(R.id.do_import);
|
||||
ok.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
BitmessageContext bmc = Singleton.getBitmessageContext(OpenBitmessageLinkActivity.this);
|
||||
BitmessageAddress bmAddress = new BitmessageAddress(address);
|
||||
bmAddress.setAlias(label.getText().toString());
|
||||
if (subscribe.isChecked()) {
|
||||
bmc.addSubscribtion(bmAddress);
|
||||
}
|
||||
if (importContact.isChecked()) {
|
||||
bmc.addContact(bmAddress);
|
||||
}
|
||||
setResult(Activity.RESULT_OK);
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private String getAddress(Uri uri) {
|
||||
StringBuilder result = new StringBuilder();
|
||||
String schemeSpecificPart = uri.getSchemeSpecificPart();
|
||||
if (!schemeSpecificPart.startsWith("BM-")) {
|
||||
result.append("BM-");
|
||||
}
|
||||
if (schemeSpecificPart.contains("?")) {
|
||||
result.append(schemeSpecificPart.substring(0, schemeSpecificPart.indexOf('?')));
|
||||
} else if (schemeSpecificPart.contains("#")) {
|
||||
result.append(schemeSpecificPart.substring(0, schemeSpecificPart.indexOf('#')));
|
||||
} else {
|
||||
result.append(schemeSpecificPart);
|
||||
}
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String[] getParameters(Uri uri) {
|
||||
int index = uri.getSchemeSpecificPart().indexOf('?');
|
||||
if (index >= 0) {
|
||||
String parameterPart = uri.getSchemeSpecificPart().substring(index + 1);
|
||||
return parameterPart.split("&");
|
||||
} else {
|
||||
return new String[0];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package ch.dissem.apps.abit;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Environment;
|
||||
import ch.dissem.bitmessage.repository.JdbcConfig;
|
||||
import org.flywaydb.core.api.android.ContextHolder;
|
||||
import org.sqldroid.SQLDroidDriver;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Properties;
|
||||
|
||||
/**
|
||||
* Created by chris on 14.07.15.
|
||||
*/
|
||||
public class SQLiteConfig extends JdbcConfig {
|
||||
|
||||
public SQLiteConfig(Context ctx) {
|
||||
super(getDbUrl(ctx), "", "");
|
||||
}
|
||||
|
||||
private static String getDbUrl(Context ctx) {
|
||||
SQLiteDatabase db = ctx.openOrCreateDatabase(Environment.getExternalStorageDirectory()
|
||||
+ "/jabit.db", Context.MODE_PRIVATE, null);
|
||||
ContextHolder.setContext(ctx);
|
||||
return "jdbc:sqlite:" + db.getPath() + "?timeout=5";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Connection getConnection() throws SQLException {
|
||||
Properties removeLocale = new Properties();
|
||||
removeLocale.put(SQLDroidDriver.ADDITONAL_DATABASE_FLAGS, android.database.sqlite.SQLiteDatabase.NO_LOCALIZED_COLLATORS);
|
||||
return DriverManager.getConnection(dbUrl, removeLocale);
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
package ch.dissem.apps.abit.repositories;
|
||||
|
||||
/**
|
||||
* Created by chris on 14.08.15.
|
||||
*/
|
||||
public class AndroidInventory {
|
||||
}
|
Reference in New Issue
Block a user