-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial commit on Signal flow optimization
- have a callback mechanism for every signal operations Signed-off-by: Arka Prava Basu <[email protected]>
- Loading branch information
Showing
6 changed files
with
135 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/org/havenapp/main/service/LoggingTaskListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.havenapp.main.service | ||
|
||
import android.util.Log | ||
|
||
/** | ||
* An implementation of [SignalExecutorTask.TaskResult] which just logs the | ||
* msg on [SignalExecutorTask.TaskResult.onSuccess] and [SignalExecutorTask.TaskResult.onFailure] | ||
* Created by Arka Prava Basu<[email protected]> on 20/03/19 | ||
**/ | ||
class LoggingTaskListener: SignalExecutorTask.TaskResult { | ||
override fun onSuccess(msg: String) { | ||
Log.i(LoggingTaskListener::class.java.simpleName, msg) | ||
} | ||
|
||
override fun onFailure(msg: String) { | ||
Log.i(LoggingTaskListener::class.java.simpleName, msg) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/havenapp/main/service/SignalExecutorTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package org.havenapp.main.service | ||
|
||
import android.os.AsyncTask | ||
import net.sourceforge.argparse4j.inf.Namespace | ||
import org.asamk.signal.Main | ||
|
||
/** | ||
* Created by Arka Prava Basu<[email protected]> on 20/03/19 | ||
**/ | ||
class SignalExecutorTask(private val commandMap: HashMap<String, Any>, | ||
private val mainSignal: Main, | ||
private val listener: TaskResult?) | ||
: AsyncTask<Unit, Unit, Int>() { | ||
|
||
override fun doInBackground(vararg params: Unit?): Int { | ||
val namespace = Namespace(commandMap) | ||
return mainSignal.handleCommands(namespace) | ||
} | ||
|
||
override fun onPostExecute(result: Int) { | ||
super.onPostExecute(result) | ||
if (result == 0) { | ||
listener?.onSuccess("Success for request map $commandMap") | ||
} else { | ||
listener?.onFailure("Failure for request map $commandMap") | ||
} | ||
} | ||
|
||
interface TaskResult { | ||
/** | ||
* Indicates that the command executed successfully | ||
*/ | ||
fun onSuccess(msg: String) | ||
|
||
/** | ||
* A failure. Should probably return a failure msg | ||
* todo | ||
*/ | ||
fun onFailure(msg: String) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters