From dcc3ec6f887375ade18a4303ba394efa6a4f7a12 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Thu, 21 Mar 2019 15:41:06 +0000 Subject: [PATCH] Fix crash when removing journal members --- .../etesync/syncadapter/ui/RemoveMemberFragment.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/com/etesync/syncadapter/ui/RemoveMemberFragment.kt b/app/src/main/java/com/etesync/syncadapter/ui/RemoveMemberFragment.kt index 1070f144..ca7cf8b6 100644 --- a/app/src/main/java/com/etesync/syncadapter/ui/RemoveMemberFragment.kt +++ b/app/src/main/java/com/etesync/syncadapter/ui/RemoveMemberFragment.kt @@ -15,8 +15,6 @@ import okhttp3.OkHttpClient class RemoveMemberFragment : DialogFragment() { private var settings: AccountSettings? = null - private var httpClient: OkHttpClient? = null - private var remote: HttpUrl? = null private var info: CollectionInfo? = null private var memberEmail: String? = null @@ -27,13 +25,10 @@ class RemoveMemberFragment : DialogFragment() { memberEmail = arguments!!.getString(KEY_MEMBER) try { settings = AccountSettings(context!!, account!!) - httpClient = HttpClient.Builder(context, settings).build().okHttpClient } catch (e: InvalidAccountException) { e.printStackTrace() } - remote = HttpUrl.get(settings!!.uri!!) - MemberRemove().execute() } @@ -49,8 +44,12 @@ class RemoveMemberFragment : DialogFragment() { private inner class MemberRemove : AsyncTask() { override fun doInBackground(vararg voids: Void): RemoveResult { + val httpClient = HttpClient.Builder(context, settings).build() + try { - val journalsManager = JournalManager(httpClient!!, remote!!) + val remote = HttpUrl.get(settings!!.uri!!) + + val journalsManager = JournalManager(httpClient.okHttpClient, remote!!) val journal = JournalManager.Journal.fakeWithUid(info!!.uid!!) val member = JournalManager.Member(memberEmail!!, "placeholder".toByteArray()) @@ -59,8 +58,9 @@ class RemoveMemberFragment : DialogFragment() { return RemoveResult(null) } catch (e: Exception) { return RemoveResult(e) + } finally { + httpClient.close() } - } override fun onPostExecute(result: RemoveResult) {