-
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.
Implement show Pinned Pairs in App Widget (#100)
* Add dependency * Provide require dependencies * Provide widget * Implement UI of widget * Rename widget * Extract composable * Implement widget action * Ui tweak * Improve widget UI and handle app open action * Remove unused imports * Replace class and mapping value * Update value to display * Fix wrong display item * Improve coding style * Remove unused imports * Improve coding style * Updae size for composable * Update spacing * Display calculators with multiple to amounts * Improve list mapping * Create event handler in widget * Simplify item * Trigger widget * Trigger Navigate to add new pair * Update when launch app * Handle navigate back and persist across instances * Create worker for quick pairs refresh * Update widget * Create worker for rates refresh * Update code * Refactor request creation * Rename class * Improve code for rates refresh * Display app logo * Rename * Use app context instead * Avoid duplicate sending broadcast * Avoid duplicate sending broadcast
- Loading branch information
Showing
17 changed files
with
524 additions
and
13 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
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
27 changes: 27 additions & 0 deletions
27
app/src/main/java/dev/arkbuilders/rate/data/worker/QuickPairsWidgetRefreshWorker.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,27 @@ | ||
package dev.arkbuilders.rate.data.worker | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.work.CoroutineWorker | ||
import androidx.work.WorkerParameters | ||
import dev.arkbuilders.rate.presentation.quick.glancewidget.QuickPairsWidgetReceiver | ||
import timber.log.Timber | ||
|
||
class QuickPairsWidgetRefreshWorker( | ||
params: WorkerParameters, | ||
private val context: Context, | ||
) : CoroutineWorker(context, params) { | ||
override suspend fun doWork(): Result { | ||
Timber.d("Refresh rates work executed") | ||
val intent = | ||
Intent(applicationContext, QuickPairsWidgetReceiver::class.java).apply { | ||
action = QuickPairsWidgetReceiver.PINNED_PAIRS_REFRESH | ||
} | ||
applicationContext.sendBroadcast(intent) | ||
return Result.success() | ||
} | ||
|
||
companion object { | ||
const val NAME = "RatesRefreshWorker" | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/dev/arkbuilders/rate/data/worker/QuickPairsWidgetRefreshWorkerFactory.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,24 @@ | ||
package dev.arkbuilders.rate.data.worker | ||
|
||
import android.content.Context | ||
import androidx.work.ListenableWorker | ||
import androidx.work.WorkerFactory | ||
import androidx.work.WorkerParameters | ||
|
||
class QuickPairsWidgetRefreshWorkerFactory : WorkerFactory() { | ||
override fun createWorker( | ||
appContext: Context, | ||
workerClassName: String, | ||
workerParameters: WorkerParameters, | ||
): ListenableWorker? { | ||
return when (workerClassName) { | ||
QuickPairsWidgetRefreshWorker::class.java.name -> | ||
QuickPairsWidgetRefreshWorker( | ||
params = workerParameters, | ||
context = appContext, | ||
) | ||
|
||
else -> null | ||
} | ||
} | ||
} |
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
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
92 changes: 92 additions & 0 deletions
92
app/src/main/java/dev/arkbuilders/rate/presentation/quick/glancewidget/QuickPairItem.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,92 @@ | ||
package dev.arkbuilders.rate.presentation.quick.glancewidget | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.unit.dp | ||
import androidx.glance.GlanceModifier | ||
import androidx.glance.Image | ||
import androidx.glance.ImageProvider | ||
import androidx.glance.layout.Alignment | ||
import androidx.glance.layout.Column | ||
import androidx.glance.layout.Row | ||
import androidx.glance.layout.Spacer | ||
import androidx.glance.layout.fillMaxWidth | ||
import androidx.glance.layout.padding | ||
import androidx.glance.layout.size | ||
import androidx.glance.layout.width | ||
import androidx.glance.text.FontWeight | ||
import androidx.glance.text.Text | ||
import androidx.glance.text.TextStyle | ||
import androidx.glance.unit.ColorProvider | ||
import dev.arkbuilders.rate.data.CurrUtils | ||
import dev.arkbuilders.rate.domain.model.PinnedQuickPair | ||
import dev.arkbuilders.rate.presentation.theme.ArkColor | ||
import dev.arkbuilders.rate.presentation.utils.IconUtils | ||
|
||
@Composable | ||
fun QuickPairItem( | ||
quick: PinnedQuickPair, | ||
context: Context, | ||
) { | ||
Row( | ||
modifier = GlanceModifier.padding(vertical = 2.dp), | ||
) { | ||
Image( | ||
modifier = GlanceModifier.size(24.dp), | ||
provider = | ||
ImageProvider( | ||
IconUtils.iconForCurrCode( | ||
context, | ||
quick.pair.from, | ||
), | ||
), | ||
contentDescription = null, | ||
) | ||
Column( | ||
modifier = GlanceModifier.padding(start = 8.dp), | ||
verticalAlignment = Alignment.Vertical.CenterVertically, | ||
) { | ||
Text( | ||
text = "${quick.pair.from} to ${quick.pair.to.joinToString( | ||
separator = ", ", | ||
) { it.code }}", | ||
style = | ||
TextStyle( | ||
color = ColorProvider(ArkColor.TextPrimary), | ||
fontWeight = FontWeight.Medium, | ||
), | ||
) | ||
|
||
Text( | ||
text = "${CurrUtils.prepareToDisplay(quick.pair.amount)} ${quick.pair.from} = ", | ||
style = | ||
TextStyle( | ||
color = ColorProvider(ArkColor.TextTertiary), | ||
), | ||
) | ||
for (toAmount in quick.actualTo) { | ||
Row(modifier = GlanceModifier.fillMaxWidth()) { | ||
Image( | ||
modifier = GlanceModifier.size(16.dp), | ||
provider = | ||
ImageProvider( | ||
IconUtils.iconForCurrCode( | ||
context, | ||
toAmount.code, | ||
), | ||
), | ||
contentDescription = null, | ||
) | ||
Spacer(modifier = GlanceModifier.width(4.dp)) | ||
Text( | ||
text = "${CurrUtils.prepareToDisplay(toAmount.value)} ${toAmount.code}", | ||
style = | ||
TextStyle( | ||
color = ColorProvider(ArkColor.TextTertiary), | ||
), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.