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

Compile problems solved and little capabilities added #518

Open
wants to merge 18 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions folioreader/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns:tools="http://schemas.android.com/tools"
package="com.folioreader">

<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-sdk tools:overrideLibrary="org.readium.r2.streamer, org.readium.r2.shared" />
Expand All @@ -21,14 +21,17 @@
<activity
android:name="com.folioreader.ui.activity.FolioActivity"
android:label="@string/app_name"
android:exported="true"
android:theme="@style/FolioActivityDayTheme" />

<activity
android:name="com.folioreader.ui.activity.ContentHighlightActivity"
android:exported="true"
android:theme="@style/AppTheme.NoActionBar" />

<activity
android:name="com.folioreader.ui.activity.SearchActivity"
android:exported="true"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
Expand All @@ -40,4 +43,4 @@

</application>

</manifest>
</manifest>
4 changes: 2 additions & 2 deletions folioreader/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ dependencies {
implementation "com.squareup.retrofit2:converter-gson:$versions.retrofit"

// R2 modules
api("com.github.codetoart:r2-shared-kotlin:$versions.r2SharedKotlin") {
implementation("com.github.codetoart:r2-shared-kotlin:$versions.r2SharedKotlin") {
changing = true
}
api("com.github.codetoart:r2-streamer-kotlin:$versions.r2StreamerKotlin") {
implementation("com.github.codetoart:r2-streamer-kotlin:$versions.r2StreamerKotlin") {
exclude group: "org.slf4j", module: "slf4j-api"
changing = true
}
Expand Down
4 changes: 2 additions & 2 deletions folioreader/res/layout/progress_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
android:id="@+id/loading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="?android:attr/android:progressBarStyle" />
/>

<TextView
android:id="@+id/label_loading"
Expand All @@ -25,4 +25,4 @@
android:textColor="@android:color/white"
android:text="@string/loading" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
16 changes: 14 additions & 2 deletions folioreader/src/main/java/com/folioreader/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class Config implements Parcelable {
public static final String CONFIG_IS_NIGHT_MODE = "is_night_mode";
public static final String CONFIG_THEME_COLOR_INT = "theme_color_int";
public static final String CONFIG_IS_TTS = "is_tts";
public static final String CONFIG_IS_SEARCH = "is_search";
public static final String CONFIG_ALLOWED_DIRECTION = "allowed_direction";
public static final String CONFIG_DIRECTION = "direction";
private static final AllowedDirection DEFAULT_ALLOWED_DIRECTION = AllowedDirection.ONLY_VERTICAL;
Expand All @@ -38,6 +39,7 @@ public class Config implements Parcelable {
private boolean showTts = true;
private AllowedDirection allowedDirection = DEFAULT_ALLOWED_DIRECTION;
private Direction direction = DEFAULT_DIRECTION;
private boolean showSearch = true;

/**
* Reading modes available
Expand Down Expand Up @@ -77,6 +79,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeByte((byte) (nightMode ? 1 : 0));
dest.writeInt(themeColor);
dest.writeByte((byte) (showTts ? 1 : 0));
dest.writeByte((byte) (showSearch ? 1 : 0));
dest.writeString(allowedDirection.toString());
dest.writeString(direction.toString());
}
Expand All @@ -87,6 +90,7 @@ protected Config(Parcel in) {
nightMode = in.readByte() != 0;
themeColor = in.readInt();
showTts = in.readByte() != 0;
showSearch = in.readByte() != 0;
allowedDirection = getAllowedDirectionFromString(LOG_TAG, in.readString());
direction = getDirectionFromString(LOG_TAG, in.readString());
}
Expand All @@ -100,6 +104,7 @@ public Config(JSONObject jsonObject) {
nightMode = jsonObject.optBoolean(CONFIG_IS_NIGHT_MODE);
themeColor = getValidColorInt(jsonObject.optInt(CONFIG_THEME_COLOR_INT));
showTts = jsonObject.optBoolean(CONFIG_IS_TTS);
showSearch = jsonObject.optBoolean(CONFIG_IS_SEARCH);
allowedDirection = getAllowedDirectionFromString(LOG_TAG,
jsonObject.optString(CONFIG_ALLOWED_DIRECTION));
direction = getDirectionFromString(LOG_TAG, jsonObject.optString(CONFIG_DIRECTION));
Expand Down Expand Up @@ -205,6 +210,14 @@ public Config setShowTts(boolean showTts) {
return this;
}

public boolean isShowSearch() {
return showSearch;
}

public void setShowSearch(boolean showSearch) {
this.showSearch = showSearch;
}

public AllowedDirection getAllowedDirection() {
return allowedDirection;
}
Expand Down Expand Up @@ -288,10 +301,9 @@ public String toString() {
", nightMode=" + nightMode +
", themeColor=" + themeColor +
", showTts=" + showTts +
", showSearch=" + showSearch +
", allowedDirection=" + allowedDirection +
", direction=" + direction +
'}';
}
}


52 changes: 37 additions & 15 deletions folioreader/src/main/java/com/folioreader/FolioReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Parcelable;

import androidx.annotation.Nullable;
import androidx.annotation.RawRes;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;

import com.folioreader.model.HighLight;
import com.folioreader.model.HighlightImpl;
import com.folioreader.model.locators.ReadLocator;
Expand All @@ -19,14 +22,15 @@
import com.folioreader.ui.base.SaveReceivedHighlightTask;
import com.folioreader.util.OnHighlightListener;
import com.folioreader.util.ReadLocatorListener;

import java.util.List;
import java.util.concurrent.TimeUnit;

import okhttp3.OkHttpClient;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
import retrofit2.converter.jackson.JacksonConverterFactory;

import java.util.List;
import java.util.concurrent.TimeUnit;

/**
* Created by avez raj on 9/13/2017.
*/
Expand Down Expand Up @@ -129,33 +133,48 @@ private FolioReader(Context context) {
new IntentFilter(ACTION_FOLIOREADER_CLOSED));
}

public FolioReader openBook(String assetOrSdcardPath) {
Intent intent = getIntentFromUrl(assetOrSdcardPath, 0);
public FolioReader openBook(String deviceStoragePath, boolean isInternalStorage) {
Intent intent = getIntentFromUrl(deviceStoragePath, 0, isInternalStorage);
context.startActivity(intent);
return singleton;
}

public FolioReader openBook(String assetPath) {
Intent intent = getIntentFromUrl(assetPath, 0, true);
context.startActivity(intent);
return singleton;
}

public FolioReader openBook(int rawId) {
Intent intent = getIntentFromUrl(null, rawId);
public FolioReader openBook(@RawRes int rawId) {
Intent intent = getIntentFromUrl(null, rawId, true);
context.startActivity(intent);
return singleton;
}

public FolioReader openBook(String assetOrSdcardPath, String bookId) {
Intent intent = getIntentFromUrl(assetOrSdcardPath, 0);
public FolioReader openBook(String assetPath, String bookId) {
Intent intent = getIntentFromUrl(assetPath, 0, true);
intent.putExtra(EXTRA_BOOK_ID, bookId);
context.startActivity(intent);
return singleton;
}


public FolioReader openBook(String deviceStoragePath, boolean isInternalStorage, String bookId) {
Intent intent = getIntentFromUrl(deviceStoragePath, 0, isInternalStorage);
intent.putExtra(EXTRA_BOOK_ID, bookId);
context.startActivity(intent);
return singleton;
}


public FolioReader openBook(int rawId, String bookId) {
Intent intent = getIntentFromUrl(null, rawId);
Intent intent = getIntentFromUrl(null, rawId, true);
intent.putExtra(EXTRA_BOOK_ID, bookId);
context.startActivity(intent);
return singleton;
}

private Intent getIntentFromUrl(String assetOrSdcardPath, int rawId) {
private Intent getIntentFromUrl(String path, int rawId, boolean isInternalStorage) {

Intent intent = new Intent(context, FolioActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand All @@ -168,16 +187,19 @@ private Intent getIntentFromUrl(String assetOrSdcardPath, int rawId) {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, rawId);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.RAW);
} else if (assetOrSdcardPath.contains(Constants.ASSET)) {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, assetOrSdcardPath);
} else if (path.contains(Constants.ASSET)) {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, path);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.ASSETS);
} else {
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, assetOrSdcardPath);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_PATH, path);
intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_TYPE,
FolioActivity.EpubSourceType.SD_CARD);
FolioActivity.EpubSourceType.DEVICE_STORAGE);
}

intent.putExtra(FolioActivity.INTENT_EPUB_SOURCE_STORAGE_TYPE,isInternalStorage);


return intent;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,25 +104,27 @@ public void setTextToSpeech(final Context context) {
mTextToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
mTextToSpeech.setLanguage(Locale.UK);
mTextToSpeech.setSpeechRate(0.70f);
}
if (mTextToSpeech != null) {
if (status != TextToSpeech.ERROR) {
mTextToSpeech.setLanguage(Locale.UK);
mTextToSpeech.setSpeechRate(0.70f);
}

mTextToSpeech.setOnUtteranceCompletedListener(
new TextToSpeech.OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
((AppCompatActivity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (mIsSpeaking) {
callbacks.highLightTTS();
mTextToSpeech.setOnUtteranceCompletedListener(
new TextToSpeech.OnUtteranceCompletedListener() {
@Override
public void onUtteranceCompleted(String utteranceId) {
((AppCompatActivity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
if (mIsSpeaking) {
callbacks.highLightTTS();
}
}
}
});
}
});
});
}
});
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ open class ReadLocator : Locator, Parcelable {
parcel.readSerializable() as LocatorText?
)

override fun writeToParcel(dest: Parcel?, flags: Int) {
override fun writeToParcel(dest: Parcel, flags: Int) {
dest?.writeString(bookId)
dest?.writeString(href)
dest?.writeLong(created)
Expand Down Expand Up @@ -94,4 +94,4 @@ open class ReadLocator : Locator, Parcelable {
null
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import android.database.SQLException;
import android.database.sqlite.SQLiteDatabase;

import androidx.annotation.Nullable;

public class DbAdapter {
private static final String TAG = "DBAdapter";

Expand Down Expand Up @@ -80,7 +82,11 @@ public static boolean updateHighLight(ContentValues highlightContentValues, Stri
return mDatabase.update(HighLightTable.TABLE_NAME, highlightContentValues, HighLightTable.ID + " = " + id, null) > 0;
}

@Nullable
public static Cursor getHighlightsForPageId(String query, String pageId) {
if (mDatabase == null) {
return null;
}
return mDatabase.rawQuery(query, null);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;

import com.folioreader.Constants;
import com.folioreader.model.HighLight;
import com.folioreader.model.HighlightImpl;

import org.jetbrains.annotations.NotNull;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.UUID;

@SuppressWarnings("PMD.AvoidDuplicateLiterals")
public class HighLightTable {
Expand Down Expand Up @@ -110,14 +117,20 @@ public static boolean deleteHighlight(int highlightId) {
return DbAdapter.deleteById(TABLE_NAME, ID, String.valueOf(highlightId));
}

@NotNull
public static List<String> getHighlightsForPageId(String pageId) {
String query = "SELECT " + COL_RANGY + " FROM " + TABLE_NAME + " WHERE " + COL_PAGE_ID + " = \"" + pageId + "\"";
Cursor c = DbAdapter.getHighlightsForPageId(query, pageId);
List<String> rangyList = new ArrayList<>();
while (c.moveToNext()) {
rangyList.add(c.getString(c.getColumnIndex(COL_RANGY)));
if (c != null) {
while (c.moveToNext()) {
int index = c.getColumnIndex(COL_RANGY);
if (index >= 0) {
rangyList.add(c.getString(index));
}
}
c.close();
}
c.close();
return rangyList;
}

Expand Down Expand Up @@ -190,6 +203,3 @@ public static void saveHighlightIfNotExists(HighLight highLight) {
}
}
}



Loading