DiaconnG8HistoryActivity spinner replacement

This commit is contained in:
Milos Kozak 2022-03-19 23:08:37 +01:00
parent f3cb252be8
commit 578d4ca674
3 changed files with 34 additions and 37 deletions

View file

@ -4,23 +4,29 @@
<uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" /> <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" /> <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<application> <application>
<activity android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8HistoryActivity" /> <activity
<activity android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8UserOptionsActivity" /> android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8HistoryActivity"
<activity android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8BLEScanActivity"> android:theme="@style/AppTheme" />
<activity
android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8UserOptionsActivity"
android:theme="@style/AppTheme" />
<activity
android:name="info.nightscout.androidaps.diaconn.activities.DiaconnG8BLEScanActivity"
android:theme="@style/AppTheme">
<intent-filter> <intent-filter>
<action android:name="info.nightscout.androidaps.plugins.PumpDiaconnG8.activities.DiaconnG8BLEScanActivity" /> <action android:name="info.nightscout.androidaps.plugins.PumpDiaconnG8.activities.DiaconnG8BLEScanActivity" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
</intent-filter> </intent-filter>
</activity> </activity>
<service android:name="info.nightscout.androidaps.diaconn.service.DiaconnG8Service"
<service
android:name="info.nightscout.androidaps.diaconn.service.DiaconnG8Service"
android:enabled="true" android:enabled="true"
android:exported="false"/> android:exported="false" />
</application> </application>
</manifest> </manifest>

View file

@ -87,11 +87,10 @@ class DiaconnG8HistoryActivity : NoSplashAppCompatActivity() {
typeList.add(TypeList(RecordTypes.RECORD_TYPE_DAILY, rh.gs(R.string.diaconn_g8_history_dailyinsulin))) typeList.add(TypeList(RecordTypes.RECORD_TYPE_DAILY, rh.gs(R.string.diaconn_g8_history_dailyinsulin)))
typeList.add(TypeList(RecordTypes.RECORD_TYPE_REFILL, rh.gs(R.string.diaconn_g8_history_refill))) typeList.add(TypeList(RecordTypes.RECORD_TYPE_REFILL, rh.gs(R.string.diaconn_g8_history_refill)))
typeList.add(TypeList(RecordTypes.RECORD_TYPE_SUSPEND, rh.gs(R.string.diaconn_g8_history_suspend))) typeList.add(TypeList(RecordTypes.RECORD_TYPE_SUSPEND, rh.gs(R.string.diaconn_g8_history_suspend)))
binding.spinner.adapter = ArrayAdapter(this, R.layout.spinner_centered, typeList) binding.typeList.setAdapter(ArrayAdapter(this, R.layout.spinner_centered, typeList))
binding.reload.setOnClickListener { binding.reload.setOnClickListener {
val selected = binding.spinner.selectedItem as TypeList? val selected = typeList.firstOrNull { it.name == binding.typeList.text.toString() } ?: return@setOnClickListener
?: return@setOnClickListener
runOnUiThread { runOnUiThread {
binding.reload.visibility = View.GONE binding.reload.visibility = View.GONE
binding.status.visibility = View.VISIBLE binding.status.visibility = View.VISIBLE
@ -107,16 +106,10 @@ class DiaconnG8HistoryActivity : NoSplashAppCompatActivity() {
} }
}) })
} }
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener { binding.typeList.onItemClickListener = AdapterView.OnItemClickListener { _, _, position, _ ->
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) { val selected = typeList[position]
val selected = typeList[position] showingType = selected.type
swapAdapter(selected.type) swapAdapter(selected.type)
showingType = selected.type
}
override fun onNothingSelected(parent: AdapterView<*>?) {
clearCardView()
}
} }
} }

View file

@ -44,34 +44,32 @@
android:orientation="horizontal" android:orientation="horizontal"
android:padding="5dp" /> android:padding="5dp" />
<LinearLayout <com.google.android.material.textfield.TextInputLayout
android:id="@+id/spinner_layout" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.ExposedDropdownMenu"
android:id="@+id/typeListLayout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_marginEnd="5dp"
android:hint="@string/eventtype"
android:layout_below="@+id/spacer" android:layout_below="@+id/spacer"
android:orientation="horizontal"> app:boxStrokeColor="@color/list_delimiter" >
<TextView <androidx.appcompat.widget.AppCompatAutoCompleteTextView
android:layout_width="wrap_content" android:id="@+id/typeList"
android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="15dp" android:clickable="true"
android:layout_marginEnd="20dp" android:enabled="false"
android:text="@string/eventtype" tools:ignore="KeyboardInaccessibleWidget" />
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner </com.google.android.material.textfield.TextInputLayout>
android:id="@+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp" />
</LinearLayout>
<TextView <TextView
android:id="@+id/status" android:id="@+id/status"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/spinner_layout" android:layout_below="@id/typeListLayout"
android:layout_gravity="center_horizontal" android:layout_gravity="center_horizontal"
android:gravity="center_horizontal" /> android:gravity="center_horizontal" />