mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
94 lines
2.1 KiB
Java
94 lines
2.1 KiB
Java
package com.b44t.messenger;
|
|
|
|
public class DcAccounts {
|
|
|
|
public DcAccounts(String dir, DcEventChannel channel) {
|
|
accountsCPtr = createAccountsCPtr(dir, channel);
|
|
if (accountsCPtr == 0) throw new RuntimeException("createAccountsCPtr() returned null pointer");
|
|
}
|
|
|
|
@Override
|
|
protected void finalize() throws Throwable {
|
|
super.finalize();
|
|
unref();
|
|
}
|
|
|
|
public void unref() {
|
|
if (accountsCPtr != 0) {
|
|
unrefAccountsCPtr();
|
|
accountsCPtr = 0;
|
|
}
|
|
}
|
|
|
|
public DcEventEmitter getEventEmitter() {
|
|
return new DcEventEmitter(getEventEmitterCPtr());
|
|
}
|
|
|
|
public DcJsonrpcInstance getJsonrpcInstance() {
|
|
return new DcJsonrpcInstance(getJsonrpcInstanceCPtr());
|
|
}
|
|
|
|
public void startIo() {
|
|
for (int accountId : getAll()) {
|
|
DcContext acc = getAccount(accountId);
|
|
if (acc.isEnabled()) {
|
|
acc.startIo();
|
|
}
|
|
}
|
|
}
|
|
;
|
|
|
|
public native void startIo2();
|
|
|
|
public native void stopIo();
|
|
|
|
public native void maybeNetwork();
|
|
|
|
public native void setPushDeviceToken(String token);
|
|
|
|
public native boolean backgroundFetch(int timeoutSeconds);
|
|
|
|
public native void stopBackgroundFetch();
|
|
|
|
public native int migrateAccount(String dbfile);
|
|
|
|
public native boolean removeAccount(int accountId);
|
|
|
|
public native int[] getAll();
|
|
|
|
public DcContext getAccount(int accountId) {
|
|
return new DcContext(getAccountCPtr(accountId));
|
|
}
|
|
|
|
public DcContext getSelectedAccount() {
|
|
return new DcContext(getSelectedAccountCPtr());
|
|
}
|
|
|
|
public native boolean selectAccount(int accountId);
|
|
|
|
// working with raw c-data
|
|
private long accountsCPtr; // CAVE: the name is referenced in the JNI
|
|
|
|
private native long createAccountsCPtr(String dir, DcEventChannel channel);
|
|
|
|
private native void unrefAccountsCPtr();
|
|
|
|
private native long getEventEmitterCPtr();
|
|
|
|
private native long getJsonrpcInstanceCPtr();
|
|
|
|
private native long getAccountCPtr(int accountId);
|
|
|
|
private native long getSelectedAccountCPtr();
|
|
|
|
public boolean isAllChatmail() {
|
|
for (int accountId : getAll()) {
|
|
DcContext dcContext = getAccount(accountId);
|
|
if (!dcContext.isChatmail()) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
}
|