diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e35571..9d952d2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,8 @@ - Closing #322. App crashed because of svg images. +- Closing #236. New sources can be added in Selfoss 2.19. + **1.6.x** - Handling hidden tags. diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt index 5246df3..a92726b 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/AddSourceActivity.kt @@ -206,42 +206,78 @@ class AddSourceActivity : AppCompatActivity() { private fun handleSaveSource(tags: EditText, title: String, url: String, api: SelfossApi) { - val sourceDetailsAvailable = + val sourceDetailsUnavailable = title.isEmpty() || url.isEmpty() || mSpoutsValue == null || mSpoutsValue!!.isEmpty() - if (sourceDetailsAvailable) { - Toast.makeText(this, R.string.form_not_complete, Toast.LENGTH_SHORT).show() - } else { - api.createSource( - title, - url, - mSpoutsValue!!, - tags.text.toString(), - "" - ).enqueue(object : Callback { - override fun onResponse( - call: Call, - response: Response - ) { - if (response.body() != null && response.body()!!.isSuccess) { - finish() - } else { + when { + sourceDetailsUnavailable -> { + Toast.makeText(this, R.string.form_not_complete, Toast.LENGTH_SHORT).show() + } + PreferenceManager.getDefaultSharedPreferences(this).getInt("apiVersionMajor", 0) > 1 -> { + val tagList = tags.text.toString().split(",").map { it.trim() } + api.createSourceApi2( + title, + url, + mSpoutsValue!!, + tagList, + "" + ).enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null && response.body()!!.isSuccess) { + finish() + } else { + Toast.makeText( + this@AddSourceActivity, + R.string.cant_create_source, + Toast.LENGTH_SHORT + ).show() + } + } + + override fun onFailure(call: Call, t: Throwable) { Toast.makeText( this@AddSourceActivity, R.string.cant_create_source, Toast.LENGTH_SHORT ).show() } - } + }) + } + else -> { + api.createSource( + title, + url, + mSpoutsValue!!, + tags.text.toString(), + "" + ).enqueue(object : Callback { + override fun onResponse( + call: Call, + response: Response + ) { + if (response.body() != null && response.body()!!.isSuccess) { + finish() + } else { + Toast.makeText( + this@AddSourceActivity, + R.string.cant_create_source, + Toast.LENGTH_SHORT + ).show() + } + } - override fun onFailure(call: Call, t: Throwable) { - Toast.makeText( - this@AddSourceActivity, - R.string.cant_create_source, - Toast.LENGTH_SHORT - ).show() - } - }) + override fun onFailure(call: Call, t: Throwable) { + Toast.makeText( + this@AddSourceActivity, + R.string.cant_create_source, + Toast.LENGTH_SHORT + ).show() + } + }) + } } } } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt index 645cc0e..558e503 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossApi.kt @@ -231,4 +231,13 @@ class SelfossApi( filter: String ): Call = service.createSource(title, url, spout, tags, filter, userName, password) + + fun createSourceApi2( + title: String, + url: String, + spout: String, + tags: List, + filter: String + ): Call = + service.createSourceApi2(title, url, spout, tags, filter, userName, password) } diff --git a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt index 00274d4..60640db 100644 --- a/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt +++ b/app/src/main/java/apps/amine/bou/readerforselfoss/api/selfoss/SelfossService.kt @@ -126,4 +126,16 @@ internal interface SelfossService { @Query("username") username: String, @Query("password") password: String ): Call + + @FormUrlEncoded + @POST("source") + fun createSourceApi2( + @Field("title") title: String, + @Field("url") url: String, + @Field("spout") spout: String, + @Field("tags[]") tags: List, + @Field("filter") filter: String, + @Query("username") username: String, + @Query("password") password: String + ): Call }