Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 39b1265a authored by alperozturk's avatar alperozturk
Browse files

add update logic

parent 015f6b4c
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -4,6 +4,7 @@ import com.nextcloud.android.sso.api.EmptyResponse
import com.owncloud.android.lib.resources.shares.OCShare
import it.niedermann.owncloud.notes.share.model.CreateShareRequest
import it.niedermann.owncloud.notes.share.model.CreateShareResponse
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
import it.niedermann.owncloud.notes.shared.model.OcsResponse
import retrofit2.Call
import retrofit2.http.Body
@@ -38,7 +39,7 @@ interface ShareAPI {
    fun deleteShare(remoteShareId: Long): Call<EmptyResponse>

    @PATCH("shares")
    fun updateShare(remoteShareId: Long): Call<OcsResponse<List<OCShare>>>
    fun updateShare(@Body request: UpdateShareRequest): Call<OcsResponse<CreateShareResponse>>

    @POST("shares")
    fun addShare(@Body request: CreateShareRequest): Call<OcsResponse<CreateShareResponse>>
+12 −12
Original line number Diff line number Diff line
@@ -552,15 +552,15 @@ class NoteShareDetailActivity : BrandedActivity(),
                SingleAccountHelper.getCurrentSingleSignOnAccount(this@NoteShareDetailActivity)

            // if modifying existing share then directly update the note and send email
            if (share != null && share?.note != noteText) {
                // repository.updateShare(ssoAcc, share, noteText)
            val result = if (share != null && share?.note != noteText) {
                repository.updateShare(ssoAcc, share!!.id, noteText)
            } else {
                if (note == null || shareeName == null) {
                    Log_OC.d(TAG, "validateShareProcessSecond cancelled")
                    return@launch
                }

                val result = repository.addShare(
                repository.addShare(
                    ssoAcc,
                    note!!,
                    shareType,
@@ -570,6 +570,7 @@ class NoteShareDetailActivity : BrandedActivity(),
                    permission,
                    noteText
                )
            }

            withContext(Dispatchers.Main) {
                if (result) {
@@ -583,7 +584,6 @@ class NoteShareDetailActivity : BrandedActivity(),
            }
        }
    }
    }

    override fun onDateSet(year: Int, monthOfYear: Int, dayOfMonth: Int, chosenDateInMillis: Long) {
        binding.shareProcessSelectExpDate.text = getString(
+11 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.share.model

import com.google.gson.annotations.Expose

data class UpdateShareRequest(
    @Expose
    val shareId: String,

    @Expose
    val noteText: String
)
+18 −9
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ import it.niedermann.owncloud.notes.persistence.ApiProvider
import it.niedermann.owncloud.notes.persistence.NotesRepository
import it.niedermann.owncloud.notes.persistence.entity.Note
import it.niedermann.owncloud.notes.share.model.CreateShareRequest
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
import it.niedermann.owncloud.notes.shared.model.ApiVersion
import org.json.JSONArray
import org.json.JSONObject
@@ -153,14 +154,22 @@ class ShareRepository(private val applicationContext: Context) {

    fun updateShare(
        account: SingleSignOnAccount,
        remoteShareId: Long
    ): Single<List<OCShare>> {
        return Single.fromCallable {
        shareId: Long,
        noteText: String
    ): Boolean {
        val shareAPI = apiProvider.getShareAPI(applicationContext, account)
            val call = shareAPI.updateShare(remoteShareId)
        val requestBody = UpdateShareRequest(shareId.toString(), noteText)
        val call = shareAPI.updateShare(requestBody)
        val response = call.execute()
            response.body()?.ocs?.data ?: throw RuntimeException("Share update failed")
        }.subscribeOn(Schedulers.io())
        if (response.isSuccessful) {
            val updateShareResponse = response.body()
            Log.d("", "Response successful: $updateShareResponse")
        } else {
            val errorBody = response.errorBody()?.string()
            Log.d("", "Response failed:$errorBody")
        }

        return response.isSuccessful
    }

    fun addShare(
@@ -194,7 +203,7 @@ class ShareRepository(private val applicationContext: Context) {
        val response = call.execute()
        if (response.isSuccessful) {
            val createShareResponse = response.body()
            Log.d("", "Response successfull: $createShareResponse")
            Log.d("", "Response successful: $createShareResponse")
        } else {
            val errorBody = response.errorBody()?.string()
            Log.d("", "Response failed:$errorBody")