mirror of https://github.com/readrops/Readrops.git
Add an option to open item url in custom tab
This commit is contained in:
parent
e0945823ee
commit
c15f093a1b
|
@ -71,7 +71,7 @@ dependencies {
|
|||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
implementation "androidx.work:work-runtime-ktx:2.4.0"
|
||||
implementation "androidx.fragment:fragment-ktx:1.2.3"
|
||||
|
||||
implementation "androidx.browser:browser:1.2.0"
|
||||
|
||||
testImplementation 'junit:junit:4.12'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
|
|
|
@ -22,6 +22,7 @@ import android.webkit.WebView;
|
|||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.browser.customtabs.CustomTabsIntent;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.app.ShareCompat;
|
||||
import androidx.lifecycle.ViewModelProvider;
|
||||
|
@ -199,12 +200,7 @@ public class ItemActivity extends AppCompatActivity {
|
|||
shareArticle();
|
||||
return true;
|
||||
case R.id.item_open:
|
||||
int value = Integer.parseInt(SharedPreferencesManager.readString(this,
|
||||
SharedPreferencesManager.SharedPrefKey.OPEN_ITEMS_IN));
|
||||
if (value == 0)
|
||||
openInNavigator();
|
||||
else
|
||||
openInWebView();
|
||||
openUrl();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
@ -217,6 +213,22 @@ public class ItemActivity extends AppCompatActivity {
|
|||
super.onBackPressed();
|
||||
}
|
||||
|
||||
private void openUrl() {
|
||||
int value = Integer.parseInt(SharedPreferencesManager.readString(this,
|
||||
SharedPreferencesManager.SharedPrefKey.OPEN_ITEMS_IN));
|
||||
switch (value) {
|
||||
case 0:
|
||||
openInNavigator();
|
||||
break;
|
||||
case 1:
|
||||
openInWebView();
|
||||
break;
|
||||
default:
|
||||
openInCustomTab();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void openInNavigator() {
|
||||
Intent urlIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(itemWithFeed.getItem().getLink()));
|
||||
startActivity(urlIntent);
|
||||
|
@ -225,11 +237,27 @@ public class ItemActivity extends AppCompatActivity {
|
|||
private void openInWebView() {
|
||||
Intent intent = new Intent(this, WebViewActivity.class);
|
||||
intent.putExtra(WEB_URL, itemWithFeed.getItem().getLink());
|
||||
intent.putExtra(ACTION_BAR_COLOR, itemWithFeed.getColor() != 0 ? itemWithFeed.getColor() : itemWithFeed.getBgColor());
|
||||
intent.putExtra(ACTION_BAR_COLOR, itemWithFeed.getBgColor() != 0 ? itemWithFeed.getBgColor() : itemWithFeed.getColor());
|
||||
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
private void openInCustomTab() {
|
||||
boolean darkTheme = Boolean.parseBoolean(SharedPreferencesManager.readString(this, SharedPreferencesManager.SharedPrefKey.DARK_THEME));
|
||||
int color = itemWithFeed.getBgColor() != 0 ? itemWithFeed.getBgColor() : itemWithFeed.getColor();
|
||||
|
||||
CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder()
|
||||
.addDefaultShareMenuItem()
|
||||
.setToolbarColor(color)
|
||||
.setSecondaryToolbarColor(color)
|
||||
.setColorScheme(darkTheme ? CustomTabsIntent.COLOR_SCHEME_DARK : CustomTabsIntent.COLOR_SCHEME_LIGHT)
|
||||
.enableUrlBarHiding()
|
||||
.setShowTitle(true)
|
||||
.build();
|
||||
|
||||
customTabsIntent.launchUrl(this, Uri.parse(itemWithFeed.getItem().getLink()));
|
||||
}
|
||||
|
||||
private void shareArticle() {
|
||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
|
|
|
@ -132,5 +132,6 @@
|
|||
<string name="show_caption">Afficher la légende</string>
|
||||
<string name="password_helper">Votre mot de passe d\'API (Configuration > Profil)</string>
|
||||
<string name="synchronize">Synchroniser</string>
|
||||
<string name="navigator_view">Vue navigateur</string>
|
||||
|
||||
</resources>
|
|
@ -33,11 +33,13 @@
|
|||
<string-array name="open_items_in">
|
||||
<item>@string/external_navigator</item>
|
||||
<item>@string/webview</item>
|
||||
<item>@string/navigator_view</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="open_item_in_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="themes">
|
||||
|
|
|
@ -138,4 +138,5 @@
|
|||
<string name="back">Back</string>
|
||||
<string name="show_caption">Show caption</string>
|
||||
<string name="synchronize">Synchronize</string>
|
||||
<string name="navigator_view">Navigator view</string>
|
||||
</resources>
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
android:title="@string/reload_feeds_colors" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:defaultValue="2"
|
||||
android:entries="@array/open_items_in"
|
||||
android:entryValues="@array/open_item_in_values"
|
||||
android:key="open_items_in"
|
||||
|
|
Loading…
Reference in New Issue