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

Update TTS notification #1322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
72 changes: 71 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,77 @@

</activity>

<receiver
<activity
android:name="com.foobnix.pdf.info.ProgressTrackerActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.ReadingGroupActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.SurveyManagerActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.ReadingTimerActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.ReminderManagerActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.NightModeManagerActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<activity
android:name="com.foobnix.pdf.info.BookRecommendationActivity"
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
android:exported="true"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan">
</activity>

<service
android:name="com.foobnix.pdf.info.NotificationService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false">
</service>

<service
android:name="com.foobnix.pdf.info.BackgroundTaskService"
android:enabled="true"
android:foregroundServiceType="dataSync"
android:exported="false">
</service>

<receiver
android:name=".widget.TTSWidget"
android:exported="false"
android:label="${appName}">
Expand Down
29 changes: 29 additions & 0 deletions app/src/main/java/com/foobnix/LibreraApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
import com.foobnix.pdf.info.AppsConfig;
import com.foobnix.pdf.info.IMG;
import com.foobnix.pdf.info.Prefs;
import com.foobnix.pdf.info.ProgressTracker;
import com.foobnix.pdf.info.ReadingGroup;
import com.foobnix.pdf.info.SurveyManager;
import com.foobnix.pdf.info.ReadingTimer;
import com.foobnix.pdf.info.ReminderManager;
import com.foobnix.pdf.info.NightModeManager;
import com.foobnix.pdf.info.BookRecommendation;
import com.foobnix.pdf.info.NotificationService;
import com.foobnix.pdf.info.BackgroundTaskService;
import com.foobnix.pdf.info.TintUtil;
import com.foobnix.tts.TTSNotification;
import com.google.android.gms.ads.MobileAds;
Expand Down Expand Up @@ -59,6 +68,15 @@ public void onCreate() {
Dips.init(this);
Prefs.get().init(this);

// Initialize new features
ProgressTracker.init(this);
ReadingGroup.init(this);
SurveyManager.init(this);
ReadingTimer.init(this);
ReminderManager.init(this);
NightModeManager.init(this);
BookRecommendation.init(this);

try {
if (!AppsConfig.checkIsProInstalled(this)) {
MobileAds.initialize(this, new OnInitializationCompleteListener() {
Expand Down Expand Up @@ -147,4 +165,15 @@ public void onTrimMemory(int level) {
super.onTrimMemory(level);
LOG.d("onTrimMemory", level);
}

// Add methods to handle notifications and background tasks
public static void startNotificationService() {
Intent intent = new Intent(context, NotificationService.class);
context.startService(intent);
}

public static void startBackgroundTaskService() {
Intent intent = new Intent(context, BackgroundTaskService.class);
context.startService(intent);
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/BookRecommendation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.foobnix.pdf.info;

import android.content.Context;

public class BookRecommendation {

private static BookRecommendation instance;
private Context context;

private BookRecommendation(Context context) {
this.context = context;
}

public static synchronized void init(Context context) {
if (instance == null) {
instance = new BookRecommendation(context);
}
}

public static synchronized BookRecommendation getInstance() {
if (instance == null) {
throw new IllegalStateException("BookRecommendation is not initialized, call init() method first.");
}
return instance;
}

public void generateRecommendations(String userId) {
// Code to generate book recommendations based on user interests
}

public void getRecommendations(String userId) {
// Code to retrieve book recommendations for the user
}
}
48 changes: 48 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/NightModeManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.foobnix.pdf.info;

import android.content.Context;
import android.content.SharedPreferences;

public class NightModeManager {

private static final String PREFS_NAME = "NightModePrefs";
private static final String NIGHT_MODE_ENABLED = "NightModeEnabled";
private static final String FONT_SIZE = "FontSize";
private static final String BACKGROUND_COLOR = "BackgroundColor";

private SharedPreferences sharedPreferences;

public NightModeManager(Context context) {
sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
}

public void enableNightMode(boolean enable) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putBoolean(NIGHT_MODE_ENABLED, enable);
editor.apply();
}

public boolean isNightModeEnabled() {
return sharedPreferences.getBoolean(NIGHT_MODE_ENABLED, false);
}

public void setFontSize(int size) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(FONT_SIZE, size);
editor.apply();
}

public int getFontSize() {
return sharedPreferences.getInt(FONT_SIZE, 16);
}

public void setBackgroundColor(int color) {
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(BACKGROUND_COLOR, color);
editor.apply();
}

public int getBackgroundColor() {
return sharedPreferences.getInt(BACKGROUND_COLOR, 0xFFFFFF);
}
}
17 changes: 17 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/Prefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,21 @@ public void remove(String path, int page) {
sp.edit().remove(makeHash(path, page)).commit();
}

// Add methods to store and retrieve progress tracking data
public void putProgress(String bookId, int progress) {
sp.edit().putInt("progress_" + bookId, progress).commit();
}

public int getProgress(String bookId) {
return sp.getInt("progress_" + bookId, 0);
}

// Add methods to store and retrieve reminder settings
public void putReminder(String reminderId, long time) {
sp.edit().putLong("reminder_" + reminderId, time).commit();
}

public long getReminder(String reminderId) {
return sp.getLong("reminder_" + reminderId, 0);
}
}
34 changes: 34 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/ProgressTracker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.foobnix.pdf.info;

import android.content.Context;

public class ProgressTracker {

private static ProgressTracker instance;
private Context context;

private ProgressTracker(Context context) {
this.context = context;
}

public static synchronized void init(Context context) {
if (instance == null) {
instance = new ProgressTracker(context);
}
}

public static synchronized ProgressTracker getInstance() {
if (instance == null) {
throw new IllegalStateException("ProgressTracker is not initialized, call init() method first.");
}
return instance;
}

public void updateProgress(String bookId, int progress) {
Prefs.get().putProgress(bookId, progress);
}

public int getProgress(String bookId) {
return Prefs.get().getProgress(bookId);
}
}
38 changes: 38 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/ReadingGroup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.foobnix.pdf.info;

import android.content.Context;

public class ReadingGroup {

private static ReadingGroup instance;
private Context context;

private ReadingGroup(Context context) {
this.context = context;
}

public static synchronized void init(Context context) {
if (instance == null) {
instance = new ReadingGroup(context);
}
}

public static synchronized ReadingGroup getInstance() {
if (instance == null) {
throw new IllegalStateException("ReadingGroup is not initialized, call init() method first.");
}
return instance;
}

public void createGroup(String groupName) {
// Code to create a new reading group
}

public void joinGroup(String groupId) {
// Code to join an existing reading group
}

public void manageGroup(String groupId) {
// Code to manage a reading group
}
}
43 changes: 43 additions & 0 deletions app/src/main/java/com/foobnix/pdf/info/ReadingTimer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.foobnix.pdf.info;

import android.content.Context;
import android.os.SystemClock;

public class ReadingTimer {

private static ReadingTimer instance;
private Context context;
private long startTime;
private long totalTime;

private ReadingTimer(Context context) {
this.context = context;
this.totalTime = 0;
}

public static synchronized void init(Context context) {
if (instance == null) {
instance = new ReadingTimer(context);
}
}

public static synchronized ReadingTimer getInstance() {
if (instance == null) {
throw new IllegalStateException("ReadingTimer is not initialized, call init() method first.");
}
return instance;
}

public void start() {
startTime = SystemClock.elapsedRealtime();
}

public void stop() {
long endTime = SystemClock.elapsedRealtime();
totalTime += (endTime - startTime);
}

public long getTotalTime() {
return totalTime;
}
}
Loading