parent
6d4f23517c
commit
2b9926767b
14 changed files with 310 additions and 42 deletions
@ -0,0 +1,40 @@ |
|||||||
|
package com.project.survey.ui.instrument.coordinatesystem |
||||||
|
|
||||||
|
import android.content.Context |
||||||
|
import android.view.ViewGroup |
||||||
|
import com.bingce.coordlib.model.CoordinateSystem |
||||||
|
import com.chad.library.adapter4.BaseQuickAdapter |
||||||
|
import com.chad.library.adapter4.viewholder.QuickViewHolder |
||||||
|
import com.project.survey.R |
||||||
|
import com.project.survey.extend.setOnClickNoRepeatListener |
||||||
|
|
||||||
|
class CoordinateSystemAdapter : BaseQuickAdapter<CoordinateSystem, QuickViewHolder>() { |
||||||
|
|
||||||
|
private var selectedPosition = -1 |
||||||
|
private var lastPosition = -1 |
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: QuickViewHolder, position: Int, item: CoordinateSystem?) { |
||||||
|
if (item == null) return |
||||||
|
|
||||||
|
holder.setText(R.id.tvName, item.name) |
||||||
|
.setText(R.id.tvDescribe, item.country + " " + item.projection.name) |
||||||
|
holder.itemView.isSelected = position == selectedPosition |
||||||
|
|
||||||
|
holder.itemView.setOnClickNoRepeatListener { |
||||||
|
holder.itemView.isSelected = true |
||||||
|
lastPosition = selectedPosition |
||||||
|
selectedPosition = position |
||||||
|
notifyItemChanged(lastPosition) |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
fun getSelectedPosition(): Int = selectedPosition |
||||||
|
|
||||||
|
override fun onCreateViewHolder( |
||||||
|
context: Context, |
||||||
|
parent: ViewGroup, |
||||||
|
viewType: Int |
||||||
|
): QuickViewHolder { |
||||||
|
return QuickViewHolder(R.layout.rv_item_coordinate_system, parent) |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,74 @@ |
|||||||
|
package com.project.survey.ui.instrument.coordinatesystem |
||||||
|
|
||||||
|
import android.R |
||||||
|
import android.os.Bundle |
||||||
|
import android.view.MenuItem |
||||||
|
import androidx.activity.viewModels |
||||||
|
import com.bingce.coordlib.util.CoordinateSystemUtil |
||||||
|
import com.project.survey.constants.EventConstants |
||||||
|
import com.project.survey.databinding.ActivityCoordinateSystemListBinding |
||||||
|
import com.project.survey.extend.setOnClickNoRepeatListener |
||||||
|
import com.project.survey.extend.toast |
||||||
|
import com.project.survey.logic.event.Message |
||||||
|
import com.project.survey.logic.viewmodel.CoordinateSystemViewModel |
||||||
|
import com.project.survey.util.ActivityNavUtil |
||||||
|
import org.polaric.colorful.ColorfulActivity |
||||||
|
|
||||||
|
/** |
||||||
|
* 坐标系统列表 |
||||||
|
*/ |
||||||
|
class CoordinateSystemListActivity : ColorfulActivity() { |
||||||
|
|
||||||
|
private lateinit var binding: ActivityCoordinateSystemListBinding |
||||||
|
private val adapter by lazy { CoordinateSystemAdapter() } |
||||||
|
private val viewModel: CoordinateSystemViewModel by viewModels() |
||||||
|
|
||||||
|
override fun onCreate(savedInstanceState: Bundle?) { |
||||||
|
super.onCreate(savedInstanceState) |
||||||
|
binding = ActivityCoordinateSystemListBinding.inflate(layoutInflater, null, false) |
||||||
|
setContentView(binding.root) |
||||||
|
setSupportActionBar(binding.toolbar) |
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true) |
||||||
|
|
||||||
|
binding.recyclerView.itemAnimator = null |
||||||
|
binding.recyclerView.adapter = adapter |
||||||
|
|
||||||
|
viewModel.downloadCoordinateSystemResponse.observe(this) { |
||||||
|
adapter.submitList(it.map { data -> |
||||||
|
CoordinateSystemUtil.importCoordSysString(data.values.ZBZHCS_ZHCS) |
||||||
|
}) |
||||||
|
} |
||||||
|
viewModel.downloadCoordinateSystem() |
||||||
|
|
||||||
|
// 选择 |
||||||
|
binding.btnChoose.setOnClickNoRepeatListener { |
||||||
|
if (adapter.getSelectedPosition() == -1) { |
||||||
|
toast("请选择坐标系统") |
||||||
|
return@setOnClickNoRepeatListener |
||||||
|
} |
||||||
|
if (adapter.getSelectedPosition() < adapter.itemCount) { |
||||||
|
adapter.getItem(adapter.getSelectedPosition())?.let { item -> |
||||||
|
viewModel.msgEvent.postValue( |
||||||
|
Message(EventConstants.CHOOSE_COORDINATE_SYSTEM, obj = item) |
||||||
|
) |
||||||
|
finish() |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
override fun onOptionsItemSelected(item: MenuItem): Boolean { |
||||||
|
if (R.id.home == item.itemId) { |
||||||
|
onBackPressed() |
||||||
|
return true |
||||||
|
} |
||||||
|
return super.onOptionsItemSelected(item) |
||||||
|
} |
||||||
|
|
||||||
|
companion object { |
||||||
|
@JvmStatic |
||||||
|
fun start() { |
||||||
|
ActivityNavUtil.startActivity<CoordinateSystemListActivity> {} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,15 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<selector xmlns:android="http://schemas.android.com/apk/res/android"> |
||||||
|
|
||||||
|
<item android:state_selected="true"> |
||||||
|
<shape> |
||||||
|
<solid android:color="#33396BD0" /> |
||||||
|
</shape> |
||||||
|
</item> |
||||||
|
<item> |
||||||
|
<shape> |
||||||
|
<solid android:color="@color/white" /> |
||||||
|
</shape> |
||||||
|
</item> |
||||||
|
|
||||||
|
</selector> |
@ -0,0 +1,34 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="match_parent" |
||||||
|
android:orientation="vertical"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.Toolbar |
||||||
|
android:id="@+id/toolbar" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="?android:attr/actionBarSize" |
||||||
|
android:background="?colorPrimary" |
||||||
|
android:minHeight="?android:attr/actionBarSize" |
||||||
|
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" |
||||||
|
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" /> |
||||||
|
|
||||||
|
<androidx.recyclerview.widget.RecyclerView |
||||||
|
android:id="@+id/recyclerView" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="0dp" |
||||||
|
android:layout_weight="1" |
||||||
|
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" |
||||||
|
tools:itemCount="2" |
||||||
|
tools:listitem="@layout/rv_item_coordinate_system" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatButton |
||||||
|
android:id="@+id/btnChoose" |
||||||
|
style="@style/Widget.AppCompat.Button.Colored" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:text="@string/choose" /> |
||||||
|
|
||||||
|
</LinearLayout> |
@ -0,0 +1,35 @@ |
|||||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" |
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto" |
||||||
|
xmlns:tools="http://schemas.android.com/tools" |
||||||
|
android:layout_width="match_parent" |
||||||
|
android:layout_height="@dimen/sw_60dp" |
||||||
|
android:layout_marginBottom="@dimen/sw_1dp" |
||||||
|
android:background="@drawable/bg_rv_item_coordinate_system" |
||||||
|
android:paddingHorizontal="@dimen/sw_10dp"> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/tvName" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:textColor="@color/text_color_1" |
||||||
|
android:textSize="@dimen/sw_14sp" |
||||||
|
android:textStyle="bold" |
||||||
|
app:layout_constraintBottom_toTopOf="@id/tvDescribe" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toTopOf="parent" |
||||||
|
app:layout_constraintVertical_chainStyle="packed" |
||||||
|
tools:text="000" /> |
||||||
|
|
||||||
|
<androidx.appcompat.widget.AppCompatTextView |
||||||
|
android:id="@+id/tvDescribe" |
||||||
|
android:layout_width="wrap_content" |
||||||
|
android:layout_height="wrap_content" |
||||||
|
android:layout_marginTop="@dimen/sw_5dp" |
||||||
|
android:textColor="@color/text_color_404145" |
||||||
|
android:textSize="@dimen/sw_12sp" |
||||||
|
app:layout_constraintBottom_toBottomOf="parent" |
||||||
|
app:layout_constraintStart_toStartOf="parent" |
||||||
|
app:layout_constraintTop_toBottomOf="@id/tvName" |
||||||
|
tools:text="000" /> |
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout> |
Loading…
Reference in new issue