Skip to content

Commit

Permalink
Added "Don't show again" checkbox in oCIS accounts warning dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
JuancaG05 committed May 16, 2023
1 parent 312abc7 commit 26ccad5
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
18 changes: 16 additions & 2 deletions owncloudApp/src/main/java/com/owncloud/android/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
import android.widget.CheckBox
import androidx.appcompat.app.AlertDialog
import androidx.core.content.pm.PackageInfoCompat
import com.owncloud.android.presentation.authentication.AccountUtils
Expand Down Expand Up @@ -130,12 +131,23 @@ class MainApp : Application() {

} else {
ReleaseNotesActivity.runIfNeeded(activity)
if (shouldShowDialog(activity)) {

val pref = PreferenceManager.getDefaultSharedPreferences(appContext)
val dontShowAgainDialogPref = pref.getBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, false)
if (!dontShowAgainDialogPref && shouldShowDialog(activity)) {
val checkboxDialog = activity.layoutInflater.inflate(R.layout.checkbox_dialog, null)
val checkbox = checkboxDialog.findViewById<CheckBox>(R.id.checkbox_dialog)
checkbox.setText(R.string.ocis_accounts_warning_checkbox_message)
val builder = AlertDialog.Builder(activity).apply {
setView(checkboxDialog)
setTitle(R.string.ocis_accounts_warning_title)
setMessage(R.string.ocis_accounts_warning_message)
setCancelable(false)
setPositiveButton(R.string.ocis_accounts_warning_button, null)
setPositiveButton(R.string.ocis_accounts_warning_button) { _, _ ->
if (checkbox.isChecked) {
pref.edit().putBoolean(PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG, true).apply()
}
}
}
val alertDialog = builder.create()
alertDialog.show()
Expand Down Expand Up @@ -300,6 +312,8 @@ class MainApp : Application() {

const val PREFERENCE_KEY_LAST_SEEN_VERSION_CODE = "lastSeenVersionCode"

const val PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG = "PREFERENCE_KEY_DONT_SHOW_OCIS_ACCOUNT_WARNING_DIALOG"

/**
* Next methods give access in code to some constants that need to be defined in string resources to be referred
* in AndroidManifest.xml file or other xml resource files; or that need to be easy to modify in build time.
Expand Down
16 changes: 16 additions & 0 deletions owncloudApp/src/main/res/layout/checkbox_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="clip_horizontal"
android:orientation="vertical"
android:padding="@dimen/standard_padding">

<CheckBox
android:id="@+id/checkbox_dialog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Message for the checkbox"/>

</LinearLayout>
1 change: 1 addition & 0 deletions owncloudApp/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,7 @@
<!-- oCIS accounts warning -->
<string name="ocis_accounts_warning_title">oCIS accounts warning</string>
<string name="ocis_accounts_warning_message">Please, remove the account and login again to get the spaces feature</string>
<string name="ocis_accounts_warning_checkbox_message">Don\'t show again</string>
<string name="ocis_accounts_warning_button">Understood</string>

</resources>

0 comments on commit 26ccad5

Please sign in to comment.