extract hardcodings

Signed-off-by: Marcel Hibbe <dev@mhibbe.de>
This commit is contained in:
Marcel Hibbe 2021-06-07 11:32:56 +02:00 committed by Andy Scherzinger
parent 49b2455a23
commit ab63a1970b
No known key found for this signature in database
GPG Key ID: 6CADC7E3523C308B
6 changed files with 34 additions and 31 deletions

View File

@ -45,9 +45,6 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
private val TAG = "LocationMessageViewHolder" private val TAG = "LocationMessageViewHolder"
var mapProviderUrl: String = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
var mapProviderAttribution: String = "OpenStreetMap contributors"
var locationLon: String? = "" var locationLon: String? = ""
var locationLat: String? = "" var locationLat: String? = ""
var locationName: String? = "" var locationName: String? = ""
@ -285,8 +282,9 @@ class IncomingLocationMessageViewHolder(incomingView: View) : MessageHolders
} }
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html") val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(mapProviderUrl)) urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(context!!.getString(R.string.osm_tile_server_url)))
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(mapProviderAttribution)) urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(context!!.getString(R.string
.osm_tile_server_attributation)))
urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat)) urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat))
urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon)) urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon))
urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName)) urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName))

View File

@ -43,9 +43,6 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
private val TAG = "LocationMessageViewHolder" private val TAG = "LocationMessageViewHolder"
var mapProviderUrl: String = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
var mapProviderAttribution: String = "OpenStreetMap contributors"
var locationLon: String? = "" var locationLon: String? = ""
var locationLat: String? = "" var locationLat: String? = ""
var locationName: String? = "" var locationName: String? = ""
@ -243,8 +240,9 @@ class OutcomingLocationMessageViewHolder(incomingView: View) : MessageHolders
} }
val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html") val urlStringBuffer = StringBuffer("file:///android_asset/leafletMapMessagePreview.html")
urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(mapProviderUrl)) urlStringBuffer.append("?mapProviderUrl=" + URLEncoder.encode(context!!.getString(R.string.osm_tile_server_url)))
urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(mapProviderAttribution)) urlStringBuffer.append("&mapProviderAttribution=" + URLEncoder.encode(context!!.getString(R.string
.osm_tile_server_attributation)))
urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat)) urlStringBuffer.append("&locationLat=" + URLEncoder.encode(locationLat))
urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon)) urlStringBuffer.append("&locationLon=" + URLEncoder.encode(locationLon))
urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName)) urlStringBuffer.append("&locationName=" + URLEncoder.encode(locationName))

View File

@ -16,6 +16,7 @@ import android.view.ViewGroup
import android.view.inputmethod.EditorInfo import android.view.inputmethod.EditorInfo
import android.widget.AdapterView import android.widget.AdapterView
import android.widget.ListView import android.widget.ListView
import android.widget.Toast
import androidx.appcompat.widget.SearchView import androidx.appcompat.widget.SearchView
import androidx.core.view.MenuItemCompat import androidx.core.view.MenuItemCompat
import androidx.preference.PreferenceManager import androidx.preference.PreferenceManager
@ -111,7 +112,6 @@ class GeocodingController(args: Bundle) : BaseController(args), SearchView.OnQue
geocodingResultListView?.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id -> geocodingResultListView?.onItemClickListener = AdapterView.OnItemClickListener { parent, view, position, id ->
val address: Address = adapter.getItem(position) as Address val address: Address = adapter.getItem(position) as Address
val listener: GeocodingResultListener? = targetController as GeocodingResultListener? val listener: GeocodingResultListener? = targetController as GeocodingResultListener?
listener?.receiveChosenGeocodingResult(address.latitude, address.longitude, address.displayName) listener?.receiveChosenGeocodingResult(address.latitude, address.longitude, address.displayName)
router.popCurrentController() router.popCurrentController()
@ -133,7 +133,6 @@ class GeocodingController(args: Bundle) : BaseController(args), SearchView.OnQue
super.onPrepareOptionsMenu(menu) super.onPrepareOptionsMenu(menu)
hideSearchBar() hideSearchBar()
actionBar.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent))) actionBar.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent)))
actionBar.title = "Share location"
} }
override fun onQueryTextSubmit(query: String?): Boolean { override fun onQueryTextSubmit(query: String?): Boolean {
@ -152,18 +151,17 @@ class GeocodingController(args: Bundle) : BaseController(args), SearchView.OnQue
val searchManager = activity!!.getSystemService(Context.SEARCH_SERVICE) as SearchManager val searchManager = activity!!.getSystemService(Context.SEARCH_SERVICE) as SearchManager
if (searchItem != null) { if (searchItem != null) {
searchView = MenuItemCompat.getActionView(searchItem) as SearchView searchView = MenuItemCompat.getActionView(searchItem) as SearchView
searchView?.setMaxWidth(Int.MAX_VALUE) searchView?.maxWidth = Int.MAX_VALUE
searchView?.setInputType(InputType.TYPE_TEXT_VARIATION_FILTER) searchView?.inputType = InputType.TYPE_TEXT_VARIATION_FILTER
var imeOptions = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN var imeOptions = EditorInfo.IME_ACTION_DONE or EditorInfo.IME_FLAG_NO_FULLSCREEN
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences!!.isKeyboardIncognito) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && appPreferences!!.isKeyboardIncognito) {
imeOptions = imeOptions or EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING imeOptions = imeOptions or EditorInfo.IME_FLAG_NO_PERSONALIZED_LEARNING
} }
searchView?.setImeOptions(imeOptions) searchView?.imeOptions = imeOptions
searchView?.setQueryHint(resources!!.getString(R.string.nc_search)) searchView?.queryHint = resources!!.getString(R.string.nc_search)
searchView?.setSearchableInfo(searchManager.getSearchableInfo(activity!!.componentName)) searchView?.setSearchableInfo(searchManager.getSearchableInfo(activity!!.componentName))
searchView?.setOnQueryTextListener(this) searchView?.setOnQueryTextListener(this)
searchItem?.setOnActionExpandListener(object : MenuItem.OnActionExpandListener { searchItem?.setOnActionExpandListener(object : MenuItem.OnActionExpandListener {
override fun onMenuItemActionExpand(menuItem: MenuItem): Boolean { override fun onMenuItemActionExpand(menuItem: MenuItem): Boolean {
return true return true
@ -183,8 +181,8 @@ class GeocodingController(args: Bundle) : BaseController(args), SearchView.OnQue
registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443)) registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443))
val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry) val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry)
val httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val httpClient: HttpClient = DefaultHttpClient(connexionManager, null)
val baseUrl = "https://nominatim.openstreetmap.org/" val baseUrl = context!!.getString(R.string.osm_geocoder_url)
val email = "android@nextcloud.com" val email = context!!.getString(R.string.osm_geocoder_contact)
nominatimClient = JsonNominatimClient(baseUrl, httpClient, email) nominatimClient = JsonNominatimClient(baseUrl, httpClient, email)
} }
@ -206,6 +204,7 @@ class GeocodingController(args: Bundle) : BaseController(args), SearchView.OnQue
} }
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Failed to get geocoded addresses", e) Log.e(TAG, "Failed to get geocoded addresses", e)
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
} }
updateResultsOnMainThread(results) updateResultsOnMainThread(results)
} }

View File

@ -146,10 +146,9 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
override fun onPrepareOptionsMenu(menu: Menu) { override fun onPrepareOptionsMenu(menu: Menu) {
super.onPrepareOptionsMenu(menu) super.onPrepareOptionsMenu(menu)
Log.d(TAG, "onPrepareOptionsMenu")
hideSearchBar() hideSearchBar()
actionBar.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent))) actionBar.setIcon(ColorDrawable(resources!!.getColor(android.R.color.transparent)))
actionBar.title = "Share location" actionBar.title = context!!.getString(R.string.nc_share_location)
} }
override fun onViewBound(view: View) { override fun onViewBound(view: View) {
@ -163,7 +162,7 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
placeName?.text.toString() placeName?.text.toString()
) )
} else { } else {
Log.d(TAG, "readyToShareLocation was false while user tried to share location.") Log.w(TAG, "readyToShareLocation was false while user tried to share location.")
} }
} }
} }
@ -181,9 +180,7 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
} }
searchView?.setImeOptions(imeOptions) searchView?.setImeOptions(imeOptions)
searchView?.setQueryHint(resources!!.getString(R.string.nc_search)) searchView?.setQueryHint(resources!!.getString(R.string.nc_search))
if (searchManager != null) { searchView?.setSearchableInfo(searchManager.getSearchableInfo(activity!!.componentName))
searchView?.setSearchableInfo(searchManager.getSearchableInfo(activity!!.componentName))
}
searchView?.setOnQueryTextListener(this) searchView?.setOnQueryTextListener(this)
} }
} }
@ -286,15 +283,15 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
private fun setLocationDescription(isGpsLocation: Boolean, isGeocodedResult: Boolean) { private fun setLocationDescription(isGpsLocation: Boolean, isGeocodedResult: Boolean) {
when { when {
isGpsLocation -> { isGpsLocation -> {
shareLocationDescription?.text = "Share current location" shareLocationDescription?.text = context!!.getText(R.string.nc_share_current_location)
placeName?.text = "" placeName?.text = ""
} }
isGeocodedResult -> { isGeocodedResult -> {
shareLocationDescription?.text = "Share this location" shareLocationDescription?.text = context!!.getText(R.string.nc_share_this_location)
placeName?.text = geocodedName placeName?.text = geocodedName
} }
else -> { else -> {
shareLocationDescription?.text = "Share this location" shareLocationDescription?.text = context!!.getText(R.string.nc_share_this_location)
placeName?.text = "" placeName?.text = ""
} }
} }
@ -379,7 +376,7 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (requestCode == REQUEST_PERMISSIONS_REQUEST_CODE && grantResults.size > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
initMap() initMap()
} else { } else {
Toast.makeText(context, "location permission required!", Toast.LENGTH_LONG).show() Toast.makeText(context, context!!.getString(R.string.nc_location_permission_required), Toast.LENGTH_LONG).show()
} }
} }
@ -395,8 +392,8 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443)) registry.register(Scheme("https", SSLSocketFactory.getSocketFactory(), 443))
val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry) val connexionManager: ClientConnectionManager = SingleClientConnManager(null, registry)
val httpClient: HttpClient = DefaultHttpClient(connexionManager, null) val httpClient: HttpClient = DefaultHttpClient(connexionManager, null)
val baseUrl = "https://nominatim.openstreetmap.org/" val baseUrl = context!!.getString(R.string.osm_geocoder_url)
val email = "android@nextcloud.com" val email = context!!.getString(R.string.osm_geocoder_contact)
nominatimClient = JsonNominatimClient(baseUrl, httpClient, email) nominatimClient = JsonNominatimClient(baseUrl, httpClient, email)
} }
@ -413,6 +410,7 @@ class LocationPickerController(args: Bundle) : BaseController(args), SearchView.
address = nominatimClient!!.getAddress(lon, lat) address = nominatimClient!!.getAddress(lon, lat)
} catch (e: Exception) { } catch (e: Exception) {
Log.e(TAG, "Failed to get geocoded addresses", e) Log.e(TAG, "Failed to get geocoded addresses", e)
Toast.makeText(context, R.string.nc_common_error_sorry, Toast.LENGTH_LONG).show()
} }
updateResultOnMainThread(lat, lon, address?.displayName) updateResultOnMainThread(lat, lon, address?.displayName)
} }

View File

@ -54,4 +54,11 @@
<string name="google_app_id" translatable="false">1:829118773643:android:54b65087c544d819</string> <string name="google_app_id" translatable="false">1:829118773643:android:54b65087c544d819</string>
<string name="google_crash_reporting_api_key" translatable="false">AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s</string> <string name="google_crash_reporting_api_key" translatable="false">AIzaSyAWIyOcLafaFp8PFL61h64cy1NNZW2cU_s</string>
<string name="google_storage_bucket" translatable="false">nextcloud-a7dea.appspot.com</string> <string name="google_storage_bucket" translatable="false">nextcloud-a7dea.appspot.com</string>
<!-- Map and Geocoding -->
<string name="osm_tile_server_url" translatable="false">https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png</string>
<string name="osm_tile_server_attributation" translatable="false">OpenStreetMap contributors</string>
<string name="osm_geocoder_url" translatable="false">https://nominatim.openstreetmap.org/</string>
<string name="osm_geocoder_contact" translatable="false">android@nextcloud.com</string>
</resources> </resources>

View File

@ -375,6 +375,9 @@
<!-- location sharing --> <!-- location sharing -->
<string name="nc_share_location">Share location</string> <string name="nc_share_location">Share location</string>
<string name="nc_location_permission_required">location permission is required</string>
<string name="nc_share_current_location">Share current location</string>
<string name="nc_share_this_location">Share this location</string>
<!-- Phonebook Integration --> <!-- Phonebook Integration -->
<string name="nc_settings_phone_book_integration_key" translatable="false">phone_book_integration</string> <string name="nc_settings_phone_book_integration_key" translatable="false">phone_book_integration</string>