Skip to content

Commit

Permalink
Accept group in AddQuickScreen, pass group on new pair from widget
Browse files Browse the repository at this point in the history
  • Loading branch information
mdrlzy committed Sep 20, 2024
1 parent 4e75874 commit d81ae34
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import dev.arkbuilders.rate.presentation.destinations.PortfolioScreenDestination
import dev.arkbuilders.rate.presentation.destinations.QuickScreenDestination
import dev.arkbuilders.rate.presentation.destinations.SettingsScreenDestination
import dev.arkbuilders.rate.presentation.quick.glancewidget.action.AddNewPairAction.Companion.ADD_NEW_PAIR
import dev.arkbuilders.rate.presentation.quick.glancewidget.action.AddNewPairAction.Companion.ADD_NEW_PAIR_GROUP_KEY
import dev.arkbuilders.rate.presentation.ui.AnimatedRateBottomNavigation
import dev.arkbuilders.rate.presentation.ui.ConnectivityOfflineSnackbar
import dev.arkbuilders.rate.presentation.ui.ConnectivityOfflineSnackbarVisuals
Expand All @@ -59,7 +60,9 @@ fun MainScreen() {
val intent = activity?.intent
val createNewPair = intent?.getStringExtra(ADD_NEW_PAIR) ?: ""
if (createNewPair.isNotEmpty()) {
navController.navigate(AddQuickScreenDestination())
val group = intent?.getStringExtra(ADD_NEW_PAIR_GROUP_KEY)
navController.navigate(AddQuickScreenDestination(group = group))
intent?.removeExtra(ADD_NEW_PAIR_GROUP_KEY)
intent?.removeExtra(ADD_NEW_PAIR)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,15 @@ fun AddQuickScreen(
quickPairId: Long? = null,
newCode: CurrencyCode? = null,
reuseNotEdit: Boolean = true,
group: String? = null,
navigator: DestinationsNavigator,
) {
val ctx = LocalContext.current
val viewModel: AddQuickViewModel =
viewModel(
factory =
DIManager.component.addQuickVMFactory()
.create(quickPairId, newCode, reuseNotEdit),
.create(quickPairId, newCode, reuseNotEdit, group),
)

val state by viewModel.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class AddQuickViewModel(
private val quickPairId: Long?,
private val newCode: CurrencyCode?,
private val reuseNotEdit: Boolean,
private val group: String?,
private val quickRepo: QuickRepo,
private val convertUseCase: ConvertWithRateUseCase,
private val codeUseStatRepo: CodeUseStatRepo,
Expand Down Expand Up @@ -105,7 +106,7 @@ class AddQuickViewModel(
newCode?.let {
listOf(AmountStr(newCode, ""))
} ?: state.currencies
state.copy(currencies = currencies, availableGroups = groups)
state.copy(currencies = currencies, availableGroups = groups, group = group)
}
}
}
Expand Down Expand Up @@ -201,8 +202,9 @@ class AddQuickViewModel(

class AddQuickViewModelFactory @AssistedInject constructor(
@Assisted private val quickPairId: Long?,
@Assisted private val newCode: CurrencyCode?,
@Assisted("newCode") private val newCode: CurrencyCode?,
@Assisted private val reuseNotEdit: Boolean,
@Assisted("group") private val group: String?,
private val quickRepo: QuickRepo,
private val codeUseStatRepo: CodeUseStatRepo,
private val convertUseCase: ConvertWithRateUseCase,
Expand All @@ -213,6 +215,7 @@ class AddQuickViewModelFactory @AssistedInject constructor(
quickPairId,
newCode,
reuseNotEdit,
group,
quickRepo,
convertUseCase,
codeUseStatRepo,
Expand All @@ -224,8 +227,9 @@ class AddQuickViewModelFactory @AssistedInject constructor(
interface Factory {
fun create(
quickPairId: Long?,
newCode: CurrencyCode?,
@Assisted("newCode") newCode: CurrencyCode?,
reuseNotEdit: Boolean,
@Assisted("group") group: String?,
): AddQuickViewModelFactory
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,32 @@ import android.content.Intent
import androidx.glance.GlanceId
import androidx.glance.action.ActionParameters
import androidx.glance.appwidget.action.ActionCallback
import androidx.glance.appwidget.state.updateAppWidgetState
import dev.arkbuilders.rate.presentation.MainActivity
import dev.arkbuilders.rate.presentation.quick.glancewidget.QuickPairsWidgetReceiver

class AddNewPairAction : ActionCallback {
override suspend fun onAction(
context: Context,
glanceId: GlanceId,
parameters: ActionParameters,
) {
var group: String? = null

updateAppWidgetState(context, glanceId) { pref ->
group = pref[QuickPairsWidgetReceiver.currentGroupKey]
}
context.startActivity(
Intent(context, MainActivity::class.java).apply {
putExtra(ADD_NEW_PAIR, "ADD_NEW_PAIR")
putExtra(ADD_NEW_PAIR_GROUP_KEY, group)
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
},
)
}

companion object {
const val ADD_NEW_PAIR = "QUICK_PAIRS_WIDGET_NEW_PAIR"
const val ADD_NEW_PAIR_GROUP_KEY = "ADD_NEW_PAIR_GROUP_KEY"
}
}

0 comments on commit d81ae34

Please sign in to comment.