enable auto sync by default / add preview of new items in notification

Signed-off-by: David Luhmer <david-dev@live.de>
This commit is contained in:
David-Development 2020-09-15 19:55:29 +02:00 committed by David Luhmer
parent 5ff9c289d7
commit 7641dea377
3 changed files with 32 additions and 13 deletions

View file

@ -14,12 +14,13 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ListView; import android.widget.ListView;
import javax.inject.Inject;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import javax.inject.Inject;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import de.luhmer.owncloudnewsreader.authentication.AccountGeneral; import de.luhmer.owncloudnewsreader.authentication.AccountGeneral;
@ -94,7 +95,7 @@ public class SyncIntervalSelectorActivity extends AppCompatActivity {
public static void setAccountSyncInterval(Context context, SharedPreferences mPrefs) { public static void setAccountSyncInterval(Context context, SharedPreferences mPrefs) {
int minutes = mPrefs.getInt(SYNC_INTERVAL_IN_MINUTES_STRING, 0); int minutes = mPrefs.getInt(SYNC_INTERVAL_IN_MINUTES_STRING, 1440);
AccountManager mAccountManager = AccountManager.get(context); AccountManager mAccountManager = AccountManager.get(context);
Account[] accounts = mAccountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); Account[] accounts = mAccountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);
@ -158,11 +159,11 @@ public class SyncIntervalSelectorActivity extends AppCompatActivity {
lvItems.setAdapter(adapter); lvItems.setAdapter(adapter);
if(!mPrefs.contains(SYNC_INTERVAL_IN_MINUTES_STRING)) if(!mPrefs.contains(SYNC_INTERVAL_IN_MINUTES_STRING)) {
lvItems.setItemChecked(items.length - 1, true);//The last item is 24hours. This is the default value! lvItems.setItemChecked(items.length - 1, true); // The last item is 24hours. This is the default value!
else { } else {
int position = 0; int position = 0;
int minutes = mPrefs.getInt(SYNC_INTERVAL_IN_MINUTES_STRING, 0); int minutes = mPrefs.getInt(SYNC_INTERVAL_IN_MINUTES_STRING, 1440);
for(String item : ((SyncIntervalSelectorActivity)getActivity()).items_values) { for(String item : ((SyncIntervalSelectorActivity)getActivity()).items_values) {
if(Integer.parseInt(item) == minutes) if(Integer.parseInt(item) == minutes)
break; break;

View file

@ -353,6 +353,10 @@ public class DatabaseConnectionOrm {
return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).limit(100).orderDesc(RssItemDao.Properties.PubDate).listLazy(); return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).limit(100).orderDesc(RssItemDao.Properties.PubDate).listLazy();
} }
public LazyList<RssItem> getAllUnreadRssItemsForNotification() {
return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).limit(6).orderDesc(RssItemDao.Properties.PubDate).listLazy();
}
public LazyList<RssItem> getAllUnreadRssItemsForDownloadWebPageService() { public LazyList<RssItem> getAllUnreadRssItemsForDownloadWebPageService() {
return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).orderDesc(RssItemDao.Properties.PubDate).listLazy(); return daoSession.getRssItemDao().queryBuilder().where(RssItemDao.Properties.Read_temp.eq(false)).orderDesc(RssItemDao.Properties.PubDate).listLazy();
} }

View file

@ -12,25 +12,30 @@ import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.service.notification.StatusBarNotification; import android.service.notification.StatusBarNotification;
import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import android.support.v4.media.MediaDescriptionCompat; import android.support.v4.media.MediaDescriptionCompat;
import android.support.v4.media.MediaMetadataCompat; import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat; import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat; import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat; import android.support.v4.media.session.PlaybackStateCompat;
import android.text.TextUtils;
import androidx.media.session.MediaButtonReceiver; import androidx.core.app.NotificationCompat;
import androidx.core.content.FileProvider;
import androidx.media.app.NotificationCompat.MediaStyle; import androidx.media.app.NotificationCompat.MediaStyle;
import androidx.media.session.MediaButtonReceiver;
import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.assist.ImageSize;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.List;
import de.luhmer.owncloudnewsreader.BuildConfig; import de.luhmer.owncloudnewsreader.BuildConfig;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity; import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R; import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
public class NextcloudNotificationManager { public class NextcloudNotificationManager {
@ -252,16 +257,25 @@ public class NextcloudNotificationManager {
Resources res = context.getResources(); Resources res = context.getResources();
String tickerMessage = res.getQuantityString(R.plurals.notification_new_items_ticker, newItemsCount, newItemsCount); String tickerMessage = res.getQuantityString(R.plurals.notification_new_items_ticker, newItemsCount, newItemsCount);
String contentText = res.getQuantityString(R.plurals.notification_new_items_text, newItemsCount, newItemsCount); String contentText = res.getQuantityString(R.plurals.notification_new_items_text, newItemsCount, newItemsCount);
String title = context.getString(R.string.app_name);
String channelId = context.getString(R.string.app_name); String channelId = context.getString(R.string.app_name);
NotificationManager notificationManager = getNotificationManagerAndCreateChannel(context, channelId); NotificationManager notificationManager = getNotificationManagerAndCreateChannel(context, channelId);
DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(context);
List<RssItem> items = dbConn.getAllUnreadRssItemsForNotification();
List<String> previewLines = new ArrayList<>();
for(RssItem item : items) {
// = \u2022, = \u25CF, = \u25CB, = \u25AA, = \u25A0, = \u25A1, = \u25BA
previewLines.add("\u25CF " + item.getTitle().trim());
}
String previewText = TextUtils.join("\n", previewLines);
NotificationCompat.Builder builder = NotificationCompat.Builder builder =
new NotificationCompat.Builder(context, channelId) new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification) .setSmallIcon(R.drawable.ic_notification)
.setTicker(tickerMessage) .setContentTitle(tickerMessage)
.setContentTitle(title) .setStyle(new NotificationCompat.BigTextStyle().bigText(previewText))
//.setDefaults(Notification.DEFAULT_ALL) //.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true) .setAutoCancel(true)
.setNumber(newItemsCount) .setNumber(newItemsCount)