The only way to fix the headliner is to glue it. That means buying a new headliner and removing the front window, rear window and buying new rubber seals for each. Additionally you need to replace the perimeter seals and the seals under the stainless steel strips securing each side weatherstrip. It’s a big job.
Royce is correct. Ive seen it done without doing those steps and its always half assed. Do it right the first time and you will thank yourself later. However you mentioned painting the car and if that is going to happen sometime soon I would wait to do the headliner until its painted.
You may be able to patch it somehow to keep it driving until your ready to install a replacement
Just an FYI, no matter how you decide to proceed with the headliner be sure that you keep the headliner bows in the exact same order as you remove them. Each bow is unique and must go back in the same place as it came from. The bows are not interchangable. Also the very last bow (the one closest to the rear window) has a pair of clips that hold it in place and keep it from rolling over.