WIP: Implement Google Play Billing
This commit is contained in:
parent
45f1c54eb1
commit
96478b7748
7 changed files with 52 additions and 9 deletions
1
app/.gitignore
vendored
1
app/.gitignore
vendored
|
@ -1,3 +1,4 @@
|
||||||
/build
|
/build
|
||||||
crashlytics.properties
|
crashlytics.properties
|
||||||
*.apk
|
*.apk
|
||||||
|
google-services.json
|
|
@ -73,7 +73,7 @@ android {
|
||||||
}
|
}
|
||||||
|
|
||||||
ext {
|
ext {
|
||||||
acraVersion = '5.1.3'
|
acraVersion = '5.2.0'
|
||||||
support_version = "28.0.0"
|
support_version = "28.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
<uses-permission android:name="android.permission.INTERNET" />
|
<uses-permission android:name="android.permission.INTERNET" />
|
||||||
|
<uses-permission android:name="com.android.vending.BILLING" />
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:name=".MarkdownApplication"
|
android:name=".MarkdownApplication"
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
package com.wbrawner.simplemarkdown;
|
package com.wbrawner.simplemarkdown;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
||||||
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter;
|
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenter;
|
||||||
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenterImpl;
|
import com.wbrawner.simplemarkdown.presentation.MarkdownPresenterImpl;
|
||||||
|
@ -15,6 +17,11 @@ import dagger.Provides;
|
||||||
|
|
||||||
@Module
|
@Module
|
||||||
public class AppModule {
|
public class AppModule {
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
public AppModule(Context context) {
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
@Provides
|
@Provides
|
||||||
public MarkdownFile provideMarkdownFile() {
|
public MarkdownFile provideMarkdownFile() {
|
||||||
return new MarkdownFile();
|
return new MarkdownFile();
|
||||||
|
@ -22,6 +29,6 @@ public class AppModule {
|
||||||
|
|
||||||
@Provides @Singleton
|
@Provides @Singleton
|
||||||
public MarkdownPresenter provideMarkdownPresenter(MarkdownFile file) {
|
public MarkdownPresenter provideMarkdownPresenter(MarkdownFile file) {
|
||||||
return new MarkdownPresenterImpl(file);
|
return new MarkdownPresenterImpl(context.getApplicationContext(), file);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -67,7 +67,7 @@ public class MarkdownApplication extends Application {
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
component = DaggerAppComponent.builder()
|
component = DaggerAppComponent.builder()
|
||||||
.appModule(new AppModule())
|
.appModule(new AppModule(this))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,8 +78,6 @@ public class MarkdownApplication extends Application {
|
||||||
@Override
|
@Override
|
||||||
protected void attachBaseContext(Context base) {
|
protected void attachBaseContext(Context base) {
|
||||||
super.attachBaseContext(base);
|
super.attachBaseContext(base);
|
||||||
|
|
||||||
// The following line triggers the initialization of ACRA
|
|
||||||
ACRA.init(this);
|
ACRA.init(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,13 +3,15 @@ package com.wbrawner.simplemarkdown.presentation;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
|
import com.android.billingclient.api.BillingClientStateListener;
|
||||||
|
import com.android.billingclient.api.PurchasesUpdatedListener;
|
||||||
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
import com.wbrawner.simplemarkdown.view.MarkdownEditView;
|
||||||
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView;
|
import com.wbrawner.simplemarkdown.view.MarkdownPreviewView;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public interface MarkdownPresenter {
|
public interface MarkdownPresenter extends PurchasesUpdatedListener, BillingClientStateListener {
|
||||||
File getFile();
|
File getFile();
|
||||||
void loadMarkdown();
|
void loadMarkdown();
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,12 @@ import android.database.Cursor;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.android.billingclient.api.BillingClient;
|
||||||
|
import com.android.billingclient.api.BillingClientStateListener;
|
||||||
|
import com.android.billingclient.api.Purchase;
|
||||||
|
import com.android.billingclient.api.PurchasesUpdatedListener;
|
||||||
import com.commonsware.cwac.anddown.AndDown;
|
import com.commonsware.cwac.anddown.AndDown;
|
||||||
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
import com.wbrawner.simplemarkdown.model.MarkdownFile;
|
||||||
import com.wbrawner.simplemarkdown.utility.Utils;
|
import com.wbrawner.simplemarkdown.utility.Utils;
|
||||||
|
@ -18,18 +23,27 @@ import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class MarkdownPresenterImpl implements MarkdownPresenter {
|
public class MarkdownPresenterImpl
|
||||||
|
implements MarkdownPresenter, BillingClientStateListener, PurchasesUpdatedListener {
|
||||||
private final Object fileLock = new Object();
|
private final Object fileLock = new Object();
|
||||||
private MarkdownFile file;
|
private MarkdownFile file;
|
||||||
private volatile MarkdownEditView editView;
|
private volatile MarkdownEditView editView;
|
||||||
private volatile MarkdownPreviewView previewView;
|
private volatile MarkdownPreviewView previewView;
|
||||||
private Handler fileHandler = new Handler();
|
private Handler fileHandler = new Handler();
|
||||||
|
private BillingClient billingClient;
|
||||||
|
|
||||||
public MarkdownPresenterImpl(MarkdownFile file) {
|
public MarkdownPresenterImpl(Context context, MarkdownFile file) {
|
||||||
synchronized (fileLock) {
|
synchronized (fileLock) {
|
||||||
this.file = file;
|
this.file = file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
billingClient = BillingClient.newBuilder(context.getApplicationContext())
|
||||||
|
.setListener(this)
|
||||||
|
.build();
|
||||||
|
billingClient.startConnection(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -242,4 +256,24 @@ public class MarkdownPresenterImpl implements MarkdownPresenter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBillingSetupFinished(int responseCode) {
|
||||||
|
if (responseCode != BillingClient.BillingResponse.OK) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The billing client is ready. You can query purchases here.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBillingServiceDisconnected() {
|
||||||
|
// TODO: Set a flag and just try again later
|
||||||
|
billingClient.startConnection(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue