Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fun addPost(): Unit {
- viewModel.addPost(dataSource.text.get(), dataSource.title.get(), { postID: Long ->
- if (postID.equals(0)) {
- Toast.makeText(MyApp.instance.getContext(), "Error", Toast.LENGTH_LONG).show()
- } else {
- (arguments.get(ARG_RunOnPositiveDismiss) as (DMPost) -> Unit)(DMPost(postID, MyOptions.User.GET()!!.UserID, dataSource.title.get(), dataSource.text.get()))
- dismiss()
- }
- })
- }
- fun addPost(title:String,text:String,onSuccess: (Long) -> Unit): Unit {
- rep.insertPost(DMPost(0, MyOptions.User.GET()!!.UserID, title, text),onSuccess)
- }
- fun insertPost(post: DMPost, onSuccess: (Long) -> Unit) {
- if (MyOptions.Online.GET()!!) {
- val client = retrofit.create(APIPost::class.java)
- val insertPost: Call<Long> = client.insertPost(post)
- insertPost.enqueue(object : Callback<Long> {
- override fun onResponse(call: Call<Long>, response: Response<Long>) {
- if (response.isSuccessful) {
- onSuccess(response.body()!!)
- } else {
- onSuccess(0)
- }
- }
- override fun onFailure(call: Call<Long>, t: Throwable) {
- onSuccess(0)
- }
- })
- } else {
- AsyncTask.execute {
- try {
- onSuccess(daoPost.insertPost(EntityPost(post)))
- } catch (e: Exception) {
- onSuccess(0)
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment