Support adding sources with api 2 (#353)
* Support adding sources with api 2 * Update changelog
This commit is contained in:
parent
2e38639910
commit
abba04839a
@ -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.
|
||||
|
@ -206,12 +206,47 @@ 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) {
|
||||
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<SuccessResponse> {
|
||||
override fun onResponse(
|
||||
call: Call<SuccessResponse>,
|
||||
response: Response<SuccessResponse>
|
||||
) {
|
||||
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<SuccessResponse>, t: Throwable) {
|
||||
Toast.makeText(
|
||||
this@AddSourceActivity,
|
||||
R.string.cant_create_source,
|
||||
Toast.LENGTH_SHORT
|
||||
).show()
|
||||
}
|
||||
})
|
||||
}
|
||||
else -> {
|
||||
api.createSource(
|
||||
title,
|
||||
url,
|
||||
@ -245,3 +280,4 @@ class AddSourceActivity : AppCompatActivity() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -231,4 +231,13 @@ class SelfossApi(
|
||||
filter: String
|
||||
): Call<SuccessResponse> =
|
||||
service.createSource(title, url, spout, tags, filter, userName, password)
|
||||
|
||||
fun createSourceApi2(
|
||||
title: String,
|
||||
url: String,
|
||||
spout: String,
|
||||
tags: List<String>,
|
||||
filter: String
|
||||
): Call<SuccessResponse> =
|
||||
service.createSourceApi2(title, url, spout, tags, filter, userName, password)
|
||||
}
|
||||
|
@ -126,4 +126,16 @@ internal interface SelfossService {
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("source")
|
||||
fun createSourceApi2(
|
||||
@Field("title") title: String,
|
||||
@Field("url") url: String,
|
||||
@Field("spout") spout: String,
|
||||
@Field("tags[]") tags: List<String>,
|
||||
@Field("filter") filter: String,
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<SuccessResponse>
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user