Skip to content

Commit

Permalink
Merge pull request #1 from sidsharma2002/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
sidsharma2002 authored Sep 11, 2022
2 parents e19aa1e + 2469249 commit 947cebd
Show file tree
Hide file tree
Showing 22 changed files with 680 additions and 33 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.

51 changes: 46 additions & 5 deletions app/src/main/java/com/example/spinwill/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,22 @@ 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
import com.example.spinwill.utils.Resource
import kotlinx.coroutines.*
Expand All @@ -30,20 +36,55 @@ class MainActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

AppWillRoomDatabase.getInstance(this.applicationContext)
setupDependencies()
// setupWork()
setupUi()
// setupUi()
setupWheelView()
}

private fun setupWheelView() {
val layout = findViewById<FrameLayout>(R.id.frame)
val willView = SpinWillView1<SpinWillItem>(this)
layout.addView(willView)
scope.launch(Dispatchers.IO) {
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 {
return item.rewardText
}

override fun getOverlayText(item: SpinWillItem): String {
return item.rewardText
}

override fun getRewardBitmap(item: SpinWillItem): Bitmap? {
return item.rewardBitmap
}
})
}
}
}
}

private fun setupDependencies() {
// set context, remoteDb, localDb, dao, bitmap load use-case.
injector.init(this, RemoteDatabaseImpl())

val daoConc = SpinWillDaoConc()
daoConc.setDao(AppWillRoomDatabase.getInstance(this.applicationContext).getSpinWillDao())
val daoActions = SpinWillDaoConc()
daoActions.setDao(AppWillRoomDatabase.getInstance(this.applicationContext).getSpinWillDao())
injector.setLocalDatabase(
SpinWillLocalDbImpl(daoConc)
SpinWillLocalDbImpl(daoActions)
)

injector.setBitmapLoadUseCase(
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)
}
}
20 changes: 12 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,27 @@
android:id="@+id/iv_1"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/iv_2"
android:layout_width="200dp"
android:layout_height="200dp"
app:layout_constraintTop_toBottomOf="@id/iv_1"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
app:layout_constraintTop_toBottomOf="@id/iv_1" />

<ProgressBar
android:layout_width="50dp"
android:layout_height="50dp"
<FrameLayout
android:id="@+id/frame"
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_constraintEnd_toEndOf="parent"/>
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
@@ -0,0 +1,11 @@
package com.example.spinwill.models

data class WillDimenProperties(
var paddingLeft: Int = 0,
var paddingRight: Int = 0,
var paddingTop: Int = 0,
var paddingBottom: Int = 0,
var padding: Int = 0,
var radius: Int = 0,
var center: Int = 0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.spinwill.models

import android.graphics.RadialGradient

data class WillGradient(
var darkYellow: RadialGradient? = null,
var lightYellow: RadialGradient? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.example.spinwill.models

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

data class WillPaintProperties(
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
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.example.spinwill.ui.DimenAdapters

import com.example.spinwill.models.WillDimenProperties
import com.example.spinwill.models.WillPaintProperties

interface OffSetDimenAdapter1 {

fun getVOffsetOverLayText(
tempAngle: Float,
sweepAngle: Float,
text: String,
itemsSize: Int,
paintProps: WillPaintProperties,
dimenProps: WillDimenProperties
): Int

fun getHOffsetOverlayText(
tempAngle: Float,
sweepAngle: Float,
text: String,
itemsSize: Int,
paintProps: WillPaintProperties,
dimenProps: WillDimenProperties
): Int
}
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 947cebd

Please sign in to comment.