summaryrefslogtreecommitdiffhomepage
path: root/android
diff options
context:
space:
mode:
authorDavid Göransson <david.goransson90@gmail.com>2023-09-11 16:57:08 +0200
committerDavid Göransson <david.goransson90@gmail.com>2023-09-12 11:22:16 +0200
commit966b3c51e259adaea3c28d995f56790df236f64e (patch)
tree7f6b62d922843dbc9a17e85a1dc08e5a3ebe19fe /android
parentd63db4ab40c71b07368f7778d8fb0f23392352e2 (diff)
downloadmullvadvpn-966b3c51e259adaea3c28d995f56790df236f64e.tar.xz
mullvadvpn-966b3c51e259adaea3c28d995f56790df236f64e.zip
Remove unused classes
Diffstat (limited to 'android')
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt64
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt10
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt7
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt26
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt23
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt3
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt39
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt7
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt9
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt125
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt19
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt52
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt5
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt10
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt32
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt34
-rw-r--r--android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt15
17 files changed, 0 insertions, 480 deletions
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt
deleted file mode 100644
index 613fe49e8f..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ListItemData.kt
+++ /dev/null
@@ -1,64 +0,0 @@
-package net.mullvad.mullvadvpn.applist
-
-import androidx.annotation.DrawableRes
-import androidx.annotation.IntDef
-import androidx.annotation.StringRes
-import net.mullvad.mullvadvpn.ui.widget.WidgetState
-
-data class ListItemData
-private constructor(
- val identifier: String,
- val text: String? = null,
- @StringRes val textRes: Int? = null,
- @DrawableRes val iconRes: Int?,
- val isSelected: Boolean,
- @ItemType val type: Int,
- val widget: WidgetState? = null,
- val action: ItemAction? = null
-) {
-
- @Retention @IntDef(DIVIDER, PLAIN, ACTION) annotation class ItemType
-
- class Builder(private val identifier: String) {
- var text: String? = null
-
- @StringRes var textRes: Int? = null
-
- @DrawableRes var iconRes: Int? = null
- var isSelected: Boolean = false
-
- @ItemType var type: Int = 0
- var widget: WidgetState? = null
- var action: ItemAction? = null
-
- fun build(): ListItemData {
- if ((this.text == null && this.textRes == null) && type > PROGRESS)
- throw IllegalArgumentException("ListItem should be configured with text")
-
- return ListItemData(
- this.identifier,
- this.text,
- this.textRes,
- this.iconRes,
- this.isSelected,
- this.type,
- this.widget,
- this.action
- )
- }
- }
-
- data class ItemAction(val identifier: String)
-
- companion object {
- const val DIVIDER = 0
- const val PROGRESS = 1
- const val PLAIN = 2
- const val ACTION = 3
- const val DOUBLE_ACTION = 4
- const val APPLICATION = 5
-
- fun build(identifier: String, setUp: Builder.() -> Unit): ListItemData =
- Builder(identifier).also(setUp).build()
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt
deleted file mode 100644
index 4469bd00ef..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/applist/ViewIntent.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package net.mullvad.mullvadvpn.applist
-
-sealed class ViewIntent {
- // In future we will have search intent
- data class ChangeApplicationGroup(val item: ListItemData) : ViewIntent()
-
- object ViewIsReady : ViewIntent()
-
- data class ShowSystemApps(internal val show: Boolean) : ViewIntent()
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt
deleted file mode 100644
index edbaaf39d1..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/GetItemResult.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.mullvad.mullvadvpn.relaylist
-
-sealed class GetItemResult {
- data class Item(val item: RelayItem) : GetItemResult()
-
- data class Count(val count: Int) : GetItemResult()
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt
index 4817b401bf..eee85252cd 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCity.kt
@@ -17,30 +17,4 @@ data class RelayCity(
override val hasChildren
get() = relays.isNotEmpty()
- fun getItem(position: Int): GetItemResult {
- if (position == 0) {
- return GetItemResult.Item(this)
- }
-
- if (!expanded) {
- return GetItemResult.Count(1)
- }
-
- val offset = position - 1
- val relayCount = relays.size
-
- return if (offset >= relayCount) {
- GetItemResult.Count(1 + relayCount)
- } else {
- GetItemResult.Item(relays[offset])
- }
- }
-
- fun getItemCount(): Int {
- return if (expanded) {
- 1 + relays.size
- } else {
- 1
- }
- }
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt
index e9487c7b4c..6c9367aacd 100644
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt
+++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayCountry.kt
@@ -17,27 +17,4 @@ data class RelayCountry(
override val hasChildren
get() = cities.isNotEmpty()
- fun getItem(position: Int): GetItemResult {
- if (position == 0) {
- return GetItemResult.Item(this)
- }
-
- var itemCount = 1
- var remaining = position - 1
-
- if (expanded) {
- for (city in cities) {
-
- when (val itemOrCount = city.getItem(remaining)) {
- is GetItemResult.Item -> return itemOrCount
- is GetItemResult.Count -> {
- remaining -= itemOrCount.count
- itemCount += itemOrCount.count
- }
- }
- }
- }
-
- return GetItemResult.Count(itemCount)
- }
}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt
deleted file mode 100644
index 09dfafebc8..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListAdapterPosition.kt
+++ /dev/null
@@ -1,3 +0,0 @@
-package net.mullvad.mullvadvpn.relaylist
-
-data class RelayListAdapterPosition(var position: Int)
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt
deleted file mode 100644
index 3305418a48..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/BlockingController.kt
+++ /dev/null
@@ -1,39 +0,0 @@
-package net.mullvad.mullvadvpn.ui
-
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.Job
-import kotlinx.coroutines.launch
-
-class BlockingController(val blockableView: BlockableView) {
- var job: Job? = null
- var innerJob: Job? = null
-
- fun action() {
- if (job?.isActive != true) {
- job =
- GlobalScope.launch(Dispatchers.Main) {
- blockableView.setEnabled(false)
- innerJob = blockableView.onClick()
- innerJob?.join()
- blockableView.setEnabled(true)
- }
- }
- }
-
- fun onPause() {
- innerJob?.cancel()
- job?.cancel()
- blockableView.setEnabled(true)
- }
-
- fun onDestroy() {
- onPause()
- }
-}
-
-interface BlockableView {
- fun setEnabled(enabled: Boolean)
-
- fun onClick(): Job
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt
deleted file mode 100644
index 07c5520d34..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/ListItemListener.kt
+++ /dev/null
@@ -1,7 +0,0 @@
-package net.mullvad.mullvadvpn.ui
-
-import net.mullvad.mullvadvpn.applist.ListItemData
-
-interface ListItemListener {
- fun onItemAction(item: ListItemData)
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt
deleted file mode 100644
index e92265b2df..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/ui/widget/WidgetState.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package net.mullvad.mullvadvpn.ui.widget
-
-import androidx.annotation.DrawableRes
-
-sealed class WidgetState {
- data class ImageState(@DrawableRes val imageRes: Int) : WidgetState()
-
- data class SwitchState(val isChecked: Boolean) : WidgetState()
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt
deleted file mode 100644
index 89b0057f63..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/AdapterWithHeader.kt
+++ /dev/null
@@ -1,125 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import android.view.LayoutInflater
-import android.view.View
-import android.view.ViewGroup
-import androidx.recyclerview.widget.RecyclerView
-import androidx.recyclerview.widget.RecyclerView.ViewHolder
-import kotlin.properties.Delegates.observable
-
-class AdapterWithHeader<H : ViewHolder>(
- val adapter: RecyclerView.Adapter<H>,
- val headerLayoutId: Int
-) : RecyclerView.Adapter<HeaderOrHolder<H>>() {
- private val observer =
- object : RecyclerView.AdapterDataObserver() {
- override fun onChanged() {
- notifyDataSetChanged()
- }
-
- override fun onItemRangeChanged(start: Int, count: Int) {
- notifyItemRangeChanged(start + 1, count)
- }
-
- override fun onItemRangeChanged(start: Int, count: Int, payload: Any?) {
- notifyItemRangeChanged(start + 1, count, payload)
- }
-
- override fun onItemRangeInserted(start: Int, count: Int) {
- notifyItemRangeInserted(start + 1, count)
- }
-
- override fun onItemRangeMoved(from: Int, to: Int, count: Int) {
- if (from == to) {
- notifyItemRangeChanged(from + 1, count)
- } else {
- val sourceStart = from + 1
- val sourceEnd = sourceStart + count
- val destinationStart = to + 1
- val destinationEnd = destinationStart + count
-
- val ascendingIndices =
- (sourceStart..sourceEnd).zip(destinationStart..destinationEnd)
-
- val indices =
- if (from < to) {
- ascendingIndices.asReversed()
- } else {
- ascendingIndices
- }
-
- for ((source, destination) in indices) {
- notifyItemMoved(source, destination)
- }
- }
- }
-
- override fun onItemRangeRemoved(start: Int, count: Int) {
- notifyItemRangeRemoved(start + 1, count)
- }
- }
-
- private var headerView: View? by
- observable<View?>(null) { _, _, newView ->
- newView?.let { view -> onHeaderAvailable?.invoke(view) }
- }
-
- var onHeaderAvailable by
- observable<((View) -> Unit)?>(null) { _, _, listener ->
- headerView?.let { header -> listener?.invoke(header) }
- }
-
- init {
- adapter.registerAdapterDataObserver(observer)
- }
-
- override fun getItemCount() = adapter.itemCount + 1
-
- override fun getItemId(position: Int): Long {
- if (position == 0) {
- return 0L
- } else {
- return adapter.getItemId(position - 1) + 1
- }
- }
-
- override fun getItemViewType(position: Int): Int {
- if (position == 0) {
- return 0
- } else {
- return adapter.getItemViewType(position - 1) + 1
- }
- }
-
- override fun onBindViewHolder(holder: HeaderOrHolder<H>, position: Int) {
- when (holder) {
- is HeaderOrHolder.Header -> {
- if (position != 0) {
- throw IllegalArgumentException("Adapter position is not for the header")
- }
- }
- is HeaderOrHolder.Holder -> {
- if (position > 0) {
- adapter.onBindViewHolder(holder.holder, position - 1)
- } else {
- throw IllegalArgumentException("Adapter position is for the header")
- }
- }
- }
- }
-
- override fun onCreateViewHolder(parentView: ViewGroup, viewType: Int): HeaderOrHolder<H> {
- if (viewType == 0) {
- val inflater = LayoutInflater.from(parentView.context)
- val view = inflater.inflate(headerLayoutId, parentView, false)
-
- headerView = view
-
- return HeaderOrHolder.Header(view)
- } else {
- val holder = adapter.onCreateViewHolder(parentView, viewType - 1)
-
- return HeaderOrHolder.Holder(holder)
- }
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt
deleted file mode 100644
index c8361a36c4..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ChangeMonitor.kt
+++ /dev/null
@@ -1,19 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import kotlin.properties.Delegates.observable
-
-class ChangeMonitor {
- var changed = false
- private set
-
- fun <T> monitor(initialValue: T) =
- observable(initialValue) { _, oldValue, newValue ->
- if (oldValue != newValue) {
- changed = true
- }
- }
-
- fun reset() {
- changed = false
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt
deleted file mode 100644
index 1117b0b749..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ExponentialBackoff.kt
+++ /dev/null
@@ -1,52 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-// Calculates a series of delays that increase exponentially.
-//
-// The delays follow the formula:
-//
-// (base ^ retryAttempt) * scale
-//
-// but it is never larger than the specified cap value.
-class ExponentialBackoff : Iterator<Long> {
- private var unscaledValue = 1L
- private var current = 1L
-
- var iteration = 1
- private set
-
- var base = 2L
- var scale = 1000L
- var cap = Long.MAX_VALUE
- var count: Int? = null
-
- override fun hasNext(): Boolean {
- val maxIterations = count
-
- if (maxIterations != null) {
- return iteration < maxIterations
- } else {
- return true
- }
- }
-
- override fun next(): Long {
- iteration += 1
-
- if (current >= cap) {
- return cap
- } else {
- val value = current
-
- unscaledValue *= base
- current = Math.min(cap, scale * unscaledValue)
-
- return value
- }
- }
-
- fun reset() {
- unscaledValue = 1L
- current = 1L
- iteration = 1
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt
deleted file mode 100644
index 0ab0485c79..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/GenericExtensions.kt
+++ /dev/null
@@ -1,5 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-inline fun <T1 : Any, T2 : Any, R : Any> safeLet(p1: T1?, p2: T2?, block: (T1, T2) -> R?): R? {
- return if (p1 != null && p2 != null) block(p1, p2) else null
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt
deleted file mode 100644
index a1b50c6efb..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/HeaderOrHolder.kt
+++ /dev/null
@@ -1,10 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import android.view.View
-import androidx.recyclerview.widget.RecyclerView.ViewHolder
-
-sealed class HeaderOrHolder<H : ViewHolder>(itemView: View) : ViewHolder(itemView) {
- class Header<H : ViewHolder>(headerView: View) : HeaderOrHolder<H>(headerView)
-
- class Holder<H : ViewHolder>(val holder: H) : HeaderOrHolder<H>(holder.itemView)
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt
deleted file mode 100644
index 45ee4a2a17..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/SmartDeferred.kt
+++ /dev/null
@@ -1,32 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import kotlinx.coroutines.Deferred
-import kotlinx.coroutines.Dispatchers
-import kotlinx.coroutines.GlobalScope
-import kotlinx.coroutines.launch
-import net.mullvad.mullvadvpn.lib.common.util.JobTracker
-
-class SmartDeferred<T>(private val deferred: Deferred<T>) {
- private val jobTracker = JobTracker()
-
- private var active = true
-
- fun awaitThen(action: T.() -> Unit): Long? {
- if (active) {
- return jobTracker.newJob(
- GlobalScope.launch(Dispatchers.Default) { deferred.await().action() }
- )
- } else {
- return null
- }
- }
-
- fun cancelJob(jobId: Long) {
- jobTracker.cancelJob(jobId)
- }
-
- fun cancel() {
- active = false
- jobTracker.cancelAllJobs()
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt
deleted file mode 100644
index 3ae5f499cd..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/TimeAgoFormatter.kt
+++ /dev/null
@@ -1,34 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import android.content.res.Resources
-import net.mullvad.mullvadvpn.R
-import org.joda.time.DateTime
-import org.joda.time.Duration
-import org.joda.time.PeriodType
-
-class TimeAgoFormatter(val resources: Resources) {
- private val periodType = PeriodType.standard().withMillisRemoved().withSecondsRemoved()
-
- fun format(instant: DateTime): String {
- val elapsedTime = Duration(instant, DateTime.now())
- val elapsedTimeInfo = elapsedTime.toPeriodTo(instant, periodType)
-
- if (elapsedTimeInfo.years > 0) {
- return getRemainingText(R.plurals.years_ago, elapsedTimeInfo.years)
- } else if (elapsedTimeInfo.months > 0) {
- return getRemainingText(R.plurals.months_ago, elapsedTimeInfo.months)
- } else if (elapsedTimeInfo.days > 0) {
- return getRemainingText(R.plurals.days_ago, elapsedTimeInfo.days)
- } else if (elapsedTimeInfo.hours > 0) {
- return getRemainingText(R.plurals.hours_ago, elapsedTimeInfo.hours)
- } else if (elapsedTimeInfo.minutes > 0) {
- return getRemainingText(R.plurals.minutes_ago, elapsedTimeInfo.minutes)
- } else {
- return resources.getString(R.string.less_than_a_minute_ago)
- }
- }
-
- private fun getRemainingText(pluralId: Int, quantity: Int): String {
- return resources.getQuantityString(pluralId, quantity, quantity)
- }
-}
diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt
deleted file mode 100644
index fb4a4c65b6..0000000000
--- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/util/ViewKtx.kt
+++ /dev/null
@@ -1,15 +0,0 @@
-package net.mullvad.mullvadvpn.util
-
-import android.util.Log
-import android.view.View
-import android.view.ViewGroup.MarginLayoutParams
-
-fun View.setMargins(l: Int? = null, t: Int? = null, r: Int? = null, b: Int? = null) {
- if (this.layoutParams is MarginLayoutParams) {
- val p = this.layoutParams as MarginLayoutParams
- p.setMargins(l ?: p.leftMargin, t ?: p.topMargin, r ?: p.rightMargin, b ?: p.bottomMargin)
- this.requestLayout()
- } else {
- Log.w("mullvad", "setMargins is not supported")
- }
-}