Skip to content

Commit

Permalink
Do not log history in incognito mode (even temporary #119)
Browse files Browse the repository at this point in the history
  • Loading branch information
truefedex committed Dec 12, 2022
1 parent 92e2b55 commit 5c529d3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ open class MainActivity : AppCompatActivity(), ActionBar.Callback {

vb.flWebViewContainer.setCallback(object : CursorLayout.Callback {
override fun onUserInteraction() {
val tab = tabsModel.currentTab.value
if (tab != null) {
if (!tab.webPageInteractionDetected) {
tab.webPageInteractionDetected = true
viewModel.logVisitedHistory(tab.title, tab.url, tab.faviconHash, config.incognitoMode)
val tab = tabsModel.currentTab.value ?: return
if (!tab.webPageInteractionDetected) {
tab.webPageInteractionDetected = true
if (!config.incognitoMode) {
viewModel.logVisitedHistory(tab.title, tab.url, tab.faviconHash)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class MainActivityViewModel: ActiveModel() {
}
}

fun logVisitedHistory(title: String?, url: String, faviconHash: String?, incognito: Boolean) {
fun logVisitedHistory(title: String?, url: String, faviconHash: String?) {
if ((url == lastHistoryItem?.url) || url == Config.DEFAULT_HOME_URL) {
return
}
Expand All @@ -87,7 +87,6 @@ class MainActivityViewModel: ActiveModel() {
item.title = title ?: ""
item.time = Date().time
item.favicon = faviconHash
item.incognito = incognito
lastHistoryItem = item
modelScope.launch(Dispatchers.Main) {
AppDatabase.db.historyDao().insert(item)
Expand Down Expand Up @@ -210,7 +209,6 @@ class MainActivityViewModel: ActiveModel() {

fun clearIncognitoData() = modelScope.launch(Dispatchers.IO) {
Log.d(TAG, "clearIncognitoData")
AppDatabase.db.historyDao().deleteIncognitoHistory()

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
val webViewData = File(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class HistoryItem {
var title: String = ""
var url: String = ""
var favicon: String? = null
@Deprecated("Not used anymore")
var incognito: Boolean? = null

@Ignore
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ interface HistoryDao {
@Query("DELETE FROM history WHERE time < :time")
suspend fun deleteWhereTimeLessThan(time: Long)

@Query("DELETE FROM history WHERE incognito")
suspend fun deleteIncognitoHistory()

@Query("SELECT COUNT(*) FROM history")
suspend fun count(): Int

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import com.phlox.tvwebbrowser.TVBro
import com.phlox.tvwebbrowser.model.*
import com.phlox.tvwebbrowser.model.dao.*

@Database(entities = [Download::class, FavoriteItem::class, HistoryItem::class, WebTabState::class], version = 15/*, exportSchema = true*/)
@Database(entities = [Download::class, FavoriteItem::class, HistoryItem::class, WebTabState::class], version = 16/*, exportSchema = true*/)
abstract class AppDatabase : RoomDatabase() {
abstract fun downloadDao(): DownloadDao
abstract fun historyDao(): HistoryDao
Expand Down Expand Up @@ -116,6 +116,12 @@ abstract class AppDatabase : RoomDatabase() {
}
}

private val MIGRATION_15_16 = object : Migration(15, 16) {
override fun migrate(db: SupportSQLiteDatabase) {
db.execSQL("DELETE FROM history WHERE incognito")
}
}

private fun createAdBlockListTable(db: SupportSQLiteDatabase) {
db.execSQL("CREATE TABLE IF NOT EXISTS 'adblocklist' ('id' INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, 'type' INTEGER NOT NULL, 'value' TEXT NOT NULL)")
db.execSQL("CREATE INDEX IF NOT EXISTS 'type_value_idx' ON 'adblocklist' ('type', 'value')")
Expand Down Expand Up @@ -154,7 +160,7 @@ abstract class AppDatabase : RoomDatabase() {
AppDatabase::class.java, "main.db"
).addMigrations(MIGRATION_1_2, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_8, MIGRATION_8_9,
MIGRATION_9_10, MIGRATION_10_11, MIGRATION_11_12, MIGRATION_12_13, MIGRATION_13_14,
MIGRATION_14_15).build()
MIGRATION_14_15, MIGRATION_15_16).build()
}
}
}

0 comments on commit 5c529d3

Please sign in to comment.