mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-23 06:07:16 +00:00
[#19] gem purchase part 1 / BaseFragment bugfixes
This commit is contained in:
parent
933c9cd515
commit
b1c3520e0e
8 changed files with 142 additions and 179 deletions
|
|
@ -86,14 +86,6 @@
|
|||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".GemPurchaseActivity"
|
||||
android:label="@string/title_activity_gem_purchase"
|
||||
android:parentActivityName=".MainActivity">
|
||||
<meta-data
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value=".MainActivity" />
|
||||
</activity>
|
||||
|
||||
<activity android:name="com.facebook.FacebookActivity"
|
||||
android:configChanges=
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:gravity="center"
|
||||
tools:context=".GemPurchaseActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="?attr/colorPrimary"
|
||||
android:theme="@style/Toolbar"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
12
Habitica/res/layout/fragment_gem_purchase.xml
Normal file
12
Habitica/res/layout/fragment_gem_purchase.xml
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Buy"
|
||||
android:id="@+id/btn.purchase.gems"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
</LinearLayout>
|
||||
|
|
@ -1,134 +0,0 @@
|
|||
package com.habitrpg.android.habitica;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
|
||||
import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.mikepenz.materialdrawer.AccountHeader;
|
||||
import com.mikepenz.materialdrawer.Drawer;
|
||||
import com.mikepenz.materialdrawer.model.ProfileDrawerItem;
|
||||
import com.mikepenz.materialdrawer.model.interfaces.IProfile;
|
||||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.BillingRequests;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
import org.solovyev.android.checkout.Purchase;
|
||||
import org.solovyev.android.checkout.RequestListener;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
public class GemPurchaseActivity extends AppCompatActivity {
|
||||
|
||||
// region View Elements
|
||||
|
||||
@InjectView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
|
||||
Drawer drawer;
|
||||
AccountHeader accountHeader;
|
||||
// endregion
|
||||
|
||||
// region IAP
|
||||
|
||||
@NonNull
|
||||
private final ActivityCheckout checkout = Checkout.forActivity(this, HabiticaApplication.Instance.getCheckout());
|
||||
|
||||
// endregion
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_gem_purchase);
|
||||
|
||||
// Inject Controls
|
||||
ButterKnife.inject(this);
|
||||
|
||||
if (toolbar != null) {
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
|
||||
if (actionBar != null) {
|
||||
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
actionBar.setDisplayShowHomeEnabled(false);
|
||||
actionBar.setDisplayShowTitleEnabled(true);
|
||||
actionBar.setDisplayUseLogoEnabled(false);
|
||||
actionBar.setHomeButtonEnabled(false);
|
||||
}
|
||||
|
||||
actionBar.setTitle("Purchase Gems");
|
||||
}
|
||||
|
||||
accountHeader = MainDrawerBuilder.CreateDefaultAccountHeader(this).build();
|
||||
|
||||
HostConfig hostConfig = PrefsActivity.fromContext(this);
|
||||
HabitRPGUser user = new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).querySingle();
|
||||
|
||||
final IProfile profile = accountHeader.getProfiles().get(0);
|
||||
if (user.getAuthentication() != null) {
|
||||
if (user.getAuthentication().getLocalAuthentication() != null) {
|
||||
profile.withEmail(user.getAuthentication().getLocalAuthentication().getEmail());
|
||||
}
|
||||
} profile.withName(user.getProfile().getName());
|
||||
new UserPicture(user, this, true, false).setPictureWithRunnable(new UserPictureRunnable() {
|
||||
public void run(Bitmap avatar) {
|
||||
profile.withIcon(avatar);
|
||||
accountHeader.updateProfile(profile);
|
||||
}
|
||||
});
|
||||
accountHeader.updateProfile(profile);
|
||||
|
||||
checkout.start();
|
||||
// you only need this if this activity starts purchase process
|
||||
checkout.createPurchaseFlow(new RequestListener<Purchase>() {
|
||||
@Override
|
||||
public void onSuccess(Purchase purchase) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i, Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
checkout.whenReady(new Checkout.Listener() {
|
||||
@Override
|
||||
public void onReady(BillingRequests billingRequests) {
|
||||
billingRequests.purchase(ProductTypes.IN_APP, HabiticaApplication.Purchase20Gems, null, checkout.getPurchaseFlow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(BillingRequests billingRequests, String s, boolean b) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
checkout.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
checkout.stop();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ public class HabiticaApplication extends Application {
|
|||
}
|
||||
});
|
||||
|
||||
public static String Purchase20Gems = "com.habitrpg.android.habitica.buy20gems";
|
||||
public static String Purchase20Gems = "com.habitrpg.android.habitica.iap.20.gems";
|
||||
|
||||
/**
|
||||
* Application wide {@link org.solovyev.android.checkout.Checkout} instance (can be used anywhere in the app).
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import android.view.View;
|
|||
import com.habitrpg.android.habitica.AboutActivity;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.MainActivity;
|
||||
import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.PartyFragment;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.ui.fragments.TasksFragment;
|
||||
|
|
@ -109,6 +110,10 @@ public class MainDrawerBuilder {
|
|||
fragment = new TavernFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_PURCHASE:{
|
||||
fragment = new GemsPurchaseFragment();
|
||||
break;
|
||||
}
|
||||
case SIDEBAR_SETTINGS: {
|
||||
newActivityClass = PrefsActivity.class;
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -16,12 +16,15 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|||
|
||||
import butterknife.ButterKnife;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import de.greenrobot.event.EventBusException;
|
||||
|
||||
/**
|
||||
* Created by admin on 18/11/15.
|
||||
*/
|
||||
public abstract class BaseFragment extends Fragment {
|
||||
|
||||
private boolean registerEventBus = false;
|
||||
|
||||
public MainActivity activity;
|
||||
public TabLayout tabLayout;
|
||||
public APIHelper mAPIHelper;
|
||||
|
|
@ -29,12 +32,22 @@ public abstract class BaseFragment extends Fragment {
|
|||
public boolean usesTabLayout;
|
||||
public int fragmentSidebarPosition;
|
||||
|
||||
public void setUser(HabitRPGUser user) { this.user = user; }
|
||||
public void updateUserData(HabitRPGUser user) { this.user = user; }
|
||||
public void setUser(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void updateUserData(HabitRPGUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public void setTabLayout(TabLayout tabLayout) {
|
||||
this.tabLayout = tabLayout;
|
||||
}
|
||||
public void setActivity(MainActivity activity) {this.activity = activity; }
|
||||
|
||||
public void setActivity(MainActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
@ -44,14 +57,22 @@ public abstract class BaseFragment extends Fragment {
|
|||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
if (this.usesTabLayout) {
|
||||
tabLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
|
||||
if (tabLayout != null) {
|
||||
if (this.usesTabLayout) {
|
||||
tabLayout.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
tabLayout.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
// Receive Events
|
||||
EventBus.getDefault().register(this);
|
||||
try {
|
||||
EventBus.getDefault().register(this);
|
||||
registerEventBus = true;
|
||||
} catch (EventBusException ignored) {
|
||||
|
||||
}
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
|
|
@ -62,7 +83,9 @@ public abstract class BaseFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
EventBus.getDefault().unregister(this);
|
||||
if (registerEventBus) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.BillingRequests;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
import org.solovyev.android.checkout.Purchase;
|
||||
import org.solovyev.android.checkout.RequestListener;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
|
||||
/**
|
||||
* Created by Negue on 24.11.2015.
|
||||
*/
|
||||
public class GemsPurchaseFragment extends BaseFragment {
|
||||
|
||||
@InjectView(R.id.btn_purchase_gems)
|
||||
Button btnPurchaseGems;
|
||||
|
||||
|
||||
private ActivityCheckout checkout = null;
|
||||
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
this.usesTabLayout = true;
|
||||
super.onCreateView(inflater, container, savedInstanceState);
|
||||
|
||||
View v = inflater.inflate(R.layout.fragment_gem_purchase, container, false);
|
||||
|
||||
ButterKnife.inject(this, v);
|
||||
|
||||
checkout = Checkout.forActivity(this.activity, HabiticaApplication.Instance.getCheckout());
|
||||
|
||||
checkout.start();
|
||||
// you only need this if this activity starts purchase process
|
||||
checkout.createPurchaseFlow(new RequestListener<Purchase>() {
|
||||
@Override
|
||||
public void onSuccess(Purchase purchase) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(int i, Exception e) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
checkout.whenReady(new Checkout.Listener() {
|
||||
@Override
|
||||
public void onReady(BillingRequests billingRequests) {
|
||||
billingRequests.purchase(ProductTypes.IN_APP, HabiticaApplication.Purchase20Gems, null, checkout.getPurchaseFlow());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady(BillingRequests billingRequests, String s, boolean b) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
checkout.onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
checkout.stop();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue