-
Notifications
You must be signed in to change notification settings - Fork 761
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use clipboard hack to get deferred deeplink
- Loading branch information
NIkita Fedrunov
committed
Dec 23, 2022
1 parent
67edf66
commit 2dc103f
Showing
8 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...d/src/main/java/org/matrix/android/sdk/api/session/permalinks/DeferredPermalinkService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.api.session.permalinks | ||
|
||
/** | ||
* Service to handle deferred links, e.g. when user open link to the room but the app is not installed yet | ||
*/ | ||
interface DeferredPermalinkService { | ||
|
||
/** | ||
* Checks system clipboard for matrix.to links and returns first room link if any found | ||
* @return first room link in clipboard or null if none is found | ||
*/ | ||
fun getLinkFromClipBoard(): String? | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...ava/org/matrix/android/sdk/internal/session/permalinks/DefaultDeferredPermalinkService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright 2022 The Matrix.org Foundation C.I.C. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.matrix.android.sdk.internal.session.permalinks | ||
|
||
import android.content.ClipboardManager | ||
import android.content.Context | ||
import org.matrix.android.sdk.api.session.permalinks.DeferredPermalinkService | ||
import org.matrix.android.sdk.api.session.permalinks.PermalinkData | ||
import org.matrix.android.sdk.api.session.permalinks.PermalinkParser | ||
import androidx.core.content.getSystemService | ||
import javax.inject.Inject | ||
|
||
class DefaultDeferredPermalinkService @Inject constructor( | ||
private val context: Context | ||
) : DeferredPermalinkService { | ||
|
||
override fun getLinkFromClipBoard(): String? { | ||
val clipboard = context.getSystemService<ClipboardManager>() | ||
clipboard?.primaryClip?.let { clip -> | ||
if (clip.itemCount == 0) { | ||
return null | ||
} | ||
for (i in 0 until clip.itemCount) { | ||
val clipText = clip.getItemAt(i).text.toString() | ||
val data = PermalinkParser.parse(clipText) | ||
if (data is PermalinkData.RoomLink) { | ||
return clipText | ||
} | ||
} | ||
} | ||
return null | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters