- improve starting speed & responsiveness

pull/3354/head
James Brown 9 months ago
parent 8e29fa68e8
commit 7959f93bb1
  1. 1
      app/src/main/java/com/alphawallet/app/service/PriceAlertsService.java
  2. 10
      app/src/main/java/com/alphawallet/app/service/TokensService.java
  3. 8
      app/src/main/java/com/alphawallet/app/ui/NFTAssetsFragment.java
  4. 56
      app/src/main/java/com/alphawallet/app/ui/WalletFragment.java
  5. 7
      app/src/main/java/com/alphawallet/app/viewmodel/HomeViewModel.java
  6. 1
      app/src/main/java/com/alphawallet/app/viewmodel/WalletViewModel.java

@ -93,7 +93,6 @@ public class PriceAlertsService extends Service
{ {
tokensService.setCurrentAddress(wallet.address); tokensService.setCurrentAddress(wallet.address);
assetDefinitionService.startEventListener(); assetDefinitionService.startEventListener();
tokensService.startUpdateCycle();
defaultWallet = wallet; defaultWallet = wallet;
} }

@ -232,9 +232,17 @@ public class TokensService
startUpdateCycle(); startUpdateCycle();
} }
public void startUpdateCycleIfRequired()
{
if (eventTimer == null || eventTimer.isDisposed())
{
startUpdateCycle();
}
}
public void startUpdateCycle() public void startUpdateCycle()
{ {
if ((lastStartCycleTime + 1000) > System.currentTimeMillis()) if ((lastStartCycleTime + 2000) > System.currentTimeMillis())
{ {
return; // Block this refresh - we need to ensure the cycle restarts but within 1 second no need to restart return; // Block this refresh - we need to ensure the cycle restarts but within 1 second no need to restart
} }

@ -50,6 +50,7 @@ import java.math.BigInteger;
import java.util.List; import java.util.List;
import dagger.hilt.android.AndroidEntryPoint; import dagger.hilt.android.AndroidEntryPoint;
import timber.log.Timber;
@AndroidEntryPoint @AndroidEntryPoint
public class NFTAssetsFragment extends BaseFragment implements OnAssetClickListener, TokensAdapterCallback { public class NFTAssetsFragment extends BaseFragment implements OnAssetClickListener, TokensAdapterCallback {
@ -187,12 +188,19 @@ public class NFTAssetsFragment extends BaseFragment implements OnAssetClickListe
} }
public void showListView() public void showListView()
{
try
{ {
recyclerView.setLayoutManager(new LinearLayoutManager(requireContext())); recyclerView.setLayoutManager(new LinearLayoutManager(requireContext()));
recyclerView.removeItemDecoration(gridItemDecoration); recyclerView.removeItemDecoration(gridItemDecoration);
recyclerView.setPadding(0, 0, 0, 0); recyclerView.setPadding(0, 0, 0, 0);
initAndAttachAdapter(false); initAndAttachAdapter(false);
} }
catch (Exception e)
{
Timber.e(e);
}
}
private void initAndAttachAdapter(boolean isGridView) private void initAndAttachAdapter(boolean isGridView)
{ {

@ -30,6 +30,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.GridLayoutManager; import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
@ -66,7 +67,6 @@ import com.alphawallet.app.ui.widget.holder.WarningHolder;
import com.alphawallet.app.util.LocaleUtils; import com.alphawallet.app.util.LocaleUtils;
import com.alphawallet.app.viewmodel.WalletViewModel; import com.alphawallet.app.viewmodel.WalletViewModel;
import com.alphawallet.app.walletconnect.AWWalletConnectClient; import com.alphawallet.app.walletconnect.AWWalletConnectClient;
import com.alphawallet.app.widget.AWalletAlertDialog;
import com.alphawallet.app.widget.BuyEthOptionsView; import com.alphawallet.app.widget.BuyEthOptionsView;
import com.alphawallet.app.widget.LargeTitleView; import com.alphawallet.app.widget.LargeTitleView;
import com.alphawallet.app.widget.NotificationView; import com.alphawallet.app.widget.NotificationView;
@ -117,6 +117,7 @@ public class WalletFragment extends BaseFragment implements
private LargeTitleView largeTitleView; private LargeTitleView largeTitleView;
private ActivityResultLauncher<Intent> handleBackupClick; private ActivityResultLauncher<Intent> handleBackupClick;
private ActivityResultLauncher<Intent> tokenManagementLauncher; private ActivityResultLauncher<Intent> tokenManagementLauncher;
private boolean completed = false;
@Inject @Inject
AWWalletConnectClient awWalletConnectClient; AWWalletConnectClient awWalletConnectClient;
@ -210,6 +211,34 @@ public class WalletFragment extends BaseFragment implements
}); });
} }
class CompletionLayoutListener extends LinearLayoutManager
{
public CompletionLayoutListener(Context context)
{
super(context);
}
public CompletionLayoutListener(FragmentActivity activity, int orientation, boolean reverseLayout)
{
super(activity, orientation, reverseLayout);
}
@Override
public void onLayoutCompleted(RecyclerView.State state)
{
super.onLayoutCompleted(state);
final int firstVisibleItemPosition = findFirstVisibleItemPosition();
final int lastVisibleItemPosition = findLastVisibleItemPosition();
int itemsShown = lastVisibleItemPosition - firstVisibleItemPosition + 1;
if (!completed && itemsShown > 1)
{
completed = true;
viewModel.startUpdateListener();
viewModel.getTokensService().startUpdateCycleIfRequired();
}
}
}
private void initList() private void initList()
{ {
adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(), adapter = new TokensAdapter(this, viewModel.getAssetDefinitionService(), viewModel.getTokensService(),
@ -225,7 +254,7 @@ public class WalletFragment extends BaseFragment implements
refreshLayout.setOnRefreshListener(this::refreshList); refreshLayout.setOnRefreshListener(this::refreshList);
recyclerView.addRecyclerListener(holder -> adapter.onRViewRecycled(holder)); recyclerView.addRecyclerListener(holder -> adapter.onRViewRecycled(holder));
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new CompletionLayoutListener(getActivity(), LinearLayoutManager.VERTICAL, false));
} }
private void initViewModel() private void initViewModel()
@ -373,13 +402,17 @@ public class WalletFragment extends BaseFragment implements
public void comeIntoFocus() public void comeIntoFocus()
{ {
isVisible = true; isVisible = true;
if (completed)
{
viewModel.startUpdateListener(); viewModel.startUpdateListener();
viewModel.getTokensService().startUpdateCycle(); viewModel.getTokensService().startUpdateCycleIfRequired();
}
} }
@Override @Override
public void leaveFocus() public void leaveFocus()
{ {
isVisible = false;
viewModel.stopUpdateListener(); viewModel.stopUpdateListener();
softKeyboardGone(); softKeyboardGone();
} }
@ -388,6 +421,10 @@ public class WalletFragment extends BaseFragment implements
public void onPause() public void onPause()
{ {
super.onPause(); super.onPause();
if (isVisible)
{
viewModel.stopUpdateListener();
}
} }
private void initTabLayout(View view) private void initTabLayout(View view)
@ -418,7 +455,7 @@ public class WalletFragment extends BaseFragment implements
case ASSETS: case ASSETS:
case DEFI: case DEFI:
case GOVERNANCE: case GOVERNANCE:
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setLayoutManager(new CompletionLayoutListener(getActivity()));
viewModel.prepare(); viewModel.prepare();
break; break;
case COLLECTIBLES: case COLLECTIBLES:
@ -538,6 +575,12 @@ public class WalletFragment extends BaseFragment implements
largeTitleView.setVisibility(View.VISIBLE); //show or hide Fiat summary largeTitleView.setVisibility(View.VISIBLE); //show or hide Fiat summary
} }
} }
if (isVisible)
{
viewModel.startUpdateListener();
viewModel.getTokensService().startUpdateCycleIfRequired();
}
} }
private void onTokens(TokenCardMeta[] tokens) private void onTokens(TokenCardMeta[] tokens)
@ -550,11 +593,6 @@ public class WalletFragment extends BaseFragment implements
} }
systemView.showProgress(false); systemView.showProgress(false);
if (isVisible)
{
viewModel.startUpdateListener();
}
if (currentTabPos.equals(TokenFilter.ALL)) if (currentTabPos.equals(TokenFilter.ALL))
{ {
awWalletConnectClient.updateNotification(); awWalletConnectClient.updateNotification();

@ -779,13 +779,6 @@ public class HomeViewModel extends BaseViewModel
currencyRepository.setDefaultCurrency(preferenceRepository.getDefaultCurrency()); currencyRepository.setDefaultCurrency(preferenceRepository.getDefaultCurrency());
} }
public void sendMsgPumpToWC(Context context)
{
//NB: WalletConnect v1 has been deprecated
//Timber.d("Start WC service");
//WCUtils.startServiceLocal(context, null, WalletConnectActions.MSG_PUMP);
}
// Restart walletconnect sessions if required // Restart walletconnect sessions if required
private void initWalletConnectSessions(Activity activity, Wallet wallet) private void initWalletConnectSessions(Activity activity, Wallet wallet)
{ {

@ -219,7 +219,6 @@ public class WalletViewModel extends BaseViewModel
tokensService.setCurrentAddress(wallet.address); tokensService.setCurrentAddress(wallet.address);
assetDefinitionService.startEventListener(); assetDefinitionService.startEventListener();
defaultWallet.postValue(wallet); defaultWallet.postValue(wallet);
tokensService.startUpdateCycle();
fetchTokens(wallet); fetchTokens(wallet);
} }

Loading…
Cancel
Save