Skip to content

Commit

Permalink
Added set purchasing
Browse files Browse the repository at this point in the history
  • Loading branch information
DSteve595 committed Jul 9, 2015
1 parent cfd5451 commit 0ebd499
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 38 deletions.
2 changes: 1 addition & 1 deletion Emoji Switcher/Emoji Switcher.iml
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@
<orderEntry type="jdk" jdkName="Android API 22 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="gson-2.3.1" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="guava-18.0" level="project" />
<orderEntry type="library" exported="" name="commons-io-2.4" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-22.2.0" level="project" />
<orderEntry type="library" exported="" name="rxandroid-0.25.0" level="project" />
<orderEntry type="library" exported="" name="support-annotations-22.2.0" level="project" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.stevenschoen.emojiswitcher;

import android.content.Context;
import android.widget.ArrayAdapter;

import com.stevenschoen.emojiswitcher.network.EmojiSetListing;

import java.util.List;

public class EmojiSetSelectionAdapter extends ArrayAdapter<EmojiSetListing> {

public EmojiSetSelectionAdapter(Context context, List<EmojiSetListing> objects) {
super(context, android.R.layout.simple_spinner_item, objects);
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -286,28 +286,6 @@ public void onClick(DialogInterface dialog, int which) {
return builder.create();
}

// private static class InstallEmojiSetTask extends AsyncTask<Object, Void, Void> {
// @Override
// protected Void doInBackground(Object... params) {
// final Activity activity = (Activity) params[0];
// EmojiSet emojiSet = (EmojiSet) params[1];
//
// File systemEmojiSetFile = new File(systemEmojiFilePath);
// File backupFile = new File(systemEmojiBackupFilePath(activity));
// if (backupFile.length() == 0) {
// RootTools.copyFile(systemEmojiSetFile.getAbsolutePath(),
// backupFile.getAbsolutePath(), true, false);
// }
//
// File emojiSetFile = emojiSet.path;
// RootTools.copyFile(emojiSetFile.getAbsolutePath(),
// systemEmojiSetFile.getAbsolutePath(), true, false);
// applyPermissions(activity, "644", systemEmojiFilePath);
//
// return null;
// }
// }

public static Observable<EmojiSetListing> currentEmojiSet(final Context context, final List<EmojiSetListing> sets) {
return Observable.create(new Observable.OnSubscribe<EmojiSetListing>() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,9 @@ public void onNext(EmojiSwitcherUtils.InstallProgress installProgress) {
final AlertDialog dialog = new AlertDialog.Builder(getActivity())
.setView(view)
.setTitle(getString(R.string.installing_x_emoji, listing.name))
.setCancelable(false)
.create();
dialog.setCanceledOnTouchOutside(false);

laterView.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,31 @@
package com.stevenschoen.emojiswitcher;

import android.app.Activity;

import com.stevenschoen.emojiswitcher.billing.IabException;
import com.stevenschoen.emojiswitcher.billing.IabHelper;
import com.stevenschoen.emojiswitcher.network.EmojiSetListing;

import java.util.ArrayList;
import java.util.List;

public class SetListingUtils {
public static boolean userOwnsSet(EmojiSetListing listing, IabHelper billingHelper) {
// TODO
return true;
if (listing.googlePlaySku == null) {
return true;
} else {
List<String> skuList = new ArrayList<>();
skuList.add(listing.googlePlaySku);
try {
return billingHelper.queryInventory(true, skuList, null).hasPurchase(listing.googlePlaySku);
} catch (IabException e) {
e.printStackTrace();
return false;
}
}
}

public static void purchaseSet(Activity activity, EmojiSetListing listing, IabHelper billingHelper, IabHelper.OnIabPurchaseFinishedListener listener) {
billingHelper.launchPurchaseFlow(activity, listing.googlePlaySku, 0, listener);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.stevenschoen.emojiswitcher;

import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
Expand All @@ -14,6 +16,7 @@
import android.widget.ImageButton;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
Expand Down Expand Up @@ -50,6 +53,14 @@ public class SwitcherActivity extends RxAppCompatActivity implements InstallEmoj
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
if (cm.getActiveNetworkInfo() == null || !cm.getActiveNetworkInfo().isConnected()) {
Toast.makeText(this, "This app needs internet access to work.", Toast.LENGTH_LONG).show();
finish();
return;
}

setContentView(R.layout.activity_emojiswitcher);

verifyRoot();
Expand Down Expand Up @@ -97,21 +108,28 @@ public void onClick(View v) {
});

spinnerInstallEmojis = (Spinner) findViewById(R.id.spinner_pickemojiset);
emojiSetsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, emojiSetListings);
emojiSetsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
emojiSetsAdapter = new EmojiSetSelectionAdapter(this, emojiSetListings);
spinnerInstallEmojis.setAdapter(emojiSetsAdapter);

spinnerInstallEmojis.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
int lastSelectedSetPosition;

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
public void onItemSelected(final AdapterView<?> parent, View view, final int position, long id) {
EmojiSetListing listing = (EmojiSetListing) parent.getItemAtPosition(position);
if (SetListingUtils.userOwnsSet(listing, billingHelper)) {
lastSelectedSetPosition = position;
} else {
parent.setSelection(lastSelectedSetPosition);
// buy
SetListingUtils.purchaseSet(SwitcherActivity.this, listing, billingHelper,
new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isSuccess()) {
parent.setSelection(position);
}
}
});
}
}

Expand All @@ -123,14 +141,19 @@ public void onNothingSelected(AdapterView<?> parent) { }
buttonInstallEmojiSet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EmojiSetListing listing = (EmojiSetListing) spinnerInstallEmojis.getSelectedItem();
final EmojiSetListing listing = (EmojiSetListing) spinnerInstallEmojis.getSelectedItem();
if (SetListingUtils.userOwnsSet(listing, billingHelper)) {
Bundle options = new Bundle();
options.putParcelable("listing", (EmojiSetListing) spinnerInstallEmojis.getSelectedItem());
InstallEmojiFragment installFragment = (InstallEmojiFragment) Fragment.instantiate(SwitcherActivity.this, InstallEmojiFragment.class.getName(), options);
installFragment.show(getSupportFragmentManager(), "install");
installSet(listing);
} else {
// buy
SetListingUtils.purchaseSet(SwitcherActivity.this, listing, billingHelper,
new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase info) {
if (result.isSuccess()) {
installSet(listing);
}
}
});
}
}
});
Expand All @@ -140,6 +163,13 @@ public void onClick(View v) {
setupBilling();
}

private void installSet(EmojiSetListing listing) {
Bundle options = new Bundle();
options.putParcelable("listing", listing);
InstallEmojiFragment installFragment = (InstallEmojiFragment) Fragment.instantiate(SwitcherActivity.this, InstallEmojiFragment.class.getName(), options);
installFragment.show(getSupportFragmentManager(), "install");
}

private void refreshCurrentSystemEmojiSet() {
verifyRoot();

Expand Down
15 changes: 13 additions & 2 deletions Emoji Switcher/src/main/res/layout/install_emoji.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@
android:id="@+id/install_emoji_reboot_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingStart="16dp">
android:orientation="vertical">

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="2dp"
android:background="#4888" />

<TextView
android:layout_width="wrap_content"
android:layout_height="44dp"
android:fontFamily="sans-serif-medium"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingTop="16dp"
android:text="@string/reboot_question"
android:textAllCaps="true"
Expand All @@ -38,6 +47,8 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:text="@string/reboot_explanation" />

<LinearLayout
Expand Down
3 changes: 2 additions & 1 deletion Emoji Switcher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
<string name="refresh">Refresh</string>
<string name="try_again">Try again</string>
<string name="check_root">Check root</string>
<string name="root_problem">There was a problem getting root access, which is needed to modify the built-in emoji data.\n\nDoes this app have root permissions?</string>
<string name="root_problem">There was a problem getting root access.\n\nRoot access is given after you "root" your device, which lets apps do advanced things like modify system files.
It\'s a different process for each device.\n\nDoes this app have root permissions?</string>
<string name="are_you_rooted">Are you rooted?</string>
<string name="failed_to_get_root">Failed to get root!</string>
<string name="switch_emojis_to">Switch emojis to…</string>
Expand Down

0 comments on commit 0ebd499

Please sign in to comment.