Donations improvements

This commit is contained in:
Grishka 2024-06-13 18:58:24 +03:00
parent 4e1bf80e12
commit 6270a3dfdc
21 changed files with 306 additions and 22 deletions

View File

@ -13,7 +13,7 @@ android {
applicationId "org.joinmastodon.android"
minSdk 23
targetSdk 33
versionCode 99
versionCode 100
versionName "2.5.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

View File

@ -79,6 +79,7 @@
<data android:mimeType="*/*"/>
</intent-filter>
</activity>
<activity android:name=".DonationFragmentActivity" android:exported="false" android:configChanges="orientation|screenSize" android:windowSoftInputMode="adjustResize"/>
<service android:name=".AudioPlayerService" android:foregroundServiceType="mediaPlayback"/>
<service android:name=".NotificationActionHandlerService" android:exported="false"/>

View File

@ -0,0 +1,29 @@
package org.joinmastodon.android;
import android.os.Bundle;
import org.joinmastodon.android.fragments.DonationWebViewFragment;
import androidx.annotation.Nullable;
import me.grishka.appkit.FragmentStackActivity;
// This exists because our designer wanted to avoid extra sheet showing/hiding animations.
// This is the only way to show a fragment on top of a sheet without having to rewrite way too many things.
public class DonationFragmentActivity extends FragmentStackActivity{
@Override
protected void onCreate(@Nullable Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(savedInstanceState==null){
DonationWebViewFragment fragment=new DonationWebViewFragment();
fragment.setArguments(getIntent().getBundleExtra("fragmentArgs"));
showFragment(fragment);
overridePendingTransition(R.anim.fragment_enter, R.anim.no_op_300ms);
}
}
@Override
public void finish(){
super.finish();
overridePendingTransition(0, R.anim.fragment_exit);
}
}

View File

@ -1,14 +1,20 @@
package org.joinmastodon.android.fragments;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebResourceRequest;
import org.joinmastodon.android.BuildConfig;
import org.joinmastodon.android.E;
import org.joinmastodon.android.R;
import org.joinmastodon.android.api.session.AccountSessionManager;
import org.joinmastodon.android.events.DismissDonationCampaignBannerEvent;
import org.joinmastodon.android.ui.M3AlertDialogBuilder;
import org.joinmastodon.android.ui.sheets.DonationSuccessfulSheet;
import java.util.Objects;
@ -18,6 +24,14 @@ public class DonationWebViewFragment extends WebViewFragment{
public static final String SUCCESS_URL="https://sponsor.joinmastodon.org/donation/success";
public static final String FAILURE_URL="https://sponsor.joinmastodon.org/donation/failure";
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
if(BuildConfig.DEBUG){
setHasOptionsMenu(true);
}
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState){
super.onViewCreated(view, savedInstanceState);
@ -28,25 +42,47 @@ public class DonationWebViewFragment extends WebViewFragment{
protected boolean shouldOverrideUrlLoading(WebResourceRequest req){
String url=req.getUrl().buildUpon().clearQuery().fragment(null).build().toString();
if(url.equalsIgnoreCase(SUCCESS_URL)){
new M3AlertDialogBuilder(getActivity())
.setTitle("Success")
.setMessage("Some sort of UI that would tell the user that their payment was successful")
.setPositiveButton(R.string.ok, null)
.setOnDismissListener(dlg->Nav.finish(this))
.show();
String campaignID=getArguments().getString("campaignID");
AccountSessionManager.getInstance().markDonationCampaignAsDismissed(campaignID);
E.post(new DismissDonationCampaignBannerEvent(campaignID));
onSuccess();
return true;
}else if(url.equalsIgnoreCase(FAILURE_URL)){
onFailure();
return true;
}
return false;
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater){
super.onCreateOptionsMenu(menu, inflater);
if(BuildConfig.DEBUG){
menu.add(0, 0, 0, "Simulate success");
menu.add(0, 1, 0, "Simulate failure");
}
}
@Override
public boolean onOptionsItemSelected(MenuItem item){
if(item.getItemId()==0)
onSuccess();
else if(item.getItemId()==1)
onFailure();
return super.onOptionsItemSelected(item);
}
private void onFailure(){
new M3AlertDialogBuilder(getActivity())
.setTitle("Failure")
.setMessage("Some sort of UI that would tell the user that their payment didn't go through")
.setPositiveButton(R.string.ok, null)
.setOnDismissListener(dlg->Nav.finish(this))
.show();
return true;
}
return false;
private void onSuccess(){
String campaignID=getArguments().getString("campaignID");
AccountSessionManager.getInstance().markDonationCampaignAsDismissed(campaignID);
E.post(new DismissDonationCampaignBannerEvent(campaignID));
getActivity().setResult(Activity.RESULT_OK);
getActivity().finish();
}
}

View File

@ -6,6 +6,7 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.text.SpannableStringBuilder;
@ -55,6 +56,7 @@ import org.joinmastodon.android.model.donations.DonationCampaign;
import org.joinmastodon.android.ui.displayitems.GapStatusDisplayItem;
import org.joinmastodon.android.ui.displayitems.StatusDisplayItem;
import org.joinmastodon.android.ui.sheets.DonationSheet;
import org.joinmastodon.android.ui.sheets.DonationSuccessfulSheet;
import org.joinmastodon.android.ui.utils.DiscoverInfoBannerHelper;
import org.joinmastodon.android.ui.viewcontrollers.HomeTimelineMenuController;
import org.joinmastodon.android.ui.viewcontrollers.ToolbarDropdownMenuController;
@ -77,8 +79,11 @@ import me.grishka.appkit.api.SimpleCallback;
import me.grishka.appkit.utils.CubicBezierInterpolator;
import me.grishka.appkit.utils.MergeRecyclerAdapter;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.BottomSheet;
public class HomeTimelineFragment extends StatusListFragment implements ToolbarDropdownMenuController.HostFragment{
private static final int DONATION_RESULT=211;
private ImageButton fab;
private LinearLayout listsDropdown;
private FixedAspectRatioImageView listsDropdownArrow;
@ -100,6 +105,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
private String maxID;
private String lastSavedMarkerID;
private DonationCampaign currentDonationCampaign;
private BottomSheet donationSheet;
public HomeTimelineFragment(){
setListLayoutId(R.layout.fragment_timeline);
@ -129,6 +135,13 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
})
.execNoAuth("");
}
E.register(this);
}
@Override
public void onDestroy(){
super.onDestroy();
E.unregister(this);
}
@Override
@ -639,6 +652,7 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
updateUpdateState(ev.state);
}
@Subscribe
public void onDismissDonationCampaignBanner(DismissDonationCampaignBannerEvent ev){
if(currentDonationCampaign!=null && ev.campaignID.equals(currentDonationCampaign.id)){
dismissDonationBanner();
@ -699,6 +713,17 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
super.onDataLoaded(d, more);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
if(requestCode==DONATION_RESULT){
if(donationSheet!=null)
donationSheet.dismissWithoutAnimation();
if(resultCode==Activity.RESULT_OK){
new DonationSuccessfulSheet(getActivity(), accountID).showWithoutAnimation();
}
}
}
private String getCurrentListTitle(){
return switch(listMode){
case FOLLOWING -> getString(R.string.timeline_following);
@ -773,7 +798,9 @@ public class HomeTimelineFragment extends StatusListFragment implements ToolbarD
}
private void openDonationSheet(){
new DonationSheet(getActivity(), currentDonationCampaign, accountID).show();
donationSheet=new DonationSheet(getActivity(), currentDonationCampaign, accountID, intent->startActivityForResult(intent, DONATION_RESULT));
donationSheet.setOnDismissListener(dialog->donationSheet=null);
donationSheet.show();
}
private enum ListMode{

View File

@ -2,6 +2,7 @@ package org.joinmastodon.android.ui.sheets;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.Bundle;
@ -11,11 +12,11 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.ToggleButton;
import org.joinmastodon.android.DonationFragmentActivity;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.DonationWebViewFragment;
import org.joinmastodon.android.model.donations.DonationCampaign;
@ -29,10 +30,10 @@ import java.util.Arrays;
import java.util.Currency;
import java.util.List;
import java.util.Locale;
import java.util.function.Consumer;
import java.util.stream.Collectors;
import androidx.annotation.NonNull;
import me.grishka.appkit.Nav;
import me.grishka.appkit.utils.CustomViewHelper;
import me.grishka.appkit.utils.V;
import me.grishka.appkit.views.BottomSheet;
@ -40,6 +41,7 @@ import me.grishka.appkit.views.BottomSheet;
public class DonationSheet extends BottomSheet{
private final DonationCampaign campaign;
private final String accountID;
private final Consumer<Intent> startCallback;
private DonationFrequency frequency=DonationFrequency.MONTHLY;
private View onceTab, monthlyTab, yearlyTab;
@ -50,11 +52,12 @@ public class DonationSheet extends BottomSheet{
private TextView buttonText;
private Activity activity;
public DonationSheet(@NonNull Activity activity, DonationCampaign campaign, String accountID){
public DonationSheet(@NonNull Activity activity, DonationCampaign campaign, String accountID, Consumer<Intent> startCallback){
super(activity);
this.campaign=campaign;
this.accountID=accountID;
this.activity=activity;
this.startCallback=startCallback;
Context context=activity;
View content=context.getSystemService(LayoutInflater.class).inflate(R.layout.sheet_donation, null);
@ -246,8 +249,8 @@ public class DonationSheet extends BottomSheet{
args.putString("url", builder.build().toString());
args.putString("account", accountID);
args.putString("campaignID", campaign.id);
Nav.go(activity, DonationWebViewFragment.class, args);
dismiss();
args.putBoolean("_can_go_back", true);
startCallback.accept(new Intent(activity, DonationFragmentActivity.class).putExtra("fragmentArgs", args));
}
private static long getMinimumChargeAmount(String currency){

View File

@ -0,0 +1,36 @@
package org.joinmastodon.android.ui.sheets;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import org.joinmastodon.android.R;
import org.joinmastodon.android.fragments.ComposeFragment;
import org.joinmastodon.android.ui.utils.UiUtils;
import androidx.annotation.NonNull;
import me.grishka.appkit.Nav;
import me.grishka.appkit.views.BottomSheet;
public class DonationSuccessfulSheet extends BottomSheet{
public DonationSuccessfulSheet(@NonNull Context context, @NonNull String accountID){
super(context);
View content=context.getSystemService(LayoutInflater.class).inflate(R.layout.sheet_donation_success, null);
setContentView(content);
setNavigationBarBackground(new ColorDrawable(UiUtils.alphaBlendColors(UiUtils.getThemeColor(context, R.attr.colorM3Surface),
UiUtils.getThemeColor(context, R.attr.colorM3Primary), 0.05f)), !UiUtils.isDarkTheme());
content.findViewById(R.id.btn_done).setOnClickListener(v->dismiss());
content.findViewById(R.id.btn_share).setOnClickListener(v->{
Bundle args=new Bundle();
args.putString("account", accountID);
args.putString("prefilledText", "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi a sapien metus. Nunc feugiat a felis sed hendrerit.");
Nav.go((Activity) context, ComposeFragment.class, args);
dismiss();
});
}
}

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="300"
android:interpolator="@interpolator/cubic_bezier_default"
android:shareInterpolator="true"
>
<alpha
android:fromAlpha="0"
android:toAlpha="1" />
<translate
android:fromXDelta="@integer/hundred_dp"
android:toXDelta="0"/>
</set>

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="200"
android:interpolator="@interpolator/cubic_bezier_default"
android:shareInterpolator="true"
>
<alpha
android:fromAlpha="1"
android:toAlpha="0" />
<translate
android:fromXDelta="0"
android:toXDelta="@integer/hundred_dp"/>
</set>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:duration="300">
</set>

Binary file not shown.

After

Width:  |  Height:  |  Size: 67 KiB

View File

@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="20dp"
android:height="20dp"
android:viewportWidth="20"
android:viewportHeight="20">
<path
android:fillColor="@android:color/white"
android:pathData="M15,10.875V9.125H18.333V10.875ZM16,16.667 L13.333,14.667 14.375,13.25 17.042,15.25ZM14.396,6.729 L13.333,5.333 16,3.333 17.062,4.729ZM4.167,15.833V12.5H3.417Q2.729,12.5 2.198,12.052Q1.667,11.604 1.667,10.917V9.083Q1.667,8.396 2.198,7.948Q2.729,7.5 3.417,7.5H6.667L10.833,5V15L6.667,12.5H5.917V15.833ZM11.708,12.792V7.208Q12.271,7.708 12.615,8.427Q12.958,9.146 12.958,10Q12.958,10.854 12.615,11.573Q12.271,12.292 11.708,12.792ZM3.417,9.25Q3.417,9.25 3.417,9.25Q3.417,9.25 3.417,9.25V10.75Q3.417,10.75 3.417,10.75Q3.417,10.75 3.417,10.75H7.208L9.083,11.917V8.083L7.208,9.25ZM6.25,10Q6.25,10 6.25,10Q6.25,10 6.25,10Q6.25,10 6.25,10Q6.25,10 6.25,10Z"/>
</vector>

View File

@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<pathInterpolator xmlns:android="http://schemas.android.com/apk/res/android"
android:controlX1="0.25" android:controlY1="0.1" android:controlX2="0.25" android:controlY2="1"/>

View File

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<org.joinmastodon.android.ui.views.CustomScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@drawable/bg_bottom_sheet"
android:outlineProvider="background"
android:elevation="1dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="16dp"
android:paddingHorizontal="16dp">
<View
android:id="@+id/handle"
android:layout_width="match_parent"
android:layout_height="36dp"
android:layout_marginBottom="8dp"
android:background="@drawable/bg_bottom_sheet_handle"/>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/m3_headline_medium"
android:textColor="?colorM3OnSurface"
android:gravity="center"
android:text="@string/donation_success_title"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:textAppearance="@style/m3_body_large"
android:gravity="center"
android:textColor="?colorM3OnSurfaceVariant"
android:text="@string/donation_success_subtitle"/>
<org.joinmastodon.android.ui.views.FixedAspectRatioImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:src="@drawable/donation_successful_art"
app:aspectRatio="1.777777"/>
<FrameLayout
android:id="@+id/btn_share"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
style="@style/Widget.Mastodon.M3.Button.Filled">
<TextView
android:id="@+id/button_text"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_gravity="center_horizontal"
android:drawableStart="@drawable/ic_campaign_20px"
style="@style/Widget.Mastodon.M3.Button.Filled"
android:background="@null"
android:padding="0dp"
android:drawablePadding="8dp"
android:drawableTint="@color/button_text_m3_filled"
android:clickable="false"
android:focusable="false"
android:duplicateParentState="true"
android:text="@string/donation_success_share"/>
</FrameLayout>
<Button
android:id="@+id/btn_done"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="16dp"
style="@style/Widget.Mastodon.M3.Button.Outlined"
android:text="@string/done"/>
</LinearLayout>
</org.joinmastodon.android.ui.views.CustomScrollView>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">150</integer>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">133</integer>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">200</integer>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">300</integer>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">400</integer>
</resources>

View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<integer name="hundred_dp">100</integer>
</resources>

View File

@ -771,4 +771,7 @@
<string name="donation_monthly">Monthly</string>
<string name="donation_yearly">Yearly</string>
<string name="currency">Currency</string>
<string name="donation_success_share">Spread the word</string>
<string name="donation_success_title">Thank you for your contribution!</string>
<string name="donation_success_subtitle">You should receive an email confirming your donation soon.</string>
</resources>