Skip to content

Commit f564274

Browse files
authored
koin (#513)
* koin * фикс тестов * фикс github actions
1 parent 32f56e6 commit f564274

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+1231
-1094
lines changed

.github/workflows/gradle.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,17 @@ jobs:
4949
rm -f ~/.gradle/caches/modules-2/gc.properties
5050
5151
- name: Get APK
52-
uses: actions/upload-artifact@v3.1.1
52+
uses: actions/upload-artifact@v4
5353
with:
5454
name: app-debug
5555
path: app/build/outputs/apk/debug/app-debug.apk
5656

5757
- name: Get wearos APK
58-
uses: actions/upload-artifact@v3.1.1
58+
uses: actions/upload-artifact@v4
5959
with:
6060
name: wearos-debug
6161
path: wearos/build/outputs/apk/debug/wearos-debug.apk
62+
retention-days: 5
6263

6364
- name: Send apk to telegram
6465
env:

app/build.gradle

+6
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ dependencies {
157157
// coroutines
158158
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.1'
159159
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.10.1'
160+
161+
// koin
162+
implementation platform("io.insert-koin:koin-bom:4.0.2")
163+
implementation 'io.insert-koin:koin-android'
164+
implementation 'io.insert-koin:koin-androidx-compose'
160165
// AppMetrica SDK.
161166
// implementation ('com.yandex.android:mobmetricalib:5.3.0') {
162167
// exclude group: 'com.yandex.android', module: 'mobmetricalib-identifiers'
@@ -171,4 +176,5 @@ dependencies {
171176
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
172177
testImplementation 'com.squareup.okhttp3:mockwebserver:4.12.0'
173178
testImplementation 'org.json:json:20241224'
179+
testImplementation "io.insert-koin:koin-test-junit4:4.0.2"
174180
}

app/src/main/java/com/cooper/wheellog/AppConfig.kt

+10-4
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,20 @@ import android.net.Uri
66
import androidx.appcompat.app.AppCompatDelegate.MODE_NIGHT_UNSPECIFIED
77
import androidx.preference.PreferenceManager
88
import com.cooper.wheellog.utils.MiBandEnum
9+
import com.cooper.wheellog.utils.NotificationUtil
910
import com.cooper.wheellog.utils.ThemeEnum
11+
import com.cooper.wheellog.utils.VolumeKeyController
1012
import com.wheellog.shared.Constants
1113
import com.wheellog.shared.WearPage
1214
import com.wheellog.shared.WearPages
15+
import org.koin.core.component.KoinComponent
16+
import org.koin.core.component.inject
1317
// import com.yandex.metrica.YandexMetrica
1418
import timber.log.Timber
1519

16-
class AppConfig(var context: Context) {
20+
class AppConfig(var context: Context): KoinComponent {
21+
private val notifications: NotificationUtil by inject()
22+
private val volumeKeyController: VolumeKeyController by inject()
1723
private val sharedPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
1824
private var specificPrefix: String = ""
1925
private val separator = ";"
@@ -101,7 +107,7 @@ class AppConfig(var context: Context) {
101107
get() = getValue(R.string.notification_buttons, null)
102108
set(value) {
103109
setValue(R.string.notification_buttons, value)
104-
WheelLog.Notifications.update()
110+
notifications.update()
105111
}
106112

107113
var notificationButtons: Array<String>
@@ -156,7 +162,7 @@ class AppConfig(var context: Context) {
156162
get() = getValue(R.string.beep_on_volume_up, false)
157163
set(value) {
158164
setValue(R.string.beep_on_volume_up, value)
159-
WheelLog.VolumeKeyController.setActive(wd.isConnected && value)
165+
volumeKeyController.setActive(wd.isConnected && value)
160166
}
161167

162168
var beepByWheel: Boolean
@@ -282,7 +288,7 @@ class AppConfig(var context: Context) {
282288
get() = getValue(R.string.miband_fixrs_enable, false)
283289
set(value) {
284290
setValue(R.string.miband_fixrs_enable, value)
285-
WheelLog.Notifications.updateKostilTimer()
291+
notifications.updateKostilTimer()
286292
}
287293

288294
var wearOsPages: WearPages

app/src/main/java/com/cooper/wheellog/BluetoothService.kt

+11-8
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import com.cooper.wheellog.utils.Constants.WHEEL_TYPE
1010
import com.cooper.wheellog.utils.SomeUtil.playSound
1111
import com.cooper.wheellog.utils.StringUtil.toHexStringRaw
1212
import com.welie.blessed.*
13+
import org.koin.android.ext.android.inject
1314
import timber.log.Timber
1415
import java.text.SimpleDateFormat
1516
import java.util.*
1617

1718
class BluetoothService: Service() {
19+
private val appConfig: AppConfig by inject()
20+
private val notifications: NotificationUtil by inject()
1821
private var mDisconnectTime: Date? = null
1922
private val wheelConnection: BluetoothPeripheral?
2023
get() = if (wheelAddress.isNotEmpty() && BluetoothAdapter.checkBluetoothAddress(wheelAddress)) {
@@ -65,8 +68,8 @@ class BluetoothService: Service() {
6568

6669
override fun onConnectedPeripheral(peripheral: BluetoothPeripheral) {
6770
super.onConnectedPeripheral(peripheral)
68-
val connectionSound = WheelLog.AppConfig.connectionSound
69-
val noConnectionSound = WheelLog.AppConfig.noConnectionSound * 1000
71+
val connectionSound = appConfig.connectionSound
72+
val noConnectionSound = appConfig.noConnectionSound * 1000
7073
if (connectionSound) {
7174
if (noConnectionSound > 0) {
7275
stopBeepTimer()
@@ -93,8 +96,8 @@ class BluetoothService: Service() {
9396
mDisconnectTime = Calendar.getInstance().time
9497
if (!disconnectRequested && wheelAddress.isNotEmpty()) {
9598
Timber.i("Trying to reconnect")
96-
val connectionSound = WheelLog.AppConfig.connectionSound
97-
val noConnectionSound = WheelLog.AppConfig.noConnectionSound * 1000
99+
val connectionSound = appConfig.connectionSound
100+
val noConnectionSound = appConfig.noConnectionSound * 1000
98101
if (connectionSound) {
99102
playSound(applicationContext, R.raw.sound_disconnect)
100103
if (wl?.isHeld == true) {
@@ -198,7 +201,7 @@ class BluetoothService: Service() {
198201

199202
private fun readData(characteristic: BluetoothGattCharacteristic, value: ByteArray) {
200203
// RAW data
201-
if (WheelLog.AppConfig.enableRawData) {
204+
if (appConfig.enableRawData) {
202205
if (fileUtilRawData == null) {
203206
fileUtilRawData = FileUtil(applicationContext)
204207
}
@@ -298,8 +301,8 @@ class BluetoothService: Service() {
298301

299302
override fun onBind(p0: Intent?): IBinder {
300303
mgr = this.getSystemService(POWER_SERVICE) as PowerManager
301-
startForeground(Constants.MAIN_NOTIFICATION_ID, WheelLog.Notifications.notification)
302-
if (WheelLog.AppConfig.useReconnect) {
304+
startForeground(Constants.MAIN_NOTIFICATION_ID, notifications.notification)
305+
if (appConfig.useReconnect) {
303306
startReconnectTimer()
304307
}
305308
Timber.i("BluetoothService is started.")
@@ -540,7 +543,7 @@ class BluetoothService: Service() {
540543
acquire(5 * 60 * 1000L /*5 minutes*/)
541544
}
542545
timerTicks = 0
543-
val noConnectionSound = WheelLog.AppConfig.noConnectionSound * 1000
546+
val noConnectionSound = appConfig.noConnectionSound * 1000
544547
val beepTimerTask: TimerTask = object : TimerTask() {
545548
override fun run() {
546549
timerTicks++

app/src/main/java/com/cooper/wheellog/DeviceListAdapter.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,14 @@
1010

1111
import androidx.appcompat.app.AppCompatActivity;
1212

13+
import org.koin.core.component.KoinComponent;
14+
import org.koin.java.KoinJavaComponent;
15+
1316
import java.util.ArrayList;
1417

1518
// Adapter for holding devices found through scanning.
1619
public class DeviceListAdapter extends BaseAdapter {
20+
private final AppConfig appConfig = KoinJavaComponent.get(AppConfig.class);
1721
private final ArrayList<BluetoothDevice> mLeDevices;
1822
private final ArrayList<String> mLeAdvDatas;
1923
private final LayoutInflater mInflator;
@@ -31,7 +35,7 @@ public DeviceListAdapter(AppCompatActivity appCompatActivity) {
3135
}
3236

3337
public void addDevice(BluetoothDevice device, String advData) {
34-
if (!WheelLog.AppConfig.getShowUnknownDevices()) {
38+
if (!appConfig.getShowUnknownDevices()) {
3539
@SuppressLint("MissingPermission")
3640
String deviceName = device.getName();
3741
if (deviceName == null || deviceName.length() == 0)

app/src/main/java/com/cooper/wheellog/DialogHelper.kt

+19-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.cooper.wheellog
22

3+
//import com.yandex.metrica.YandexMetrica
34
import android.annotation.SuppressLint
45
import android.content.Context
56
import android.content.DialogInterface
@@ -22,10 +23,12 @@ import com.cooper.wheellog.databinding.EdittextLayoutBinding
2223
import com.cooper.wheellog.databinding.PrivacyPolicyBinding
2324
import com.cooper.wheellog.databinding.UpdatePwmSettingsBinding
2425
import com.cooper.wheellog.utils.Constants
25-
//import com.yandex.metrica.YandexMetrica
2626
import com.cooper.wheellog.utils.PermissionsUtil
27+
import org.koin.core.component.KoinComponent
28+
import org.koin.core.component.inject
2729

28-
object DialogHelper {
30+
object DialogHelper : KoinComponent {
31+
private val appConfig: AppConfig by inject()
2932
/**
3033
* return false if in App's Battery settings "Not optimized" and true if "Optimizing battery use"
3134
*/
@@ -53,7 +56,7 @@ object DialogHelper {
5356

5457
@SuppressLint("BatteryLife")
5558
fun checkBatteryOptimizationsAndShowAlert(context: Context) {
56-
if (!WheelLog.AppConfig.detectBatteryOptimization ||
59+
if (!appConfig.detectBatteryOptimization ||
5760
Build.VERSION.SDK_INT < Build.VERSION_CODES.M ||
5861
!isBatteryOptimizations(context)
5962
) {
@@ -68,11 +71,11 @@ object DialogHelper {
6871

6972
fun checkPWMIsSetAndShowAlert(context: Context) {
7073
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) {
7275
return
7376
}
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
7679
return
7780
}
7881
val inflater: LayoutInflater = LayoutInflater.from(context)
@@ -206,21 +209,21 @@ object DialogHelper {
206209
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
207210
when (selectedOption) {
208211
1 -> {
209-
WheelLog.AppConfig.apply {
212+
appConfig.apply {
210213
rotationSpeed = binding.seekBarSpeed.progress
211214
rotationVoltage = binding.seekBarVoltage.progress
212215
}
213-
WheelLog.AppConfig.rotationIsSet = true
216+
appConfig.rotationIsSet = true
214217
}
215218
2 -> TODO("доделать как-то Авто")
216219
3 -> {
217220
val temp = templates[templatesBox.selectedItem]
218221
if (temp != null) {
219-
WheelLog.AppConfig.apply {
222+
appConfig.apply {
220223
rotationSpeed = temp.first
221224
rotationVoltage = temp.second
222225
}
223-
WheelLog.AppConfig.rotationIsSet = true
226+
appConfig.rotationIsSet = true
224227
}
225228
}
226229
}
@@ -230,7 +233,7 @@ object DialogHelper {
230233
}
231234

232235
fun checkAndShowPrivatePolicyDialog(mainActivity: MainActivity) {
233-
if (WheelLog.AppConfig.privatePolicyAccepted) {
236+
if (appConfig.privatePolicyAccepted) {
234237
return
235238
}
236239

@@ -259,8 +262,8 @@ object DialogHelper {
259262
}
260263
}
261264
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
264267
// YandexMetrica.setStatisticsSending(
265268
// mainActivity.applicationContext,
266269
// binding.agreeWithMetrica.isChecked
@@ -276,19 +279,19 @@ object DialogHelper {
276279
fun showEditProfileName(context: Context) {
277280
val inflater: LayoutInflater = LayoutInflater.from(context)
278281
val binding = EdittextLayoutBinding.inflate(inflater, null, false)
279-
binding.edit.setText(WheelLog.AppConfig.profileName)
282+
binding.edit.setText(appConfig.profileName)
280283
AlertDialog.Builder(context)
281284
.setTitle(context.getText(R.string.profile_name_title))
282285
.setView(binding.root)
283286
.setPositiveButton(android.R.string.ok) { _: DialogInterface?, _: Int ->
284-
WheelLog.AppConfig.profileName = binding.edit.text.toString()
287+
appConfig.profileName = binding.edit.text.toString()
285288
}
286289
.setNegativeButton(android.R.string.cancel) { _: DialogInterface, _: Int -> }
287290
.show()
288291
}
289292

290293
fun checkAndShowLocationDialog(context: Context) {
291-
if (WheelLog.AppConfig.useGps) {
294+
if (appConfig.useGps) {
292295
val mLocationManager = ContextCompat.getSystemService(
293296
context,
294297
LocationManager::class.java

0 commit comments

Comments
 (0)