-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #190 from alexandr7035/develop
Release v5.1 - Add repository page - Update contribution types plot - Show privacy policy in Fragment instead of WebView
- Loading branch information
Showing
52 changed files
with
1,387 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
app/src/main/java/by/alexandr7035/gitstat/core/view/HorizontalRatioBarView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
app/src/main/java/by/alexandr7035/gitstat/data/local/RoomTypeConverters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
app/src/main/java/by/alexandr7035/gitstat/data/local/model/RepoLanguage.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.