Search in sources :

Example 1 with DB

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();
}
Also used : Context(android.content.Context) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) ActivityHelper(ru.sash0k.thriftbox.ActivityHelper) DB(ru.sash0k.thriftbox.database.DB)

Example 2 with DB

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();
    }
}
Also used : MainActivity(ru.sash0k.thriftbox.MainActivity) DB(ru.sash0k.thriftbox.database.DB)

Example 3 with DB

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);
}
Also used : RemoteViews(android.widget.RemoteViews) SharedPreferences(android.content.SharedPreferences) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) DB(ru.sash0k.thriftbox.database.DB) Paint(android.graphics.Paint)

Example 4 with DB

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;
}
Also used : Context(android.content.Context) BarDataSet(com.github.mikephil.charting.data.BarDataSet) ArrayList(java.util.ArrayList) BarEntry(com.github.mikephil.charting.data.BarEntry) Paint(android.graphics.Paint) FinanceFormatter(ru.sash0k.thriftbox.charting.FinanceFormatter) BarData(com.github.mikephil.charting.data.BarData) DB(ru.sash0k.thriftbox.database.DB)

Aggregations

DB (ru.sash0k.thriftbox.database.DB)4 Context (android.content.Context)2 Paint (android.graphics.Paint)2 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Bundle (android.os.Bundle)1 RemoteViews (android.widget.RemoteViews)1 BarData (com.github.mikephil.charting.data.BarData)1 BarDataSet (com.github.mikephil.charting.data.BarDataSet)1 BarEntry (com.github.mikephil.charting.data.BarEntry)1 ArrayList (java.util.ArrayList)1 ActivityHelper (ru.sash0k.thriftbox.ActivityHelper)1 MainActivity (ru.sash0k.thriftbox.MainActivity)1 FinanceFormatter (ru.sash0k.thriftbox.charting.FinanceFormatter)1