Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for custom lists #5737

Merged
merged 11 commits into from
Feb 8, 2024

Conversation

Pururun
Copy link
Contributor

@Pururun Pururun commented Jan 30, 2024

Add support for custom lists and connected actions to the android app.

THIS DOES NOT INCLUDE ANY UI CHANGES. This will come in the next PR.


This change is Reviewable

@Pururun Pururun added the Android Issues related to Android label Jan 30, 2024
@Pururun Pururun requested review from Rawa and dlon January 30, 2024 10:59
Copy link

linear bot commented Jan 30, 2024

@Pururun Pururun force-pushed the add-support-for-custom-list-in-the-app-layer-droid-653 branch from c6244bd to 17c5b14 Compare January 30, 2024 11:36
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 5 of 32 files at r1.
Reviewable status: 5 of 32 files reviewed, all discussions resolved

Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 4 files at r2.
Reviewable status: 5 of 34 files reviewed, all discussions resolved

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 27 of 32 files at r1, 2 of 4 files at r2, all commit messages.
Reviewable status: all files reviewed, 8 unresolved discussions (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt line 6 at r2 (raw file):

fun CustomList.toRelayItemList(relayCountries: List<RelayCountry>): CustomRelayItemList =
    // return this.items.map { RelayItem(it) }

Old comment?


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt line 73 at r2 (raw file):

fun List<RelayCountry>.findItemForGeographicLocationConstraint(
    location: GeographicLocationConstraint

constraint sounds like a better variable name than location, it feels more accurate to the type. What do you think?


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt line 233 at r2 (raw file):

                }
            }
            else -> this

Can we be explicit and enter the other alternatives?


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/SelectedLocation.kt line 8 at r2 (raw file):

    val id: String,
    val name: String,
    val geographicLocationConstraint: GeographicLocationConstraint?

I'm a bit confused by the naming here. SelectedLocation, why does it need a location constraint? Is it the constraint that was used to select this location?


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/CustomListsUseCase.kt line 6 at r2 (raw file):

import net.mullvad.mullvadvpn.repository.CustomListsRepository

class CustomListsUseCase(private val customListsRepository: CustomListsRepository) {

I'm not sure if this UseCase add any value, seems like it just wraps the repository, if this is the case and no other logic is needed we might as well just use the Repository right away.


android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Event.kt line 68 at r2 (raw file):

    @Parcelize object VpnPermissionRequest : Event()

    @Parcelize data class CreateCustomListResultEvent(val result: String) : Event()

CreateCustomListResultwork be enough, also what does result contain? Can we make it more clear? How do we interpret it?


android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/CustomListsSettings.kt line 6 at r2 (raw file):

import kotlinx.parcelize.Parcelize

@Parcelize data class CustomListsSettings(val customLists: ArrayList<CustomList>) : Parcelable

Is ArrayList because it is from the daemon? Would be nice if it was List otherwise.


android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Settings.kt line 10 at r2 (raw file):

    val relaySettings: RelaySettings,
    val obfuscationSettings: ObfuscationSettings,
    val customLists: CustomListsSettings,

I guess we don't have full control of this structure since it comes from the daemon? It would make more sense otherwise if it just was:

data class Settings( ... val customLists: List<CustomList> ... )

Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 6 unresolved discussions (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/CustomListExtensions.kt line 6 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

Old comment?

Probably. Fixed.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt line 73 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

constraint sounds like a better variable name than location, it feels more accurate to the type. What do you think?

Sure. Fixed.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt line 233 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

Can we be explicit and enter the other alternatives?

Added null instead.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/SelectedLocation.kt line 8 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

I'm a bit confused by the naming here. SelectedLocation, why does it need a location constraint? Is it the constraint that was used to select this location?

I think we should discuss this in person.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/usecase/CustomListsUseCase.kt line 6 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

I'm not sure if this UseCase add any value, seems like it just wraps the repository, if this is the case and no other logic is needed we might as well just use the Repository right away.

Yeah it was added when I thought it would be more complex. Will remove.


android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Event.kt line 68 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

CreateCustomListResultwork be enough, also what does result contain? Can we make it more clear? How do we interpret it?

Yeah agree it is quite redundant to add Event at the end. Will remove. Updated the val to call it listId as it is the value returned.


android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/CustomListsSettings.kt line 6 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

Is ArrayList because it is from the daemon? Would be nice if it was List otherwise.

Yeah daemon dependency. :/


android/lib/model/src/main/kotlin/net/mullvad/mullvadvpn/model/Settings.kt line 10 at r2 (raw file):

Previously, Rawa (David Göransson) wrote…

I guess we don't have full control of this structure since it comes from the daemon? It would make more sense otherwise if it just was:

data class Settings( ... val customLists: List<CustomList> ... )

Yeah would just add a lot of unnecessary code to do it like that.

Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 11 of 43 files reviewed, 6 unresolved discussions (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/SelectedLocation.kt line 8 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

I think we should discuss this in person.

Implemented what we discussed, making CustomList implement RelayItem. Please check. :)

@Rawa Rawa self-requested a review February 7, 2024 09:19
Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 32 of 32 files at r3, all commit messages.
Reviewable status: all files reviewed, 4 unresolved discussions (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt line 293 at r3 (raw file):

                    }
                }
                else -> {}

Preferably we should be explicit here:

RelayItem.CustomList, RelayItem.Relay -> {}


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 284 at r3 (raw file):

                is RelayItem.City -> relayListState.selectedItem.location.countryCode
                is RelayItem.Relay -> relayListState.selectedItem.location.countryCode
                else -> null

Same here, lets avoid else.

We could also make it an extension function or property:

fun RelayListState.RelayList.indexOfSelectedRelayItem(): Int {
    if(selectedItem == null) {
        return -1
    }
    countries.indexOfFirst { relayCountry ->
        relayCountry.location.location.country ==
            when (relayListState.selectedItem) {
                is RelayItem.CustomList -> null
                is RelayItem.Country -> relayListState.selectedItem.code
                is RelayItem.City -> relayListState.selectedItem.location.countryCode
                is RelayItem.Relay -> relayListState.selectedItem.location.countryCode
                null -> null
    }
}

android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItem.kt line 79 at r3 (raw file):

        }
    }
}

Looks really good! Nice work! 👏 I'm a little bit against having expanded here but since it does not introduce it as a new concept I think we can consider that in another PR.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayItemExtensions.kt line 12 at r3 (raw file):

        is RelayItem.CustomList -> LocationConstraint.CustomList(id)
    }
}

Nice 🤩


android/app/src/main/kotlin/net/mullvad/mullvadvpn/relaylist/RelayListExtensions.kt line 233 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Added null instead.

Nice 👍


android/lib/ipc/src/main/kotlin/net/mullvad/mullvadvpn/lib/ipc/Event.kt line 68 at r2 (raw file):

Previously, Pururun (Jonatan Rhodin) wrote…

Yeah agree it is quite redundant to add Event at the end. Will remove. Updated the val to call it listId as it is the value returned.

Great 👍 much more clear!

Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 2 unresolved discussions (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/cell/RelayLocationCell.kt line 293 at r3 (raw file):

Previously, Rawa (David Göransson) wrote…

Preferably we should be explicit here:

RelayItem.CustomList, RelayItem.Relay -> {}

Done.


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 284 at r3 (raw file):

Previously, Rawa (David Göransson) wrote…

Same here, lets avoid else.

We could also make it an extension function or property:

fun RelayListState.RelayList.indexOfSelectedRelayItem(): Int {
    if(selectedItem == null) {
        return -1
    }
    countries.indexOfFirst { relayCountry ->
        relayCountry.location.location.country ==
            when (relayListState.selectedItem) {
                is RelayItem.CustomList -> null
                is RelayItem.Country -> relayListState.selectedItem.code
                is RelayItem.City -> relayListState.selectedItem.location.countryCode
                is RelayItem.Relay -> relayListState.selectedItem.location.countryCode
                null -> null
    }
}

Done.

@Pururun Pururun force-pushed the add-support-for-custom-list-in-the-app-layer-droid-653 branch from f30f4c2 to 570cee8 Compare February 7, 2024 12:19
@Pururun Pururun requested a review from Rawa February 7, 2024 12:19
Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 4 files at r4, 1 of 1 files at r5, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 281 at r5 (raw file):

}

private fun RelayListState.RelayList.indexOfSelectedRelayItem(selectedItem: RelayItem?): Int =

Nitpicking, indexOfRelayItem(item: RelayItem?) selection really has nothing to do with it at this level. Soooorrrii 🗡️

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 281 at r5 (raw file):

Previously, Rawa (David Göransson) wrote…

Nitpicking, indexOfRelayItem(item: RelayItem?) selection really has nothing to do with it at this level. Soooorrrii 🗡️

or rather just indexOf() relayItem is sort of already described in argument

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @Pururun)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 281 at r5 (raw file):

Previously, Rawa (David Göransson) wrote…

or rather just indexOf() relayItem is sort of already described in argument

Clarification, we can remove selectedItem since it already exists in RelayList

@Pururun Pururun force-pushed the add-support-for-custom-list-in-the-app-layer-droid-653 branch 2 times, most recently from 3eb665f to 52cc2c0 Compare February 7, 2024 22:38
Copy link
Contributor Author

@Pururun Pururun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 42 of 43 files reviewed, 1 unresolved discussion (waiting on @Rawa)


android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreen.kt line 281 at r5 (raw file):

Previously, Rawa (David Göransson) wrote…

Clarification, we can remove selectedItem since it already exists in RelayList

Done.

@Pururun Pururun requested a review from Rawa February 7, 2024 22:38
Copy link
Member

@dlon dlon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 4 files at r4.
Reviewable status: 42 of 43 files reviewed, 1 unresolved discussion (waiting on @Rawa)

Copy link
Contributor

@Rawa Rawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: Great work! 👏

Reviewed 1 of 1 files at r6, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved

@Pururun Pururun force-pushed the add-support-for-custom-list-in-the-app-layer-droid-653 branch from 52cc2c0 to af3df96 Compare February 8, 2024 09:51
@Pururun Pururun merged commit ec4c473 into main Feb 8, 2024
37 checks passed
@Pururun Pururun deleted the add-support-for-custom-list-in-the-app-layer-droid-653 branch February 8, 2024 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Issues related to Android
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants