1
1
package com.cooper.wheellog
2
2
3
+ // import com.yandex.metrica.YandexMetrica
3
4
import android.annotation.SuppressLint
4
5
import android.content.Context
5
6
import android.content.DialogInterface
@@ -22,10 +23,12 @@ import com.cooper.wheellog.databinding.EdittextLayoutBinding
22
23
import com.cooper.wheellog.databinding.PrivacyPolicyBinding
23
24
import com.cooper.wheellog.databinding.UpdatePwmSettingsBinding
24
25
import com.cooper.wheellog.utils.Constants
25
- // import com.yandex.metrica.YandexMetrica
26
26
import com.cooper.wheellog.utils.PermissionsUtil
27
+ import org.koin.core.component.KoinComponent
28
+ import org.koin.core.component.inject
27
29
28
- object DialogHelper {
30
+ object DialogHelper : KoinComponent {
31
+ private val appConfig: AppConfig by inject()
29
32
/* *
30
33
* return false if in App's Battery settings "Not optimized" and true if "Optimizing battery use"
31
34
*/
@@ -53,7 +56,7 @@ object DialogHelper {
53
56
54
57
@SuppressLint(" BatteryLife" )
55
58
fun checkBatteryOptimizationsAndShowAlert (context : Context ) {
56
- if (! WheelLog . AppConfig .detectBatteryOptimization ||
59
+ if (! appConfig .detectBatteryOptimization ||
57
60
Build .VERSION .SDK_INT < Build .VERSION_CODES .M ||
58
61
! isBatteryOptimizations(context)
59
62
) {
@@ -68,11 +71,11 @@ object DialogHelper {
68
71
69
72
fun checkPWMIsSetAndShowAlert (context : Context ) {
70
73
val wd = WheelData .getInstance()
71
- if (! wd.isWheelIsReady || wd.isHardwarePWM || WheelLog . AppConfig . hwPwm || WheelLog . AppConfig .rotationIsSet) {
74
+ if (! wd.isWheelIsReady || wd.isHardwarePWM || appConfig. hwPwm || appConfig .rotationIsSet) {
72
75
return
73
76
}
74
- if (WheelLog . AppConfig . rotationSpeed != 500 && WheelLog . AppConfig .rotationVoltage != 840 ) {
75
- WheelLog . AppConfig .rotationIsSet = true
77
+ if (appConfig. rotationSpeed != 500 && appConfig .rotationVoltage != 840 ) {
78
+ appConfig .rotationIsSet = true
76
79
return
77
80
}
78
81
val inflater: LayoutInflater = LayoutInflater .from(context)
@@ -206,21 +209,21 @@ object DialogHelper {
206
209
.setPositiveButton(android.R .string.ok) { _: DialogInterface ? , _: Int ->
207
210
when (selectedOption) {
208
211
1 -> {
209
- WheelLog . AppConfig .apply {
212
+ appConfig .apply {
210
213
rotationSpeed = binding.seekBarSpeed.progress
211
214
rotationVoltage = binding.seekBarVoltage.progress
212
215
}
213
- WheelLog . AppConfig .rotationIsSet = true
216
+ appConfig .rotationIsSet = true
214
217
}
215
218
2 -> TODO (" доделать как-то Авто" )
216
219
3 -> {
217
220
val temp = templates[templatesBox.selectedItem]
218
221
if (temp != null ) {
219
- WheelLog . AppConfig .apply {
222
+ appConfig .apply {
220
223
rotationSpeed = temp.first
221
224
rotationVoltage = temp.second
222
225
}
223
- WheelLog . AppConfig .rotationIsSet = true
226
+ appConfig .rotationIsSet = true
224
227
}
225
228
}
226
229
}
@@ -230,7 +233,7 @@ object DialogHelper {
230
233
}
231
234
232
235
fun checkAndShowPrivatePolicyDialog (mainActivity : MainActivity ) {
233
- if (WheelLog . AppConfig .privatePolicyAccepted) {
236
+ if (appConfig .privatePolicyAccepted) {
234
237
return
235
238
}
236
239
@@ -259,8 +262,8 @@ object DialogHelper {
259
262
}
260
263
}
261
264
binding.okButton.setOnClickListener {
262
- WheelLog . AppConfig .privatePolicyAccepted = true
263
- WheelLog . AppConfig .yandexMetricaAccepted = binding.agreeWithMetrica.isChecked
265
+ appConfig .privatePolicyAccepted = true
266
+ appConfig .yandexMetricaAccepted = binding.agreeWithMetrica.isChecked
264
267
// YandexMetrica.setStatisticsSending(
265
268
// mainActivity.applicationContext,
266
269
// binding.agreeWithMetrica.isChecked
@@ -276,19 +279,19 @@ object DialogHelper {
276
279
fun showEditProfileName (context : Context ) {
277
280
val inflater: LayoutInflater = LayoutInflater .from(context)
278
281
val binding = EdittextLayoutBinding .inflate(inflater, null , false )
279
- binding.edit.setText(WheelLog . AppConfig .profileName)
282
+ binding.edit.setText(appConfig .profileName)
280
283
AlertDialog .Builder (context)
281
284
.setTitle(context.getText(R .string.profile_name_title))
282
285
.setView(binding.root)
283
286
.setPositiveButton(android.R .string.ok) { _: DialogInterface ? , _: Int ->
284
- WheelLog . AppConfig .profileName = binding.edit.text.toString()
287
+ appConfig .profileName = binding.edit.text.toString()
285
288
}
286
289
.setNegativeButton(android.R .string.cancel) { _: DialogInterface , _: Int -> }
287
290
.show()
288
291
}
289
292
290
293
fun checkAndShowLocationDialog (context : Context ) {
291
- if (WheelLog . AppConfig .useGps) {
294
+ if (appConfig .useGps) {
292
295
val mLocationManager = ContextCompat .getSystemService(
293
296
context,
294
297
LocationManager ::class .java
0 commit comments