#!/bin/bash

nanodroid_pull () {
	update_microg
	update_fdroid
	update_apps
	update_swipe
	update_gsync
	update_bromite
	update_osmand
}

update_swipe () {
	for ARCH in arm arm64 x86 x86_64; do
		grab_lib_from_ogapps libjni_keyboarddecoder.so 23 ${ARCH} false
	done

	for ARCH in arm arm64; do
		for SDK in 19 21 22 23 27 28; do
			grab_lib_from_ogapps libjni_latinimegoogle.so ${SDK} ${ARCH} true
		done
	done

	for ARCH in x86 x86_64; do
		grab_lib_from_ogapps libjni_latinimegoogle.so 23 ${ARCH} false
	done
}

update_microg () {
	# applications managed in repositories
	grab_apk_from_repo ${uG_GMSCORE[@]}
	grab_apk_from_repo ${uG_GSFPROXY[@]}
	grab_apk_from_repo ${uG_DROIDGUARD[@]}
	grab_apk_from_repo ${uG_FAKESTORE[@]}
	grab_apk_from_repo ${fd_NLPDEJAVU[@]}
	grab_apk_from_repo ${fd_NLPMOZILLA[@]}
	grab_apk_from_repo ${fd_NLPNOMINATIM[@]}
	grab_apk_from_repo ${fd_NLPAPPLE[@]}
	grab_apk_from_repo ${fd_NLPRADIOCELL[@]}
	grab_apk_from_repo ${fd_YALPSTORE[@]}
	grab_apk_from_repo ${fd_AURORASTORE[@]}
	grab_apk_from_repo ${nlx_PHONESKY[@]}

	# GitLab
	grab_apk_from_gitlab ${gl_AURORASERVICES[@]}
}

update_gsync () {
	#          KK LL M  N  O  P
	for API in 19 21 23 24 26 28; do
		grab_apk_from_ogapps ${og_CALSYNC[@]} ${API}
		grab_apk_from_ogapps ${og_CONSYNC[@]} ${API}
		grab_apk_from_ogapps ${og_BTRANSP[@]} ${API}
	done
}

update_fdroid () {
	grab_apk_from_repo ${fd_FDROID[@]}
	grab_apk_from_repo ${fd_FDROID_PE[@]}
	grab_apk_from_repo ${fd_AURORADROID[@]}
	grab_apk_from_gitlab ${gl_AURORASERVICES[@]}
}

update_apps () {
	# applications managed in repositories
	grab_apk_from_repo ${fd_ALARMIO[@]}
	grab_apk_from_repo ${fd_AMAZE[@]}
	grab_apk_from_repo ${fd_ANYSOFTKEYBOARD[@]}
	grab_apk_from_repo ${fd_BLOCKADA[@]}
	grab_apk_from_repo ${fd_FACESLIM[@]}
	grab_apk_from_repo ${fd_HACKERSKEYBOARD[@]}
	grab_apk_from_repo ${fd_KEEPASSDX[@]}
	grab_apk_from_repo ${fd_K9MAIL[@]}
	grab_apk_from_repo ${nlx_MPV[@]}
	grab_apk_from_repo ${fd_NEWPIPE[@]}
	grab_apk_from_repo ${fd_OANDBACKUP[@]}
	grab_apk_from_repo ${fd_ODYSSEY[@]}
	grab_apk_from_repo ${fd_OPENCAMERA[@]}
	grab_apk_from_repo ${fd_OPENKEYCHAIN[@]}
	grab_apk_from_repo ${fd_OPENLAUNCHER[@]}
	grab_apk_from_repo ${fd_OPENVPN[@]}
	grab_apk_from_repo ${fd_PRIVACY_BROWSER[@]}
	grab_apk_from_repo ${fd_QKSMS[@]}
	grab_apk_from_repo ${fd_SIMPLECALENDAR[@]}
	grab_apk_from_repo ${fd_SIMPLEGALLERY[@]}
	grab_apk_from_repo ${fd_TERMUX[@]}
	grab_apk_from_repo ${fd_TWIDERE[@]}
	grab_apk_from_repo ${gd_ORBOT[@]}
	grab_apk_from_repo ${gd_TORBROWSER[@]}

	# GitHub
	grab_apk_from_github ${gh_SMARTPACKKERNELMANAGER[@]}
	grab_apk_from_github ${gh_SUBSTRATUM[@]}

	# URL
	grab_apk_from_url ${raw_XDALABS[@]}
}

update_bromite () {
	grab_apk_from_repo ${bm_WEBVIEW_arm64[@]}
	grab_apk_from_repo ${bm_WEBVIEW_arm[@]}
	grab_apk_from_repo ${bm_WEBVIEW_x86[@]}
}

update_osmand () {
	grab_apk_from_repo ${fd_OSMAND[@]}
	grab_apk_from_repo ${fd_OSMAND_CONTOURLINES[@]}
}
