Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

per-feed open-in settings #1266

Merged
merged 2 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1133,35 +1133,76 @@ private void UpdateListView() {

@Override
public void onClick(RssItemViewHolder vh, int position) {
Feed feed = vh.getRssItem().getFeed();
Long openIn = feed.getOpenIn();

Uri currentUrl = Uri.parse(vh.getRssItem().getLink());

if (openIn == null) {
if (mPrefs.getBoolean(SettingsActivity.CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING, false)) {

//Choose Browser based on user settings
//modified copy from NewsDetailFragment.java:loadUrl(String url)
int selectedBrowser = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_DISPLAY_BROWSER, "0"));
switch(selectedBrowser) {
case 0:
openRssItemInCustomTab(currentUrl);
break;
case 1:
//openRssItemInInternalBrowser(currentUrl);
break;
case 2:
openRssItemInExternalBrowser(currentUrl);
break;
}

if (mPrefs.getBoolean(SettingsActivity.CB_SKIP_DETAILVIEW_AND_OPEN_BROWSER_DIRECTLY_STRING, false)) {
String currentUrl = vh.getRssItem().getLink();

//Choose Browser based on user settings
//modified copy from NewsDetailFragment.java:loadUrl(String url)
int selectedBrowser = Integer.parseInt(mPrefs.getString(SettingsActivity.SP_DISPLAY_BROWSER, "0"));
if (selectedBrowser == 0) { // Custom Tabs
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left)
.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right)
.addDefaultShareMenuItem();
builder.build().launchUrl(this, Uri.parse(currentUrl));
} else { //External browser
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(currentUrl));
startActivity(browserIntent);
((NewsListRecyclerAdapter) getNewsReaderDetailFragment().getRecyclerView().getAdapter()).changeReadStateOfItem(vh, true);
} else {
openRssItemInDetailedView(position);
}

((NewsListRecyclerAdapter) getNewsReaderDetailFragment().getRecyclerView().getAdapter()).changeReadStateOfItem(vh, true);
} else {
Intent intentNewsDetailAct = new Intent(this, NewsDetailActivity.class);

intentNewsDetailAct.putExtra(NewsReaderListActivity.ITEM_ID, position);
intentNewsDetailAct.putExtra(NewsReaderListActivity.TITLE, getNewsReaderDetailFragment().getTitle());
startActivityForResult(intentNewsDetailAct, Activity.RESULT_CANCELED);
switch (openIn.intValue()) {
case 1:
openRssItemInDetailedView(position);
break;
case 2:
openRssItemInCustomTab(currentUrl);
break;
case 3:
openRssItemInExternalBrowser(currentUrl);
break;
default:
throw new RuntimeException("Unreachable: openIn has illegal value " + openIn);
}
}
}

private void openRssItemInDetailedView(int position) {
Intent intentNewsDetailAct = new Intent(this, NewsDetailActivity.class);

intentNewsDetailAct.putExtra(NewsReaderListActivity.ITEM_ID, position);
intentNewsDetailAct.putExtra(NewsReaderListActivity.TITLE, getNewsReaderDetailFragment().getTitle());
startActivityForResult(intentNewsDetailAct, Activity.RESULT_CANCELED);
}

private void openRssItemInCustomTab(Uri currentUrl) {
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder()
.setShowTitle(true)
.setStartAnimations(this, R.anim.slide_in_right, R.anim.slide_out_left)
.setExitAnimations(this, R.anim.slide_in_left, R.anim.slide_out_right)
.setShareState(CustomTabsIntent.SHARE_STATE_ON);
builder.build().launchUrl(this, currentUrl);
}

private void openRssItemInExternalBrowser(Uri currentUrl) {
Intent browserIntent = new Intent(Intent.ACTION_VIEW, currentUrl);
startActivity(browserIntent);
}

// private void openRssItemInInternalBrowser(Uri currentUrl) {
// getNewsReaderDetailFragment().binding.webview.loadUrl(currentUrl.toString());
// }

@Override
public boolean onLongClick(RssItemViewHolder vh, int position) {
RssItem rssItem = vh.getRssItem();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -82,6 +83,8 @@ public void onCreate(Bundle savedInstanceState) {

mMenuItems.put(getString(R.string.action_feed_notification_settings), () -> showNotificationSettingsView(mFeedId));

mMenuItems.put(getString(R.string.action_feed_open_in), () -> showOpenSettingsView(mFeedId));

setStyle(DialogFragment.STYLE_NO_TITLE, R.style.FloatingDialog);
}

Expand Down Expand Up @@ -280,6 +283,47 @@ private void showMoveFeedView(final long mFeedId) {
});
}

private void showOpenSettingsView(final long feedId) {
binding.lvMenuList.setVisibility(View.GONE);
binding.openFeedDialog.setVisibility(View.VISIBLE);

DatabaseConnectionOrm dbConn = new DatabaseConnectionOrm(getContext());
Feed feed = dbConn.getFeedById(feedId);
Long openIn = feed.getOpenIn();

binding.openInUseGeneralSetting.setChecked(false);
binding.openInDetailedView.setChecked(false);
binding.openInBrowserCct.setChecked(false);
binding.openInBrowserExternal.setChecked(false);

if (openIn == null) {
binding.openInUseGeneralSetting.setChecked(true);
} else {
switch (openIn.intValue()) {
case 1:
binding.openInDetailedView.setChecked(true);
break;
case 2:
binding.openInBrowserCct.setChecked(true);
break;
case 3:
binding.openInBrowserExternal.setChecked(true);
break;
default:
throw new RuntimeException("Unreachable: openIn has illegal value " + openIn);
}
}

binding.openInUseGeneralSetting.setOnCheckedChangeListener((button, checked)
-> setOpenInForFeed(feed, null, checked));
binding.openInDetailedView.setOnCheckedChangeListener((button, checked)
-> setOpenInForFeed(feed, 1L, checked));
binding.openInBrowserCct.setOnCheckedChangeListener((button, checked)
-> setOpenInForFeed(feed, 2L, checked));
binding.openInBrowserExternal.setOnCheckedChangeListener((button, checked)
-> setOpenInForFeed(feed, 3L, checked));
}

private void showNotificationSettingsView(final long feedId) {
binding.lvMenuList.setVisibility(View.GONE);
binding.notificationFeedDialog.setVisibility(View.VISIBLE);
Expand Down Expand Up @@ -313,6 +357,14 @@ private void showNotificationSettingsView(final long feedId) {
setNotificationChannelForFeed(feed, feed.getFeedTitle(), checked));
}

private void setOpenInForFeed(Feed feed, Long openIn, Boolean checked) {
if (checked) {
feed.setOpenIn(openIn);
feed.update();
this.showOpenSettingsView(feed.getId()); // reload dialog
}
}

private void setNotificationChannelForFeed(Feed feed, String channel, Boolean checked) {
if (checked) {
feed.setNotificationChannel(channel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,39 @@

</LinearLayout>

<LinearLayout
android:id="@+id/open_feed_dialog"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/horizontalDivider"
android:orientation="vertical"
android:visibility="gone">

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/open_in_use_general_setting"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_feed_open_in_general_setting" />

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/open_in_detailed_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/action_feed_open_in_detailed_view" />

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/open_in_browser_cct"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_display_browser_cct" />

<com.google.android.material.radiobutton.MaterialRadioButton
android:id="@+id/open_in_browser_external"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pref_display_browser_external" />
</LinearLayout>

<RelativeLayout
android:id="@+id/progressView"
android:layout_width="match_parent"
Expand Down
4 changes: 4 additions & 0 deletions News-Android-App/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,16 @@
<string name="action_feed_rename">Rename Feed</string>
<string name="action_feed_move">Move Feed</string>
<string name="action_feed_notification_settings">Notification settings</string>
<string name="action_feed_open_in">Open-in settings</string>
<string name="action_feed_open_in_general_setting">Use general setting</string>
<string name="action_feed_open_in_detailed_view">Detailed view</string>
<string name="feed_remove_button">Remove</string>
<string name="feed_rename_button">Rename</string>
<string name="confirm_feed_remove">Do you really want to remove this Feed? This cannot be undone!</string>
<string name="feed_move_list_description">Select folder to move feed in</string>
<string name="move_feed_root_folder">Root folder</string>


<!-- Strings related to FolderOptionsDialogFragment (Rename/Remove folder) -->
<string name="action_folder_remove">Remove folder</string>
<string name="action_folder_rename">Rename folder</string>
Expand Down