Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve project architecture #330

Merged
merged 1 commit into from
Apr 15, 2024
Merged

Improve project architecture #330

merged 1 commit into from
Apr 15, 2024

Conversation

SuhasDissa
Copy link
Member

@SuhasDissa SuhasDissa commented Apr 10, 2024

.
├── App.kt
├── data
│   └── database
│       ├── AppDatabase.kt
│       ├── dao
│       │   ├── AlarmsDao.kt
│       │   ├── Converters.kt
│       │   └── TimeZonesDao.kt
│       └── DatabaseHolder.kt
├── domain
│   └── model
│       ├── AlarmFilters.kt
│       ├── Alarm.kt
│       ├── CountryTimezone.kt
│       ├── NumberKeypadOperation.kt
│       ├── PersistentTimer.kt
│       ├── ScheduledObject.kt
│       ├── SortOrder.kt
│       ├── TimeObject.kt
│       ├── TimeUnit.kt
│       ├── TimeZone.kt
│       └── WatchState.kt
├── navigation
│   ├── NavContainer.kt
│   ├── NavHost.kt
│   ├── NavRoutes.kt
│   └── TopBarScaffold.kt
├── presentation
│   ├── components
│   │   ├── BlobIconBox.kt
│   │   ├── ClickableIcon.kt
│   │   ├── DialogButton.kt
│   │   ├── DisabledTextField.kt
│   │   ├── SwitchWithDivider.kt
│   │   └── TimePickerDial.kt
│   ├── features
│   │   ├── AlarmReceiverDialog.kt
│   │   ├── RingtonePickerDialog.kt
│   │   └── TimerReceiverDialog.kt
│   ├── screens
│   │   ├── alarm
│   │   │   ├── AlarmActivity.kt
│   │   │   ├── AlarmAlertScreen.kt
│   │   │   ├── AlarmScreen.kt
│   │   │   ├── components
│   │   │   │   ├── AlarmFilterSection.kt
│   │   │   │   ├── AlarmRow.kt
│   │   │   │   ├── AlarmSettingsSheet.kt
│   │   │   │   ├── AlarmTimePicker.kt
│   │   │   │   ├── SnoozeTimePickerDialog.kt
│   │   │   │   └── TimePickerDialog.kt
│   │   │   └── model
│   │   │       └── AlarmModel.kt
│   │   ├── clock
│   │   │   ├── ClockScreen.kt
│   │   │   └── model
│   │   │       └── ClockModel.kt
│   │   ├── settings
│   │   │   ├── components
│   │   │   │   ├── ButtonGroupPref.kt
│   │   │   │   ├── ColorPref.kt
│   │   │   │   ├── IconPreference.kt
│   │   │   │   ├── PreferenceItem.kt
│   │   │   │   ├── SettingsCategory.kt
│   │   │   │   └── SwitchPref.kt
│   │   │   ├── model
│   │   │   │   └── SettingsModel.kt
│   │   │   └── SettingsScreen.kt
│   │   ├── stopwatch
│   │   │   ├── model
│   │   │   │   └── StopwatchModel.kt
│   │   │   └── StopwatchScreen.kt
│   │   └── timer
│   │       ├── components
│   │       │   ├── FormattedTimerTime.kt
│   │       │   ├── KeyboardTimePicker.kt
│   │       │   ├── NumberKeypad.kt
│   │       │   ├── ScrollTimePicker.kt
│   │       │   ├── SingleElementButton.kt
│   │       │   └── TimerItem.kt
│   │       ├── model
│   │       │   ├── RingingToneModel.kt
│   │       │   └── TimerModel.kt
│   │       └── TimerScreen.kt
│   └── widgets
│       ├── AnalogClockWidget.kt
│       ├── DigitalClockWidgetConfig.kt
│       ├── DigitalClockWidget.kt
│       └── VerticalClockWidget.kt
├── ui
│   ├── MainActivity.kt
│   └── theme
│       ├── Color.kt
│       ├── Theme.kt
│       └── Type.kt
└── util
    ├── AlarmHelper.kt
    ├── extensions
    │   ├── AddZero.kt
    │   ├── Context.kt
    │   ├── KeepScreenOn.kt
    │   └── ModifierExtension.kt
    ├── IntentHelper.kt
    ├── NotificationHelper.kt
    ├── PermissionHelper.kt
    ├── PickPersistentFileContract.kt
    ├── Preferences.kt
    ├── receivers
    │   ├── AlarmReceiver.kt
    │   └── BootReceiver.kt
    ├── RingtoneHelper.kt
    ├── services
    │   ├── AlarmService.kt
    │   ├── ScheduleService.kt
    │   ├── StopwatchService.kt
    │   └── TimerService.kt
    ├── ThemeUtil.kt
    ├── TimeHelper.kt
    └── TimezoneHelper.kt

@SuhasDissa
Copy link
Member Author

Proposal: Change project structure to improve code readability and maintenance

Use three main directories to store code according to it's use case

  • data : Databases or any other data sources
  • domain : The link between data source and UI, Store repositories and data classes here
  • presentation : The user presentable parts of the app

Categorize UI components according to screens

  • Use the presentation directory to store all the user presented components.
  • This can be further categorized into:
  • screens : screens with their own navigation destination
  • widgets : home screen widgets
  • components : simple composables that are being used by multiple screens
  • features : more complex composables that can't be considered as screens ( dialogs, bottom sheets)
  • Create directories for each screen and store all the related components and viewmodels under that

This will make it easier to locate components used by each screen

Make the code simple and easy to read

  • Make a screen as simple as possible by dividing it into self explanatory composable functions.
    for example:
@Composable
fun ClockScreen(){
  Column{
      CurrentTimeDisplay()
      WorldClockList()
  }
}
  • Make sure each viewModel is used only by one screen

This will help prevent any unexpected behavior when navigating

  • Avoid passing viewModels into smaller components and use function parameters and callbacks.

Makes it easy to test and preview the components.
Makes the components re-usable


This is what I personally suggest. If you have any other ideas please let me know.
I completed only the first two steps in this PR

@SuhasDissa SuhasDissa changed the title WIP: Improve project architecture Improve project architecture Apr 14, 2024
@SuhasDissa SuhasDissa requested a review from Bnyro April 15, 2024 08:54
@SuhasDissa SuhasDissa merged commit 089285f into main Apr 15, 2024
2 checks passed
@SuhasDissa SuhasDissa deleted the refactor branch April 15, 2024 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants