Skip to content

Commit

Permalink
Merge pull request #190 from alexandr7035/develop
Browse files Browse the repository at this point in the history
Release v5.1

- Add repository page
- Update contribution types plot
- Show privacy policy in Fragment instead of WebView
  • Loading branch information
alexandr7035 authored Nov 21, 2021
2 parents 54b6b6e + 815cc27 commit f7972ae
Show file tree
Hide file tree
Showing 52 changed files with 1,387 additions and 314 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ android {
applicationId 'by.alexandr7035.gitstat'
minSdkVersion 21
targetSdkVersion 31
versionCode 1800
versionName "5.0"
versionCode 1900
versionName "5.1"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
28 changes: 28 additions & 0 deletions app/src/main/graphql/com/alexandr7035/gitstat/Repositories.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,47 @@ query Repositories {
nodes {
databaseId
name
nameWithOwner

description
homepageUrl

repositoryTopics(first: 100) {
nodes {
topic {
name
}
}
}

primaryLanguage {
color
name
}

languages(first: 100) {
edges {
node {
name
color
}
size
}
}

isPrivate
isArchived
isFork

stargazerCount

createdAt
updatedAt
diskUsage

parent {
nameWithOwner
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package by.alexandr7035.gitstat.core.view

import android.annotation.SuppressLint
import android.content.Context
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.RectF
import android.util.AttributeSet
import android.view.View
import by.alexandr7035.gitstat.R
import by.alexandr7035.gitstat.extensions.debug
import timber.log.Timber


class HorizontalRatioBarView(context: Context, private val attrs: AttributeSet) : View(context, attrs) {

private val paint = Paint()

private var colors: List<Int>? = null
private var values: List<Float>? = null

private var spacingBetweenEntries = 0f
private var entryCornerRadius = 0f

init {
val typedArray = context.theme.obtainStyledAttributes(
attrs, R.styleable.HorizontalRatioBarView, 0, 0
)

spacingBetweenEntries = typedArray.getDimension(R.styleable.HorizontalRatioBarView_hrb_entries_between_spacing, 0f)
entryCornerRadius = typedArray.getDimensionPixelSize(R.styleable.HorizontalRatioBarView_hrb_entry_corner_radius, 0).toFloat()
Timber.debug("customView onAttachToWindow() spacing $spacingBetweenEntries corners $entryCornerRadius")

typedArray.recycle()
}


@SuppressLint("DrawAllocation")
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
Timber.debug("customView onDraw()")

if ((! colors.isNullOrEmpty()) && (! values.isNullOrEmpty())) {

// Total sum of values
// Used to calculate percentage for a particular value
val total = values!!.sum()

// View width without spacings
val realWidth = width - spacingBetweenEntries * (values!!.size - 1)

// Inset is changed for next value
var inset = 0f

values!!.forEachIndexed { index, bar ->

// Calculate value percentage
val valuePercentage = bar / total

val rectLeft = inset
val rectTop = 0f
// Value pixel size considering percentage and width of view
val rectRight = inset + valuePercentage*realWidth
val rectBottom = height.toFloat()

// Set color
paint.color = colors!![index]


// Draw entry
val rect = RectF(rectLeft, rectTop, rectRight, rectBottom)
canvas.drawRoundRect(
rect,
entryCornerRadius,
entryCornerRadius,
paint
)

inset += rect.width()
inset += spacingBetweenEntries
}
}

}

fun setValues(values: List<Float>, colors: List<Int>) {

if (values.size != colors.size) {
throw IllegalArgumentException("Lengths of values and colors lists MUST be the same!")
}

this.values = values
this.colors = colors
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class ReposRepository @Inject constructor(
return dao.getRepositoriesLiveData()
}

fun getRepositoryLiveData(repositoryId: Int): LiveData<RepositoryEntity> {
return dao.getRepositoryLiveData(repositoryId)
}

suspend fun fetchAllRepositoriesFromDb(): List<RepositoryEntity> {
return dao.getRepositories()
}
Expand Down Expand Up @@ -57,14 +61,14 @@ class ReposRepository @Inject constructor(
val languagesList = ArrayList<Language>()

repos.forEach {
languagesList.add(Language(it.language, it.languageColor, 0))
languagesList.add(Language(it.primaryLanguage, it.primaryLanguageColor, 0))
}

val trimmedLanguages = languagesList.distinct()

repos.forEach { repo ->
trimmedLanguages.forEach { language ->
if (repo.language == language.name) {
if (repo.primaryLanguage == language.name) {
language.count += 1
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package by.alexandr7035.gitstat.data.local

import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import by.alexandr7035.gitstat.data.local.dao.ContributionsDao
import by.alexandr7035.gitstat.data.local.dao.RepositoriesDao
import by.alexandr7035.gitstat.data.local.dao.UserDao
Expand All @@ -13,8 +14,9 @@ import by.alexandr7035.gitstat.data.local.model.*
ContributionRateEntity::class,
ContributionsYearEntity::class,
ContributionTypesEntity::class,
ContributionsMonthEntity::class], version = 20)
ContributionsMonthEntity::class], version = 21)

@TypeConverters(RoomTypeConverters::class)
abstract class CacheDB : RoomDatabase() {

abstract fun getUserDao(): UserDao
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package by.alexandr7035.gitstat.data.local

import androidx.room.ProvidedTypeConverter
import androidx.room.TypeConverter
import by.alexandr7035.gitstat.core.Language
import by.alexandr7035.gitstat.data.local.model.RepoLanguage
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken

@ProvidedTypeConverter
class RoomTypeConverters(private val gson: Gson) {

@TypeConverter
fun fromString(value: String?): ArrayList<String?>? {
val listType = object : TypeToken<ArrayList<String?>?>() {}.type
return gson.fromJson(value, listType)
}

@TypeConverter
fun fromArrayList(list: ArrayList<String?>?): String? {
return gson.toJson(list)
}

@TypeConverter
fun fromLanguage(languages: List<RepoLanguage>?): String? {
return gson.toJson(languages)
}

@TypeConverter
fun getLanguageFromString(languagesStr: String?): List<RepoLanguage>? {
val listType = object : TypeToken<List<RepoLanguage>?>() {}.type
return gson.fromJson(languagesStr, listType)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ interface RepositoriesDao {
@Query("select * from repositories")
fun getRepositoriesLiveData(): LiveData<List<RepositoryEntity>>

@Query("select * from repositories where id = (:repositoryId)")
fun getRepositoryLiveData(repositoryId: Int): LiveData<RepositoryEntity>

@Query("select * from repositories")
suspend fun getRepositories(): List<RepositoryEntity>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package by.alexandr7035.gitstat.data.local.model

data class RepoLanguage(
val name: String,
val color: String,
val size: Int
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,34 @@ package by.alexandr7035.gitstat.data.local.model

import androidx.room.Entity
import androidx.room.PrimaryKey
import by.alexandr7035.gitstat.core.Language

@Entity(tableName = "repositories")
class RepositoryEntity(

@PrimaryKey
@PrimaryKey
var id: Int,
var name: String,
var language: String,
var languageColor: String,
var name: String,
var nameWithOwner: String,
var parentNameWithOwner: String,

var isPrivate: Boolean,
var isArchived: Boolean,
var isFork: Boolean,
var description: String,
var websiteUrl: String,

var stars: Int,
var primaryLanguage: String,
var primaryLanguageColor: String,

var created_at: Long)
var languages: List<RepoLanguage>,

var isPrivate: Boolean,
var isArchived: Boolean,
var isFork: Boolean,

var stars: Int,

var created_at: Long,
var updated_at: Long,

var diskUsageKB: Int,

val topics: ArrayList<String>)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package by.alexandr7035.gitstat.data.remote.mappers
import by.alexandr7035.gitstat.apollo.RepositoriesQuery
import by.alexandr7035.gitstat.core.Mapper
import by.alexandr7035.gitstat.core.TimeHelper
import by.alexandr7035.gitstat.data.local.model.RepoLanguage
import by.alexandr7035.gitstat.data.local.model.RepositoryEntity
import by.alexandr7035.gitstat.extensions.debug
import timber.log.Timber
import javax.inject.Inject

class RepositoriesRemoteToCacheMapper @Inject constructor(private val timeHelper: TimeHelper): Mapper<RepositoriesQuery.Data, List<RepositoryEntity>> {
Expand Down Expand Up @@ -35,19 +38,76 @@ class RepositoriesRemoteToCacheMapper @Inject constructor(private val timeHelper
}
}

val websiteUrl = if (repo.homepageUrl != null) {
repo.homepageUrl as String
} else {
""
}

val topics = ArrayList<String>()

if (repo.repositoryTopics.nodes != null) {
for (node in repo.repositoryTopics.nodes) {
if (node != null) {
topics.add(node.topic.name)
}
}
}

Timber.debug("topics $topics")

val languages = ArrayList<RepoLanguage>()

if (repo.languages?.edges != null) {

if (repo.languages.edges.isNotEmpty()) {

for (edge in repo.languages.edges) {

val nodeLanguage = when (edge?.node?.name) {
null -> "Unknown"
else -> edge.node.name
}

val nodeLanguageColor = when (edge?.node?.color) {
null -> "#C3C3C3"
else -> edge.node.color
}

val size = edge?.size ?: 0

languages.add(RepoLanguage(name = nodeLanguage, color = nodeLanguageColor, size = size))
}
}
else {
languages.add(RepoLanguage("Unknown", "#C3C3C3", size = 1))
}
}

val repository = RepositoryEntity(
id = repo.databaseId!!,
name = repo.name,
language = language,
languageColor = languageColor,
nameWithOwner = repo.nameWithOwner,
parentNameWithOwner = repo.parent?.nameWithOwner ?: "",

description = repo.description ?: "No repository description provided.",
websiteUrl = websiteUrl,
primaryLanguage = language,
primaryLanguageColor = languageColor,

isPrivate = repo.isPrivate,
isArchived = repo.isArchived,
isFork = repo.isFork,

stars = repo.stargazerCount,

created_at = timeHelper.getUnixDateFromISO8601(repo.createdAt as String)
created_at = timeHelper.getUnixDateFromISO8601(repo.createdAt as String),
updated_at = timeHelper.getUnixDateFromISO8601(repo.updatedAt as String),

diskUsageKB = repo.diskUsage ?: 0,

topics = topics,
languages = languages
)

cachedList.add(repository)
Expand Down
Loading

0 comments on commit f7972ae

Please sign in to comment.