Skip to content

Commit

Permalink
#42: added new style with translucent navigation and status bar. Rena…
Browse files Browse the repository at this point in the history
…med color for background. Added DiffUtils.
  • Loading branch information
temnik15 committed Dec 25, 2020
1 parent 8b6278a commit c639f9d
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 28 deletions.
14 changes: 14 additions & 0 deletions app/src/main/java/so/codex/hawk/HawkApp.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package so.codex.hawk

import android.app.Application
import androidx.core.content.ContextCompat
import so.codex.hawk.entity.res.Density
import so.codex.hawk.entity.res.ProjectIconSide
import so.codex.hawk.entity.res.TextColorIcon
import so.codex.hawk.logging.FileLoggingTree
import so.codex.hawk.logging.LogcatFormatterImpl
import timber.log.Timber
Expand All @@ -19,5 +23,15 @@ class HawkApp : Application() {
SessionKeeper.init(applicationContext)
// Initializing the class for logging
Timber.plant(FileLoggingTree(applicationInfo.dataDir, formatter = LogcatFormatterImpl()))

val res = applicationContext.resources
Density.setDensity(res.displayMetrics.density)
ProjectIconSide.setSide(res.getDimensionPixelSize(R.dimen.project_icon_side))
TextColorIcon.setColor(
ContextCompat.getColor(
applicationContext,
R.color.colorDefaultTextIcon
)
)
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/so/codex/hawk/entity/res/Density.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package so.codex.hawk.entity.res

object Density {
var value = -1f
private set

fun setDensity(density:Float){
if(value<0){
value=density
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/so/codex/hawk/entity/res/ProjectIconSide.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package so.codex.hawk.entity.res

object ProjectIconSide {
var value: Int = -1
private set

fun setSide(side: Int) {
if (value == -1) {
value = side
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/so/codex/hawk/entity/res/TextColorIcon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package so.codex.hawk.entity.res

object TextColorIcon {
var value: Int = -1
private set

fun setColor(newColor: Int) {
if (value == -1) {
value = newColor
}
}
}
19 changes: 9 additions & 10 deletions app/src/main/java/so/codex/hawk/ui/data/UiProject.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package so.codex.hawk.ui.data

import android.content.Context
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Rect
import android.graphics.Typeface
import android.view.View
import androidx.core.content.ContextCompat
import so.codex.hawk.R
import so.codex.hawk.entity.res.Density
import so.codex.hawk.entity.res.ProjectIconSide
import so.codex.hawk.entity.res.TextColorIcon
import so.codex.hawk.extensions.domain.Utils

/**
Expand Down Expand Up @@ -49,28 +48,28 @@ data class UiProject(
/**
* Method for obtaining a standard icon.
*/
fun getDefaultIcon(view: View): Bitmap {
fun getDefaultIcon(): Bitmap {
if (defaultIcon == null) {
createDefaultLogo(view.context)
createDefaultLogo()
}
return defaultIcon!!
}

/**
* Method for creating a standard icon
*/
fun createDefaultLogo(appContext: Context) {
val side = appContext.resources.getDimensionPixelSize(R.dimen.workspace_icon_side)
fun createDefaultLogo() {
val side = ProjectIconSide.value
val defaultIcon = Bitmap.createBitmap(
side,
side,
Bitmap.Config.ARGB_8888
)
val canvas = Canvas(defaultIcon!!)
val fontPaint = Paint(Paint.ANTI_ALIAS_FLAG).apply {
textSize = 14f * appContext.resources.displayMetrics.density + 0.5f
textSize = 14f * Density.value + 0.5f
typeface = Typeface.create("roboto", Typeface.BOLD)
color = ContextCompat.getColor(appContext, R.color.colorDefaultTextIcon)
color = TextColorIcon.value
}
val bounds = Rect()
fontPaint.getTextBounds(abbreviationName, 0, abbreviationName.length, bounds)
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/java/so/codex/hawk/ui/main/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ class MainActivity : AppCompatActivity() {
* ViewModel handle models from business logic and convert to ui models
*/
private val viewModel: MainViewModel by lazy {
val item = ViewModelProvider(
ViewModelProvider(
this,
ViewModelProvider.NewInstanceFactory()
).get(MainViewModel::class.java)
item.context = applicationContext
item
}

/**
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/java/so/codex/hawk/ui/main/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import so.codex.hawk.ui.data.UiWorkspace
*/
class MainViewModel : ViewModel() {

/**
* @see Context
*/
lateinit var context: Context

/**
* A LiveData of [UiMainViewModel] that should be inserted to the view
*/
Expand Down Expand Up @@ -107,7 +102,7 @@ class MainViewModel : ViewModel() {
val item =
UiProject(it.id, it.name, it.description, it.image, it.unreadCount)
if (item.image.isBlank()) {
item.createDefaultLogo(context)
item.createDefaultLogo()
}
item
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class ProjectAdapter : ListAdapter<UiProject, ProjectAdapter.ViewHolder>(Project
if (item.image.isNotEmpty()) {
Picasso.get().load(item.image).into(iconImageView)
} else {
iconImageView.setImageBitmap(item.getDefaultIcon(iconImageView))
iconImageView.setImageBitmap(item.getDefaultIcon())
}
eventsTextView.visibility = if (item.unreadCount == 0) {
View.INVISIBLE
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/project_list_item.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

<so.codex.hawk.custom.views.SquircleImageView
android:id="@+id/icon"
android:layout_width="@dimen/workspace_icon_side"
android:layout_height="@dimen/workspace_icon_side"
android:layout_width="@dimen/project_icon_side"
android:layout_height="@dimen/project_icon_side"
android:layout_gravity="center"
android:scaleType="centerCrop"
android:src="@drawable/ic_launcher_background" />
Expand Down
7 changes: 1 addition & 6 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,7 @@
<dimen name="radius_small">4dp</dimen>
<dimen name="radius_default">8dp</dimen>

<!-- project icon -->
<dimen name="default_icon_width">32dp</dimen>
<dimen name="default_icon_height">32dp</dimen>

<!-- workspace icon -->
<dimen name="workspace_icon_side">48dp</dimen>
<dimen name="project_icon_side">48dp</dimen>

<!-- Other -->
<dimen name="default_border">1dp</dimen>
Expand Down

0 comments on commit c639f9d

Please sign in to comment.