i am assuming your interactions to date have been purely platonic free of any physical or emotional incidents between you and him. Also you have no relation with his ex girlfriend. When he is in affectionate mode, lightly hint you are receptive to slowly exploring mutual compatibility when he recovers from his recent break up. Make him initiate each convo and act like a platonic friend until he initiates interest in ratcheting up your relations.
There is nothing wrong with thinking about prospects with someone. It happens when you tend to like someone, so you’re not in the wrong in anyway whatsoever. The thing to remember is that getting worked up over it isn’t going to solve anything.
He’s alternating between affection and animosity simply because he’s in pain. He isn’t sure of what to do and is prone to mood swings. You are on the receiving end of the consequences of these mood swings. Prospecting is good but I would advise that you let him know that you like him. Sometimes, it’s easier to move on when someone is agreeing to stand by you.
The hardest part during this debacle is silencing your mind. If you’re speculating whether he likes you or not, it would be better for you to consider that he doesn’t. This is the safest route for you and would lead to minimum damage if you guys don’t hit it off.