Receive & send transition

This commit is contained in:
m2049r 2021-03-14 11:49:47 +01:00
parent 2fbd152fb3
commit 16870fcbb9
No known key found for this signature in database
GPG Key ID: 4386E69AF260078D
8 changed files with 68 additions and 36 deletions

View File

@ -50,6 +50,7 @@ import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.transition.MaterialContainerTransform;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.WriterException;
@ -64,6 +65,7 @@ import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.MoneroThreadPoolExecutor;
import com.m2049r.xmrwallet.util.ThemeHelper;
import com.m2049r.xmrwallet.widget.ExchangeView;
import com.m2049r.xmrwallet.widget.Toolbar;
@ -244,6 +246,11 @@ public class ReceiveFragment extends Fragment {
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
final MaterialContainerTransform transform = new MaterialContainerTransform();
transform.setDrawingViewId(R.id.fragment_container);
transform.setDuration(getResources().getInteger(R.integer.tx_item_transition_duration));
transform.setAllContainerColors(ThemeHelper.getThemedColor(getContext(), R.attr.colorSurface));
setSharedElementEnterTransition(transform);
}
private ShareActionProvider shareActionProvider;

View File

@ -43,7 +43,6 @@ import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.google.android.material.dialog.MaterialAlertDialogBuilder;
import com.google.android.material.navigation.NavigationView;
@ -60,9 +59,9 @@ import com.m2049r.xmrwallet.model.TransactionInfo;
import com.m2049r.xmrwallet.model.Wallet;
import com.m2049r.xmrwallet.model.WalletManager;
import com.m2049r.xmrwallet.service.WalletService;
import com.m2049r.xmrwallet.util.ThemeHelper;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.MoneroThreadPoolExecutor;
import com.m2049r.xmrwallet.util.ThemeHelper;
import com.m2049r.xmrwallet.widget.Toolbar;
import java.util.ArrayList;
@ -542,8 +541,8 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
}
@Override
public void onSendRequest() {
replaceFragment(SendFragment.newInstance(uri), null, null);
public void onSendRequest(View view) {
replaceFragmentWithTransition(view, SendFragment.newInstance(uri), null, null);
uri = null; // only use uri once
}
@ -832,8 +831,18 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
if (extras != null) {
newFragment.setArguments(extras);
}
int transition;
if (newFragment instanceof TxFragment)
transition = R.string.tx_details_transition_name;
else if (newFragment instanceof ReceiveFragment)
transition = R.string.receive_transition_name;
else if (newFragment instanceof SendFragment)
transition = R.string.send_transition_name;
else
throw new IllegalStateException("expecting known transition");
getSupportFragmentManager().beginTransaction()
.addSharedElement(view, getString(R.string.tx_details_transition_name))
.addSharedElement(view, getString(transition))
.replace(R.id.fragment_container, newFragment)
.addToBackStack(stackName)
.commit();
@ -843,10 +852,11 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
if (extras != null) {
newFragment.setArguments(extras);
}
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment);
transaction.addToBackStack(stackName);
transaction.commit();
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.fragment_container, newFragment)
.addToBackStack(stackName)
.commit();
}
private void onWalletDetails() {
@ -983,20 +993,13 @@ public class WalletActivity extends BaseActivity implements WalletFragment.Liste
}
@Override
public void onWalletReceive() {
startReceive(getWallet().getAddress());
}
void startReceive(String address) {
public void onWalletReceive(View view) {
final String address = getWallet().getAddress();
Timber.d("startReceive()");
Bundle b = new Bundle();
b.putString("address", address);
b.putString("name", getWalletName());
startReceiveFragment(b);
}
void startReceiveFragment(Bundle extras) {
replaceFragment(new ReceiveFragment(), null, extras);
replaceFragmentWithTransition(view, new ReceiveFragment(), null, b);
Timber.d("ReceiveFragment placed");
}

View File

@ -36,6 +36,7 @@ import android.widget.ProgressBar;
import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
@ -104,6 +105,13 @@ public class WalletFragment extends Fragment
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_wallet, container, false);
final MaterialElevationScale exitTransition = new MaterialElevationScale(false);
exitTransition.setDuration(getResources().getInteger(R.integer.tx_item_transition_duration));
setExitTransition(exitTransition);
final MaterialElevationScale reenterTransition = new MaterialElevationScale(true);
reenterTransition.setDuration(getResources().getInteger(R.integer.tx_item_transition_duration));
setReenterTransition(reenterTransition);
ivStreetGunther = view.findViewById(R.id.ivStreetGunther);
tvStreetView = view.findViewById(R.id.tvStreetView);
llBalance = view.findViewById(R.id.llBalance);
@ -169,18 +177,8 @@ public class WalletFragment extends Fragment
recyclerView.addOnItemTouchListener(swipeTouchListener);
bSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activityCallback.onSendRequest();
}
});
bReceive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
activityCallback.onWalletReceive();
}
});
bSend.setOnClickListener(v -> activityCallback.onSendRequest(v));
bReceive.setOnClickListener(v -> activityCallback.onWalletReceive(v));
sCurrency.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
@ -203,6 +201,16 @@ public class WalletFragment extends Fragment
return view;
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
postponeEnterTransition();
view.getViewTreeObserver().addOnPreDrawListener(() -> {
startPostponedEnterTransition();
return true;
});
}
void showBalance(String balance) {
tvBalance.setText(balance);
final boolean streetMode = activityCallback.isStreetMode();
@ -483,7 +491,7 @@ public class WalletFragment extends Fragment
long getDaemonHeight(); //mBoundService.getDaemonHeight();
void onSendRequest();
void onSendRequest(View view);
void onTxDetailsRequest(View view, TransactionInfo info);
@ -497,7 +505,7 @@ public class WalletFragment extends Fragment
String getTxKey(String txId);
void onWalletReceive();
void onWalletReceive(View view);
boolean hasWallet();

View File

@ -36,6 +36,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentStatePagerAdapter;
import androidx.viewpager.widget.ViewPager;
import com.google.android.material.transition.MaterialContainerTransform;
import com.m2049r.xmrwallet.OnBackPressedListener;
import com.m2049r.xmrwallet.OnUriScannedListener;
import com.m2049r.xmrwallet.R;
@ -49,6 +50,7 @@ import com.m2049r.xmrwallet.layout.SpendViewPager;
import com.m2049r.xmrwallet.model.PendingTransaction;
import com.m2049r.xmrwallet.util.Helper;
import com.m2049r.xmrwallet.util.Notice;
import com.m2049r.xmrwallet.util.ThemeHelper;
import com.m2049r.xmrwallet.widget.DotBar;
import com.m2049r.xmrwallet.widget.Toolbar;
@ -538,10 +540,14 @@ public class SendFragment extends Fragment
enableNavigation();
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
final MaterialContainerTransform transform = new MaterialContainerTransform();
transform.setDrawingViewId(R.id.fragment_container);
transform.setDuration(getResources().getInteger(R.integer.tx_item_transition_duration));
transform.setAllContainerColors(ThemeHelper.getThemedColor(getContext(), R.attr.colorSurface));
setSharedElementEnterTransition(transform);
}
@Override

View File

@ -3,7 +3,8 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="match_parent"
android:transitionName="@string/receive_transition_name">
<EditText
android:id="@+id/etDummy"

View File

@ -4,7 +4,8 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:orientation="vertical"
android:transitionName="@string/send_transition_name">
<LinearLayout
android:id="@+id/llNotice"

View File

@ -165,6 +165,7 @@
android:layout_weight="1"
android:enabled="false"
android:text="@string/label_wallet_receive"
android:transitionName="@string/receive_btn_transition_name"
app:icon="@drawable/ic_hand" />
<Button
@ -176,6 +177,7 @@
android:layout_weight="1"
android:enabled="false"
android:text="@string/label_wallet_send"
android:transitionName="@string/send_btn_transition_name"
app:icon="@drawable/ic_send" />
</LinearLayout>

View File

@ -474,5 +474,9 @@
<string name="tx_item_transition_name" translatable="false">tx_transition_%1$s</string>
<string name="tx_details_transition_name" translatable="false">tx_transition</string>
<string name="receive_transition_name" translatable="false">receive_transition</string>
<string name="receive_btn_transition_name" translatable="false">receive_btn_transition</string>
<string name="send_transition_name" translatable="false">send_transition</string>
<string name="send_btn_transition_name" translatable="false">send_btn_transition</string>
</resources>