Skip to content

Commit

Permalink
sync: more server configurations (fixes #4031) (#4032)
Browse files Browse the repository at this point in the history
Co-authored-by: dogi <[email protected]>
  • Loading branch information
Okuro3499 and dogi authored Aug 6, 2024
1 parent 6e837cb commit e0c01ad
Show file tree
Hide file tree
Showing 14 changed files with 407 additions and 127 deletions.
49 changes: 43 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "org.ole.planet.myplanet"
minSdkVersion 21
targetSdkVersion 34
versionCode 1759
versionName "0.17.59"
versionCode 1760
versionName "0.17.60"
ndkVersion '21.3.6528147'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -75,20 +75,57 @@ android {
def planetLearningPin = project.findProperty('PLANET_LEARNING_PIN') ?: ""
def planetGuatemalaUrl = project.findProperty('PLANET_GUATEMALA_URL') ?: ""
def planetGuatemalaPin = project.findProperty('PLANET_GUATEMALA_PIN') ?: ""
def planetXelaUrl = project.findProperty('PLANET_XELA_URL') ?: ""
def planetXelaPin = project.findProperty('PLANET_XELA_PIN') ?: ""
def planetSanPabloUrl = project.findProperty('PLANET_SANPABLO_URL') ?: ""
def planetSanPabloPin = project.findProperty('PLANET_SANPABLO_PIN') ?: ""
def planetEarthUrl = project.findProperty('PLANET_EARTH_URL') ?: ""
def planetEarthPin = project.findProperty('PLANET_EARTH_PIN') ?: ""
def planetSomaliaUrl = project.findProperty('PLANET_SOMALIA_URL') ?: ""
def planetSomaliaPin = project.findProperty('PLANET_SOMALIA_PIN') ?: ""
def planetViUrl = project.findProperty('PLANET_VI_URL') ?: ""
def planetViPin = project.findProperty('PLANET_VI_PIN') ?: ""
def planetXelaUrl = project.findProperty('PLANET_XELA_URL') ?: ""
def planetXelaPin = project.findProperty('PLANET_XELA_PIN') ?: ""
//def planetUriurUrl = project.findProperty('PLANET_URIUR_URL') ?: ""
//def planetUriurPin = project.findProperty('PLANET_URIUR_PIN') ?: ""
def planetRuiruUrl = project.findProperty('PLANET_RUIRU_URL') ?: ""
def planetRuiruPin = project.findProperty('PLANET_RUIRU_PIN') ?: ""
def planetEmbakasiUrl = project.findProperty('PLANET_EMBAKASI_URL') ?: ""
def planetEmbakasiPin = project.findProperty('PLANET_EMBAKASI_PIN') ?: ""
def planetCambridgeUrl = project.findProperty('PLANET_CAMBRIDGE_URL') ?: ""
def planetCambridgePin = project.findProperty('PLANET_CAMBRIDGE_PIN') ?: ""
//def planetEgdirbmacUrl = project.findProperty('PLANET_EGDIRBMAC_URL') ?: ""
//def planetEgdirbmacPin = project.findProperty('PLANET_EGDIRBMAC_PIN') ?: ""
def planetPalmBayUrl = project.findProperty('PLANET_PALMBAY_URL') ?: ""
def planetPalmBayPin = project.findProperty('PLANET_PALMBAY_PIN') ?: ""


buildTypes.each {
it.buildConfigField 'String', 'PLANET_LEARNING_URL', "\"$planetLearningUrl\""
it.buildConfigField 'String', 'PLANET_LEARNING_PIN', "\"${planetLearningPin}\""
it.buildConfigField 'String', 'PLANET_GUATEMALA_URL', "\"${planetGuatemalaUrl}\""
it.buildConfigField 'String', 'PLANET_GUATEMALA_PIN', "\"${planetGuatemalaPin}\""
it.buildConfigField 'String', 'PLANET_XELA_URL', "\"${planetXelaUrl}\""
it.buildConfigField 'String', 'PLANET_XELA_PIN', "\"${planetXelaPin}\""
it.buildConfigField 'String', 'PLANET_SANPABLO_URL', "\"${planetSanPabloUrl}\""
it.buildConfigField 'String', 'PLANET_SANPABLO_PIN', "\"${planetSanPabloPin}\""
it.buildConfigField 'String', 'PLANET_EARTH_URL', "\"${planetEarthUrl}\""
it.buildConfigField 'String', 'PLANET_EARTH_PIN', "\"${planetEarthPin}\""
it.buildConfigField 'String', 'PLANET_SOMALIA_URL', "\"${planetSomaliaUrl}\""
it.buildConfigField 'String', 'PLANET_SOMALIA_PIN', "\"${planetSomaliaPin}\""
it.buildConfigField 'String', 'PLANET_VI_URL', "\"${planetViUrl}\""
it.buildConfigField 'String', 'PLANET_VI_PIN', "\"${planetViPin}\""
it.buildConfigField 'String', 'PLANET_XELA_URL', "\"${planetXelaUrl}\""
it.buildConfigField 'String', 'PLANET_XELA_PIN', "\"${planetXelaPin}\""
//it.buildConfigField('String', 'PLANET_URIUR_URL', "\"${planetUriurUrl}\"")
//it.buildConfigField('String', 'PLANET_URIUR_PIN', "\"${planetUriurPin}\"")
it.buildConfigField('String', 'PLANET_RUIRU_URL', "\"${planetRuiruUrl}\"")
it.buildConfigField('String', 'PLANET_RUIRU_PIN', "\"${planetRuiruPin}\"")
it.buildConfigField('String', 'PLANET_EMBAKASI_URL', "\"${planetEmbakasiUrl}\"")
it.buildConfigField('String', 'PLANET_EMBAKASI_PIN', "\"${planetEmbakasiPin}\"")
it.buildConfigField('String', 'PLANET_CAMBRIDGE_URL', "\"${planetCambridgeUrl}\"")
it.buildConfigField('String', 'PLANET_CAMBRIDGE_PIN', "\"${planetCambridgePin}\"")
//it.buildConfigField('String', 'PLANET_EGDIRBMAC_URL', "\"${planetEgdirbmacUrl}\"")
//it.buildConfigField('String', 'PLANET_EGDIRBMAC_PIN', "\"${planetEgdirbmacPin}\"")
it.buildConfigField('String', 'PLANET_PALMBAY_URL', "\"${planetPalmBayUrl}\"")
it.buildConfigField('String', 'PLANET_PALMBAY_PIN', "\"${planetPalmBayPin}\"")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.ole.planet.myplanet.model

data class ServerAddressesModel(val name: String, val url: String)
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package org.ole.planet.myplanet.ui.sync

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.google.android.material.button.MaterialButton
import org.ole.planet.myplanet.R
import org.ole.planet.myplanet.model.ServerAddressesModel

class ServerAddressAdapter(
private var serverList: List<ServerAddressesModel>,
private val onItemClick: (ServerAddressesModel) -> Unit,
private val onClearDataDialog: (ServerAddressesModel, Int) -> Unit, // Add callback for clear data dialog
private val urlWithoutProtocol: String? // Pass the urlWithoutProtocol to the adapter
) : RecyclerView.Adapter<ServerAddressAdapter.ViewHolder>() {
private var selectedPosition: Int = -1
private var lastSelectedPosition: Int = -1

fun updateList(newList: List<ServerAddressesModel>) {
serverList = newList
notifyDataSetChanged()
}

fun setSelectedPosition(position: Int) {
lastSelectedPosition = selectedPosition
selectedPosition = position
notifyDataSetChanged()
}

fun revertSelection() {
selectedPosition = lastSelectedPosition
notifyDataSetChanged()
}

fun clearSelection() {
selectedPosition = -1
notifyDataSetChanged()
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val view = LayoutInflater.from(parent.context).inflate(R.layout.item_server_address, parent, false)
return ViewHolder(view)
}

override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val serverAddress = serverList[position]
holder.bind(serverAddress, position == selectedPosition)
holder.itemView.setOnClickListener {
if (!urlWithoutProtocol.isNullOrEmpty() && serverAddress.url.replace(Regex("^https?://"), "") != urlWithoutProtocol) {
onClearDataDialog(serverAddress, position)
} else {
onItemClick(serverAddress)
setSelectedPosition(position)
}
}
}

override fun getItemCount(): Int = serverList.size

inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
private val button: MaterialButton = itemView.findViewById(R.id.btn_server_address)

fun bind(serverAddress: ServerAddressesModel, isSelected: Boolean) {
button.text = serverAddress.name
button.isSelected = isSelected
if (isSelected) {
button.setBackgroundColor(ContextCompat.getColor(button.context, R.color.selected_color))
} else {
button.setBackgroundColor(ContextCompat.getColor(button.context, android.R.color.transparent))
}
}
}
}
Loading

0 comments on commit e0c01ad

Please sign in to comment.