This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implementation 'com.squareup.retrofit2:retrofit:2.8.0' | |
implementation 'com.squareup.retrofit2:converter-gson:2.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Version( | |
@SerializedName("documents") | |
var documents: List<DocumentItems> | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class DocumentItems( | |
@SerializedName("name") | |
var name: String, | |
@SerializedName("fields") | |
var fields: Fields, | |
@SerializedName("createdTime") | |
var createdTime: String, | |
@SerializedName("updateTime") | |
var updateTime: String, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class Fields( | |
@SerializedName("app_version") | |
var app_version: StringValue | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data class StringValue( | |
@SerializedName("stringValue") | |
var version: String | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private const val BASE_URL = "https://firestore.googleapis.com/v1/projects/firestoreforceupdate/databases/" | |
class FirebaseClient { | |
// Coroutines | |
private val job = Job() | |
private val coroutineContext = Dispatchers.IO + job | |
private val uiScope = CoroutineScope(coroutineContext) | |
fun getAppVersionFromApi(callback: (isSuccess: Boolean, response: Version?, message: String?) -> (Unit)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object ApiClient { | |
private var retrofit: Retrofit? = null | |
fun api(url: String): Retrofit { | |
retrofit = | |
Retrofit.Builder() | |
.baseUrl(url) | |
.addConverterFactory(GsonConverterFactory.create()) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface ApiService { | |
@GET("(default)/documents/forceupdate") | |
fun getVersion(): Call<Version> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
private val apiClient by lazy { FirebaseClient() } | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
apiClient.getAppVersionFromApi { isSuccess, response, message -> | |
if (isSuccess) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
android { | |
buildFeatures { | |
viewBinding = true | |
} | |
} |
OlderNewer