remove unnecessary methods from callback
This commit is contained in:
parent
8b6027ac9a
commit
5ce94dc933
6 changed files with 30 additions and 37 deletions
|
@ -6,8 +6,4 @@ interface IOsmAndAidlCallback {
|
|||
void onSearchComplete(in List<SearchResult> resultSet);
|
||||
|
||||
void onUpdate();
|
||||
|
||||
long getId();
|
||||
|
||||
void setId(long id);
|
||||
}
|
|
@ -131,6 +131,6 @@ interface IOsmAndAidlInterface {
|
|||
boolean search(in SearchParams params, IOsmAndAidlCallback callback);
|
||||
boolean navigateSearch(in NavigateSearchParams params);
|
||||
|
||||
boolean registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
|
||||
boolean unregisterFromUpdates(in IOsmAndAidlCallback callback);
|
||||
long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
|
||||
boolean unregisterFromUpdates(in long callbackId);
|
||||
}
|
|
@ -89,13 +89,6 @@ class OsmandAidlHelper(private val app: TelegramApplication) {
|
|||
mUpdatesListener!!.update()
|
||||
}
|
||||
}
|
||||
|
||||
override fun getId() = osmandCallbackId
|
||||
|
||||
|
||||
override fun setId(id: Long) {
|
||||
osmandCallbackId = id
|
||||
}
|
||||
}
|
||||
|
||||
fun setSearchCompleteListener(mSearchCompleteListener: SearchCompleteListener) {
|
||||
|
@ -1046,7 +1039,8 @@ class OsmandAidlHelper(private val app: TelegramApplication) {
|
|||
fun registerForUpdates(): Boolean {
|
||||
if (mIOsmAndAidlInterface != null) {
|
||||
try {
|
||||
return mIOsmAndAidlInterface!!.registerForUpdates(UPDATE_TIME_MS, mIOsmAndAidlCallback)
|
||||
osmandCallbackId = mIOsmAndAidlInterface!!.registerForUpdates(UPDATE_TIME_MS, mIOsmAndAidlCallback)
|
||||
return osmandCallbackId > 0
|
||||
} catch (e: RemoteException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
@ -1057,7 +1051,7 @@ class OsmandAidlHelper(private val app: TelegramApplication) {
|
|||
fun unregisterFromUpdates(): Boolean {
|
||||
if (mIOsmAndAidlInterface != null) {
|
||||
try {
|
||||
return mIOsmAndAidlInterface!!.unregisterFromUpdates(mIOsmAndAidlCallback)
|
||||
return mIOsmAndAidlInterface!!.unregisterFromUpdates(osmandCallbackId)
|
||||
} catch (e: RemoteException) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
|
|
|
@ -6,8 +6,4 @@ interface IOsmAndAidlCallback {
|
|||
void onSearchComplete(in List<SearchResult> resultSet);
|
||||
|
||||
void onUpdate();
|
||||
|
||||
long getId();
|
||||
|
||||
void setId(long id);
|
||||
}
|
|
@ -131,6 +131,6 @@ interface IOsmAndAidlInterface {
|
|||
boolean search(in SearchParams params, IOsmAndAidlCallback callback);
|
||||
boolean navigateSearch(in NavigateSearchParams params);
|
||||
|
||||
boolean registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
|
||||
boolean unregisterFromUpdates(in IOsmAndAidlCallback callback);
|
||||
long registerForUpdates(in long updateTimeMS, IOsmAndAidlCallback callback);
|
||||
boolean unregisterFromUpdates(in long callbackId);
|
||||
}
|
|
@ -71,6 +71,8 @@ public class OsmandAidlService extends Service {
|
|||
|
||||
private static final int MIN_UPDATE_TIME_MS = 1000;
|
||||
|
||||
private static final int MIN_UPDATE_TIME_MS_ERROR = -1;
|
||||
|
||||
private Map<Long, IOsmAndAidlCallback> callbacks;
|
||||
private Handler mHandler = null;
|
||||
HandlerThread mHandlerThread = new HandlerThread("OsmAndAidlServiceThread");
|
||||
|
@ -102,6 +104,13 @@ public class OsmandAidlService extends Service {
|
|||
callbacks = new HashMap<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
callbacks.clear();
|
||||
mHandlerThread.quit();
|
||||
}
|
||||
|
||||
private final IOsmAndAidlInterface.Stub mBinder = new IOsmAndAidlInterface.Stub() {
|
||||
|
||||
private void handleException(Exception e) {
|
||||
|
@ -593,39 +602,37 @@ public class OsmandAidlService extends Service {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) throws RemoteException {
|
||||
if (callback != null && updateTimeMS >= MIN_UPDATE_TIME_MS) {
|
||||
callback.setId(updateCallbackId);
|
||||
callbacks.put(updateCallbackId, callback);
|
||||
public long registerForUpdates(long updateTimeMS, IOsmAndAidlCallback callback) throws RemoteException {
|
||||
if (updateTimeMS >= MIN_UPDATE_TIME_MS) {
|
||||
updateCallbackId++;
|
||||
startRemoteUpdates(updateTimeMS, callback);
|
||||
return true;
|
||||
callbacks.put(updateCallbackId, callback);
|
||||
startRemoteUpdates(updateTimeMS, updateCallbackId, callback);
|
||||
return updateCallbackId;
|
||||
} else {
|
||||
return MIN_UPDATE_TIME_MS_ERROR;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean unregisterFromUpdates(IOsmAndAidlCallback callback) throws RemoteException {
|
||||
if (callback != null) {
|
||||
callbacks.remove(callback.getId());
|
||||
}
|
||||
return false;
|
||||
public boolean unregisterFromUpdates(long callbackId) throws RemoteException {
|
||||
callbacks.remove(callbackId);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void startRemoteUpdates(final long updateTimeMS, final IOsmAndAidlCallback callback) {
|
||||
void startRemoteUpdates(final long updateTimeMS, final long callbackId, final IOsmAndAidlCallback callback) {
|
||||
mHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (callbacks.containsKey(callback.getId())) {
|
||||
if (callbacks.containsKey(callbackId)) {
|
||||
if (getApi("isUpdateAllowed").isUpdateAllowed()) {
|
||||
callback.onUpdate();
|
||||
}
|
||||
startRemoteUpdates(updateTimeMS, callback);
|
||||
startRemoteUpdates(updateTimeMS, callbackId, callback);
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
e.printStackTrace();
|
||||
LOG.error("AIDL e.getMessage()", e);
|
||||
}
|
||||
}
|
||||
}, updateTimeMS);
|
||||
|
|
Loading…
Reference in a new issue