Skip to content

Commit

Permalink
- default read locator
Browse files Browse the repository at this point in the history
  • Loading branch information
oguzhanaslann committed Oct 10, 2023
1 parent 2815834 commit 71be31b
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
1 change: 1 addition & 0 deletions folioreader/src/main/java/com/folioreader/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public class Constants {
public static final int WRITE_EXTERNAL_STORAGE_REQUEST = 102;
public static final String CHAPTER_ID = "id";
public static final String HREF = "href";
public static final String LAST_READ_LOCATOR = "com.folioreader.model.locators.last_read_locator";

public static String[] getWriteExternalStoragePerms() {
return new String[]{
Expand Down
51 changes: 37 additions & 14 deletions folioreader/src/main/java/com/folioreader/FolioReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.content.IntentFilter;
import android.os.Parcelable;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
Expand All @@ -20,6 +21,7 @@
import com.folioreader.ui.activity.FolioActivity;
import com.folioreader.ui.base.OnSaveHighlight;
import com.folioreader.ui.base.SaveReceivedHighlightTask;
import com.folioreader.util.DefaultReadLocatorManager;
import com.folioreader.util.OnHighlightListener;
import com.folioreader.util.ReadLocatorListener;

Expand Down Expand Up @@ -125,12 +127,18 @@ private FolioReader(Context context) {
DbAdapter.initialize(context);

LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(context);
localBroadcastManager.registerReceiver(highlightReceiver,
new IntentFilter(HighlightImpl.BROADCAST_EVENT));
localBroadcastManager.registerReceiver(readLocatorReceiver,
new IntentFilter(ACTION_SAVE_READ_LOCATOR));
localBroadcastManager.registerReceiver(closedReceiver,
new IntentFilter(ACTION_FOLIOREADER_CLOSED));
localBroadcastManager.registerReceiver(
highlightReceiver,
new IntentFilter(HighlightImpl.BROADCAST_EVENT)
);
localBroadcastManager.registerReceiver(
readLocatorReceiver,
new IntentFilter(ACTION_SAVE_READ_LOCATOR)
);
localBroadcastManager.registerReceiver(
closedReceiver,
new IntentFilter(ACTION_FOLIOREADER_CLOSED)
);
}

public FolioReader openBook(String deviceStoragePath, boolean isInternalStorage) {
Expand Down Expand Up @@ -185,19 +193,25 @@ private Intent getIntentFromUrl(String path, int rawId, boolean isInternalStorag

if (rawId != 0) {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, rawId);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.RAW);
intent.putExtra(
FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.RAW
);
} else if (path.contains(Constants.ASSET)) {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, path);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.ASSETS);
intent.putExtra(
FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.ASSETS
);
} else {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, path);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.DEVICE_STORAGE);
intent.putExtra(
FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.DEVICE_STORAGE
);
}

intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_STORAGE_TYPE,isInternalStorage);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_STORAGE_TYPE, isInternalStorage);


return intent;
Expand Down Expand Up @@ -237,7 +251,8 @@ public static void initRetrofit(String streamerUrl) {
.baseUrl(streamerUrl)
.addConverterFactory(new QualifiedTypeConverterFactory(
JacksonConverterFactory.create(),
GsonConverterFactory.create()))
GsonConverterFactory.create()
))
.client(client)
.build();

Expand All @@ -254,6 +269,14 @@ public FolioReader setReadLocatorListener(ReadLocatorListener readLocatorListene
return singleton;
}


public FolioReader defaultReadLocator(@NonNull final Context context) {
DefaultReadLocatorManager defaultReadLocatorManager = new DefaultReadLocatorManager(context);
setReadLocatorListener(defaultReadLocatorManager);
setReadLocator(defaultReadLocatorManager.getLastReadLocator());
return singleton;
}

public FolioReader setOnClosedListener(OnClosedListener onClosedListener) {
this.onClosedListener = onClosedListener;
return singleton;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.folioreader.ui.activity;

import android.graphics.Rect;

import com.folioreader.Config;
import com.folioreader.model.DisplayUnit;
import com.folioreader.model.locators.ReadLocator;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.folioreader.util

import android.content.Context
import com.folioreader.Constants
import com.folioreader.model.locators.ReadLocator

class DefaultReadLocatorManager(private val context: Context) : ReadLocatorListener {
override fun saveReadLocator(readLocator: ReadLocator?) {
val locator = readLocator ?: return
SharedPreferenceUtil.putSharedPreferencesString(
context,
Constants.LAST_READ_LOCATOR,
readLocator.toJson()
)
}

fun getLastReadLocator(): ReadLocator? {
return ReadLocator.fromJson(
SharedPreferenceUtil.getSharedPreferencesString(
context,
Constants.LAST_READ_LOCATOR,
null
)
)
}
}

0 comments on commit 71be31b

Please sign in to comment.