-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a91029c
commit b0f5efb
Showing
59 changed files
with
1,280 additions
and
750 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package io.wookey.wallet.data.entity | ||
|
||
import android.os.Parcelable | ||
import kotlinx.android.parcel.Parcelize | ||
|
||
@Parcelize | ||
data class SubAddress @JvmOverloads constructor(var id: Int = 0, var address: String, var label: String) : Parcelable |
110 changes: 110 additions & 0 deletions
110
app/src/main/java/io/wookey/wallet/dialog/SubAddressEditDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package io.wookey.wallet.dialog | ||
|
||
import android.arch.lifecycle.Observer | ||
import android.arch.lifecycle.ViewModelProviders | ||
import android.os.Bundle | ||
import android.support.v4.app.DialogFragment | ||
import android.support.v4.app.FragmentManager | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import android.view.WindowManager | ||
import io.wookey.wallet.R | ||
import io.wookey.wallet.support.BackgroundHelper | ||
import io.wookey.wallet.support.extensions.dp2px | ||
import io.wookey.wallet.support.extensions.hideKeyboard | ||
import io.wookey.wallet.support.extensions.screenWidth | ||
import io.wookey.wallet.support.extensions.toast | ||
import kotlinx.android.synthetic.main.dialog_sub_address_edit.* | ||
|
||
class SubAddressEditDialog : DialogFragment() { | ||
|
||
|
||
private var cancelListener: (() -> Unit)? = null | ||
private var confirmListener: (() -> Unit)? = null | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setStyle(STYLE_NO_TITLE, R.style.CustomDialog) | ||
isCancelable = false | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return inflater.inflate(R.layout.dialog_sub_address_edit, container, false) | ||
} | ||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
|
||
val viewModel = ViewModelProviders.of(this).get(SubAddressEditViewModel::class.java) | ||
|
||
val layoutParams = editContainer.layoutParams | ||
layoutParams.width = (screenWidth() * 0.85).toInt() | ||
layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT | ||
|
||
editContainer.background = BackgroundHelper.getBackground(context, R.color.color_FFFFFF, dp2px(5)) | ||
addressTag.background = BackgroundHelper.getEditBackground(context) | ||
|
||
confirm.background = BackgroundHelper.getButtonBackground(context) | ||
|
||
confirm.setOnClickListener { | ||
val tag = addressTag.text.toString().trim() | ||
if (tag.isNullOrBlank()) { | ||
toast(R.string.address_tag_hint) | ||
} else { | ||
viewModel.addSubAddress(tag) | ||
} | ||
} | ||
|
||
cancel.setOnClickListener { | ||
cancelListener?.invoke() | ||
hide() | ||
} | ||
|
||
viewModel.showLoading.observe(this, Observer { | ||
confirm.visibility = View.GONE | ||
progressBar.visibility = View.VISIBLE | ||
}) | ||
|
||
viewModel.hideLoading.observe(this, Observer { | ||
confirm.visibility = View.VISIBLE | ||
progressBar.visibility = View.GONE | ||
}) | ||
|
||
viewModel.toastRes.observe(this, Observer { toast(it) }) | ||
|
||
viewModel.success.observe(this, Observer { | ||
confirmListener?.invoke() | ||
hide() | ||
}) | ||
} | ||
|
||
fun hide() { | ||
val activity = activity | ||
if (activity != null && !activity.isFinishing && !activity.isDestroyed) { | ||
addressTag?.hideKeyboard() | ||
dismiss() | ||
} | ||
} | ||
|
||
companion object { | ||
private const val TAG = "SubAddressEditDialog" | ||
fun newInstance(): SubAddressEditDialog { | ||
val fragment = SubAddressEditDialog() | ||
return fragment | ||
} | ||
|
||
fun display(fm: FragmentManager, cancelListener: (() -> Unit)? = null, confirmListener: (() -> Unit)?) { | ||
val ft = fm.beginTransaction() | ||
val prev = fm.findFragmentByTag(TAG) | ||
if (prev != null) { | ||
ft.remove(prev) | ||
} | ||
ft.addToBackStack(null) | ||
newInstance().apply { | ||
this.cancelListener = cancelListener | ||
this.confirmListener = confirmListener | ||
}.show(ft, TAG) | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
app/src/main/java/io/wookey/wallet/dialog/SubAddressEditViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.wookey.wallet.dialog | ||
|
||
import android.arch.lifecycle.MutableLiveData | ||
import io.wookey.wallet.R | ||
import io.wookey.wallet.base.BaseViewModel | ||
import io.wookey.wallet.core.XMRWalletController | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.launch | ||
import kotlinx.coroutines.withContext | ||
|
||
class SubAddressEditViewModel : BaseViewModel() { | ||
val success = MutableLiveData<Boolean>() | ||
|
||
val showLoading = MutableLiveData<Boolean>() | ||
val hideLoading = MutableLiveData<Boolean>() | ||
val toastRes = MutableLiveData<Int>() | ||
|
||
fun addSubAddress(label: String) { | ||
showLoading.postValue(true) | ||
uiScope.launch { | ||
try { | ||
withContext(Dispatchers.IO) { | ||
XMRWalletController.addSubAddress(label) | ||
} | ||
hideLoading.postValue(true) | ||
success.postValue(true) | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
hideLoading.postValue(true) | ||
toastRes.postValue(R.string.node_connect_failed) | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.