Skip to content

Commit 47570f5

Browse files
authored
Bookmarks ui tweaks and dialog leak clean up
1 parent 83169ef commit 47570f5

File tree

11 files changed

+60
-34
lines changed

11 files changed

+60
-34
lines changed

app/src/main/java/com/duckduckgo/app/bookmarks/ui/BookmarksActivity.kt

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
package com.duckduckgo.app.bookmarks.ui
1818

1919
import android.app.Activity
20+
import android.app.AlertDialog
2021
import android.arch.lifecycle.Observer
2122
import android.arch.lifecycle.ViewModelProviders
2223
import android.content.Context
2324
import android.content.Intent
2425
import android.os.Bundle
2526
import android.support.v7.widget.RecyclerView.Adapter
2627
import android.support.v7.widget.RecyclerView.ViewHolder
28+
import android.text.Html
2729
import android.view.LayoutInflater
2830
import android.view.View
2931
import android.view.ViewGroup
@@ -38,11 +40,12 @@ import org.jetbrains.anko.alert
3840
import org.jetbrains.anko.doAsync
3941
import javax.inject.Inject
4042

41-
class BookmarksActivity: DuckDuckGoActivity() {
43+
class BookmarksActivity : DuckDuckGoActivity() {
4244

4345
@Inject
4446
lateinit var viewModelFactory: ViewModelFactory
4547
lateinit var adapter: BookmarksAdapter
48+
private var deleteDialog: AlertDialog? = null
4649

4750
private val viewModel: BookmarksViewModel by lazy {
4851
ViewModelProviders.of(this, viewModelFactory).get(BookmarksViewModel::class.java)
@@ -74,11 +77,11 @@ class BookmarksActivity: DuckDuckGoActivity() {
7477
})
7578

7679
viewModel.command.observe(this, Observer {
77-
when(it) {
80+
when (it) {
7881
is BookmarksViewModel.Command.ConfirmDeleteBookmark -> confirmDeleteBookmark(it.bookmark)
7982
is BookmarksViewModel.Command.OpenBookmark -> openBookmark(it.bookmark)
8083
}
81-
})
84+
})
8285
}
8386

8487
private fun openBookmark(bookmark: BookmarkEntity) {
@@ -87,13 +90,15 @@ class BookmarksActivity: DuckDuckGoActivity() {
8790
finish()
8891
}
8992

93+
@Suppress("deprecation")
9094
private fun confirmDeleteBookmark(bookmark: BookmarkEntity) {
91-
val message = getString(R.string.bookmarkDeleteConfirmMessage, bookmark.title)
95+
val message = Html.fromHtml(getString(R.string.bookmarkDeleteConfirmMessage, bookmark.title))
9296
val title = getString(R.string.bookmarkDeleteConfirmTitle)
93-
alert(message, title) {
97+
deleteDialog = alert(message, title) {
9498
positiveButton(android.R.string.yes) { delete(bookmark) }
9599
negativeButton(android.R.string.no) { }
96-
}.show()
100+
}.build()
101+
deleteDialog?.show()
97102
}
98103

99104
private fun delete(bookmark: BookmarkEntity) {
@@ -102,6 +107,11 @@ class BookmarksActivity: DuckDuckGoActivity() {
102107
}
103108
}
104109

110+
override fun onDestroy() {
111+
deleteDialog?.dismiss()
112+
super.onDestroy()
113+
}
114+
105115
companion object {
106116
fun intent(context: Context): Intent {
107117
return Intent(context, BookmarksActivity::class.java)
@@ -110,7 +120,7 @@ class BookmarksActivity: DuckDuckGoActivity() {
110120
val OPEN_URL_RESULT_CODE = Activity.RESULT_FIRST_USER
111121
}
112122

113-
class BookmarksAdapter(val context: Context, val viewModel: BookmarksViewModel): Adapter<BookmarksViewHolder>() {
123+
class BookmarksAdapter(val context: Context, val viewModel: BookmarksViewModel) : Adapter<BookmarksViewHolder>() {
114124

115125
var bookmarks: List<BookmarkEntity> = emptyList()
116126
set(value) {

app/src/main/java/com/duckduckgo/app/browser/BrowserActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,11 @@ class BrowserActivity : DuckDuckGoActivity() {
428428
webView.hide()
429429
}
430430

431+
override fun onDestroy() {
432+
popupMenu.dismiss()
433+
super.onDestroy()
434+
}
435+
431436
companion object {
432437

433438
fun intent(context: Context, sharedText: String? = null): Intent {

app/src/main/java/com/duckduckgo/app/home/HomeActivity.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ class HomeActivity : AppCompatActivity() {
152152
startActivity(BrowserActivity.intent(this, url))
153153
}
154154

155+
override fun onDestroy() {
156+
popupMenu.dismiss()
157+
super.onDestroy()
158+
}
159+
155160
companion object {
156161

157162
private const val SETTINGS_REQUEST_CODE = 100
-714 Bytes
Binary file not shown.
-478 Bytes
Binary file not shown.
-1.02 KB
Binary file not shown.
-1.64 KB
Binary file not shown.
-2.31 KB
Binary file not shown.

app/src/main/res/layout/content_bookmarks.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
<android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android"
1919
android:id="@+id/recycler"
20+
android:paddingTop="18dp"
21+
android:paddingBottom="18dp"
2022
android:layout_width="match_parent"
2123
android:layout_height="match_parent"
2224
xmlns:app="http://schemas.android.com/apk/res-auto"
Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
<?xml version="1.0" encoding="utf-8"?>
2-
<!--
1+
<?xml version="1.0" encoding="utf-8"?><!--
32
~ Copyright (c) 2018 DuckDuckGo
43
~
54
~ Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,40 +14,45 @@
1514
~ limitations under the License.
1615
-->
1716

18-
<android.support.constraint.ConstraintLayout
19-
xmlns:android="http://schemas.android.com/apk/res/android"
20-
xmlns:tools="http://schemas.android.com/tools"
17+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2118
xmlns:app="http://schemas.android.com/apk/res-auto"
19+
xmlns:tools="http://schemas.android.com/tools"
2220
android:layout_width="match_parent"
2321
android:layout_height="wrap_content"
24-
android:padding="20dp"
2522
android:background="?android:attr/selectableItemBackground"
26-
android:clickable="true">
23+
android:clickable="true"
24+
android:focusable="true"
25+
android:padding="16dp">
2726

28-
<!-- content description set to network name in code -->
29-
<ImageView
30-
android:id="@+id/delete"
31-
android:contentDescription="@string/appName"
27+
<TextView
28+
android:id="@+id/title"
29+
android:layout_width="0dp"
30+
android:layout_height="wrap_content"
31+
android:fontFamily="sans-serif"
32+
android:lineSpacingExtra="4sp"
33+
android:paddingEnd="4dp"
34+
android:paddingStart="8dp"
35+
android:textColor="@color/white"
36+
android:textSize="16sp"
37+
android:textStyle="normal"
38+
app:layout_constraintBottom_toBottomOf="parent"
39+
app:layout_constraintEnd_toStartOf="@+id/delete"
3240
app:layout_constraintStart_toStartOf="parent"
3341
app:layout_constraintTop_toTopOf="parent"
34-
app:layout_constraintBottom_toBottomOf="parent"
35-
android:layout_width="wrap_content"
36-
android:layout_height="wrap_content"
37-
android:src="@drawable/ic_remove" />
42+
tools:text="Bookmark" />
3843

39-
<TextView
40-
android:id="@+id/title"
44+
<!-- content description set to network name in code -->
45+
<ImageView
46+
android:id="@+id/delete"
4147
android:layout_width="wrap_content"
4248
android:layout_height="wrap_content"
43-
android:layout_marginStart="19dp"
44-
android:textColor="@color/white"
49+
android:contentDescription="@string/appName"
50+
android:padding="4dp"
51+
android:src="@drawable/ic_clear_black_24px"
52+
android:tint="@color/white"
53+
app:layout_constraintBottom_toBottomOf="parent"
4554
app:layout_constraintEnd_toEndOf="parent"
46-
app:layout_constraintHorizontal_bias="0.0"
47-
app:layout_constraintTop_toTopOf="parent"
48-
app:layout_constraintStart_toEndOf="@+id/delete"
49-
android:textSize="16sp"
50-
android:textStyle="bold"
51-
android:fontFamily="sans-serif-medium"
52-
tools:text="Title" />
55+
app:layout_constraintTop_toTopOf="parent" />
56+
5357

5458
</android.support.constraint.ConstraintLayout>

0 commit comments

Comments
 (0)