diff options
Diffstat (limited to 'News-Android-App/src/main/java/de')
10 files changed, 37 insertions, 31 deletions
diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java index cbe00113..c7a5ab95 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailActivity.java @@ -97,14 +97,6 @@ public class NewsDetailActivity extends PodcastFragmentActivity { SharedPreferences mPrefs; private boolean mShowFastActions; - - public static SORT_DIRECTION getSortDirectionFromSettings(SharedPreferences prefs) { - SORT_DIRECTION sDirection = SORT_DIRECTION.asc; - String sortDirection = prefs.getString(SettingsActivity.SP_SORT_ORDER, "1"); - if ("1".equals(sortDirection)) - sDirection = SORT_DIRECTION.desc; - return sDirection; - } @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailImageDialogFragment.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailImageDialogFragment.java index f7f00059..36c61463 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailImageDialogFragment.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsDetailImageDialogFragment.java @@ -447,7 +447,7 @@ public class NewsDetailImageDialogFragment extends DialogFragment { //String imagePath = downloadManager.getUriForDownloadedFile(refID).toString(); - String downloadFileLocalUri = cursor.getString(cursor.getColumnIndex(DownloadManager.COLUMN_LOCAL_URI)); + String downloadFileLocalUri = cursor.getString(cursor.getColumnIndexOrThrow(DownloadManager.COLUMN_LOCAL_URI)); File image = new File(Uri.parse(downloadFileLocalUri).getPath()); NextcloudNotificationManager.showNotificationDownloadSingleImageComplete(context, image); diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java index 1caa0066..573eb86b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/NewsReaderListActivity.java @@ -117,6 +117,7 @@ import io.reactivex.schedulers.Schedulers; import io.reactivex.subjects.PublishSubject; import static android.Manifest.permission.ACCESS_FINE_LOCATION; +import static androidx.annotation.VisibleForTesting.PROTECTED; import static de.luhmer.owncloudnewsreader.LoginDialogActivity.RESULT_LOGIN; import static de.luhmer.owncloudnewsreader.LoginDialogActivity.ShowAlertDialog; @@ -141,9 +142,10 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements public static HashSet<Long> stayUnreadItems = new HashSet<>(); - private static MenuItem menuItemDownloadMoreItems; + private MenuItem menuItemDownloadMoreItems; - protected ActivityNewsreaderBinding binding; + @VisibleForTesting(otherwise = PROTECTED) + public ActivityNewsreaderBinding binding; //private ServiceConnection mConnection = null; @@ -383,8 +385,9 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements boolean isAccountThere = false; Account[] accounts = mAccountManager.getAccounts(); + String accountType = AccountGeneral.getAccountType(this); for (Account account : accounts) { - if (account.type.intern().equals(AccountGeneral.ACCOUNT_TYPE)) { + if (account.type.intern().equals(accountType)) { isAccountThere = true; } } @@ -392,7 +395,7 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements //If the account is not in the Android Account Manager if (!isAccountThere) { //Then add the new account - Account account = new Account(getString(R.string.app_name), AccountGeneral.ACCOUNT_TYPE); + Account account = new Account(getString(R.string.app_name), accountType); mAccountManager.addAccountExplicitly(account, "", new Bundle()); SyncIntervalSelectorActivity.setAccountSyncInterval(this, mPrefs); @@ -652,8 +655,9 @@ public class NewsReaderListActivity extends PodcastFragmentActivity implements AccountManager mAccountManager = AccountManager.get(this); Account[] accounts = mAccountManager.getAccounts(); for(Account acc : accounts) { - if (acc.type.equals(AccountGeneral.ACCOUNT_TYPE)) { - ContentResolver.requestSync(acc, AccountGeneral.ACCOUNT_TYPE, accBundle); + String accountType = AccountGeneral.getAccountType(this); + if (acc.type.equals(accountType)) { + ContentResolver.requestSync(acc, accountType, accBundle); } } //http://stackoverflow.com/questions/5253858/why-does-contentresolver-requestsync-not-trigger-a-sync diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SyncIntervalSelectorActivity.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SyncIntervalSelectorActivity.java index 53bffb53..59cf2b37 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SyncIntervalSelectorActivity.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/SyncIntervalSelectorActivity.java @@ -72,21 +72,22 @@ public class SyncIntervalSelectorActivity extends AppCompatActivity { int minutes = mPrefs.getInt(SYNC_INTERVAL_IN_MINUTES_STRING, SYNC_DEFAULT_INTERVAL); AccountManager mAccountManager = AccountManager.get(context); - Account[] accounts = mAccountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE); + String accountType = AccountGeneral.getAccountType(context); + Account[] accounts = mAccountManager.getAccountsByType(accountType); for (Account account : accounts) { if (minutes != 0) { long SYNC_INTERVAL = minutes * SECONDS_PER_MINUTE; - ContentResolver.setSyncAutomatically(account, AccountGeneral.ACCOUNT_TYPE, true); + ContentResolver.setSyncAutomatically(account, accountType, true); Bundle bundle = new Bundle(); ContentResolver.addPeriodicSync( account, - AccountGeneral.ACCOUNT_TYPE, + accountType, bundle, SYNC_INTERVAL); } else { - ContentResolver.setSyncAutomatically(account, AccountGeneral.ACCOUNT_TYPE, false); + ContentResolver.setSyncAutomatically(account, accountType, false); } } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java index 10525cd4..d0e9936b 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/adapter/NewsListRecyclerAdapter.java @@ -37,7 +37,7 @@ import de.luhmer.owncloudnewsreader.helper.StopWatch; import de.luhmer.owncloudnewsreader.interfaces.IPlayPausePodcastClicked; import de.luhmer.owncloudnewsreader.model.CurrentRssViewDataHolder; -public class NewsListRecyclerAdapter extends RecyclerView.Adapter { +public class NewsListRecyclerAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> { private static final String TAG = "NewsListRecyclerAdapter"; private final int VIEW_ITEM = 1; // Item diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/AccountGeneral.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/AccountGeneral.java index 81b3902a..f8d2734d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/AccountGeneral.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/AccountGeneral.java @@ -1,10 +1,10 @@ package de.luhmer.owncloudnewsreader.authentication; +import android.content.Context; + +import de.luhmer.owncloudnewsreader.R; + public class AccountGeneral { - /** - * Account type id - */ - public static final String ACCOUNT_TYPE = "de.luhmer.owncloudnewsreader"; /** * Account name @@ -21,4 +21,10 @@ public class AccountGeneral { public static final String AUTHTOKEN_TYPE_FULL_ACCESS = "Full access"; public static final String AUTHTOKEN_TYPE_FULL_ACCESS_LABEL = "Full access to an Nextcloud News account"; + /** + * Account type id + */ + public static String getAccountType(Context context) { + return context.getString(R.string.account_type); + } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/OwnCloudSyncAdapter.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/OwnCloudSyncAdapter.java index 0ad3dde7..90e42a69 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/OwnCloudSyncAdapter.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/authentication/OwnCloudSyncAdapter.java @@ -60,7 +60,7 @@ public class OwnCloudSyncAdapter extends AbstractThreadedSyncAdapter { public OwnCloudSyncAdapter(Context context, boolean autoInitialize) { super(context, autoInitialize); - ((NewsReaderApplication) context.getApplicationContext()).getAppComponent().injectService(this); + ((NewsReaderApplication) context).getAppComponent().injectService(this); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java index fdc51be1..c6aec03c 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/DownloadImagesService.java @@ -114,10 +114,10 @@ public class DownloadImagesService extends JobIntentService { if(downloadMode.equals(DownloadMode.FAVICONS_ONLY)) { List<Feed> feedList = dbConn.getListOfFeeds(); - FavIconHandler favIconHandler = new FavIconHandler(this); + FavIconHandler favIconHandler = new FavIconHandler(getApplicationContext()); for(Feed feed : feedList) { try { - favIconHandler.preCacheFavIcon(feed, this); + favIconHandler.preCacheFavIcon(feed, getApplicationContext()); } catch(IllegalStateException ex) { Log.e(TAG, ex.getMessage()); } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java index 8792c3f3..15693a0d 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/services/OwnCloudSyncService.java @@ -24,7 +24,7 @@ public class OwnCloudSyncService extends Service { */ synchronized (sSyncAdapterLock) { if (sSyncAdapter == null) { - sSyncAdapter = new OwnCloudSyncAdapter(this, true); + sSyncAdapter = new OwnCloudSyncAdapter(getApplicationContext(), true); } } } diff --git a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java index 0c7ef79d..6c7a1218 100644 --- a/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java +++ b/News-Android-App/src/main/java/de/luhmer/owncloudnewsreader/widget/WidgetNewsViewsFactory.java @@ -35,8 +35,8 @@ import android.widget.RemoteViewsService; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; +import de.greenrobot.dao.query.LazyList; import de.luhmer.owncloudnewsreader.Constants; import de.luhmer.owncloudnewsreader.R; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; @@ -47,7 +47,7 @@ public class WidgetNewsViewsFactory implements RemoteViewsService.RemoteViewsFac private static final String TAG = WidgetNewsViewsFactory.class.getCanonicalName(); private DatabaseConnectionOrm dbConn; - private List<RssItem> rssItems; + private LazyList<RssItem> rssItems; private Context context; private int appWidgetId; @@ -70,6 +70,7 @@ public class WidgetNewsViewsFactory implements RemoteViewsService.RemoteViewsFac @Override public void onDestroy() { + rssItems.close(); } @Override @@ -186,11 +187,13 @@ public class WidgetNewsViewsFactory implements RemoteViewsService.RemoteViewsFac return(true); } - @SuppressWarnings("deprecation") @Override public void onDataSetChanged() { Log.v(TAG, "DataSetChanged - WidgetID: " + appWidgetId); + if (rssItems != null && !rssItems.isClosed()) { + rssItems.close(); + } rssItems = dbConn.getAllUnreadRssItemsForWidget(); Log.v(TAG, "DataSetChanged finished!"); |