Commit 44031d09 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Merge branch 'develop'

parents 3f77d742 014c7573
Privacy Policy of GitFox android application.
Konstantin Tskhovrebov built the GitFox app as an Open Source app. This SERVICE is provided by Konstantin Tskhovrebov at no cost and is intended for use as is.
This page is used to inform visitors regarding my policies with the collection, use, and disclosure of Personal Information if anyone decided to use my Service.
If you choose to use my Service, then you agree to the collection and use of information in relation to this policy. The Personal Information that I collect is used for providing and improving the Service. I will not use or share your information with anyone except as described in this Privacy Policy.
The terms used in this Privacy Policy have the same meanings as in our Terms and Conditions, which is accessible at GitFox unless otherwise defined in this Privacy Policy.
Information Collection and Use
For a better experience, while using our Service, I may require you to provide us with certain personally identifiable information. The information that I request will be retained on your device and is not collected by me in any way.
The app does use third party services that may collect information used to identify you.
Link to privacy policy of third party service providers used by the app
Firebase Analytics (https://firebase.google.com/policies/analytics)
Crashlytics (http://try.crashlytics.com/terms/privacy-policy.pdf)
Log Data
I want to inform you that whenever you use my Service, in a case of an error in the app I collect data and information (through third party products) on your phone called Log Data. This Log Data may include information such as your device Internet Protocol (“IP”) address, device name, operating system version, the configuration of the app when utilizing my Service, the time and date of your use of the Service, and other statistics.
Cookies
Cookies are files with a small amount of data that are commonly used as anonymous unique identifiers. These are sent to your browser from the websites that you visit and are stored on your device's internal memory.
This Service does not use these “cookies” explicitly. However, the app may use third party code and libraries that use “cookies” to collect information and improve their services. You have the option to either accept or refuse these cookies and know when a cookie is being sent to your device. If you choose to refuse our cookies, you may not be able to use some portions of this Service.
Service Providers
I may employ third-party companies and individuals due to the following reasons:
To facilitate our Service;
To provide the Service on our behalf;
To perform Service-related services; or
To assist us in analyzing how our Service is used.
I want to inform users of this Service that these third parties have access to your Personal Information. The reason is to perform the tasks assigned to them on our behalf. However, they are obligated not to disclose or use the information for any other purpose.
Security
I value your trust in providing us your Personal Information, thus we are striving to use commercially acceptable means of protecting it. But remember that no method of transmission over the internet, or method of electronic storage is 100% secure and reliable, and I cannot guarantee its absolute security.
Links to Other Sites
This Service may contain links to other sites. If you click on a third-party link, you will be directed to that site. Note that these external sites are not operated by me. Therefore, I strongly advise you to review the Privacy Policy of these websites. I have no control over and assume no responsibility for the content, privacy policies, or practices of any third-party sites or services.
Children’s Privacy
These Services do not address anyone under the age of 13. I do not knowingly collect personally identifiable information from children under 13. In the case I discover that a child under 13 has provided me with personal information, I immediately delete this from our servers. If you are a parent or guardian and you are aware that your child has provided us with personal information, please contact me so that I will be able to do necessary actions.
Changes to This Privacy Policy
I may update our Privacy Policy from time to time. Thus, you are advised to review this page periodically for any changes. I will notify you of any changes by posting the new Privacy Policy on this page. These changes are effective immediately after they are posted on this page.
Contact Us
If you have any questions or suggestions about my Privacy Policy, do not hesitate to contact me.
\ No newline at end of file
......@@ -7,7 +7,7 @@ apply from: '../ci.gradle'
android {
compileSdkVersion 28
buildToolsVersion '28.0.2'
buildToolsVersion '28.0.3'
defaultConfig {
applicationId "com.gitlab.terrakok.gitfox"
......@@ -15,8 +15,8 @@ android {
minSdkVersion 19
targetSdkVersion 28
versionName "1.1.1"
versionCode 6
versionName "1.2.0"
versionCode 7
buildConfigField "String", "VERSION_UID", '"' + getBuildUid() + '"'
buildConfigField "String", "APP_DESCRIPTION", '"Gitfox is an Android client for Gitlab."'
......@@ -90,7 +90,7 @@ dependencies {
kapt "com.arello-mobile:moxy-compiler:$moxyVersion"
implementation "com.arello-mobile:moxy-app-compat:$moxyVersion"
//Cicerone Navigation
implementation "ru.terrakok.cicerone:cicerone:3.0.0"
implementation "ru.terrakok.cicerone:cicerone:4.0.2"
//DI
implementation "com.github.stephanenicolas.toothpick:toothpick-runtime:$toothpickVersion"
kapt "com.github.stephanenicolas.toothpick:toothpick-compiler:$toothpickVersion"
......
......@@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="ru.terrakok.gitlabclient">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".App"
......@@ -16,10 +16,11 @@
<activity
android:name=".ui.AppActivity"
android:theme="@style/AppTheme.Splash">
android:theme="@style/AppTheme.Splash"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
......
package ru.terrakok.gitlabclient.entity
import com.google.gson.annotations.SerializedName
import org.threeten.bp.LocalDateTime
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
*/
data class Commit(
@SerializedName("id") val id: String,
@SerializedName("short_id") val shortId: String,
@SerializedName("title") val title: String,
@SerializedName("author_name") val authorName: String,
@SerializedName("author_email") val authorEmail: String?,
@SerializedName("authored_date") val authoredDate: LocalDateTime,
@SerializedName("commiter_name") val commiterName: String?,
@SerializedName("commiter_email") val commiterEmail: String?,
@SerializedName("commited_date") val commitedDate: LocalDateTime?,
@SerializedName("created_at") val createdAt: LocalDateTime,
@SerializedName("message") val message: String,
@SerializedName("parent_ids") val parentIds: List<String>
)
\ No newline at end of file
package ru.terrakok.gitlabclient.entity.app
import ru.terrakok.gitlabclient.entity.Commit
/**
* Created by Eugene Shapovalov (@CraggyHaggy) on 20.10.18.
*/
data class CommitWithAvatarUrl(val commit: Commit, val authorAvatarUrl: String?)
\ No newline at end of file
......@@ -6,14 +6,18 @@ import ru.terrakok.gitlabclient.entity.Author
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 24.12.17.
*/
data class TargetHeader(
val author: Author,
val icon: TargetHeaderIcon,
val title: TargetHeaderTitle,
val body: CharSequence,
val date: LocalDateTime,
val target: AppTarget,
val targetId: Long,
val internal: TargetInternal?,
val badges: List<TargetBadge>
)
\ No newline at end of file
sealed class TargetHeader {
data class Public(
val author: Author,
val icon: TargetHeaderIcon,
val title: TargetHeaderTitle,
val body: CharSequence,
val date: LocalDateTime,
val target: AppTarget,
val targetId: Long,
val internal: TargetInternal?,
val badges: List<TargetBadge>
) : TargetHeader()
object Confidential : TargetHeader()
}
\ No newline at end of file
package ru.terrakok.gitlabclient.extension
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
import android.graphics.Color
import android.graphics.drawable.Drawable
import android.net.Uri
......@@ -13,12 +15,14 @@ import android.support.v4.graphics.drawable.DrawableCompat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import android.webkit.URLUtil
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions
import ru.terrakok.cicerone.Navigator
import ru.terrakok.cicerone.android.support.SupportAppScreen
import ru.terrakok.cicerone.commands.BackTo
import ru.terrakok.cicerone.commands.Replace
import ru.terrakok.gitlabclient.R
......@@ -31,11 +35,11 @@ import timber.log.Timber
/**
* @author Konstantin Tskhovrebov (aka terrakok). Date: 03.03.17
*/
fun Navigator.setLaunchScreen(screenKey: String, data: Any? = null) {
fun Navigator.setLaunchScreen(screen: SupportAppScreen) {
applyCommands(
arrayOf(
BackTo(null),
Replace(screenKey, data)
Replace(screen)
)
)
}
......@@ -43,9 +47,17 @@ fun Navigator.setLaunchScreen(screenKey: String, data: Any? = null) {
fun Context.color(colorRes: Int) = ContextCompat.getColor(this, colorRes)
fun Context.getTintDrawable(drawableRes: Int, colorRes: Int): Drawable {
val wrapDrawable = DrawableCompat.wrap(ContextCompat.getDrawable(this, drawableRes)!!).mutate()
DrawableCompat.setTint(wrapDrawable, color(colorRes))
return wrapDrawable
val source = ContextCompat.getDrawable(this, drawableRes)!!.mutate()
val wrapped = DrawableCompat.wrap(source)
DrawableCompat.setTint(wrapped, color(colorRes))
return wrapped
}
fun Context.getTintDrawable(drawableRes: Int, colorResources: IntArray, states: Array<IntArray>): Drawable {
val source = ContextCompat.getDrawable(this, drawableRes)!!.mutate()
val wrapped = DrawableCompat.wrap(source)
DrawableCompat.setTintList(wrapped, ColorStateList(states, colorResources.map { color(it) }.toIntArray()))
return wrapped
}
fun TextView.setStartDrawable(drawable: Drawable) {
......@@ -135,35 +147,29 @@ fun ImageView.loadRoundedImage(
.into(this)
}
fun TargetHeader.openInfo(router: FlowRouter) {
fun TargetHeader.Public.openInfo(router: FlowRouter) {
when (target) {
AppTarget.PROJECT -> {
router.startFlow(Screens.PROJECT_FLOW, targetId)
router.startFlow(Screens.ProjectFlow(targetId))
}
AppTarget.USER -> {
router.startFlow(Screens.USER_FLOW, targetId)
router.startFlow(Screens.UserFlow(targetId))
}
AppTarget.MERGE_REQUEST -> {
internal?.let { targetInternal ->
router.startFlow(
Screens.MR_FLOW,
Pair(targetInternal.projectId, targetInternal.targetIid)
)
router.startFlow(Screens.MergeRequestFlow(targetInternal.projectId, targetInternal.targetIid))
}
}
AppTarget.ISSUE -> {
internal?.let { targetInternal ->
router.startFlow(
Screens.ISSUE_FLOW,
Pair(targetInternal.projectId, targetInternal.targetIid)
)
router.startFlow(Screens.IssueFlow(targetInternal.projectId, targetInternal.targetIid))
}
}
else -> {
internal?.let { targetInternal ->
Timber.i("Temporary open project flow")
//todo
router.startFlow(Screens.PROJECT_FLOW, targetInternal.projectId)
router.startFlow(Screens.ProjectFlow(targetInternal.projectId))
}
}
}
......@@ -176,4 +182,13 @@ fun Fragment.showSnackMessage(message: String) {
messageTextView.setTextColor(Color.WHITE)
snackbar.show()
}
}
\ No newline at end of file
}
fun Activity.hideKeyboard() {
currentFocus?.apply {
val inputManager = getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputManager.hideSoftInputFromWindow(windowToken, InputMethodManager.HIDE_NOT_ALWAYS)
}
}
fun Any.objectScopeName() = "${javaClass.simpleName}_${hashCode()}"
\ No newline at end of file
package ru.terrakok.gitlabclient.model.data.cache
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.toothpick.PrimitiveWrapper
import ru.terrakok.gitlabclient.toothpick.qualifier.CacheLifetime
import timber.log.Timber
import java.util.concurrent.ConcurrentHashMap
import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 14.10.18.
*/
class ProjectCache @Inject constructor(
@CacheLifetime lifetimeWrapper: PrimitiveWrapper<Long>
) {
private val lifetime = lifetimeWrapper.value
private data class ProjectCacheItem(val time: Long, val data: Project)
private val cache = ConcurrentHashMap<Long, ProjectCacheItem>()
fun clear() {
Timber.d("Clear cache")
cache.clear()
}
fun put(data: List<Project>) {
Timber.d("Put projects")
cache.putAll(
data
.asSequence()
.map { ProjectCacheItem(System.currentTimeMillis(), it) }
.associateBy { it.data.id }
)
}
fun get(id: Long): Project? {
val item = cache[id]
if (item == null || System.currentTimeMillis() - item.time > lifetime) {
Timber.d("Get NULL project($id)")
return null
} else {
Timber.d("Get CACHED project($id)")
return item.data
}
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.data.server
import io.reactivex.Single
import ru.terrakok.gitlabclient.entity.OrderBy
import ru.terrakok.gitlabclient.entity.Project
import ru.terrakok.gitlabclient.entity.Sort
import ru.terrakok.gitlabclient.entity.Visibility
import ru.terrakok.gitlabclient.model.data.cache.ProjectCache
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 14.10.18.
*/
class ApiWithCache(
private val serverApi: GitlabApi,
private val projectCache: ProjectCache
) : GitlabApi by serverApi {
override fun getProjects(
archived: Boolean?,
visibility: Visibility?,
orderBy: OrderBy?,
sort: Sort?,
search: String?,
simple: Boolean?,
owned: Boolean?,
membership: Boolean?,
starred: Boolean?,
page: Int,
pageSize: Int
): Single<List<Project>> =
serverApi
.getProjects(
archived,
visibility,
orderBy,
sort,
search,
simple,
owned,
membership,
starred,
page,
pageSize
)
.doOnSuccess { projectCache.put(it) }
override fun getProject(
id: Long,
statistics: Boolean
): Single<Project> =
Single
.defer {
val cachedProject = projectCache.get(id)
if (cachedProject == null) {
serverApi.getProject(id, statistics)
.doOnSuccess { projectCache.put(listOf(it)) }
} else {
Single.just(cachedProject)
}
}
}
\ No newline at end of file
......@@ -223,4 +223,36 @@ interface GitlabApi {
@Query("page") page: Int,
@Query("per_page") pageSize: Int
): Single<List<Note>>
@FormUrlEncoded
@POST("$API_PATH/projects/{project_id}/issues/{issue_id}/notes")
fun createIssueNote(
@Path("project_id") projectId: Long,
@Path("issue_id") issueId: Long,
@Field("body") body: String
): Single<Note>
@FormUrlEncoded
@POST("$API_PATH/projects/{project_id}/merge_requests/{merge_request_id}/notes")
fun createMergeRequestNote(
@Path("project_id") projectId: Long,
@Path("merge_request_id") mergeRequestId: Long,
@Field("body") body: String
): Single<Note>
@GET("$API_PATH/projects/{project_id}/merge_requests/{merge_request_id}/commits")
fun getMergeRequestCommits(
@Path("project_id") projectId: Long,
@Path("merge_request_id") mergeRequestId: Long,
@Query("page") page: Int,
@Query("per_page") pageSize: Int
): Single<List<Commit>>
@GET("$API_PATH/projects/{project_id}/merge_requests/{merge_request_id}/participants")
fun getMergeRequestParticipants(
@Path("project_id") projectId: Long,
@Path("merge_request_id") mergeRequestId: Long,
@Query("page") page: Int,
@Query("per_page") pageSize: Int
): Single<List<Author>>
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.interactor.auth
import io.reactivex.Completable
import ru.terrakok.gitlabclient.model.data.cache.ProjectCache
import ru.terrakok.gitlabclient.model.repository.auth.AuthRepository
import ru.terrakok.gitlabclient.toothpick.DI
import ru.terrakok.gitlabclient.toothpick.module.ServerModule
......@@ -19,20 +20,23 @@ class AuthInteractor(
private val defaultServerPath: String,
private val authRepository: AuthRepository,
private val hash: String,
private val oauthParams: OAuthParams
private val oauthParams: OAuthParams,
private val projectCache: ProjectCache
) {
@Inject constructor(
@ServerPath serverPath: String,
@DefaultServerPath defaultServerPath: String,
authRepository: AuthRepository,
oauthParams: OAuthParams
oauthParams: OAuthParams,
projectCache: ProjectCache
) : this(
serverPath,
defaultServerPath,
authRepository,
UUID.randomUUID().toString(),
oauthParams
oauthParams,
projectCache
)
val oauthUrl = "${serverPath}oauth/authorize?client_id=${oauthParams.appId}" +
......@@ -73,6 +77,7 @@ class AuthInteractor(
fun logout() {
authRepository.clearAuthData()
projectCache.clear()
switchServerIfNeeded(defaultServerPath)
}
......
......@@ -48,4 +48,15 @@ class IssueInteractor @Inject constructor(
issueId: Long,
page: Int
) = issueRepository.getIssueNotes(projectId, issueId, Sort.ASC, OrderBy.UPDATED_AT, page)
fun getAllIssueNotes(
projectId: Long,
issueId: Long
) = issueRepository.getAllIssueNotes(projectId, issueId, Sort.ASC, OrderBy.UPDATED_AT)
fun createIssueNote(
projectId: Long,
issueId: Long,
body: String
) = issueRepository.createIssueNote(projectId, issueId, body)
}
\ No newline at end of file
......@@ -44,4 +44,21 @@ class MergeRequestInteractor @Inject constructor(
mergeRequestId: Long,
page: Int
) = mergeRequestRepository.getMergeRequestNotes(projectId, mergeRequestId, Sort.ASC, OrderBy.UPDATED_AT, page)
fun getAllMergeRequestNotes(
projectId: Long,
mergeRequestId: Long
) = mergeRequestRepository.getAllMergeRequestNotes(projectId, mergeRequestId, Sort.ASC, OrderBy.UPDATED_AT)
fun createMergeRequestNote(
projectId: Long,
issueId: Long,
body: String
) = mergeRequestRepository.createMergeRequestNote(projectId, issueId, body)
fun getMergeRequestCommits(
projectId: Long,
mergeRequestId: Long,
page: Int
) = mergeRequestRepository.getMergeRequestCommits(projectId, mergeRequestId, page)
}
\ No newline at end of file
......@@ -51,6 +51,7 @@ class EventRepository @Inject constructor(
page,
pageSize
)
.map { filterBrokenEvents(it) }
.flatMap { events ->
Single.zip(
Single.just(events),
......@@ -85,6 +86,7 @@ class EventRepository @Inject constructor(
page,
pageSize
)
.map { filterBrokenEvents(it) }
.flatMap { events ->
Single.zip(
Single.just(events),
......@@ -97,38 +99,58 @@ class EventRepository @Inject constructor(
.subscribeOn(schedulers.io())
.observeOn(schedulers.ui())
private fun filterBrokenEvents(events: List<Event>): List<Event> = events.filter { !isNoteBroken(it) }
/**
* Sometimes GitLab returns event with targetType = DIFF_NOTE || targetType = _NOTE, but _note = null.
* On web these events are filtered.
*/
private fun isNoteBroken(event: Event) =
event.targetType != null
&& (event.targetType == EventTargetType.DIFF_NOTE || event.targetType == EventTargetType.NOTE)
&& event.note == null
private fun getDistinctProjects(events: List<Event>): Single<Map<Long, Project>> {
return Observable.fromIterable(events)
.filter { it.projectId != 0L }
.distinct { it.projectId }
.flatMapSingle { event -> api.getProject(event.projectId) }
.toMap { it.id }
}
private fun getTargetHeader(event: Event, project: Project?): TargetHeader {
val targetData = getTarget(event)
val badges = mutableListOf<TargetBadge>()
project?.let { badges.add(TargetBadge.Text(it.name, AppTarget.PROJECT, it.id)) }
badges.add(TargetBadge.Text(event.author.username, AppTarget.USER, event.author.id))
event.pushData?.let { pushData ->
badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMITS, pushData.commitCount))
}
// There are two event types: public and confidential.
// Public events are opened to read with any rights in project.
// Confidential event is closed to read without specific rights in project.
// So GitLab returns it will undefined values.
return if (event.projectId != 0L) {
val targetData = getTarget(event)
val badges = mutableListOf<TargetBadge>()
project?.let { badges.add(TargetBadge.Text(it.name, AppTarget.PROJECT, it.id)) }
badges.add(TargetBadge.Text(event.author.username, AppTarget.USER, event.author.id))
event.pushData?.let { pushData ->
badges.add(TargetBadge.Icon(TargetBadgeIcon.COMMITS, pushData.commitCount))
}
return TargetHeader(
event.author,
getIcon(event.actionName),
TargetHeaderTitle.Event(
event.author.name,
event.actionName,
targetData.name,
project?.name ?: ""
),
getBody(event, project) ?: "",
event.createdAt,
targetData.target,
targetData.id,
getTargetInternal(event),
badges
)
TargetHeader.Public(
event.author,
getIcon(event.actionName),
TargetHeaderTitle.Event(
event.author.name,
event.actionName,
targetData.name,
project?.name ?: ""
),
getBody(event, project) ?: "",
event.createdAt,
targetData.target,
targetData.id,
getTargetInternal(event),
badges
)
} else {
TargetHeader.Confidential
}
}
private fun getIcon(action: EventAction) = when (action) {
......
......@@ -105,7 +105,7 @@ class IssueRepository @Inject constructor(
badges.add(TargetBadge.Icon(TargetBadgeIcon.DOWN_VOTES, issue.downvotes))
issue.labels.forEach { label -> badges.add(TargetBadge.Text(label)) }
return TargetHeader(
return TargetHeader.Public(
issue.author,
TargetHeaderIcon.NONE,
TargetHeaderTitle.Event(
......@@ -154,19 +154,50 @@ class IssueRepository @Inject constructor(
api.getProject(projectId),
api.getIssueNotes(projectId, issueId, sort, orderBy, page, pageSize),
BiFunction<Project, List<Note>, List<Note>> { project, notes ->
ArrayList(notes).apply {
val iterator = listIterator()
while (iterator.hasNext()) {
val note = iterator.next()
val resolved = markDownUrlResolver.resolve(note.body, project)
notes.map { resolveMarkDownUrl(it, project) }
}
)
.subscribeOn(schedulers.io())