Skip to content

Commit

Permalink
Revamped the Settings Screen UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aritra-tech committed Jul 29, 2023
1 parent 1dd6e7c commit 21f59c3
Show file tree
Hide file tree
Showing 11 changed files with 161 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import com.aritra.notify.R
fun SettingsComponent(
modifier: Modifier = Modifier,
settingHeaderText: String,
settingText: String,
painterResourceID: Int,
clickable: () -> Unit
) {
Expand All @@ -51,33 +50,25 @@ fun SettingsComponent(
.padding(12.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Icon(
painter = painterResource(painterResourceID),
contentDescription = stringResource(R.string.icon),
modifier = modifier.size(30.dp),
)
Column(
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.Start,
modifier = modifier
.padding(10.dp)
modifier = modifier.padding(10.dp)
) {
Text(
text = settingHeaderText,
fontSize = 20.sp,
fontFamily = FontFamily(Font(R.font.poppins_semibold))
)

Text(
text = settingText,
fontSize = 12.sp,
fontFamily = FontFamily(Font(R.font.poppins_light))
)
}
Icon(
painter = painterResource(painterResourceID),
contentDescription = stringResource(R.string.icon),
modifier = modifier
.size(35.dp),
tint = MaterialTheme.colorScheme.primary
)

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BackupRepository(
provider.close()

context.contentResolver.openOutputStream(uri)?.use { stream ->
context.getDatabasePath(Const.NAME).inputStream().copyTo(stream)
context.getDatabasePath(Const.DB_NAME).inputStream().copyTo(stream)
}
}
}
Expand All @@ -35,7 +35,7 @@ class BackupRepository(
provider.close()

context.contentResolver.openInputStream(uri)?.use { stream ->
val dbFile = context.getDatabasePath(Const.NAME)
val dbFile = context.getDatabasePath(Const.DB_NAME)
dbFile?.delete()
stream.copyTo(dbFile.outputStream())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,30 @@ import android.net.Uri
import androidx.activity.compose.rememberLauncherForActivityResult
import androidx.activity.result.contract.ActivityResultContracts
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.OutlinedButton
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.collectAsState
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.contentDescription
import androidx.compose.ui.semantics.semantics
Expand All @@ -48,7 +47,6 @@ import com.aritra.notify.utils.Const
fun SettingsScreen() {
val settingsViewModel = hiltViewModel<SettingsViewModel>()
val context = LocalContext.current
var isDialogShowingState by rememberSaveable { mutableStateOf(false) }
val themeViewModel: ThemeViewModel = hiltViewModel()
val themeState by themeViewModel.themeState.collectAsState()

Expand All @@ -74,8 +72,17 @@ fun SettingsScreen() {
Column(
modifier = Modifier
.fillMaxWidth()
.padding(12.dp)
.padding(14.dp)
) {
/** App Settings. */

Text(
modifier = Modifier.padding(start = 5.dp),
text = "App Settings",
fontSize = 18.sp,
fontFamily = FontFamily(Font(R.font.poppins_medium))
)
Spacer(modifier = Modifier.height(10.dp))
Card(
modifier = Modifier
.clip(RoundedCornerShape(10.dp))
Expand All @@ -88,69 +95,81 @@ fun SettingsScreen() {
.padding(16.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically,
horizontalArrangement = Arrangement.SpaceBetween
) {
Icon(
painter = painterResource(id = R.drawable.moon_icon),
contentDescription = stringResource(R.string.icon),
modifier = Modifier.size(30.dp),
)
Text(
modifier = Modifier.padding(start = 10.dp),
text = stringResource(R.string.dark_mode),
fontSize = 20.sp,
fontFamily = FontFamily(Font(R.font.poppins_semibold))
)
Switch(
modifier = Modifier.semantics { contentDescription = "Theme Switch" },
modifier = Modifier
.semantics { contentDescription = "Theme Switch" }
.padding(start = 120.dp),
checked = themeState.isDarkMode,
onCheckedChange = { themeViewModel.toggleTheme() }
)
}
}

/** Import & Export. **/

Spacer(modifier = Modifier.height(20.dp))
Text(
modifier = Modifier.padding(start = 5.dp),
text = stringResource(R.string.import_export),
fontSize = 18.sp,
fontFamily = FontFamily(Font(R.font.poppins_medium))
)
Spacer(modifier = Modifier.height(5.dp))
SettingsComponent(
settingHeaderText = stringResource(R.string.backup_data),
painterResourceID = R.drawable.backup_icon
) {
exportLauncher.launch(Const.DATABASE_FILE_NAME)
}
SettingsComponent(
settingHeaderText = stringResource(R.string.export_import),
settingText = stringResource(R.string.export_or_import_your_notes_to_a_file),
painterResourceID = R.drawable.history
settingHeaderText = stringResource(R.string.import_data),
painterResourceID = R.drawable.import_icon
) {
// Dialog will open up
isDialogShowingState = true
importLauncher.launch(arrayOf("*/*"))
}

/** Product. **/

Spacer(modifier = Modifier.height(20.dp))
Text(
modifier = Modifier.padding(start = 5.dp),
text = stringResource(R.string.product),
fontSize = 18.sp,
fontFamily = FontFamily(Font(R.font.poppins_medium))
)
SettingsComponent(
settingHeaderText = stringResource(R.string.visit_github),
settingText = stringResource(R.string.notify_is_completely_open_source_have_a_feedback_visit_github),
painterResourceID = R.drawable.github_icon
) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse(Const.GITHUB_URL)
)
context.startActivity(intent)
}
SettingsComponent(
settingHeaderText = stringResource(R.string.request_feature),
painterResourceID = R.drawable.code
) {
val intent = Intent(
Intent.ACTION_VIEW,
Uri.parse("https://github.com/aritra-tech/Notify")
Uri.parse(Const.GITHUB_ISSUE)
)
context.startActivity(intent)
}
}
}
}
if (isDialogShowingState) {
AlertDialog(
onDismissRequest = {
isDialogShowingState = false
},
title = {
Text(stringResource(R.string.export_and_import))
},
text = {
Text(stringResource(R.string.export_or_import_of_your_notes_internally_on_your_phone))
},
confirmButton = {
OutlinedButton(onClick = {
exportLauncher.launch(Const.DATABASE_FILE_NAME)
isDialogShowingState = false
}) {
Text(text = stringResource(R.string.export))
}
},
dismissButton = {
OutlinedButton(onClick = {
importLauncher.launch(arrayOf("*/*"))
isDialogShowingState = false
}) {
Text(text = stringResource(R.string.Import))
}
}
)
}
}
7 changes: 5 additions & 2 deletions app/src/main/java/com/aritra/notify/utils/Const.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package com.aritra.notify.utils
object Const {

const val DATABASE_FILE_NAME = "Notify.db"
const val NAME = "Note_database"
const val DB_NAME = "Note_database"
const val DATE_TIME_FORMAT = "dd MMMM, hh:mm a"
const val DATE_FORMAT = "dd MMMM"
const val TIME_FORMAT = "hh:mm a"
const val CONFIRM_BUTTON = "confirm_button"
const val DISMISS_BUTTON = "dismiss_button"

const val GITHUB_URL = "https://github.com/aritra-tech/Notify"
const val GITHUB_ISSUE = "https://github.com/aritra-tech/Notify/issues"
const val TERMS_AND_CONDITION = "https://www.freeprivacypolicy.com/live/48a09fcc-8451-4a03-acfb-29a0d8b536d5"
const val PRIVACY_POLICY = "https://www.freeprivacypolicy.com/live/e4342ac0-aedf-4b36-9a7c-95900bf66074"
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/backup_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,3L12.197,2.54C12.135,2.513 12.068,2.5 12,2.5C11.932,2.5 11.865,2.513 11.803,2.54L12,3ZM12,21L11.752,21.434C11.828,21.477 11.913,21.5 12,21.5C12.087,21.5 12.172,21.477 12.248,21.434L12,21ZM8.024,18.727L7.775,19.162L8.023,18.728L8.024,18.727ZM11.802,2.54L5.409,5.28L5.803,6.2L12.197,3.46L11.803,2.54H11.802ZM4.5,6.66V13.518H5.5V6.66H4.5ZM7.775,19.162L11.752,21.434L12.248,20.566L8.271,18.293L7.775,19.162ZM12.248,21.434L16.225,19.162L15.729,18.293L11.752,20.566L12.248,21.434ZM19.5,13.518V6.66H18.5V13.52H19.5V13.518ZM18.59,5.281L12.197,2.54L11.803,3.46L18.197,6.2L18.591,5.28L18.59,5.281ZM19.5,6.66C19.5,6.366 19.413,6.078 19.252,5.833C19.09,5.589 18.86,5.396 18.59,5.281L18.197,6.2C18.287,6.239 18.364,6.303 18.418,6.385C18.471,6.466 18.5,6.562 18.5,6.66H19.5ZM16.225,19.162C17.22,18.593 18.047,17.772 18.622,16.781C19.197,15.79 19.5,14.664 19.5,13.518H18.5C18.5,14.488 18.244,15.44 17.757,16.278C17.27,17.117 16.571,17.812 15.729,18.293L16.225,19.162ZM4.5,13.518C4.5,14.664 4.803,15.79 5.378,16.781C5.953,17.772 6.78,18.593 7.775,19.162L8.271,18.293C7.429,17.812 6.73,17.117 6.243,16.278C5.756,15.44 5.5,14.488 5.5,13.518H4.5ZM5.41,5.281C5.14,5.396 4.91,5.589 4.748,5.833C4.587,6.078 4.5,6.366 4.5,6.66H5.5C5.5,6.46 5.62,6.28 5.803,6.2L5.41,5.281Z"
android:fillColor="#000000"/>
</vector>
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/github_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M16,22.027V19.157C16.038,18.68 15.973,18.201 15.811,17.751C15.649,17.301 15.393,16.89 15.06,16.547C18.2,16.197 21.5,15.007 21.5,9.547C21.5,8.151 20.963,6.808 20,5.797C20.456,4.576 20.424,3.225 19.91,2.027C19.91,2.027 18.73,1.677 16,3.507C13.708,2.886 11.292,2.886 9,3.507C6.27,1.677 5.09,2.027 5.09,2.027C4.576,3.225 4.544,4.576 5,5.797C4.03,6.816 3.492,8.17 3.5,9.577C3.5,14.997 6.8,16.187 9.94,16.577C9.611,16.917 9.357,17.322 9.195,17.767C9.033,18.211 8.967,18.685 9,19.157V22.027"
android:strokeLineJoin="round"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M9,20.027C6,21 3.5,20.027 2,17.027"
android:strokeLineJoin="round"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/import_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M6,4H16.59L20,7.41V18C20,18.796 19.684,19.559 19.121,20.121C18.559,20.684 17.796,21 17,21H6C5.204,21 4.441,20.684 3.879,20.121C3.316,19.559 3,18.796 3,18V7C3,6.204 3.316,5.441 3.879,4.879C4.441,4.316 5.204,4 6,4ZM6,5C5.47,5 4.961,5.211 4.586,5.586C4.211,5.961 4,6.47 4,7V18C4,18.53 4.211,19.039 4.586,19.414C4.961,19.789 5.47,20 6,20H17C17.53,20 18.039,19.789 18.414,19.414C18.789,19.039 19,18.53 19,18V7.91L16.09,5H15V10H6V5ZM7,5V9H14V5H7ZM12,12C12.796,12 13.559,12.316 14.121,12.879C14.684,13.441 15,14.204 15,15C15,15.796 14.684,16.559 14.121,17.121C13.559,17.684 12.796,18 12,18C11.204,18 10.441,17.684 9.879,17.121C9.316,16.559 9,15.796 9,15C9,14.204 9.316,13.441 9.879,12.879C10.441,12.316 11.204,12 12,12ZM12,13C11.47,13 10.961,13.211 10.586,13.586C10.211,13.961 10,14.47 10,15C10,15.53 10.211,16.039 10.586,16.414C10.961,16.789 11.47,17 12,17C12.53,17 13.039,16.789 13.414,16.414C13.789,16.039 14,15.53 14,15C14,14.47 13.789,13.961 13.414,13.586C13.039,13.211 12.53,13 12,13Z"
android:fillColor="#000000"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/moon_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M21.63,13.599C21.582,13.551 21.521,13.517 21.455,13.5C21.389,13.484 21.32,13.486 21.255,13.506C19.76,13.958 18.17,13.995 16.656,13.615C15.141,13.235 13.757,12.451 12.653,11.346C11.549,10.242 10.765,8.858 10.385,7.344C10.004,5.829 10.042,4.239 10.494,2.744C10.514,2.679 10.516,2.61 10.5,2.543C10.483,2.477 10.449,2.417 10.401,2.369C10.353,2.32 10.292,2.286 10.226,2.27C10.16,2.253 10.091,2.255 10.026,2.275C8.124,2.859 6.456,4.027 5.257,5.614C3.903,7.419 3.246,9.652 3.406,11.903C3.566,14.154 4.533,16.272 6.128,17.868C7.724,19.464 9.842,20.43 12.093,20.59C14.344,20.75 16.577,20.093 18.382,18.739C19.969,17.54 21.136,15.871 21.719,13.97C21.739,13.906 21.741,13.837 21.725,13.772C21.709,13.707 21.677,13.648 21.63,13.599ZM17.934,18.143C16.274,19.393 14.217,20.001 12.144,19.856C10.07,19.71 8.119,18.82 6.649,17.351C5.179,15.881 4.29,13.93 4.144,11.856C3.999,9.783 4.607,7.726 5.857,6.066C6.819,4.793 8.112,3.809 9.595,3.22C9.256,4.759 9.309,6.359 9.751,7.872C10.193,9.385 11.009,10.762 12.123,11.877C13.238,12.991 14.615,13.807 16.128,14.249C17.641,14.691 19.241,14.744 20.78,14.405C20.191,15.888 19.207,17.181 17.934,18.143Z"
android:fillColor="#000000"/>
</vector>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/policy.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M12,22C9.683,21.417 7.771,20.087 6.262,18.012C4.753,15.937 3.999,13.633 4,11.1V5L12,2L20,5V11.1C20,13.633 19.246,15.938 17.737,18.013C16.228,20.088 14.316,21.417 12,22ZM12,14C12.55,14 13.021,13.804 13.413,13.412C13.805,13.02 14.001,12.549 14,12C14,11.45 13.804,10.979 13.412,10.587C13.02,10.195 12.549,9.999 12,10C11.45,10 10.979,10.196 10.587,10.588C10.195,10.98 9.999,11.451 10,12C10,12.55 10.196,13.021 10.588,13.413C10.98,13.805 11.451,14.001 12,14ZM12,19.9C12.75,19.667 13.442,19.325 14.075,18.875C14.708,18.425 15.283,17.883 15.8,17.25L14,15.45C13.7,15.633 13.379,15.771 13.037,15.863C12.695,15.955 12.349,16.001 12,16C10.9,16 9.958,15.608 9.175,14.825C8.392,14.042 8,13.1 8,12C8,10.9 8.392,9.958 9.175,9.175C9.958,8.392 10.9,8 12,8C13.1,8 14.042,8.392 14.825,9.175C15.608,9.958 16,10.9 16,12C16,12.367 15.954,12.721 15.862,13.063C15.77,13.405 15.633,13.734 15.45,14.05L16.925,15.525C17.258,14.858 17.521,14.154 17.713,13.412C17.905,12.67 18.001,11.899 18,11.1V6.375L12,4.125L6,6.375V11.1C6,13.117 6.567,14.95 7.7,16.6C8.833,18.25 10.267,19.35 12,19.9Z"
android:fillColor="#000000"/>
</vector>
20 changes: 20 additions & 0 deletions app/src/main/res/drawable/terms_conditions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M8,10H16M8,18H16M8,14H12M4,21.4V2.6C4,2.441 4.063,2.288 4.176,2.176C4.288,2.063 4.441,2 4.6,2H16.252C16.411,2 16.564,2.063 16.676,2.176L19.824,5.324C19.88,5.38 19.924,5.446 19.955,5.519C19.985,5.593 20,5.671 20,5.75V21.4C20,21.479 19.985,21.557 19.954,21.63C19.924,21.702 19.88,21.768 19.824,21.824C19.768,21.88 19.702,21.924 19.63,21.954C19.557,21.985 19.479,22 19.4,22H4.6C4.521,22 4.443,21.985 4.37,21.954C4.298,21.924 4.231,21.88 4.176,21.824C4.12,21.768 4.076,21.702 4.046,21.63C4.016,21.557 4,21.479 4,21.4Z"
android:strokeLineJoin="round"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
<path
android:pathData="M16,2V5.4C16,5.559 16.063,5.712 16.176,5.824C16.288,5.937 16.441,6 16.6,6H20"
android:strokeLineJoin="round"
android:strokeWidth="1.5"
android:fillColor="#00000000"
android:strokeColor="#000000"
android:strokeLineCap="round"/>
</vector>
Loading

0 comments on commit 21f59c3

Please sign in to comment.