use of ru.sash0k.thriftbox.database.DB in project Thrift-box by Sash0k.
the class DeleteConfirmDialog method onCreateDialog.
// ============================================================================
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Context context = getActivity();
String[] categories = context.getResources().getStringArray(R.array.categories);
final Bundle args = getArguments();
final int id = args.getInt(BaseColumns._ID);
final String date = args.getString(DB.DATE);
final int category = args.getInt(DB.CATEGORY);
final String value = Utils.formatValue(args.getLong(DB.VALUE)) + Utils.ROUBLE + "?";
final String title = getString(R.string.delete_label) + " " + value;
final String msg = context.getString(R.string.delete_msg) + '\n' + date + divider + categories[category] + divider + value;
android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(context).setTitle(((ActivityHelper) getActivity()).parseRouble(title)).setMessage(((ActivityHelper) getActivity()).parseRouble(msg)).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
new DB(context).deleteItem(context, id);
Utils.updateWidgets(context);
}
}).setNegativeButton(android.R.string.no, null);
return builder.create();
}
use of ru.sash0k.thriftbox.database.DB in project Thrift-box by Sash0k.
the class InputFragment method enterValue.
// ============================================================================
private void enterValue(Context context) {
if (valueTV != null) {
final String textValue = valueTV.getText().toString();
final int value = Utils.parseCurrency(textValue);
if (value > 0) {
final String comment = commentTV.getText().toString();
new DB(context).insertItem(context, value, categories.getSelected(), comment);
Toast.makeText(context, ((MainActivity) context).parseRouble(getString(R.string.enter_value_done) + " " + textValue + Utils.ROUBLE + " " + comment), Toast.LENGTH_SHORT).show();
cleanValues();
Utils.updateWidgets(context);
} else
Toast.makeText(context, getString(R.string.enter_value_invalid), Toast.LENGTH_SHORT).show();
}
}
use of ru.sash0k.thriftbox.database.DB in project Thrift-box by Sash0k.
the class Widget method updateWidget.
public static void updateWidget(Context context, AppWidgetManager appWidgetManager, int widgetID) {
RemoteViews widgetView = new RemoteViews(context.getPackageName(), R.layout.widget);
long[] timestamps = Utils.getTimestamps();
DB db = new DB(context);
final String today = Utils.formatValue(db.getExpense(context, timestamps[0]));
final String week = Utils.formatValue(db.getExpense(context, timestamps[1]));
final String month = Utils.formatValue(db.getExpense(context, timestamps[2]));
// настройка прозрачности виджета
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final int transparency = Integer.parseInt(preferences.getString(SettingsFragment.PREF_WIDGET_TRANSPARENCY_KEY, "255"));
widgetView.setInt(R.id.widget_background, "setColorFilter", Color.WHITE);
widgetView.setInt(R.id.widget_background, alpha, transparency);
// настройка цвета текста
final int color = preferences.getInt(SettingsFragment.PREF_WIDGET_TEXT_COLOR_KEY, Color.BLACK);
widgetView.setImageViewBitmap(R.id.ruble_icon, changeBitmapColor(context, R.mipmap.ic_currency_rub_black_24dp, color));
widgetView.setTextColor(R.id.widget_today, color);
widgetView.setTextColor(R.id.widget_week, color);
widgetView.setTextColor(R.id.widget_month, color);
widgetView.setTextViewText(R.id.widget_today, today);
widgetView.setTextViewText(R.id.widget_week, context.getString(R.string.week) + " " + week + " " + ROUBLE);
widgetView.setTextViewText(R.id.widget_month, context.getString(R.string.month) + " " + month + " " + ROUBLE);
// Запуск по клику на виджет
final Intent intent = new Intent(context, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
final PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
widgetView.setOnClickPendingIntent(R.id.widget, pendingIntent);
// Обновляем виджет
appWidgetManager.updateAppWidget(widgetID, widgetView);
}
use of ru.sash0k.thriftbox.database.DB in project Thrift-box by Sash0k.
the class ChartsFragment method generateMonthlyData.
// ============================================================================
/**
* Заполнение графика данными
*/
private BarData generateMonthlyData() {
final Context ctx = getActivity();
// получение категорий
final String[] bars = ctx.getResources().getStringArray(R.array.categories);
// получение данных
final long month = getArguments().getLong(DB.TIMESTAMP);
// Статистика за текущий месяц
List<Float> stats = new DB(ctx).getStatData(ctx, month, bars.length);
final int count = stats.size();
ArrayList<BarEntry> entries = new ArrayList<>();
final ArrayList<String> usedBars = new ArrayList<>();
int j = 0;
for (int i = 0; i < count; i++) {
float value = stats.get(i);
if (value > 0f) {
usedBars.add(bars[i]);
entries.add(new BarEntry(value, j, bars[i]));
j++;
}
}
// данные графика
BarDataSet ds = new BarDataSet(entries, null);
ds.setDrawValues(true);
ds.setColor(getResources().getColor(R.color.accent));
// подписи к линиям графика
BarData d = new BarData(usedBars, ds);
d.setValueTextColor(getResources().getColor(R.color.primary_text));
d.setValueTextSize(14f);
d.setValueFormatter(new FinanceFormatter());
return d;
}
Aggregations