Skip to content

Commit

Permalink
Merge pull request #199 from codetoart/master
Browse files Browse the repository at this point in the history
Fixed app crashing for android api verison < 26
  • Loading branch information
Mahavir Jain committed May 4, 2018
2 parents dd6bb68 + 397af03 commit dcdff42
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 7 deletions.
2 changes: 1 addition & 1 deletion folioreader/build.gradle
Expand Up @@ -15,7 +15,7 @@ ext {
siteUrl = 'https://github.com/FolioReader/FolioReader-Android'
gitUrl = 'https://github.com/FolioReader/FolioReader-Android.git'

libraryVersion = '0.3.7'
libraryVersion = '0.3.8'

developerId = 'mobisystech'
developerName = 'Folio Reader'
Expand Down
32 changes: 30 additions & 2 deletions folioreader/src/main/java/com/folioreader/FolioReader.java
Expand Up @@ -5,6 +5,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.os.Parcelable;
import android.support.v4.content.LocalBroadcastManager;

Expand Down Expand Up @@ -79,7 +80,7 @@ private FolioReader() {

private FolioReader(Context context) {
this.context = context;
new DbAdapter(context);
DbAdapter.initialize(context);
LocalBroadcastManager.getInstance(context).registerReceiver(highlightReceiver,
new IntentFilter(HighlightImpl.BROADCAST_EVENT));
LocalBroadcastManager.getInstance(context).registerReceiver(readPositionReceiver,
Expand Down Expand Up @@ -157,6 +158,8 @@ public FolioReader openBook(String assetOrSdcardPath, Config config, String book
private Intent getIntentFromUrl(String assetOrSdcardPath, int rawId) {

Intent intent = new Intent(context, FolioActivity.class);
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.M)
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
intent.putExtra(FolioActivity.EXTRA_READ_POSITION, (Parcelable) readPosition);

if (rawId != 0) {
Expand Down Expand Up @@ -192,12 +195,37 @@ public void saveReceivedHighLights(List<HighLight> highlights, OnSaveHighlight o
new SaveReceivedHighlightTask(onSaveHighlight, highlights).execute();
}

public static void clear() {
/**
* Nullifies readPosition and listeners.
* This method ideally should be used in onDestroy() of Activity or Fragment.
* Use this method if you want to use FolioReader singleton instance again in the application,
* else use {@link #stop()} which destruct the FolioReader singleton instance.
*/
public static synchronized void clear() {

if (singleton != null) {
singleton.readPosition = null;
singleton.onHighlightListener = null;
singleton.readPositionListener = null;
}
}

/**
* Destructs the FolioReader singleton instance.
* Use this method only if you are sure that you won't need to use
* FolioReader singleton instance again in application, else use {@link #clear()}.
*/
public static synchronized void stop() {

if (singleton != null) {
DbAdapter.terminate();
singleton.unregisterListeners();
singleton = null;
}
}

private void unregisterListeners() {
LocalBroadcastManager.getInstance(context).unregisterReceiver(highlightReceiver);
LocalBroadcastManager.getInstance(context).unregisterReceiver(readPositionReceiver);
}
}
Expand Up @@ -9,14 +9,16 @@
public class DbAdapter {
private static final String TAG = "DBAdapter";

private Context mContext;
public static SQLiteDatabase mDatabase;

public DbAdapter(Context ctx) {
this.mContext = ctx;
public static void initialize(Context mContext) {
mDatabase = FolioDatabaseHelper.getInstance(mContext).getMyWritableDatabase();
}

public static void terminate() {
FolioDatabaseHelper.clearInstance();
}

public static boolean insert(String table, ContentValues contentValues) {

return mDatabase.insert(table, null, contentValues) > 0;
Expand Down
Expand Up @@ -30,6 +30,10 @@ public static FolioDatabaseHelper getInstance(Context context) {
return mInstance;
}

public static void clearInstance() {
mInstance = null;
}

public SQLiteDatabase getMyWritableDatabase() {
if ((myWritableDb == null) || (!myWritableDb.isOpen())) {
myWritableDb = this.getWritableDatabase();
Expand Down
2 changes: 1 addition & 1 deletion webViewMarker/build.gradle
Expand Up @@ -13,7 +13,7 @@ ext {
siteUrl = 'https://github.com/FolioReader/FolioReader-Android'
gitUrl = 'https://github.com/FolioReader/FolioReader-Android.git'

libraryVersion = '0.3.7'
libraryVersion = '0.3.8'

developerId = 'mobisystech'
developerName = 'Folio Reader'
Expand Down

0 comments on commit dcdff42

Please sign in to comment.