Skip to content

Commit ec625ee

Browse files
Merge pull request #26 from TechnourceDeveloper/dev_MainMenu
Add comments in functions and change git repo variable name
2 parents b35d704 + 264097c commit ec625ee

File tree

4 files changed

+44
-10
lines changed

4 files changed

+44
-10
lines changed

app/src/main/java/com/technource/android/preference/PreferenceHelper.kt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@ interface PreferenceHelper {
55
/**
66
Sets the selected language.
77
@param language The language to be set.
8-
*/
8+
*/
99
fun setLanguage(language: String)
1010
/**
1111
Retrieves the selected language.
1212
@return The selected language.
13-
*/
13+
*/
1414
fun getLanguage(): String
1515
/**
1616
Sets the language code for localization purposes.
1717
@param languageCode The language code to be set.
18-
*/
18+
*/
1919
fun setLanguageCode(languageCode: String)
2020
/**
2121
Retrieves the language code for localization.
2222
@return The language code.
23-
*/
23+
*/
2424
fun getLanguageCode(): String
2525
/**
2626
Sets the flag indicating whether the intro screen has been completed.
@@ -42,5 +42,8 @@ interface PreferenceHelper {
4242
@return True if the user is logged in, false otherwise.
4343
*/
4444
fun isLoggedIn(): Boolean
45+
/**
46+
Clears all the stored preferences.
47+
*/
4548
fun clear()
4649
}

app/src/main/java/com/technource/android/ui/settingsModule/DrawerMenuItemAdapter.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,6 @@ class DrawerMenuItemAdapter(private var drawerMenu: List<DrawerMenu>) :
1616
private var rowIndex = 0
1717
private var oldSelectedPosition = 0
1818

19-
fun setOnItemClick(onItemClick: RecyclerviewInterface) {
20-
setOnItemClick = onItemClick
21-
}
22-
2319
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): DrawerMenuViewHolder {
2420
val view =
2521
DrawerMenuItemLayoutBinding.inflate(LayoutInflater.from(parent.context), parent, false)
@@ -74,6 +70,14 @@ class DrawerMenuItemAdapter(private var drawerMenu: List<DrawerMenu>) :
7470
return drawerMenu.size
7571
}
7672

73+
/**
74+
Sets the click listener for the RecyclerView item.
75+
@param onItemClick The click listener to be set.
76+
*/
77+
fun setOnItemClick(onItemClick: RecyclerviewInterface) {
78+
setOnItemClick = onItemClick
79+
}
80+
7781
class DrawerMenuViewHolder(val binding: DrawerMenuItemLayoutBinding) :
7882
RecyclerView.ViewHolder(binding.root)
7983
}

app/src/main/java/com/technource/android/ui/settingsModule/SettingsFragment.kt

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SettingsFragment(private val mActivity: AppCompatActivity) :
5757
5 -> {
5858
// Open the GitHub repository in a browser when "Git Repo" is selected
5959
val uri: Uri =
60-
Uri.parse(Constants.gitRepo) // missing 'http://' will cause crashed
60+
Uri.parse(Constants.GIT_REPO_LINK) // missing 'http://' will cause crashed
6161

6262
val intent = Intent(Intent.ACTION_VIEW, uri)
6363
startActivity(intent)
@@ -84,6 +84,17 @@ class SettingsFragment(private val mActivity: AppCompatActivity) :
8484
binding.logoutBtn.setOnClickListener { openLogoutDialog() }
8585
}
8686

87+
88+
/**
89+
Opens the logout dialog.
90+
The dialog is created using a custom Dialog class and inflated with the logout_dialog.xml layout.
91+
The layout parameters are set to match the parent view.
92+
The dialog is set to be non-cancelable to prevent dismissing it by clicking outside.
93+
Click listeners are set for the "Logout" button, "Cancel" button, and "Close" button.
94+
When the "Logout" button is clicked, the user preferences are cleared, and the user is redirected to the LoginActivity.
95+
The finishAffinity() method is called to finish all activities in the current task.
96+
When the "Cancel" or "Close" button is clicked, the dialog is dismissed.
97+
*/
8798
private fun openLogoutDialog() {
8899
// Create and show the logout dialog
89100
val logoutDialog = Dialog(mActivity)
@@ -104,6 +115,15 @@ class SettingsFragment(private val mActivity: AppCompatActivity) :
104115
logoutDialog.show()
105116
}
106117

118+
119+
/**
120+
Adds data to the menu list in the drawer.
121+
The existing drawerItemList is cleared.
122+
DrawerMenu objects representing the menu items are created and added to the drawerItemList.
123+
Each menu item consists of a title, subtitle, and icon.
124+
The titles and icons are retrieved from resources using string resource IDs and drawable resource IDs.
125+
The subtitle for the "Change Language" menu item is dynamically set based on the language code stored in preferences.
126+
*/
107127
private fun addDataInMenu() {
108128
drawerItemList.clear()
109129
drawerItemList.add(
@@ -151,6 +171,13 @@ class SettingsFragment(private val mActivity: AppCompatActivity) :
151171
drawerItemList.add(DrawerMenu(resources.getString(R.string.more), "", R.drawable.ic_more))
152172
}
153173

174+
/**
175+
Refreshes the drawer menu.
176+
Resets the isChangeLanguageSelected flag to false.
177+
Adds data to the menu items in the drawer.
178+
Notifies the drawerAdapter that the data set has changed.
179+
Updates the text of the logout, deactivate, and delete account TextViews with the corresponding string resources.
180+
*/
154181
private fun refreshDrawer() {
155182
isChangeLanguageSelected = false
156183
addDataInMenu()

app/src/main/java/com/technource/android/utils/Constant.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class Constants {
88
const val LANGUAGE_CODE = "language_code"
99
const val IS_INTRO_SCREEN_DONE = "is_intro_screen_done"
1010
const val IS_LOGGED_IN = "is_logged_in"
11-
const val gitRepo = "https://github.com/TechnourceDeveloper/Android-Kotlin-Boilarplate"
11+
const val GIT_REPO_LINK = "https://github.com/TechnourceDeveloper/Android-Kotlin-Boilarplate"
1212
const val aboutUs = "https://www.technource.com/services/"
1313
const val termsNCondition = "https://www.technource.com/terms-conditions/"
1414
const val privacyPolicy = "https://technource.com/privacy-policy/"

0 commit comments

Comments
 (0)