Add donation fragment
This commit is contained in:
@@ -20,11 +20,15 @@ package org.sufficientlysecure.keychain.ui;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
|
||||
import org.sufficientlysecure.donations.DonationsFragment;
|
||||
import org.sufficientlysecure.keychain.BuildConfig;
|
||||
import org.sufficientlysecure.keychain.Constants;
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.ui.adapter.PagerTabStripAdapter;
|
||||
import org.sufficientlysecure.keychain.ui.base.BaseActivity;
|
||||
@@ -36,10 +40,15 @@ public class HelpActivity extends BaseActivity {
|
||||
public static final int TAB_START = 0;
|
||||
public static final int TAB_CONFIRM = 1;
|
||||
public static final int TAB_FAQ = 2;
|
||||
public static final int TAB_CHANGELOG = 3;
|
||||
public static final int TAB_ABOUT = 4;
|
||||
public static final int TAB_DONATE = 3;
|
||||
public static final int TAB_CHANGELOG = 4;
|
||||
public static final int TAB_ABOUT = 5;
|
||||
|
||||
// Google Play
|
||||
private static final String[] GOOGLE_PLAY_CATALOG = new String[]{"keychain.donation.1",
|
||||
"keychain.donation.2", "keychain.donation.3", "keychain.donation.5", "keychain.donation.10",
|
||||
"keychain.donation.50", "keychain.donation.100"};
|
||||
|
||||
ViewPager mViewPager;
|
||||
private PagerTabStripAdapter mTabsAdapter;
|
||||
|
||||
@Override
|
||||
@@ -53,12 +62,12 @@ public class HelpActivity extends BaseActivity {
|
||||
}
|
||||
});
|
||||
|
||||
mViewPager = (ViewPager) findViewById(R.id.pager);
|
||||
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
|
||||
PagerSlidingTabStrip slidingTabLayout =
|
||||
(PagerSlidingTabStrip) findViewById(R.id.sliding_tab_layout);
|
||||
|
||||
mTabsAdapter = new PagerTabStripAdapter(this);
|
||||
mViewPager.setAdapter(mTabsAdapter);
|
||||
viewPager.setAdapter(mTabsAdapter);
|
||||
|
||||
int selectedTab = TAB_START;
|
||||
Intent intent = getIntent();
|
||||
@@ -81,6 +90,26 @@ public class HelpActivity extends BaseActivity {
|
||||
mTabsAdapter.addTab(HelpMarkdownFragment.class, faqBundle,
|
||||
getString(R.string.help_tab_faq));
|
||||
|
||||
Bundle donationsBundle = new Bundle();
|
||||
donationsBundle.putBoolean(DonationsFragment.ARG_DEBUG, Constants.DEBUG);
|
||||
if (BuildConfig.DONATIONS_GOOGLE) {
|
||||
donationsBundle.putBoolean(DonationsFragment.ARG_GOOGLE_ENABLED, true);
|
||||
donationsBundle.putString(DonationsFragment.ARG_GOOGLE_PUBKEY, BuildConfig.GOOGLE_PLAY_PUBKEY);
|
||||
donationsBundle.putStringArray(DonationsFragment.ARG_GOOGLE_CATALOG, GOOGLE_PLAY_CATALOG);
|
||||
donationsBundle.putStringArray(DonationsFragment.ARG_GOOGLE_CATALOG_VALUES,
|
||||
getResources().getStringArray(R.array.help_donation_google_catalog_values));
|
||||
} else {
|
||||
donationsBundle.putBoolean(DonationsFragment.ARG_PAYPAL_ENABLED, true);
|
||||
donationsBundle.putString(DonationsFragment.ARG_PAYPAL_CURRENCY_CODE, BuildConfig.PAYPAL_CURRENCY_CODE);
|
||||
donationsBundle.putString(DonationsFragment.ARG_PAYPAL_USER, BuildConfig.PAYPAL_USER);
|
||||
donationsBundle.putString(DonationsFragment.ARG_PAYPAL_ITEM_NAME,
|
||||
getString(R.string.help_donation_paypal_item));
|
||||
donationsBundle.putBoolean(DonationsFragment.ARG_BITCOIN_ENABLED, true);
|
||||
donationsBundle.putString(DonationsFragment.ARG_BITCOIN_ADDRESS, BuildConfig.BITCOIN_ADDRESS);
|
||||
}
|
||||
mTabsAdapter.addTab(DonationsFragment.class, donationsBundle,
|
||||
getString(R.string.help_tab_donations));
|
||||
|
||||
Bundle changelogBundle = new Bundle();
|
||||
changelogBundle.putInt(HelpMarkdownFragment.ARG_MARKDOWN_RES, R.raw.help_changelog);
|
||||
mTabsAdapter.addTab(HelpMarkdownFragment.class, changelogBundle,
|
||||
@@ -90,10 +119,10 @@ public class HelpActivity extends BaseActivity {
|
||||
getString(R.string.help_tab_about));
|
||||
|
||||
// NOTE: must be after adding the tabs!
|
||||
slidingTabLayout.setViewPager(mViewPager);
|
||||
slidingTabLayout.setViewPager(viewPager);
|
||||
|
||||
// switch to tab selected by extra
|
||||
mViewPager.setCurrentItem(selectedTab);
|
||||
viewPager.setCurrentItem(selectedTab);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -107,4 +136,18 @@ public class HelpActivity extends BaseActivity {
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Needed for Google Play In-app Billing. It uses startIntentSenderForResult(). The result is not propagated to
|
||||
* the Fragment like in startActivityForResult(). Thus we need to propagate manually to our Fragment.
|
||||
*/
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
|
||||
Fragment fragment = mTabsAdapter.getRegisteredFragment(TAB_DONATE);
|
||||
if (fragment != null) {
|
||||
fragment.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,12 +22,15 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.SparseArray;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PagerTabStripAdapter extends FragmentPagerAdapter {
|
||||
protected final Activity mActivity;
|
||||
protected final ArrayList<TabInfo> mTabs = new ArrayList<>();
|
||||
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
|
||||
|
||||
static final class TabInfo {
|
||||
public final Class<?> clss;
|
||||
@@ -72,4 +75,21 @@ public class PagerTabStripAdapter extends FragmentPagerAdapter {
|
||||
public CharSequence getPageTitle(int position) {
|
||||
return mTabs.get(position).title;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object instantiateItem(ViewGroup container, int position) {
|
||||
Fragment fragment = (Fragment) super.instantiateItem(container, position);
|
||||
registeredFragments.put(position, fragment);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroyItem(ViewGroup container, int position, Object object) {
|
||||
registeredFragments.remove(position);
|
||||
super.destroyItem(container, position, object);
|
||||
}
|
||||
|
||||
public Fragment getRegisteredFragment(int position) {
|
||||
return registeredFragments.get(position);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -502,6 +502,7 @@
|
||||
<string name="help_tab_changelog">"Changelog"</string>
|
||||
<string name="help_tab_about">"About"</string>
|
||||
<string name="help_about_version">"Version:"</string>
|
||||
<string name="help_tab_donations">"Donate"</string>
|
||||
|
||||
<!-- Import -->
|
||||
<string name="import_tab_keyserver">"Keyserver"</string>
|
||||
@@ -1725,5 +1726,13 @@
|
||||
<string name="prompt_fidesmo_app_install_message">"To install PGP you need the Fidesmo Android app."</string>
|
||||
<string name="prompt_fidesmo_app_install_button_positive">"Install"</string>
|
||||
<string name="prompt_fidesmo_app_install_button_negative">"Cancel"</string>
|
||||
|
||||
<string name="help_donation_paypal_item">OpenKeychain Donation</string>
|
||||
<string-array name="help_donation_google_catalog_values">
|
||||
<item>1 Euro</item>
|
||||
<item>3 Euro</item>
|
||||
<item>5 Euro</item>
|
||||
<item>10 Euro</item>
|
||||
<item>50 Euro</item>
|
||||
<item>100 Euro</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user