Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/debug/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
<resources>
<string name="app_name">LabCoat Debug</string>
<string name="leak_canary_display_activity_label">LabCoat Leaks</string>
<string name="file_provider_authority">com.commit451.gitlab.files.debug</string>
</resources>
14 changes: 14 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,20 @@
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />

<provider
android:name=".providers.FileProvider"
android:authorities="@string/file_provider_authority"
android:grantUriPermissions="true"
android:exported="true"
android:enabled="@bool/has_file_provider"
android:permission="android.permission.MANAGE_DOCUMENTS">

<intent-filter>
<action android:name="android.content.action.DOCUMENTS_PROVIDER" />
</intent-filter>

</provider>

</application>

</manifest>
4 changes: 4 additions & 0 deletions app/src/main/java/com/commit451/gitlab/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class App : Application() {
companion object {

var bus: EventBus = EventBus.getDefault()
var authenticated : Boolean = false

private lateinit var instance: App

fun bus(): EventBus {
Expand Down Expand Up @@ -74,7 +76,9 @@ class App : Application() {
setAccount(accounts[0])
}

authenticated = false
Lift.track(this)

}

override fun attachBaseContext(base: Context) {
Expand Down
22 changes: 5 additions & 17 deletions app/src/main/java/com/commit451/gitlab/activity/FileActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -252,27 +252,15 @@ class FileActivity : BaseActivity() {
fun openFile() {

if (blob != null && fileName != null) {
val intent = Intent(Intent.ACTION_VIEW)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK

val file = FileUtil.saveBlobToProviderDirectory(this, blob!!, fileName!!)
val extension = fileExtension(fileName!!)
if (extension.isNotEmpty()) {
intent.type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension)
if(!FileUtil.openFile(this, fileName!!, blob!!)){
Snackbar.make(root, getString(R.string.open_error), Snackbar.LENGTH_SHORT).show()
}
intent.flags = Intent.FLAG_GRANT_READ_URI_PERMISSION
intent.data = FileUtil.uriForFile(this, file)

try {
startActivity(intent)
} catch (e: Exception) {
Timber.e(e)
Snackbar.make(root, getString(R.string.open_error), Snackbar.LENGTH_SHORT)
.show()
}
} else {
Snackbar.make(root, getString(R.string.open_error), Snackbar.LENGTH_SHORT)
.show()
Snackbar.make(root, getString(R.string.open_error), Snackbar.LENGTH_SHORT).show()
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import android.view.ViewGroup
import android.widget.Toast
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.data.Prefs
import com.commit451.gitlab.extension.with
Expand Down Expand Up @@ -41,7 +42,10 @@ class LaunchActivity : BaseActivity() {
super.onActivityResult(requestCode, resultCode, data)
when (requestCode) {
REQUEST_DEVICE_AUTH -> if (resultCode == Activity.RESULT_OK) {

App.authenticated = true
moveAlong()

} else {
finish()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.app.AlertDialog
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.provider.DocumentsContract
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.textfield.TextInputLayout
import androidx.appcompat.widget.Toolbar
Expand Down Expand Up @@ -33,6 +35,7 @@ import com.commit451.gitlab.model.Account
import com.commit451.gitlab.model.api.Message
import com.commit451.gitlab.model.api.User
import com.commit451.gitlab.navigation.Navigator
import com.commit451.gitlab.providers.FileProvider
import com.commit451.gitlab.rx.CustomResponseSingleObserver
import com.commit451.gitlab.ssl.CustomHostnameVerifier
import com.commit451.gitlab.ssl.X509CertificateException
Expand Down Expand Up @@ -237,6 +240,11 @@ class LoginActivity : BaseActivity() {
currentAccount.email = userFull.email
currentAccount.username = userFull.username
Prefs.addAccount(currentAccount)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
contentResolver.notifyChange(DocumentsContract.buildRootsUri(FileProvider.getAuthority()), null)
}

App.get().setAccount(currentAccount)
App.bus().post(LoginEvent(currentAccount))
//This is mostly for if projects already exists, then we will reload the data
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/com/commit451/gitlab/adapter/FileAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class FileAdapter(private val listener: FileAdapter.Listener) : androidx.recycle
val treeItem = getValueAt(position)
holder.bind(treeItem)
holder.itemView.setTag(R.id.list_position, position)
holder.popupMenu.menu.findItem(R.id.action_open_external).setVisible(treeItem.type == RepositoryTreeObject.TYPE_FILE)
holder.popupMenu.setOnMenuItemClickListener(PopupMenu.OnMenuItemClickListener { item ->
when (item.itemId) {
R.id.action_copy -> {
Expand All @@ -48,6 +49,10 @@ class FileAdapter(private val listener: FileAdapter.Listener) : androidx.recycle
listener.onOpenInBrowserClicked(treeItem)
return@OnMenuItemClickListener true
}
R.id.action_open_external -> {
listener.onOpenExternalClicked(treeItem)
return@OnMenuItemClickListener true
}
}
false
})
Expand Down Expand Up @@ -80,5 +85,6 @@ class FileAdapter(private val listener: FileAdapter.Listener) : androidx.recycle
fun onCopyClicked(treeItem: RepositoryTreeObject)
fun onShareClicked(treeItem: RepositoryTreeObject)
fun onOpenInBrowserClicked(treeItem: RepositoryTreeObject)
fun onOpenExternalClicked(treeItem: RepositoryTreeObject)
}
}
5 changes: 5 additions & 0 deletions app/src/main/java/com/commit451/gitlab/api/GitLabService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,11 @@ interface GitLabService {
@Path("file_path") path: String,
@Query("ref") ref: String): Single<RepositoryFile>

@HEAD("projects/{id}/repository/files/{file_path}")
fun getFileHead(@Path("id") projectId: Long,
@Path("file_path") path: String,
@Query("ref") ref: String): Single<Response<Void>>

@GET("projects/{id}/repository/commits")
fun getCommits(@Path("id") projectId: Long,
@Query("ref_name") branchName: String,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package com.commit451.gitlab.api

import android.content.Intent
import android.os.Build
import android.provider.DocumentsContract
import android.widget.Toast
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.activity.LoginActivity
import com.commit451.gitlab.data.Prefs
import com.commit451.gitlab.model.Account
import com.commit451.gitlab.providers.FileProvider
import com.commit451.gitlab.util.ThreadUtil
import okhttp3.Authenticator
import okhttp3.Request
Expand Down Expand Up @@ -40,6 +43,11 @@ class OpenSignInAuthenticator(private val account: Account) : Authenticator {
ThreadUtil.postOnMainThread(Runnable {
//Remove the account, so that the user can sign in again
Prefs.removeAccount(account)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
App.get().applicationContext.contentResolver.notifyChange(DocumentsContract.buildRootsUri(FileProvider.getAuthority()), null)
}

Toast.makeText(App.get(), R.string.error_401, Toast.LENGTH_LONG)
.show()
val intent = LoginActivity.newIntent(App.get())
Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/com/commit451/gitlab/fragment/FilesFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.commit451.gitlab.fragment

import android.app.ProgressDialog
import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
Expand Down Expand Up @@ -27,6 +28,7 @@ import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.model.api.RepositoryTreeObject
import com.commit451.gitlab.navigation.Navigator
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.util.FileUtil
import com.commit451.gitlab.util.IntentUtil
import org.greenrobot.eventbus.Subscribe
import timber.log.Timber
Expand All @@ -53,6 +55,8 @@ class FilesFragment : ButterKnifeFragment() {
lateinit var listBreadcrumbs: androidx.recyclerview.widget.RecyclerView
@BindView(R.id.message_text)
lateinit var textMessage: TextView
@BindView(R.id.progress)
lateinit var progress: View

lateinit var adapterFiles: FileAdapter
lateinit var adapterBreadcrumb: BreadcrumbAdapter
Expand All @@ -62,6 +66,25 @@ class FilesFragment : ButterKnifeFragment() {
var currentPath = ""

val filesAdapterListener = object : FileAdapter.Listener {

override fun onOpenExternalClicked(treeItem: RepositoryTreeObject) {

progress.visibility = View.VISIBLE

val path = currentPath + treeItem.name
FileUtil.open(context!!, project!!.id, path, ref!!)
.observe(this@FilesFragment, androidx.lifecycle.Observer { success ->

progress.visibility = View.GONE

if(!success){
Snackbar.make(root, getString(R.string.error_opening_file), Snackbar.LENGTH_SHORT).show()
}

})

}

override fun onFolderClicked(treeItem: RepositoryTreeObject) {
loadData(currentPath + treeItem.name + "/")
}
Expand Down
Loading