Search in sources :

Example 11 with CropCircleTransformation

use of com.polito.mad17.madmax.entities.CropCircleTransformation in project MadMax by deviz92.

the class PayGroupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pay_group);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String defaultCurrency = sharedPref.getString(SettingsFragment.DEFAULT_CURRENCY, "");
    Intent intent = getIntent();
    groupID = intent.getStringExtra("groupID");
    userID = intent.getStringExtra("userID");
    groupName = intent.getStringExtra("groupName");
    groupImageURL = intent.getStringExtra("groupImage");
    totBalances = (HashMap<String, Double>) intent.getSerializableExtra("totBalances");
    shownCurrency = intent.getStringExtra("shownCurrency");
    debt = totBalances.get(shownCurrency);
    debt = abs(Math.floor(debt * 100) / 100);
    currency = (Spinner) findViewById(R.id.currency);
    amountEditText = (EditText) findViewById(R.id.amount);
    amountEditText.setFilters(new InputFilter[] { new DecimalDigitsInputFilter(7, 2) });
    groupNameTextView = (TextView) findViewById(R.id.tv_receiver);
    groupNameTextView.setText(groupName);
    amountEditText.setText(debt.toString());
    // creating spinner for currencies
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.currencies, android.R.layout.simple_spinner_item);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    currency.setAdapter(adapter);
    // set the defaultCurrency value for the spinner based on the user preferences
    int spinnerPosition = adapter.getPosition(shownCurrency);
    currency.setSelection(spinnerPosition);
    userImage = (ImageView) findViewById(R.id.sender_photo);
    groupImage = (ImageView) findViewById(R.id.receiver_photo);
    userImageURL = MainActivity.getCurrentUser().getProfileImage();
    userImage = (ImageView) findViewById(R.id.sender_photo);
    if (userImageURL != null) {
        Glide.with(getLayoutInflater().getContext()).load(userImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
    } else {
        Glide.with(getLayoutInflater().getContext()).load(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(userImage);
    }
    groupImage = (ImageView) findViewById(R.id.receiver_photo);
    if (groupImageURL != null) {
        Glide.with(getLayoutInflater().getContext()).load(groupImageURL).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
    } else {
        Glide.with(getLayoutInflater().getContext()).load(R.drawable.group_default).centerCrop().bitmapTransform(new CropCircleTransformation(getLayoutInflater().getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(groupImage);
    }
}
Also used : SharedPreferences(android.content.SharedPreferences) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation) Intent(android.content.Intent) DecimalDigitsInputFilter(com.polito.mad17.madmax.activities.DecimalDigitsInputFilter)

Example 12 with CropCircleTransformation

use of com.polito.mad17.madmax.entities.CropCircleTransformation in project MadMax by deviz92.

the class FriendsViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ItemFriendsViewHolder holder, int position) {
    Log.d(TAG, "isGroupDetail " + isGroupDetail);
    if (position == (mData.size() - 1)) {
        Log.d(TAG, "item.getKey().equals(\"nullGroup\")");
        holder.nameTextView.setText("");
        holder.balanceTextView.setText("");
        holder.balanceTextTextView.setText("");
    } else {
        Map.Entry<String, User> item = getItem(position);
        Log.d(TAG, item.getKey() + " " + item.getValue().getName() + " " + item.getValue().getProfileImage());
        if (isGroupDetail)
            holder.balanceLayout.setVisibility(View.VISIBLE);
        else
            holder.balanceLayout.setVisibility(View.GONE);
        String photo = item.getValue().getProfileImage();
        if (photo != null && !photo.equals("")) {
            Glide.with(layoutInflater.getContext()).load(photo).centerCrop().bitmapTransform(new CropCircleTransformation(layoutInflater.getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
        } else {
            Glide.with(layoutInflater.getContext()).load(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(layoutInflater.getContext())).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
        }
        holder.nameTextView.setText(item.getValue().getName() + " " + item.getValue().getSurname());
        // Double balance = item.getValue().getBalanceWithGroup();
        totBalances = item.getValue().getBalancesWithGroup();
        SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
        String defaultCurrency = sharedPref.getString(SettingsFragment.DEFAULT_CURRENCY, "");
        Boolean multipleCurrencies = false;
        Double shownBal;
        String shownCurr;
        if (totBalances != null && !totBalances.isEmpty()) {
            if (!totBalances.isEmpty()) {
                // If there is more than one currency
                if (totBalances.size() > 1) {
                    multipleCurrencies = true;
                } else // If there is just one currency
                {
                    multipleCurrencies = false;
                }
                if (totBalances.containsKey(defaultCurrency)) {
                    shownBal = totBalances.get(defaultCurrency);
                    shownCurr = defaultCurrency;
                } else {
                    shownCurr = (String) totBalances.keySet().toArray()[0];
                    shownBal = totBalances.get(shownCurr);
                }
                // Print balance
                if (shownBal > 0) {
                    if (isGroupDetail) {
                        holder.balanceTextTextView.setText(R.string.should_receive_from_the_group);
                    } else {
                        holder.balanceTextTextView.setText(R.string.you_should_receive);
                    }
                    holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent));
                    if (multipleCurrencies)
                        holder.balanceTextView.setText(df.format(shownBal) + " " + shownCurr + "*");
                    else
                        holder.balanceTextView.setText(df.format(shownBal) + " " + shownCurr);
                    holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent));
                } else if (shownBal < 0) {
                    if (isGroupDetail) {
                        holder.balanceTextTextView.setText(R.string.owes_to_the_group);
                    } else {
                        holder.balanceTextTextView.setText(R.string.you_owe);
                    }
                    holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                    if (multipleCurrencies)
                        holder.balanceTextView.setText(df.format(Math.abs(shownBal)) + " " + shownCurr + "*");
                    else
                        holder.balanceTextView.setText(df.format(Math.abs(shownBal)) + " " + shownCurr);
                    holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                } else if (shownBal == 0) {
                    holder.balanceTextTextView.setText(R.string.no_debts);
                    holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorSecondaryText));
                    holder.balanceTextView.setText("0 " + defaultCurrency);
                    holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorSecondaryText));
                }
            }
        } else // If there are no balances in the map
        {
            holder.balanceTextTextView.setText(R.string.no_debts);
            holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorSecondaryText));
            holder.balanceTextView.setText("0 " + defaultCurrency);
            holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorSecondaryText));
        }
    // todo fin qui
    /*if (balance != null)
            {
                DecimalFormat df = new DecimalFormat("#.##");
                if (balance > 0) {
                    holder.balanceTextTextView.setText(R.string.should_receive_from_the_group);
                    holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent));

                    //todo mettere valuta
                    String balanceText = df.format(Math.abs(balance)) + " €";
                    holder.balanceTextView.setText(balanceText);
                    holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent));

                }
                else
                {
                    if (balance < 0) {
                        holder.balanceTextTextView.setText(R.string.owes_to_the_group);
                        holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                        //todo mettere valuta
                        String balanceText = df.format(Math.abs(balance)) + " €";
                        holder.balanceTextView.setText(balanceText);
                        holder.balanceTextView.setTextColor(ContextCompat.getColor(context, R.color.colorPrimaryDark));
                    } else {
                        holder.balanceTextTextView.setText(R.string.no_debts);
                        holder.balanceTextTextView.setTextColor(ContextCompat.getColor(context, R.color.colorSecondaryText));
                        //todo mettere valuta
                        holder.balanceTextView.setText("0 €");
                    }
                    //holder.balanceTextView.setVisibility(View.GONE);
                }
            }

            else if (balance == null)
            {
                holder.balanceTextView.setVisibility(View.GONE);
                holder.balanceTextTextView.setVisibility(View.GONE);

            }*/
    }
}
Also used : User(com.polito.mad17.madmax.entities.User) SharedPreferences(android.content.SharedPreferences) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation) HashMap(java.util.HashMap) Map(java.util.Map)

Example 13 with CropCircleTransformation

use of com.polito.mad17.madmax.entities.CropCircleTransformation in project MadMax by deviz92.

the class ExpenseCommentsViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ExpenseCommentsViewHolder expenseCommentsViewHolder, int position) {
    Comment comment = getItem(position).getValue();
    // loading author profile photo
    Glide.with(context).load(comment.getAuthorPhoto()).centerCrop().bitmapTransform(new CropCircleTransformation(context)).diskCacheStrategy(DiskCacheStrategy.ALL).into(expenseCommentsViewHolder.authorPhoto);
    expenseCommentsViewHolder.authorTextView.setText(comment.getAuthor());
    expenseCommentsViewHolder.commentTextView.setText(comment.getMessage());
    expenseCommentsViewHolder.timestampTextView.setText(context.getString(R.string.day) + " " + comment.getDate() + " " + context.getString(R.string.at) + " " + comment.getTime());
}
Also used : Comment(com.polito.mad17.madmax.entities.Comment) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation)

Example 14 with CropCircleTransformation

use of com.polito.mad17.madmax.entities.CropCircleTransformation in project MadMax by deviz92.

the class SplittersViewAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final SplittersViewAdapter.ItemSplittersViewAdapter holder, final int position) {
    final Map.Entry<String, User> item = getItem(position);
    String photo = item.getValue().getProfileImage();
    if (photo != null) {
        Glide.with(context).load(photo).placeholder(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(context)).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
    } else {
        Glide.with(context).load(R.drawable.user_default).centerCrop().bitmapTransform(new CropCircleTransformation(context)).diskCacheStrategy(DiskCacheStrategy.ALL).into(holder.imageView);
    }
    Log.d(TAG, "Nome: " + item.getValue().getName());
    Log.d(TAG, "Cognome: " + item.getValue().getSurname());
    holder.nameTextView.setText(item.getValue().getName() + " " + item.getValue().getSurname());
    holder.currencyTextView.setText(item.getValue().getExpenseCurrency());
    holder.amountEditText.setText(item.getValue().getSplitPart().toString());
    // update MyCustomEditTextListener every time we bind a new item
    // so that it knows what item in mDataset to update
    holder.myCustomEditTextListener.updateUser(item);
}
Also used : User(com.polito.mad17.madmax.entities.User) CropCircleTransformation(com.polito.mad17.madmax.entities.CropCircleTransformation) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

CropCircleTransformation (com.polito.mad17.madmax.entities.CropCircleTransformation)13 Map (java.util.Map)7 User (com.polito.mad17.madmax.entities.User)5 SharedPreferences (android.content.SharedPreferences)4 Intent (android.content.Intent)3 View (android.view.View)3 ImageView (android.widget.ImageView)3 Expense (com.polito.mad17.madmax.entities.Expense)3 HashMap (java.util.HashMap)3 ViewGroup (android.view.ViewGroup)2 TextView (android.widget.TextView)2 DecimalDigitsInputFilter (com.polito.mad17.madmax.activities.DecimalDigitsInputFilter)2 Group (com.polito.mad17.madmax.entities.Group)2 DecimalFormat (java.text.DecimalFormat)2 TargetApi (android.annotation.TargetApi)1 DataSnapshot (com.google.firebase.database.DataSnapshot)1 DatabaseError (com.google.firebase.database.DatabaseError)1 ValueEventListener (com.google.firebase.database.ValueEventListener)1 DetailFragment (com.polito.mad17.madmax.activities.DetailFragment)1 MainActivity (com.polito.mad17.madmax.activities.MainActivity)1