From ff89c6cfa9aa90c7f0a6668a9175c4059374281a Mon Sep 17 00:00:00 2001 From: David Luhmer Date: Tue, 26 Jan 2021 15:42:19 +0100 Subject: fix failed merge Signed-off-by: David Luhmer --- .../owncloudnewsreader/NewsDetailActivity.java | 492 ++++++++++----------- 1 file changed, 237 insertions(+), 255 deletions(-) (limited to 'News-Android-App/src/main/java') 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 86878af3..c9fc72c6 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 @@ -1,23 +1,22 @@ /** -* Android ownCloud News -* -* @author David Luhmer -* @copyright 2013 David Luhmer david-dev@live.de -* -* This library is free software; you can redistribute it and/or -* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE -* License as published by the Free Software Foundation; either -* version 3 of the License, or any later version. -* -* This library is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU AFFERO GENERAL PUBLIC LICENSE for more details. -* -* You should have received a copy of the GNU Affero General Public -* License along with this library. If not, see . -* -*/ + * Android ownCloud News + * + * @author David Luhmer + * @copyright 2013 David Luhmer david-dev@live.de + *

+ * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + *

+ * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU AFFERO GENERAL PUBLIC LICENSE for more details. + *

+ * You should have received a copy of the GNU Affero General Public + * License along with this library. If not, see . + */ package de.luhmer.owncloudnewsreader; @@ -36,10 +35,7 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; -import android.widget.ProgressBar; -import androidx.appcompat.widget.AppCompatImageButton; -import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; @@ -49,19 +45,19 @@ import androidx.viewpager.widget.ViewPager; import java.lang.ref.WeakReference; import java.util.HashSet; -import java.util.List; import java.util.Set; import javax.inject.Inject; -import butterknife.BindView; -import butterknife.ButterKnife; +import de.greenrobot.dao.query.LazyList; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm; import de.luhmer.owncloudnewsreader.database.DatabaseConnectionOrm.SORT_DIRECTION; import de.luhmer.owncloudnewsreader.database.model.RssItem; +import de.luhmer.owncloudnewsreader.databinding.ActivityNewsDetailBinding; import de.luhmer.owncloudnewsreader.helper.ThemeUtils; import de.luhmer.owncloudnewsreader.model.PodcastItem; import de.luhmer.owncloudnewsreader.model.TTSItem; +import de.luhmer.owncloudnewsreader.view.PodcastSlidingUpPanelLayout; import de.luhmer.owncloudnewsreader.widget.WidgetProvider; @@ -79,18 +75,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { * {@link FragmentStatePagerAdapter}. */ private SectionsPagerAdapter mSectionsPagerAdapter; - protected @BindView(R.id.toolbar) Toolbar toolbar; - // protected @BindView(R.id.bottomAppBar) BottomAppBar bottomAppBar; - protected @BindView(R.id.progressIndicator) ProgressBar progressIndicator; - //protected @BindView(R.id.btn_disable_incognito) ImageButton mBtnDisableIncognito; - protected @BindView(R.id.fa_detail_bar) View fastActionDetailBar; - protected @BindView(R.id.fa_collapse_layout) View fastActionCollapseLayout; - protected @BindView(R.id.fa_star) AppCompatImageButton fastActionStar; - protected @BindView(R.id.fa_mark_as_read) AppCompatImageButton fastActionRead; - protected @BindView(R.id.fa_toggle) AppCompatImageButton fastActionToggle; - protected @BindView(R.id.fa_open_in_browser) AppCompatImageButton fastActionOpenInBrowser; - protected @BindView(R.id.fa_share) AppCompatImageButton fastActionShare; - + public LazyList rssItems; /** * The {@link ViewPager} that will host the section contents. @@ -103,19 +88,46 @@ public class NewsDetailActivity extends PodcastFragmentActivity { private MenuItem menuItem_Read; private DatabaseConnectionOrm dbConn; - public List rssItems; + protected ActivityNewsDetailBinding binding; - protected @Inject SharedPreferences mPrefs; + protected @Inject + SharedPreferences mPrefs; private boolean mShowFastActions; //public static final String DATABASE_IDS_OF_ITEMS = "DATABASE_IDS_OF_ITEMS"; + private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() { + + @Override + public void onPageSelected(int pos) { + pageChanged(pos); + } + + @Override + public void onPageScrolled(int arg0, float arg1, int arg2) { + } + + @Override + public void onPageScrollStateChanged(int arg0) { + } + }; + + 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) { - ((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this); + ((NewsReaderApplication) getApplication()).getAppComponent().injectActivity(this); super.onCreate(savedInstanceState); + binding = ActivityNewsDetailBinding.inflate(getLayoutInflater()); + setContentView(binding.getRoot()); + /* //make full transparent statusBar if (Build.VERSION.SDK_INT >= 19 && Build.VERSION.SDK_INT < 21) { @@ -144,10 +156,6 @@ public class NewsDetailActivity extends PodcastFragmentActivity { } */ - - - setContentView(R.layout.activity_news_detail); - /* // For Debugging the WebView using Chrome Remote Debugging if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { @@ -155,11 +163,9 @@ public class NewsDetailActivity extends PodcastFragmentActivity { } */ - ButterKnife.bind(this); - - if (toolbar != null) { - setSupportActionBar(toolbar); - } + if (binding.toolbarLayout.toolbar != null) { + setSupportActionBar(binding.toolbarLayout.toolbar); + } /* if (bottomAppBar != null) { setSupportActionBar(bottomAppBar); @@ -171,71 +177,89 @@ public class NewsDetailActivity extends PodcastFragmentActivity { Intent intent = getIntent(); int item_id = 0; - if(intent.hasExtra(NewsReaderListActivity.ITEM_ID)) { + if (intent.hasExtra(NewsReaderListActivity.ITEM_ID)) { item_id = intent.getExtras().getInt(NewsReaderListActivity.ITEM_ID); } - if(intent.hasExtra(NewsReaderListActivity.TITLE)) { + if (intent.hasExtra(NewsReaderListActivity.TITLE)) { getSupportActionBar().setTitle(intent.getExtras().getString(NewsReaderListActivity.TITLE)); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); - rssItems = dbConn.getCurrentRssItemView(-1); - - //If the Activity gets started from the Widget, read the item id and get the selected index in the cursor. - if(intent.hasExtra(WidgetProvider.RSS_ITEM_ID)) { - long rss_item_id = intent.getExtras().getLong(WidgetProvider.RSS_ITEM_ID); - for(RssItem rssItem : rssItems) { - if(rss_item_id == rssItem.getId()) { - getSupportActionBar().setTitle(rssItem.getTitle()); - break; - } - else { - item_id++; - } - } - } + rssItems = dbConn.getAllRssItems(); + + //If the Activity gets started from the Widget, read the item id and get the selected index in the cursor. + if (intent.hasExtra(WidgetProvider.RSS_ITEM_ID)) { + long rss_item_id = intent.getExtras().getLong(WidgetProvider.RSS_ITEM_ID); + for (RssItem rssItem : rssItems) { + if (rss_item_id == rssItem.getId()) { + getSupportActionBar().setTitle(rssItem.getTitle()); + break; + } else { + item_id++; + } + } + } // Create the adapter that will return a fragment for each of the three // primary sections of the app. mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); - progressIndicator.setMax(mSectionsPagerAdapter.getCount()); + binding.progressIndicator.setMax(mSectionsPagerAdapter.getCount()); // Set up the ViewPager with the sections adapter. mViewPager = findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); - try { - mViewPager.setCurrentItem(item_id, true); - if(savedInstanceState == null) { - // Only do that when activity is started for the first time. Not on orientation changes etc.. - pageChanged(item_id); - } - } catch(Exception ex) { + try { + mViewPager.setCurrentItem(item_id, true); + if (savedInstanceState == null) { + // Only do that when activity is started for the first time. Not on orientation changes etc.. + pageChanged(item_id); + } + } catch (Exception ex) { ex.printStackTrace(); } - mViewPager.addOnPageChangeListener(onPageChangeListener); - // mBtnDisableIncognito.setOnClickListener(v -> { + mViewPager.addOnPageChangeListener(onPageChangeListener); + // mBtnDisableIncognito.setOnClickListener(v -> { // toggleIncognitoMode(); // }); this.initFastActionBar(); } - @Override - protected void onResume() { - super.onResume(); + @Override + protected void onResume() { + super.onResume(); + + updateActionBarIcons(); + } + + @Override + protected PodcastSlidingUpPanelLayout getPodcastSlidingUpPanelLayout() { + return binding.slidingLayout; + } + + private void toggleIncognitoMode() { + // toggle incognito mode + setIncognitoEnabled(!isIncognitoEnabled()); - updateActionBarIcons(); - } + for (int i = currentPosition - 1; i <= currentPosition + 1; i++) { + Log.d(TAG, "change incognito for idx: " + i); + WeakReference ndf = mSectionsPagerAdapter.items.get(i); + if (ndf != null) { + ndf.get().syncIncognitoState(); + ndf.get().startLoadRssItemToWebViewTask(); + } + } + } - /** + /** * Init fast action bar based on user settings. * Only show if user selected setting CB_SHOW_FAST_ACTIONS. Otherwise hide. - * + *

* author: emasty https://github.com/emasty */ private void initFastActionBar() { @@ -243,18 +267,18 @@ public class NewsDetailActivity extends PodcastFragmentActivity { if (mShowFastActions) { // Set click listener for buttons on action bar - fastActionOpenInBrowser.setOnClickListener(v -> this.openInBrowser(currentPosition)); - fastActionToggle.setOnClickListener(v -> this.toggleFastActionBar()); // toggle expand / collapse - fastActionStar.setOnClickListener(v -> NewsDetailActivity.this.toggleRssItemStarredState()); - fastActionRead.setOnClickListener(v -> NewsDetailActivity.this.markRead(currentPosition)); - fastActionShare.setOnClickListener(v -> this.share(currentPosition)); + binding.faDetailBar.faOpenInBrowser.setOnClickListener(v -> this.openInBrowser(currentPosition)); + binding.faDetailBar.faToggle.setOnClickListener(v -> this.toggleFastActionBar()); // toggle expand / collapse + binding.faDetailBar.faStar.setOnClickListener(v -> NewsDetailActivity.this.toggleRssItemStarredState()); + binding.faDetailBar.faMarkAsRead.setOnClickListener(v -> NewsDetailActivity.this.markRead(currentPosition)); + binding.faDetailBar.faShare.setOnClickListener(v -> this.share(currentPosition)); - fastActionDetailBar.setVisibility(View.VISIBLE); + binding.faDetailBar.getRoot().setVisibility(View.VISIBLE); // initially the bar should be opened in the expanded state this.toggleFastActionBar(); } else { - fastActionDetailBar.setVisibility(View.INVISIBLE); + binding.faDetailBar.getRoot().setVisibility(View.INVISIBLE); } } @@ -262,98 +286,57 @@ public class NewsDetailActivity extends PodcastFragmentActivity { * Expands or shrinks the fast action bar to show/hide secondary functions */ private void toggleFastActionBar() { - int currentState = fastActionCollapseLayout.getVisibility(); + int currentState = binding.faDetailBar.faCollapseLayout.getVisibility(); switch (currentState) { case View.GONE: - fastActionToggle.setImageResource(R.drawable.ic_fa_expand); - fastActionCollapseLayout.setVisibility(View.VISIBLE); + binding.faDetailBar.faToggle.setImageResource(R.drawable.ic_fa_expand); + binding.faDetailBar.faCollapseLayout.setVisibility(View.VISIBLE); break; case View.VISIBLE: - fastActionToggle.setImageResource(R.drawable.ic_fa_shrink); - fastActionCollapseLayout.setVisibility(View.GONE); + binding.faDetailBar.faToggle.setImageResource(R.drawable.ic_fa_shrink); + binding.faDetailBar.faCollapseLayout.setVisibility(View.GONE); break; default: break; } //((Animatable)fastActionToggle.getDrawable()).start(); - fastActionToggle.setScaleX(-1); - } - - private void toggleIncognitoMode() { - // toggle incognito mode - setIncognitoEnabled(!isIncognitoEnabled()); - - for(int i = currentPosition-1; i <= currentPosition+1; i++) { - Log.d(TAG, "change incognito for idx: " + i); - WeakReference ndf = mSectionsPagerAdapter.items.get(i); - if(ndf != null) { - ndf.get().syncIncognitoState(); - ndf.get().startLoadRssItemToWebViewTask(); - } - } + binding.faDetailBar.faToggle.setScaleX(-1); } @Override protected void onDestroy() { super.onDestroy(); + rssItems.close(); } - private ViewPager.OnPageChangeListener onPageChangeListener = new ViewPager.OnPageChangeListener() { - - @Override - public void onPageSelected(int pos) { - pageChanged(pos); - } - - @Override public void onPageScrolled(int arg0, float arg1, int arg2) { } - - @Override public void onPageScrollStateChanged(int arg0) { } - }; - - 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 - public boolean onKeyDown(int keyCode, KeyEvent event) { - if(mPrefs.getBoolean(SettingsActivity.CB_NAVIGATE_WITH_VOLUME_BUTTONS_STRING, false)) - { - if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) - { - if(currentPosition < rssItems.size()-1) - { - mViewPager.setCurrentItem(currentPosition + 1, true); - } + public boolean onKeyDown(int keyCode, KeyEvent event) { + if (mPrefs.getBoolean(SettingsActivity.CB_NAVIGATE_WITH_VOLUME_BUTTONS_STRING, false)) { + if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) { + if (currentPosition < rssItems.size() - 1) { + mViewPager.setCurrentItem(currentPosition + 1, true); + } // capture event to avoid volume change at end of feed return true; - } - - else if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) - { - if(currentPosition > 0) - { - mViewPager.setCurrentItem(currentPosition - 1, true); - } + } else if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) { + if (currentPosition > 0) { + mViewPager.setCurrentItem(currentPosition - 1, true); + } // capture event to avoid volume change at beginning of feed return true; - } + } } - if(keyCode == KeyEvent.KEYCODE_BACK) - { + if (keyCode == KeyEvent.KEYCODE_BACK) { NewsDetailFragment ndf = getNewsDetailFragmentAtPosition(currentPosition);//(NewsDetailFragment) getSupportFragmentManager().findFragmentByTag("android:switcher:" + R.id.pager + ":" + currentPosition); - if(ndf != null && ndf.canNavigateBack()) { + if (ndf != null && ndf.canNavigateBack()) { ndf.navigateBack(); return true; } } return super.onKeyDown(keyCode, event); - } + } @Override public boolean onKeyUp(int keyCode, KeyEvent event) { @@ -364,97 +347,96 @@ public class NewsDetailActivity extends PodcastFragmentActivity { return super.onKeyUp(keyCode, event); } - private void pageChanged(int position) - { + private void pageChanged(int position) { stopVideoOnCurrentPage(); currentPosition = position; resumeVideoPlayersOnCurrentPage(); - progressIndicator.setProgress(position + 1); + binding.progressIndicator.setProgress(position + 1); - if(rssItems.get(position).getFeed() != null) { - // Try getting the feed title and use it for the action bar title + if (rssItems.get(position).getFeed() != null) { + // Try getting the feed title and use it for the action bar title getSupportActionBar().setTitle(rssItems.get(position).getFeed().getFeedTitle()); } else { getSupportActionBar().setTitle(rssItems.get(position).getTitle()); } - RssItem rssItem = rssItems.get(position); - if(!rssItem.getRead_temp()) { - if (!NewsReaderListActivity.stayUnreadItems.contains(rssItem.getId())) { - markItemAsReadOrUnread(rssItems.get(position), true); - } + RssItem rssItem = rssItems.get(position); + if (!rssItem.getRead_temp()) { + if (!NewsReaderListActivity.stayUnreadItems.contains(rssItem.getId())) { + markItemAsReadOrUnread(rssItems.get(position), true); + } - mPostDelayHandler.delayTimer(); + mPostDelayHandler.delayTimer(); - Log.v("PAGE CHANGED", "PAGE: " + position + " - IDFEED: " + rssItems.get(position).getId()); - } + Log.v("PAGE CHANGED", "PAGE: " + position + " - IDFEED: " + rssItems.get(position).getId()); + } updateActionBarIcons(); } - private NewsDetailFragment getNewsDetailFragmentAtPosition(int position) { - if(mSectionsPagerAdapter.items.get(position) != null) + private NewsDetailFragment getNewsDetailFragmentAtPosition(int position) { + if (mSectionsPagerAdapter.items.get(position) != null) return mSectionsPagerAdapter.items.get(position).get(); return null; - } + } private void resumeVideoPlayersOnCurrentPage() { NewsDetailFragment fragment = getNewsDetailFragmentAtPosition(currentPosition); - if(fragment != null) { // could be null if not instantiated yet - fragment.resumeCurrentPage(); - } + if (fragment != null) { // could be null if not instantiated yet + fragment.resumeCurrentPage(); + } } private void stopVideoOnCurrentPage() { - NewsDetailFragment fragment = getNewsDetailFragmentAtPosition(currentPosition); - if(fragment != null) { // could be null if not instantiated yet - fragment.pauseCurrentPage(); - } + NewsDetailFragment fragment = getNewsDetailFragmentAtPosition(currentPosition); + if (fragment != null) { // could be null if not instantiated yet + fragment.pauseCurrentPage(); + } } public void updateActionBarIcons() { - RssItem rssItem = rssItems.get(currentPosition); + RssItem rssItem = rssItems.get(currentPosition); - boolean isStarred = rssItem.getStarred_temp(); - boolean isRead = rssItem.getRead_temp(); + boolean isStarred = rssItem.getStarred_temp(); + boolean isRead = rssItem.getRead_temp(); - PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(this, rssItem); - boolean podcastAvailable = !"".equals(podcastItem.link); + PodcastItem podcastItem = DatabaseConnectionOrm.ParsePodcastItemFromRssItem(this, rssItem); + boolean podcastAvailable = !"".equals(podcastItem.link); - if(menuItem_PlayPodcast != null) { + if (menuItem_PlayPodcast != null) { menuItem_PlayPodcast.setVisible(podcastAvailable); } - if(menuItem_Starred != null) { + if (menuItem_Starred != null) { if (isStarred) { menuItem_Starred.setIcon(R.drawable.ic_action_star_dark); - fastActionStar.setImageResource(R.drawable.ic_action_star_dark); - } else { + binding.faDetailBar.faStar.setImageResource(R.drawable.ic_action_star_dark); + } else { menuItem_Starred.setIcon(R.drawable.ic_action_star_border_dark); - fastActionStar.setImageResource(R.drawable.ic_action_star_border_dark); + binding.faDetailBar.faStar.setImageResource(R.drawable.ic_action_star_border_dark); } } - if(menuItem_Read != null) { + if (menuItem_Read != null) { if (isRead) { menuItem_Read.setIcon(R.drawable.ic_check_box_white); menuItem_Read.setChecked(true); - fastActionRead.setImageResource(R.drawable.ic_check_box_white); + binding.faDetailBar.faMarkAsRead.setImageResource(R.drawable.ic_check_box_white); } else { menuItem_Read.setIcon(R.drawable.ic_check_box_outline_blank_white); menuItem_Read.setChecked(false); - fastActionRead.setImageResource(R.drawable.ic_check_box_outline_blank_white); + binding.faDetailBar.faMarkAsRead.setImageResource(R.drawable.ic_check_box_outline_blank_white); } } - } + } - @Override - public void onBackPressed() { - if(!handlePodcastBackPressed()) - super.onBackPressed(); - } + @Override + public void onBackPressed() { + if (!handlePodcastBackPressed()) + super.onBackPressed(); + } @Override public boolean onCreateOptionsMenu(Menu menu) { @@ -466,35 +448,35 @@ public class NewsDetailActivity extends PodcastFragmentActivity { menuItem_Starred = menu.findItem(R.id.action_starred); menuItem_Read = menu.findItem(R.id.action_read); - menuItem_PlayPodcast = menu.findItem(R.id.action_playPodcast); + menuItem_PlayPodcast = menu.findItem(R.id.action_playPodcast); - if(mShowFastActions) { - menuItem_Starred.setVisible(false); + if (mShowFastActions) { + menuItem_Starred.setVisible(false); menuItem_Read.setVisible(false); menuItem_OpenInBrowser.setVisible(false); menuItem_ShareItem.setVisible(false); } Set selections = mPrefs.getStringSet("sp_news_detail_actionbar_icons", new HashSet<>()); - String[] selected = selections.toArray(new String[] {}); - for(String selection : selected) { - switch(selection) { - case "open_in_browser": + String[] selected = selections.toArray(new String[]{}); + for (String selection : selected) { + switch (selection) { + case "open_in_browser": menuItem_OpenInBrowser.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - break; - case "share": + break; + case "share": menuItem_ShareItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - break; - case "podcast": + break; + case "podcast": menuItem_PlayPodcast.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - break; - //case "tts": - // menu.findItem(R.id.action_tts).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); - // break; - } + break; + //case "tts": + // menu.findItem(R.id.action_tts).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS); + // break; + } } - updateActionBarIcons(); + updateActionBarIcons(); initIncognitoMode(); @@ -510,29 +492,29 @@ public class NewsDetailActivity extends PodcastFragmentActivity { onBackPressed(); return true; - case R.id.action_read: + case R.id.action_read: this.markRead(currentPosition); - break; + break; - case R.id.action_starred: - toggleRssItemStarredState(); - break; + case R.id.action_starred: + toggleRssItemStarredState(); + break; - case R.id.action_openInBrowser: + case R.id.action_openInBrowser: this.openInBrowser(currentPosition); break; - case R.id.action_playPodcast: - openPodcast(rssItem); - break; + case R.id.action_playPodcast: + openPodcast(rssItem); + break; - case R.id.action_tts: - this.startTTS(currentPosition); - break; + case R.id.action_tts: + this.startTTS(currentPosition); + break; - case R.id.action_ShareItem: + case R.id.action_ShareItem: this.share(currentPosition); - break; + break; case R.id.action_incognito_mode: toggleIncognitoMode(); @@ -552,15 +534,15 @@ public class NewsDetailActivity extends PodcastFragmentActivity { NewsDetailFragment newsDetailFragment = getNewsDetailFragmentAtPosition(currentPosition); String link = "about:blank"; - if(newsDetailFragment != null && newsDetailFragment.mWebView != null) { - link = newsDetailFragment.mWebView.getUrl(); + if (newsDetailFragment != null && newsDetailFragment.binding.webview != null) { + link = newsDetailFragment.binding.webview.getUrl(); } - if("about:blank".equals(link)) { + if ("about:blank".equals(link)) { link = rssItem.getLink(); } - if(link.length() > 0) + if (link.length() > 0) { newsDetailFragment.loadURL(link); } @@ -577,10 +559,10 @@ public class NewsDetailActivity extends PodcastFragmentActivity { String content = rssItem.getLink(); NewsDetailFragment fragment = getNewsDetailFragmentAtPosition(currentPosition); - if(fragment != null) { // could be null if not instantiated yet - if(!fragment.mWebView.getUrl().equals("about:blank") && !fragment.mWebView.getUrl().trim().equals("")) { - content = fragment.mWebView.getUrl(); - title = fragment.mWebView.getTitle(); + if (fragment != null) { // could be null if not instantiated yet + if (!fragment.binding.webview.getUrl().equals("about:blank") && !fragment.binding.webview.getUrl().trim().equals("")) { + content = fragment.binding.webview.getUrl(); + title = fragment.binding.webview.getTitle(); } } @@ -622,7 +604,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { public void toggleRssItemStarredState() { - RssItem rssItem = rssItems.get(currentPosition); + RssItem rssItem = rssItems.get(currentPosition); Boolean curState = rssItem.getStarred_temp(); rssItem.setStarred_temp(!curState); dbConn.updateRssItem(rssItem); @@ -636,16 +618,16 @@ public class NewsDetailActivity extends PodcastFragmentActivity { Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse("http://")); ResolveInfo resolveInfo = getPackageManager().resolveActivity(browserIntent, PackageManager.MATCH_DEFAULT_ONLY); - Log.v(TAG, "Default Browser is: " + resolveInfo.loadLabel(getPackageManager()).toString()); + Log.v(TAG, "Default Browser is: " + resolveInfo.loadLabel(getPackageManager()).toString()); return (resolveInfo.loadLabel(getPackageManager()).toString().contains("Chrome")); } private void markItemAsReadOrUnread(RssItem item, boolean read) { - NewsReaderListActivity.stayUnreadItems.add(item.getId()); + NewsReaderListActivity.stayUnreadItems.add(item.getId()); - item.setRead_temp(read); - dbConn.updateRssItem(item); - updateActionBarIcons(); + item.setRead_temp(read); + dbConn.updateRssItem(item); + updateActionBarIcons(); } @Override @@ -657,17 +639,17 @@ public class NewsDetailActivity extends PodcastFragmentActivity { } public boolean isIncognitoEnabled() { - return mPrefs.getBoolean(INCOGNITO_MODE_ENABLED, false); + return mPrefs.getBoolean(INCOGNITO_MODE_ENABLED, false); } public void setIncognitoEnabled(boolean enabled) { - mPrefs.edit().putBoolean(INCOGNITO_MODE_ENABLED, enabled).commit(); + mPrefs.edit().putBoolean(INCOGNITO_MODE_ENABLED, enabled).commit(); initIncognitoMode(); } public void initIncognitoMode() { int color = getResources().getColor(isIncognitoEnabled() ? R.color.material_grey_900 : R.color.colorPrimary); - ThemeUtils.colorizeToolbar(toolbar, color); + ThemeUtils.colorizeToolbar(binding.toolbarLayout.toolbar, color); //ThemeUtils.colorizeToolbar(bottomAppBar, color); //ThemeUtils.changeStatusBarColor(this, color); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { @@ -722,19 +704,19 @@ public class NewsDetailActivity extends PodcastFragmentActivity { //public class SectionsPagerAdapter extends FragmentPagerAdapter { public class SectionsPagerAdapter extends FragmentStatePagerAdapter { - SparseArray> items = new SparseArray<>(); + SparseArray> items = new SparseArray<>(); - public SectionsPagerAdapter(FragmentManager fm) { - super(fm); + public SectionsPagerAdapter(FragmentManager fm) { + super(fm); - for (Fragment fragment : fm.getFragments()) { - if (fragment instanceof NewsDetailFragment) { - int id = ((NewsDetailFragment) fragment).getSectionNumber(); - Log.v(TAG, "Retaining NewsDetailFragment with ID: " + id); - items.put(id, new WeakReference<>((NewsDetailFragment) fragment)); - } - } - } + for (Fragment fragment : fm.getFragments()) { + if (fragment instanceof NewsDetailFragment) { + int id = ((NewsDetailFragment) fragment).getSectionNumber(); + Log.v(TAG, "Retaining NewsDetailFragment with ID: " + id); + items.put(id, new WeakReference<>((NewsDetailFragment) fragment)); + } + } + } @Override public Fragment getItem(int position) { @@ -765,7 +747,7 @@ public class NewsDetailActivity extends PodcastFragmentActivity { @Override public int getCount() { //return cursor.getCount(); - return rssItems.size(); + return rssItems.size(); } @Override @@ -777,4 +759,4 @@ public class NewsDetailActivity extends PodcastFragmentActivity { protected void setBackgroundColorOfViewPager(int backgroundColor) { this.mViewPager.setBackgroundColor(backgroundColor); } -} +} \ No newline at end of file -- cgit v1.2.3