Skip to content

Commit

Permalink
wheelView fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sidsharma2002 committed Sep 11, 2022
1 parent c49c5b6 commit 2469249
Show file tree
Hide file tree
Showing 15 changed files with 230 additions and 88 deletions.
2 changes: 2 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions app/src/main/java/com/example/spinwill/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@ package com.example.spinwill

import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Color
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.widget.FrameLayout
import android.widget.ImageView
import androidx.core.content.ContextCompat
import androidx.work.*
import com.example.spinwill.adapter.WillItemAdapter
import com.example.spinwill.cron.SpinWillWorker
import com.example.spinwill.cron.SpinWillWorkerFactory
import com.example.spinwill.database.local.SpinWillLocalDbImpl
import com.example.spinwill.di.SpinWillInjector
import com.example.spinwill.ui.SpinWillView1
import com.example.spinwill.ui.WillView1
import com.example.spinwill.ui.adapters.WillItemUiAdapter
import com.example.spinwill.usecases.SpinWillBitmapLoadUseCaseImpl
Expand All @@ -35,18 +38,26 @@ class MainActivity : AppCompatActivity() {

setupDependencies()
// setupWork()
setupUi()
// setupUi()
setupWheelView()
}

private fun setupWheelView() {
val layout = findViewById<FrameLayout>(R.id.frame)
val willView = WillView1<SpinWillItem>(this, null)
val willView = SpinWillView1<SpinWillItem>(this)
layout.addView(willView)
scope.launch(Dispatchers.IO) {
val result = injector.getLocalDatabase().getAllWillItems()
injector.getRepository().fetchAndUpdateWheelItem()
val result = injector.getRepository().loadBitmapAndSave()

if (result is Resource.Success && result.data != null) {
val list = result.data!!
Log.d("MainAct", "result size " + list.size)

runOnUiThread {
willView.getWillView().paintProps.textPaint.apply {
color = Color.WHITE
}
willView.setItems(result.data!!)
willView.setItemAdapter(object : WillItemUiAdapter<SpinWillItem> {
override fun getRewardText(item: SpinWillItem): String {
Expand Down
32 changes: 12 additions & 20 deletions app/src/main/java/com/example/spinwill/RemoteDatabaseImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,20 @@ class RemoteDatabaseImpl : SpinWillRemoteDatabase<SpinWillItem> {
Log.d("App", "23")
val list = mutableListOf<SpinWillItem>()

list.add(
SpinWillItem(
rewardId = 1L,
rewardAmount = 100L,
rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg",
rewardText = "100 COINS"
/*
when number of items is odd it creates repetition in color of arcs
*/
for (i in 0..5) {
list.add(
SpinWillItem(
rewardId = 1L,
rewardAmount = i * 100L,
rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg",
rewardText = "${i}00"
)
)
)

delay(1000L)

list.add(
SpinWillItem(
rewardId = 1L,
rewardAmount = 100L,
rewardImage = "https://images.pexels.com/photos/2014422/pexels-photo-2014422.jpeg",
rewardText = "100 COINS"
)
)

}
Log.d("App", "19")

return Resource.Success(list)
}
}
9 changes: 5 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
android:id="@+id/iv_1"
android:layout_width="100dp"
android:layout_height="100dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -18,18 +19,18 @@
android:id="@+id/iv_2"
android:layout_width="200dp"
android:layout_height="200dp"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_1" />

<FrameLayout
android:id="@+id/frame"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_marginBottom="22dp"
android:layout_width="240dp"
android:layout_height="240dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_2" />
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
4 changes: 4 additions & 0 deletions jitpack.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
jdk:
- openjdk11
before_install:
- ./scripts/prepareJitpackEnvironment.sh
15 changes: 15 additions & 0 deletions spinwill/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id 'kotlin-android'
id 'kotlin-android-extensions'
id 'kotlin-kapt'
id 'maven-publish'
}

android {
Expand Down Expand Up @@ -58,4 +59,18 @@ dependencies {
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}

afterEvaluate {
publishing {
publications {
release(MavenPublication) {
from components.release

groupId = 'com.github.sidsharma2002'
artifactId = 'SpinWill'
version = '0.1'
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.example.spinwill.adapter

import android.graphics.Paint

interface WillPaintAdapter {
fun setPaintProperties(paint: Paint)
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,34 @@
package com.example.spinwill.models

import android.graphics.Paint
import com.example.spinwill.adapter.WillPaintAdapter

data class WillPaintProperties(
val archPaint: Paint = Paint(),
val textPaint: Paint = Paint(),
val overlayTextPaint: Paint = Paint(),
val separationArchPaint: Paint = Paint(),
val bitmapPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG or Paint.FILTER_BITMAP_FLAG)
val archPaint: Paint = Paint().apply {
isAntiAlias = true
isDither = true
style = Paint.Style.FILL_AND_STROKE
},
val textPaint: Paint = Paint().apply {
isAntiAlias = true
isDither = true
letterSpacing = 0.1f
},
val overlayTextPaint: Paint = Paint().apply {
isAntiAlias = true
isDither = true
letterSpacing = 0.1f
},
val separationArchPaint: Paint = Paint().apply {
style = Paint.Style.STROKE
isAntiAlias = true
isDither = true
},
val bitmapPaint: Paint = Paint(Paint.ANTI_ALIAS_FLAG or Paint.DITHER_FLAG or Paint.FILTER_BITMAP_FLAG),

var archPaintAdapter: WillPaintAdapter? = null,
var textPaintAdapter: WillPaintAdapter? = null,
var overlayTextPaintAdapter: WillPaintAdapter? = null,
var separationArchPaintAdapter: WillPaintAdapter? = null,
var bitmapPaintAdapter: WillPaintAdapter? = null
)
46 changes: 46 additions & 0 deletions spinwill/src/main/java/com/example/spinwill/ui/SpinWillView1.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.example.spinwill.ui

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.widget.FrameLayout
import androidx.annotation.ColorRes
import androidx.annotation.IdRes
import androidx.constraintlayout.widget.ConstraintLayout
import com.example.spinwill.R
import com.example.spinwill.ui.adapters.WillItemUiAdapter

class SpinWillView1<T> constructor(
context: Context
) : ConstraintLayout(context) {

private lateinit var willView1: WillView1<T>

init {
val parentView =
LayoutInflater.from(context).inflate(R.layout.layout_spinwillview1, null, false)
willView1 = WillView1<T>(context, null)
val parentLayout: FrameLayout = parentView.findViewById(R.id.container)
parentLayout.addView(willView1)
addView(parentView)
postInvalidate()
}

fun setItems(data: List<T>) {
willView1.setItems(data)
willView1.invalidate()
}

fun setItemAdapter(willItemUiAdapter: WillItemUiAdapter<T>) {
willView1.setItemAdapter(willItemUiAdapter)
willView1.invalidate()
}

fun getWillView(): WillView1<T> {
return willView1
}

fun setTextColor(@IdRes color: Int) {
willView1.paintProps.textPaint.color = color
}
}
Loading

0 comments on commit 2469249

Please sign in to comment.