Skip to content

Commit

Permalink
Update to new tox api and enable tcp only be default. Option to enabl…
Browse files Browse the repository at this point in the history
…e udp coming later
  • Loading branch information
markwinter committed Sep 3, 2014
1 parent 8014fa7 commit e16c9b2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import im.tox.antox.utils.AntoxFriendList;
import im.tox.jtoxcore.JTox;
import im.tox.jtoxcore.ToxException;
import im.tox.jtoxcore.ToxOptions;
import im.tox.jtoxcore.callbacks.CallbackHandler;

public class CreateAcccountActivity extends ActionBarActivity{
Expand Down Expand Up @@ -117,16 +118,12 @@ public void onClickRegisterAccount(View view) {
Toast toast = Toast.makeText(context, text, duration);
toast.show();
} else {
// Load tox libraries
try {
System.load("/data/data/im.tox.antox/lib/libsodium.so");
System.load("/data/data/im.tox.antox/lib/libtoxcore.so");
System.load("/data/data/im.tox.antox/lib/libtox.so");
} catch (Exception e) {
Log.d("CreateAccount", "Failed System.load()");
e.printStackTrace();
Log.d("CreateAccount", e.getMessage());
}


// Add user to DB
UserDB db = new UserDB(this);
db.addUser(account, password1);
Expand All @@ -137,7 +134,11 @@ public void onClickRegisterAccount(View view) {
try {
AntoxFriendList antoxFriendList = new AntoxFriendList();
CallbackHandler callbackHandler = new CallbackHandler(antoxFriendList);
JTox jTox = new JTox(antoxFriendList, callbackHandler);
ToxOptions toxOptions = new ToxOptions();
toxOptions.setUdpEnabled(false);
toxOptions.setIpv6Enabled(true);
toxOptions.setProxyEnabled(false);
JTox jTox = new JTox(antoxFriendList, callbackHandler, toxOptions);
ToxDataFile toxDataFile = new ToxDataFile(this, account);
toxDataFile.saveFile(jTox.save());
ID = jTox.getAddress();
Expand Down
7 changes: 4 additions & 3 deletions app/src/main/java/im/tox/antox/fragments/ChatFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,19 @@ else if((msg.charAt(i) & ThreeByte) == 0)
total += 4;

if(numberOfMessagesSent == numOfMessages-1) {
toxSingleton.jTox.sendMessage(friend, msg.substring(previous), id);
// TODO: fix id's since withid was removed
toxSingleton.jTox.sendMessage(friend, msg.substring(previous));
break;
} else if(total >= 1366) {
toxSingleton.jTox.sendMessage(friend, msg.substring(previous, i), id);
toxSingleton.jTox.sendMessage(friend, msg.substring(previous, i));
numberOfMessagesSent++;
previous = i;
total = 0;
}
}

} else {
toxSingleton.jTox.sendMessage(friend, msg, id);
toxSingleton.jTox.sendMessage(friend, msg);
}

} catch (ToxException e) {
Expand Down
20 changes: 12 additions & 8 deletions app/src/main/java/im/tox/antox/tox/ToxSingleton.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import im.tox.jtoxcore.JTox;
import im.tox.jtoxcore.ToxException;
import im.tox.jtoxcore.ToxFileControl;
import im.tox.jtoxcore.ToxOptions;
import im.tox.jtoxcore.ToxUserStatus;
import im.tox.jtoxcore.callbacks.CallbackHandler;
import rx.Observable;
Expand Down Expand Up @@ -564,7 +565,8 @@ public void sendUnsentMessages(Context ctx) {
}
try {
if (friend != null) {
jTox.sendMessage(friend, unsentMessageList.get(i).message, id);
// TODO: fix for withid change
jTox.sendMessage(friend, unsentMessageList.get(i).message);
}
} catch (ToxException e) {
Log.d(TAG, e.toString());
Expand Down Expand Up @@ -628,24 +630,26 @@ private ToxSingleton() {
public void initTox(Context ctx) {

try {
System.load("/data/data/im.tox.antox/lib/libsodium.so");
System.load("/data/data/im.tox.antox/lib/libtoxcore.so");
System.load("/data/data/im.tox.antox/lib/libtox.so");
} catch (Exception e) {
Log.d(TAG, "Failed System.load()");
e.printStackTrace();
Log.d("CreateAccount", e.getMessage());
}


antoxFriendList = new AntoxFriendList();
callbackHandler = new CallbackHandler(antoxFriendList);

qrFile = ctx.getFileStreamPath("userkey_qr.png");
dataFile = new ToxDataFile(ctx);

ToxOptions options = new ToxOptions();
options.setIpv6Enabled(true);
options.setUdpEnabled(false);
options.setProxyEnabled(false);

/* Choose appropriate constructor depending on if data file exists */
if (!dataFile.doesFileExist()) {
try {
jTox = new JTox(antoxFriendList, callbackHandler);
jTox = new JTox(antoxFriendList, callbackHandler, options);
/* Save data file */
dataFile.saveFile(jTox.save());
/* Save users public key to settings */
Expand All @@ -658,7 +662,7 @@ public void initTox(Context ctx) {
}
} else {
try {
jTox = new JTox(dataFile.loadFile(), antoxFriendList, callbackHandler);
jTox = new JTox(dataFile.loadFile(), antoxFriendList, callbackHandler, options);
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(ctx);
SharedPreferences.Editor editor = preferences.edit();
editor.putString("tox_id", jTox.getAddress());
Expand Down

0 comments on commit e16c9b2

Please sign in to comment.