Skip to content

Commit

Permalink
ADS: Unprotected Sites migration (#2606)
Browse files Browse the repository at this point in the history
Task/Issue URL: https://app.asana.com/0/0/1203467500325941/f

### Description

- Migrate Unprotected Sites screen to new components 
- Created new CustomAlertDialog component

### Steps to test this PR

- Install from this branch
- Go to Settings > Unprotected Sites
- [ ] Check screen look as expected

### UI changes
| Before  | After |
| ------ | ----- |
![Screenshot_20221206_180155_DuckDuckGo](https://user-images.githubusercontent.com/20798495/205987523-0e85ae6f-3fb7-4e9a-a71c-23f396584966.jpg)|![Screenshot_20221206_141121_DuckDuckGo](https://user-images.githubusercontent.com/20798495/205987409-c1bfbb9e-2ef6-439a-95e2-87bd28ba24e8.jpg)|
  • Loading branch information
nalcalag authored and malmstein committed Jan 12, 2023
1 parent affb797 commit 466b046
Show file tree
Hide file tree
Showing 15 changed files with 338 additions and 130 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import com.duckduckgo.app.privacy.model.UserWhitelistedDomain
import com.duckduckgo.mobile.android.databinding.RowOneLineListItemBinding
import com.duckduckgo.mobile.android.databinding.ViewSectionHeaderBinding
import com.duckduckgo.mobile.android.ui.menu.PopupMenu
import com.duckduckgo.mobile.android.ui.view.divider.HorizontalDivider
import kotlinx.coroutines.launch
import timber.log.Timber

Expand All @@ -46,15 +45,13 @@ class WebsitesAdapter(
const val SITE_ENTRY = 0
const val DESCRIPTION_TYPE = 1
const val EMPTY_STATE_TYPE = 2
const val DIVIDER_TYPE = 3
const val SECTION_TITLE_TYPE = 4
const val SECTION_TITLE_TYPE = 3

const val EMPTY_HINT_ITEM_SIZE = 1
}

private val sortedHeaderElements = listOf(
DESCRIPTION_TYPE,
DIVIDER_TYPE,
SECTION_TITLE_TYPE,
)

Expand Down Expand Up @@ -106,9 +103,6 @@ class WebsitesAdapter(
binding.websiteDescription.setText(R.string.whitelistExplanation)
WebsiteViewHolder.SimpleViewHolder(binding.root)
}
DIVIDER_TYPE -> {
WebsiteViewHolder.SimpleViewHolder(HorizontalDivider(parent.context))
}
SECTION_TITLE_TYPE -> {
val binding = ViewSectionHeaderBinding.inflate(inflater, parent, false)
binding.sectionHeader.setText(R.string.settingsPrivacyProtectionWhitelist)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import com.duckduckgo.anvil.annotations.InjectWith
import com.duckduckgo.app.browser.R
import com.duckduckgo.app.browser.databinding.ActivityWhitelistBinding
import com.duckduckgo.app.browser.databinding.EditWhitelistBinding
import com.duckduckgo.app.browser.databinding.DialogEditWhitelistBinding
import com.duckduckgo.app.browser.favicon.FaviconManager
import com.duckduckgo.app.global.DuckDuckGoActivity
import com.duckduckgo.app.global.extensions.html
import com.duckduckgo.app.privacy.model.UserWhitelistedDomain
import com.duckduckgo.app.privacy.ui.WhitelistViewModel.Command.*
import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.mobile.android.ui.view.dialog.CustomAlertDialogBuilder
import com.duckduckgo.mobile.android.ui.view.dialog.TextAlertDialogBuilder
import com.duckduckgo.mobile.android.ui.view.dialog.TextAlertDialogBuilder.EventListener
import com.duckduckgo.mobile.android.ui.viewbinding.viewBinding
import javax.inject.Inject

Expand All @@ -43,10 +45,7 @@ class WhitelistActivity : DuckDuckGoActivity() {
lateinit var faviconManager: FaviconManager

private lateinit var adapter: WebsitesAdapter

private val binding: ActivityWhitelistBinding by viewBinding()

private var dialog: AlertDialog? = null
private val viewModel: WhitelistViewModel by bindViewModel()

private val toolbar
Expand Down Expand Up @@ -107,64 +106,62 @@ class WhitelistActivity : DuckDuckGoActivity() {
}

private fun showAddDialog() {
val dialogBinding = EditWhitelistBinding.inflate(layoutInflater)
val addDialog = AlertDialog.Builder(this).apply {
setTitle(R.string.dialogAddTitle)
setView(dialogBinding.root)
setPositiveButton(R.string.dialogSaveAction) { _, _ ->
val newText = dialogBinding.textInput.text.toString()
viewModel.onEntryAdded(UserWhitelistedDomain(newText))
}
setNegativeButton(android.R.string.no) { _, _ -> }
}.create()

dialog?.dismiss()
dialog = addDialog
addDialog.show()
val inputBinding = DialogEditWhitelistBinding.inflate(layoutInflater)
CustomAlertDialogBuilder(this)
.setTitle(R.string.dialogAddTitle)
.setPositiveButton(R.string.dialogSave)
.setNegativeButton(R.string.cancel)
.setView(inputBinding)
.addEventListener(
object : CustomAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked() {
val newText = inputBinding.customDialogTextInput.text
viewModel.onEntryAdded(UserWhitelistedDomain(newText))
}
},
)
.show()
}

private fun showEditDialog(entry: UserWhitelistedDomain) {
val dialogBinding = EditWhitelistBinding.inflate(layoutInflater)
val editDialog = AlertDialog.Builder(this).apply {
setTitle(R.string.dialogEditTitle)
setView(dialogBinding.root)
setPositiveButton(R.string.dialogSaveAction) { _, _ ->
val newText = dialogBinding.textInput.text.toString()
viewModel.onEntryEdited(entry, UserWhitelistedDomain(newText))
}
setNegativeButton(android.R.string.no) { _, _ -> }
}.create()

dialog?.dismiss()
dialog = editDialog
editDialog.show()

dialogBinding.textInput.setText(entry.domain)
dialogBinding.textInput.setSelection(entry.domain.length)
val inputBinding = DialogEditWhitelistBinding.inflate(layoutInflater)
inputBinding.customDialogTextInput.text = entry.domain
CustomAlertDialogBuilder(this)
.setTitle(R.string.dialogEditTitle)
.setPositiveButton(R.string.dialogSave)
.setNegativeButton(R.string.cancel)
.setView(inputBinding)
.addEventListener(
object : CustomAlertDialogBuilder.EventListener() {
override fun onPositiveButtonClicked() {
val newText = inputBinding.customDialogTextInput.text
viewModel.onEntryEdited(entry, UserWhitelistedDomain(newText))
}
},
)
.show()
}

private fun showDeleteDialog(entry: UserWhitelistedDomain) {
val deleteDialog = AlertDialog.Builder(this).apply {
setTitle(R.string.dialogConfirmTitle)
setMessage(getString(R.string.whitelistEntryDeleteConfirmMessage, entry.domain).html(this.context))
setPositiveButton(android.R.string.yes) { _, _ -> viewModel.onEntryDeleted(entry) }
setNegativeButton(android.R.string.no) { _, _ -> }
}.create()

dialog?.dismiss()
dialog = deleteDialog
deleteDialog.show()
TextAlertDialogBuilder(this)
.setTitle(R.string.dialogConfirmTitle)
.setMessage(getString(R.string.whitelistEntryDeleteConfirmMessage, entry.domain).html(this))
.setPositiveButton(android.R.string.yes)
.setNegativeButton(android.R.string.no)
.addEventListener(
object : EventListener() {
override fun onPositiveButtonClicked() {
viewModel.onEntryDeleted(entry)
}
},
)
.show()
}

private fun showWhitelistFormatError() {
Toast.makeText(this, R.string.whitelistFormatError, Toast.LENGTH_LONG).show()
}

override fun onDestroy() {
dialog?.dismiss()
super.onDestroy()
}

companion object {
fun intent(context: Context): Intent {
return Intent(context, WhitelistActivity::class.java)
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/res/layout/dialog_edit_whitelist.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2022 DuckDuckGo
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<com.duckduckgo.mobile.android.ui.view.text.DaxTextInput
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customDialogTextInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/keyline_4"
android:hint="@string/whitelistDomainHint"
android:inputType="textUri" />
39 changes: 0 additions & 39 deletions app/src/main/res/layout/edit_whitelist.xml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="@dimen/keyline_4"
android:paddingTop="@dimen/keyline_5"
android:paddingEnd="@dimen/keyline_4"
android:paddingBottom="@dimen/keyline_5">
android:padding="@dimen/keyline_4">

<com.duckduckgo.mobile.android.ui.view.text.DaxTextView
android:id="@+id/fireproofWebsiteEmptyHint"
Expand Down
17 changes: 9 additions & 8 deletions app/src/main/res/layout/view_list_item_description.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2020 DuckDuckGo
~ Copyright (c) 2022 DuckDuckGo
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
Expand All @@ -14,14 +14,15 @@
~ limitations under the License.
-->

<com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
<com.duckduckgo.mobile.android.ui.view.text.DaxTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/websiteDescription"
style="@style/Widget.DuckDuckGo.ListItem.Description"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="16dp"
android:paddingTop="12dp"
android:paddingEnd="16dp"
android:paddingBottom="12dp"
android:paddingStart="@dimen/keyline_4"
android:paddingEnd="@dimen/keyline_4"
android:paddingBottom="@dimen/keyline_3"
app:textType="secondary"
app:typography="body2"
tools:text="Lorem ipsum dolor sit amet" />
20 changes: 14 additions & 6 deletions app/src/main/res/layout/view_list_item_empty_hint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@
~ limitations under the License.
-->

<com.google.android.material.textview.MaterialTextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/listItemEmptyHintTitle"
style="@style/Widget.DuckDuckGo.ListItem.EmptyHint"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/whitelistNoEntries"
tools:text="Lorem ipsum dolor sit amet" />
android:padding="@dimen/keyline_4">

<com.duckduckgo.mobile.android.ui.view.text.DaxTextView
android:id="@+id/listItemEmptyHintTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="@string/whitelistNoEntries"
app:textType="secondary"
app:typography="body2" />

</FrameLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/menu/menu_tab_switcher_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

<item
android:id="@+id/newTab"
android:icon="@drawable/ic_add"
android:icon="@drawable/ic_add_24"
android:title="@string/newTabMenuItem"
app:showAsAction="always" />

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/menu/whitelist_activity_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

<item
android:id="@+id/add"
android:icon="@drawable/ic_add"
android:icon="@drawable/ic_add_24"
android:title="@string/dialogAddTitle"
app:showAsAction="always" />

Expand Down

0 comments on commit 466b046

Please sign in to comment.