Fresh on the heels of “Sorry to Bother You,” here’s another inventive, refreshing, funny, heart-wrenching movie about Oakland. Written by and starring Oakland natives Daveed Diggs and Rafael Casal, it’s a riff on intersecting stories of race and class, black culture and white privilege, romance and living in a hometown you almost don’t recognize anymore.

As economic inequality rockets skyward in the San Francisco Bay Area, pushing well-heeled new arrivals onto their turf, African-American Collin (“Hamilton” star Diggs in compelling form) and his white best pal Miles (Casal, a rapper and playwright) try to deal with a city that feels like a province of a colonial power. Like the place, they contain reservoirs of empathy, happiness and ambition side by side with anger and self-defeating impulses. Telling their stories, the film moves like a pendulum between the comforting tone of a buddy comedy and dark themes of systemic racism and police brutality.

Collin is the easygoing, good-tempered, cautious one of the pair, quick to serve up a smile. He’s in the last several days of felony probation and is eager to avoid the attention of the local cops, abstain from crossing the county line or otherwise violate any conditions of his release. He’s trying to reconnect with the woman that he used to be with, patiently buttering her up with sweet talk.

Miles, who looks like a gangbanger, all tats and grillwork on his teeth, is Collin’s partner at a local moving company. He’s a conscientious worker, devoted to his girlfriend and their little son but prone to push back hard against perceived disrespect. He’s a nonstop wiseguy hustler, doing rap-rich one-man shows to sell curling irons at the ghetto beauty parlor and an abandoned sailboat on the street.

And Miles has just bought a gun as a stupid joke, which doesn’t have Collin amused at all. They’ve been side by side since grade school, though what seems to keep them together now is tradition more than shared values.

Collin and Miles contain rival forces that don’t even get along inside themselves. Collin’s run-in with the law was incentive to grow up and move on, which is not that easy for a felon in Oakland. But he’s trying. Meanwhile, the city is changing around him. The old burger shop is now serving vegan patties, the bodega is selling green vegetable juice for $10 a bottle and he eats both without complaint because a healthy lifestyle could help him win back Val (an impressive Janina Gavankar), the woman he used to love.

It could be time for each man-child to refresh his role in the friendship. But Miles has always had Collin’s back, and right now that’s important. Early in the story, Collin sees an unarmed suspect run from a policeman, with the tragic outcome that’s all too familiar. That trauma pops back into his consciousness in his dreams and even when he’s distance-running around the city graveyard wide awake.

He’s already had a bad experience with the justice system, and doesn’t expect that telling the police how he saw the incident would help the dead civilian or himself. Even keeping quiet, he projects a palpable sense of fear. When Collin is walking home late at night and a police car pulls up behind him, shining a spotlight in his direction, the movie takes on the sense of a horror movie. How can he live without Miles right now? How can he deal with that unescapable gun?

In his feature directing debut, Carlos López Estrada keeps the competing threads of drama and humor in check. Diggs and Casal, who met in high school and have been close friends for half their lives, are tremendous together, making each scene they share play like a championship tennis match. While their script has the beginners’ impulse to include everything they have to say about every subject under the sun, it’s both genuinely provocative and exuberantly entertaining. There’s an inevitable degree of mess in a first effort like this, but the talent and energy make up for every misstep.