Compare commits
	
		
			2 Commits
		
	
	
		
			v171810289
			...
			v171810290
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 5fe76d735e | ||
|  | 3064b3b835 | 
| @@ -2,6 +2,8 @@ | ||||
|  | ||||
| - Closing #1. Initial article caching. | ||||
|  | ||||
| - Closing #228 by removing the list action bar. Action buttons are exclusively on the card view from now on. | ||||
|  | ||||
| **1.6.x** | ||||
|  | ||||
| - Handling hidden tags. | ||||
|   | ||||
| @@ -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,6 +14,7 @@ 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.buildCustomTabsIntent | ||||
| import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper | ||||
| @@ -38,6 +39,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, | ||||
|   | ||||
| @@ -14,6 +14,7 @@ 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.buildCustomTabsIntent | ||||
| import apps.amine.bou.readerforselfoss.utils.customtabs.CustomTabActivityHelper | ||||
| @@ -39,6 +40,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, | ||||
| @@ -49,7 +51,6 @@ class ItemListAdapter( | ||||
| ) : ItemsAdapter<ItemListAdapter.ViewHolder>() { | ||||
|     private val generator: ColorGenerator = ColorGenerator.MATERIAL | ||||
|     private val c: Context = app.baseContext | ||||
|     private val bars: ArrayList<Boolean> = ArrayList(Collections.nCopies(items.size + 1, false)) | ||||
|  | ||||
|     override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder { | ||||
|         val v = LayoutInflater.from(c).inflate( | ||||
| @@ -105,19 +106,6 @@ class ItemListAdapter( | ||||
|         } else { | ||||
|             c.bitmapCenterCrop(itm.getThumbnail(c), holder.mView.itemImage) | ||||
|         } | ||||
|  | ||||
|         // TODO: maybe handle this differently. It crashes when changing tab | ||||
|         try { | ||||
|             if (bars[position]) { | ||||
|                 holder.mView.actionBar.visibility = View.VISIBLE | ||||
|             } else { | ||||
|                 holder.mView.actionBar.visibility = View.GONE | ||||
|             } | ||||
|         } catch (e: IndexOutOfBoundsException) { | ||||
|             holder.mView.actionBar.visibility = View.GONE | ||||
|         } | ||||
|  | ||||
|         holder.mView.favButton.isLiked = itm.starred | ||||
|     } | ||||
|  | ||||
|     override fun getItemCount(): Int = items.size | ||||
| @@ -125,76 +113,14 @@ class ItemListAdapter( | ||||
|     inner class ViewHolder(val mView: ConstraintLayout) : RecyclerView.ViewHolder(mView) { | ||||
|  | ||||
|         init { | ||||
|             handleClickListeners() | ||||
|             handleCustomTabActions() | ||||
|         } | ||||
|  | ||||
|         private fun handleClickListeners() { | ||||
|  | ||||
|             mView.favButton.setOnLikeListener(object : OnLikeListener { | ||||
|                 override fun liked(likeButton: LikeButton) { | ||||
|                     val (id) = items[adapterPosition] | ||||
|                     api.starrItem(id).enqueue(object : Callback<SuccessResponse> { | ||||
|                         override fun onResponse( | ||||
|                             call: Call<SuccessResponse>, | ||||
|                             response: Response<SuccessResponse> | ||||
|                         ) { | ||||
|                         } | ||||
|  | ||||
|                         override fun onFailure( | ||||
|                             call: Call<SuccessResponse>, | ||||
|                             t: Throwable | ||||
|                         ) { | ||||
|                             mView.favButton.isLiked = false | ||||
|                             Toast.makeText( | ||||
|                                 c, | ||||
|                                 R.string.cant_mark_favortie, | ||||
|                                 Toast.LENGTH_SHORT | ||||
|                             ).show() | ||||
|                         } | ||||
|                     }) | ||||
|                 } | ||||
|  | ||||
|                 override fun unLiked(likeButton: LikeButton) { | ||||
|                     val (id) = items[adapterPosition] | ||||
|                     api.unstarrItem(id).enqueue(object : Callback<SuccessResponse> { | ||||
|                         override fun onResponse( | ||||
|                             call: Call<SuccessResponse>, | ||||
|                             response: Response<SuccessResponse> | ||||
|                         ) { | ||||
|                         } | ||||
|  | ||||
|                         override fun onFailure( | ||||
|                             call: Call<SuccessResponse>, | ||||
|                             t: Throwable | ||||
|                         ) { | ||||
|                             mView.favButton.isLiked = true | ||||
|                             Toast.makeText( | ||||
|                                 c, | ||||
|                                 R.string.cant_unmark_favortie, | ||||
|                                 Toast.LENGTH_SHORT | ||||
|                             ).show() | ||||
|                         } | ||||
|                     }) | ||||
|                 } | ||||
|             }) | ||||
|  | ||||
|             mView.shareBtn.setOnClickListener { | ||||
|                 c.shareLink(items[adapterPosition].getLinkDecoded()) | ||||
|             } | ||||
|  | ||||
|             mView.browserBtn.setOnClickListener { | ||||
|                 c.openInBrowserAsNewTask(items[adapterPosition]) | ||||
|  | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private fun handleCustomTabActions() { | ||||
|             val customTabsIntent = c.buildCustomTabsIntent() | ||||
|             helper.bindCustomTabsService(app) | ||||
|  | ||||
|             mView.setOnClickListener { actionBarShowHide() } | ||||
|             mView.setOnLongClickListener { | ||||
|             mView.setOnClickListener { | ||||
|                 c.openItemUrl( | ||||
|                     items, | ||||
|                     adapterPosition, | ||||
| @@ -204,16 +130,6 @@ class ItemListAdapter( | ||||
|                     articleViewer, | ||||
|                     app | ||||
|                 ) | ||||
|                 true | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         private fun actionBarShowHide() { | ||||
|             bars[adapterPosition] = true | ||||
|             if (mView.actionBar.visibility == View.GONE) { | ||||
|                 mView.actionBar.visibility = View.VISIBLE | ||||
|             } else { | ||||
|                 mView.actionBar.visibility = View.GONE | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -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) | ||||
| } | ||||
| @@ -11,7 +11,6 @@ | ||||
|         android:id="@+id/itemImage" | ||||
|         android:layout_width="88dp" | ||||
|         android:layout_height="88dp" | ||||
|         app:layout_constraintBottom_toBottomOf="@+id/actionBar" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         app:layout_constraintTop_toTopOf="parent" /> | ||||
|  | ||||
| @@ -40,79 +39,16 @@ | ||||
|         android:id="@+id/sourceTitleAndDate" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:layout_marginBottom="8dp" | ||||
|         android:layout_marginEnd="16dp" | ||||
|         android:layout_marginStart="16dp" | ||||
|         android:layout_marginTop="8dp" | ||||
|         android:layout_marginEnd="16dp" | ||||
|         android:gravity="start" | ||||
|         android:textAlignment="viewStart" | ||||
|         android:textSize="14sp" | ||||
|         app:layout_constraintBottom_toBottomOf="@+id/actionBar" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintHorizontal_bias="0.0" | ||||
|         app:layout_constraintStart_toEndOf="@+id/itemImage" | ||||
|         app:layout_constraintTop_toBottomOf="@+id/title" | ||||
|         tools:text="Google Actualité Il y a 5h" /> | ||||
|  | ||||
|     <RelativeLayout | ||||
|         android:id="@+id/actionBar" | ||||
|         android:layout_width="0dp" | ||||
|         android:layout_height="wrap_content" | ||||
|         android:background="#BBBBBB" | ||||
|         android:visibility="gone" | ||||
|         app:layout_constraintBottom_toBottomOf="parent" | ||||
|         app:layout_constraintEnd_toEndOf="parent" | ||||
|         app:layout_constraintStart_toStartOf="parent" | ||||
|         tools:visibility="visible"> | ||||
|  | ||||
|         <com.like.LikeButton | ||||
|             android:id="@+id/favButton" | ||||
|             android:layout_width="35dp" | ||||
|             android:layout_height="35dp" | ||||
|             android:layout_alignParentEnd="true" | ||||
|             android:layout_alignParentRight="true" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:layout_marginEnd="8dp" | ||||
|             android:layout_marginRight="8dp" | ||||
|             android:elevation="5dp" | ||||
|             android:padding="4dp" | ||||
|             app:icon_size="22dp" | ||||
|             app:icon_type="heart" /> | ||||
|  | ||||
|         <ImageButton | ||||
|             android:id="@+id/shareBtn" | ||||
|             android:layout_width="35dp" | ||||
|             android:layout_height="35dp" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:layout_marginEnd="16dp" | ||||
|             android:layout_marginRight="16dp" | ||||
|             android:layout_toLeftOf="@+id/favButton" | ||||
|             android:layout_toStartOf="@+id/favButton" | ||||
|             android:adjustViewBounds="true" | ||||
|             android:background="@android:color/transparent" | ||||
|             android:backgroundTint="?android:attr/textColorPrimary" | ||||
|             android:elevation="5dp" | ||||
|             android:padding="4dp" | ||||
|             android:scaleType="centerCrop" | ||||
|             android:src="@drawable/ic_share_black_24dp" /> | ||||
|  | ||||
|         <ImageButton | ||||
|             android:id="@+id/browserBtn" | ||||
|             android:layout_width="35dp" | ||||
|             android:layout_height="35dp" | ||||
|             android:layout_centerVertical="true" | ||||
|             android:layout_marginEnd="16dp" | ||||
|             android:layout_marginRight="16dp" | ||||
|             android:layout_toLeftOf="@+id/shareBtn" | ||||
|             android:layout_toStartOf="@+id/shareBtn" | ||||
|             android:adjustViewBounds="true" | ||||
|             android:background="@android:color/transparent" | ||||
|             android:backgroundTint="?android:attr/textColorPrimary" | ||||
|             android:elevation="5dp" | ||||
|             android:padding="4dp" | ||||
|             android:scaleType="centerCrop" | ||||
|             android:src="@drawable/ic_open_in_browser_black_24dp" /> | ||||
|  | ||||
|     </RelativeLayout> | ||||
|  | ||||
| </androidx.constraintlayout.widget.ConstraintLayout> | ||||
		Reference in New Issue
	
	Block a user