Skip to content

Commit

Permalink
add wear compact list
Browse files Browse the repository at this point in the history
  • Loading branch information
Razeeman committed Mar 21, 2024
1 parent 53a821d commit 757074d
Show file tree
Hide file tree
Showing 84 changed files with 1,198 additions and 92 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.util.simpletimetracker.domain.interactor

import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.asSharedFlow
import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SettingsDataUpdateInteractor @Inject constructor() {

val dataUpdated: SharedFlow<Unit> get() = _dataUpdated.asSharedFlow()

private val _dataUpdated = MutableSharedFlow<Unit>(
extraBufferCapacity = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST,
)

suspend fun send() {
_dataUpdated.emit(Unit)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import com.example.util.simpletimetracker.core.extension.set
import com.example.util.simpletimetracker.core.model.NavigationTab
import com.example.util.simpletimetracker.feature_base_adapter.ViewHolderType
import com.example.util.simpletimetracker.core.viewData.SettingsBlock
import com.example.util.simpletimetracker.domain.interactor.SettingsDataUpdateInteractor
import com.example.util.simpletimetracker.feature_settings.mapper.SettingsMapper
import com.example.util.simpletimetracker.feature_settings.viewModel.delegate.SettingsAdditionalViewModelDelegate
import com.example.util.simpletimetracker.feature_settings.viewModel.delegate.SettingsBackupViewModelDelegate
Expand All @@ -24,6 +25,7 @@ import com.example.util.simpletimetracker.navigation.Router
import com.example.util.simpletimetracker.navigation.params.screen.DateTimeDialogParams
import com.example.util.simpletimetracker.navigation.params.screen.DateTimeDialogType
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.launch
import javax.inject.Inject

Expand All @@ -40,6 +42,7 @@ class SettingsViewModel @Inject constructor(
private val exportDelegate: SettingsExportViewModelDelegate,
private val translatorsDelegate: SettingsTranslatorsViewModelDelegate,
private val contributorsDelegate: SettingsContributorsViewModelDelegate,
private val settingsDataUpdateInteractor: SettingsDataUpdateInteractor,
) : BaseViewModel(), SettingsParent {

val content: LiveData<List<ViewHolderType>> by lazySuspend { loadContent() }
Expand All @@ -52,6 +55,7 @@ class SettingsViewModel @Inject constructor(
additionalDelegate.init(this)
backupDelegate.init(this)
exportDelegate.init(this)
subscribeToUpdates()
}

override fun onCleared() {
Expand Down Expand Up @@ -267,6 +271,12 @@ class SettingsViewModel @Inject constructor(
content.set(loadContent())
}

private fun subscribeToUpdates() = viewModelScope.launch {
settingsDataUpdateInteractor.dataUpdated.collect {
updateContent()
}
}

private suspend fun loadContent(): List<ViewHolderType> {
val result = mutableListOf<ViewHolderType>()
result += mainDelegate.getViewData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import com.example.util.simpletimetracker.domain.interactor.RecordTagInteractor
import com.example.util.simpletimetracker.domain.interactor.RecordTypeInteractor
import com.example.util.simpletimetracker.domain.interactor.RemoveRunningRecordMediator
import com.example.util.simpletimetracker.domain.interactor.RunningRecordInteractor
import com.example.util.simpletimetracker.domain.interactor.SettingsDataUpdateInteractor
import com.example.util.simpletimetracker.domain.interactor.WidgetInteractor
import com.example.util.simpletimetracker.domain.mapper.AppColorMapper
import com.example.util.simpletimetracker.domain.model.AppColor
import com.example.util.simpletimetracker.domain.model.RecordTag
import com.example.util.simpletimetracker.domain.model.RunningRecord
import com.example.util.simpletimetracker.domain.model.WidgetType
import com.example.util.simpletimetracker.navigation.Router
import com.example.util.simpletimetracker.wear_api.WearActivity
import com.example.util.simpletimetracker.wear_api.WearCommunicationAPI
Expand All @@ -34,6 +37,8 @@ class WearCommunicationInteractor @Inject constructor(
private val addRunningRecordMediator: Lazy<AddRunningRecordMediator>,
private val appColorMapper: AppColorMapper,
private val router: Router,
private val widgetInteractor: WidgetInteractor,
private val settingsDataUpdateInteractor: SettingsDataUpdateInteractor,
) : WearCommunicationAPI {

override suspend fun queryActivities(): List<WearActivity> {
Expand Down Expand Up @@ -99,6 +104,12 @@ class WearCommunicationInteractor @Inject constructor(
)
}

override suspend fun setSettings(settings: WearSettings) {
prefsInteractor.setAllowMultitasking(settings.allowMultitasking)
widgetInteractor.updateWidgets(listOf(WidgetType.QUICK_SETTINGS))
settingsDataUpdateInteractor.send()
}

override suspend fun openPhoneApp() {
router.startApp()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import android.content.Context
import com.example.util.simpletimetracker.wear_api.WearCommunicationAPI
import com.example.util.simpletimetracker.wear_api.WearCurrentActivity
import com.example.util.simpletimetracker.wear_api.WearRequests
import com.example.util.simpletimetracker.wear_api.WearSettings
import com.google.android.gms.tasks.Tasks
import com.google.android.gms.wearable.Wearable
import com.google.gson.Gson
Expand All @@ -34,6 +35,7 @@ class WearRPCServer @Inject constructor(
WearRequests.SET_CURRENT_ACTIVITIES -> onSetCurrentActivities(request)
WearRequests.QUERY_TAGS_FOR_ACTIVITY -> onQueryTagsForActivity(request)
WearRequests.QUERY_SETTINGS -> onQuerySettings()
WearRequests.SET_SETTINGS -> onSetSettings(request)
WearRequests.OPEN_PHONE_APP -> onOpenPhoneApp()
else -> {
Timber.d("$path is an invalid RPC call")
Expand Down Expand Up @@ -90,6 +92,12 @@ class WearRPCServer @Inject constructor(
return mapToBytes(api.querySettings())
}

private suspend fun onSetSettings(request: ByteArray): ByteArray? {
val settings: WearSettings = mapFromBytes(request) ?: return null
api.setSettings(settings)
return ByteArray(0)
}

private suspend fun onOpenPhoneApp(): ByteArray? {
api.openPhoneApp()
return null
Expand Down
1 change: 1 addition & 0 deletions features/feature_wear/src/main/res/values/wear.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<item>/stt/SET_CURRENT_ACTIVITIES</item>
<item>/stt/QUERY_TAGS_FOR_ACTIVITY</item>
<item>/stt/QUERY_SETTINGS</item>
<item>/stt/SET_SETTINGS</item>
<item>/stt/OPEN_PHONE_APP</item>
</string-array>
</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@
<!-- Wear -->
<string name="wear_loading_error">تحقق من اتصالك وحاول مرة أخرى</string>
<string name="wear_open_on_phone">فتح على الهاتف</string>
<string name="wear_settings_title">إعدادات</string>
<string name="wear_settings_title_show_compact_list">عرض القائمة المدمجة</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Exemple:<br/>
<!-- Wear -->
<string name="wear_loading_error">Comprova la teva connexió i torna-ho a provar</string>
<string name="wear_open_on_phone">Obre al telèfon</string>
<string name="wear_settings_title">Configuració</string>
<string name="wear_settings_title_show_compact_list">Mostra la llista compacta</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Beispiel:<br/>
<!-- Wear -->
<string name="wear_loading_error">Überprüfen Sie Ihre Verbindung und versuchen Sie es erneut</string>
<string name="wear_open_on_phone">Am Telefon geöffnet</string>
<string name="wear_settings_title">Einstellungen</string>
<string name="wear_settings_title_show_compact_list">Kompakte Liste anzeigen</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Ejemplo:<br/>
<!-- Wear -->
<string name="wear_loading_error">Comprueba tu conexión y vuelve a intentarlo.</string>
<string name="wear_open_on_phone">Abierto en el teléfono</string>
<string name="wear_settings_title">Ajustes</string>
<string name="wear_settings_title_show_compact_list">Mostrar lista compacta</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-fa/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@
<!-- Wear -->
<string name="wear_loading_error">اتصال خود را بررسی کنید و دوباره امتحان کنید</string>
<string name="wear_open_on_phone">روی گوشی باز کنید</string>
<string name="wear_settings_title">تنظیمات</string>
<string name="wear_settings_title_show_compact_list">نمایش لیست فشرده</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Exemple:<br/>
<!-- Wear -->
<string name="wear_loading_error">Vérifiez votre connexion et réessayez</string>
<string name="wear_open_on_phone">Ouvrir sur téléphone</string>
<string name="wear_settings_title">Paramètres</string>
<string name="wear_settings_title_show_compact_list">Afficher la liste compacte</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ csv फ़ाइल में कॉमा से अलग किए गए य
<!-- Wear -->
<string name="wear_loading_error">अपना कनेक्शन जांचें और पुनः प्रयास करें</string>
<string name="wear_open_on_phone">फ़ोन पर खोलें</string>
<string name="wear_settings_title">समायोजन</string>
<string name="wear_settings_title_show_compact_list">संक्षिप्त सूची दिखाएँ</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-in/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Contoh:<br/>
<!-- Wear -->
<string name="wear_loading_error">Periksa koneksi Anda dan coba lagi</string>
<string name="wear_open_on_phone">Buka di ponsel</string>
<string name="wear_settings_title">Pengaturan</string>
<string name="wear_settings_title_show_compact_list">Tampilkan daftar ringkas</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Esempio:<br/>
<!-- Wear -->
<string name="wear_loading_error">Controlla la connessione e riprova</string>
<string name="wear_open_on_phone">Apri sul telefono</string>
<string name="wear_settings_title">Impostazioni</string>
<string name="wear_settings_title_show_compact_list">Mostra elenco compatto</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ CSV ファイルには、カンマで区切られた次の列が含まれてい
<!-- Wear -->
<string name="wear_loading_error">接続を確認して再試行してください</string>
<string name="wear_open_on_phone">電話で開く</string>
<string name="wear_settings_title">設定</string>
<string name="wear_settings_title_show_compact_list">コンパクトなリストを表示</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ csv 파일은 다음과 같은 열(column)들을 가져야합니다:<br/>
<!-- Wear -->
<string name="wear_loading_error">연결을 확인하고 다시 시도하세요.</string>
<string name="wear_open_on_phone">휴대전화에서 열기</string>
<string name="wear_settings_title">설정</string>
<string name="wear_settings_title_show_compact_list">간략한 목록 표시</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Voorbeeld:<br/>
<!-- Wear -->
<string name="wear_loading_error">Controleer uw verbinding en probeer het opnieuw</string>
<string name="wear_open_on_phone">Openen op telefoon</string>
<string name="wear_settings_title">Instellingen</string>
<string name="wear_settings_title_show_compact_list">Toon compacte lijst</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-pt-rPT/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Exemplo:<br/>
<!-- Wear -->
<string name="wear_loading_error">Verifique sua conexão e tente novamente</string>
<string name="wear_open_on_phone">Abra no telefone</string>
<string name="wear_settings_title">Configurações</string>
<string name="wear_settings_title_show_compact_list">Mostrar lista compacta</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Exemplo:<br/>
<!-- Wear -->
<string name="wear_loading_error">Verifique sua conexão e tente novamente</string>
<string name="wear_open_on_phone">Abra no telefone</string>
<string name="wear_settings_title">Configurações</string>
<string name="wear_settings_title_show_compact_list">Mostrar lista compacta</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ CSV-файл должен содержать следующие столбцы,
<!-- Wear -->
<string name="wear_loading_error">Проверьте подключение и повторите попытку.</string>
<string name="wear_open_on_phone">Открыть на телефоне</string>
<string name="wear_settings_title">Настройки</string>
<string name="wear_settings_title_show_compact_list">Показать компактный список</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-sv/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Exempel:<br/>
<!-- Wear -->
<string name="wear_loading_error">Kontrollera din anslutning och försök igen</string>
<string name="wear_open_on_phone">Öppna på telefonen</string>
<string name="wear_settings_title">inställningar</string>
<string name="wear_settings_title_show_compact_list">Visa kompakt lista</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-tr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ CSV dosyası virgülle ayrılmış şu sütunları içermelidir:<br/>
<!-- Wear -->
<string name="wear_loading_error">Bağlantınızı kontrol edip tekrar deneyin</string>
<string name="wear_open_on_phone">Telefonda aç</string>
<string name="wear_settings_title">Ayarlar</string>
<string name="wear_settings_title_show_compact_list">Kompakt listeyi göster</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@
<!-- Wear -->
<string name="wear_loading_error">Перевірте підключення та повторіть спробу</string>
<string name="wear_open_on_phone">Відкрити на телефоні</string>
<string name="wear_settings_title">Налаштування</string>
<string name="wear_settings_title_show_compact_list">Показати компактний список</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-vi/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Ví dụ:<br/>
<!-- Wear -->
<string name="wear_loading_error">Kiểm tra kết nối của bạn và thử lại</string>
<string name="wear_open_on_phone">Mở trên điện thoại</string>
<string name="wear_settings_title">Cài đặt</string>
<string name="wear_settings_title_show_compact_list">Hiển thị danh sách thu gọn</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ csv 文件必須包含以逗號分隔的這些列:<br/>
<!-- Wear -->
<string name="wear_loading_error">檢查您的連線並重試</string>
<string name="wear_open_on_phone">在手機上打開</string>
<string name="wear_settings_title">設定</string>
<string name="wear_settings_title_show_compact_list">顯示緊湊列表</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ csv 文件必须包含以逗号分隔的这些列:<br/>
<!-- Wear -->
<string name="wear_loading_error">检查您的连接并重试</string>
<string name="wear_open_on_phone">在手机上打开</string>
<string name="wear_settings_title">设置</string>
<string name="wear_settings_title_show_compact_list">显示紧凑列表</string>

</resources>
2 changes: 2 additions & 0 deletions resources/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -489,5 +489,7 @@ Example:<br/>
<!-- Wear -->
<string name="wear_loading_error">Check your connection and try again</string>
<string name="wear_open_on_phone">Open on phone</string>
<string name="wear_settings_title">Settings</string>
<string name="wear_settings_title_show_compact_list">Show compact list</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import androidx.wear.watchface.complications.datasource.SuspendingComplicationDa
import com.example.util.simpletimetracker.R
import com.example.util.simpletimetracker.data.WearDataRepo
import com.example.util.simpletimetracker.data.WearIconMapper
import com.example.util.simpletimetracker.domain.WearActivityIcon
import com.example.util.simpletimetracker.domain.model.WearActivityIcon
import com.example.util.simpletimetracker.utils.getMainStartIntent
import dagger.hilt.android.AndroidEntryPoint
import java.time.Instant
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import android.view.LayoutInflater
import android.widget.FrameLayout
import androidx.core.view.isVisible
import com.example.util.simpletimetracker.databinding.WearIconViewLayoutBinding
import com.example.util.simpletimetracker.domain.WearActivityIcon
import com.example.util.simpletimetracker.domain.model.WearActivityIcon

class WearIconView @JvmOverloads constructor(
context: Context,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
package com.example.util.simpletimetracker.data

import android.content.Context
import android.content.SharedPreferences
import com.example.util.simpletimetracker.domain.repo.WearPrefsRepo
import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
interface WearDataModule {

@Binds
@Singleton
fun WearPrefsRepoImpl.bindPrefsRepo(): WearPrefsRepo

companion object {
private const val PREFS_NAME = "prefs_simple_time_tracker_wear"

@Provides
@Singleton
fun getSharedPrefs(@ApplicationContext context: Context): SharedPreferences {
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
}
}
}
Loading

0 comments on commit 757074d

Please sign in to comment.