Search code examples
androidmysqlxmldialogcolor-picker

Dialog colorpicker which only displays purchased colors


So, for the moment I am programming an application with a shop system, you gain credits by doing and can spend your credits in the shop for colors to change the layout of the app.
Idea: In my ShopFragment is a FAB which opens a dialog when clicked, which should contain ONLY the colors already purchased set in ImageViews (if purchased or not is stored in a mysql table, 0 is not purchased and 1 is purchased) and when I click on one ImageView it should be like outlined and open another dialog if I would like to set this color as layout.

The problem: I dont know how to make a dialog which works as colorpicker which contains ONLY the purchased colors, prefered in order. Example 1: Available colors are red, blue, green, orange, purple, gold and pink, I bought only red so there should be only one ImageView in the dialog when I open it. Example 2: I bought red, green and pink. Now there should be only 3 ImageViews in the order red green and pink which I can click.

But how do I make them being 1. displayed, 2. being in the right order and 3. being outlined when clicked on?

Thanks for your attention guys!


Solution

  • 1 & 2: Do it the other way around. Add all the colors to your layout and then set those which are not purchased to visibility GONE. This way you can control the order in xml which makes it very easy.

    3: Use a custom selector background for your items, see https://stackoverflow.com/a/29848987/4388512