use of com.nightonke.saver.model.CoCoinRecord in project CoCoin by Nightonke.
the class DB method getData.
public void getData() {
RecordManager.RECORDS = new LinkedList<>();
RecordManager.TAGS = new LinkedList<>();
Cursor cursor = sqliteDatabase.query(TAG_DB_NAME_STRING, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
Tag tag = new Tag();
tag.setId(cursor.getInt(cursor.getColumnIndex("ID")) - 1);
tag.setName(cursor.getString(cursor.getColumnIndex("NAME")));
tag.setWeight(cursor.getInt(cursor.getColumnIndex("WEIGHT")));
RecordManager.TAGS.add(tag);
} while (cursor.moveToNext());
if (cursor != null)
cursor.close();
}
cursor = sqliteDatabase.query(RECORD_DB_NAME_STRING, null, null, null, null, null, null);
if (cursor.moveToFirst()) {
do {
CoCoinRecord coCoinRecord = new CoCoinRecord();
coCoinRecord.setId(cursor.getLong(cursor.getColumnIndex("ID")));
coCoinRecord.setMoney(cursor.getFloat(cursor.getColumnIndex("MONEY")));
coCoinRecord.setCurrency(cursor.getString(cursor.getColumnIndex("CURRENCY")));
coCoinRecord.setTag(cursor.getInt(cursor.getColumnIndex("TAG")));
coCoinRecord.setCalendar(cursor.getString(cursor.getColumnIndex("TIME")));
coCoinRecord.setRemark(cursor.getString(cursor.getColumnIndex("REMARK")));
coCoinRecord.setUserId(cursor.getString(cursor.getColumnIndex("USER_ID")));
coCoinRecord.setLocalObjectId(cursor.getString(cursor.getColumnIndex("OBJECT_ID")));
coCoinRecord.setIsUploaded(cursor.getInt(cursor.getColumnIndex("IS_UPLOADED")) == 0 ? false : true);
if (BuildConfig.DEBUG)
Log.d("CoCoin Debugger", "Load " + coCoinRecord.toString() + " S");
RecordManager.RECORDS.add(coCoinRecord);
RecordManager.SUM += (int) coCoinRecord.getMoney();
} while (cursor.moveToNext());
if (cursor != null)
cursor.close();
}
}
use of com.nightonke.saver.model.CoCoinRecord in project CoCoin by Nightonke.
the class CustomViewFragment method select.
private void select() {
if (RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS == null || RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size() == 0) {
return;
}
start = -1;
end = 0;
Sum = 0;
lastPieSelectedPosition = -1;
if (from.after(RecordManager.RECORDS.get(RecordManager.RECORDS.size() - 1).getCalendar())) {
return;
}
if (to.before(RecordManager.RECORDS.get(0).getCalendar())) {
return;
}
for (int i = RecordManager.RECORDS.size() - 1; i >= 0; i--) {
if (RecordManager.RECORDS.get(i).getCalendar().before(from)) {
end = i + 1;
break;
} else if (RecordManager.RECORDS.get(i).getCalendar().before(to)) {
if (start == -1) {
start = i;
}
}
}
startDayCalendar = (Calendar) from.clone();
startDayCalendar.set(Calendar.HOUR_OF_DAY, 0);
startDayCalendar.set(Calendar.MINUTE, 0);
startDayCalendar.set(Calendar.SECOND, 0);
final long startDay = TimeUnit.MILLISECONDS.toDays(startDayCalendar.getTimeInMillis());
final long days = TimeUnit.MILLISECONDS.toDays(to.getTimeInMillis()) - startDay + 1;
TagExpanse = new TreeMap<>();
Expanse = new HashMap<>();
originalTargets = new float[(int) days];
int size = RecordManager.TAGS.size();
for (int j = 2; j < size; j++) {
TagExpanse.put(RecordManager.TAGS.get(j).getId(), Double.valueOf(0));
Expanse.put(RecordManager.TAGS.get(j).getId(), new ArrayList<CoCoinRecord>());
}
for (int i = start; i >= end; i--) {
CoCoinRecord coCoinRecord = RecordManager.RECORDS.get(i);
TagExpanse.put(coCoinRecord.getTag(), TagExpanse.get(coCoinRecord.getTag()) + Double.valueOf(coCoinRecord.getMoney()));
Expanse.get(coCoinRecord.getTag()).add(coCoinRecord);
Sum += coCoinRecord.getMoney();
originalTargets[(int) (TimeUnit.MILLISECONDS.toDays(coCoinRecord.getCalendar().getTimeInMillis()) - startDay)] += coCoinRecord.getMoney();
}
expense.setText(CoCoinUtil.GetInMoney(Sum));
emptyTip.setVisibility(View.GONE);
TagExpanse = CoCoinUtil.SortTreeMapByValues(TagExpanse);
final ArrayList<SliceValue> sliceValues = new ArrayList<>();
for (Map.Entry<Integer, Double> entry : TagExpanse.entrySet()) {
if (entry.getValue() >= 1) {
SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), CoCoinUtil.GetTagColor(entry.getKey()));
sliceValue.setLabel(String.valueOf(entry.getKey()));
sliceValues.add(sliceValue);
}
}
final PieChartData pieChartData = new PieChartData(sliceValues);
pieChartData.setHasLabels(false);
pieChartData.setHasLabelsOnlyForSelected(false);
pieChartData.setHasLabelsOutside(false);
pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
pie.setPieChartData(pieChartData);
pie.setChartRotationEnabled(false);
pie.setVisibility(View.VISIBLE);
iconRight.setVisibility(View.VISIBLE);
iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition - 1 + sliceValues.size()) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
pie.selectValue(selectedValue);
}
});
iconLeft.setVisibility(View.VISIBLE);
iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition + 1) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
pie.selectValue(selectedValue);
}
});
// set value touch listener of pie//////////////////////////////////////////////////////////////////
dateShownString = mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + " " + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR);
pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int p, SliceValue sliceValue) {
// snack bar
String text;
tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
double percent = sliceValue.getValue() / Sum * 100;
if ("zh".equals(CoCoinUtil.GetLanguage())) {
text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
} else {
text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
}
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
}
Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(-3)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForPie());
SnackbarManager.show(snackbar);
if (p == lastPieSelectedPosition) {
return;
} else {
lastPieSelectedPosition = p;
}
}
@Override
public void onValueDeselected() {
}
});
all.setVisibility(View.VISIBLE);
all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<CoCoinRecord> data = new LinkedList<CoCoinRecord>();
for (int i = start; i >= end; i--) data.add(RecordManager.RECORDS.get(i));
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = dateShownString + "\n" + CoCoinUtil.GetSpendString(Sum) + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = CoCoinUtil.GetSpendString(Sum) + " " + mContext.getResources().getString(R.string.from) + " " + CoCoinUtil.GetMonthShort(from.get(Calendar.MONTH) + 1) + " " + from.get(Calendar.DAY_OF_MONTH) + " " + from.get(Calendar.YEAR) + "\n" + mContext.getResources().getString(R.string.to) + " " + CoCoinUtil.GetMonthShort(to.get(Calendar.MONTH) + 1) + " " + to.get(Calendar.DAY_OF_MONTH) + " " + to.get(Calendar.YEAR) + " " + "in " + CoCoinUtil.GetTagName(tagId);
}
((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, data, dialogTitle), "MyDialog").commit();
}
});
}
use of com.nightonke.saver.model.CoCoinRecord in project CoCoin by Nightonke.
the class AccountBookListViewActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_account_book_list_view);
mContext = this;
userName = (TextView) findViewById(R.id.user_name);
userEmail = (TextView) findViewById(R.id.user_email);
userName.setTypeface(CoCoinUtil.typefaceLatoRegular);
userEmail.setTypeface(CoCoinUtil.typefaceLatoLight);
User user = BmobUser.getCurrentUser(CoCoinApplication.getAppContext(), User.class);
if (user != null) {
userName.setText(user.getUsername());
userEmail.setText(user.getEmail());
}
int size = RecordManager.getInstance(CoCoinApplication.getAppContext()).RECORDS.size();
if (RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS == null) {
RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS = new LinkedList<>();
}
RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS.clear();
for (int i = 0; i < size; i++) {
CoCoinRecord record = new CoCoinRecord();
record.set(RecordManager.RECORDS.get(i));
RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_RECORDS.add(record);
}
RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_SUM = Double.valueOf(RecordManager.getInstance(CoCoinApplication.getAppContext()).SUM);
originalSum = RecordManager.getInstance(CoCoinApplication.getAppContext()).SELECTED_SUM;
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
setTitle("");
mDrawer = (DrawerLayout) findViewById(R.id.drawer_layout);
int currentapiVersion = android.os.Build.VERSION.SDK_INT;
if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
// Do something for lollipop and above versions
Window window = this.getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(ContextCompat.getColor(mContext, R.color.statusBarColor));
} else {
// do something for phones running an SDK before lollipop
View statusBarView = (View) findViewById(R.id.status_bar_view);
statusBarView.getLayoutParams().height = CoCoinUtil.getStatusBarHeight();
}
if (toolbar != null) {
setSupportActionBar(toolbar);
final ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setDisplayShowHomeEnabled(true);
actionBar.setDisplayShowTitleEnabled(true);
actionBar.setDisplayUseLogoEnabled(false);
actionBar.setHomeButtonEnabled(true);
}
}
mDrawerToggle = new ActionBarDrawerToggle(this, mDrawer, 0, 0);
mDrawer.setDrawerListener(mDrawerToggle);
searchView = (MaterialSearchView) findViewById(R.id.search_view);
searchView.setVoiceSearch(false);
searchView.setHint(mContext.getResources().getString(R.string.input_remark_to_search));
searchView.setOnQueryTextListener(new MaterialSearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
progressDialog = new MaterialDialog.Builder(mContext).title(R.string.selecting_title).content(R.string.selecting_content).cancelable(false).progress(true, 0).show();
new SelectRecordsByRemark(query).execute();
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
searchView.setOnSearchViewListener(new MaterialSearchView.SearchViewListener() {
@Override
public void onSearchViewShown() {
//Do some magic
Log.d("Saver", "onSearchViewShown");
}
@Override
public void onSearchViewClosed() {
//Do some magic
Log.d("Saver", "onSearchViewClosed");
}
});
emptyTip = (TextView) findViewById(R.id.empty_tip);
emptyTip.setTypeface(CoCoinUtil.GetTypeface());
recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
layoutManager = new LinearLayoutManager(mContext, LinearLayoutManager.VERTICAL, false);
recyclerViewTouchActionGuardManager = new RecyclerViewTouchActionGuardManager();
recyclerViewTouchActionGuardManager.setInterceptVerticalScrollingWhileAnimationRunning(true);
recyclerViewTouchActionGuardManager.setEnabled(true);
recyclerViewSwipeManager = new RecyclerViewSwipeManager();
mAdapter = new MySwipeableItemAdapter(mContext, RecordManager.SELECTED_RECORDS, this, this);
mAdapter.setEventListener(new MySwipeableItemAdapter.EventListener() {
@Override
public void onItemRemoved(int position) {
activityOnItemRemoved(position);
}
@Override
public void onItemPinned(int position) {
activityOnItemPinned(position);
}
@Override
public void onItemViewClicked(View v, boolean pinned) {
int position = recyclerView.getChildAdapterPosition(v);
if (position != RecyclerView.NO_POSITION) {
activityOnItemClicked(position);
}
}
});
adapter = mAdapter;
wrappedAdapter = recyclerViewSwipeManager.createWrappedAdapter(mAdapter);
final GeneralItemAnimator animator = new SwipeDismissItemAnimator();
animator.setSupportsChangeAnimations(false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(wrappedAdapter);
recyclerView.setItemAnimator(animator);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
// Lollipop or later has native drop shadow feature. ItemShadowDecorator is not required.
} else {
recyclerView.addItemDecoration(new ItemShadowDecorator((NinePatchDrawable) ContextCompat.getDrawable(mContext, R.drawable.material_shadow_z1)));
}
recyclerView.addItemDecoration(new SimpleListDividerDecorator(ContextCompat.getDrawable(mContext, R.drawable.list_divider_h), true));
// NOTE:
// The initialization order is very important! This order determines the priority of touch event handling.
//
// priority: TouchActionGuard > Swipe > DragAndDrop
recyclerViewTouchActionGuardManager.attachRecyclerView(recyclerView);
recyclerViewSwipeManager.attachRecyclerView(recyclerView);
verticalRecyclerViewFastScroller = (VerticalRecyclerViewFastScroller) findViewById(R.id.fast_scroller);
// Connect the recycler to the scroller (to let the scroller scroll the list)
verticalRecyclerViewFastScroller.setRecyclerView(recyclerView);
// Connect the scroller to the recycler (to let the recycler scroll the scroller's handle)
recyclerView.setOnScrollListener(verticalRecyclerViewFastScroller.getOnScrollListener());
CoCoinUtil.backupCoCoinRecord = null;
if (RecordManager.SELECTED_RECORDS.size() == 0) {
emptyTip.setVisibility(View.VISIBLE);
verticalRecyclerViewFastScroller.setVisibility(View.INVISIBLE);
} else {
emptyTip.setVisibility(View.GONE);
verticalRecyclerViewFastScroller.setVisibility(View.VISIBLE);
}
infoLayout = (FrameLayout) mDrawer.findViewById(R.id.info_layout);
LinearLayout.LayoutParams infoLayoutParams = new LinearLayout.LayoutParams(infoLayout.getLayoutParams());
infoLayoutParams.setMargins(0, CoCoinUtil.getStatusBarHeight() - CoCoinUtil.dpToPx(30), 0, 0);
infoLayout.setLayoutParams(infoLayoutParams);
profileImage = (CircleImageView) mDrawer.findViewById(R.id.profile_image);
profileImage.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (SettingManager.getInstance().getLoggenOn()) {
CoCoinUtil.showToast(mContext, R.string.change_logo_tip);
} else {
CoCoinUtil.showToast(mContext, R.string.login_tip);
}
}
});
mDemoSlider = (SliderLayout) findViewById(R.id.slider);
HashMap<String, Integer> urls = CoCoinUtil.GetDrawerTopUrl();
for (String name : urls.keySet()) {
CustomSliderView customSliderView = new CustomSliderView(this);
// initialize a SliderLayout
customSliderView.image(urls.get(name)).setScaleType(BaseSliderView.ScaleType.Fit);
mDemoSlider.addSlider(customSliderView);
}
mDemoSlider.setPresetTransformer(SliderLayout.Transformer.ZoomOut);
mDemoSlider.setCustomAnimation(new DescriptionAnimation());
mDemoSlider.setDuration(4000);
mDemoSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
titleExpense = (TextView) findViewById(R.id.title_expense);
titleExpense.setTypeface(CoCoinUtil.typefaceLatoLight);
titleExpense.setText(CoCoinUtil.GetInMoney((int) (double) RecordManager.getInstance(mContext).SELECTED_SUM));
titleSum = (TextView) findViewById(R.id.title_sum);
titleSum.setTypeface(CoCoinUtil.typefaceLatoLight);
titleSum.setText(RecordManager.getInstance(mContext).SELECTED_RECORDS.size() + "'s");
// titleSlider = (SliderLayout)findViewById(R.id.title_slider);
// titleSlider.getLayoutParams().height = 48;
// titleSlider.getLayoutParams().width = 400 - CoCoinUtil.dpToPx(60 * 2);
//
// HashMap<String, Integer> urls2 = CoCoinUtil.getTransparentUrls();
//
// CustomTitleSliderView customTitleSliderView = new CustomTitleSliderView(0 + "'s", CoCoinFragmentManager.NUMBER_SLIDER);
// customTitleSliderView
// .image(urls2.get("0"))
// .setScaleType(BaseSliderView.ScaleType.Fit);
// titleSlider.addSlider(customTitleSliderView);
//
// customTitleSliderView = new CustomTitleSliderView(CoCoinUtil.GetInMoney(0), CoCoinFragmentManager.EXPENSE_SLIDER);
// customTitleSliderView
// .image(urls2.get("1"))
// .setScaleType(BaseSliderView.ScaleType.Fit);
// titleSlider.addSlider(customTitleSliderView);
//
// titleSlider.setPresetTransformer(SliderLayout.Transformer.ZoomOut);
// titleSlider.setCustomAnimation(new DescriptionAnimation());
// titleSlider.setDuration(3000);
// titleSlider.setCustomIndicator((PagerIndicator) findViewById(R.id.custom_indicator));
((TextView) findViewById(R.id.tag_title)).setTypeface(CoCoinUtil.GetTypeface());
((TextView) findViewById(R.id.tag_title_expense)).setTypeface(CoCoinUtil.GetTypeface());
((TextView) findViewById(R.id.tag_title_time)).setTypeface(CoCoinUtil.GetTypeface());
((TextView) findViewById(R.id.tag_title_tag)).setTypeface(CoCoinUtil.GetTypeface());
setMoney = (TextView) findViewById(R.id.select_expense);
setMoney.setTypeface(CoCoinUtil.GetTypeface());
setMoney.setOnClickListener(this);
noMoney = (TextView) findViewById(R.id.no_expense);
noMoney.setTypeface(CoCoinUtil.GetTypeface());
noMoney.setOnClickListener(this);
setTime = (TextView) findViewById(R.id.select_time);
setTime.setTypeface(CoCoinUtil.GetTypeface());
setTime.setOnClickListener(this);
noTime = (TextView) findViewById(R.id.no_time);
noTime.setTypeface(CoCoinUtil.GetTypeface());
noTime.setOnClickListener(this);
setTag = (TextView) findViewById(R.id.select_tag);
setTag.setTypeface(CoCoinUtil.GetTypeface());
setTag.setOnClickListener(this);
noTag = (TextView) findViewById(R.id.no_tag);
noTag.setTypeface(CoCoinUtil.GetTypeface());
noTag.setOnClickListener(this);
select = (TextView) findViewById(R.id.select);
select.setTypeface(CoCoinUtil.GetTypeface());
select.setOnClickListener(this);
leftExpense = (TextView) findViewById(R.id.left_expense);
leftExpense.setTypeface(CoCoinUtil.GetTypeface());
rightExpense = (TextView) findViewById(R.id.right_expense);
rightExpense.setTypeface(CoCoinUtil.GetTypeface());
leftTime = (TextView) findViewById(R.id.left_time);
leftTime.setTypeface(CoCoinUtil.GetTypeface());
rightTime = (TextView) findViewById(R.id.right_time);
rightTime.setTypeface(CoCoinUtil.GetTypeface());
tagImage = (ImageView) findViewById(R.id.tag_image);
tagName = (TextView) findViewById(R.id.tag_name);
tagName.setTypeface(CoCoinUtil.GetTypeface());
setConditions();
loadLogo();
}
use of com.nightonke.saver.model.CoCoinRecord in project CoCoin by Nightonke.
the class MySwipeableItemAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(MyViewHolder holder, final int position) {
// set listeners
// (if the item is *not pinned*, click event comes to the itemView)
holder.itemView.setOnClickListener(new SwipeableItemOnClickListener(position) {
@Override
public void onClick(View v) {
onItemViewClick(v);
}
});
// (if the item is *pinned*, click event comes to the mContainer)
holder.mContainer.setOnClickListener(new SwipeableItemOnClickListener(position) {
@Override
public void onClick(View v) {
onSwipeableViewContainerClick(v);
onItemClickListener.onItemClick(position);
}
});
// set text
int tPosition = records.size() - 1 - position;
CoCoinRecord record = records.get(tPosition);
holder.tagImage.setImageResource(CoCoinUtil.GetTagIcon(record.getTag()));
holder.date.setText(record.getCalendarString());
holder.money.setText(String.valueOf((int) record.getMoney()));
holder.date.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.money.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.money.setTextColor(ContextCompat.getColor(CoCoinApplication.getAppContext(), R.color.my_blue));
holder.index.setText((position + 1) + "");
holder.index.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.remark.setText(record.getRemark());
holder.remark.setTypeface(CoCoinUtil.typefaceLatoLight);
// set background resource (target view ID: container)
final int swipeState = holder.getSwipeStateFlags();
if ((swipeState & Swipeable.STATE_FLAG_IS_UPDATED) != 0) {
int bgResId;
if ((swipeState & Swipeable.STATE_FLAG_IS_ACTIVE) != 0) {
bgResId = R.drawable.bg_item_swiping_active_state;
} else if ((swipeState & Swipeable.STATE_FLAG_SWIPING) != 0) {
bgResId = R.drawable.bg_item_swiping_state;
} else {
bgResId = R.drawable.bg_item_normal_state;
}
holder.mContainer.setBackgroundResource(bgResId);
}
holder.setSwipeItemHorizontalSlideAmount(pinned.get((int) records.get(records.size() - 1 - position).getId()) ? Swipeable.OUTSIDE_OF_THE_WINDOW_LEFT : 0);
}
use of com.nightonke.saver.model.CoCoinRecord in project CoCoin by Nightonke.
the class TodayViewRecyclerViewAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(final viewHolder holder, final int position) {
switch(getItemViewType(position)) {
case TYPE_HEADER:
holder.date.setText(dateString);
holder.dateBottom.setText(dateString);
holder.expanseSum.setText(CoCoinUtil.GetInMoney((int) Sum));
holder.date.setTypeface(CoCoinUtil.GetTypeface());
holder.dateBottom.setTypeface(CoCoinUtil.GetTypeface());
holder.expanseSum.setTypeface(CoCoinUtil.typefaceLatoLight);
if (IS_EMPTY) {
holder.emptyTip.setVisibility(View.VISIBLE);
holder.emptyTip.setText(CoCoinUtil.GetTodayViewEmptyTip(fragmentPosition));
holder.emptyTip.setTypeface(CoCoinUtil.GetTypeface());
holder.reset.setVisibility(View.GONE);
holder.pie.setVisibility(View.GONE);
holder.iconLeft.setVisibility(View.GONE);
holder.iconRight.setVisibility(View.GONE);
holder.histogram.setVisibility(View.GONE);
holder.histogram_icon_left.setVisibility(View.GONE);
holder.histogram_icon_right.setVisibility(View.GONE);
holder.all.setVisibility(View.GONE);
holder.dateBottom.setVisibility(View.GONE);
} else {
holder.emptyTip.setVisibility(View.GONE);
final ArrayList<SliceValue> sliceValues = new ArrayList<>();
for (Map.Entry<Integer, Double> entry : TagExpanse.entrySet()) {
if (entry.getValue() >= 1) {
SliceValue sliceValue = new SliceValue((float) (double) entry.getValue(), mContext.getApplicationContext().getResources().getColor(CoCoinUtil.GetTagColorResource(entry.getKey())));
sliceValue.setLabel(String.valueOf(entry.getKey()));
sliceValues.add(sliceValue);
}
}
final PieChartData pieChartData = new PieChartData(sliceValues);
pieChartData.setHasLabels(false);
pieChartData.setHasLabelsOnlyForSelected(false);
pieChartData.setHasLabelsOutside(false);
pieChartData.setHasCenterCircle(SettingManager.getInstance().getIsHollow());
holder.pie.setPieChartData(pieChartData);
holder.pie.setChartRotationEnabled(false);
// two control button of pie////////////////////////////////////////////////////////////////////////
holder.iconRight.setVisibility(View.VISIBLE);
holder.iconRight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition - 1 + sliceValues.size()) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
holder.iconLeft.setVisibility(View.VISIBLE);
holder.iconLeft.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (lastPieSelectedPosition != -1) {
pieSelectedPosition = lastPieSelectedPosition;
}
pieSelectedPosition = (pieSelectedPosition + 1) % sliceValues.size();
SelectedValue selectedValue = new SelectedValue(pieSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
holder.pie.selectValue(selectedValue);
}
});
final List<Column> columns = new ArrayList<>();
final ColumnChartData columnChartData = new ColumnChartData(columns);
if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
for (int i = 0; i < columnNumber; i++) {
if (lastHistogramSelectedPosition == -1 && originalTargets[i] == 0) {
lastHistogramSelectedPosition = i;
}
SubcolumnValue value = new SubcolumnValue(originalTargets[i], CoCoinUtil.GetRandomColor());
List<SubcolumnValue> subcolumnValues = new ArrayList<>();
subcolumnValues.add(value);
Column column = new Column(subcolumnValues);
column.setHasLabels(false);
column.setHasLabelsOnlyForSelected(false);
columns.add(column);
}
Axis axisX = new Axis();
List<AxisValue> axisValueList = new ArrayList<>();
for (int i = 0; i < columnNumber; i++) {
axisValueList.add(new AxisValue(i).setLabel(CoCoinUtil.GetAxisDateName(axis_date, i)));
}
axisX.setValues(axisValueList);
Axis axisY = new Axis().setHasLines(true);
columnChartData.setAxisXBottom(axisX);
columnChartData.setAxisYLeft(axisY);
columnChartData.setStacked(true);
holder.histogram.setColumnChartData(columnChartData);
holder.histogram.setZoomEnabled(false);
// two control button of histogram//////////////////////////////////////////////////////////////////
holder.histogram_icon_left.setVisibility(View.VISIBLE);
holder.histogram_icon_left.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
lastHistogramSelectedPosition = (lastHistogramSelectedPosition - 1 + columnNumber) % columnNumber;
} while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
holder.histogram.selectValue(selectedValue);
}
});
holder.histogram_icon_right.setVisibility(View.VISIBLE);
holder.histogram_icon_right.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do {
lastHistogramSelectedPosition = (lastHistogramSelectedPosition + 1) % columnNumber;
} while (columnChartData.getColumns().get(lastHistogramSelectedPosition).getValues().get(0).getValue() == 0);
SelectedValue selectedValue = new SelectedValue(lastHistogramSelectedPosition, 0, SelectedValue.SelectedValueType.NONE);
holder.histogram.selectValue(selectedValue);
}
});
}
if (fragmentPosition == TODAY || fragmentPosition == YESTERDAY) {
holder.histogram_icon_left.setVisibility(View.INVISIBLE);
holder.histogram_icon_right.setVisibility(View.INVISIBLE);
holder.histogram.setVisibility(View.GONE);
holder.dateBottom.setVisibility(View.GONE);
holder.reset.setVisibility(View.GONE);
}
// set value touch listener of pie//////////////////////////////////////////////////////////////////
holder.pie.setOnValueTouchListener(new PieChartOnValueSelectListener() {
@Override
public void onValueSelected(int p, SliceValue sliceValue) {
// snack bar
RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
String text;
tagId = Integer.valueOf(String.valueOf(sliceValue.getLabelAsChars()));
double percent = sliceValue.getValue() / Sum * 100;
if ("zh".equals(CoCoinUtil.GetLanguage())) {
text = CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + CoCoinUtil.GetPercentString(percent) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
} else {
text = "Spend " + (int) sliceValue.getValue() + " (takes " + String.format("%.2f", percent) + "%)\n" + "in " + CoCoinUtil.GetTagName(tagId);
}
if ("zh".equals(CoCoinUtil.GetLanguage())) {
dialogTitle = dateShownString + CoCoinUtil.GetSpendString((int) sliceValue.getValue()) + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
} else {
dialogTitle = "Spend " + (int) sliceValue.getValue() + dateShownString + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
}
Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForPie());
SnackbarManager.show(snackbar);
if (p == lastPieSelectedPosition) {
return;
} else {
lastPieSelectedPosition = p;
}
if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
// histogram data///////////////////////////////////////////////////////////////////////////////////
float[] targets = new float[columnNumber];
for (int i = 0; i < columnNumber; i++) targets[i] = 0;
for (int i = Expanse.get(tagId).size() - 1; i >= 0; i--) {
CoCoinRecord coCoinRecord = Expanse.get(tagId).get(i);
if (axis_date == Calendar.DAY_OF_WEEK) {
if (CoCoinUtil.WEEK_START_WITH_SUNDAY) {
targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
} else {
targets[(coCoinRecord.getCalendar().get(axis_date) + 5) % 7] += coCoinRecord.getMoney();
}
} else if (axis_date == Calendar.DAY_OF_MONTH) {
targets[coCoinRecord.getCalendar().get(axis_date) - 1] += coCoinRecord.getMoney();
} else {
targets[coCoinRecord.getCalendar().get(axis_date)] += coCoinRecord.getMoney();
}
}
lastHistogramSelectedPosition = -1;
for (int i = 0; i < columnNumber; i++) {
if (lastHistogramSelectedPosition == -1 && targets[i] != 0) {
lastHistogramSelectedPosition = i;
}
columnChartData.getColumns().get(i).getValues().get(0).setTarget(targets[i]);
}
holder.histogram.startDataAnimation();
}
}
@Override
public void onValueDeselected() {
}
});
if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
// set value touch listener of histogram////////////////////////////////////////////////////////////
holder.histogram.setOnValueTouchListener(new ColumnChartOnValueSelectListener() {
@Override
public void onValueSelected(int columnIndex, int subcolumnIndex, SubcolumnValue value) {
lastHistogramSelectedPosition = columnIndex;
timeIndex = columnIndex;
// snack bar
RecordManager recordManager = RecordManager.getInstance(mContext.getApplicationContext());
String text = CoCoinUtil.GetSpendString((int) value.getValue());
if (tagId != -1)
// belongs a tag
if ("zh".equals(CoCoinUtil.GetLanguage()))
text = getSnackBarDateString() + text + "\n" + "于" + CoCoinUtil.GetTagName(tagId);
else
text += getSnackBarDateString() + "\n" + "in " + CoCoinUtil.GetTagName(tagId);
else // don't belong to any tag
if ("zh".equals(CoCoinUtil.GetLanguage()))
text = getSnackBarDateString() + "\n" + text;
else
text += "\n" + getSnackBarDateString();
// setting the snack bar and dialog title of histogram//////////////////////////////////////////////
dialogTitle = text;
Snackbar snackbar = Snackbar.with(mContext).type(SnackbarType.MULTI_LINE).duration(Snackbar.SnackbarDuration.LENGTH_SHORT).position(Snackbar.SnackbarPosition.BOTTOM).margin(15, 15).backgroundDrawable(CoCoinUtil.GetSnackBarBackground(fragmentPosition - 2)).text(text).textTypeface(CoCoinUtil.GetTypeface()).textColor(Color.WHITE).actionLabelTypeface(CoCoinUtil.GetTypeface()).actionLabel(mContext.getResources().getString(R.string.check)).actionColor(Color.WHITE).actionListener(new mActionClickListenerForHistogram());
SnackbarManager.show(snackbar);
}
@Override
public void onValueDeselected() {
}
});
}
// set the listener of the reset button/////////////////////////////////////////////////////////////
if (!(fragmentPosition == TODAY || fragmentPosition == YESTERDAY)) {
holder.reset.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
tagId = -1;
lastHistogramSelectedPosition = -1;
for (int i = 0; i < columnNumber; i++) {
if (lastHistogramSelectedPosition == -1 && originalTargets[i] != 0) {
lastHistogramSelectedPosition = i;
}
columnChartData.getColumns().get(i).getValues().get(0).setTarget(originalTargets[i]);
}
holder.histogram.startDataAnimation();
}
});
}
// set the listener of the show all button//////////////////////////////////////////////////////////
holder.all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
((FragmentActivity) mContext).getSupportFragmentManager().beginTransaction().add(new RecordCheckDialogFragment(mContext, allData, getAllDataDialogTitle()), "MyDialog").commit();
}
});
}
break;
case TYPE_BODY:
holder.tagImage.setImageResource(CoCoinUtil.GetTagIcon(allData.get(position - 1).getTag()));
holder.money.setText((int) allData.get(position - 1).getMoney() + "");
holder.money.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.cell_date.setText(allData.get(position - 1).getCalendarString());
holder.cell_date.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.remark.setText(allData.get(position - 1).getRemark());
holder.remark.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.index.setText(position + "");
holder.index.setTypeface(CoCoinUtil.typefaceLatoLight);
holder.layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String subTitle;
double spend = allData.get(position - 1).getMoney();
int tagId = allData.get(position - 1).getTag();
if ("zh".equals(CoCoinUtil.GetLanguage())) {
subTitle = CoCoinUtil.GetSpendString((int) spend) + "于" + CoCoinUtil.GetTagName(tagId);
} else {
subTitle = "Spend " + (int) spend + "in " + CoCoinUtil.GetTagName(tagId);
}
dialog = new MaterialDialog.Builder(mContext).icon(CoCoinUtil.GetTagIconDrawable(allData.get(position - 1).getTag())).limitIconToDefaultSize().title(subTitle).customView(R.layout.dialog_a_record, true).positiveText(R.string.get).show();
dialogView = dialog.getCustomView();
TextView remark = (TextView) dialogView.findViewById(R.id.remark);
TextView date = (TextView) dialogView.findViewById(R.id.date);
remark.setText(allData.get(position - 1).getRemark());
date.setText(allData.get(position - 1).getCalendarString());
}
});
break;
}
}
Aggregations