スワイプしてリフレッシュを修正

This commit is contained in:
ろむねこ 2024-07-12 11:18:19 +09:00
parent 48949d3c60
commit a5dcde0d54
Signed by: Fujimatsu
GPG Key ID: FA1F39A1BA37D168

View File

@ -16,6 +16,7 @@ import one.nem.kidshift.utils.FabManager;
import one.nem.kidshift.utils.KSLogger; import one.nem.kidshift.utils.KSLogger;
import one.nem.kidshift.utils.ToolBarManager; import one.nem.kidshift.utils.ToolBarManager;
import one.nem.kidshift.utils.factory.KSLoggerFactory; import one.nem.kidshift.utils.factory.KSLoggerFactory;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
@AndroidEntryPoint @AndroidEntryPoint
public class WalletContentFragment extends Fragment { public class WalletContentFragment extends Fragment {
@ -38,6 +39,7 @@ public class WalletContentFragment extends Fragment {
private String childId; private String childId;
private TextView totalRewardTextView; private TextView totalRewardTextView;
private SwipeRefreshLayout swipeRefreshLayout;
public WalletContentFragment() { public WalletContentFragment() {
// Required empty public constructor // Required empty public constructor
@ -80,6 +82,13 @@ public class WalletContentFragment extends Fragment {
totalRewardTextView = view.findViewById(R.id.totalRewardTextView); totalRewardTextView = view.findViewById(R.id.totalRewardTextView);
swipeRefreshLayout = view.findViewById(R.id.swipeRefreshLayout);
swipeRefreshLayout.setOnRefreshListener(() -> {
updateTotalReward();
swipeRefreshLayout.setRefreshing(false);
});
return view; return view;
} }
@ -89,9 +98,14 @@ public class WalletContentFragment extends Fragment {
} }
private void updateTotalReward() { private void updateTotalReward() {
swipeRefreshLayout.setRefreshing(true);
rewardData.getTotalReward(childId).thenAccept(totalReward -> { rewardData.getTotalReward(childId).thenAccept(totalReward -> {
logger.debug("Total reward: " + totalReward); logger.debug("Total reward: " + totalReward);
totalRewardTextView.setText(String.valueOf(totalReward) + ""); totalRewardTextView.setText(String.valueOf(totalReward) + "");
}).thenRun(() -> {
requireActivity().runOnUiThread(() -> {
swipeRefreshLayout.setRefreshing(false);
});
}).exceptionally(throwable -> { }).exceptionally(throwable -> {
logger.error("Failed to get total reward: " + throwable.getMessage()); logger.error("Failed to get total reward: " + throwable.getMessage());
return null; return null;