create a dialog for adding new blocked numbers

This commit is contained in:
tibbi 2018-11-30 15:52:46 +01:00
parent fa7a447369
commit 841a13b068
4 changed files with 66 additions and 10 deletions

View File

@ -10,6 +10,7 @@ import com.simplemobiletools.commons.extensions.updateTextColors
import com.simplemobiletools.commons.interfaces.RefreshRecyclerViewListener
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.adapters.ManageBlockedNumbersAdapter
import com.simplemobiletools.contacts.pro.dialogs.AddBlockedNumberDialog
import com.simplemobiletools.contacts.pro.extensions.getBlockedNumbers
import kotlinx.android.synthetic.main.activity_manage_blocked_numbers.*
@ -32,13 +33,13 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen
private fun updateBlockedNumbers() {
Thread {
val blockedNumbers = getBlockedNumbers()
ManageBlockedNumbersAdapter(this, blockedNumbers, this, manage_blocked_numbers_list) {
}.apply {
manage_blocked_numbers_list.adapter = this
}
runOnUiThread {
ManageBlockedNumbersAdapter(this, blockedNumbers, this, manage_blocked_numbers_list) {
}.apply {
manage_blocked_numbers_list.adapter = this
}
manage_blocked_numbers_placeholder.beVisibleIf(blockedNumbers.isEmpty())
manage_blocked_numbers_placeholder_2.beVisibleIf(blockedNumbers.isEmpty())
}
@ -63,6 +64,8 @@ class ManageBlockedNumbersActivity : SimpleActivity(), RefreshRecyclerViewListen
}
private fun addBlockedNumber() {
AddBlockedNumberDialog(this) {
updateBlockedNumbers()
}
}
}

View File

@ -71,9 +71,7 @@ class ManageBlockedNumbersAdapter(activity: BaseSimpleActivity, var blockedNumbe
getSelectedItems().forEach {
removeBlockedNumbers.add(it)
Thread {
activity.deleteBlockedNumber(it.number)
}.start()
activity.deleteBlockedNumber(it.number)
}
blockedNumbers.removeAll(removeBlockedNumbers)

View File

@ -0,0 +1,35 @@
package com.simplemobiletools.contacts.pro.dialogs
import androidx.appcompat.app.AlertDialog
import com.simplemobiletools.commons.activities.BaseSimpleActivity
import com.simplemobiletools.commons.extensions.setupDialogStuff
import com.simplemobiletools.commons.extensions.showKeyboard
import com.simplemobiletools.commons.extensions.value
import com.simplemobiletools.contacts.pro.R
import com.simplemobiletools.contacts.pro.extensions.addBlockedNumber
import kotlinx.android.synthetic.main.dialog_add_blocked_number.view.*
class AddBlockedNumberDialog(val activity: BaseSimpleActivity, val callback: () -> Unit) {
init {
val view = activity.layoutInflater.inflate(R.layout.dialog_add_blocked_number, null)
AlertDialog.Builder(activity)
.setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, null)
.create().apply {
activity.setupDialogStuff(view, this) {
showKeyboard(view.add_blocked_number_edittext)
getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener {
val phoneNumber = view.add_blocked_number_edittext.value
if (phoneNumber.isNotEmpty()) {
activity.addBlockedNumber(phoneNumber)
}
callback()
dismiss()
}
}
}
}
}

View File

@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dialog_holder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_margin">
<com.simplemobiletools.commons.views.MyEditText
android:id="@+id/add_blocked_number_edittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/activity_margin"
android:layout_marginTop="@dimen/small_margin"
android:layout_marginRight="@dimen/activity_margin"
android:inputType="phone"
android:textCursorDrawable="@null"
android:textSize="@dimen/bigger_text_size"/>
</RelativeLayout>