Skip to content

Commit

Permalink
Update receivers to API34
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesSmartCell committed Nov 30, 2024
1 parent 2432434 commit d5e10c2
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 15 deletions.
26 changes: 22 additions & 4 deletions app/src/main/java/com/alphawallet/app/entity/FinishReceiver.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.alphawallet.app.entity;

import static androidx.core.content.ContextCompat.RECEIVER_NOT_EXPORTED;
import static androidx.core.content.ContextCompat.registerReceiver;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

Expand All @@ -19,12 +23,19 @@ public FinishReceiver(Activity ctx)
{
activity = ctx;
broadcastManager = LocalBroadcastManager.getInstance(ctx);
register();
register(ctx);
}

private void register()
private void register(Activity ctx)
{
broadcastManager.registerReceiver(this, new IntentFilter(C.PRUNE_ACTIVITY));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
registerReceiver(ctx, this, new IntentFilter(C.WALLET_CONNECT_COUNT_CHANGE), RECEIVER_NOT_EXPORTED);
}
else
{
broadcastManager.registerReceiver(this, new IntentFilter(C.PRUNE_ACTIVITY));
}
}

@Override
Expand All @@ -35,6 +46,13 @@ public void onReceive(Context context, Intent intent)

public void unregister()
{
broadcastManager.unregisterReceiver(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
activity.unregisterReceiver(this);
}
else
{
broadcastManager.unregisterReceiver(this);
}
}
}
27 changes: 23 additions & 4 deletions app/src/main/java/com/alphawallet/app/entity/HomeReceiver.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.alphawallet.app.entity;

import static androidx.core.content.ContextCompat.registerReceiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;

import androidx.core.content.ContextCompat;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.alphawallet.app.C;
Expand Down Expand Up @@ -42,17 +46,32 @@ public void onReceive(Context context, Intent intent)
}
}

public void register()
public void register(Context ctx)
{
IntentFilter filter = new IntentFilter();
filter.addAction(C.REQUEST_NOTIFICATION_ACCESS);
filter.addAction(C.BACKUP_WALLET_SUCCESS);
filter.addAction(C.WALLET_CONNECT_REQUEST);
broadcastManager.registerReceiver(this, filter);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
registerReceiver(ctx, this, new IntentFilter(C.WALLET_CONNECT_COUNT_CHANGE), ContextCompat.RECEIVER_NOT_EXPORTED);
}
else
{
broadcastManager.registerReceiver(this, filter);
}
}

public void unregister()
public void unregister(Context ctx)
{
broadcastManager.unregisterReceiver(this);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
ctx.unregisterReceiver(this);
}
else
{
broadcastManager.unregisterReceiver(this);
}
}
}
4 changes: 2 additions & 2 deletions app/src/main/java/com/alphawallet/app/ui/HomeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ protected void onResume()
if (homeReceiver == null)
{
homeReceiver = new HomeReceiver(this, this);
homeReceiver.register();
homeReceiver.register(this);
}
initViews();
}
Expand Down Expand Up @@ -669,7 +669,7 @@ public void onDestroy()
viewModel.onClean();
if (homeReceiver != null)
{
homeReceiver.unregister();
homeReceiver.unregister(this);
homeReceiver = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK;

import static androidx.core.content.ContentProviderCompat.requireContext;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
Expand All @@ -24,7 +23,6 @@

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu;
import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
Expand Down Expand Up @@ -60,6 +58,7 @@ public class WalletConnectSessionActivity extends BaseActivity
{
private final Handler handler = new Handler(Looper.getMainLooper());
private LocalBroadcastManager broadcastManager;
private
WalletConnectViewModel viewModel;
private RecyclerView recyclerView;
private Button btnConnectWallet;
Expand Down Expand Up @@ -246,12 +245,26 @@ public void onSessionDisconnected()

private void startConnectionCheck()
{
broadcastManager.registerReceiver(walletConnectChangeReceiver, new IntentFilter(C.WALLET_CONNECT_COUNT_CHANGE));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
registerReceiver(walletConnectChangeReceiver, new IntentFilter(C.WALLET_CONNECT_COUNT_CHANGE), RECEIVER_NOT_EXPORTED);
}
else
{
broadcastManager.registerReceiver(walletConnectChangeReceiver, new IntentFilter(C.WALLET_CONNECT_COUNT_CHANGE));
}
}

private void stopConnectionCheck()
{
broadcastManager.unregisterReceiver(walletConnectChangeReceiver);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
{
unregisterReceiver(walletConnectChangeReceiver);
}
else
{
broadcastManager.unregisterReceiver(walletConnectChangeReceiver);
}
}

public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.CustomViewHolder>
Expand Down

0 comments on commit d5e10c2

Please sign in to comment.