diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4b3025057..c2d620e35 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -334,7 +334,77 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/java/com/foobnix/LibreraApp.java b/app/src/main/java/com/foobnix/LibreraApp.java index 453302012..a54fff019 100644 --- a/app/src/main/java/com/foobnix/LibreraApp.java +++ b/app/src/main/java/com/foobnix/LibreraApp.java @@ -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; @@ -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() { @@ -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); + } } diff --git a/app/src/main/java/com/foobnix/pdf/info/BookRecommendation.java b/app/src/main/java/com/foobnix/pdf/info/BookRecommendation.java new file mode 100644 index 000000000..794b94350 --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/BookRecommendation.java @@ -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 + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/NightModeManager.java b/app/src/main/java/com/foobnix/pdf/info/NightModeManager.java new file mode 100644 index 000000000..84f69850f --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/NightModeManager.java @@ -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); + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/Prefs.java b/app/src/main/java/com/foobnix/pdf/info/Prefs.java index 6c5792a90..525bc73ec 100644 --- a/app/src/main/java/com/foobnix/pdf/info/Prefs.java +++ b/app/src/main/java/com/foobnix/pdf/info/Prefs.java @@ -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); + } } diff --git a/app/src/main/java/com/foobnix/pdf/info/ProgressTracker.java b/app/src/main/java/com/foobnix/pdf/info/ProgressTracker.java new file mode 100644 index 000000000..74c1ff6f7 --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/ProgressTracker.java @@ -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); + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/ReadingGroup.java b/app/src/main/java/com/foobnix/pdf/info/ReadingGroup.java new file mode 100644 index 000000000..0e50a29e1 --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/ReadingGroup.java @@ -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 + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/ReadingTimer.java b/app/src/main/java/com/foobnix/pdf/info/ReadingTimer.java new file mode 100644 index 000000000..c3fa3563f --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/ReadingTimer.java @@ -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; + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/ReminderManager.java b/app/src/main/java/com/foobnix/pdf/info/ReminderManager.java new file mode 100644 index 000000000..a62ec1bbe --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/ReminderManager.java @@ -0,0 +1,50 @@ +package com.foobnix.pdf.info; + +import android.app.AlarmManager; +import android.app.PendingIntent; +import android.content.Context; +import android.content.Intent; + +public class ReminderManager { + + private static ReminderManager instance; + private Context context; + private AlarmManager alarmManager; + + private ReminderManager(Context context) { + this.context = context; + this.alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); + } + + public static synchronized void init(Context context) { + if (instance == null) { + instance = new ReminderManager(context); + } + } + + public static synchronized ReminderManager getInstance() { + if (instance == null) { + throw new IllegalStateException("ReminderManager is not initialized, call init() method first."); + } + return instance; + } + + public void setReminder(String reminderId, long time) { + Intent intent = new Intent(context, ReminderReceiver.class); + intent.putExtra("reminderId", reminderId); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, reminderId.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); + alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent); + Prefs.get().putReminder(reminderId, time); + } + + public void cancelReminder(String reminderId) { + Intent intent = new Intent(context, ReminderReceiver.class); + PendingIntent pendingIntent = PendingIntent.getBroadcast(context, reminderId.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT); + alarmManager.cancel(pendingIntent); + Prefs.get().putReminder(reminderId, 0); + } + + public long getReminderTime(String reminderId) { + return Prefs.get().getReminder(reminderId); + } +} diff --git a/app/src/main/java/com/foobnix/pdf/info/SurveyManager.java b/app/src/main/java/com/foobnix/pdf/info/SurveyManager.java new file mode 100644 index 000000000..7662c4671 --- /dev/null +++ b/app/src/main/java/com/foobnix/pdf/info/SurveyManager.java @@ -0,0 +1,34 @@ +package com.foobnix.pdf.info; + +import android.content.Context; + +public class SurveyManager { + + private static SurveyManager instance; + private Context context; + + private SurveyManager(Context context) { + this.context = context; + } + + public static synchronized void init(Context context) { + if (instance == null) { + instance = new SurveyManager(context); + } + } + + public static synchronized SurveyManager getInstance() { + if (instance == null) { + throw new IllegalStateException("SurveyManager is not initialized, call init() method first."); + } + return instance; + } + + public void createSurvey(String surveyId, String question, String[] options) { + // Code to create a new survey + } + + public void manageSurvey(String surveyId) { + // Code to manage an existing survey + } +} diff --git a/app/src/main/java/com/foobnix/tts/TTSControlsView.java b/app/src/main/java/com/foobnix/tts/TTSControlsView.java index 541a898b6..f903b1c84 100644 --- a/app/src/main/java/com/foobnix/tts/TTSControlsView.java +++ b/app/src/main/java/com/foobnix/tts/TTSControlsView.java @@ -142,7 +142,7 @@ public void onClick(View v) { } catch (CanceledException e) { LOG.d(e); } - + TTSNotification.updateNotification(context, "Next track"); } }); ttsPrev.setOnClickListener(new OnClickListener() { @@ -155,7 +155,7 @@ public void onClick(View v) { } catch (CanceledException e) { LOG.d(e); } - + TTSNotification.updateNotification(context, "Previous track"); } }); @@ -180,6 +180,7 @@ public void onClick(View v) { Urls.openTTS(getContext()); } else { TTSService.playPause(context, controller); + TTSNotification.updateNotification(context, "Play/Pause"); } } }); diff --git a/app/src/main/java/com/foobnix/tts/TTSNotification.java b/app/src/main/java/com/foobnix/tts/TTSNotification.java index 6f7a798b3..57acc953c 100644 --- a/app/src/main/java/com/foobnix/tts/TTSNotification.java +++ b/app/src/main/java/com/foobnix/tts/TTSNotification.java @@ -101,7 +101,7 @@ public static void show(String bookPath, int page, int maxPages) { try { NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); - NotificationCompat.Builder builder = new NotificationCompat.Builder(context, DEFAULT); + NotificationCompat.Builder builder = createNotificationBuilder(context, bookPath, page, maxPages); FileMeta fileMeta = AppDB.get().getOrCreate(bookPath); @@ -256,5 +256,280 @@ public static void showLast() { } + public static void updateNotification(String bookPath, int page, int maxPages) { + bookPath1 = bookPath; + page1 = page; + pageCount = maxPages; + try { + NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); + + NotificationCompat.Builder builder = createNotificationBuilder(context, bookPath, page, maxPages); + + FileMeta fileMeta = AppDB.get().getOrCreate(bookPath); + + boolean isEasyMode = AppSP.get().readingMode == AppState.READING_MODE_BOOK; + + Intent intent = new Intent(context, isEasyMode ? HorizontalViewActivity.class : VerticalViewActivity.class);//TO-CHECK + intent.setAction(ACTION_TTS); + intent.setData(Uri.fromFile(new File(bookPath))); + if (page > 0) { + intent.putExtra("page", page - 1); + } + + PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + + PendingIntent playPause = PendingIntent.getService(context, 0, new Intent(TTS_PLAY_PAUSE, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent pause = PendingIntent.getService(context, 0, new Intent(TTS_PAUSE, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent play = PendingIntent.getService(context, 0, new Intent(TTS_PLAY, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent next = PendingIntent.getService(context, 0, new Intent(TTS_NEXT, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent prev = PendingIntent.getService(context, 0, new Intent(TTS_PREV, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent stopDestroy = PendingIntent.getService(context, 0, new Intent(TTS_STOP_DESTROY, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_tts_line); + RemoteViews remoteViewsSmall = new RemoteViews(context.getPackageName(), R.layout.notification_tts_line_small); + + + //remoteViews.setImageViewBitmap(R.id.ttsIcon, bookImage); + remoteViews.setOnClickPendingIntent(R.id.ttsPlay, playPause); + remoteViews.setOnClickPendingIntent(R.id.ttsNext, next); + remoteViews.setOnClickPendingIntent(R.id.ttsPrev, prev); + remoteViews.setOnClickPendingIntent(R.id.ttsStop, stopDestroy); + + + //remoteViewsSmall.setImageViewBitmap(R.id.ttsIcon, bookImage); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsPlay, playPause); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsNext, next); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsPrev, prev); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsStop, stopDestroy); + + + remoteViews.setViewVisibility(R.id.ttsNextTrack, View.GONE); + remoteViews.setViewVisibility(R.id.ttsPrevTrack, View.GONE); + + remoteViewsSmall.setViewVisibility(R.id.ttsNextTrack, View.GONE); + remoteViewsSmall.setViewVisibility(R.id.ttsPrevTrack, View.GONE); + + + remoteViews.setViewVisibility(R.id.ttsDialog, View.GONE); + remoteViewsSmall.setViewVisibility(R.id.ttsDialog, View.GONE); + + if (TTSEngine.get().isPlaying()) { + remoteViews.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_174_pause); + remoteViewsSmall.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_174_pause); + } else { + remoteViews.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_175_play); + remoteViewsSmall.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_175_play); + } + + final int color = AppState.get().isUiTextColor ? AppState.get().uiTextColor : AppState.get().tintColor; + + + remoteViews.setInt(R.id.ttsPlay, "setColorFilter", color); + remoteViews.setInt(R.id.ttsNext, "setColorFilter", color); + remoteViews.setInt(R.id.ttsPrev, "setColorFilter", color); + remoteViews.setInt(R.id.ttsStop, "setColorFilter", color); + + remoteViewsSmall.setInt(R.id.ttsPlay, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsNext, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsPrev, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsStop, "setColorFilter", color); + + String fileMetaBookName = TxtUtils.getFileMetaBookName(fileMeta); + + String pageNumber = "(" + TxtUtils.getProgressPercent(page, maxPages) + " " + page + "/" + maxPages + ")"; + + if (page == -1 || maxPages == -1) { + pageNumber = ""; + } + + String textLine = pageNumber + " " + fileMetaBookName; + + if (TxtUtils.isNotEmpty(BookCSS.get().mp3BookPathGet())) { + textLine = "[" + ExtUtils.getFileName(BookCSS.get().mp3BookPathGet()) + "] " + textLine; + } + + remoteViews.setTextViewText(R.id.bookInfo, textLine.replace(TxtUtils.LONG_DASH1 + " ", "\n").trim()); + //remoteViews.setViewVisibility(R.id.bookInfo, View.VISIBLE); + + remoteViewsSmall.setTextViewText(R.id.bookInfo, textLine.trim()); + //remoteViewsSmall.setViewVisibility(R.id.bookInfo, View.VISIBLE); + final String extraText = textLine; + + String url = IMG.toUrl(bookPath, ImageExtractor.COVER_PAGE_NO_EFFECT, IMG.getImageSize()); + + Glide.with(LibreraApp.context).asBitmap().load(url).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + remoteViews.setImageViewBitmap(R.id.ttsIcon, resource); + remoteViewsSmall.setImageViewBitmap(R.id.ttsIcon, resource); + + builder.setContentIntent(contentIntent) // + .setSmallIcon(R.drawable.glyphicons_smileys_100_headphones) // + .setColor(color) + .setOngoing(true)// + .setPriority(NotificationCompat.PRIORITY_HIGH) // + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)// + .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()) + .setSilent(true) + .setCustomBigContentView(remoteViews) /// + .setCustomContentView(remoteViewsSmall); /// + Notification n = builder.build(); // + + nm.notify(NOT_ID, n); + + + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + + + Intent update = new Intent(LibreraApp.context, TTSWidget.class); + update.setAction("android.appwidget.action.APPWIDGET_UPDATE"); + update.putExtra(Intent.EXTRA_TEXT, extraText); + update.putExtra("bookPath", bookPath); + LibreraApp.context.sendBroadcast(update); + } catch (Exception e) { + LOG.e(e); + } + + } + + private static NotificationCompat.Builder createNotificationBuilder(Context context, String bookPath, int page, int maxPages) { + NotificationCompat.Builder builder = new NotificationCompat.Builder(context, DEFAULT); + + FileMeta fileMeta = AppDB.get().getOrCreate(bookPath); + + boolean isEasyMode = AppSP.get().readingMode == AppState.READING_MODE_BOOK; + + Intent intent = new Intent(context, isEasyMode ? HorizontalViewActivity.class : VerticalViewActivity.class);//TO-CHECK + intent.setAction(ACTION_TTS); + intent.setData(Uri.fromFile(new File(bookPath))); + if (page > 0) { + intent.putExtra("page", page - 1); + } + + PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE); + + PendingIntent playPause = PendingIntent.getService(context, 0, new Intent(TTS_PLAY_PAUSE, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent pause = PendingIntent.getService(context, 0, new Intent(TTS_PAUSE, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent play = PendingIntent.getService(context, 0, new Intent(TTS_PLAY, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent next = PendingIntent.getService(context, 0, new Intent(TTS_NEXT, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent prev = PendingIntent.getService(context, 0, new Intent(TTS_PREV, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + PendingIntent stopDestroy = PendingIntent.getService(context, 0, new Intent(TTS_STOP_DESTROY, null, context, TTSService.class), PendingIntent.FLAG_IMMUTABLE); + + RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_tts_line); + RemoteViews remoteViewsSmall = new RemoteViews(context.getPackageName(), R.layout.notification_tts_line_small); + + + //remoteViews.setImageViewBitmap(R.id.ttsIcon, bookImage); + remoteViews.setOnClickPendingIntent(R.id.ttsPlay, playPause); + remoteViews.setOnClickPendingIntent(R.id.ttsNext, next); + remoteViews.setOnClickPendingIntent(R.id.ttsPrev, prev); + remoteViews.setOnClickPendingIntent(R.id.ttsStop, stopDestroy); + + + //remoteViewsSmall.setImageViewBitmap(R.id.ttsIcon, bookImage); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsPlay, playPause); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsNext, next); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsPrev, prev); + remoteViewsSmall.setOnClickPendingIntent(R.id.ttsStop, stopDestroy); + + + remoteViews.setViewVisibility(R.id.ttsNextTrack, View.GONE); + remoteViews.setViewVisibility(R.id.ttsPrevTrack, View.GONE); + + remoteViewsSmall.setViewVisibility(R.id.ttsNextTrack, View.GONE); + remoteViewsSmall.setViewVisibility(R.id.ttsPrevTrack, View.GONE); + + + remoteViews.setViewVisibility(R.id.ttsDialog, View.GONE); + remoteViewsSmall.setViewVisibility(R.id.ttsDialog, View.GONE); + + if (TTSEngine.get().isPlaying()) { + remoteViews.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_174_pause); + remoteViewsSmall.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_174_pause); + } else { + remoteViews.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_175_play); + remoteViewsSmall.setImageViewResource(R.id.ttsPlay, R.drawable.glyphicons_175_play); + } + + final int color = AppState.get().isUiTextColor ? AppState.get().uiTextColor : AppState.get().tintColor; + + + remoteViews.setInt(R.id.ttsPlay, "setColorFilter", color); + remoteViews.setInt(R.id.ttsNext, "setColorFilter", color); + remoteViews.setInt(R.id.ttsPrev, "setColorFilter", color); + remoteViews.setInt(R.id.ttsStop, "setColorFilter", color); + + remoteViewsSmall.setInt(R.id.ttsPlay, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsNext, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsPrev, "setColorFilter", color); + remoteViewsSmall.setInt(R.id.ttsStop, "setColorFilter", color); + + String fileMetaBookName = TxtUtils.getFileMetaBookName(fileMeta); + + String pageNumber = "(" + TxtUtils.getProgressPercent(page, maxPages) + " " + page + "/" + maxPages + ")"; + + if (page == -1 || maxPages == -1) { + pageNumber = ""; + } + + String textLine = pageNumber + " " + fileMetaBookName; + + if (TxtUtils.isNotEmpty(BookCSS.get().mp3BookPathGet())) { + textLine = "[" + ExtUtils.getFileName(BookCSS.get().mp3BookPathGet()) + "] " + textLine; + } + + remoteViews.setTextViewText(R.id.bookInfo, textLine.replace(TxtUtils.LONG_DASH1 + " ", "\n").trim()); + //remoteViews.setViewVisibility(R.id.bookInfo, View.VISIBLE); + + remoteViewsSmall.setTextViewText(R.id.bookInfo, textLine.trim()); + //remoteViewsSmall.setViewVisibility(R.id.bookInfo, View.VISIBLE); + final String extraText = textLine; + + String url = IMG.toUrl(bookPath, ImageExtractor.COVER_PAGE_NO_EFFECT, IMG.getImageSize()); + + Glide.with(LibreraApp.context).asBitmap().load(url).into(new CustomTarget() { + @Override + public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition transition) { + remoteViews.setImageViewBitmap(R.id.ttsIcon, resource); + remoteViewsSmall.setImageViewBitmap(R.id.ttsIcon, resource); + + builder.setContentIntent(contentIntent) // + .setSmallIcon(R.drawable.glyphicons_smileys_100_headphones) // + .setColor(color) + .setOngoing(true)// + .setPriority(NotificationCompat.PRIORITY_HIGH) // + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)// + .setStyle(new androidx.media.app.NotificationCompat.MediaStyle()) + .setSilent(true) + .setCustomBigContentView(remoteViews) /// + .setCustomContentView(remoteViewsSmall); /// + Notification n = builder.build(); // + + nm.notify(NOT_ID, n); + + + } + + @Override + public void onLoadCleared(@Nullable Drawable placeholder) { + + } + }); + + + Intent update = new Intent(LibreraApp.context, TTSWidget.class); + update.setAction("android.appwidget.action.APPWIDGET_UPDATE"); + update.putExtra(Intent.EXTRA_TEXT, extraText); + update.putExtra("bookPath", bookPath); + LibreraApp.context.sendBroadcast(update); + + return builder; + } } diff --git a/app/src/main/java/com/foobnix/tts/TTSService.java b/app/src/main/java/com/foobnix/tts/TTSService.java index 1af941941..5a66cd6b1 100644 --- a/app/src/main/java/com/foobnix/tts/TTSService.java +++ b/app/src/main/java/com/foobnix/tts/TTSService.java @@ -724,7 +724,7 @@ public void onUtteranceCompleted(String utteranceId) { TTSEngine.get().speek(firstPart); - TTSNotification.show(AppSP.get().lastBookPath, pageNumber + 1, dc.getPageCount()); + TTSNotification.updateNotification(AppSP.get().lastBookPath, pageNumber + 1, dc.getPageCount()); LOG.d("TtsStatus send"); EventBus.getDefault().post(new TtsStatus());