Skip to content

Commit

Permalink
Merge pull request #809 from hussainmohd-a/v054
Browse files Browse the repository at this point in the history
v054a
  • Loading branch information
hussainmohd-a authored Mar 8, 2023
2 parents d3ce845 + f96cc2e commit 139272a
Show file tree
Hide file tree
Showing 24 changed files with 192 additions and 138 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ android {
applicationId "com.celzero.bravedns"
minSdkVersion 23
targetSdkVersion 33
versionCode 26 // for version name 054
versionName "054"
versionCode 27 // for version name 054a
versionName "054a"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

Expand Down Expand Up @@ -174,7 +174,7 @@ dependencies {
fullImplementation 'com.github.kirich1409:viewbindingpropertydelegate-noreflection:1.5.6'

// Tun2socks (https://jitpack.io/#celzero/firestack)
implementation 'com.github.celzero:firestack:bd82a8dd65'
implementation 'com.github.celzero:firestack:89daaaffcc'
// implementation project(":tun2socks")

// Work manager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,17 @@ class CustomDomainAdapter(val context: Context) :
)
dialog.setContentView(dBind.root)

var selectedType: DomainRulesManager.DomainType = DomainRulesManager.DomainType.DOMAIN
var selectedType: DomainRulesManager.DomainType =
DomainRulesManager.DomainType.getType(customDomain.type)

when (selectedType) {
DomainRulesManager.DomainType.DOMAIN -> {
dBind.dacdDomainChip.isChecked = true
}
DomainRulesManager.DomainType.WILDCARD -> {
dBind.dacdWildcardChip.isChecked = true
}
}

dBind.dacdDomainEditText.setText(customDomain.domain)

Expand Down Expand Up @@ -382,8 +392,8 @@ class CustomDomainAdapter(val context: Context) :
lp.width = WindowManager.LayoutParams.MATCH_PARENT
lp.height = WindowManager.LayoutParams.WRAP_CONTENT
dialog.show()
dialog.setCancelable(false)
dialog.setCanceledOnTouchOutside(false)
dialog.setCancelable(true)
dialog.setCanceledOnTouchOutside(true)
dialog.window?.attributes = lp

dBind.dacdUrlTitle.text = context.getString(R.string.cd_dialog_title)
Expand All @@ -406,7 +416,10 @@ class CustomDomainAdapter(val context: Context) :
handleDomain(dBind, selectedType, customDomain, DomainRulesManager.Status.TRUST)
}

dBind.dacdCancelBtn.setOnClickListener { dialog.dismiss() }
dBind.dacdCancelBtn.setOnClickListener {
val status = DomainRulesManager.Status.getStatus(customDomain.status)
handleDomain(dBind, selectedType, customDomain, status)
}
dialog.show()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ class RetrofitManager {
DEFAULT,
CLOUDFLARE,
GOOGLE,
SYSTEM_DNS
SYSTEM_DNS,
FALLBACK_DNS
}

fun getBlocklistBaseBuilder(dnsType: OkHttpDnsType): Retrofit.Builder {
Expand All @@ -41,15 +42,14 @@ class RetrofitManager {
}

fun okHttpClient(dnsType: OkHttpDnsType): OkHttpClient {
val okhttpClientBuilder = OkHttpClient.Builder()
okhttpClientBuilder.callTimeout(5, TimeUnit.MINUTES)
okhttpClientBuilder.connectTimeout(5, TimeUnit.MINUTES)
okhttpClientBuilder.readTimeout(20, TimeUnit.MINUTES)
okhttpClientBuilder.writeTimeout(20, TimeUnit.MINUTES)
okhttpClientBuilder.retryOnConnectionFailure(true)
val b = OkHttpClient.Builder()
b.connectTimeout(1, TimeUnit.MINUTES)
b.readTimeout(20, TimeUnit.MINUTES)
b.writeTimeout(5, TimeUnit.MINUTES)
b.retryOnConnectionFailure(true)
// If unset, the system-wide default DNS will be used.
customDns(dnsType)?.let { okhttpClientBuilder.dns(it) }
return okhttpClientBuilder.build()
customDns(dnsType)?.let { b.dns(it) }
return b.build()
}

// As of now, quad9 is used as default dns in okhttp client.
Expand Down Expand Up @@ -92,6 +92,10 @@ class RetrofitManager {
.build()
}
OkHttpDnsType.SYSTEM_DNS -> {
return Dns.SYSTEM
}
OkHttpDnsType.FALLBACK_DNS -> {
// todo: return retrieved system dns
return null
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,8 @@ class BlocklistDownloadHelper {
0 -> RetrofitManager.Companion.OkHttpDnsType.SYSTEM_DNS
1 -> RetrofitManager.Companion.OkHttpDnsType.CLOUDFLARE
2 -> RetrofitManager.Companion.OkHttpDnsType.GOOGLE
else -> RetrofitManager.Companion.OkHttpDnsType.SYSTEM_DNS
3 -> RetrofitManager.Companion.OkHttpDnsType.SYSTEM_DNS
else -> RetrofitManager.Companion.OkHttpDnsType.FALLBACK_DNS
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ class HomeScreenFragment : Fragment(R.layout.fragment_home_screen) {

appConfig.getBraveModeObservable().postValue(appConfig.getBraveMode().mode)
b.fhsCardRulesTv.text = getString(R.string.lbl_rules).replaceFirstChar(Char::titlecase)
b.fhsCardLogsTv.text = getString(R.string.lbl_logs).replaceFirstChar(Char::titlecase)
}

private fun handleQuickSettingsChips() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ class MiscSettingsActivity : AppCompatActivity(R.layout.activity_misc_settings)

private fun showDefaultDnsDialog() {
val alertBuilder = AlertDialog.Builder(this)
alertBuilder.setTitle(getString(R.string.settings_default_dns_dialog_title))
alertBuilder.setTitle(getString(R.string.settings_default_dns_heading))
val items = Constants.DEFAULT_DNS_LIST.map { it.name }.toTypedArray()
// get the index of the default dns url
// if the default dns url is not in the list, then select the first item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import androidx.paging.*
import com.celzero.bravedns.database.ConnectionTracker
import com.celzero.bravedns.database.ConnectionTrackerDAO
import com.celzero.bravedns.ui.ConnectionTrackerFragment
import com.celzero.bravedns.util.Constants
import com.celzero.bravedns.util.Constants.Companion.LIVEDATA_PAGE_SIZE

class ConnectionTrackerViewModel(private val connectionTrackerDAO: ConnectionTrackerDAO) :
ViewModel() {
Expand Down Expand Up @@ -73,25 +75,15 @@ class ConnectionTrackerViewModel(private val connectionTrackerDAO: ConnectionTra
private fun getBlockedNetworkLogs(input: String): LiveData<PagingData<ConnectionTracker>> {
return if (filterRules.isNotEmpty()) {
Pager(
PagingConfig(
pageSize = 15,
enablePlaceholders = false,
maxSize = 30,
prefetchDistance = 1
)
PagingConfig(LIVEDATA_PAGE_SIZE)
) {
connectionTrackerDAO.getBlockedConnectionsFiltered("%$input%", filterRules)
}
.liveData
.cachedIn(viewModelScope)
} else {
Pager(
PagingConfig(
pageSize = 15,
enablePlaceholders = false,
maxSize = 30,
prefetchDistance = 1
)
PagingConfig(LIVEDATA_PAGE_SIZE)
) {
connectionTrackerDAO.getBlockedConnections("%$input%")
}
Expand All @@ -103,25 +95,15 @@ class ConnectionTrackerViewModel(private val connectionTrackerDAO: ConnectionTra
private fun getAllowedNetworkLogs(input: String): LiveData<PagingData<ConnectionTracker>> {
return if (filterRules.isNotEmpty()) {
Pager(
PagingConfig(
pageSize = 15,
enablePlaceholders = false,
maxSize = 30,
prefetchDistance = 1
)
PagingConfig(LIVEDATA_PAGE_SIZE)
) {
connectionTrackerDAO.getAllowedConnectionsFiltered("%$input%", filterRules)
}
.liveData
.cachedIn(viewModelScope)
} else {
Pager(
PagingConfig(
pageSize = 15,
enablePlaceholders = false,
maxSize = 30,
prefetchDistance = 1
)
PagingConfig(LIVEDATA_PAGE_SIZE)
) {
connectionTrackerDAO.getAllowedConnections("%$input%")
}
Expand All @@ -131,14 +113,7 @@ class ConnectionTrackerViewModel(private val connectionTrackerDAO: ConnectionTra
}

private fun getAllNetworkLogs(input: String): LiveData<PagingData<ConnectionTracker>> {
return Pager(
PagingConfig(
pageSize = 15,
enablePlaceholders = false,
maxSize = 30,
prefetchDistance = 1
)
) {
return Pager(PagingConfig(LIVEDATA_PAGE_SIZE)) {
connectionTrackerDAO.getConnectionTrackerByName("%$input%")
}
.liveData
Expand Down
Loading

0 comments on commit 139272a

Please sign in to comment.