Add preference to open item link in external navigator or webview
This commit is contained in:
parent
232a9f1efa
commit
097a5a7aae
@ -26,6 +26,7 @@ import com.readrops.app.database.pojo.ItemWithFeed;
|
|||||||
import com.readrops.app.utils.DateUtils;
|
import com.readrops.app.utils.DateUtils;
|
||||||
import com.readrops.app.utils.GlideApp;
|
import com.readrops.app.utils.GlideApp;
|
||||||
import com.readrops.app.utils.ReadropsWebView;
|
import com.readrops.app.utils.ReadropsWebView;
|
||||||
|
import com.readrops.app.utils.SharedPreferencesManager;
|
||||||
import com.readrops.app.utils.Utils;
|
import com.readrops.app.utils.Utils;
|
||||||
import com.readrops.app.viewmodels.ItemViewModel;
|
import com.readrops.app.viewmodels.ItemViewModel;
|
||||||
|
|
||||||
@ -113,7 +114,7 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
viewModel = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(ItemViewModel.class);
|
||||||
viewModel.getItemById(itemId).observe(this, this::bindUI);
|
viewModel.getItemById(itemId).observe(this, this::bindUI);
|
||||||
actionButton.setOnClickListener(v -> openLink());
|
actionButton.setOnClickListener(v -> openInNavigator());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void bindUI(ItemWithFeed itemWithFeed) {
|
private void bindUI(ItemWithFeed itemWithFeed) {
|
||||||
@ -207,7 +208,12 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
shareArticle();
|
shareArticle();
|
||||||
return true;
|
return true;
|
||||||
case R.id.item_open:
|
case R.id.item_open:
|
||||||
openLink();
|
int value = Integer.valueOf(SharedPreferencesManager.readString(this,
|
||||||
|
SharedPreferencesManager.SharedPrefKey.OPEN_ITEMS_IN));
|
||||||
|
if (value == 0)
|
||||||
|
openInNavigator();
|
||||||
|
else
|
||||||
|
openInWebView();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
@ -219,11 +225,18 @@ public class ItemActivity extends AppCompatActivity {
|
|||||||
super.onBackPressed();
|
super.onBackPressed();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void openLink() {
|
private void openInNavigator() {
|
||||||
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink()));
|
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink()));
|
||||||
startActivity(urlIntent);
|
startActivity(urlIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void openInWebView() {
|
||||||
|
Intent intent = new Intent(this, WebViewActivity.class);
|
||||||
|
intent.putExtra(WebViewActivity.WEB_URL, itemWithFeed.getItem().getLink());
|
||||||
|
|
||||||
|
startActivity(intent);
|
||||||
|
}
|
||||||
|
|
||||||
private void shareArticle() {
|
private void shareArticle() {
|
||||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
shareIntent.setType("text/plain");
|
shareIntent.setType("text/plain");
|
||||||
|
@ -50,15 +50,16 @@ public final class SharedPreferencesManager {
|
|||||||
|
|
||||||
public enum SharedPrefKey {
|
public enum SharedPrefKey {
|
||||||
SHOW_READ_ARTICLES("show_read_articles", false),
|
SHOW_READ_ARTICLES("show_read_articles", false),
|
||||||
ITEMS_TO_PARSE_MAX_NB("items_to_parse_max_nb", "20");
|
ITEMS_TO_PARSE_MAX_NB("items_to_parse_max_nb", "20"),
|
||||||
|
OPEN_ITEMS_IN("open_items_in", "0");
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private String key;
|
private String key;
|
||||||
@NonNull
|
@NonNull
|
||||||
private Object defaultValue;
|
private Object defaultValue;
|
||||||
|
|
||||||
public Boolean getBooleanDefaultValue() {
|
public boolean getBooleanDefaultValue() {
|
||||||
return (Boolean) defaultValue;
|
return (boolean) defaultValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getStringDefaultValue() {
|
public String getStringDefaultValue() {
|
||||||
|
@ -88,5 +88,8 @@
|
|||||||
<string name="feeds_colors">Couleurs des flux</string>
|
<string name="feeds_colors">Couleurs des flux</string>
|
||||||
<string name="global">Général</string>
|
<string name="global">Général</string>
|
||||||
<string name="reload_feeds_colors">Recharger les couleurs des flux</string>
|
<string name="reload_feeds_colors">Recharger les couleurs des flux</string>
|
||||||
|
<string name="open_items_in">Ouvrir les articles avec</string>
|
||||||
|
<string name="webview">Vue web</string>
|
||||||
|
<string name="external_navigator">Navigateur externe</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -19,4 +19,14 @@
|
|||||||
<item>@string/unlimited</item>
|
<item>@string/unlimited</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="open_items_in">
|
||||||
|
<item>@string/external_navigator</item>
|
||||||
|
<item>@string/webview</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="open_item_in_values">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -96,4 +96,7 @@
|
|||||||
<string name="feeds_colors">Feeds Colors</string>
|
<string name="feeds_colors">Feeds Colors</string>
|
||||||
<string name="global">Global</string>
|
<string name="global">Global</string>
|
||||||
<string name="reload_feeds_colors">Reload feeds colors</string>
|
<string name="reload_feeds_colors">Reload feeds colors</string>
|
||||||
|
<string name="open_items_in">Open items in</string>
|
||||||
|
<string name="webview">Webview</string>
|
||||||
|
<string name="external_navigator">External navigator</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -14,6 +14,13 @@
|
|||||||
<Preference
|
<Preference
|
||||||
android:key="reload_feeds_colors"
|
android:key="reload_feeds_colors"
|
||||||
android:title="@string/reload_feeds_colors" />
|
android:title="@string/reload_feeds_colors" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:defaultValue="@string/external_navigator"
|
||||||
|
android:entries="@array/open_items_in"
|
||||||
|
android:entryValues="@array/open_item_in_values"
|
||||||
|
android:key="open_items_in"
|
||||||
|
android:title="@string/open_items_in" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
x
Reference in New Issue
Block a user