SUTHERLAND SPRINGS, Texas — The man who killed more than two dozen people at a Texas church in 2017 appeared to have been planning months before, according to testimony at a trial in a lawsuit alleging the Air Force failed to flag a conviction that might have prevented him from legally buying the gun used in the shooting.

Trial began Wednesday in a lawsuit against the federal government filed by survivors and families of victims of the shooting at the First Baptist Church of Sutherland Springs.

Devin Patrick Kelley opened fire during a Sunday service there in November 2017 in the worst mass shooting in Texas history. Authorities put the official death toll at 26 because one of the 25 people killed was pregnant. Kelley died of an apparent self-inflicted gunshot wound after he was shot and chased by two men who heard the gunfire at the church.

Kelley had served nearly five years in the Air Force before being discharged in 2014 for bad conduct, after he was convicted of assaulting a former wife and stepson, cracking the child's skull. The Air Force has publicly acknowledged that the felony conviction for domestic violence, had it been put into the FBI database, could have prevented Kelley from buying guns from licensed firearms dealers, and also from possessing body armor.

During cross-examination of the lead investigator in the church shooting, government lawyer Paul Stern showed a series of notes and investigative reports, including several photos posted on Kelley's social media accounts of him pointing guns at the camera, the San Antonio Express-News reported.

Investigators also showed his iCloud account that had reminders to himself "of getting ammo, destroy phone, and clear YouTube and browser."

Lawyers for the survivors and victims' families said there was evidence Kelley not only had a history of violence but that he was also obsessed with guns and church shootings after the June 2015 mass church shooting in Charleston, South Carolina.

The bench trial is expected to last up to three weeks. U.S. District Judge Xavier Rodriguez will determine if the government is liable, and if so, the matter will proceed to a trial on damages.