Use ContextCompat

update_14
Thomas 11 months ago
parent 4a07e7c5b8
commit 9225ec35b5

@ -25,6 +25,7 @@ import android.os.Handler;
import android.os.Looper; import android.os.Looper;
import android.view.View; import android.view.View;
import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import java.io.IOException; import java.io.IOException;
@ -148,11 +149,7 @@ public abstract class PeertubeBaseMainActivity extends BaseActivity implements C
} }
} }
}; };
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(PeertubeBaseMainActivity.this, manage_chromecast, new IntentFilter(Helper.RECEIVE_CAST_SETTINGS), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(manage_chromecast, new IntentFilter(Helper.RECEIVE_CAST_SETTINGS), Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(manage_chromecast, new IntentFilter(Helper.RECEIVE_CAST_SETTINGS));
}
} }
@Override @Override

@ -73,6 +73,7 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.core.app.ActivityCompat; import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat; import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.cursoradapter.widget.CursorAdapter; import androidx.cursoradapter.widget.CursorAdapter;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -1529,13 +1530,8 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt
binding.toolbarSearch.setOnSearchClickListener(v -> binding.tabLayout.setVisibility(View.VISIBLE)); binding.toolbarSearch.setOnSearchClickListener(v -> binding.tabLayout.setVisibility(View.VISIBLE));
//For receiving data from other activities //For receiving data from other activities
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(BaseMainActivity.this, broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), Context.RECEIVER_NOT_EXPORTED); ContextCompat.registerReceiver(BaseMainActivity.this, broadcast_error_message, new IntentFilter(Helper.INTENT_COMPOSE_ERROR_MESSAGE), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(broadcast_error_message, new IntentFilter(Helper.INTENT_COMPOSE_ERROR_MESSAGE), Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
registerReceiver(broadcast_error_message, new IntentFilter(Helper.INTENT_COMPOSE_ERROR_MESSAGE));
}
if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) { if (emojis == null || !emojis.containsKey(BaseMainActivity.currentInstance) || emojis.get(BaseMainActivity.currentInstance) == null) {
new Thread(() -> { new Thread(() -> {
try { try {

@ -734,11 +734,7 @@ public class ComposeActivity extends BaseActivity implements ComposeAdapter.Mana
} }
} }
MastodonHelper.loadPPMastodon(binding.profilePicture, account.mastodon_account); MastodonHelper.loadPPMastodon(binding.profilePicture, account.mastodon_account);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(ComposeActivity.this, imageReceiver, new IntentFilter(Helper.INTENT_SEND_MODIFIED_IMAGE), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(imageReceiver, new IntentFilter(Helper.INTENT_SEND_MODIFIED_IMAGE), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(imageReceiver, new IntentFilter(Helper.INTENT_SEND_MODIFIED_IMAGE));
}
if (timer != null) { if (timer != null) {
timer.scheduleAtFixedRate(new TimerTask() { timer.scheduleAtFixedRate(new TimerTask() {
@Override @Override

@ -140,11 +140,7 @@ public class MediaActivity extends BaseTransparentActivity implements OnDownload
binding.mediaViewpager.setAdapter(mPagerAdapter); binding.mediaViewpager.setAdapter(mPagerAdapter);
binding.mediaViewpager.setSaveEnabled(false); binding.mediaViewpager.setSaveEnabled(false);
binding.mediaViewpager.setCurrentItem(mediaPosition - 1); binding.mediaViewpager.setCurrentItem(mediaPosition - 1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(MediaActivity.this, onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(onDownloadComplete, new IntentFilter(DownloadManager.ACTION_DOWNLOAD_COMPLETE));
}
String description = attachments.get(mediaPosition - 1).description; String description = attachments.get(mediaPosition - 1).description;
handler = new Handler(); handler = new Handler();
if (attachments.get(mediaPosition - 1).status != null) { if (attachments.get(mediaPosition - 1).status != null) {

@ -206,11 +206,7 @@ public class ProfileActivity extends BaseActivity {
} }
//Check if account is homeMuted //Check if account is homeMuted
accountsVM.isMuted(currentAccount, account).observe(this, result -> homeMuted = result != null && result); accountsVM.isMuted(currentAccount, account).observe(this, result -> homeMuted = result != null && result);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(ProfileActivity.this, broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
}
} }

@ -30,6 +30,7 @@ import android.view.MenuItem;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -86,11 +87,7 @@ public class AdminActionActivity extends BaseBarActivity {
setContentView(binding.getRoot()); setContentView(binding.getRoot());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(AdminActionActivity.this, mReceiver, new IntentFilter(Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(mReceiver, new IntentFilter(Helper.BROADCAST_DATA), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(mReceiver, new IntentFilter(Helper.BROADCAST_DATA));
}
if (getSupportActionBar() != null) { if (getSupportActionBar() != null) {
getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayHomeAsUpEnabled(true);
} }

@ -27,6 +27,7 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -197,11 +198,7 @@ public class FragmentMastodonContext extends Fragment {
.observe(getViewLifecycleOwner(), this::initializeContextView); .observe(getViewLifecycleOwner(), this::initializeContextView);
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
}
return binding.getRoot(); return binding.getRoot();
} }

@ -207,11 +207,7 @@ public class FragmentMastodonDirectMessage extends Fragment {
statusCompose.text = binding.text.getText().toString(); statusCompose.text = binding.text.getText().toString();
onSubmit(prepareDraft(statusCompose, MainActivity.currentInstance, MainActivity.currentUserID)); onSubmit(prepareDraft(statusCompose, MainActivity.currentInstance, MainActivity.currentUserID));
}); });
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(requireActivity(), broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
requireActivity().registerReceiver(broadcast_data, new IntentFilter(Helper.BROADCAST_DATA));
}
binding.text.setKeyBoardInputCallbackListener((inputContentInfo, flags, opts) -> { binding.text.setKeyBoardInputCallbackListener((inputContentInfo, flags, opts) -> {
if (inputContentInfo != null) { if (inputContentInfo != null) {
Uri uri = inputContentInfo.getContentUri(); Uri uri = inputContentInfo.getContentUri();

@ -28,6 +28,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -206,13 +207,8 @@ public class FragmentMastodonNotification extends Fragment implements Notificati
} }
aggregateNotification = false; aggregateNotification = false;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), android.content.Context.RECEIVER_NOT_EXPORTED); ContextCompat.registerReceiver(requireActivity(), receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
requireActivity().registerReceiver(receive_refresh, new IntentFilter(Helper.RECEIVE_REFRESH_NOTIFICATIONS_ACTION));
}
return root; return root;
} }

@ -33,6 +33,7 @@ import android.view.ViewGroup;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -454,11 +455,7 @@ public class FragmentMastodonTimeline extends Fragment implements StatusAdapter.
} }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(requireActivity(), receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
requireActivity().registerReceiver(receive_action, new IntentFilter(Helper.RECEIVE_STATUS_ACTION));
}
binding = FragmentPaginationBinding.inflate(inflater, container, false); binding = FragmentPaginationBinding.inflate(inflater, container, false);
return binding.getRoot(); return binding.getRoot();
} }

@ -1591,11 +1591,7 @@ public class PeertubeActivity extends BasePeertubeActivity implements CommentLis
} }
} }
}; };
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(PeertubeActivity.this, mPowerKeyReceiver, theFilter, ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(mPowerKeyReceiver, theFilter, android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(mPowerKeyReceiver, theFilter);
}
} }
private void unregisterReceiver() { private void unregisterReceiver() {

@ -55,6 +55,7 @@ import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.SearchView; import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.TooltipCompat; import androidx.appcompat.widget.TooltipCompat;
import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat; import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
@ -163,11 +164,7 @@ public class PeertubeMainActivity extends PeertubeBaseMainActivity {
binding = super.binding; binding = super.binding;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(PeertubeMainActivity.this, broadcast_data, new IntentFilter(app.fedilab.android.mastodon.helper.Helper.BROADCAST_DATA), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(broadcast_data, new IntentFilter(app.fedilab.android.mastodon.helper.Helper.BROADCAST_DATA), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(broadcast_data, new IntentFilter(app.fedilab.android.mastodon.helper.Helper.BROADCAST_DATA));
}
Intent intentActvity = getIntent(); Intent intentActvity = getIntent();
if (intentActvity != null) { if (intentActvity != null) {

@ -30,6 +30,7 @@ import android.os.Looper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.app.NotificationCompat; import androidx.core.app.NotificationCompat;
import androidx.core.content.ContextCompat;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Objects; import java.util.Objects;
@ -51,11 +52,7 @@ public class RetrieveInfoService extends Service implements NetworkStateReceiver
super.onCreate(); super.onCreate();
networkStateReceiver = new NetworkStateReceiver(); networkStateReceiver = new NetworkStateReceiver();
networkStateReceiver.addListener(this); networkStateReceiver.addListener(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { ContextCompat.registerReceiver(RetrieveInfoService.this, networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION), ContextCompat.RECEIVER_NOT_EXPORTED);
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION), android.content.Context.RECEIVER_NOT_EXPORTED);
} else {
registerReceiver(networkStateReceiver, new IntentFilter(android.net.ConnectivityManager.CONNECTIVITY_ACTION));
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, NotificationChannel channel = new NotificationChannel(NOTIFICATION_CHANNEL_ID,
getString(R.string.notification_channel_name), getString(R.string.notification_channel_name),

Loading…
Cancel
Save