diff --git a/app/build.gradle b/app/build.gradle index 7a6f27ac..9464b20e 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -62,7 +62,6 @@ dependencies { implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0' implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0' implementation 'androidx.preference:preference:1.1.1' - implementation 'androidx.webkit:webkit:1.3.0-alpha02' implementation 'androidx.camera:camera-camera2:1.0.0-beta03' implementation 'androidx.camera:camera-lifecycle:1.0.0-beta03' implementation 'androidx.camera:camera-view:1.0.0-alpha10' diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 854fd6cb..c03e8727 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -17,6 +17,7 @@ import android.content.res.Configuration; import android.content.res.TypedArray; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; +import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; @@ -26,7 +27,10 @@ import android.os.Handler; import android.provider.MediaStore; import android.support.v4.media.session.MediaSessionCompat; import android.text.Editable; +import android.text.Spannable; +import android.text.SpannableString; import android.text.TextWatcher; +import android.text.style.TypefaceSpan; import android.util.Base64; import android.util.Log; import android.view.KeyEvent; @@ -35,7 +39,6 @@ import android.view.Menu; import android.view.WindowManager; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.InputMethodManager; -import android.webkit.WebView; import android.widget.EditText; import android.widget.ImageView; import android.widget.TextView; @@ -63,6 +66,7 @@ import androidx.core.app.NotificationManagerCompat; import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.core.content.res.ResourcesCompat; +import androidx.core.graphics.TypefaceCompat; import androidx.core.graphics.drawable.DrawableCompat; import androidx.core.view.GravityCompat; import androidx.core.view.OnApplyWindowInsetsListener; @@ -338,8 +342,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener @Override protected void onCreate(Bundle savedInstanceState) { - // workaround to fix dark theme because https://issuetracker.google.com/issues/37124582 - new WebView(this); AppCompatDelegate.setDefaultNightMode(isDarkMode() ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO); initKeyStore(); @@ -542,6 +544,15 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener } } + public void setActionBarTitle(int stringResourceId) { + ActionBar actionBar = getSupportActionBar(); + if (actionBar != null) { + SpannableString spannable = new SpannableString(getString(stringResourceId)); + spannable.setSpan(new TypefaceSpan("inter"), 0, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + actionBar.setTitle(spannable); + } + } + public void addScreenOrientationListener(ScreenOrientationListener listener) { if (!screenOrientationListeners.contains(listener)) { screenOrientationListeners.add(listener); diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java index 441ba9b1..e8ae6052 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFormFragment.java @@ -503,10 +503,8 @@ public class ChannelFormFragment extends BaseFragment implements activity.addFilePickerListener(this); activity.addWalletBalanceListener(this); - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(editMode ? R.string.edit_channel : R.string.create_a_channel); - } + activity.setActionBarTitle(editMode ? R.string.edit_channel : R.string.create_a_channel); + } } @@ -544,10 +542,7 @@ public class ChannelFormFragment extends BaseFragment implements LbryAnalytics.setCurrentScreen(activity, "Channel Form", "ChannelForm"); activity.addStoragePermissionListener(this); if (editMode) { - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(R.string.edit_channel); - } + activity.setActionBarTitle(R.string.edit_channel); } } String filterText = Helper.getValue(inputTagFilter.getText()); diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index a36ce9fc..f464af14 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -37,8 +37,6 @@ import androidx.media.session.MediaButtonReceiver; import androidx.preference.PreferenceManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; -import androidx.webkit.WebSettingsCompat; -import androidx.webkit.WebViewFeature; import com.bumptech.glide.Glide; import com.github.chrisbanes.photoview.PhotoView; @@ -176,9 +174,6 @@ public class FileViewFragment extends BaseFragment implements private View layoutDisplayArea; private View layoutResolving; - private WebView webView; - private boolean webViewAdded; - public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_file_view, container, false); @@ -365,30 +360,11 @@ public class FileViewFragment extends BaseFragment implements } private void initWebView(View root) { - Context ctx = getContext(); - if (ctx != null) { - if (webView == null) { - webView = new WebView(ctx); - webView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT)); - webView.setWebViewClient(new LbryWebViewClient(ctx)); - WebSettings webSettings = webView.getSettings(); - webSettings.setAllowFileAccess(true); - webSettings.setJavaScriptEnabled(true); - } - - if (!webViewAdded && root != null) { - ((RelativeLayout) root.findViewById(R.id.file_view_webview_container)).addView(webView); - webViewAdded = true; - } - } - } - - private void applyThemeToWebView() { - Context context = getContext(); - if (context instanceof MainActivity && webView != null && WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { - MainActivity activity = (MainActivity) context; - WebSettingsCompat.setForceDark(webView.getSettings(), activity.isDarkMode() ? WebSettingsCompat.FORCE_DARK_ON : WebSettingsCompat.FORCE_DARK_OFF); - } + WebView webView = root.findViewById(R.id.file_view_webview); + webView.setWebViewClient(new LbryWebViewClient(getContext())); + WebSettings webSettings = webView.getSettings(); + webSettings.setAllowFileAccess(true); + webSettings.setJavaScriptEnabled(true); } private void logUrlEvent(String url) { @@ -569,13 +545,6 @@ public class FileViewFragment extends BaseFragment implements activity.removeStoragePermissionListener(this); //activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } - - if (webView != null) { - webView.removeAllViews(); - webView.loadUrl("about:blank"); - webView.destroy(); - webView = null; - } } private void setPlayerForPlayerView() { @@ -1616,9 +1585,7 @@ public class FileViewFragment extends BaseFragment implements } else if (mediaType.startsWith("text")) { // show web view (and parse markdown too) View container = root.findViewById(R.id.file_view_webview_container); - initWebView(root); - applyThemeToWebView(); - + WebView webView = root.findViewById(R.id.file_view_webview); if (Arrays.asList("text/markdown", "text/md").contains(mediaType.toLowerCase())) { loadMarkdownFromFile(claimFile.getDownloadPath()); } else { @@ -1643,9 +1610,8 @@ public class FileViewFragment extends BaseFragment implements @Override public void onSuccess(String text) { String html = buildMarkdownHtml(text); - if (webView != null) { - webView.loadData(html, "text/html", "utf-8"); - } + WebView webView = getView().findViewById(R.id.file_view_webview); + webView.loadData(html, "text/html", "utf-8"); } @Override diff --git a/app/src/main/java/io/lbry/browser/ui/other/AboutFragment.java b/app/src/main/java/io/lbry/browser/ui/other/AboutFragment.java index 0923ad1b..8091014f 100644 --- a/app/src/main/java/io/lbry/browser/ui/other/AboutFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/other/AboutFragment.java @@ -180,10 +180,7 @@ public class AboutFragment extends BaseFragment implements SdkStatusListener { activity.lockDrawer(); activity.hideFloatingWalletBalance(); - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(R.string.about_lbry); - } + activity.setActionBarTitle(R.string.about_lbry); } } diff --git a/app/src/main/java/io/lbry/browser/ui/other/SettingsFragment.java b/app/src/main/java/io/lbry/browser/ui/other/SettingsFragment.java index 6cf4deaf..7e93b6ca 100644 --- a/app/src/main/java/io/lbry/browser/ui/other/SettingsFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/other/SettingsFragment.java @@ -35,10 +35,7 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared activity.lockDrawer(); activity.hideFloatingWalletBalance(); - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(R.string.settings); - } + activity.setActionBarTitle(R.string.settings); } } diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index 7e5614ac..368d7481 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -499,10 +499,7 @@ public class PublishFormFragment extends BaseFragment implements activity.addFilePickerListener(this); activity.addWalletBalanceListener(this); - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(editMode ? R.string.edit_content : R.string.new_publish); - } + activity.setActionBarTitle(editMode ? R.string.edit_content : R.string.new_publish); } } @@ -889,10 +886,7 @@ public class PublishFormFragment extends BaseFragment implements LbryAnalytics.setCurrentScreen(activity, "Channel Form", "ChannelForm"); activity.addStoragePermissionListener(this); if (editMode) { - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(R.string.edit_content); - } + activity.setActionBarTitle(R.string.edit_content); } } diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/TransactionHistoryFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/TransactionHistoryFragment.java index d9b70c7c..32df97ca 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/TransactionHistoryFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/TransactionHistoryFragment.java @@ -10,6 +10,7 @@ import android.widget.ProgressBar; import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; +import androidx.core.content.ContextCompat; import androidx.recyclerview.widget.DividerItemDecoration; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; @@ -48,7 +49,9 @@ public class TransactionHistoryFragment extends BaseFragment implements Transact Context context = getContext(); LinearLayoutManager llm = new LinearLayoutManager(context); transactionList.setLayoutManager(llm); - transactionList.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL)); + DividerItemDecoration itemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL); + itemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.thin_divider)); + transactionList.addItemDecoration(itemDecoration); transactionList.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override @@ -133,10 +136,7 @@ public class TransactionHistoryFragment extends BaseFragment implements Transact activity.showNavigationBackIcon(); activity.lockDrawer(); - ActionBar actionBar = activity.getSupportActionBar(); - if (actionBar != null) { - actionBar.setTitle(R.string.transaction_history); - } + activity.setActionBarTitle(R.string.transaction_history); } } diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index c414b88d..9a61879a 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -633,6 +633,9 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:visibility="gone"> - + \ No newline at end of file