Skip to content

Commit

Permalink
add check if server notification app is installed for current user
Browse files Browse the repository at this point in the history
Signed-off-by: Marcel Hibbe <[email protected]>
  • Loading branch information
mahibi committed Nov 25, 2024
1 parent 98c7a9c commit 096b361
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1522,8 +1522,11 @@ class ConversationsListActivity :
val messagesChannelNotEnabled = !NotificationUtils.isMessagesNotificationChannelEnabled(this)
val callsChannelNotEnabled = !NotificationUtils.isCallsNotificationChannelEnabled(this)

val serverNotificationAppInstalled =
userManager.currentUser.blockingGet().capabilities?.notificationsCapability?.features?.isNotEmpty() ?: false

val settingsOfUserAreWrong = notificationPermissionNotGranted || batteryOptimizationNotIgnored ||
messagesChannelNotEnabled || callsChannelNotEnabled
messagesChannelNotEnabled || callsChannelNotEnabled || !serverNotificationAppInstalled

val userWantsToBeNotifiedAboutWrongSettings = appPreferences.getShowNotificationWarning()

Expand Down
20 changes: 20 additions & 0 deletions app/src/main/java/com/nextcloud/talk/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
private fun setupNotificationSettings() {
setupNotificationSoundsSettings()
setupNotificationPermissionSettings()
setupServerNotificationAppCheck()
}

@SuppressLint("StringFormatInvalid")
Expand Down Expand Up @@ -476,6 +477,24 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
}
}

private fun setupServerNotificationAppCheck() {
val serverNotificationAppInstalled =
userManager.currentUser.blockingGet().capabilities?.notificationsCapability?.features?.isNotEmpty() ?: false
if (!serverNotificationAppInstalled) {
binding.settingsServerNotificationAppWrapper.visibility = View.VISIBLE

val description = context.getString(R.string.nc_settings_contact_admin_of) + LINEBREAK +
userManager.currentUser.blockingGet().baseUrl!!

binding.settingsServerNotificationAppDescription.text = description
if (openedByNotificationWarning) {
blinkRipple(binding.settingsServerNotificationAppWrapper.background)
}
} else {
binding.settingsServerNotificationAppWrapper.visibility = View.GONE
}
}

private fun setupSourceCodeUrl() {
if (!TextUtils.isEmpty(resources!!.getString(R.string.nc_source_code_url))) {
binding.settingsSourceCode.setOnClickListener {
Expand Down Expand Up @@ -1421,6 +1440,7 @@ class SettingsActivity : BaseActivity(), SetPhoneNumberDialogFragment.SetPhoneNu
private const val START_DELAY: Long = 5000
private const val DISABLED_ALPHA: Float = 0.38f
private const val ENABLED_ALPHA: Float = 1.0f
private const val LINEBREAK = "\n"
const val HTTP_CODE_OK: Int = 200
const val HTTP_ERROR_CODE_BAD_REQUEST: Int = 400
}
Expand Down
35 changes: 27 additions & 8 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -311,21 +311,19 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
android:orientation="vertical"
android:padding="@dimen/standard_padding">

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_margin"
android:text="@string/nc_settings_call_ringtone"
android:textSize="@dimen/headline_text_size"/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/calls_ringtone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:text="@string/nc_settings_default_ringtone"
android:textSize="@dimen/supporting_text_text_size"/>
</LinearLayout>
Expand All @@ -335,25 +333,46 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical">
android:orientation="vertical"
android:padding="@dimen/standard_padding">

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/standard_margin"
android:text="@string/nc_settings_other_notifications_ringtone"
android:textSize="@dimen/headline_text_size"/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/messages_ringtone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/standard_margin"
android:layout_marginBottom="@dimen/standard_margin"
android:text="@string/nc_settings_default_ringtone"
android:textSize="@dimen/supporting_text_text_size"/>
</LinearLayout>

<LinearLayout
android:id="@+id/settings_server_notification_app_wrapper"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:orientation="vertical"
android:padding="@dimen/standard_padding">

<com.google.android.material.textview.MaterialTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nc_settings_server_notification_app_not_installed_title"
android:textSize="@dimen/headline_text_size"/>

<com.google.android.material.textview.MaterialTextView
android:id="@+id/settings_server_notification_app_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/nc_darkRed"
android:textSize="@dimen/supporting_text_text_size"
tools:text="Please contact the admin of www.example.com"/>
</LinearLayout>

</LinearLayout>

<LinearLayout
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ How to translate with transifex:
<string name="nc_settings_message_ringtone_key" translatable="false">message_ringtone</string>
<string name="nc_settings_default_ringtone" translatable="false">Librem by feandesign</string>
<string name="nc_settings_no_ringtone">No sound</string>
<string name="nc_settings_server_notification_app_not_installed_title">Server notification app not installed</string>
<string name="nc_settings_contact_admin_of">Please contact the administrator of</string>

<string name="nc_settings_appearance">Appearance</string>
<string name="nc_settings_theme_title">Theme</string>
Expand Down

0 comments on commit 096b361

Please sign in to comment.