Commit 76a56b9c authored by Dayona Joseph's avatar Dayona Joseph
Browse files

Ability to switch between production and test api

parent 7388b862
Pipeline #63729 passed with stage
in 3 minutes and 1 second
......@@ -112,6 +112,22 @@ class MainActivity : AppCompatActivity(), BottomNavigationView.OnNavigationItemS
selectFragment(currentFragmentId, null)
}
fun BASE_URL(): String {
val preferences = PreferenceManager.getDefaultSharedPreferences(mActivity)
var showAllApps:Boolean
if(android.os.Build.TAGS=="test-keys"){
showAllApps = preferences.getBoolean(getString(R.string.build_type), false)
if(showAllApps){
return "https://api.cleanapk.org/v2/"
}
else {
return "https://api.test.cleanapk.org/v2/"
}
}else{
return "https://api.cleanapk.org/v2/"
}
}
private fun initialiseFragments(applicationManager: ApplicationManager) {
homeFragment.initialise(applicationManager)
searchFragment.initialise(applicationManager)
......
......@@ -64,7 +64,7 @@ class PwaInstaller : AppCompatActivity() {
Looper.prepare();//Call looper.prepare()
try {
var uri = PwasBasicData.thisActivity!!.uri
val url = URL(Constants.BASE_URL + "media/" + uri)
val url = URL(mActivity.BASE_URL() + "media/" + uri)
val urlConnection = url.openConnection() as HttpsURLConnection
urlConnection.requestMethod = Constants.REQUEST_METHOD_GET
urlConnection.connectTimeout = Constants.CONNECT_TIMEOUT
......
......@@ -41,7 +41,7 @@ class AllAppsSearchRequest(private val keyword: String, private val page: Int, p
fun request(callback: (Error?, SearchResult?) -> Unit) {
try {
var appType =mActivity.showApplicationTypePreference()
val url = Constants.BASE_URL + "apps?action=search&type=$appType&source=$appType&keyword=${URLEncoder.encode(keyword, "utf-8")}&page=$page&nres=$resultsPerPage"
val url = mActivity.BASE_URL() + "apps?action=search&type=$appType&source=$appType&keyword=${URLEncoder.encode(keyword, "utf-8")}&page=$page&nres=$resultsPerPage"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<SearchResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -19,6 +19,8 @@ package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.data.FullData
import foundation.e.apps.application.model.data.PwaFullData
import foundation.e.apps.utils.Common
......@@ -49,7 +51,7 @@ class AppDetailRequest(private val id: String) {
fun request(callback: (Error?, FullData?) -> Unit) {
try {
val url = Constants.BASE_URL + "apps?action=app_detail&id=$id&architectures=[$sb"
val url = mActivity.BASE_URL() + "apps?action=app_detail&id=$id&architectures=[$sb"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<Result>(urlConnection.inputStream)
urlConnection.disconnect()
......@@ -64,7 +66,7 @@ class AppDetailRequest(private val id: String) {
fun Pwarequest(callback: (Error?, PwaFullData?) -> Unit) {
try {
val url = Constants.BASE_URL + "apps?action=app_detail&id=$id&architectures=[$sb"
val url = mActivity.BASE_URL() + "apps?action=app_detail&id=$id&architectures=[$sb"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val PwaResult = Pwareader.readValue<PwaResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -18,6 +18,8 @@
package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
......@@ -29,7 +31,7 @@ class AppDownloadedRequest(private val id: String) {
fun request() {
try {
val arch = System.getProperty("os.arch")
val url = Constants.BASE_URL + "apps?action=download&app_id=$id&architecture=:$arch"
val url = mActivity.BASE_URL() + "apps?action=download&app_id=$id&architecture=:$arch"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
reader.readValue<Result>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -17,6 +17,8 @@
package foundation.e.apps.api
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Error
......@@ -29,7 +31,7 @@ class AppRequestRequest {
val requestBody = JSONObject()
requestBody.put("package_name", packageName)
try {
val url = Constants.BASE_URL + "app_suggestions"
val url = mActivity.BASE_URL() + "app_suggestions"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_POST)
urlConnection.setRequestProperty("Content-Type", "application/json; charset=UTF-8")
......
......@@ -5,6 +5,7 @@ import com.fasterxml.jackson.annotation.JsonAnySetter
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.Application
import foundation.e.apps.application.model.data.PwasBasicData
import foundation.e.apps.applicationmanager.ApplicationManager
......@@ -23,7 +24,7 @@ class HomePwaRequest {
fun request(callback: (Error?, HomeResult?) -> Unit) {
try {
var appType = MainActivity.mActivity.showApplicationTypePreference()
val url = Constants.BASE_URL + "apps?action=list_home&type=$appType"
val url = mActivity.BASE_URL() + "apps?action=list_home&type=$appType"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<HomeResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -40,7 +40,7 @@ class HomeRequest {
fun request(callback: (Error?, HomeResult?) -> Unit) {
try {
var appType =mActivity.showApplicationTypePreference()
val url = Constants.BASE_URL + "apps?action=list_home&source=$appType&type=$appType"
val url = mActivity.BASE_URL() + "apps?action=list_home&source=$appType&type=$appType"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<HomeResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -40,7 +40,7 @@ class ListApplicationsRequest(private val category: String, private val page: In
try {
var appType = mActivity.showApplicationTypePreference()
val string = URLEncoder.encode(category, "utf-8").toLowerCase()
val url = Constants.BASE_URL + "apps?action=list_apps&category=$string&nres=$resultsPerPage&page=$page&type=$appType"
val url = mActivity.BASE_URL() + "apps?action=list_apps&category=$string&nres=$resultsPerPage&page=$page&type=$appType"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<ListApplicationsResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -33,7 +33,7 @@ class ListCategoriesRequest {
fun request(callback: (Error?, ListCategoriesResult?) -> Unit) {
try {
var appType = mActivity.showApplicationTypePreference()
val url = Constants.BASE_URL + "apps?action=list_cat&type=$appType"
val url = mActivity.BASE_URL() + "apps?action=list_cat&type=$appType"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<ListCategoriesResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -3,6 +3,8 @@ package foundation.e.apps.api
import android.content.Context
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.Application
import foundation.e.apps.application.model.data.PwasBasicData
import foundation.e.apps.applicationmanager.ApplicationManager
......@@ -20,7 +22,7 @@ class ListPwasRequest(private val category: String, private val page: Int, priva
fun request(callback: (Error?, ListPwasResult?) -> Unit) {
try {
val url = Constants.BASE_URL + "apps?action=list_apps&category=${URLEncoder.encode(category, "utf-8")}&nres=$resultsPerPage&page=$page&type=pwa"
val url = mActivity.BASE_URL() + "apps?action=list_apps&category=${URLEncoder.encode(category, "utf-8")}&nres=$resultsPerPage&page=$page&type=pwa"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<ListPwasResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -19,6 +19,8 @@ package foundation.e.apps.api
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.data.BasicData
import foundation.e.apps.utils.Common
import foundation.e.apps.utils.Constants
......@@ -33,7 +35,7 @@ class PackageNameSearchRequest(private val packageName: String) {
fun request(callback: (Error?, SearchResult?) -> Unit) {
try {
val url = Constants.BASE_URL + "apps?action=search&keyword=${URLEncoder.encode(packageName, "utf-8")}&by=package_name"
val url = mActivity.BASE_URL() + "apps?action=search&keyword=${URLEncoder.encode(packageName, "utf-8")}&by=package_name"
val urlConnection = Common.createConnection(url, Constants.REQUEST_METHOD_GET)
val result = reader.readValue<SearchResult>(urlConnection.inputStream)
urlConnection.disconnect()
......
......@@ -21,9 +21,10 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.Application
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Constants.BASE_URL
import foundation.e.apps.utils.Error
import foundation.e.apps.utils.Execute
import foundation.e.apps.utils.ImagesLoader
......@@ -99,7 +100,7 @@ constructor(@param:JsonProperty("_id") val id: String,
private fun loadIconSynced(): Error? {
if (icon == null) {
try {
val url = URL(BASE_URL + "media/" + iconUri)
val url = URL(mActivity.BASE_URL() + "media/" + iconUri)
val urlConnection = url.openConnection() as HttpsURLConnection
urlConnection.requestMethod = Constants.REQUEST_METHOD_GET
urlConnection.connectTimeout = Constants.CONNECT_TIMEOUT
......
......@@ -4,6 +4,8 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.Application
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Error
......@@ -94,7 +96,7 @@ constructor(@param:JsonProperty("_id") val id: String,
internal fun loadIconSynced(): Error? {
if (icon == null) {
try {
val url = URL(Constants.BASE_URL + "media/" + icon_uri)
val url = URL(mActivity.BASE_URL() + "media/" + icon_uri)
val urlConnection = url.openConnection() as HttpsURLConnection
urlConnection.requestMethod = Constants.REQUEST_METHOD_GET
urlConnection.connectTimeout = Constants.CONNECT_TIMEOUT
......
......@@ -4,6 +4,8 @@ import android.graphics.Bitmap
import android.graphics.BitmapFactory
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonProperty
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import foundation.e.apps.application.model.Application
import foundation.e.apps.utils.Constants
import foundation.e.apps.utils.Error
......@@ -69,7 +71,7 @@ class SearchAppsBasicData@JsonCreator
private fun loadIconSynced(): Error? {
if (icon == null) {
try {
val url = URL(Constants.BASE_URL + "media/" + icon_uri)
val url = URL(mActivity.BASE_URL() + "media/" + icon_uri)
val urlConnection = url.openConnection() as HttpsURLConnection
urlConnection.requestMethod = Constants.REQUEST_METHOD_GET
urlConnection.connectTimeout = Constants.CONNECT_TIMEOUT
......
......@@ -95,6 +95,15 @@ class SettingsFragment : PreferenceFragmentCompat() {
backToMainActivity()
true
}
val build_type = preferenceManager.findPreference<Preference>(getString(R.string.build_type)) as CheckBoxPreference
if(android.os.Build.TAGS=="test-keys"){
build_type.isVisible = true
build_type.setOnPreferenceChangeListener{ _, newValue ->
backToMainActivity()
true
}
}
}
......
......@@ -20,6 +20,8 @@ package foundation.e.apps.utils
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.os.AsyncTask
import foundation.e.apps.MainActivity
import foundation.e.apps.MainActivity.Companion.mActivity
import java.net.URL
import java.util.concurrent.BlockingQueue
import java.util.concurrent.LinkedBlockingQueue
......@@ -73,7 +75,7 @@ class ImagesLoader(private val imagesUri: Array<String>) {
override fun doInBackground(vararg params: BlockingQueue<Image>): Any? {
val queue = params[0]
try {
val url = URL(Constants.BASE_URL + "media/" + uri)
val url = URL(mActivity.BASE_URL() + "media/" + uri)
val urlConnection = url.openConnection() as HttpsURLConnection
urlConnection.requestMethod = Constants.REQUEST_METHOD_GET
urlConnection.connectTimeout = Constants.CONNECT_TIMEOUT
......
......@@ -149,6 +149,11 @@
<string name="show_only_pwa_apps_description">Web Apps providing Native App experiences using a browser</string>
<string name="show_only_pwa_apps">Show only PWAs</string>
<!-- Switch to production api-->
<string name="build_type">build_type</string>
<string name="build_type_title">Switch to production api</string>
......
......@@ -18,6 +18,7 @@
-->
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<PreferenceCategory android:title="@string/preference_updates_title">
......@@ -100,6 +101,16 @@
android:title="@string/show_only_pwa_apps" />
</PreferenceCategory>
<Preference
android:selectable="false"
android:layout="@layout/preference_divider"/>
<CheckBoxPreference
android:key="@string/build_type"
android:title="@string/build_type_title"
app:isPreferenceVisible="false"
/>
</PreferenceScreen>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment