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.ListView;
import javax.inject.Inject;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.fragment.app.Fragment;
import javax.inject.Inject;
import butterknife.BindView;
import butterknife.ButterKnife;
import de.luhmer.owncloudnewsreader.authentication.AccountGeneral;
@ -94,7 +95,7 @@ public class SyncIntervalSelectorActivity extends AppCompatActivity {
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);
Account[] accounts = mAccountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE);
@ -158,11 +159,11 @@ public class SyncIntervalSelectorActivity extends AppCompatActivity {
lvItems.setAdapter(adapter);
if(!mPrefs.contains(SYNC_INTERVAL_IN_MINUTES_STRING))
lvItems.setItemChecked(items.length - 1, true);//The last item is 24hours. This is the default value!
else {
if(!mPrefs.contains(SYNC_INTERVAL_IN_MINUTES_STRING)) {
lvItems.setItemChecked(items.length - 1, true); // The last item is 24hours. This is the default value!
} else {
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) {
if(Integer.parseInt(item) == minutes)
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();
}
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() {
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.os.Build;
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.MediaMetadataCompat;
import android.support.v4.media.session.MediaControllerCompat;
import android.support.v4.media.session.MediaSessionCompat;
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.session.MediaButtonReceiver;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageSize;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import de.luhmer.owncloudnewsreader.BuildConfig;
import de.luhmer.owncloudnewsreader.NewsReaderListActivity;
import de.luhmer.owncloudnewsreader.R;
import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm;
import de.luhmer.owncloudnewsreader.database.model.RssItem;
public class NextcloudNotificationManager {
@ -252,16 +257,25 @@ public class NextcloudNotificationManager {
Resources res = context.getResources();
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 title = context.getString(R.string.app_name);
String channelId = context.getString(R.string.app_name);
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 =
new NotificationCompat.Builder(context, channelId)
.setSmallIcon(R.drawable.ic_notification)
.setTicker(tickerMessage)
.setContentTitle(title)
.setContentTitle(tickerMessage)
.setStyle(new NotificationCompat.BigTextStyle().bigText(previewText))
//.setDefaults(Notification.DEFAULT_ALL)
.setAutoCancel(true)
.setNumber(newItemsCount)