Compare commits
	
		
			7 Commits
		
	
	
		
			v171811332
			...
			v171812343
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 9eac51e729 | ||
|  | fa9cce6783 | ||
|  | f0d4b63a97 | ||
|  | 83eeb11388 | ||
|  | 01f746f33d | ||
|  | 200851894b | ||
|  | 862e5cf4ab | 
| @@ -2,7 +2,15 @@ buildscript { | ||||
| } | ||||
|  | ||||
| def gitVersion() { | ||||
|     def process = "git for-each-ref refs/tags --sort=-authordate --format='%(refname:short)' --count=1".execute() | ||||
|     def process | ||||
|     def maybeTagOfCurrentCommit = 'git describe --contains HEAD'.execute() | ||||
|     if (maybeTagOfCurrentCommit.text.isEmpty()) { | ||||
|         println "No tag on current commit. Will take the latest one." | ||||
|         process = "git for-each-ref refs/tags --sort=-authordate --format='%(refname:short)' --count=1".execute() | ||||
|     } else { | ||||
|         println "Tag found on current commit" | ||||
|         process = 'git describe --contains HEAD'.execute() | ||||
|     } | ||||
|     return process.text.replaceAll("'", "").substring(1).replaceAll("\\.", "").trim() | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,6 @@ | ||||
| package apps.amine.bou.readerforselfoss | ||||
|  | ||||
| import android.content.SharedPreferences | ||||
| import android.graphics.drawable.ColorDrawable | ||||
| import android.os.Build | ||||
| import android.os.Bundle | ||||
| @@ -13,6 +14,7 @@ import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import android.view.ViewGroup | ||||
| import android.widget.Toast | ||||
| import androidx.fragment.app.Fragment | ||||
| import androidx.room.Room | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.Item | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi | ||||
| @@ -51,6 +53,11 @@ class ReaderActivity : AppCompatActivity() { | ||||
|     private lateinit var toolbarMenu: Menu | ||||
|  | ||||
|     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) { | ||||
|         toolbarMenu.findItem(R.id.save).isVisible = willAddToFavorite | ||||
| @@ -65,6 +72,8 @@ class ReaderActivity : AppCompatActivity() { | ||||
|         showMenuItem(false) | ||||
|     } | ||||
|  | ||||
|     private lateinit var editor: SharedPreferences.Editor | ||||
|  | ||||
|     override fun onCreate(savedInstanceState: Bundle?) { | ||||
|         super.onCreate(savedInstanceState) | ||||
|  | ||||
| @@ -85,11 +94,13 @@ class ReaderActivity : AppCompatActivity() { | ||||
|         supportActionBar?.setDisplayHomeAsUpEnabled(true) | ||||
|         supportActionBar?.setDisplayShowHomeEnabled(true) | ||||
|  | ||||
|         val prefs = PreferenceManager.getDefaultSharedPreferences(this) | ||||
|         prefs = PreferenceManager.getDefaultSharedPreferences(this) | ||||
|         editor = prefs.edit() | ||||
|  | ||||
|         debugReadingItems = prefs.getBoolean("read_debug", false) | ||||
|         userIdentifier = prefs.getString("unique_id", "") | ||||
|         markOnScroll = prefs.getBoolean("mark_on_scroll", false) | ||||
|         activeAlignment = prefs.getInt("text_align", JUSTIFY) | ||||
|  | ||||
|         api = SelfossApi( | ||||
|             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 { | ||||
|         val inflater = menuInflater | ||||
|         inflater.inflate(R.menu.reader_menu, menu) | ||||
| @@ -233,6 +249,11 @@ class ReaderActivity : AppCompatActivity() { | ||||
|         } else { | ||||
|             canFavorite() | ||||
|         } | ||||
|         if (activeAlignment == JUSTIFY) { | ||||
|             alignmentMenu(false) | ||||
|         } else { | ||||
|             alignmentMenu(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) | ||||
|     } | ||||
|  | ||||
|     private fun refreshFragment() { | ||||
|         finish() | ||||
|         overridePendingTransition(0, 0) | ||||
|         startActivity(intent) | ||||
|         overridePendingTransition(0, 0) | ||||
|     } | ||||
|  | ||||
|     companion object { | ||||
|         var allItems: ArrayList<Item> = ArrayList() | ||||
|     } | ||||
|   | ||||
| @@ -67,6 +67,7 @@ class ArticleFragment : Fragment() { | ||||
|     private lateinit var fab: FloatingActionButton | ||||
|     private lateinit var appColors: AppColors | ||||
|     private lateinit var db: AppDatabase | ||||
|     private lateinit var textAlignment: String | ||||
|  | ||||
|     override fun onStop() { | ||||
|         super.onStop() | ||||
| @@ -91,6 +92,7 @@ class ArticleFragment : Fragment() { | ||||
|  | ||||
|     private var rootView: ViewGroup? = null | ||||
|  | ||||
|     private lateinit var prefs: SharedPreferences | ||||
|  | ||||
|     override fun onCreateView( | ||||
|         inflater: LayoutInflater, | ||||
| @@ -107,9 +109,10 @@ class ArticleFragment : Fragment() { | ||||
|             contentImage = allItems[pageNumber.toInt()].getThumbnail(activity!!) | ||||
|             contentSource = allItems[pageNumber.toInt()].sourceAndDateText() | ||||
|  | ||||
|             val prefs = PreferenceManager.getDefaultSharedPreferences(activity) | ||||
|             prefs = PreferenceManager.getDefaultSharedPreferences(activity) | ||||
|             editor = prefs.edit() | ||||
|             fontSize = prefs.getString("reader_font_size", "16").toInt() | ||||
|             refreshAlignment() | ||||
|  | ||||
|             val settings = activity!!.getSharedPreferences(Config.settingsName, Context.MODE_PRIVATE) | ||||
|             val debugReadingItems = prefs.getBoolean("read_debug", false) | ||||
| @@ -204,7 +207,7 @@ class ArticleFragment : Fragment() { | ||||
|             } else { | ||||
|                 rootView!!.titleView.text = contentTitle | ||||
|  | ||||
|                 htmlToWebview(contentText, prefs) | ||||
|                 htmlToWebview() | ||||
|  | ||||
|                 if (!contentImage.isEmptyOrNullOrNullString() && context != null) { | ||||
|                     rootView!!.imageView.visibility = View.VISIBLE | ||||
| @@ -248,6 +251,14 @@ class ArticleFragment : Fragment() { | ||||
|         return rootView | ||||
|     } | ||||
|  | ||||
|     private fun refreshAlignment() { | ||||
|         textAlignment = when (prefs.getInt("text_align", 1)) { | ||||
|             1 -> "justify" | ||||
|             2 -> "left" | ||||
|             else -> "justify" | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     private fun getContentFromMercury( | ||||
|         customTabsIntent: CustomTabsIntent, | ||||
|         prefs: SharedPreferences | ||||
| @@ -274,7 +285,7 @@ class ArticleFragment : Fragment() { | ||||
|                                         URL(response.body()!!.url) | ||||
|                                         url = response.body()!!.url | ||||
|                                     } catch (e: MalformedURLException) { | ||||
|                                         ACRA.getErrorReporter().maybeHandleSilentException(e, activity!!) | ||||
|                                         // Mercury returned a relative url. We do nothing. | ||||
|                                     } | ||||
|                                 } catch (e: Exception) { | ||||
|                                     if (context != null) { | ||||
| @@ -283,7 +294,8 @@ class ArticleFragment : Fragment() { | ||||
|                                 } | ||||
|  | ||||
|                                 try { | ||||
|                                     htmlToWebview(response.body()!!.content.orEmpty(), prefs) | ||||
|                                     contentText = response.body()!!.content.orEmpty() | ||||
|                                     htmlToWebview() | ||||
|                                 } catch (e: Exception) { | ||||
|                                     if (context != null) { | ||||
|                                         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) | ||||
|  | ||||
|         rootView!!.webcontent.visibility = View.VISIBLE | ||||
| @@ -428,12 +440,12 @@ class ArticleFragment : Fragment() { | ||||
|                 |      } | ||||
|                 |      * { | ||||
|                 |        font-size: ${fontSize}px; | ||||
|                 |        text-align: justify; | ||||
|                 |        text-align: $textAlignment; | ||||
|                 |        word-break: break-word; | ||||
|                 |        overflow:hidden; | ||||
|                 |      } | ||||
|                 |      a, pre, code { | ||||
|                 |        text-align: left; | ||||
|                 |        text-align: $textAlignment; | ||||
|                 |      } | ||||
|                 |      pre, code { | ||||
|                 |        white-space: pre-wrap; | ||||
| @@ -443,7 +455,7 @@ class ArticleFragment : Fragment() { | ||||
|                 |   </style> | ||||
|                 |</head> | ||||
|                 |<body> | ||||
|                 |   $c | ||||
|                 |   $contentText | ||||
|                 |</body>""".trimMargin(), | ||||
|             "text/html", | ||||
|             "utf-8", | ||||
|   | ||||
| @@ -148,11 +148,7 @@ fun String.isBaseUrlValid(logErrors: Boolean, ctx: Context): Boolean { | ||||
|         existsAndEndsWithSlash = "" == pathSegments[pathSegments.size - 1] | ||||
|     } | ||||
|  | ||||
|     val isValid = Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash | ||||
|     if (!isValid && logErrors) { | ||||
|         ACRA.getErrorReporter().doHandleSilentException(java.lang.Exception("Patterns.WEB_URL.matcher(this).matches() == ${Patterns.WEB_URL.matcher(this).matches()} && existsAndEndsWithSlash == $existsAndEndsWithSlash && baseUrl.pathSegments() == ${baseUrl?.pathSegments()}"), ctx) | ||||
|     } | ||||
|     return isValid | ||||
|     return Patterns.WEB_URL.matcher(this).matches() && existsAndEndsWithSlash | ||||
| } | ||||
|  | ||||
| fun Context.openInBrowserAsNewTask(i: Item) { | ||||
|   | ||||
| @@ -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" | ||||
|     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 | ||||
|         android:id="@+id/unsave" | ||||
|         android:icon="@drawable/heart_on" | ||||
|   | ||||
| @@ -168,6 +168,6 @@ | ||||
|     <string name="shortcut_offline">Sin conexión</string> | ||||
|     <string name="pref_api_timeout">Se acabó el tiempo de espera de la API</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_title">Webview issue</string> | ||||
|     <string name="webview_dialog_issue_message">Visor web no disponible. Desactivando el visor de artículo para evitar cualquier futuro problema. Se cargarán artículos en el navegador de ahora en adelante.</string> | ||||
|     <string name="webview_dialog_issue_title">Problema con el visor web</string> | ||||
| </resources> | ||||
|   | ||||
| @@ -168,6 +168,6 @@ | ||||
|     <string name="shortcut_offline">Sen conexión</string> | ||||
|     <string name="pref_api_timeout">Acabouse o tempo de espera da API</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_title">Webview issue</string> | ||||
|     <string name="webview_dialog_issue_message">Visor web non dispoñible. Desactivando o visor de artigos pra evitar futuros problemas. Cargaranse os artigos dende o navegador de agora en adiante.</string> | ||||
|     <string name="webview_dialog_issue_title">Problema co visor web</string> | ||||
| </resources> | ||||
|   | ||||
| @@ -170,4 +170,6 @@ | ||||
|     <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_title">Webview issue</string> | ||||
|     <string name="reader_text_align_left">Align left</string> | ||||
|     <string name="reader_text_align_justify">Justify</string> | ||||
| </resources> | ||||
|   | ||||
		Reference in New Issue
	
	Block a user