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

Merge branch 'develop'

parents 6366db54 f0f31076
No related branches found
No related tags found
No related merge requests found
Pipeline #
Change Log Change Log
========== ==========
   
Version 2.4.9
----------------------------
- Crash fixes related to fetching accounts
Version 2.4.8 Version 2.4.8
---------------------------- ----------------------------
   
Loading
Loading
Loading
@@ -18,7 +18,7 @@ apply plugin: 'io.fabric'
Loading
@@ -18,7 +18,7 @@ apply plugin: 'io.fabric'
   
def versionMajor = 2 def versionMajor = 2
def versionMinor = 4 def versionMinor = 4
def versionPatch = 8 def versionPatch = 9
def versionBuild = 0 // bump for dogfood builds, public betas, etc. def versionBuild = 0 // bump for dogfood builds, public betas, etc.
   
android { android {
Loading
Loading
Loading
@@ -2,8 +2,6 @@ package com.commit451.gitlab
Loading
@@ -2,8 +2,6 @@ package com.commit451.gitlab
   
import android.app.Application import android.app.Application
import android.content.Context import android.content.Context
import android.content.res.Resources
import android.support.annotation.VisibleForTesting
import android.support.multidex.MultiDex import android.support.multidex.MultiDex
import com.commit451.gitlab.api.GitLab import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.api.GitLabFactory import com.commit451.gitlab.api.GitLabFactory
Loading
@@ -22,12 +20,11 @@ import okhttp3.OkHttpClient
Loading
@@ -22,12 +20,11 @@ import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor import okhttp3.logging.HttpLoggingInterceptor
import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.EventBus
import timber.log.Timber import timber.log.Timber
import java.util.*
   
/** /**
* App for one time init things and to house singletons * App for one time init things and to house singletons
*/ */
open class App : Application() { class App : Application() {
   
companion object { companion object {
   
Loading
@@ -64,8 +61,6 @@ open class App : Application() {
Loading
@@ -64,8 +61,6 @@ open class App : Application() {
setupThreeTen() setupThreeTen()
   
Prefs.init(this) Prefs.init(this)
//So that we don't get weird half translations
forceLocale(Locale.ENGLISH)
setupCrashReporting() setupCrashReporting()
   
if (BuildConfig.DEBUG) { if (BuildConfig.DEBUG) {
Loading
@@ -109,47 +104,27 @@ open class App : Application() {
Loading
@@ -109,47 +104,27 @@ open class App : Application() {
return currentAccount return currentAccount
} }
   
@VisibleForTesting fun setupMultidex() {
protected open fun setupMultidex() {
MultiDex.install(this) MultiDex.install(this)
} }
   
@VisibleForTesting fun setupCrashReporting() {
protected open fun setupCrashReporting() {
FabricUtil.init(this) FabricUtil.init(this)
} }
   
@VisibleForTesting fun setupLeakCanary() {
protected open fun setupLeakCanary() {
LeakCanary.install(this) LeakCanary.install(this)
} }
   
@VisibleForTesting fun setupThreeTen() {
protected open fun setupThreeTen() {
AndroidThreeTen.init(this) AndroidThreeTen.init(this)
} }
   
private fun forceLocale(locale: Locale) { fun initGitLab(account: Account, clientBuilder: OkHttpClient.Builder) {
try {
Locale.setDefault(locale)
val resources = arrayOf(Resources.getSystem(), baseContext.resources)
for (res in resources) {
val configuration = res.configuration
configuration.locale = locale
res.updateConfiguration(configuration, res.displayMetrics)
}
} catch (e: Exception) {
Timber.e(e)
}
}
private fun initGitLab(account: Account, clientBuilder: OkHttpClient.Builder) {
gitLab = GitLabFactory.createGitLab(account, clientBuilder) gitLab = GitLabFactory.createGitLab(account, clientBuilder)
} }
   
private fun initPicasso(client: OkHttpClient) { fun initPicasso(client: OkHttpClient) {
picasso = PicassoFactory.createPicasso(client) picasso = PicassoFactory.createPicasso(client)
} }
} }
Loading
@@ -105,8 +105,8 @@ class AddIssueActivity : MorphActivity() {
Loading
@@ -105,8 +105,8 @@ class AddIssueActivity : MorphActivity() {
AlertDialog.Builder(this@AddIssueActivity) AlertDialog.Builder(this@AddIssueActivity)
.setTitle(R.string.remove) .setTitle(R.string.remove)
.setMessage(R.string.are_you_sure_you_want_to_remove) .setMessage(R.string.are_you_sure_you_want_to_remove)
.setPositiveButton(android.R.string.yes) { _, _ -> adapterLabels.removeLabel(label) } .setPositiveButton(R.string.yes) { _, _ -> adapterLabels.removeLabel(label) }
.setNegativeButton(android.R.string.no) { dialog, _ -> dialog.dismiss() } .setNegativeButton(R.string.no) { dialog, _ -> dialog.dismiss() }
.show() .show()
} }
}) })
Loading
@@ -273,8 +273,8 @@ class AddIssueActivity : MorphActivity() {
Loading
@@ -273,8 +273,8 @@ class AddIssueActivity : MorphActivity() {
AlertDialog.Builder(this) AlertDialog.Builder(this)
.setTitle(R.string.discard) .setTitle(R.string.discard)
.setMessage(R.string.are_you_sure_you_want_to_discard) .setMessage(R.string.are_you_sure_you_want_to_discard)
.setPositiveButton(android.R.string.yes) { _, _ -> dismiss() } .setPositiveButton(R.string.yes) { _, _ -> dismiss() }
.setNegativeButton(android.R.string.no) { dialog, _ -> dialog.dismiss() } .setNegativeButton(R.string.no) { dialog, _ -> dialog.dismiss() }
.show() .show()
} }
   
Loading
Loading
Loading
@@ -145,7 +145,11 @@ class IssueActivity : BaseActivity() {
Loading
@@ -145,7 +145,11 @@ class IssueActivity : BaseActivity() {
   
@OnClick(R.id.fab_edit_issue) @OnClick(R.id.fab_edit_issue)
fun onEditIssueClick(fab: View) { fun onEditIssueClick(fab: View) {
Navigator.navigateToEditIssue(this@IssueActivity, fab, project!!, issue!!) val project = project
val issue = issue
if (project != null && issue != null) {
Navigator.navigateToEditIssue(this@IssueActivity, fab, project, issue)
}
} }
   
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
Loading
Loading
Loading
@@ -291,7 +291,7 @@ interface GitLabService {
Loading
@@ -291,7 +291,7 @@ interface GitLabService {
   
@GET(API_VERSION + "/projects/{id}/repository/tree") @GET(API_VERSION + "/projects/{id}/repository/tree")
fun getTree(@Path("id") projectId: Long, fun getTree(@Path("id") projectId: Long,
@Query("ref_name") branchName: String, @Query("ref_name") branchName: String?,
@Query("path") path: String?): Single<List<RepositoryTreeObject>> @Query("path") path: String?): Single<List<RepositoryTreeObject>>
   
@GET(API_VERSION + "/projects/{id}/repository/files/{file_path}") @GET(API_VERSION + "/projects/{id}/repository/files/{file_path}")
Loading
Loading
Loading
@@ -13,7 +13,7 @@ import com.squareup.moshi.Moshi
Loading
@@ -13,7 +13,7 @@ import com.squareup.moshi.Moshi
import com.squareup.moshi.JsonAdapter import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Types.newParameterizedType import com.squareup.moshi.Types.newParameterizedType
import com.squareup.moshi.Types import com.squareup.moshi.Types
import timber.log.Timber
   
   
/** /**
Loading
@@ -46,15 +46,18 @@ object Prefs {
Loading
@@ -46,15 +46,18 @@ object Prefs {
fun getAccounts(): MutableList<Account> { fun getAccounts(): MutableList<Account> {
val accountsJson = prefs.getString(KEY_ACCOUNTS, null) val accountsJson = prefs.getString(KEY_ACCOUNTS, null)
if (!accountsJson.isNullOrEmpty()) { if (!accountsJson.isNullOrEmpty()) {
val type = Types.newParameterizedType(List::class.java, Account::class.java) try {
val adapter = MoshiProvider.moshi.adapter<List<Account>>(type) val type = Types.newParameterizedType(List::class.java, Account::class.java)
val accounts = adapter.fromJson(accountsJson)!!.toMutableList() val adapter = MoshiProvider.moshi.adapter<List<Account>>(type)
Collections.sort(accounts) val accounts = adapter.fromJson(accountsJson)!!.toMutableList()
Collections.reverse(accounts) Collections.sort(accounts)
return accounts Collections.reverse(accounts)
} else { return accounts
return ArrayList() } catch (e: Exception) {
Timber.e(e)
}
} }
return mutableListOf()
} }
   
fun setAccounts(accounts: List<Account>) { fun setAccounts(accounts: List<Account>) {
Loading
Loading
Loading
@@ -17,15 +17,11 @@ import com.commit451.gitlab.event.ProjectReloadEvent
Loading
@@ -17,15 +17,11 @@ import com.commit451.gitlab.event.ProjectReloadEvent
import com.commit451.gitlab.extension.* import com.commit451.gitlab.extension.*
import com.commit451.gitlab.model.api.Project import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.model.api.RepositoryFile import com.commit451.gitlab.model.api.RepositoryFile
import com.commit451.gitlab.model.api.RepositoryTreeObject
import com.commit451.gitlab.navigation.Navigator import com.commit451.gitlab.navigation.Navigator
import com.commit451.gitlab.rx.CustomSingleObserver import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.util.InternalLinkMovementMethod import com.commit451.gitlab.util.InternalLinkMovementMethod
import com.commit451.reptar.Optional
import com.trello.rxlifecycle2.android.FragmentEvent import com.trello.rxlifecycle2.android.FragmentEvent
import io.reactivex.Single import io.reactivex.Single
import io.reactivex.SingleSource
import io.reactivex.functions.Function
import org.greenrobot.eventbus.Subscribe import org.greenrobot.eventbus.Subscribe
import retrofit2.Response import retrofit2.Response
import timber.log.Timber import timber.log.Timber
Loading
@@ -76,8 +72,8 @@ class ProjectFragment : ButterKnifeFragment() {
Loading
@@ -76,8 +72,8 @@ class ProjectFragment : ButterKnifeFragment() {
AlertDialog.Builder(activity) AlertDialog.Builder(activity)
.setTitle(R.string.project_fork_title) .setTitle(R.string.project_fork_title)
.setMessage(R.string.project_fork_message) .setMessage(R.string.project_fork_message)
.setNegativeButton(android.R.string.cancel, null) .setNegativeButton(R.string.cancel, null)
.setPositiveButton(android.R.string.ok) { _, _ -> .setPositiveButton(R.string.ok) { _, _ ->
App.get().gitLab.forkProject(it.id) App.get().gitLab.forkProject(it.id)
.setup(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) .setup(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(object : CustomSingleObserver<String>() { .subscribe(object : CustomSingleObserver<String>() {
Loading
@@ -156,70 +152,59 @@ class ProjectFragment : ButterKnifeFragment() {
Loading
@@ -156,70 +152,59 @@ class ProjectFragment : ButterKnifeFragment() {
} }
   
override fun loadData() { override fun loadData() {
if (view == null) { val project = project
return val branchName = branchName
} if (view != null && project != null && branchName != null) {
swipeRefreshLayout.isRefreshing = true
if (project == null || branchName.isNullOrEmpty()) { Single.defer {
swipeRefreshLayout.isRefreshing = false
return val readmeResult = ReadmeResult()
} val rootItems = App.get().gitLab.getTree(project.id, branchName, null)
.blockingGet()
swipeRefreshLayout.isRefreshing = true for (treeItem in rootItems) {
val treeItemName = treeItem.name
val result = ReadmeResult() if (treeItemName != null && getReadmeType(treeItemName) != README_TYPE_UNKNOWN) {
App.get().gitLab.getTree(project!!.id, branchName!!, null) //found a README
.flatMap(Function<List<RepositoryTreeObject>, SingleSource<Optional<RepositoryTreeObject>>> { repositoryTreeObjects -> val repositoryFile = App.get().gitLab.getFile(project.id, treeItemName, branchName)
for (treeItem in repositoryTreeObjects) {
if (getReadmeType(treeItem.name!!) != README_TYPE_UNKNOWN) {
return@Function Single.just(Optional(treeItem))
}
}
Single.just(Optional.empty())
})
.flatMap(Function<Optional<RepositoryTreeObject>, SingleSource<Optional<RepositoryFile>>> { repositoryTreeObjectResult ->
if (repositoryTreeObjectResult.isPresent) {
val repositoryFile = App.get().gitLab.getFile(project!!.id, repositoryTreeObjectResult.get().name!!, branchName!!)
.blockingGet() .blockingGet()
result.repositoryFile = repositoryFile readmeResult.repositoryFile = repositoryFile
return@Function Single.just(Optional(repositoryFile)) readmeResult.bytes = repositoryFile.content.base64Decode()
}
Single.just(Optional.empty<RepositoryFile>())
})
.flatMap(Function<Optional<RepositoryFile>, SingleSource<ReadmeResult>> { repositoryFileResult ->
if (repositoryFileResult.isPresent) {
result.bytes = repositoryFileResult.get().content.base64Decode()
.blockingGet() .blockingGet()
return@Function Single.just(result) break
} }
Single.just(result) }
}) Single.just(readmeResult)
.setup(bindUntilEvent(FragmentEvent.DESTROY_VIEW)) }
.subscribe(object : CustomSingleObserver<ReadmeResult>() { .setup(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(object : CustomSingleObserver<ReadmeResult>() {
   
override fun error(t: Throwable) { override fun error(t: Throwable) {
Timber.e(t) Timber.e(t)
swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false
textOverview.setText(R.string.connection_error_readme) textOverview.setText(R.string.connection_error_readme)
} }
   
override fun success(readmeResult: ReadmeResult) { override fun success(result: ReadmeResult) {
swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false
if (result.repositoryFile != null && result.bytes != null) { val repositoryFile = result.repositoryFile
val text = String(result.bytes!!) val bytes = result.bytes
when (getReadmeType(result.repositoryFile!!.fileName!!)) { if (repositoryFile != null && bytes != null) {
README_TYPE_MARKDOWN -> { val text = String(bytes)
textOverview.setMarkdownText(text, project) when (getReadmeType(repositoryFile.fileName!!)) {
README_TYPE_MARKDOWN -> textOverview.setMarkdownText(text, project)
README_TYPE_HTML -> textOverview.text = text.formatAsHtml()
README_TYPE_TEXT -> textOverview.text = text
README_TYPE_NO_EXTENSION -> textOverview.text = text
} }
README_TYPE_HTML -> textOverview.text = text.formatAsHtml() } else {
README_TYPE_TEXT -> textOverview.text = text textOverview.setText(R.string.no_readme_found)
README_TYPE_NO_EXTENSION -> textOverview.text = text
} }
} else {
textOverview.setText(R.string.no_readme_found)
} }
} })
})
} else {
swipeRefreshLayout.isRefreshing = false
}
} }
   
fun bindProject(project: Project?) { fun bindProject(project: Project?) {
Loading
Loading
Loading
@@ -5,6 +5,10 @@
Loading
@@ -5,6 +5,10 @@
<string name="app_name">LabCoat</string> <string name="app_name">LabCoat</string>
<string name="unknown">Unknown</string> <string name="unknown">Unknown</string>
<string name="or">or</string> <string name="or">or</string>
<string name="ok">OK</string>
<string name="cancel">Cancel</string>
<string name="yes">Yes</string>
<string name="no">No</string>
   
<!-- Drawer --> <!-- Drawer -->
<string name="nav_projects">Projects</string> <string name="nav_projects">Projects</string>
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