diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt index a736528..dd645a5 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/ReaderActivity.kt @@ -103,7 +103,8 @@ class ReaderActivity : AppCompatActivity(), DIAware { FragmentStateAdapter(fa) { override fun getItemCount(): Int = allItems.size - override fun createFragment(position: Int): Fragment = ArticleFragment.newInstance(allItems[position]) + override fun createFragment(position: Int): Fragment = + ArticleFragment.newInstance(allItems[position]) } override fun onKeyDown( @@ -114,15 +115,17 @@ class ReaderActivity : AppCompatActivity(), DIAware { KeyEvent.KEYCODE_VOLUME_DOWN -> { val currentFragment = supportFragmentManager.findFragmentByTag("f" + binding.pager.currentItem) as ArticleFragment - currentFragment.scrollDown() + currentFragment.volumeButtonScrollDown() true } + KeyEvent.KEYCODE_VOLUME_UP -> { val currentFragment = supportFragmentManager.findFragmentByTag("f" + binding.pager.currentItem) as ArticleFragment - currentFragment.scrollUp() + currentFragment.volumeButtonScrollUp() true } + else -> { super.onKeyDown(keyCode, event) } @@ -187,6 +190,7 @@ class ReaderActivity : AppCompatActivity(), DIAware { onBackPressedDispatcher.onBackPressed() return true } + R.id.star -> { if (allItems[binding.pager.currentItem].starred) { CoroutineScope(Dispatchers.IO).launch { @@ -200,10 +204,12 @@ class ReaderActivity : AppCompatActivity(), DIAware { afterSave() } } + R.id.align_left -> { switchAlignmentSetting(AppSettingsService.ALIGN_LEFT) refreshFragment() } + R.id.align_justify -> { switchAlignmentSetting(AppSettingsService.JUSTIFY) refreshFragment() @@ -223,4 +229,4 @@ class ReaderActivity : AppCompatActivity(), DIAware { startActivity(intent) overridePendingTransition(0, 0) } -} +} \ No newline at end of file diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt index 84226de..df42e99 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/fragments/ArticleFragment.kt @@ -1,5 +1,6 @@ package bou.amine.apps.readerforselfossv2.android.fragments +import android.content.Context import android.content.Intent import android.content.res.ColorStateList import android.content.res.TypedArray @@ -8,6 +9,7 @@ import android.graphics.Typeface import android.graphics.drawable.ColorDrawable import android.os.Bundle import android.util.TypedValue +import android.util.TypedValue.DATA_NULL_UNDEFINED import android.view.GestureDetector import android.view.InflateException import android.view.LayoutInflater @@ -399,19 +401,45 @@ class ArticleFragment : Fragment(), DIAware { } private fun htmlToWebview() { + val context: Context + try { + context = requireContext() + } catch (e: IllegalStateException) { + e.sendSilentlyWithAcraWithName("Context required is null") + return + } + + val colorOnSurface = TypedValue() + val colorSurface = TypedValue() + try { val attrs: IntArray = intArrayOf(android.R.attr.fontFamily) - val a: TypedArray = requireContext().obtainStyledAttributes(resId, attrs) + val a: TypedArray = context.obtainStyledAttributes(resId, attrs) binding.webcontent.settings.standardFontFamily = a.getString(0) binding.webcontent.visibility = View.VISIBLE - val colorOnSurface = TypedValue() - requireContext().theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true) + context.theme.resolveAttribute(R.attr.colorOnSurface, colorOnSurface, true) - val colorSurface = TypedValue() - requireContext().theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) + context.theme.resolveAttribute(R.attr.colorSurface, colorSurface, true) + } catch (e: IllegalStateException) { + e.sendSilentlyWithAcraWithName("Context issue when setting attributes, but context wasn't null before") + } + + val colorSurfaceString = + String.format( + "#%06X", + 0xFFFFFF and (if (colorSurface.data != DATA_NULL_UNDEFINED) colorSurface.data else 0xFFFFFF), + ) + + val colorOnSurfaceString = + String.format( + "#%06X", + 0xFFFFFF and (if (colorOnSurface.data != DATA_NULL_UNDEFINED) colorOnSurface.data else 0), + ) + + try { binding.webcontent.settings.useWideViewPort = true binding.webcontent.settings.loadWithOverviewMode = true binding.webcontent.settings.javaScriptEnabled = false @@ -428,13 +456,21 @@ class ArticleFragment : Fragment(), DIAware { }, ) - binding.webcontent.setOnTouchListener { _, event -> gestureDetector.onTouchEvent(event) } + binding.webcontent.setOnTouchListener { _, event -> + gestureDetector.onTouchEvent( + event + ) + } binding.webcontent.settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING + } catch (e: IllegalStateException) { + e.sendSilentlyWithAcraWithName("Context is null but wasn't, and that's causing issues with webview config") + return + } + try { var baseUrl: String? = null - try { val itemUrl = URL(url) baseUrl = itemUrl.protocol + "://" + itemUrl.host @@ -484,12 +520,12 @@ class ArticleFragment : Fragment(), DIAware { | color: ${ String.format( "#%06X", - 0xFFFFFF and resources.getColor(R.color.colorAccent), + 0xFFFFFF and context.resources.getColor(R.color.colorAccent), ) } !important; | } | *:not(a) { - | color: ${String.format("#%06X", 0xFFFFFF and colorOnSurface.data)}; + | color: $colorOnSurfaceString; | } | * { | font-size: ${fontSize}px; @@ -497,26 +533,11 @@ class ArticleFragment : Fragment(), DIAware { | word-break: break-word; | overflow:hidden; | line-height: 1.5em; - | background-color: ${ - String.format( - "#%06X", - 0xFFFFFF and colorSurface.data, - ) - }; + | background-color: $colorSurfaceString; | } | body, html { - | background-color: ${ - String.format( - "#%06X", - 0xFFFFFF and colorSurface.data, - ) - } !important; - | border-color: ${ - String.format( - "#%06X", - 0xFFFFFF and colorSurface.data, - ) - } !important; + | background-color: $colorSurfaceString !important; + | border-color: $colorSurfaceString !important; | padding: 0 !important; | margin: 0 !important; | } @@ -526,12 +547,7 @@ class ArticleFragment : Fragment(), DIAware { | pre, code { | white-space: pre-wrap; | width:100%; - | background-color: ${ - String.format( - "#%06X", - 0xFFFFFF and colorSurface.data, - ) - }; + | background-color: $colorSurfaceString; | } | | $fontLinkAndStyle @@ -545,16 +561,16 @@ class ArticleFragment : Fragment(), DIAware { null, ) } catch (e: IllegalStateException) { - e.sendSilentlyWithAcraWithName("Context required is null") + e.sendSilentlyWithAcraWithName("Context required is still null ?") } } - fun scrollDown() { + fun volumeButtonScrollDown() { val height = binding.nestedScrollView.measuredHeight binding.nestedScrollView.smoothScrollBy(0, height / 2) } - fun scrollUp() { + fun volumeButtonScrollUp() { val height = binding.nestedScrollView.measuredHeight binding.nestedScrollView.smoothScrollBy(0, -height / 2) } diff --git a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt index 0ea06be..f0594fe 100644 --- a/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt +++ b/androidApp/src/main/java/bou/amine/apps/readerforselfossv2/android/settings/SettingsActivity.kt @@ -17,6 +17,9 @@ import bou.amine.apps.readerforselfossv2.android.databinding.ActivitySettingsBin import bou.amine.apps.readerforselfossv2.android.utils.acra.sendSilentlyWithAcraWithName import bou.amine.apps.readerforselfossv2.android.utils.openUrlInBrowser import bou.amine.apps.readerforselfossv2.service.AppSettingsService +import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.API_ITEMS_NUMBER +import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.CURRENT_THEME +import bou.amine.apps.readerforselfossv2.service.AppSettingsService.Companion.READER_FONT_SIZE import com.mikepenz.aboutlibraries.LibsBuilder import org.kodein.di.DIAware import org.kodein.di.android.closestDI @@ -102,7 +105,7 @@ class SettingsActivity : ) { setPreferencesFromResource(R.xml.pref_main, rootKey) - preferenceManager.findPreference("currentMode")?.onPreferenceChangeListener = + preferenceManager.findPreference(CURRENT_THEME)?.onPreferenceChangeListener = Preference.OnPreferenceChangeListener { _, newValue -> AppCompatDelegate.setDefaultNightMode( newValue.toString().toInt() @@ -131,7 +134,7 @@ class SettingsActivity : setPreferencesFromResource(R.xml.pref_general, rootKey) val editTextPreference = - preferenceManager.findPreference("prefer_api_items_number") + preferenceManager.findPreference(API_ITEMS_NUMBER) editTextPreference?.setOnBindEditTextListener { editText -> editText.inputType = InputType.TYPE_CLASS_NUMBER editText.filters = @@ -161,7 +164,7 @@ class SettingsActivity : ) { setPreferencesFromResource(R.xml.pref_viewer, rootKey) - val fontSize = preferenceManager.findPreference("reader_font_size") + val fontSize = preferenceManager.findPreference(READER_FONT_SIZE) fontSize?.setOnBindEditTextListener { editText -> editText.inputType = InputType.TYPE_CLASS_NUMBER editText.addTextChangedListener { @@ -218,23 +221,6 @@ class SettingsActivity : } } - class ThemePreferenceFragment : PreferenceFragmentCompat() { - override fun onCreatePreferences( - savedInstanceState: Bundle?, - rootKey: String?, - ) { - setPreferencesFromResource(R.xml.pref_theme, rootKey) - - preferenceManager.findPreference("currentMode")?.onPreferenceChangeListener = - Preference.OnPreferenceChangeListener { _, newValue -> - AppCompatDelegate.setDefaultNightMode( - newValue.toString().toInt() - ) // ListPreference Only takes string-arrays ¯\_(ツ)_/¯ - true - } - } - } - class LinksPreferenceFragment : PreferenceFragmentCompat() { private fun openUrl(url: String) { context?.openUrlInBrowser(url) diff --git a/androidApp/src/main/res/xml/pref_theme.xml b/androidApp/src/main/res/xml/pref_theme.xml deleted file mode 100644 index 5a6ea0b..0000000 --- a/androidApp/src/main/res/xml/pref_theme.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - \ No newline at end of file