Skip to content
Snippets Groups Projects
Commit 6279f8d3 authored by John's avatar John
Browse files

Handle deeplink routing to project

parent 460605f8
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -56,10 +56,10 @@ class RoutingActivity : BaseActivity() {
overridePendingTransition(R.anim.fade_in, R.anim.do_nothing)
}
 
override fun onRouteUnknown(uri: Uri?) {
override fun onRouteUnknown(url: String?) {
Timber.d("Route unknown. Opening original Uri if it exists")
if (originalUri != null) {
IntentUtil.openPage(this@RoutingActivity, uri!!.toString(), App.get().currentAccount)
IntentUtil.openPage(this@RoutingActivity, url.toString(), App.get().currentAccount)
} else {
Toast.makeText(this@RoutingActivity, R.string.deeplink_navigate_error, Toast.LENGTH_SHORT)
.show()
Loading
Loading
@@ -89,8 +89,8 @@ class RoutingActivity : BaseActivity() {
}
//If it has an original uri, this means that it is an internal deep link and we
//can still fall back to what the original uri was and just show it
originalUri = intent.getParcelableExtra(DeepLinker.EXTRA_ORIGINAL_URI)
val link = intent.data
originalUri = intent.getParcelableExtra(DeepLinker.KEY_ORIGINAL_URL)
val link = intent.data.toString()
Timber.d("Received deep link %s", link)
Timber.d("Original link was %s", originalUri)
 
Loading
Loading
Loading
Loading
@@ -5,13 +5,14 @@ import android.content.Intent
import android.net.Uri
 
import com.commit451.gitlab.R
import okhttp3.HttpUrl
 
/**
* Generates deeplinks
*/
object DeepLinker {
 
const val EXTRA_ORIGINAL_URI = "original_uri"
const val KEY_ORIGINAL_URL = "original_url"
 
fun generateDeeplinkIntentFromUri(context: Context, originalUri: Uri): Intent {
val uri = originalUri.buildUpon()
Loading
Loading
@@ -20,34 +21,32 @@ object DeepLinker {
return generatePrivateIntent(context, uri, originalUri)
}
 
fun route(link: Uri?, navigator: Callbacks) {
if (link == null) {
fun route(url: String?, navigator: Callbacks) {
if (url == null) {
navigator.onRouteUnknown(null)
return
}
if (link.path == null) {
navigator.onRouteUnknown(link)
return
}
if (link.path.contains("issues")) {
if (link.lastPathSegment == "issues") {
val link = HttpUrl.parse(url)!!
val path = link.pathSegments().joinToString { "/" }
if (path.contains("issues")) {
if (link.pathSegments().last() == "issues") {
//this means it was just a link to something like
//gitlab.com/Commit451/LabCoat/issues
val index = link.pathSegments.indexOf("issues")
val index = link.pathSegments().indexOf("issues")
if (index != -1 && index > 1) {
val namespace = link.pathSegments[index - 2]
val name = link.pathSegments[index - 1]
val namespace = link.pathSegments()[index - 2]
val name = link.pathSegments()[index - 1]
//TODO make this tell what tab to open up when we get to projects
navigator.onRouteToProject(namespace, name)
return
}
} else {
val index = link.pathSegments.indexOf("issues")
val index = link.pathSegments().indexOf("issues")
//this is good, it means it is a link to an actual issue
if (index != -1 && index > 1 && link.pathSegments.size > index) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val lastSegment = link.pathSegments[index + 1]
if (index != -1 && index > 1 && link.pathSegments().size > index) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
val lastSegment = link.pathSegments()[index + 1]
//We have to do this cause there can be args on the url, such as
//https://gitlab.com/Commit451/LabCoat/issues/158#note_4560580
val stuff = lastSegment.split("#".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
Loading
Loading
@@ -56,71 +55,77 @@ object DeepLinker {
return
}
}
} else if (link.path.contains("commits")) {
} else if (path.contains("commits")) {
//Order matters here, parse commits first, then commit
val index = link.pathSegments.indexOf("commits")
val index = link.pathSegments().indexOf("commits")
if (index > 1) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
navigator.onRouteToProject(projectNamespace, projectName)
return
}
} else if (link.path.contains("commit")) {
val index = link.pathSegments.indexOf("commit")
if (index > 1 && index < link.pathSegments.size) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val commitSha = link.pathSegments[index + 1]
} else if (path.contains("commit")) {
val index = link.pathSegments().indexOf("commit")
if (index > 1 && index < link.pathSegments().size) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
val commitSha = link.pathSegments()[index + 1]
navigator.onRouteToCommit(projectNamespace, projectName, commitSha)
return
}
} else if (link.path.contains("compare")) {
val index = link.pathSegments.indexOf("compare")
if (index > 1 && index < link.pathSegments.size) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
} else if (path.contains("compare")) {
val index = link.pathSegments().indexOf("compare")
if (index > 1 && index < link.pathSegments().size) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
//comparing two commit shas
val shas = link.lastPathSegment.split("...".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val shas = link.pathSegments().last().split("...".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (shas.size == 2) {
//I believe we want to route to the second one. Should verify this
navigator.onRouteToCommit(projectNamespace, projectName, shas[1])
return
}
}
} else if (link.path.contains("merge_requests")) {
val index = link.pathSegments.indexOf("merge_requests")
if (index > 1 && index < link.pathSegments.size) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val mergeRequestId = link.pathSegments[index + 1]
} else if (path.contains("merge_requests")) {
val index = link.pathSegments().indexOf("merge_requests")
if (index > 1 && index < link.pathSegments().size) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
val mergeRequestId = link.pathSegments()[index + 1]
navigator.onRouteToMergeRequest(projectNamespace, projectName, mergeRequestId)
return
}
} else if (link.path.contains("builds")) {
val index = link.pathSegments.indexOf("builds")
if (index > 1 && index < link.pathSegments.size) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val buildId = link.pathSegments[index + 1]
} else if (path.contains("builds")) {
val index = link.pathSegments().indexOf("builds")
if (index > 1 && index < link.pathSegments().size) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
val buildId = link.pathSegments()[index + 1]
navigator.onRouteToBuild(projectNamespace, projectName, buildId)
return
}
} else if (link.path.contains("milestones")) {
val index = link.pathSegments.indexOf("milestones")
if (index > 1 && index < link.pathSegments.size) {
val projectNamespace = link.pathSegments[index - 2]
val projectName = link.pathSegments[index - 1]
val milestoneId = link.pathSegments[index + 1]
} else if (path.contains("milestones")) {
val index = link.pathSegments().indexOf("milestones")
if (index > 1 && index < link.pathSegments().size) {
val projectNamespace = link.pathSegments()[index - 2]
val projectName = link.pathSegments()[index - 1]
val milestoneId = link.pathSegments()[index + 1]
navigator.onRouteToMilestone(projectNamespace, projectName, milestoneId)
return
}
} else if (link.pathSegments().size == 2) {
//exactly two path segments, it is probably a link to a project
val projectNamespace = link.pathSegments()[0]
val projectName = link.pathSegments()[1]
navigator.onRouteToProject(projectNamespace, projectName)
return
}
navigator.onRouteUnknown(link)
navigator.onRouteUnknown(url)
}
 
private fun generatePrivateIntent(context: Context, uri: Uri, originalUri: Uri): Intent {
val intent = Intent(Intent.ACTION_VIEW, uri)
intent.putExtra(EXTRA_ORIGINAL_URI, originalUri)
intent.putExtra(KEY_ORIGINAL_URL, originalUri)
intent.`package` = context.packageName
return intent
}
Loading
Loading
@@ -135,6 +140,6 @@ object DeepLinker {
fun onRouteToProject(projectNamespace: String, projectName: String)
fun onRouteToBuild(projectNamespace: String, projectName: String, buildNumber: String)
fun onRouteToMilestone(projectNamespace: String, projectName: String, milestoneNumber: String)
fun onRouteUnknown(uri: Uri?)
fun onRouteUnknown(url: String?)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment