Skip to content
Snippets Groups Projects
Commit a0500564 authored by John Carlson's avatar John Carlson
Browse files

Prevent crash on swiping to the files fragment quickly on a project

parent 35d519b2
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -2,6 +2,7 @@ package com.commit451.gitlab.fragment
 
import android.net.Uri
import android.os.Bundle
import android.support.design.widget.Snackbar
import android.support.v4.widget.SwipeRefreshLayout
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
Loading
Loading
@@ -64,7 +65,12 @@ class FeedFragment : ButterKnifeFragment() {
 
adapterFeed = FeedAdapter(object : FeedAdapter.Listener {
override fun onFeedEntryClicked(entry: Entry) {
Navigator.navigateToUrl(activity, entry.link.href, App.get().getAccount())
if (entry.link.href.isEmpty()) {
Snackbar.make(swipeRefreshLayout, R.string.not_a_valid_url, Snackbar.LENGTH_SHORT)
.show()
} else {
Navigator.navigateToUrl(activity, entry.link.href, App.get().getAccount())
}
}
})
listEntries.layoutManager = LinearLayoutManager(activity)
Loading
Loading
Loading
Loading
@@ -52,7 +52,7 @@ class FilesFragment : ButterKnifeFragment() {
lateinit var adapterBreadcrumb: BreadcrumbAdapter
 
var project: Project? = null
lateinit var ref: String
var ref: String? = null
var currentPath = ""
 
val filesAdapterListener = object : FileAdapter.Listener {
Loading
Loading
@@ -62,30 +62,30 @@ class FilesFragment : ButterKnifeFragment() {
 
override fun onFileClicked(treeItem: RepositoryTreeObject) {
val path = currentPath + treeItem.name
Navigator.navigateToFile(activity, project!!.id, path, ref)
Navigator.navigateToFile(activity, project!!.id, path, ref!!)
}
 
override fun onCopyClicked(treeItem: RepositoryTreeObject) {
val clipboard = activity.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
 
// Creates a new text clip to put on the clipboard
val clip = ClipData.newPlainText(treeItem.name, treeItem.getUrl(project!!, ref, currentPath).toString())
val clip = ClipData.newPlainText(treeItem.name, treeItem.getUrl(project!!, ref!!, currentPath).toString())
clipboard.primaryClip = clip
Snackbar.make(root, R.string.copied_to_clipboard, Snackbar.LENGTH_SHORT)
.show()
}
 
override fun onShareClicked(treeItem: RepositoryTreeObject) {
IntentUtil.share(view!!, treeItem.getUrl(project!!, ref, currentPath))
IntentUtil.share(view!!, treeItem.getUrl(project!!, ref!!, currentPath))
}
 
override fun onOpenInBrowserClicked(treeItem: RepositoryTreeObject) {
IntentUtil.openPage(activity as BaseActivity, treeItem.getUrl(project!!, ref, currentPath).toString(), App.get().currentAccount)
IntentUtil.openPage(activity as BaseActivity, treeItem.getUrl(project!!, ref!!, currentPath).toString(), App.get().currentAccount)
}
}
 
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater!!.inflate(R.layout.fragment_files, container, false)
return inflater?.inflate(R.layout.fragment_files, container, false)
}
 
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
Loading
Loading
@@ -104,7 +104,7 @@ class FilesFragment : ButterKnifeFragment() {
 
if (activity is ProjectActivity) {
project = (activity as ProjectActivity).project
ref = (activity as ProjectActivity).getRefRef()!!
ref = (activity as ProjectActivity).getRefRef()
loadData("")
} else {
throw IllegalStateException("Incorrect parent activity")
Loading
Loading
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