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