-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AdBlocker] 🔧 Implement checkbox click to enable/disable the feature
- Loading branch information
Showing
11 changed files
with
102 additions
and
10 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/mercandalli/android/browser/ad_blocker/AdBloackerModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.mercandalli.android.browser.ad_blocker | ||
|
||
import android.content.Context | ||
|
||
class AdBloackerModule { | ||
|
||
fun createAdBlockerManager(context: Context): AdBlockerManager { | ||
val sharedPreferences = context.getSharedPreferences( | ||
AdBlockerManagerImpl.PREFERENCE_NAME, | ||
Context.MODE_PRIVATE | ||
) | ||
return AdBlockerManagerImpl( | ||
sharedPreferences | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
app/src/main/java/com/mercandalli/android/browser/ad_blocker/AdBlockerManager.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.mercandalli.android.browser.ad_blocker | ||
|
||
interface AdBlockerManager { | ||
|
||
fun isEnabled(): Boolean | ||
|
||
fun setEnabled(enabled: Boolean) | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/com/mercandalli/android/browser/ad_blocker/AdBlockerManagerImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.mercandalli.android.browser.ad_blocker | ||
|
||
import android.content.SharedPreferences | ||
|
||
class AdBlockerManagerImpl( | ||
private val sharedPreferences: SharedPreferences | ||
) : AdBlockerManager { | ||
|
||
private var enabled = false | ||
private var enabledLoaded = false | ||
|
||
override fun isEnabled(): Boolean { | ||
load() | ||
return enabled | ||
} | ||
|
||
override fun setEnabled(enabled: Boolean) { | ||
this.enabled = enabled | ||
sharedPreferences.edit().putBoolean(KEY, enabled).apply() | ||
} | ||
|
||
private fun load() { | ||
if (enabledLoaded) { | ||
return | ||
} | ||
enabledLoaded = true | ||
enabled = sharedPreferences.getBoolean(KEY, enabled) | ||
} | ||
|
||
companion object { | ||
@JvmStatic | ||
val PREFERENCE_NAME = "AdBlockerManager" | ||
private const val KEY = "ad-blocker-enabled" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters