diff --git a/app/CHANGELOG-de.md b/app/CHANGELOG-de.md index 56ae44f7..348c4560 100644 --- a/app/CHANGELOG-de.md +++ b/app/CHANGELOG-de.md @@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [0.6.19-6] +Added more logging in wish functionality. + +## [0.6.19-5] +Using OkHttp to do the API requests. Potential fix for [#165](https://github.com/ironjan/metal-only/issues/165). + ## [0.6.19-1] Added Hyperlog (Debug build). diff --git a/app/CHANGELOG.md b/app/CHANGELOG.md index 7de661b8..67948efd 100644 --- a/app/CHANGELOG.md +++ b/app/CHANGELOG.md @@ -8,6 +8,12 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] +## [0.6.19-6] +Added more logging in wish functionality. + +## [0.6.19-5] +Using OkHttp to do the API requests. Potential fix for [#165](https://github.com/ironjan/metal-only/issues/165). + ## [0.6.19-1] Added Hyperlog (Debug build). diff --git a/app/build.gradle b/app/build.gradle index 354173e5..c9b18b70 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -3,7 +3,7 @@ def versionMajor = 0 // incompatible API changes def versionMinor = 6 // added functionality in a backwards-compatible manner def versionPatch = 19 // backwards-compatible bug fixes -def versionBuild = 1 // bump for dogfood builds, public betas, etc. +def versionBuild = 6 // bump for dogfood builds, public betas, etc. apply plugin: "com.android.application" apply plugin: "kotlin-android" @@ -64,7 +64,7 @@ android { if (project.hasProperty("metalonly.signing") && new File(project.property("metalonly.signing") + ".gradle").exists()) { - apply from: project.property("metalonly.signing") + ".gradle"; + apply from: project.property("metalonly.signing") + ".gradle" println("Applied production signing config") } else{ @@ -108,8 +108,8 @@ dependencies { compile "com.android.support:appcompat-v7:$appcompat_v7_version" compile "com.android.support:support-v4:$support_v4_version" - compile('com.crashlytics.sdk.android:crashlytics:2.6.8@aar') { - transitive = true; + compile('com.crashlytics.sdk.android:crashlytics:2.9.2@aar') { + transitive = true } compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" compile 'com.hypertrack:hyperlog:0.0.9' diff --git a/app/src/androidTest/java/com/codingspezis/android/metalonly/player/StreamActivity_Navigation_Test.java b/app/src/androidTest/java/com/codingspezis/android/metalonly/player/StreamActivity_Navigation_Test.java index 778e4edf..a72157d2 100644 --- a/app/src/androidTest/java/com/codingspezis/android/metalonly/player/StreamActivity_Navigation_Test.java +++ b/app/src/androidTest/java/com/codingspezis/android/metalonly/player/StreamActivity_Navigation_Test.java @@ -64,7 +64,7 @@ public void wishActivity_Navigation_Test(){ @Test public void favoritesActivity_Navigation_Test(){ ViewInteraction actionMenuItemView = onView( - allOf(withId(R.id.mnu_favorites), withText(R.string.menu_favorites), withContentDescription(R.string.menu_favorites), isDisplayed())); + allOf(withText(R.string.menu_favorites), isDisplayed())); actionMenuItemView.perform(click()); intended(hasComponent(new ComponentName(getTargetContext(), FavoritesActivity_.class))); diff --git a/app/src/main/java/com/codingspezis/android/metalonly/player/wish/WishFragment.java b/app/src/main/java/com/codingspezis/android/metalonly/player/wish/WishFragment.java index 852945ed..1ad5eeee 100644 --- a/app/src/main/java/com/codingspezis/android/metalonly/player/wish/WishFragment.java +++ b/app/src/main/java/com/codingspezis/android/metalonly/player/wish/WishFragment.java @@ -23,6 +23,7 @@ import com.codingspezis.android.metalonly.player.wish.WishPrefs_.WishPrefsEditor_; import com.github.ironjan.metalonly.client_library.MetalOnlyClient; import com.github.ironjan.metalonly.client_library.NoInternetException; +import com.github.ironjan.metalonly.client_library.Stats; import com.github.ironjan.metalonly.client_library.WishSender; import com.hypertrack.hyperlog.HyperLog; @@ -98,20 +99,24 @@ public class WishFragment extends Fragment implements WishSender.Callback { @AfterViews @Background void loadAllowedActions() { + HyperLog.d(TAG, "loadAllowedActions() - started"); FragmentActivity activity = getActivity(); - if (activity == null) return; + if (activity == null) { + HyperLog.d(TAG, "loadAllowedActions() - activity was null, early return"); + return; + } if (HTTPGrabber.isOnline(activity)) { showLoading(true); try { - Context context = getContext(); - if (context == null) { - return; - } - updateStats(MetalOnlyClient.Companion.getClient(context).getStats()); + HyperLog.d(TAG, "loadAllowedActions() - doing actual request"); + Stats stats = MetalOnlyClient.Companion.getClient(activity).getStats(); + HyperLog.d(TAG, "loadAllowedActions() - got a response, updating stats"); + updateStats(stats); } catch (NoInternetException | RestClientException e) { + HyperLog.e(TAG, "loadAllowedActions() - loading failed:", e); loadingAllowedActionsFailed(); } } else { diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/crashlytics/CrashlyticsPrefs.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/crashlytics/CrashlyticsPrefs.kt index 95f1d562..d34ec1a4 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/crashlytics/CrashlyticsPrefs.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/crashlytics/CrashlyticsPrefs.kt @@ -6,7 +6,7 @@ import org.androidannotations.annotations.sharedpreferences.SharedPref /** * User settings for sending crash reports. Use with the `@Pref CrashlyticsPrefs_`. */ -@SharedPref(value=SharedPref.Scope.UNIQUE) +@SharedPref(value = SharedPref.Scope.UNIQUE) interface CrashlyticsPrefs { /** * @return `true`, if the user disabled sending crash reports. `false` on default. diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/CurrencyFormatInputFilter.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/CurrencyFormatInputFilter.kt index 163ea38c..d197cf02 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/CurrencyFormatInputFilter.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/CurrencyFormatInputFilter.kt @@ -13,8 +13,14 @@ class CurrencyFormatInputFilter : InputFilter { internal var mPattern = Pattern.compile("(0|[1-9]+[0-9]*)?(\\.[0-9]{0,2})?") - override fun filter(source: CharSequence, start: Int, end: Int, - dest: Spanned, dstart: Int, dend: Int): CharSequence? { + override fun filter( + source: CharSequence, + start: Int, + end: Int, + dest: Spanned, + dstart: Int, + dend: Int + ): CharSequence? { val result = dest.subSequence(0, dstart).toString() + source.toString() dest.subSequence(dend, dest.length) diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/PayPalDonationFragment.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/PayPalDonationFragment.kt index d46f8844..1b88fbf9 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/PayPalDonationFragment.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/donation/PayPalDonationFragment.kt @@ -121,5 +121,4 @@ open class PayPalDonationFragment : Fragment() { super.onPause() } - } diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/FavoritesFragment.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/FavoritesFragment.kt index c4ac4594..6627ff45 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/FavoritesFragment.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/FavoritesFragment.kt @@ -48,8 +48,12 @@ open class FavoritesFragment : Fragment() { @AfterViews internal fun bindContent() { - favoritesSaver = SongSaver(activity, JSON_FILE_FAV, -1) - adapter = SongAdapterFavorites(activity, ArrayList(0)) + if (activity == null) { + return + } + + favoritesSaver = SongSaver(activity!!, JSON_FILE_FAV, -1) + adapter = SongAdapterFavorites(activity!!, ArrayList(0)) list!!.adapter = adapter list!!.emptyView = empty displayFavorites() @@ -179,7 +183,11 @@ open class FavoritesFragment : Fragment() { @OptionsItem(R.id.mnu_deleteall) internal fun deleteAllClicked() { - askSureDelete(activity, OnClickListener { dialog, action -> + if (activity == null) { + return + } + + askSureDelete(activity!!, OnClickListener { dialog, action -> favoritesSaver!!.clear() displayFavorites() }, null) @@ -221,5 +229,4 @@ open class FavoritesFragment : Fragment() { alert.show() } } - } diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/SongSaver.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/SongSaver.kt index 63f40ac1..8433a84b 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/SongSaver.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/favorites/SongSaver.kt @@ -22,8 +22,11 @@ import java.util.LinkedList * @param limit maximum of songs (FIFO) - if value <= 0 songs are unlimited */ -class SongSaver(private val context: Context, - private val fileName: String, limit: Int) { +class SongSaver( + private val context: Context, + private val fileName: String, + limit: Int +) { private var limit: Int = 0 private val trackList: LinkedList // main data private var changes: Boolean = false // is there share to save? @@ -76,7 +79,6 @@ class SongSaver(private val context: Context, } catch (e: JSONException) { e.printStackTrace() } - } /** @@ -108,7 +110,6 @@ class SongSaver(private val context: Context, } catch (e: IOException) { e.printStackTrace() } - } } @@ -239,5 +240,4 @@ class SongSaver(private val context: Context, val JSON_STRING_THUMB = "thumb" val JSON_LONG_DATE = "date" } - } \ No newline at end of file diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/fragments/AboutFragment.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/fragments/AboutFragment.kt index 152bc2c7..02672281 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/fragments/AboutFragment.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/fragments/AboutFragment.kt @@ -70,5 +70,4 @@ open class AboutFragment : Fragment() { prefs!!.edit().isCrashlyticsDisabled.put(isCrashlyticsDisabled).apply() super.onPause() } - } diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/plan/PlanAdapter.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/plan/PlanAdapter.kt index 1779034c..951c4db1 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/plan/PlanAdapter.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/plan/PlanAdapter.kt @@ -40,5 +40,4 @@ class PlanAdapter(private val context: Context, private val data: ArrayList = LinkedBlockingQueue() + private val downloadQueue: BlockingQueue = LinkedBlockingQueue() private val imageViews = Collections.synchronizedMap(WeakHashMap()) @@ -138,7 +138,7 @@ class ImageLoader private constructor(context: Context) { /** * Gets a singleton instance of the ImageLoader for usage. */ - fun instance(context: Context) : ImageLoader { + fun instance(context: Context): ImageLoader { synchronized(lock) { if (INSTANCE == null) { INSTANCE = ImageLoader(context.applicationContext) diff --git a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/views/Marquee.kt b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/views/Marquee.kt index 0e586d13..dcc4de69 100644 --- a/app/src/main/kotlin/com/codingspezis/android/metalonly/player/views/Marquee.kt +++ b/app/src/main/kotlin/com/codingspezis/android/metalonly/player/views/Marquee.kt @@ -22,8 +22,11 @@ class Marquee(context: Context, attrs: AttributeSet) : AppCompatTextView(context gravity = Gravity.CENTER_HORIZONTAL } - override fun onFocusChanged(focused: Boolean, direction: Int, - previouslyFocusedRect: Rect?) { + override fun onFocusChanged( + focused: Boolean, + direction: Int, + previouslyFocusedRect: Rect? + ) { if (focused) { super.onFocusChanged(focused, direction, previouslyFocusedRect) } diff --git a/build.gradle b/build.gradle index 615d7cbd..d7c03ab0 100644 --- a/build.gradle +++ b/build.gradle @@ -11,17 +11,17 @@ buildscript { jdk_compatibility = "1.8" // Dependency versions - appcompat_v7_version = "25.3.0" - androidannotations_version = "4.3.1" - espresso_version = "2.2.2" - jackson_version = "2.9.1" - junit_version = "4.12" - kotlin_version = "1.1.3-2" - ktlint_version = "0.9.0" - okhttp_version = "3.7.0" + appcompat_v7_version = "27.1.1" + support_v4_version = "27.1.1" + + androidannotations_version = "4.4.0" + espresso_version = "3.0.2" + jackson_version = "2.9.5" + junit_version = "4.12" + kotlin_version = "1.2.41" + ktlint_version = "0.22.0" slf4jAndroid_version = "1.7.25" spring_android_rest_template_version = "2.0.0.M3" - support_v4_version = "25.3.0" // Travis Speedup // allows for -Dpre-dex=false to be set @@ -32,6 +32,7 @@ buildscript { repositories { jcenter() maven { url 'https://maven.google.com' } + maven { url 'https://repo.spring.io/libs-milestone' } maven { url 'http://repo1.maven.org/maven2' } maven { url 'https://oss.sonatype.org/content/repositories/snapshots' } maven { url 'https://maven.fabric.io/public' } @@ -40,7 +41,7 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:3.0.0-beta7' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" - classpath 'com.github.ben-manes:gradle-versions-plugin:0.14.0' + classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0' // We recommend changing it to the latest version from our changelog: // https://docs.fabric.io/android/changelog.html#fabric-gradle-plugin diff --git a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/HistoricTrack.kt b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/HistoricTrack.kt index e6684f24..83735946 100644 --- a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/HistoricTrack.kt +++ b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/HistoricTrack.kt @@ -2,10 +2,12 @@ package com.codingspezis.android.metalonly.player.core import java.util.Comparator -data class HistoricTrack(override val artist: String, - override val title: String, - val thumbRaw: String, - override val playedAtAsLong: Long) +data class HistoricTrack( + override val artist: String, + override val title: String, + val thumbRaw: String, + override val playedAtAsLong: Long +) : Track, HistoricTrackExtension, Comparable { override val moderator: String = thumbRaw.replace(" OnAir", "") @@ -23,9 +25,9 @@ data class HistoricTrack(override val artist: String, fun limitedEquals(other: HistoricTrack?): Boolean { if (other == null) return false else - return artist == other.artist - && moderator == other.moderator - && title == other.title + return artist == other.artist && + moderator == other.moderator && + title == other.title } override fun compareTo(other: HistoricTrack): Int { @@ -36,7 +38,5 @@ data class HistoricTrack(override val artist: String, override fun compare(o1: HistoricTrack, o2: HistoricTrack): Int { return -o1.compareTo(o2) } - } - } diff --git a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/SimpleTrack.kt b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/SimpleTrack.kt index 7d1c09d9..a19460c1 100644 --- a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/SimpleTrack.kt +++ b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/core/SimpleTrack.kt @@ -1,5 +1,7 @@ package com.codingspezis.android.metalonly.player.core -data class SimpleTrack(override val artist: String, - override val title: String) +data class SimpleTrack( + override val artist: String, + override val title: String +) : Track \ No newline at end of file diff --git a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/Metadata.kt b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/Metadata.kt index 93a6cb32..7d070d78 100644 --- a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/Metadata.kt +++ b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/Metadata.kt @@ -14,5 +14,4 @@ data class Metadata internal constructor(val moderator: String, val genre: Strin return HistoricTrack(interpret, title, moderator, date) } - } \ No newline at end of file diff --git a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/MetadataFactory.kt b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/MetadataFactory.kt index 7064dac8..70434408 100644 --- a/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/MetadataFactory.kt +++ b/core/src/main/kotlin/com/codingspezis/android/metalonly/player/stream/metadata/MetadataFactory.kt @@ -36,11 +36,9 @@ object MetadataFactory { val interpret: String = data.substring(0, data.indexOf(" - ")).trim { it <= ' ' } val title: String = data.substring(data.indexOf(" - ") + 2).trim { it <= ' ' } return createMetadata(moderator, genre, interpret, title) - } catch (e: Exception) { return DEFAULT_METADATA } - } /** diff --git a/metal-only-client-library/build.gradle b/metal-only-client-library/build.gradle index 18e6b8f2..839c8497 100644 --- a/metal-only-client-library/build.gradle +++ b/metal-only-client-library/build.gradle @@ -55,7 +55,7 @@ android { if(project.hasProperty("metalonly.fabric.io") && new File(project.property("metalonly.fabric.io") + ".gradle").exists()) { - apply from: project.property("metalonly.fabric.io") + ".gradle"; + apply from: project.property("metalonly.fabric.io") + ".gradle" println("Applied fabric.io / crashlytics settings.") }else{ println("Project does not have fabric.io / crashlytics settings.") @@ -76,7 +76,8 @@ dependencies { compile "com.fasterxml.jackson.core:jackson-databind:$jackson_version" compile 'com.hypertrack:hyperlog:0.0.9' - compile "com.squareup.okhttp3:okhttp:$okhttp_version" + compile "com.squareup.okhttp:okhttp:2.7.5" // Version 3.x is incompatible with spring-android-rest-template + compile "org.springframework.android:spring-android-rest-template:$spring_android_rest_template_version" compile "org.androidannotations:androidannotations-api:$androidannotations_version" compile "org.androidannotations:rest-spring-api:$androidannotations_version" diff --git a/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/MetalOnlyClientImplementation.kt b/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/MetalOnlyClientImplementation.kt index 7eb8d018..8e6447b4 100644 --- a/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/MetalOnlyClientImplementation.kt +++ b/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/MetalOnlyClientImplementation.kt @@ -1,11 +1,13 @@ package com.github.ironjan.metalonly.client_library import android.net.ConnectivityManager +import com.hypertrack.hyperlog.HyperLog import org.androidannotations.annotations.AfterInject import org.androidannotations.annotations.EBean import org.androidannotations.annotations.SystemService import org.androidannotations.rest.spring.annotations.RestService import org.springframework.http.client.HttpComponentsClientHttpRequestFactory +import org.springframework.http.client.OkHttpClientHttpRequestFactory import org.springframework.http.client.SimpleClientHttpRequestFactory import org.springframework.web.client.RestClientException @@ -24,26 +26,20 @@ open class MetalOnlyClientImplementation : MetalOnlyClient { @SystemService internal var cm: ConnectivityManager? = null + private val TAG: String = "MetalOnlyClientImplementation" + @AfterInject internal fun adaptApiSettings() { - changeTimeout() - disableKeepAlive() - } + HyperLog.d(TAG, "adaptApiSettings() - started") + val requestFactory = OkHttpClientHttpRequestFactory() + requestFactory.setConnectTimeout(TIME_OUT) + requestFactory.setReadTimeout(TIME_OUT) - private fun changeTimeout() { - val requestFactory = api!!.restTemplate.requestFactory + api!!.restTemplate.requestFactory = requestFactory - if (requestFactory is SimpleClientHttpRequestFactory) { - val factory = requestFactory - - factory.setConnectTimeout(TIME_OUT) - factory.setReadTimeout(TIME_OUT) - } else if (requestFactory is HttpComponentsClientHttpRequestFactory) { - val factory = requestFactory + disableKeepAlive() - factory.setReadTimeout(TIME_OUT) - factory.setConnectTimeout(TIME_OUT) - } + HyperLog.d(TAG, "adaptApiSettings() - completed") } private fun disableKeepAlive() { @@ -67,7 +63,9 @@ open class MetalOnlyClientImplementation : MetalOnlyClient { } private fun checkConnectivity() { + HyperLog.d(TAG, "checkConnectivity() - started") if (hasNoInternetConnection()) { + HyperLog.d(TAG, "checkConnectivity() - no connection, throwing NoInternetException") throw NoInternetException() } } diff --git a/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/WishSender.kt b/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/WishSender.kt index 60ea9b35..10022370 100644 --- a/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/WishSender.kt +++ b/metal-only-client-library/src/main/kotlin/com/github/ironjan/metalonly/client_library/WishSender.kt @@ -1,10 +1,11 @@ package com.github.ironjan.metalonly.client_library import android.text.TextUtils -import okhttp3.MultipartBody -import okhttp3.OkHttpClient -import okhttp3.Request -import okhttp3.RequestBody +import com.hypertrack.hyperlog.HyperLog +import com.squareup.okhttp.MultipartBuilder +import com.squareup.okhttp.OkHttpClient +import com.squareup.okhttp.Request +import com.squareup.okhttp.RequestBody import java.io.IOException /** @@ -18,6 +19,8 @@ class WishSender { private val callback: Callback + private val TAG: String = "WishSender" + constructor(callback: Callback, nick: String, greet: String, artist: String? = null, title: String? = null) { this.nick = nick this.artist = artist @@ -28,6 +31,7 @@ class WishSender { val client = OkHttpClient() + /** * Sends the wish request. Note that this method does not yet handle all error cases: * - Bitte Wunsch/Gruss und einen Nick angeben @@ -35,8 +39,8 @@ class WishSender { * TODO Fix this */ fun send() { - var requestBodyBuilder = MultipartBody.Builder() - .setType(MultipartBody.FORM) + HyperLog.d(TAG, "send() - Starting to build request.") + var requestBodyBuilder = MultipartBuilder().type(MultipartBuilder.FORM) if (!TextUtils.isEmpty(nick)) { requestBodyBuilder = requestBodyBuilder.addFormDataPart(KEY_NICK, nick) @@ -59,16 +63,23 @@ class WishSender { .method("POST", RequestBody.create(null, ByteArray(0))) .post(requestBody) .build() + + + HyperLog.d(TAG, "send() - Built request. Sending...") try { val response = client.newCall(request).execute() - val responseBody = response.body().string() - if (response.code() == 200 && responseBody.contains(BuildConfig.WISH_SUCCESS)) { - callback.onSuccess() - } else { - callback.onFail() - } + HyperLog.d(TAG, "send() - Received response.") + val isSuccessResponseBody = response.body()?.string()?.contains(BuildConfig.WISH_SUCCESS) ?: false + if (response.code() == 200 && isSuccessResponseBody) { + HyperLog.d(TAG, "send() - Response was 'success'. Doing onSuccess-callback.") + callback.onSuccess() + } else { + HyperLog.d(TAG, "send() - Response was 'failure'. Doing onFail-callback.") + callback.onFail() + } } catch (e: IOException) { + HyperLog.d(TAG, "send() - Got an IOException. Doing onException-callback.") callback.onException(e) } }