Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update kotlin to 1.8.22, replace deprecated kotlin synthetics with jetpack bindings #902

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions app/src/main/java/de/grobox/transportr/AppComponent.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import de.grobox.transportr.trips.detail.TripMapFragment;
import de.grobox.transportr.trips.search.DirectionsActivity;
import de.grobox.transportr.trips.search.DirectionsFragment;
import de.grobox.transportr.trips.search.ProductDialogFragment;
import de.grobox.transportr.trips.search.TripsFragment;

@Singleton
Expand All @@ -56,5 +57,6 @@ public interface AppComponent {
void inject(SettingsFragment fragment);
void inject(HomePickerDialogFragment fragment);
void inject(WorkPickerDialogFragment fragment);
void inject(ProductDialogFragment fragment);

}
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
16 changes: 12 additions & 4 deletions app/src/main/java/de/grobox/transportr/about/AboutFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ import android.widget.Button
import android.widget.TextView
import de.grobox.transportr.R
import de.grobox.transportr.TransportrFragment
import de.grobox.transportr.databinding.FragmentAboutBinding


class AboutFragment : TransportrFragment() {

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

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_about, container, false)
_binding = FragmentAboutBinding.inflate(inflater, container, false)

// add app name and version
val versionName = try {
Expand All @@ -44,17 +48,21 @@ class AboutFragment : TransportrFragment() {
} catch (e: NameNotFoundException) {
"?.?"
}
val appNameVersion = v.findViewById<TextView>(R.id.appNameVersion)
val appNameVersion = binding.appNameVersion
appNameVersion.text = "${getString(R.string.app_name)} $versionName"

// website button
val websiteButton = v.findViewById<Button>(R.id.websiteButton)
val websiteButton = binding.websiteButton
websiteButton.setOnClickListener {
val launchBrowser = Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.website) + getString(R.string.website_source_app)))
startActivity(launchBrowser)
}

return v
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,47 @@ import de.grobox.transportr.R
import de.grobox.transportr.TransportrFragment
import de.grobox.transportr.about.ContributorAdapter.ContributorViewHolder
import de.grobox.transportr.about.ContributorGroupAdapter.ContributorGroupViewHolder
import de.grobox.transportr.databinding.FragmentContributorsBinding
import de.grobox.transportr.databinding.FragmentTranslatorsBinding

class ContributorFragment : TransportrFragment() {
private var _binding: FragmentContributorsBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_contributors, container, false)
_binding = FragmentContributorsBinding.inflate(inflater, container, false)

val list = v.findViewById<RecyclerView>(R.id.list)
val list = binding.list
list.layoutManager = LinearLayoutManager(context)
list.adapter = ContributorGroupAdapter(CONTRIBUTORS)

return v
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}

class TranslatorsFragment : TransportrFragment() {
private var _binding: FragmentTranslatorsBinding? = null
private val binding get() = _binding!!

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_translators, container, false)
_binding = FragmentTranslatorsBinding.inflate(inflater, container, false)

val list = v.findViewById<RecyclerView>(R.id.list)
val list = binding.list
list.layoutManager = LinearLayoutManager(context)
list.adapter = ContributorGroupAdapter(LANGUAGES)

return v
return binding.root
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}


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 @@ -51,6 +51,7 @@

import de.grobox.transportr.R;
import de.grobox.transportr.TransportrActivity;
import de.grobox.transportr.databinding.ActivityDeparturesBinding;
import de.grobox.transportr.locations.WrapLocation;
import de.grobox.transportr.ui.LceAnimator;
import de.grobox.transportr.ui.TimeDateFragment;
Expand All @@ -77,6 +78,7 @@ public class DeparturesActivity extends TransportrActivity

private enum SearchState {INITIAL, TOP, BOTTOM}

private ActivityDeparturesBinding binding;
private ProgressBar progressBar;
private View errorLayout;
private TextView errorText;
Expand All @@ -101,16 +103,17 @@ public void onFinish() {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityDeparturesBinding.inflate(getLayoutInflater());

Intent intent = getIntent();
location = (WrapLocation) intent.getSerializableExtra(WRAP_LOCATION);
if (location == null || location.getLocation() == null)
throw new IllegalArgumentException("No Location");

setContentView(R.layout.activity_departures);
setContentView(binding.getRoot());

// Toolbar
Toolbar toolbar = findViewById(R.id.toolbar);
Toolbar toolbar = binding.toolbar;
setSupportActionBar(toolbar);
toolbar.setSubtitle(location.getName());
ActionBar actionBar = getSupportActionBar();
Expand All @@ -120,7 +123,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
}

// Swipe to Refresh
swipe = findViewById(R.id.swipe);
swipe = binding.swipe;
swipe.setColorSchemeResources(R.color.accent);
swipe.setDirection(SwipyRefreshLayoutDirection.BOTH);
swipe.setDistanceToTriggerSync(getDragDistance(this));
Expand All @@ -129,7 +132,7 @@ public void onCreate(@Nullable Bundle savedInstanceState) {

// Departures List
adapter = new DepartureAdapter();
list = findViewById(R.id.list);
list = binding.list;
list.setVisibility(INVISIBLE);
list.setAdapter(adapter);
list.setLayoutManager(new LinearLayoutManager(this));
Expand All @@ -139,8 +142,8 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
Loader<QueryDeparturesResult> loader = getSupportLoaderManager().initLoader(LOADER_DEPARTURES, args, this);

// Progress Bar and Error View
progressBar = findViewById(R.id.progressBar);
errorLayout = findViewById(R.id.errorLayout);
progressBar = binding.progressBar;
errorLayout = binding.errorLayout;
errorText = errorLayout.findViewById(R.id.errorText);
errorLayout.findViewById(R.id.errorButton).setOnClickListener(view -> {
LceAnimator.showLoading(progressBar, list, errorLayout);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import de.grobox.transportr.AppComponent
import de.grobox.transportr.R
import de.grobox.transportr.TransportrApplication
import de.grobox.transportr.data.locations.FavoriteLocation.FavLocationType
import de.grobox.transportr.databinding.FragmentSpecialLocationBinding
import de.grobox.transportr.favorites.trips.FavoriteTripListener
import de.grobox.transportr.locations.LocationView
import de.grobox.transportr.locations.LocationsViewModel
Expand All @@ -54,6 +55,9 @@ abstract class SpecialLocationFragment : DialogFragment(), LocationView.Location
protected lateinit var viewModel: LocationsViewModel
var listener: FavoriteTripListener? = null

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

private lateinit var loc: LocationView

@get:StringRes
Expand All @@ -72,10 +76,11 @@ abstract class SpecialLocationFragment : DialogFragment(), LocationView.Location
protected abstract fun viewModel(): LocationsViewModel // a method to init when activity has been created

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val v = inflater.inflate(R.layout.fragment_special_location, container)
_binding = FragmentSpecialLocationBinding.inflate(inflater, container, false)
val v = binding.root

// Initialize LocationView
loc = v.findViewById(R.id.location_input)
loc = binding.locationInput
loc.setHint(hint)
loc.setLocationViewListener(this)

Expand Down Expand Up @@ -121,4 +126,8 @@ abstract class SpecialLocationFragment : DialogFragment(), LocationView.Location

override fun onLocationCleared(type: FavLocationType) {}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
Loading
Loading