Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed app crashing for android api verison < 26 #199

Merged
merged 4 commits into from
May 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion folioreader/build.gradle
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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);
}
}
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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