Skip to content

Commit

Permalink
update kotlin to 1.8.22, replace deprecated kotlin synthetics with je…
Browse files Browse the repository at this point in the history
…tpack viewbindings
  • Loading branch information
mesinger committed Jan 20, 2024
1 parent 2a7823a commit 4ba2cf6
Show file tree
Hide file tree
Showing 16 changed files with 294 additions and 99 deletions.
11 changes: 8 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'
apply plugin: 'witness'
apply from: 'witness.gradle'

android {

buildFeatures {
viewBinding true
dataBinding true
}

defaultConfig {
versionCode 125
versionName "2.2.1"
Expand Down Expand Up @@ -117,8 +122,8 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'androidx.lifecycle:lifecycle-livedata:2.3.1'
implementation 'androidx.lifecycle:lifecycle-common-java8:2.3.1'
implementation 'androidx.room:room-runtime:2.3.0'
kapt 'androidx.room:room-compiler:2.3.0'
implementation 'androidx.room:room-runtime:2.4.1'
kapt 'androidx.room:room-compiler:2.4.1'
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'

implementation 'com.squareup.okhttp3:okhttp:3.12.13'
Expand Down
13 changes: 10 additions & 3 deletions app/src/main/java/de/grobox/transportr/about/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.fragment.app.FragmentPagerAdapter
import com.mikepenz.aboutlibraries.LibsBuilder
import de.grobox.transportr.R
import de.grobox.transportr.TransportrActivity
import kotlinx.android.synthetic.main.activity_about.*
import de.grobox.transportr.databinding.ActivityAboutBinding

class AboutActivity : TransportrActivity() {

Expand All @@ -35,16 +35,23 @@ class AboutActivity : TransportrActivity() {
val TAG : String = AboutActivity::class.java.simpleName
}

private lateinit var binding: ActivityAboutBinding;

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
binding = ActivityAboutBinding.inflate(layoutInflater)
setContentView(binding.root)

setUpCustomToolbar(false)

val pager = binding.pager
pager.adapter = AboutPagerAdapter(supportFragmentManager)

val tabLayout = binding.tabLayout;
tabLayout.setupWithViewPager(pager)
}

private inner class AboutPagerAdapter internal constructor(fm: FragmentManager) : FragmentPagerAdapter(fm) {
private inner class AboutPagerAdapter internal constructor(fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {

override fun getItem(i: Int): Fragment {
return when (i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import de.grobox.transportr.R
import de.grobox.transportr.TransportrActivity
import kotlinx.android.synthetic.main.activity_about.*
import de.grobox.transportr.databinding.ActivityAboutBinding

class ContributorsActivity : TransportrActivity() {

Expand All @@ -34,12 +34,19 @@ class ContributorsActivity : TransportrActivity() {
val TAG : String = ContributorsActivity::class.java.simpleName
}

private lateinit var binding: ActivityAboutBinding

public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_about)
binding = ActivityAboutBinding.inflate(layoutInflater)
setContentView(binding.root)

setUpCustomToolbar(false)

val pager = binding.pager
pager.adapter = ContributorsPagerAdapter(supportFragmentManager)

val tabLayout = binding.tabLayout
tabLayout.setupWithViewPager(pager)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.Date;

import de.grobox.transportr.R;
import de.grobox.transportr.databinding.ListItemDepartureBinding;
import de.schildbach.pte.dto.Departure;

class DepartureAdapter extends RecyclerView.Adapter<DepartureViewHolder> {
Expand Down Expand Up @@ -74,8 +75,8 @@ public boolean areContentsTheSame(Departure d1, Departure d2) {
@NonNull
@Override
public DepartureViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.list_item_departure, viewGroup, false);
return new DepartureViewHolder(v);
ListItemDepartureBinding binding = ListItemDepartureBinding.inflate(LayoutInflater.from(viewGroup.getContext()), viewGroup, false);
return new DepartureViewHolder(binding);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,26 @@ import androidx.cardview.widget.CardView
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import de.grobox.transportr.R
import de.grobox.transportr.databinding.ListItemDepartureBinding
import de.grobox.transportr.ui.LineView
import de.grobox.transportr.utils.DateUtils.formatDelay
import de.grobox.transportr.utils.DateUtils.formatTime
import de.grobox.transportr.utils.DateUtils.formatRelativeTime
import de.grobox.transportr.utils.TransportrUtils.getLocationName
import de.schildbach.pte.dto.Departure
import kotlinx.android.synthetic.main.list_item_departure.view.*
import java.util.*

internal class DepartureViewHolder(v: View) : RecyclerView.ViewHolder(v) {
internal class DepartureViewHolder(binding: ListItemDepartureBinding) : RecyclerView.ViewHolder(binding.root) {

private val card: CardView = v as CardView
private val line: LineView = v.line
private val lineName: TextView = v.lineNameView
private val timeRel: TextView = v.departureTimeRel
private val timeAbs: TextView = v.departureTimeAbs
private val delay: TextView = v.delay
private val destination: TextView = v.destinationView
private val position: TextView = v.positionView
private val message: TextView = v.messageView
private val card: CardView = binding.root
private var line: LineView = binding.line
private val lineName: TextView = binding.lineNameView
private val timeRel: TextView = binding.departureTimeRel
private val timeAbs: TextView = binding.departureTimeAbs
private val delay: TextView = binding.delay
private val destination: TextView = binding.destinationView
private val position: TextView = binding.positionView
private val message: TextView = binding.messageView

fun bind(dep: Departure) {
// times and delay
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import de.grobox.transportr.R
import de.grobox.transportr.databinding.ListItemLegBinding
import de.grobox.transportr.trips.detail.LegViewHolder.LegType
import de.grobox.transportr.trips.detail.LegViewHolder.LegType.*
import de.schildbach.pte.dto.Trip.Leg
Expand All @@ -33,8 +34,8 @@ internal class LegAdapter internal constructor(
private val showLineName: Boolean) : Adapter<LegViewHolder>() {

override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): LegViewHolder {
val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.list_item_leg, viewGroup, false)
return LegViewHolder(v, listener, showLineName)
val binding = ListItemLegBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)
return LegViewHolder(binding, listener, showLineName)
}

override fun onBindViewHolder(ui: LegViewHolder, i: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import androidx.recyclerview.widget.RecyclerView
import com.google.common.base.Strings
import com.google.common.base.Strings.isNullOrEmpty
import de.grobox.transportr.R
import de.grobox.transportr.databinding.ListItemLegBinding
import de.grobox.transportr.trips.BaseViewHolder
import de.grobox.transportr.trips.detail.LegViewHolder.LegType.*
import de.grobox.transportr.ui.LineView
Expand All @@ -43,10 +44,9 @@ import de.schildbach.pte.dto.Line
import de.schildbach.pte.dto.Stop
import de.schildbach.pte.dto.Style.RED
import de.schildbach.pte.dto.Trip.*
import kotlinx.android.synthetic.main.list_item_leg.view.*


internal class LegViewHolder(v: View, private val listener: LegClickListener, private val showLineName: Boolean) : BaseViewHolder(v) {
internal class LegViewHolder(binding: ListItemLegBinding, private val listener: LegClickListener, private val showLineName: Boolean) : BaseViewHolder(binding.root) {

internal enum class LegType {
FIRST, MIDDLE, LAST, FIRST_LAST
Expand All @@ -56,22 +56,22 @@ internal class LegViewHolder(v: View, private val listener: LegClickListener, pr
internal val DEFAULT_LINE_COLOR = RED
}

private val fromCircle: ImageView = v.fromCircle
private val fromLocation: TextView = v.fromLocation
private val fromButton: ImageButton = v.fromButton

private val lineBar: ImageView = v.lineBar
private val lineView: LineView = v.lineView
private val lineDestination: TextView = v.lineDestination
private val message: TextView = v.message
private val duration: TextView = v.duration
private val stopsText: TextView = v.stopsText
private val stopsButton: ImageButton = v.stopsButton
private val stopsList: RecyclerView = v.stopsList

private val toCircle: ImageView = v.toCircle
private val toLocation: TextView = v.toLocation
private val toButton: ImageButton = v.toButton
private val fromCircle: ImageView = binding.fromCircle
private val fromLocation: TextView = binding.fromLocation
private val fromButton: ImageButton = binding.fromButton

private val lineBar: ImageView = binding.lineBar
private val lineView: LineView = binding.lineView
private val lineDestination: TextView = binding.lineDestination
private val message: TextView = binding.message
private val duration: TextView = binding.duration
private val stopsText: TextView = binding.stopsText
private val stopsButton: ImageButton = binding.stopsButton
private val stopsList: RecyclerView = binding.stopsList

private val toCircle: ImageView = binding.toCircle
private val toLocation: TextView = binding.toLocation
private val toButton: ImageButton = binding.toButton

private val adapter = StopAdapter(listener)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import androidx.recyclerview.widget.RecyclerView.Adapter
import android.view.LayoutInflater
import android.view.ViewGroup
import de.grobox.transportr.R
import de.grobox.transportr.databinding.ListItemStopBinding
import de.grobox.transportr.trips.detail.LegViewHolder.Companion.DEFAULT_LINE_COLOR
import de.schildbach.pte.dto.Stop

Expand All @@ -39,8 +40,8 @@ internal class StopAdapter internal constructor(private val listener: LegClickLi
}

override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): StopViewHolder {
val v = LayoutInflater.from(viewGroup.context).inflate(R.layout.list_item_stop, viewGroup, false)
return StopViewHolder(v, listener)
val binding = ListItemStopBinding.inflate(LayoutInflater.from(viewGroup.context), viewGroup, false)
return StopViewHolder(binding, listener)
}

override fun onBindViewHolder(ui: StopViewHolder, i: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,23 @@
package de.grobox.transportr.trips.detail


import android.view.View
import android.view.View.*
import android.widget.ImageButton
import android.widget.ImageView
import android.widget.TextView
import de.grobox.transportr.databinding.ListItemStopBinding
import de.grobox.transportr.trips.BaseViewHolder
import de.grobox.transportr.utils.DateUtils.formatTime
import de.grobox.transportr.utils.TransportrUtils.getLocationName
import de.schildbach.pte.dto.Stop
import kotlinx.android.synthetic.main.list_item_stop.view.*
import java.util.Date


internal class StopViewHolder(v: View, private val listener : LegClickListener) : BaseViewHolder(v) {
internal class StopViewHolder(binding: ListItemStopBinding, private val listener : LegClickListener) : BaseViewHolder(binding.root) {

private val circle: ImageView = v.circle
private val stopLocation: TextView = v.stopLocation
private val stopButton: ImageButton = v.stopButton
private val circle: ImageView = binding.circle
private val stopLocation: TextView = binding.stopLocation
private val stopButton: ImageButton = binding.stopButton

fun bind(stop: Stop, color: Int) {
if (stop.arrivalTime != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,17 @@ import android.os.CountDownTimer
import android.view.*
import android.view.View.GONE
import android.view.View.VISIBLE
import android.widget.TextView
import android.widget.Toast
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat.getColor
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import de.grobox.transportr.R
import de.grobox.transportr.TransportrFragment
import de.grobox.transportr.databinding.FragmentTripDetailBinding
import de.grobox.transportr.trips.detail.TripDetailViewModel.SheetState
import de.grobox.transportr.trips.detail.TripDetailViewModel.SheetState.*
import de.grobox.transportr.trips.detail.TripUtils.getStandardFare
Expand All @@ -43,7 +46,6 @@ import de.grobox.transportr.utils.DateUtils.formatTime
import de.grobox.transportr.utils.DateUtils.formatRelativeTime
import de.grobox.transportr.utils.TransportrUtils.getColorFromAttr
import de.schildbach.pte.dto.Trip
import kotlinx.android.synthetic.main.fragment_trip_detail.*
import javax.inject.Inject

class TripDetailFragment : TransportrFragment(), Toolbar.OnMenuItemClickListener {
Expand All @@ -57,6 +59,23 @@ class TripDetailFragment : TransportrFragment(), Toolbar.OnMenuItemClickListener

private lateinit var viewModel: TripDetailViewModel

private var _binding: FragmentTripDetailBinding? = null
private val binding get() = _binding!!

private lateinit var fromTimeRel: TextView
private lateinit var fromTime: TextView
private lateinit var from: TextView
private lateinit var toTime: TextView
private lateinit var to: TextView
private lateinit var duration: TextView
private lateinit var durationTop: TextView
private lateinit var price: TextView
private lateinit var priceTop: TextView
private lateinit var toolbar: Toolbar
private lateinit var topBar: View
private lateinit var bottomBar: View
private lateinit var list: RecyclerView

private val timeUpdater: CountDownTimer = object : CountDownTimer(Long.MAX_VALUE, 1000 * 30) {
override fun onTick(millisUntilFinished: Long) {
viewModel.getTrip().value?.let {
Expand All @@ -73,7 +92,23 @@ class TripDetailFragment : TransportrFragment(), Toolbar.OnMenuItemClickListener
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.fragment_trip_detail, container, false)
_binding = FragmentTripDetailBinding.inflate(inflater, container, false)

fromTimeRel = binding.fromTimeRel
fromTime = binding.fromTime
from = binding.from
toTime = binding.toTime
to = binding.to
duration = binding.duration
durationTop = binding.durationTop
price = binding.price
priceTop = binding.priceTop
toolbar = binding.toolbar
topBar = binding.topBar
bottomBar = binding.bottomBar
list = binding.list

return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
Expand Down
Loading

0 comments on commit 4ba2cf6

Please sign in to comment.