Skip to content
Snippets Groups Projects
Commit 9612f4c8 authored by Jawnnypoo's avatar Jawnnypoo
Browse files

GitLab delegation of API and RSS

parent 2c66a686
No related branches found
No related tags found
No related merge requests found
Showing
with 64 additions and 49 deletions
Loading
Loading
@@ -75,7 +75,7 @@ android {
ext {
supportLibVersion = '25.3.1'
retrofitVersion = '2.2.0'
okHttpVersion = '3.6.0'
okHttpVersion = '3.7.0'
butterknifeVersion = '8.5.1'
loganSquareVersion = '1.3.7'
parcelerVersion = '1.1.6'
Loading
Loading
@@ -175,7 +175,7 @@ dependencies {
 
compile 'com.wdullaer:materialdatetimepicker:3.1.3'
 
compile 'com.github.novoda:simple-chrome-custom-tabs:0.1.4'
compile 'com.github.novoda:simple-chrome-custom-tabs:0.1.5'
 
compile "com.afollestad.material-dialogs:core:$materialDialogsVersion"
compile "com.afollestad.material-dialogs:commons:$materialDialogsVersion"
Loading
Loading
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.commit451.gitlab"
xmlns:android="http://schemas.android.com/apk/res/android">
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.commit451.gitlab">
 
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
Loading
Loading
@@ -105,6 +105,9 @@
android:label="@string/title_activity_fullscreen_image"
android:theme="@style/FullscreenTheme">
</activity>
<activity android:name=".activity.DebugActivity"/>
<receiver
android:name=".widget.UserFeedWidgetProvider"
android:label="User Feed">
Loading
Loading
@@ -131,7 +134,7 @@
<service
android:name=".widget.ProjectFeedWidgetService"
android:exported="false"
android:permission="android.permission.BIND_REMOTEVIEWS" />
android:permission="android.permission.BIND_REMOTEVIEWS"/>
 
</application>
 
Loading
Loading
Loading
Loading
@@ -39,9 +39,8 @@ open class App : Application() {
}
}
 
lateinit var gitLab: GitLab
lateinit var currentAccount: Account
lateinit var gitLab: GitLabService
lateinit var gitLabRss: GitLabRss
lateinit var picasso: Picasso
 
override fun onCreate() {
Loading
Loading
@@ -92,7 +91,6 @@ open class App : Application() {
}
val client = clientBuilder.build()
initGitLab(account, client)
initGitLabRss(account, client)
if (BuildConfig.DEBUG) {
initPicasso(OkHttpClientFactory.create(account).build())
} else {
Loading
Loading
@@ -136,11 +134,9 @@ open class App : Application() {
}
 
private fun initGitLab(account: Account, client: OkHttpClient) {
gitLab = GitLabFactory.create(account, client)
}
private fun initGitLabRss(account: Account, client: OkHttpClient) {
gitLabRss = GitLabRssFactory.create(account, client)
val gitLabService = GitLabFactory.create(account, client)
val gitLabRss = GitLabRssFactory.create(account, client)
gitLab = GitLab(gitLabService, gitLabRss)
}
 
private fun initPicasso(client: OkHttpClient) {
Loading
Loading
Loading
Loading
@@ -15,10 +15,10 @@ import butterknife.OnClick
import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.extension.setup
import com.commit451.gitlab.extension.toPart
import com.commit451.gitlab.model.api.FileUploadResponse
import com.commit451.gitlab.model.api.Project
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.rx.FileObservableFactory
import io.codetail.animation.ViewAnimationUtils
import org.parceler.Parcels
import pl.aprilapps.easyphotopicker.DefaultCallback
Loading
Loading
@@ -120,7 +120,7 @@ class AttachActivity : BaseActivity() {
fun onPhotoReturned(photo: File) {
progress.visibility = View.VISIBLE
rootButtons.visibility = View.INVISIBLE
FileObservableFactory.toPart(photo)
photo.toPart()
.flatMap { part -> App.get().gitLab.uploadFile(project!!.id, part) }
.setup(bindToLifecycle())
.subscribe(object : CustomSingleObserver<FileUploadResponse>() {
Loading
Loading
package com.commit451.gitlab.activity
 
import android.Manifest
import android.annotation.SuppressLint
import android.annotation.TargetApi
import android.content.ActivityNotFoundException
import android.content.Context
Loading
Loading
@@ -23,7 +24,6 @@ import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.model.api.RepositoryFile
import com.commit451.gitlab.rx.CustomSingleObserver
import com.commit451.gitlab.rx.DecodeObservableFactory
 
import java.io.File
import java.io.FileOutputStream
Loading
Loading
@@ -32,6 +32,7 @@ import java.nio.charset.Charset
 
import butterknife.BindView
import butterknife.ButterKnife
import com.commit451.gitlab.extension.base64Decode
import com.commit451.gitlab.extension.setup
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
Loading
Loading
@@ -150,7 +151,7 @@ class FileActivity : BaseActivity() {
}
 
private fun loadBlob(repositoryFile: RepositoryFile) {
DecodeObservableFactory.newDecode(repositoryFile.content)
repositoryFile.content.base64Decode()
.setup(bindToLifecycle())
.subscribe(object : CustomSingleObserver<ByteArray>() {
 
Loading
Loading
@@ -208,7 +209,7 @@ class FileActivity : BaseActivity() {
toolbar.inflateMenu(R.menu.menu_file)
}
 
@TargetApi(23)
@SuppressLint("NewApi")
private fun checkAccountPermission() {
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
if (option == OPTION_SAVE) {
Loading
Loading
Loading
Loading
@@ -50,7 +50,7 @@ class FullscreenImageActivity : BaseActivity() {
 
var imageUrl: String = intent.getStringExtra(IMAGE_URL)
if (imageUrl.startsWith("/")) {
imageUrl = App.get().getAccount().serverUrl.toString() + project?.pathWithNamespace + imageUrl
imageUrl = App.get().getAccount().serverUrl.toString() + project.pathWithNamespace + imageUrl
}
App.get().picasso.load(imageUrl).into(contentView)
}
Loading
Loading
Loading
Loading
@@ -5,15 +5,20 @@ import com.bluelinelabs.logansquare.LoganSquare
import com.commit451.gitlab.api.converter.UriTypeConverter
 
/**
* Provides access to all the GitLab things
* Provides access to all the GitLab things. Wraps RSS and the Retrofit service, in
* case we need to do overrides or global
*/
object GitLab {
class GitLab(gitLabService: GitLabService, gitLabRss: GitLabRss): GitLabService by gitLabService,
GitLabRss by gitLabRss {
 
fun init() {
/**
* Register our type converters on our singleton LoganSquare get. Needs to be set here
* since we are fetching accounts immediately with LoganSquare
*/
LoganSquare.registerTypeConverter(Uri::class.java, UriTypeConverter())
companion object {
fun init() {
/**
* Register our type converters on our singleton LoganSquare get. Needs to be set here
* since we are fetching accounts immediately with LoganSquare
*/
LoganSquare.registerTypeConverter(Uri::class.java, UriTypeConverter())
}
}
}
\ No newline at end of file
Loading
Loading
@@ -7,7 +7,7 @@ import java.text.DateFormat
/**
* Converts due dates
*/
class DueDateTypeConverter() : DateTypeConverter() {
class DueDateTypeConverter : DateTypeConverter() {
 
override fun getDateFormat(): DateFormat {
return Milestone.DUE_DATE_FORMAT
Loading
Loading
Loading
Loading
@@ -40,9 +40,9 @@ class AccessDialog private constructor(context: Context, internal var member: Me
listener = accessAppliedListener
}
 
constructor(context: Context, member: Member, group: Group) : this(context, member, group, -1) {}
constructor(context: Context, member: Member, group: Group) : this(context, member, group, -1)
 
constructor(context: Context, member: Member, projectId: Long) : this(context, member, null, projectId) {}
constructor(context: Context, member: Member, projectId: Long) : this(context, member, null, projectId)
 
init {
getActionButton(DialogAction.POSITIVE).setOnClickListener { onApply() }
Loading
Loading
package com.commit451.gitlab.rx
package com.commit451.gitlab.extension
 
import com.commit451.gitlab.util.FileUtil
import io.reactivex.Single
import okhttp3.MultipartBody
import java.io.File
 
/**
* Rx'ifies file util calls
*/
object FileObservableFactory {
//File extensions
 
fun toPart(file: File): Single<MultipartBody.Part> {
return Single.defer {
Single.just(FileUtil.toPart(file))
}
fun File.toPart(): Single<MultipartBody.Part> {
return Single.fromCallable {
FileUtil.toPart(this)
}
}
}
\ No newline at end of file
package com.commit451.gitlab.extension
import android.util.Base64
import io.reactivex.Single
//String extension methods
fun String.base64Decode(): Single<ByteArray> {
return Single.defer {
Single.just(Base64.decode(this, Base64.DEFAULT))
}
}
Loading
Loading
@@ -99,7 +99,7 @@ class FeedFragment : ButterKnifeFragment() {
}
textMessage.visibility = View.GONE
swipeRefreshLayout.isRefreshing = true
App.get().gitLabRss.getFeed(feedUrl!!.toString())
App.get().gitLab.getFeed(feedUrl!!.toString())
.setup(bindUntilEvent(FragmentEvent.DESTROY_VIEW))
.subscribe(object : CustomSingleObserver<Feed>() {
override fun success(feed: Feed) {
Loading
Loading
Loading
Loading
@@ -16,13 +16,13 @@ import com.commit451.gitlab.App
import com.commit451.gitlab.R
import com.commit451.gitlab.activity.ProjectActivity
import com.commit451.gitlab.event.ProjectReloadEvent
import com.commit451.gitlab.extension.base64Decode
import com.commit451.gitlab.extension.setup
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.rx.DecodeObservableFactory
import com.commit451.gitlab.util.BypassFactory
import com.commit451.gitlab.util.BypassImageGetterFactory
import com.commit451.gitlab.util.InternalLinkMovementMethod
Loading
Loading
@@ -198,7 +198,7 @@ class ProjectFragment : ButterKnifeFragment() {
})
.flatMap(Function<Result<RepositoryFile>, SingleSource<ReadmeResult>> { repositoryFileResult ->
if (repositoryFileResult.isPresent) {
result.bytes = DecodeObservableFactory.newDecode(repositoryFileResult.get().content)
result.bytes = repositoryFileResult.get().content.base64Decode()
.blockingGet()
return@Function Single.just(result)
}
Loading
Loading
package com.commit451.gitlab.rx
import android.util.Base64
import io.reactivex.Single
/**
* Observable that decodes a byte array
*/
object DecodeObservableFactory {
fun newDecode(string: String): Single<ByteArray> {
return Single.defer {
Single.just(Base64.decode(string, Base64.DEFAULT))
}
}
}
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