Some cleaning and preparing for items storage in room.
This commit is contained in:
parent
0dc6981913
commit
5569a47674
@ -87,7 +87,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private var items: ArrayList<Item> = ArrayList()
|
||||
private var allItems: ArrayList<Item> = ArrayList()
|
||||
|
||||
private var clickBehavior = false
|
||||
private var debugReadingItems = false
|
||||
private var shouldLogEverything = false
|
||||
private var internalBrowser = false
|
||||
@ -194,11 +193,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
}
|
||||
alertDialog.show()
|
||||
}
|
||||
|
||||
if (sharedPref.getString("acra.user.email", "").isNotEmpty()) {
|
||||
sharedEditor.remove("acra.user.email")
|
||||
sharedEditor.commit()
|
||||
}
|
||||
}
|
||||
|
||||
private fun handleSwipeRefreshLayout() {
|
||||
@ -364,7 +358,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
private fun handleSharedPrefs() {
|
||||
debugReadingItems = sharedPref.getBoolean("read_debug", false)
|
||||
shouldLogEverything = sharedPref.getBoolean("should_log_everything", false)
|
||||
clickBehavior = sharedPref.getBoolean("tab_on_tap", false)
|
||||
internalBrowser = sharedPref.getBoolean("prefer_internal_browser", true)
|
||||
articleViewer = sharedPref.getBoolean("prefer_article_viewer", true)
|
||||
shouldBeCardView = sharedPref.getBoolean("card_view_active", false)
|
||||
@ -664,7 +657,7 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
if (maybeDrawerData.sources != null) {
|
||||
thread {
|
||||
val sourceEntities =
|
||||
maybeDrawerData.sources.map { it.toEntity(this@HomeActivity) }
|
||||
maybeDrawerData.sources.map { it.toEntity() }
|
||||
db.drawerDataDao().insertAllSources(*sourceEntities.toTypedArray())
|
||||
}
|
||||
}
|
||||
@ -1013,7 +1006,6 @@ class HomeActivity : AppCompatActivity(), SearchView.OnQueryTextListener {
|
||||
items,
|
||||
api,
|
||||
customTabActivityHelper,
|
||||
clickBehavior,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
debugReadingItems,
|
||||
|
@ -40,7 +40,6 @@ class ItemListAdapter(
|
||||
override var items: ArrayList<Item>,
|
||||
override val api: SelfossApi,
|
||||
private val helper: CustomTabActivityHelper,
|
||||
private val clickBehavior: Boolean,
|
||||
private val internalBrowser: Boolean,
|
||||
private val articleViewer: Boolean,
|
||||
override val debugReadingItems: Boolean,
|
||||
@ -194,37 +193,18 @@ class ItemListAdapter(
|
||||
val customTabsIntent = c.buildCustomTabsIntent()
|
||||
helper.bindCustomTabsService(app)
|
||||
|
||||
|
||||
if (!clickBehavior) {
|
||||
mView.setOnClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
}
|
||||
mView.setOnLongClickListener {
|
||||
actionBarShowHide()
|
||||
true
|
||||
}
|
||||
} else {
|
||||
mView.setOnClickListener { actionBarShowHide() }
|
||||
mView.setOnLongClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
true
|
||||
}
|
||||
mView.setOnClickListener { actionBarShowHide() }
|
||||
mView.setOnLongClickListener {
|
||||
c.openItemUrl(
|
||||
items,
|
||||
adapterPosition,
|
||||
items[adapterPosition].getLinkDecoded(),
|
||||
customTabsIntent,
|
||||
internalBrowser,
|
||||
articleViewer,
|
||||
app
|
||||
)
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -125,6 +125,9 @@ class SelfossApi(
|
||||
): Call<List<Item>> =
|
||||
getItems("starred", tag, sourceId, search, itemsNumber, offset)
|
||||
|
||||
fun allItems(): Call<List<Item>> =
|
||||
service.allItems(userName, password)
|
||||
|
||||
private fun getItems(
|
||||
type: String,
|
||||
tag: String?,
|
||||
|
@ -27,6 +27,12 @@ internal interface SelfossService {
|
||||
@Query("offset") offset: Int
|
||||
): Call<List<Item>>
|
||||
|
||||
@GET("items")
|
||||
fun allItems(
|
||||
@Query("username") username: String,
|
||||
@Query("password") password: String
|
||||
): Call<List<Item>>
|
||||
|
||||
@Headers("Content-Type: application/x-www-form-urlencoded")
|
||||
@POST("mark/{id}")
|
||||
fun markAsRead(
|
||||
|
@ -0,0 +1,25 @@
|
||||
package apps.amine.bou.readerforselfoss.persistence.dao
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.ItemEntity
|
||||
import androidx.room.Update
|
||||
|
||||
|
||||
|
||||
@Dao
|
||||
interface ItemsDao {
|
||||
@Query("SELECT * FROM items")
|
||||
fun items(): List<ItemEntity>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
fun insertAllItems(vararg tags: ItemEntity)
|
||||
|
||||
@Query("DELETE FROM items")
|
||||
fun deleteAllItems()
|
||||
|
||||
@Update
|
||||
fun updateItem(item: ItemEntity)
|
||||
}
|
@ -3,6 +3,8 @@ package apps.amine.bou.readerforselfoss.persistence.database
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.Database
|
||||
import apps.amine.bou.readerforselfoss.persistence.dao.DrawerDataDao
|
||||
import apps.amine.bou.readerforselfoss.persistence.dao.ItemsDao
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.ItemEntity
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.SourceEntity
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.TagEntity
|
||||
|
||||
|
@ -0,0 +1,32 @@
|
||||
package apps.amine.bou.readerforselfoss.persistence.entities
|
||||
|
||||
import androidx.room.ColumnInfo
|
||||
import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "items")
|
||||
data class ItemEntity(
|
||||
@PrimaryKey
|
||||
@ColumnInfo(name = "id")
|
||||
val id: String,
|
||||
@ColumnInfo(name = "datetime")
|
||||
val datetime: String,
|
||||
@ColumnInfo(name = "title")
|
||||
val title: String,
|
||||
@ColumnInfo(name = "content")
|
||||
val content: String,
|
||||
@ColumnInfo(name = "unread")
|
||||
val unread: Boolean,
|
||||
@ColumnInfo(name = "starred")
|
||||
var starred: Boolean,
|
||||
@ColumnInfo(name = "thumbnail")
|
||||
val thumbnail: String,
|
||||
@ColumnInfo(name = "icon")
|
||||
val icon: String,
|
||||
@ColumnInfo(name = "link")
|
||||
val link: String,
|
||||
@ColumnInfo(name = "sourcetitle")
|
||||
val sourcetitle: String,
|
||||
@ColumnInfo(name = "tags")
|
||||
val tags: String
|
||||
)
|
@ -152,17 +152,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
addPreferencesFromResource(R.xml.pref_general);
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
SwitchPreference cardViewActive = (SwitchPreference) findPreference("card_view_active");
|
||||
final SwitchPreference tabOnTap = (SwitchPreference) findPreference("tab_on_tap");
|
||||
tabOnTap.setEnabled(!cardViewActive.isChecked());
|
||||
cardViewActive.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
boolean isEnabled = (Boolean) newValue;
|
||||
tabOnTap.setEnabled(!isEnabled);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
EditTextPreference itemsNumber = (EditTextPreference) findPreference("prefer_api_items_number");
|
||||
itemsNumber.getEditText().setFilters(new InputFilter[]{
|
||||
new InputFilter() {
|
||||
|
@ -1,8 +1,9 @@
|
||||
package apps.amine.bou.readerforselfoss.utils.persistence
|
||||
|
||||
import android.content.Context
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Item
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Source
|
||||
import apps.amine.bou.readerforselfoss.api.selfoss.Tag
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.ItemEntity
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.SourceEntity
|
||||
import apps.amine.bou.readerforselfoss.persistence.entities.TagEntity
|
||||
|
||||
@ -23,14 +24,14 @@ fun SourceEntity.toView(): Source =
|
||||
this.icon
|
||||
)
|
||||
|
||||
fun Source.toEntity(context: Context): SourceEntity =
|
||||
fun Source.toEntity(): SourceEntity =
|
||||
SourceEntity(
|
||||
this.id,
|
||||
this.title,
|
||||
this.tags,
|
||||
this.spout,
|
||||
this.error,
|
||||
this.getIcon(context)
|
||||
this.icon.orEmpty()
|
||||
)
|
||||
|
||||
fun Tag.toEntity(): TagEntity =
|
||||
@ -39,3 +40,33 @@ fun Tag.toEntity(): TagEntity =
|
||||
this.color,
|
||||
this.unread
|
||||
)
|
||||
|
||||
fun ItemEntity.toView(): Item =
|
||||
Item(
|
||||
this.id,
|
||||
this.datetime,
|
||||
this.title,
|
||||
this.content,
|
||||
this.unread,
|
||||
this.starred,
|
||||
this.thumbnail,
|
||||
this.icon,
|
||||
this.link,
|
||||
this.sourcetitle,
|
||||
this.tags
|
||||
)
|
||||
|
||||
fun Item.toEntity(): ItemEntity =
|
||||
ItemEntity(
|
||||
this.id,
|
||||
this.datetime,
|
||||
this.title,
|
||||
this.content,
|
||||
this.unread,
|
||||
this.starred,
|
||||
this.thumbnail,
|
||||
this.icon,
|
||||
this.link,
|
||||
this.sourcetitle,
|
||||
this.tags
|
||||
)
|
@ -78,11 +78,5 @@
|
||||
android:title="@string/pref_general_category_actions">
|
||||
|
||||
</PreferenceCategory>
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="tab_on_tap"
|
||||
android:summaryOff="@string/pref_switch_actions_tap_off"
|
||||
android:summaryOn="@string/pref_switch_actions_tap_on"
|
||||
android:title="@string/pref_switch_actions_tap_title" />
|
||||
|
||||
</PreferenceScreen>
|
||||
|
Loading…
Reference in New Issue
Block a user