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

Unverified Commit 1f505d39 authored by alperozturk's avatar alperozturk
Browse files

add getShares

parent 9920b406
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.persistence.sync

import com.google.gson.internal.LinkedTreeMap
import com.nextcloud.android.sso.api.EmptyResponse
import com.owncloud.android.lib.common.operations.RemoteOperation
import com.owncloud.android.lib.resources.shares.OCShare
import it.niedermann.owncloud.notes.share.model.CreateShareRequest
import it.niedermann.owncloud.notes.share.model.CreateShareResponse
@@ -10,7 +11,6 @@ import it.niedermann.owncloud.notes.share.model.UpdateSharePermissionRequest
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
import it.niedermann.owncloud.notes.shared.model.OcsResponse
import retrofit2.Call
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
@@ -30,8 +30,18 @@ interface ShareAPI {
        @Query("lookup") lookup: String = "false",
    ): LinkedTreeMap<String, Any?>?

    @GET("shares")
    fun getShares(remoteId: Long): Call<OcsResponse<List<OCShare>>>
    @GET("shares/{remoteId}?format=json")
    fun getShares(
        @Path("remoteId") remoteId: Long,
        @Query("include_tags") includeTags: Boolean = true,
    ): Call<OcsResponse<List<CreateShareResponse>>>

    @GET("shares?format=json")
    fun getSharesForNote(
        @Query("path") path: String,
        @Query("reshares") reshares: Boolean,
        @Query("subfiles") subfiles: Boolean,
    ): RemoteOperation<List<OCShare>>

    @GET("shares")
    fun getSharesForFile(
+4 −1
Original line number Diff line number Diff line
@@ -113,8 +113,11 @@ public class NoteShareActivity extends BrandedActivity implements ShareeListAdap
                final var ssoAcc = SingleAccountHelper.getCurrentSingleSignOnAccount(NoteShareActivity.this);
                repository = new ShareRepository(NoteShareActivity.this, ssoAcc);

                // TODO: Used saved ids
                final var shares = repository.getShares(note);

                runOnUiThread(() -> {
                    binding.sharesList.setAdapter(new ShareeListAdapter(this, new ArrayList<>(), this, account));
                    binding.sharesList.setAdapter(new ShareeListAdapter(this, shares, this, account));
                    binding.sharesList.setLayoutManager(new LinearLayoutManager(this));
                    binding.pickContactEmailBtn.setOnClickListener(v -> checkContactPermission());
                    binding.btnShareButton.setOnClickListener(v -> ShareUtil.openShareDialog(this, note.getTitle(), note.getContent()));
+3 −0
Original line number Diff line number Diff line
@@ -119,4 +119,7 @@ data class CreateShareResponse(
    @Expose
    @SerializedName("hide_download")
    val hideDownload: Long,

    @Expose
    val attributes: Any?,
)
+36 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.share.model

import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareType

fun List<CreateShareResponse>.toOCShare(): List<OCShare> {
    return map { response ->
        OCShare().apply {
            id = response.id.toLongOrNull() ?: 0
            fileSource = response.fileSource
            itemSource = response.itemSource
            shareType = when (response.shareType) {
                0L -> ShareType.USER
                1L -> ShareType.GROUP
                3L -> ShareType.PUBLIC_LINK
                else -> null
            }
            shareWith = response.shareWith
            path = response.path
            permissions = response.permissions.toInt()
            sharedDate = response.stime
            token = null
            sharedWithDisplayName = response.shareWithDisplayname
            isFolder = response.itemType == "folder"
            userId = response.uidOwner
            shareLink = null
            isPasswordProtected = false
            note = response.note
            isHideFileDownload = response.hideDownload > 0
            label = response.label
            isHasPreview = response.hasPreview
            mimetype = response.mimetype
            ownerDisplayName = response.displaynameOwner
        }
    }
}
+39 −8
Original line number Diff line number Diff line
@@ -2,21 +2,26 @@ package it.niedermann.owncloud.notes.share.repository

import android.content.Context
import android.icu.text.SimpleDateFormat
import android.net.Uri
import com.google.gson.Gson
import com.google.gson.internal.LinkedTreeMap
import com.nextcloud.android.sso.model.SingleSignOnAccount
import com.owncloud.android.lib.common.utils.Log_OC
import com.owncloud.android.lib.resources.shares.OCShare
import com.owncloud.android.lib.resources.shares.ShareToRemoteOperationResultParser
import com.owncloud.android.lib.resources.shares.ShareType
import com.owncloud.android.lib.resources.shares.ShareXMLParser
import io.reactivex.Single
import io.reactivex.schedulers.Schedulers
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.CreateShareResponse
import it.niedermann.owncloud.notes.share.model.UpdateShareInformationRequest
import it.niedermann.owncloud.notes.share.model.UpdateSharePermissionRequest
import it.niedermann.owncloud.notes.share.model.UpdateShareRequest
import it.niedermann.owncloud.notes.share.model.toOCShare
import it.niedermann.owncloud.notes.shared.model.ApiVersion
import org.json.JSONObject
import java.util.Date
@@ -93,14 +98,40 @@ class ShareRepository(private val applicationContext: Context, private val accou
    }

    fun getShares(
        remoteId: Long
    ): Single<List<OCShare>> {
        return Single.fromCallable {
        note: Note
    ): List<OCShare>? {
        /*
         val notesPathCall = notesRepository.getServerSettings(account, ApiVersion.API_VERSION_1_0)
        val notesPathResponse = notesPathCall.execute()
        val notesPathResponseResult = notesPathResponse.body() ?: return null
        val notesPath = notesPathResponseResult.notesPath
        val notesSuffix = notesPathResponseResult.fileSuffix
        val remotePath =  "/" + notesPath + "/" + note.title + notesSuffix

        val shareAPI = apiProvider.getShareAPI(applicationContext, account)
            val call = shareAPI.getShares(remoteId)
        val call = shareAPI.getSharesForNote(remotePath, true, true)



        return  null

         */
        val shareAPI = apiProvider.getShareAPI(applicationContext, account)
        val call = shareAPI.getShares(12)
        val response = call.execute()
            response.body()?.ocs?.data ?: throw RuntimeException("No shares available")
        }.subscribeOn(Schedulers.io())

        return try {
            if (response.isSuccessful) {
                val result = response.body()?.ocs?.data ?: throw RuntimeException("No shares available")
                result.toOCShare()
            } else {
                Log_OC.d(tag, "Failed to getShares: ${response.errorBody()?.string()}")
                null
            }
        } catch (e: Exception) {
            Log_OC.d(tag, "Exception while getShares: $e")
            null
        }
    }

    fun getSharesForFile(