WearFragment, SkinInterface -> jetpack

This commit is contained in:
Milos Kozak 2021-01-23 22:42:13 +01:00
parent 724b52e929
commit 4e3506007f
3 changed files with 53 additions and 41 deletions

View file

@ -5,21 +5,34 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import dagger.android.support.DaggerFragment
import info.nightscout.androidaps.R
import kotlinx.android.synthetic.main.wear_fragment.*
import info.nightscout.androidaps.databinding.WearFragmentBinding
import javax.inject.Inject
class WearFragment : DaggerFragment() {
@Inject lateinit var wearPlugin: WearPlugin
private var _binding: WearFragmentBinding? = null
// This property is only valid between onCreateView and
// onDestroyView.
private val binding get() = _binding!!
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.wear_fragment, container, false)
savedInstanceState: Bundle?): View {
_binding = WearFragmentBinding.inflate(inflater, container, false)
return binding.root
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
wear_resend.setOnClickListener { wearPlugin.resendDataToWatch() }
wear_opensettings.setOnClickListener { wearPlugin.openSettings() }
binding.resend.setOnClickListener { wearPlugin.resendDataToWatch() }
binding.opensettings.setOnClickListener { wearPlugin.openSettings() }
}
@Synchronized
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

View file

@ -9,9 +9,6 @@ import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.constraintlayout.widget.ConstraintLayout
import info.nightscout.androidaps.R
import kotlinx.android.synthetic.main.overview_fragment_nsclient.view.*
import kotlinx.android.synthetic.main.overview_info_layout.view.*
import kotlinx.android.synthetic.main.overview_statuslights_layout.view.*
interface SkinInterface {
@ -33,52 +30,54 @@ interface SkinInterface {
val landscape = screenHeight < screenWidth
if (landscape) {
val iobLayoutParams = view.overview_iob_llayout.layoutParams as ConstraintLayout.LayoutParams
val iobLayout = view.findViewById<LinearLayout>(R.id.overview_iob_llayout)
val iobLayoutParams = iobLayout.layoutParams as ConstraintLayout.LayoutParams
val timeLayout = view.findViewById<LinearLayout>(R.id.overview_time_llayout)
iobLayoutParams.startToStart = ConstraintLayout.LayoutParams.UNSET
iobLayoutParams.startToEnd = view.overview_time_llayout.id
iobLayoutParams.startToEnd = timeLayout.id
iobLayoutParams.topToBottom = ConstraintLayout.LayoutParams.UNSET
iobLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
val timeLayoutParams = view.overview_time_llayout.layoutParams as ConstraintLayout.LayoutParams
val timeLayoutParams = timeLayout.layoutParams as ConstraintLayout.LayoutParams
timeLayoutParams.endToEnd = ConstraintLayout.LayoutParams.UNSET
timeLayoutParams.endToStart = view.overview_iob_llayout.id
val cobLayoutParams = view.overview_cob_llayout.layoutParams as ConstraintLayout.LayoutParams
timeLayoutParams.endToStart = iobLayout.id
val cobLayoutParams = view.findViewById<LinearLayout>(R.id.overview_cob_llayout).layoutParams as ConstraintLayout.LayoutParams
cobLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
val basalLayoutParams = view.overview_basal_llayout.layoutParams as ConstraintLayout.LayoutParams
val basalLayoutParams = view.findViewById<LinearLayout>(R.id.overview_basal_llayout).layoutParams as ConstraintLayout.LayoutParams
basalLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
val extendedLayoutParams = view.overview_extended_llayout.layoutParams as ConstraintLayout.LayoutParams
val extendedLayoutParams = view.findViewById<LinearLayout>(R.id.overview_extended_llayout).layoutParams as ConstraintLayout.LayoutParams
extendedLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
val asLayoutParams = view.overview_as_llayout.layoutParams as ConstraintLayout.LayoutParams
val asLayoutParams = view.findViewById<LinearLayout>(R.id.overview_as_llayout).layoutParams as ConstraintLayout.LayoutParams
asLayoutParams.topToTop = ConstraintLayout.LayoutParams.PARENT_ID
if (isTablet) {
for (v in listOf<TextView?>(
view.overview_bg,
view.overview_time,
view.overview_timeagoshort,
view.overview_iob,
view.overview_cob,
view.overview_basebasal,
view.overview_extendedbolus,
view.overview_sensitivity
view.findViewById(R.id.overview_bg),
view.findViewById(R.id.overview_time),
view.findViewById(R.id.overview_timeagoshort),
view.findViewById(R.id.overview_iob),
view.findViewById(R.id.overview_cob),
view.findViewById(R.id.overview_basebasal),
view.findViewById(R.id.overview_extendedbolus),
view.findViewById(R.id.overview_sensitivity)
)) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.5f)
for (v in listOf<TextView?>(
view.overview_pump,
view.overview_openaps,
view.overview_uploader,
view.careportal_canulaage,
view.careportal_insulinage,
view.careportal_reservoirlevel,
view.careportal_reservoirlevel,
view.careportal_sensorage,
view.careportal_pbage,
view.careportal_batterylevel
view.findViewById(R.id.overview_pump),
view.findViewById(R.id.overview_openaps),
view.findViewById(R.id.overview_uploader),
view.findViewById(R.id.careportal_canulaage),
view.findViewById(R.id.careportal_insulinage),
view.findViewById(R.id.careportal_reservoirlevel),
view.findViewById(R.id.careportal_reservoirlevel),
view.findViewById(R.id.careportal_sensorage),
view.findViewById(R.id.careportal_pbage),
view.findViewById(R.id.careportal_batterylevel)
)) v?.setTextSize(COMPLEX_UNIT_PX, v.textSize * 1.3f)
view.overview_time_llayout?.orientation = LinearLayout.HORIZONTAL
view.overview_timeagoshort?.setTextSize(COMPLEX_UNIT_PX, view.overview_time.textSize)
timeLayout?.orientation = LinearLayout.HORIZONTAL
view.findViewById<TextView>(R.id.overview_timeagoshort)?.setTextSize(COMPLEX_UNIT_PX, view.findViewById<TextView>(R.id.overview_time).textSize)
view.overview_delta_large?.visibility = View.VISIBLE
view.findViewById<TextView>(R.id.overview_delta_large)?.visibility = View.VISIBLE
} else {
view.overview_delta_large?.visibility = View.GONE
view.findViewById<TextView>(R.id.overview_delta_large)?.visibility = View.GONE
}
}
}

View file

@ -11,7 +11,7 @@
android:orientation="vertical">
<Button
android:id="@+id/wear_resend"
android:id="@+id/resend"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@ -24,7 +24,7 @@
android:textColor="@color/colorTreatmentButton" />
<Button
android:id="@+id/wear_opensettings"
android:id="@+id/opensettings"
style="?android:attr/buttonStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"