Compare commits
	
		
			5 Commits
		
	
	
		
			v171810290
			...
			v171810304
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | ab2d0c4036 | ||
|  | 99fc417109 | ||
|  | dc304ef8c1 | ||
|  | c5511880bc | ||
|  | 5fe76d735e | 
							
								
								
									
										21
									
								
								app/proguard-rules.pro
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										21
									
								
								app/proguard-rules.pro
									
									
									
									
										vendored
									
									
								
							| @@ -30,22 +30,6 @@ | ||||
|     <fields>; | ||||
| } | ||||
|  | ||||
|  | ||||
| ##Retrofit | ||||
| #-keep class com.google.gson.** { *; } | ||||
| #-keep class com.google.inject.** { *; } | ||||
| #-keep class org.apache.http.** { *; } | ||||
| #-keep class org.apache.james.mime4j.** { *; } | ||||
| #-keep class javax.inject.** { *; } | ||||
| #-keep class retrofit.** { *; } | ||||
| #-keepclassmembernames interface * { | ||||
| #    @retrofit.http.* <methods>; | ||||
| #} | ||||
| #-keep class retrofit.** { *; } | ||||
| #-keep class apps.amine.bou.readerforselfoss.api.selfoss.model.** { *; } | ||||
| #-keepclassmembernames interface * { | ||||
| #    @retrofit.http.* <methods>; | ||||
| #} | ||||
| -dontwarn okio.** | ||||
| -dontwarn retrofit2.Platform$Java8 | ||||
| -keep class retrofit.** { *; } | ||||
| @@ -75,4 +59,7 @@ | ||||
|  | ||||
| -dontwarn javax.annotation.** | ||||
|  | ||||
| -keep class android.support.v7.widget.SearchView { *; } | ||||
| -keep class android.support.v7.widget.SearchView { *; } | ||||
|  | ||||
| # maybe remove later ? | ||||
| -keep class * extends androidx.fragment.app.Fragment | ||||
|   | ||||
| @@ -1034,6 +1034,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                             this, | ||||
|                             items, | ||||
|                             api, | ||||
|                             db, | ||||
|                             customTabActivityHelper, | ||||
|                             internalBrowser, | ||||
|                             articleViewer, | ||||
| @@ -1050,6 +1051,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener { | ||||
|                             this, | ||||
|                             items, | ||||
|                             api, | ||||
|                             db, | ||||
|                             customTabActivityHelper, | ||||
|                             internalBrowser, | ||||
|                             articleViewer, | ||||
|   | ||||
| @@ -13,14 +13,18 @@ import android.view.Menu | ||||
| import android.view.MenuItem | ||||
| import android.view.ViewGroup | ||||
| import android.widget.Toast | ||||
| import androidx.room.Room | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.Item | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse | ||||
| import apps.amine.bou.readerforselfoss.fragments.ArticleFragment | ||||
| import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase | ||||
| import apps.amine.bou.readerforselfoss.persistence.migrations.MIGRATION_1_2 | ||||
| import apps.amine.bou.readerforselfoss.themes.AppColors | ||||
| import apps.amine.bou.readerforselfoss.themes.Toppings | ||||
| import apps.amine.bou.readerforselfoss.transformers.DepthPageTransformer | ||||
| import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException | ||||
| import apps.amine.bou.readerforselfoss.utils.persistence.toEntity | ||||
| import apps.amine.bou.readerforselfoss.utils.succeeded | ||||
| import apps.amine.bou.readerforselfoss.utils.toggleStar | ||||
| import com.ftinc.scoop.Scoop | ||||
| @@ -30,6 +34,7 @@ import org.acra.ACRA | ||||
| import retrofit2.Call | ||||
| import retrofit2.Callback | ||||
| import retrofit2.Response | ||||
| import kotlin.concurrent.thread | ||||
|  | ||||
| class ReaderActivity : AppCompatActivity() { | ||||
|  | ||||
| @@ -42,6 +47,8 @@ class ReaderActivity : AppCompatActivity() { | ||||
|  | ||||
|     private lateinit var toolbarMenu: Menu | ||||
|  | ||||
|     private lateinit var db: AppDatabase | ||||
|  | ||||
|     private fun showMenuItem(willAddToFavorite: Boolean) { | ||||
|         toolbarMenu.findItem(R.id.save).isVisible = willAddToFavorite | ||||
|         toolbarMenu.findItem(R.id.unsave).isVisible = !willAddToFavorite | ||||
| @@ -60,6 +67,11 @@ class ReaderActivity : AppCompatActivity() { | ||||
|  | ||||
|         setContentView(R.layout.activity_reader) | ||||
|  | ||||
|         db = Room.databaseBuilder( | ||||
|             applicationContext, | ||||
|             AppDatabase::class.java, "selfoss-database" | ||||
|         ).addMigrations(MIGRATION_1_2).build() | ||||
|  | ||||
|         val scoop = Scoop.getInstance() | ||||
|         scoop.bind(this, Toppings.PRIMARY.value, toolBar) | ||||
|         if  (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | ||||
| @@ -89,7 +101,7 @@ class ReaderActivity : AppCompatActivity() { | ||||
|  | ||||
|         currentItem = intent.getIntExtra("currentItem", 0) | ||||
|  | ||||
|         readItem(allItems[currentItem].id) | ||||
|         readItem(allItems[currentItem]) | ||||
|  | ||||
|         pager.adapter = ScreenSlidePagerAdapter(supportFragmentManager, AppColors(this@ReaderActivity)) | ||||
|         pager.currentItem = currentItem | ||||
| @@ -113,15 +125,18 @@ class ReaderActivity : AppCompatActivity() { | ||||
|                     } else { | ||||
|                         canFavorite() | ||||
|                     } | ||||
|                     readItem(allItems[pager.currentItem].id) | ||||
|                     readItem(allItems[pager.currentItem]) | ||||
|                 } | ||||
|             } | ||||
|         ) | ||||
|     } | ||||
|  | ||||
|     fun readItem(id: String) { | ||||
|     fun readItem(item: Item) { | ||||
|         if (markOnScroll) { | ||||
|             api.markItem(id).enqueue( | ||||
|             thread { | ||||
|                 db.itemsDao().delete(item.toEntity()) | ||||
|             } | ||||
|             api.markItem(item.id).enqueue( | ||||
|                 object : Callback<SuccessResponse> { | ||||
|                     override fun onResponse( | ||||
|                         call: Call<SuccessResponse>, | ||||
| @@ -145,6 +160,9 @@ class ReaderActivity : AppCompatActivity() { | ||||
|                         call: Call<SuccessResponse>, | ||||
|                         t: Throwable | ||||
|                     ) { | ||||
|                         thread { | ||||
|                             db.itemsDao().insertAllItems(item.toEntity()) | ||||
|                         } | ||||
|                         if (debugReadingItems) { | ||||
|                             ACRA.getErrorReporter().maybeHandleSilentException(t, this@ReaderActivity) | ||||
|                         } | ||||
|   | ||||
| @@ -14,7 +14,9 @@ import apps.amine.bou.readerforselfoss.R | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.Item | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse | ||||
| import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase | ||||
| import apps.amine.bou.readerforselfoss.themes.AppColors | ||||
| import apps.amine.bou.readerforselfoss.utils.LinkOnTouchListener | ||||
| import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent | ||||
| import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper | ||||
| import apps.amine.bou.readerforselfoss.utils.glide.bitmapCenterCrop | ||||
| @@ -38,6 +40,7 @@ class ItemCardAdapter( | ||||
|     override val app: Activity, | ||||
|     override var items: ArrayList<Item>, | ||||
|     override val api: SelfossApi, | ||||
|     override val db: AppDatabase, | ||||
|     private val helper: CustomTabActivityHelper, | ||||
|     private val internalBrowser: Boolean, | ||||
|     private val articleViewer: Boolean, | ||||
| @@ -63,6 +66,7 @@ class ItemCardAdapter( | ||||
|  | ||||
|         holder.mView.favButton.isLiked = itm.starred | ||||
|         holder.mView.title.text = Html.fromHtml(itm.title) | ||||
|         holder.mView.title.setOnTouchListener(LinkOnTouchListener()) | ||||
|  | ||||
|         holder.mView.title.setLinkTextColor(appColors.colorAccent) | ||||
|  | ||||
|   | ||||
| @@ -5,16 +5,22 @@ import android.content.Context | ||||
| import androidx.constraintlayout.widget.ConstraintLayout | ||||
| import androidx.recyclerview.widget.RecyclerView | ||||
| import android.text.Html | ||||
| import android.text.Spannable | ||||
| import android.text.style.ClickableSpan | ||||
| import android.util.TypedValue | ||||
| import android.view.LayoutInflater | ||||
| import android.view.MotionEvent | ||||
| import android.view.View | ||||
| import android.view.ViewGroup | ||||
| import android.widget.TextView | ||||
| import android.widget.Toast | ||||
| import apps.amine.bou.readerforselfoss.R | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.Item | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse | ||||
| import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase | ||||
| import apps.amine.bou.readerforselfoss.themes.AppColors | ||||
| import apps.amine.bou.readerforselfoss.utils.LinkOnTouchListener | ||||
| import apps.amine.bou.readerforselfoss.utils.buildCustomTabsIntent | ||||
| import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper | ||||
| import apps.amine.bou.readerforselfoss.utils.glide.bitmapCenterCrop | ||||
| @@ -39,6 +45,7 @@ class ItemListAdapter( | ||||
|     override val app: Activity, | ||||
|     override var items: ArrayList<Item>, | ||||
|     override val api: SelfossApi, | ||||
|     override val db: AppDatabase, | ||||
|     private val helper: CustomTabActivityHelper, | ||||
|     private val internalBrowser: Boolean, | ||||
|     private val articleViewer: Boolean, | ||||
| @@ -65,6 +72,8 @@ class ItemListAdapter( | ||||
|  | ||||
|         holder.mView.title.text = Html.fromHtml(itm.title) | ||||
|  | ||||
|         holder.mView.title.setOnTouchListener(LinkOnTouchListener()) | ||||
|  | ||||
|         holder.mView.title.setLinkTextColor(appColors.colorAccent) | ||||
|  | ||||
|         holder.mView.sourceTitleAndDate.text = itm.sourceAndDateText() | ||||
|   | ||||
| @@ -10,17 +10,21 @@ import apps.amine.bou.readerforselfoss.R | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.Item | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SelfossApi | ||||
| import apps.amine.bou.readerforselfoss.api.selfoss.SuccessResponse | ||||
| import apps.amine.bou.readerforselfoss.persistence.database.AppDatabase | ||||
| import apps.amine.bou.readerforselfoss.themes.AppColors | ||||
| import apps.amine.bou.readerforselfoss.utils.maybeHandleSilentException | ||||
| import apps.amine.bou.readerforselfoss.utils.persistence.toEntity | ||||
| import apps.amine.bou.readerforselfoss.utils.succeeded | ||||
| import org.acra.ACRA | ||||
| import retrofit2.Call | ||||
| import retrofit2.Callback | ||||
| import retrofit2.Response | ||||
| import kotlin.concurrent.thread | ||||
|  | ||||
| abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapter<VH>() { | ||||
|     abstract var items: ArrayList<Item> | ||||
|     abstract val api: SelfossApi | ||||
|     abstract val db: AppDatabase | ||||
|     abstract val debugReadingItems: Boolean | ||||
|     abstract val userIdentifier: String | ||||
|     abstract val app: Activity | ||||
| @@ -42,6 +46,9 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte | ||||
|             ) | ||||
|             .setAction(R.string.undo_string) { | ||||
|                 items.add(position, i) | ||||
|                 thread { | ||||
|                     db.itemsDao().insertAllItems(i.toEntity()) | ||||
|                 } | ||||
|                 notifyItemInserted(position) | ||||
|                 updateItems(items) | ||||
|  | ||||
| @@ -54,6 +61,9 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte | ||||
|  | ||||
|                     override fun onFailure(call: Call<SuccessResponse>, t: Throwable) { | ||||
|                         items.remove(i) | ||||
|                         thread { | ||||
|                             db.itemsDao().delete(i.toEntity()) | ||||
|                         } | ||||
|                         notifyItemRemoved(position) | ||||
|                         updateItems(items) | ||||
|                         doUnmark(i, position) | ||||
| @@ -75,6 +85,12 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte | ||||
|         notifyItemRemoved(position) | ||||
|         updateItems(items) | ||||
|  | ||||
|         // TODO: Handle network status. | ||||
|         // IF offline, delete from cached articles, and add to some table that will replay the calls on network activation. | ||||
|  | ||||
|         thread { | ||||
|             db.itemsDao().delete(i.toEntity()) | ||||
|         } | ||||
|  | ||||
|         api.markItem(i.id).enqueue(object : Callback<SuccessResponse> { | ||||
|             override fun onResponse( | ||||
| @@ -93,6 +109,7 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte | ||||
|                     ACRA.getErrorReporter().maybeHandleSilentException(Exception(message), app) | ||||
|                     Toast.makeText(app.baseContext, message, Toast.LENGTH_LONG).show() | ||||
|                 } | ||||
|  | ||||
|                 doUnmark(i, position) | ||||
|             } | ||||
|  | ||||
| @@ -110,6 +127,9 @@ abstract class ItemsAdapter<VH : RecyclerView.ViewHolder?> : RecyclerView.Adapte | ||||
|                 notifyItemInserted(position) | ||||
|                 updateItems(items) | ||||
|  | ||||
|                 thread { | ||||
|                     db.itemsDao().insertAllItems(i.toEntity()) | ||||
|                 } | ||||
|             } | ||||
|         }) | ||||
|     } | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package apps.amine.bou.readerforselfoss.persistence.dao | ||||
|  | ||||
| import androidx.room.Dao | ||||
| import androidx.room.Delete | ||||
| import androidx.room.Insert | ||||
| import androidx.room.OnConflictStrategy | ||||
| import androidx.room.Query | ||||
| @@ -15,11 +16,14 @@ interface ItemsDao { | ||||
|     fun items(): List<ItemEntity> | ||||
|  | ||||
|     @Insert(onConflict = OnConflictStrategy.REPLACE) | ||||
|     fun insertAllItems(vararg tags: ItemEntity) | ||||
|     fun insertAllItems(vararg items: ItemEntity) | ||||
|  | ||||
|     @Query("DELETE FROM items") | ||||
|     fun deleteAllItems() | ||||
|  | ||||
|     @Delete | ||||
|     fun delete(item: ItemEntity) | ||||
|  | ||||
|     @Update | ||||
|     fun updateItem(item: ItemEntity) | ||||
| } | ||||
| @@ -6,8 +6,13 @@ import android.content.Context | ||||
| import android.content.Intent | ||||
| import android.graphics.BitmapFactory | ||||
| import android.net.Uri | ||||
| import android.text.Spannable | ||||
| import android.text.style.ClickableSpan | ||||
| import androidx.browser.customtabs.CustomTabsIntent | ||||
| import android.util.Patterns | ||||
| import android.view.MotionEvent | ||||
| import android.view.View | ||||
| import android.widget.TextView | ||||
| import android.widget.Toast | ||||
| import apps.amine.bou.readerforselfoss.R | ||||
| import apps.amine.bou.readerforselfoss.ReaderActivity | ||||
| @@ -146,3 +151,40 @@ fun Context.openInBrowserAsNewTask(i: Item) { | ||||
|     intent.data = Uri.parse(i.getLinkDecoded().toStringUriWithHttp()) | ||||
|     startActivity(intent) | ||||
| } | ||||
|  | ||||
| class LinkOnTouchListener: View.OnTouchListener { | ||||
|     override fun onTouch(v: View?, event: MotionEvent?): Boolean { | ||||
|         var ret = false | ||||
|         val widget: TextView = v as TextView | ||||
|         val text: CharSequence = widget.text | ||||
|         val stext = Spannable.Factory.getInstance().newSpannable(text) | ||||
|  | ||||
|         val action = event!!.action | ||||
|  | ||||
|         if (action == MotionEvent.ACTION_UP || | ||||
|             action == MotionEvent.ACTION_DOWN) { | ||||
|             var x: Float = event.x | ||||
|             var y: Float = event.y | ||||
|  | ||||
|             x -= widget.totalPaddingLeft | ||||
|             y -= widget.totalPaddingTop | ||||
|  | ||||
|             x += widget.scrollX | ||||
|             y += widget.scrollY | ||||
|  | ||||
|             val layout = widget.layout | ||||
|             val line = layout.getLineForVertical(y.toInt()) | ||||
|             val off = layout.getOffsetForHorizontal(line, x) | ||||
|  | ||||
|             val link = stext.getSpans(off, off, ClickableSpan::class.java) | ||||
|  | ||||
|             if (link.isNotEmpty()) { | ||||
|                 if (action == MotionEvent.ACTION_UP) { | ||||
|                     link[0].onClick(widget) | ||||
|                 } | ||||
|                 ret = true | ||||
|             } | ||||
|         } | ||||
|         return ret | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -15,7 +15,7 @@ buildscript { | ||||
|         } | ||||
|     } | ||||
|     dependencies { | ||||
|         classpath 'com.android.tools.build:gradle:3.2.0' | ||||
|         classpath 'com.android.tools.build:gradle:3.2.1' | ||||
|         classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1 +1,14 @@ | ||||
| include ':app' | ||||
| include ':app' | ||||
|  | ||||
| ext.isCiServer = !!System.getProperty("CI") | ||||
|  | ||||
| buildCache { | ||||
|     local { | ||||
|         enabled = !isCiServer | ||||
|     } | ||||
|     remote(HttpBuildCache) { | ||||
|         // DO NOT COMMIT !!!!! | ||||
|         url = 'http://amine-bou.fr:8885/cache/' | ||||
|         push = isCiServer | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user