Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikhail Barashkov committed Jan 23, 2021
2 parents abd7a2d + b34b62d commit 6c30391
Show file tree
Hide file tree
Showing 56 changed files with 1,051 additions and 1,167 deletions.
6 changes: 3 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -401,19 +401,19 @@
android:name="com.handydev.financier.activity.AccountListTotalsDetailsActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="@string/totals"
android:theme="@style/Theme.AppCompat.Dialog" />
android:theme="@style/DialogStyle" />

<activity
android:name="com.handydev.financier.activity.BlotterTotalsDetailsActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="@string/totals"
android:theme="@style/Theme.AppCompat.Dialog" />
android:theme="@style/DialogStyle" />

<activity
android:name="com.handydev.financier.activity.BudgetListTotalsDetailsActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:label="@string/totals"
android:theme="@style/Theme.AppCompat.Dialog" />
android:theme="@style/DialogStyle" />

<activity
android:name="com.handydev.financier.activity.PurgeAccountActivity"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/java/com/handydev/financier/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class MainViewModel(activity: FragmentActivity, val context: Context): ViewModel
val blotter = BlotterFragment()
val bundle = Bundle()
bundle.putBoolean(BlotterFragment.SAVE_FILTER, true)
bundle.putBoolean(BlotterFragment.SHOW_TITLE, false)
blotter.arguments = bundle
return blotter
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,11 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.totals_details);

u = new Utils(this);
layout = (LinearLayout)findViewById(R.id.list);
layout = findViewById(R.id.list);
calculatingNode = activityLayout.addTitleNodeNoDivider(layout, R.string.calculating);

Button bOk = (Button)findViewById(R.id.bOK);
bOk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
finish();
}
});
bOk.setOnClickListener(view -> finish());

internalOnCreate();
calculateTotals();
Expand Down
378 changes: 0 additions & 378 deletions app/src/main/java/com/handydev/financier/activity/ActivityLayout.java

This file was deleted.

276 changes: 276 additions & 0 deletions app/src/main/java/com/handydev/financier/activity/ActivityLayout.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
package com.handydev.financier.activity

import android.content.Context
import android.content.DialogInterface
import android.database.Cursor
import android.view.View
import android.widget.*
import androidx.appcompat.app.AlertDialog
import com.handydev.financier.R
import com.handydev.financier.model.MultiChoiceItem
import com.handydev.financier.utils.Utils
import com.handydev.financier.view.NodeInflater

class ActivityLayout(private val inflater: NodeInflater, private val listener: ActivityLayoutListener) {

fun getInflater(): NodeInflater {
return inflater
}

fun addTitleNodeNoDivider(layout: LinearLayout?, labelId: Int): View {
val b = inflater.Builder(layout!!, R.layout.select_entry_title)
return b.withLabel(labelId).withNoDivider().create()
}

fun addTitleNodeNoDivider(layout: LinearLayout?, label: String?): View {
val b = inflater.Builder(layout!!, R.layout.select_entry_title)
return b.withLabel(label).withNoDivider().create()
}

fun addInfoNodeSingle(layout: LinearLayout?, id: Int, labelId: Int) {
val b = inflater.Builder(layout!!, R.layout.select_entry_single)
b.withId(id, listener).withLabel(labelId).create()
}

fun addInfoNodeSingle(layout: LinearLayout?, id: Int, label: String?): TextView {
val b = inflater.Builder(layout!!, R.layout.select_entry_single)
val v = b.withId(id, listener).withLabel(label).create()
val labelView = v.findViewById<TextView>(R.id.label)
labelView.tag = v
return labelView
}

fun addInfoNode(layout: LinearLayout?, id: Int, labelId: Int, defaultValueResId: Int): TextView {
val b = inflater.Builder(layout!!, R.layout.select_entry_simple)
val v = b.withId(id, listener).withLabel(labelId).withData(defaultValueResId).create()
val data = v.findViewById<TextView>(R.id.data)
data.tag = v
return data
}

fun addInfoNode(layout: LinearLayout?, id: Int, labelId: Int, defaultValue: String?): TextView {
val b = inflater.Builder(layout!!, R.layout.select_entry_simple)
val v = b.withId(id, listener).withLabel(labelId).withData(defaultValue).create()
return v.findViewById<View>(R.id.data) as TextView
}

fun addListNodeIcon(layout: LinearLayout?, id: Int, labelId: Int, defaultValueResId: Int): View {
val b = inflater.Builder(layout!!, R.layout.select_entry_icon)
return b.withId(id, listener).withLabel(labelId).withData(defaultValueResId).create()
}

fun addListNode(layout: LinearLayout?, id: Int, labelId: Int, defaultValueResId: Int): TextView {
val b = inflater.Builder(layout!!, R.layout.select_entry)
val v = b.withId(id, listener).withLabel(labelId).withData(defaultValueResId).create()
val data = v.findViewById<TextView>(R.id.data)
data.tag = v
return data
}

fun addListNode(layout: LinearLayout?, id: Int, labelId: Int, defaultValue: String?): TextView {
val b = inflater.Builder(layout!!, R.layout.select_entry)
val v = b.withId(id, listener).withLabel(labelId).withData(defaultValue).create()
return v.findViewById<View>(R.id.data) as TextView
}

fun addCheckboxNode(layout: LinearLayout?, id: Int, labelId: Int, dataId: Int, checked: Boolean): CheckBox {
val b = inflater.CheckBoxBuilder(layout!!)
val v = b.withCheckbox(checked).withLabel(labelId).withId(id, listener).withData(dataId).create()
return v.findViewById<View>(R.id.checkbox) as CheckBox
}

fun addInfoNodePlus(layout: LinearLayout?, id: Int, plusId: Int, labelId: Int) {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_simple_plus)
b.withButtonId(plusId, listener).withLabel(labelId).withId(id, listener).create()
}

fun addListNodePlus(layout: LinearLayout?, id: Int, plusId: Int, labelId: Int, defaultValueResId: Int): TextView {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_plus)
val v = b.withButtonId(plusId, listener)
.withId(id, listener)
.withLabel(labelId)
.withData(defaultValueResId)
.create()
val textView = v.findViewById<TextView>(R.id.data)
textView.setTag(R.id.bMinus, v.findViewById(plusId))
textView.tag = v
return textView
}

class FilterNode(val nodeLayout: View, val listLayout: View, val filterLayout: View, val textView: TextView, val autoCompleteTextView: AutoCompleteTextView) {
fun showFilter() {
listLayout.visibility = View.GONE
filterLayout.visibility = View.VISIBLE
autoCompleteTextView.setText("")
Utils.openSoftKeyboard(autoCompleteTextView, autoCompleteTextView.context)
}

fun hideFilter() {
Utils.closeSoftKeyboard(autoCompleteTextView, autoCompleteTextView.context)
filterLayout.visibility = View.GONE
listLayout.visibility = View.VISIBLE
}

val isFilterOn: Boolean
get() = filterLayout.visibility == View.VISIBLE
}

fun addFilterNode(layout: LinearLayout?, id: Int, actBtnId: Int, clearBtnId: Int, labelId: Int, defaultValueResId: Int, showListId: Int, closeFilterId: Int, showFilterId: Int, darkUI: Boolean = false): FilterNode {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_filter)
val v = b.withButtonId(actBtnId, listener)
.withClearButtonId(clearBtnId, listener)
.withAutoCompleteFilter(listener, showListId)
.withId(id, listener)
.withLabel(labelId, darkUI)
.create()
val filterTxt = getAutoCompleteTextView(showListId, v)
filterTxt.setHint(defaultValueResId)
var filterToggle = v.findViewById<ImageView>(R.id.closeFilter)
filterToggle.id = closeFilterId
filterToggle.setOnClickListener(listener)
filterToggle = v.findViewById(R.id.showFilter)
filterToggle.id = showFilterId
filterToggle.setOnClickListener(listener)
val textView = v.findViewById<TextView>(R.id.data)
textView.setText(defaultValueResId)
textView.setTag(R.id.bMinus, v.findViewById(clearBtnId))
textView.tag = v
return FilterNode(v, v.findViewById(R.id.list_node_row), v.findViewById(R.id.filter_node_row), textView, filterTxt)
}

fun addCategoryNodeForTransaction(layout: LinearLayout?, emptyResId: Int, darkUI: Boolean): FilterNode {
val filterNode = addFilterNode(layout, R.id.category, R.id.category_add, R.id.category_clear, R.string.category, emptyResId,
R.id.category_show_list, R.id.category_close_filter, R.id.category_show_filter, darkUI)
val splitImage = filterNode.nodeLayout.findViewById<ImageView>(R.id.split)
splitImage.visibility = View.VISIBLE
splitImage.id = R.id.category_split
splitImage.setOnClickListener(listener)
return filterNode
}

fun addCategoryNodeForTransfer(layout: LinearLayout?, emptyResId: Int, darkUI: Boolean): FilterNode {
return addFilterNode(layout, R.id.category, R.id.category_add, R.id.category_clear, R.string.category, emptyResId,
R.id.category_show_list, R.id.category_close_filter, R.id.category_show_filter, darkUI)
}

fun addCategoryNodeForFilter(layout: LinearLayout?, emptyResId: Int, darkUI: Boolean): FilterNode {
return addFilterNode(layout, R.id.category, -1, R.id.category_clear, R.string.category, emptyResId,
R.id.category_show_list, R.id.category_close_filter, R.id.category_show_filter, darkUI)
}

private fun getAutoCompleteTextView(showListId: Int, v: View): AutoCompleteTextView {
val filterTxt = v.findViewById<AutoCompleteTextView>(R.id.autocomplete_filter)
val showList = v.findViewById<View>(showListId)
filterTxt.setTag(R.id.list, showList)
return filterTxt
}

fun addNodeUnsplit(layout: LinearLayout?): View {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_unsplit)
val v = b.withButtonId(R.id.add_split, listener).withId(R.id.unsplit_action, listener).withLabel(R.string.unsplit_amount).withData("0").create()
val transferImageView = v.findViewById<ImageView>(R.id.add_split_transfer)
transferImageView.setOnClickListener(listener)
return v
}

fun addSplitNodeMinus(layout: LinearLayout?, id: Int, minusId: Int, labelId: Int, defaultValue: String?): View {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_minus)
return b.withButtonId(minusId, listener).withoutMoreButton().withId(id, listener).withLabel(labelId).withData(defaultValue).create()
}

@JvmOverloads
fun addFilterNodeMinus(layout: LinearLayout?, id: Int, minusId: Int, labelId: Int, defaultValueResId: Int, defaultValue: String? = null): TextView {
val b = inflater.ListBuilder(layout!!, R.layout.select_entry_minus).withButtonId(minusId, listener).withId(id, listener).withLabel(labelId)
if (defaultValue != null) {
b.withData(defaultValue)
} else {
b.withData(defaultValueResId)
}
val v = b.create()
val clearBtn = hideButton(v, minusId)
val text = v.findViewById<TextView>(R.id.data)
text.setTag(R.id.bMinus, clearBtn) // needed for dynamic toggling in any activity with filters
return text
}

private fun hideButton(v: View, btnId: Int): ImageView {
val plusImageView = v.findViewById<ImageView>(btnId)
plusImageView.visibility = View.GONE
return plusImageView
}

fun addPictureNodeMinus(context: Context?, layout: LinearLayout?, id: Int, minusId: Int, labelId: Int, defaultLabelResId: Int): ImageView {
val b = inflater.PictureBuilder(layout!!)
val v = b.withPicture(context!!, null).withButtonId(minusId, listener).withId(id, listener)
.withLabel(labelId).withData(defaultLabelResId).create()
return v.findViewById<View>(R.id.picture) as ImageView
}

fun addEditNode(layout: LinearLayout?, labelId: Int, view: View?): View {
val b = inflater.EditBuilder(layout!!, view)
return b.withLabel(labelId).create()
}

private fun selectSingleChoice(context: Context, titleId: Int, adapter: ListAdapter, checkedItem: Int,
onClickListener: DialogInterface.OnClickListener) {
AlertDialog.Builder(context)
.setSingleChoiceItems(adapter, checkedItem, onClickListener)
.setTitle(titleId)
.show()
}

fun selectMultiChoice(context: Context?, id: Int, titleId: Int, items: List<MultiChoiceItem?>) {
val count = items.size
val titles = arrayOfNulls<String>(count)
val checked = BooleanArray(count)
for (i in 0 until count) {
titles[i] = items[i]!!.title
checked[i] = items[i]!!.isChecked
}
AlertDialog.Builder(context!!)
.setMultiChoiceItems(titles, checked) { dialog: DialogInterface?, which: Int, isChecked: Boolean -> items[which]!!.isChecked = isChecked }
.setPositiveButton(R.string.ok) { dialog: DialogInterface?, which: Int -> listener.onSelected(id, items) }
.setNegativeButton(R.string.cancel) { dialog: DialogInterface?, which: Int -> }
.setTitle(titleId)
.show()
}

fun selectPosition(context: Context, id: Int, titleId: Int,
adapter: ListAdapter, selectedPosition: Int) {
selectSingleChoice(context, titleId, adapter, selectedPosition
) { dialog: DialogInterface, which: Int ->
dialog.cancel()
listener.onSelectedPos(id, which)
}
}

fun selectItemId(context: Context, id: Int, titleId: Int,
adapter: ListAdapter, selectedPosition: Int) {
selectSingleChoice(context, titleId, adapter, selectedPosition
) { dialog: DialogInterface, which: Int ->
dialog.cancel()
val selectedId = adapter.getItemId(which)
listener.onSelectedId(id, selectedId)
}
}

fun select(context: Context, id: Int, titleId: Int,
cursor: Cursor, adapter: ListAdapter,
idColumn: String?, valueId: Long) {
val pos = Utils.moveCursor(cursor, idColumn, valueId)
selectSingleChoice(context, titleId, adapter, pos
) { dialog: DialogInterface, which: Int ->
dialog.cancel()
cursor.moveToPosition(which)
val selectedId = cursor.getLong(cursor.getColumnIndexOrThrow(idColumn))
listener.onSelectedId(id, selectedId)
}
}

fun addRateNode(layout: LinearLayout?): View {
return inflater.Builder(layout!!, R.layout.select_entry_rate)
.withLabel(R.string.rate)
.withData(R.string.no_rate)
.create()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class BlotterFilterActivity extends FilterAbstractActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
supportRequestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.blotter_filter);

df = DateUtils.getShortDateFormat(this);
Expand All @@ -68,10 +68,10 @@ protected void onCreate(Bundle savedInstanceState) {
period = activityLayout.addFilterNodeMinus(layout, R.id.period, R.id.period_clear, R.string.period, R.string.no_filter);
account = activityLayout.addFilterNodeMinus(layout, R.id.account, R.id.account_clear, R.string.account, R.string.no_filter);
currency = activityLayout.addFilterNodeMinus(layout, R.id.currency, R.id.currency_clear, R.string.currency, R.string.no_filter);
initCategorySelector(layout);
initPayeeSelector(layout);
initProjectSelector(layout);
initLocationSelector(layout);
initCategorySelector(layout, true);
initPayeeSelector(layout, true);
initProjectSelector(layout, true);
initLocationSelector(layout, true);
note = activityLayout.addFilterNodeMinus(layout, R.id.note, R.id.note_clear, R.string.note, R.string.no_filter);
status = activityLayout.addFilterNodeMinus(layout, R.id.status, R.id.status_clear, R.string.transaction_status, R.string.no_filter);
sortOrder = activityLayout.addFilterNodeMinus(layout, R.id.sort_order, R.id.sort_order_clear, R.string.sort_order, 0, sortBlotterEntries[0]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ private void addSmsTemplates() {
* todo.mb: consider refactoring to common logic with attributes and so on.
*/
private void addSmsTemplate(SmsTemplate t) {
View v = activityLayout.inflater.new Builder(smsTemplatesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_sms_template, this).create();
View v = activityLayout.getInflater().new Builder(smsTemplatesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_sms_template, this).create();
setSmsTemplateData(v, t);
ImageView minusImageView = v.findViewById(R.id.plus_minus);
minusImageView.setId(R.id.remove_sms_template);
Expand Down Expand Up @@ -223,7 +223,7 @@ private void addParentAttributes() {
ArrayList<Attribute> attributes = db.getAllAttributesForCategory(categoryId);
if (attributes.size() > 0) {
for (Attribute a : attributes) {
View v = activityLayout.inflater.new Builder(parentAttributesLayout, R.layout.select_entry_simple).create();
View v = activityLayout.getInflater().new Builder(parentAttributesLayout, R.layout.select_entry_simple).create();
v.setTag(a);
setAttributeData(v, a);
}
Expand All @@ -233,7 +233,7 @@ private void addParentAttributes() {
}

private void addAttribute(Attribute a) {
View v = activityLayout.inflater.new Builder(attributesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_attribute, this).create();
View v = activityLayout.getInflater().new Builder(attributesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_attribute, this).create();
setAttributeData(v, a);
ImageView plusImageView = v.findViewById(R.id.plus_minus);
plusImageView.setId(R.id.remove_attribute);
Expand Down
Loading

0 comments on commit 6c30391

Please sign in to comment.