Skip to content
Snippets Groups Projects
Commit 792cc6c2 authored by John's avatar John
Browse files

Make account accessible

parent 93b8c503
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -4,7 +4,7 @@ buildscript {
}
 
dependencies {
classpath 'io.fabric.tools:gradle:1.25.2'
classpath 'io.fabric.tools:gradle:1.25.4'
}
}
 
Loading
Loading
@@ -116,7 +116,7 @@ dependencies {
implementation "com.android.support:cardview-v7:$supportLibVersion"
implementation "com.android.support:palette-v7:$supportLibVersion"
implementation "com.android.support:customtabs:$supportLibVersion"
implementation 'com.android.support:multidex:1.0.2'
implementation 'com.android.support:multidex:1.0.3'
 
implementation 'com.google.code.findbugs:jsr305:3.0.2'
 
Loading
Loading
@@ -139,11 +139,11 @@ dependencies {
implementation "com.jakewharton:butterknife:$butterknifeVersion"
kapt "com.jakewharton:butterknife-compiler:$butterknifeVersion"
implementation 'com.jakewharton.timber:timber:4.7.0'
implementation 'com.jakewharton.threetenabp:threetenabp:1.0.5'
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
 
implementation 'org.greenrobot:eventbus:3.1.1'
 
implementation 'io.reactivex.rxjava2:rxjava:2.1.12'
implementation 'io.reactivex.rxjava2:rxjava:2.1.13'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.2'
 
implementation "com.uber.autodispose:autodispose-kotlin:$autodisposeVersion"
Loading
Loading
@@ -197,7 +197,7 @@ dependencies {
 
implementation 'com.wdullaer:materialdatetimepicker:3.5.2'
 
implementation 'com.github.novoda:simple-chrome-custom-tabs:0.1.5'
implementation 'com.github.novoda:simple-chrome-custom-tabs:0.1.6'
 
implementation "com.afollestad.material-dialogs:core:$materialDialogsVersion"
implementation "com.afollestad.material-dialogs:commons:$materialDialogsVersion"
Loading
Loading
@@ -212,9 +212,7 @@ dependencies {
 
implementation 'com.atlassian.commonmark:commonmark:0.11.0'
 
normalImplementation('com.crashlytics.sdk.android:crashlytics:2.8.0@aar') {
transitive = true
}
normalImplementation 'com.crashlytics.sdk.android:crashlytics:2.9.2'
 
debugImplementation "com.squareup.leakcanary:leakcanary-android:$leakCanaryVersion"
releaseImplementation "com.squareup.leakcanary:leakcanary-android-no-op:$leakCanaryVersion"
Loading
Loading
@@ -225,7 +223,7 @@ dependencies {
exclude group: 'com.jakewharton.threetenabp', module: 'threetenabp'
}
 
androidTestImplementation('com.android.support.test:runner:1.0.1') {
androidTestImplementation('com.android.support.test:runner:1.0.2') {
exclude group: 'com.android.support', module: 'support-annotations'
}
}
package com.commit451.gitlab.activity
 
import android.support.v7.app.AppCompatActivity
import com.commit451.gitlab.App
import com.commit451.gitlab.api.GitLab
import com.commit451.gitlab.model.Account
import com.novoda.simplechromecustomtabs.SimpleChromeCustomTabs
import com.uber.autodispose.android.lifecycle.AndroidLifecycleScopeProvider
 
Loading
Loading
@@ -11,6 +14,12 @@ abstract class BaseActivity : AppCompatActivity() {
 
val scopeProvider by lazy { AndroidLifecycleScopeProvider.from(this) }
 
val account: Account
get() = App.get().gitLab.account
val gitLab: GitLab
get() = App.get().gitLab
open fun hasBrowsableLinks(): Boolean {
return false
}
Loading
Loading
Loading
Loading
@@ -85,8 +85,8 @@ class LoginActivity : BaseActivity() {
 
lateinit var teleprinter: Teleprinter
 
var account: Account = Account()
var gitLab: GitLab? = null
var currentAccount: Account = Account()
var currentGitLab: GitLab? = null
 
@OnClick(R.id.button_info)
fun onInfoClicked() {
Loading
Loading
@@ -139,8 +139,8 @@ class LoginActivity : BaseActivity() {
return
}
 
account = Account()
account.serverUrl = uri
currentAccount = Account()
currentAccount.serverUrl = uri
 
login()
}
Loading
Loading
@@ -194,30 +194,30 @@ class LoginActivity : BaseActivity() {
// This seems useless - But believe me, it makes everything work! Don't remove it.
// (OkHttpClientFactory caches the clients and needs a new account to recreate them)
val newAccount = Account()
newAccount.serverUrl = account.serverUrl
newAccount.trustedCertificate = account.trustedCertificate
newAccount.trustedHostname = account.trustedHostname
newAccount.authorizationHeader = account.authorizationHeader
account = newAccount
newAccount.serverUrl = currentAccount.serverUrl
newAccount.trustedCertificate = currentAccount.trustedCertificate
newAccount.trustedHostname = currentAccount.trustedHostname
newAccount.authorizationHeader = currentAccount.authorizationHeader
currentAccount = newAccount
 
progress.visibility = View.VISIBLE
progress.alpha = 0.0f
progress.animate().alpha(1.0f)
 
account.privateToken = textToken.text.toString()
val gitlabClientBuilder = OkHttpClientFactory.create(account, false)
currentAccount.privateToken = textToken.text.toString()
val gitlabClientBuilder = OkHttpClientFactory.create(currentAccount, false)
if (BuildConfig.DEBUG) {
gitlabClientBuilder.addInterceptor(HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
}
 
gitLab = GitLabFactory.createGitLab(account, gitlabClientBuilder)
currentGitLab = GitLabFactory.createGitLab(currentAccount, gitlabClientBuilder)
 
loadUser(gitlabClientBuilder)
}
 
fun loadUser(gitlabClientBuilder: OkHttpClient.Builder) {
 
val gitLabService = GitLabFactory.create(account, gitlabClientBuilder.build())
val gitLabService = GitLabFactory.create(currentAccount, gitlabClientBuilder.build())
gitLabService.getThisUser()
.with(this)
.subscribe(object : CustomResponseSingleObserver<User>() {
Loading
Loading
@@ -233,12 +233,12 @@ class LoginActivity : BaseActivity() {
 
override fun responseNonNullSuccess(userFull: User) {
progress.visibility = View.GONE
account.lastUsed = Date()
account.email = userFull.email
account.username = userFull.username
Prefs.addAccount(account)
App.get().setAccount(account)
App.bus().post(LoginEvent(account))
currentAccount.lastUsed = Date()
currentAccount.email = userFull.email
currentAccount.username = userFull.username
Prefs.addAccount(currentAccount)
App.get().setAccount(currentAccount)
App.bus().post(LoginEvent(currentAccount))
//This is mostly for if projects already exists, then we will reload the data
App.bus().post(ReloadDataEvent())
Navigator.navigateToStartingActivity(this@LoginActivity)
Loading
Loading
@@ -251,14 +251,14 @@ class LoginActivity : BaseActivity() {
progress.visibility = View.GONE
 
if (t is SSLHandshakeException && t.cause is X509CertificateException) {
account.trustedCertificate = null
currentAccount.trustedCertificate = null
val fingerprint = X509Util.getFingerPrint((t.cause as X509CertificateException).chain[0])
 
val dialog = AlertDialog.Builder(this)
.setTitle(R.string.certificate_title)
.setMessage(String.format(resources.getString(R.string.certificate_message), fingerprint))
.setPositiveButton(R.string.ok_button) { dialog, _ ->
account.trustedCertificate = fingerprint
currentAccount.trustedCertificate = fingerprint
login()
dialog.dismiss()
}
Loading
Loading
@@ -267,15 +267,15 @@ class LoginActivity : BaseActivity() {
 
dialog.findViewById<TextView>(android.R.id.message).movementMethod = LinkMovementMethod.getInstance()
} else if (t is SSLPeerUnverifiedException && t.message?.toLowerCase()!!.contains("hostname")) {
account.trustedHostname = null
val hostNameVerifier = gitLab?.client?.hostnameVerifier() as? CustomHostnameVerifier
currentAccount.trustedHostname = null
val hostNameVerifier = currentGitLab?.client?.hostnameVerifier() as? CustomHostnameVerifier
val finalHostname = hostNameVerifier?.lastFailedHostname
val dialog = AlertDialog.Builder(this)
.setTitle(R.string.hostname_title)
.setMessage(R.string.hostname_message)
.setPositiveButton(R.string.ok_button) { dialog, _ ->
if (finalHostname != null) {
account.trustedHostname = finalHostname
currentAccount.trustedHostname = finalHostname
login()
}
 
Loading
Loading
@@ -294,7 +294,7 @@ class LoginActivity : BaseActivity() {
progress.visibility = View.GONE
when (response.code()) {
401 -> {
account.authorizationHeader = null
currentAccount.authorizationHeader = null
 
val header = response.headers().get("WWW-Authenticate")
if (header != null) {
Loading
Loading
@@ -341,7 +341,7 @@ class LoginActivity : BaseActivity() {
 
val dialog = HttpLoginDialog(this, realm, object : HttpLoginDialog.LoginListener {
override fun onLogin(username: String, password: String) {
account.authorizationHeader = Credentials.basic(username, password)
currentAccount.authorizationHeader = Credentials.basic(username, password)
login()
}
 
Loading
Loading
Loading
Loading
@@ -80,8 +80,8 @@ interface GitLabService {
@GET("$API_VERSION/projects?membership=true&order_by=last_activity_at&archived=false")
fun getAllProjects(): Single<Response<List<Project>>>
 
@GET("$API_VERSION/projects?owned=true&order_by=last_activity_at&archived=false")
fun getMyProjects(): Single<Response<List<Project>>>
@GET("$API_VERSION/users/{userId}/projects?order_by=last_activity_at&archived=false")
fun getMyProjects(@Path("userId") userId: String): Single<Response<List<Project>>>
 
@GET("$API_VERSION/projects?starred=true")
fun getStarredProjects(): Single<Response<List<Project>>>
Loading
Loading
Loading
Loading
@@ -150,7 +150,7 @@ class ProjectsFragment : ButterKnifeFragment() {
}
MODE_MINE -> {
showLoading()
actuallyLoadIt(getGitLab().getMyProjects())
actuallyLoadIt(getGitLab().getMyProjects(baseActivty.account.username!!))
}
MODE_STARRED -> {
showLoading()
Loading
Loading
Loading
Loading
@@ -27,7 +27,7 @@ import java.util.*
class ProjectFeedWidgetConfigureActivity : BaseActivity() {
 
companion object {
val REQUEST_PROJECT = 1
private const val REQUEST_PROJECT = 1
}
 
@BindView(R.id.toolbar)
Loading
Loading
@@ -39,7 +39,7 @@ class ProjectFeedWidgetConfigureActivity : BaseActivity() {
 
lateinit var adapterAccounts: AccountsAdapter
 
var account: Account? = null
var widgetAccount: Account? = null
var appWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID
 
public override fun onCreate(icicle: Bundle?) {
Loading
Loading
@@ -65,8 +65,8 @@ class ProjectFeedWidgetConfigureActivity : BaseActivity() {
 
adapterAccounts = AccountsAdapter()
adapterAccounts.setOnItemClickListener { adapter, _, position ->
account = adapter.get(position)
moveAlongToChooseProject(account!!)
widgetAccount = adapter.get(position)
moveAlongToChooseProject(widgetAccount!!)
}
list.layoutManager = LinearLayoutManager(this)
list.adapter = adapterAccounts
Loading
Loading
@@ -80,7 +80,7 @@ class ProjectFeedWidgetConfigureActivity : BaseActivity() {
REQUEST_PROJECT -> {
if (resultCode == Activity.RESULT_OK) {
val project = data?.getParcelerParcelableExtra<Project>(ProjectFeedWidgetConfigureProjectActivity.EXTRA_PROJECT)!!
saveWidgetConfig(account!!, project)
saveWidgetConfig(widgetAccount!!, project)
}
}
}
Loading
Loading
@@ -89,8 +89,8 @@ class ProjectFeedWidgetConfigureActivity : BaseActivity() {
fun loadAccounts() {
val accounts = Prefs.getAccounts()
Timber.d("Got %s accounts", accounts.size)
Collections.sort(accounts)
Collections.reverse(accounts)
accounts.sort()
accounts.reverse()
if (accounts.isEmpty()) {
textMessage.visibility = View.VISIBLE
} else {
Loading
Loading
apply plugin: 'com.github.ben-manes.versions'
apply plugin: 'com.commit451.updatewrapper'
buildscript {
ext.kotlinVersion = '1.2.31'
ext.kotlinVersion = '1.2.41'
repositories {
jcenter()
maven { url "https://jitpack.io" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.1.1'
classpath 'com.android.tools.build:gradle:3.1.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath 'com.github.ben-manes:gradle-versions-plugin:0.17.0'
classpath 'com.github.Commit451:updatewrapper:1.2.0'
Loading
Loading
Loading
Loading
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip
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