I'm using a MAX471 to measure current passing through a USB charge cable. This is an analog current sensing chip. I bought this a few years ago off EBay when I was evaluating various current measuring modules for a project to measure 18650 battery capacity. Although this one is not highly accurate (especially when one considers the accuracy of the analog output is limited by the ADC resolution in the microcontroller) it is perfectly adequate for this application where I'm only interested in a rough mAh count.
I could have used a standard ATMEGA328 Arduino but I was interested in keeping this build fairly compact so opted for an ATTiny85. I bought a small stash of about a dozen of these from Cool Components for use in LED and Neopixel projects. The current measurement is made using analogRead() which depends on the absolute voltage supply rail which might vary from 4.5 to 5.3 volts depending on what I plug this into. I tried using the ATTiny85's internal 1.1V reference but this would limit the max current that can be measured. So instead I'm using a TL431 to provide a 2.5V reference on another ADC pin to correct for any variations in VCC. This precision voltage reference was included in an assortment of through hole transistors I ordered from China.
In order to convert the current measurements into a mAh count, I need a fairly accurate clock. Although the ATTiny85's internal RC oscillator can drift significantly than when using a clock crystal, the error tends to be consistent and fairly stable over a modest temperature range. So this device will need to be calibrated against a USB charge doctor.
Power to the phone is switched on and off using a IRLZ44N logic-level N-channel MOSFET. I had bought a wide range of MOSFETs from Ebay and Rapid Electronics for use in motor controller, robotics, and high powered lighting projects. A quick test showed that it could switch the USB charger power when connected on the low side.
The TM1637 4-digit module is used to display the measured current and the mAh count down. This module is a clone of the Grove 4-digit LED display by Seeed Studio. The TM1637 can actually support more LEDs than those on the module, as well as up to 16 buttons. So this is great for making efficient use of the limited GPIO pins on the ATTiny85. I bought these as an add-on item on an Amazon order. I later discovered that the TM1637 wasn't being used to its full potential on these dirt cheap modules and so ordered a few more in a variety of LED colours and sizes from TxHang Electronic (aka alice11o1983)
Other assorted components - USB charge cable from Poundland, micro USB breakout from Ebay, USB port (female) from a broken Powerbank, double throw switch from battery pack of a Christmas decoration, wires collected from discards by BT Openreach engineers working on the phone cabinets near home.
Lipo longevity research: https://batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries