Show countries rather than IPs

This commit is contained in:
nielsandriesse 2020-06-02 15:18:09 +10:00
parent 51f0374109
commit 1217e5278f
3 changed files with 9 additions and 14 deletions

View File

@ -34,10 +34,7 @@ import org.thoughtcrime.securesms.database.model.ThreadRecord
import org.thoughtcrime.securesms.loki.dialogs.PNModeBottomSheet import org.thoughtcrime.securesms.loki.dialogs.PNModeBottomSheet
import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol import org.thoughtcrime.securesms.loki.protocol.ClosedGroupsProtocol
import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation import org.thoughtcrime.securesms.loki.protocol.LokiSessionResetImplementation
import org.thoughtcrime.securesms.loki.utilities.getColorWithID import org.thoughtcrime.securesms.loki.utilities.*
import org.thoughtcrime.securesms.loki.utilities.push
import org.thoughtcrime.securesms.loki.utilities.recipient
import org.thoughtcrime.securesms.loki.utilities.show
import org.thoughtcrime.securesms.loki.views.ConversationView import org.thoughtcrime.securesms.loki.views.ConversationView
import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegate import org.thoughtcrime.securesms.loki.views.NewConversationButtonSetViewDelegate
import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate import org.thoughtcrime.securesms.loki.views.SeedReminderViewDelegate
@ -70,6 +67,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) { override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
super.onCreate(savedInstanceState, isReady) super.onCreate(savedInstanceState, isReady)
IP2Country.configureIfNeeded(this)
// Process any outstanding deletes // Process any outstanding deletes
val threadDatabase = DatabaseFactory.getThreadDatabase(this) val threadDatabase = DatabaseFactory.getThreadDatabase(this)
val archivedConversationCount = threadDatabase.archivedConversationListCount val archivedConversationCount = threadDatabase.archivedConversationListCount

View File

@ -22,12 +22,9 @@ import kotlinx.android.synthetic.main.activity_path.*
import network.loki.messenger.R import network.loki.messenger.R
import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity import org.thoughtcrime.securesms.PassphraseRequiredActionBarActivity
import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.DatabaseFactory
import org.thoughtcrime.securesms.loki.utilities.animateSizeChange import org.thoughtcrime.securesms.loki.utilities.*
import org.thoughtcrime.securesms.loki.utilities.fadeIn
import org.thoughtcrime.securesms.loki.utilities.fadeOut
import org.thoughtcrime.securesms.loki.utilities.getColorWithID
import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI
import org.whispersystems.signalservice.loki.api.Snode import org.whispersystems.signalservice.loki.api.Snode
import org.whispersystems.signalservice.loki.api.onionrequests.OnionRequestAPI
class PathActivity : PassphraseRequiredActionBarActivity() { class PathActivity : PassphraseRequiredActionBarActivity() {
private val broadcastReceivers = mutableListOf<BroadcastReceiver>() private val broadcastReceivers = mutableListOf<BroadcastReceiver>()
@ -142,7 +139,7 @@ class PathActivity : PassphraseRequiredActionBarActivity() {
private fun getPathRow(snode: Snode, location: LineView.Location, dotAnimationStartDelay: Long, dotAnimationRepeatInterval: Long, isGuardSnode: Boolean): LinearLayout { private fun getPathRow(snode: Snode, location: LineView.Location, dotAnimationStartDelay: Long, dotAnimationRepeatInterval: Long, isGuardSnode: Boolean): LinearLayout {
val title = if (isGuardSnode) resources.getString(R.string.activity_path_guard_node_row_title) else resources.getString(R.string.activity_path_service_node_row_title) val title = if (isGuardSnode) resources.getString(R.string.activity_path_guard_node_row_title) else resources.getString(R.string.activity_path_service_node_row_title)
val subtitle = snode.toString().removePrefix("https://").substringBefore(":") val subtitle = IP2Country.shared.getCountry(snode.ip)
return getPathRow(title, subtitle, location, dotAnimationStartDelay, dotAnimationRepeatInterval) return getPathRow(title, subtitle, location, dotAnimationStartDelay, dotAnimationRepeatInterval)
} }
// endregion // endregion

View File

@ -67,13 +67,13 @@ class IP2Country private constructor(private val context: Context) {
return file return file
} }
private fun getCountry(ip: String): String { fun getCountry(ip: String): String {
var truncatedIP = ip var truncatedIP = ip
fun getCountryInternal(): String { fun getCountryInternal(): String {
val country = countryNamesCache[ip] val country = countryNamesCache[ip]
if (country != null) { return country } if (country != null) { return country }
val ipv4TableReader = CSVReader(FileReader(ipv4Table.absoluteFile)) val ipv4TableReader = CSVReader(FileReader(ipv4Table.absoluteFile))
val countryNamesTableReader = CSVReader(FileReader(ipv4Table.absoluteFile)) val countryNamesTableReader = CSVReader(FileReader(countryNamesTable.absoluteFile))
var ipv4TableLine = ipv4TableReader.readNext() var ipv4TableLine = ipv4TableReader.readNext()
while (ipv4TableLine != null) { while (ipv4TableLine != null) {
if (!ipv4TableLine[0].startsWith(truncatedIP)) { if (!ipv4TableLine[0].startsWith(truncatedIP)) {
@ -93,8 +93,8 @@ class IP2Country private constructor(private val context: Context) {
} }
} }
if (truncatedIP.contains(".") && !truncatedIP.endsWith(".")) { // The fuzziest we want to go is xxx.x if (truncatedIP.contains(".") && !truncatedIP.endsWith(".")) { // The fuzziest we want to go is xxx.x
truncatedIP.dropLast(1) truncatedIP = truncatedIP.dropLast(1)
if (truncatedIP.endsWith(".")) { truncatedIP.dropLast(1) } if (truncatedIP.endsWith(".")) { truncatedIP = truncatedIP.dropLast(1) }
return getCountryInternal() return getCountryInternal()
} else { } else {
return "Unknown Country" return "Unknown Country"