Closes #257.
This commit is contained in:
parent
fa9cce6783
commit
9eac51e729
@ -1,5 +1,6 @@
|
|||||||
package apps.amine.bou.readerforselfoss
|
package apps.amine.bou.readerforselfoss
|
||||||
|
|
||||||
|
import android.content.SharedPreferences
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
@ -13,6 +14,7 @@ import android.view.Menu
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
|
import androidx.fragment.app.Fragment
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||||
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi
|
||||||
@ -51,6 +53,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
private lateinit var toolbarMenu: Menu
|
private lateinit var toolbarMenu: Menu
|
||||||
|
|
||||||
private lateinit var db: AppDatabase
|
private lateinit var db: AppDatabase
|
||||||
|
private lateinit var prefs: SharedPreferences
|
||||||
|
|
||||||
|
private var activeAlignment: Int = 1
|
||||||
|
val JUSTIFY = 1
|
||||||
|
val ALIGN_LEFT = 2
|
||||||
|
|
||||||
private fun showMenuItem(willAddToFavorite: Boolean) {
|
private fun showMenuItem(willAddToFavorite: Boolean) {
|
||||||
toolbarMenu.findItem(R.id.save).isVisible = willAddToFavorite
|
toolbarMenu.findItem(R.id.save).isVisible = willAddToFavorite
|
||||||
@ -65,6 +72,8 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
showMenuItem(false)
|
showMenuItem(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private lateinit var editor: SharedPreferences.Editor
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
@ -85,11 +94,13 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
supportActionBar?.setDisplayShowHomeEnabled(true)
|
supportActionBar?.setDisplayShowHomeEnabled(true)
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
prefs = PreferenceManager.getDefaultSharedPreferences(this)
|
||||||
|
editor = prefs.edit()
|
||||||
|
|
||||||
debugReadingItems = prefs.getBoolean("read_debug", false)
|
debugReadingItems = prefs.getBoolean("read_debug", false)
|
||||||
userIdentifier = prefs.getString("unique_id", "")
|
userIdentifier = prefs.getString("unique_id", "")
|
||||||
markOnScroll = prefs.getBoolean("mark_on_scroll", false)
|
markOnScroll = prefs.getBoolean("mark_on_scroll", false)
|
||||||
|
activeAlignment = prefs.getInt("text_align", JUSTIFY)
|
||||||
|
|
||||||
api = SelfossApi(
|
api = SelfossApi(
|
||||||
this,
|
this,
|
||||||
@ -223,6 +234,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun alignmentMenu(showJustify: Boolean) {
|
||||||
|
toolbarMenu.findItem(R.id.align_left).isVisible = !showJustify
|
||||||
|
toolbarMenu.findItem(R.id.align_justify).isVisible = showJustify
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
val inflater = menuInflater
|
val inflater = menuInflater
|
||||||
inflater.inflate(R.menu.reader_menu, menu)
|
inflater.inflate(R.menu.reader_menu, menu)
|
||||||
@ -233,6 +249,11 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
canFavorite()
|
canFavorite()
|
||||||
}
|
}
|
||||||
|
if (activeAlignment == JUSTIFY) {
|
||||||
|
alignmentMenu(false)
|
||||||
|
} else {
|
||||||
|
alignmentMenu(true)
|
||||||
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
@ -314,10 +335,29 @@ class ReaderActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
R.id.align_left -> {
|
||||||
|
editor.putInt("text_align", ALIGN_LEFT)
|
||||||
|
editor.apply()
|
||||||
|
alignmentMenu(true)
|
||||||
|
refreshFragment()
|
||||||
|
}
|
||||||
|
R.id.align_justify -> {
|
||||||
|
editor.putInt("text_align", JUSTIFY)
|
||||||
|
editor.apply()
|
||||||
|
alignmentMenu(false)
|
||||||
|
refreshFragment()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun refreshFragment() {
|
||||||
|
finish()
|
||||||
|
overridePendingTransition(0, 0)
|
||||||
|
startActivity(intent)
|
||||||
|
overridePendingTransition(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
var allItems: ArrayList<Item> = ArrayList()
|
var allItems: ArrayList<Item> = ArrayList()
|
||||||
}
|
}
|
||||||
|
@ -67,6 +67,7 @@ class ArticleFragment : Fragment() {
|
|||||||
private lateinit var fab: FloatingActionButton
|
private lateinit var fab: FloatingActionButton
|
||||||
private lateinit var appColors: AppColors
|
private lateinit var appColors: AppColors
|
||||||
private lateinit var db: AppDatabase
|
private lateinit var db: AppDatabase
|
||||||
|
private lateinit var textAlignment: String
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
super.onStop()
|
super.onStop()
|
||||||
@ -91,6 +92,7 @@ class ArticleFragment : Fragment() {
|
|||||||
|
|
||||||
private var rootView: ViewGroup? = null
|
private var rootView: ViewGroup? = null
|
||||||
|
|
||||||
|
private lateinit var prefs: SharedPreferences
|
||||||
|
|
||||||
override fun onCreateView(
|
override fun onCreateView(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
@ -107,9 +109,10 @@ class ArticleFragment : Fragment() {
|
|||||||
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!)
|
||||||
contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
|
contentSource = allItems[pageNumber.toInt()].sourceAndDateText()
|
||||||
|
|
||||||
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
prefs = PreferenceManager.getDefaultSharedPreferences(activity)
|
||||||
editor = prefs.edit()
|
editor = prefs.edit()
|
||||||
fontSize = prefs.getString("reader_font_size", "16").toInt()
|
fontSize = prefs.getString("reader_font_size", "16").toInt()
|
||||||
|
refreshAlignment()
|
||||||
|
|
||||||
val settings = activity!!.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
val settings = activity!!.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE)
|
||||||
val debugReadingItems = prefs.getBoolean("read_debug", false)
|
val debugReadingItems = prefs.getBoolean("read_debug", false)
|
||||||
@ -204,7 +207,7 @@ class ArticleFragment : Fragment() {
|
|||||||
} else {
|
} else {
|
||||||
rootView!!.titleView.text = contentTitle
|
rootView!!.titleView.text = contentTitle
|
||||||
|
|
||||||
htmlToWebview(contentText, prefs)
|
htmlToWebview()
|
||||||
|
|
||||||
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
if (!contentImage.isEmptyOrNullOrNullString() && context != null) {
|
||||||
rootView!!.imageView.visibility = View.VISIBLE
|
rootView!!.imageView.visibility = View.VISIBLE
|
||||||
@ -248,6 +251,14 @@ class ArticleFragment : Fragment() {
|
|||||||
return rootView
|
return rootView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun refreshAlignment() {
|
||||||
|
textAlignment = when (prefs.getInt("text_align", 1)) {
|
||||||
|
1 -> "justify"
|
||||||
|
2 -> "left"
|
||||||
|
else -> "justify"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun getContentFromMercury(
|
private fun getContentFromMercury(
|
||||||
customTabsIntent: CustomTabsIntent,
|
customTabsIntent: CustomTabsIntent,
|
||||||
prefs: SharedPreferences
|
prefs: SharedPreferences
|
||||||
@ -283,7 +294,8 @@ class ArticleFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
htmlToWebview(response.body()!!.content.orEmpty(), prefs)
|
contentText = response.body()!!.content.orEmpty()
|
||||||
|
htmlToWebview()
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
|
ACRA.getErrorReporter().maybeHandleSilentException(e, context!!)
|
||||||
@ -346,7 +358,7 @@ class ArticleFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun htmlToWebview(c: String, prefs: SharedPreferences) {
|
private fun htmlToWebview() {
|
||||||
val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent)
|
val stringColor = String.format("#%06X", 0xFFFFFF and appColors.colorAccent)
|
||||||
|
|
||||||
rootView!!.webcontent.visibility = View.VISIBLE
|
rootView!!.webcontent.visibility = View.VISIBLE
|
||||||
@ -428,12 +440,12 @@ class ArticleFragment : Fragment() {
|
|||||||
| }
|
| }
|
||||||
| * {
|
| * {
|
||||||
| font-size: ${fontSize}px;
|
| font-size: ${fontSize}px;
|
||||||
| text-align: justify;
|
| text-align: $textAlignment;
|
||||||
| word-break: break-word;
|
| word-break: break-word;
|
||||||
| overflow:hidden;
|
| overflow:hidden;
|
||||||
| }
|
| }
|
||||||
| a, pre, code {
|
| a, pre, code {
|
||||||
| text-align: left;
|
| text-align: $textAlignment;
|
||||||
| }
|
| }
|
||||||
| pre, code {
|
| pre, code {
|
||||||
| white-space: pre-wrap;
|
| white-space: pre-wrap;
|
||||||
@ -443,7 +455,7 @@ class ArticleFragment : Fragment() {
|
|||||||
| </style>
|
| </style>
|
||||||
|</head>
|
|</head>
|
||||||
|<body>
|
|<body>
|
||||||
| $c
|
| $contentText
|
||||||
|</body>""".trimMargin(),
|
|</body>""".trimMargin(),
|
||||||
"text/html",
|
"text/html",
|
||||||
"utf-8",
|
"utf-8",
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M3,21h18v-2L3,19v2zM3,17h18v-2L3,15v2zM3,13h18v-2L3,11v2zM3,9h18L21,7L3,7v2zM3,3v2h18L21,3L3,3z"/>
|
||||||
|
</vector>
|
@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M15,15L3,15v2h12v-2zM15,7L3,7v2h12L15,7zM3,13h18v-2L3,11v2zM3,21h18v-2L3,19v2zM3,3v2h18L21,3L3,3z"/>
|
||||||
|
</vector>
|
@ -2,6 +2,18 @@
|
|||||||
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<item android:id="@+id/align_left"
|
||||||
|
android:icon="@drawable/ic_format_align_left"
|
||||||
|
android:visible="true"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:title="@string/reader_text_align_left" />
|
||||||
|
|
||||||
|
<item android:id="@+id/align_justify"
|
||||||
|
android:icon="@drawable/ic_format_align_justify"
|
||||||
|
android:visible="true"
|
||||||
|
app:showAsAction="ifRoom"
|
||||||
|
android:title="@string/reader_text_align_justify" />
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/unsave"
|
android:id="@+id/unsave"
|
||||||
android:icon="@drawable/heart_on"
|
android:icon="@drawable/heart_on"
|
||||||
|
@ -170,4 +170,6 @@
|
|||||||
<string name="pref_header_experimental">Experimental</string>
|
<string name="pref_header_experimental">Experimental</string>
|
||||||
<string name="webview_dialog_issue_message">Webview not available. Disabling the article viewer to avoid any future crashes. Will load articles inside of your browser from now on.</string>
|
<string name="webview_dialog_issue_message">Webview not available. Disabling the article viewer to avoid any future crashes. Will load articles inside of your browser from now on.</string>
|
||||||
<string name="webview_dialog_issue_title">Webview issue</string>
|
<string name="webview_dialog_issue_title">Webview issue</string>
|
||||||
|
<string name="reader_text_align_left">Align left</string>
|
||||||
|
<string name="reader_text_align_justify">Justify</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user