diff --git a/.idea/modules.xml b/.idea/modules.xml index ff6460ae..c801d253 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -2,6 +2,7 @@ + diff --git a/build.gradle b/build.gradle index 85901470..6b5d8df2 100644 --- a/build.gradle +++ b/build.gradle @@ -70,7 +70,7 @@ android { namespace "com.irccloud.android" defaultConfig { - versionCode 354 + versionCode 355 versionName "4.31" minSdkVersion 22 targetSdkVersion 33 diff --git a/src/com/irccloud/android/activity/MainActivity.java b/src/com/irccloud/android/activity/MainActivity.java index 5bc78419..caa99318 100644 --- a/src/com/irccloud/android/activity/MainActivity.java +++ b/src/com/irccloud/android/activity/MainActivity.java @@ -170,6 +170,7 @@ import com.irccloud.android.data.model.Buffer; import com.irccloud.android.data.model.Channel; import com.irccloud.android.data.model.Event; +import com.irccloud.android.data.model.Notification; import com.irccloud.android.data.model.Server; import com.irccloud.android.data.model.User; import com.irccloud.android.fragment.AcceptListFragment; @@ -2277,7 +2278,7 @@ public void onItemClick(AdapterView parent, View view, int position, long id) } try { - if (NetworkConnection.getInstance().session != null && NetworkConnection.getInstance().session.length() > 0) { + if (notificationPermissionsGranted() && NetworkConnection.getInstance().session != null && NetworkConnection.getInstance().session.length() > 0) { FirebaseMessaging.getInstance().getToken().addOnSuccessListener(new OnSuccessListener() { @Override public void onSuccess(@NonNull String s) { @@ -2293,9 +2294,6 @@ public void onSuccess(@NonNull String s) { sendBtn.setEnabled(conn.getState() == NetworkConnection.STATE_CONNECTED && messageTxt.getText().length() > 0); photoBtn.setVisibility(bubble ? View.GONE : View.VISIBLE); IRCCloudLinkMovementMethod.bubble = bubble; - - if(!notificationPermissionsGranted()) - requestNotificationPermissions(REQUEST_NOTIFICATIONS); } CustomTabsServiceConnection mCustomTabsConnection = new CustomTabsServiceConnection() { @@ -3591,6 +3589,8 @@ public void run() { @Override public void run() { recreate(); + if(!notificationPermissionsGranted()) + requestNotificationPermissions(REQUEST_NOTIFICATIONS); } }); } else { @@ -3607,6 +3607,8 @@ public void run() { }); if (launchBid == -1 && server == null && conn != null && conn.getUserInfo() != null) launchBid = conn.getUserInfo().last_selected_bid; + if(!notificationPermissionsGranted()) + requestNotificationPermissions(REQUEST_NOTIFICATIONS); } break; case NetworkConnection.EVENT_STATUSCHANGED: @@ -4361,22 +4363,29 @@ public void onRequestPermissionsResult(int requestCode, String[] permissions, in for(int j = 0; j < grantResults.length; j++) { if(grantResults[j] != PackageManager.PERMISSION_GRANTED) { IRCCloudLog.Log(Log.ERROR, "IRCCloud", "Permission denied: " + permissions[j]); - if(fileUploadTask != null) { - if(fileUploadTask.metadataDialog != null) { - try { - fileUploadTask.metadataDialog.cancel(); - } catch (Exception e) { + if(requestCode == REQUEST_NOTIFICATIONS) { + SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()).edit(); + prefs.putString("notify_type", "0"); + prefs.commit(); + Toast.makeText(this, "Highlight and mention notifications have been disabled", Toast.LENGTH_SHORT).show(); + } else { + if (fileUploadTask != null) { + if (fileUploadTask.metadataDialog != null) { + try { + fileUploadTask.metadataDialog.cancel(); + } catch (Exception e) { + } } + fileUploadTask.cancel(true); + fileUploadTask = null; } - fileUploadTask.cancel(true); - fileUploadTask = null; - } - if(imgurTask != null) { - imgurTask.cancel(true); - imgurTask = null; + if (imgurTask != null) { + imgurTask.cancel(true); + imgurTask = null; + } + Toast.makeText(this, "Upload cancelled: permission denied", Toast.LENGTH_SHORT).show(); } - Toast.makeText(this, "Upload cancelled: permission denied", Toast.LENGTH_SHORT).show(); return; } } @@ -4466,6 +4475,10 @@ private boolean notificationPermissionsGranted() { } private void requestNotificationPermissions(int requestCode) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(IRCCloudApplication.getInstance().getApplicationContext()); + if(Integer.parseInt(prefs.getString("notify_type", "1")) == 0) + return; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.POST_NOTIFICATIONS},