Bimba.git

commit b04a327a35089710cfbfaab4a470d4c73e6a1a44

Author: Adam Pioterek <adam.pioterek@protonmail.ch>

new SDK & prepare for favourite based StopActivity

%!v(PANIC=String method: strings: negative Repeat count)


diff --git a/.idea/misc.xml b/.idea/misc.xml
index ba7052b8197ddf8ba8756022d905d03055c7ad60..635999df1e86791ad3787e455b4524e4d8879b93 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -24,7 +24,7 @@         
       </value>
     </option>
   </component>
-  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
+  <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
     <output url="file://$PROJECT_DIR$/build/classes" />
   </component>
   <component name="ProjectType">




diff --git a/app/build.gradle b/app/build.gradle
index 63a9f4b8168d84fe249a5c20a900476847cf7ff5..23ffef9efa24de9b56650df82605fe7da4d4959e 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -2,12 +2,12 @@ apply plugin: 'com.android.application'
 apply plugin: 'kotlin-android'
 
 android {
-    compileSdkVersion 25
-    buildToolsVersion "25.0.3"
+    compileSdkVersion 26
+    buildToolsVersion "26.0.2"
     defaultConfig {
         applicationId "ml.adamsprogs.bimba"
         minSdkVersion 19
-        targetSdkVersion 25
+        targetSdkVersion 26
         versionCode 5
         versionName "1.1.1"
         testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
@@ -26,10 +26,10 @@     implementation fileTree(dir: 'libs', include: ['*.jar'])
     androidTestImplementation('com.android.support.test.espresso:espresso-core:2.2.2', {
         exclude group: 'com.android.support', module: 'support-annotations'
     })
-    implementation 'com.android.support:appcompat-v7:25.3.1'
-    implementation 'com.android.support:cardview-v7:25.3.1'
-    implementation 'com.android.support:design:25.3.1'
-    implementation 'com.android.support:support-vector-drawable:25.3.1'
+    implementation 'com.android.support:appcompat-v7:26.1.0'
+    implementation 'com.android.support:cardview-v7:26.1.0'
+    implementation 'com.android.support:design:26.1.0'
+    implementation 'com.android.support:support-vector-drawable:26.1.0'
     testImplementation 'junit:junit:4.12'
     implementation 'com.android.support.constraint:constraint-layout:1.0.2'
     implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"




diff --git a/app/src/main/java/ml/adamsprogs/bimba/TimetableDownloader.kt b/app/src/main/java/ml/adamsprogs/bimba/TimetableDownloader.kt
index 18dc9b9000c129195152a33b65473644bf4b402c..f49ae019176280aa383a4de8a6b17fd249dd1f60 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/TimetableDownloader.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/TimetableDownloader.kt
@@ -94,6 +94,7 @@         sendBroadcast(broadcastIntent)
     }
 
     private fun notify(progress: Int) {
+        //todo create channel
         val builder = NotificationCompat.Builder(this)
                 .setSmallIcon(R.drawable.ic_download)
                 .setContentTitle(getString(R.string.timetable_downloading))




diff --git a/app/src/main/java/ml/adamsprogs/bimba/VmClient.kt b/app/src/main/java/ml/adamsprogs/bimba/VmClient.kt
index 65af3a69ec89aae991893b260629b5fe9b5b54dc..28072c8281dfc11d353fdc143d7c21b7341256bb 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/VmClient.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/VmClient.kt
@@ -2,7 +2,6 @@ package ml.adamsprogs.bimba
 
 import android.app.IntentService
 import android.content.Intent
-import android.util.Log
 import ml.adamsprogs.bimba.models.*
 import okhttp3.*
 import com.google.gson.Gson




diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
index dfa9714fe459b1ee5143d595d8b8a54492d496be..1f2257b90b00f26960d288968e9383a2ae580418 100644
--- a/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
+++ b/app/src/main/java/ml/adamsprogs/bimba/activities/DashActivity.kt
@@ -1,5 +1,6 @@
 package ml.adamsprogs.bimba.activities
 
+import android.annotation.SuppressLint
 import android.content.*
 import android.os.*
 import android.support.design.widget.Snackbar
@@ -18,8 +19,8 @@ import android.view.inputmethod.InputMethodManager
 import ml.adamsprogs.bimba.*
 import java.util.*
 import android.os.Bundle
-
-
+import android.util.Log
+import kotlinx.android.synthetic.main.activity_dash.*
 
 class DashActivity : AppCompatActivity(), MessageReceiver.OnTimetableDownloadListener,
         FavouritesAdapter.OnMenuItemClickListener {
@@ -29,7 +30,7 @@     val receiver = MessageReceiver()
     lateinit var timetable: Timetable
     var stops: ArrayList<StopSuggestion>? = null
     private lateinit var drawerLayout: DrawerLayout
-    private lateinit var drawer: NavigationView
+    private lateinit var drawerView: NavigationView
     lateinit var favouritesList: RecyclerView
     lateinit var searchView: FloatingSearchView
     lateinit var favourites: FavouriteStorage
@@ -40,7 +41,6 @@     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
         setContentView(R.layout.activity_dash)
         AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_AUTO)
-        val toolbar = findViewById(R.id.toolbar) as Toolbar
         setSupportActionBar(toolbar)
         supportActionBar?.title = getString(R.string.merge_favourites)
 
@@ -55,10 +55,10 @@         prepareFavourites()
 
         scheduleRefresh()
 
-        drawerLayout = findViewById(R.id.drawer_layout) as DrawerLayout
-        drawer = findViewById(R.id.drawer) as NavigationView
+        drawerLayout = drawer_layout
+        drawerView = drawer
         //drawer.setCheckedItem(R.id.drawer_home)
-        drawer.setNavigationItemSelectedListener { item ->
+        drawerView.setNavigationItemSelectedListener { item ->
             when (item.itemId) {
                 R.id.drawer_refresh -> {
                     startDownloaderService()
@@ -69,14 +69,14 @@                 }
                 else -> {
                 }
             }
-            drawerLayout.closeDrawer(drawer)
+            drawerLayout.closeDrawer(drawerView)
             super.onOptionsItemSelected(item)
         }
 
         val validity = timetable.getValidity()
-        drawer.menu.findItem(R.id.drawer_validity).title = getString(R.string.valid_through, validity)
+        drawerView.menu.findItem(R.id.drawer_validity).title = getString(R.string.valid_through, validity)
 
-        searchView = findViewById(R.id.search_view) as FloatingSearchView
+        searchView = search_view
 
         searchView.setOnFocusChangeListener(object : FloatingSearchView.OnFocusChangeListener {
             override fun onFocus() {
@@ -111,8 +111,10 @@                 }
                 imm.hideSoftInputFromWindow(view.windowToken, 0)
                 intent = Intent(context, StopActivity::class.java)
                 searchSuggestion as StopSuggestion
+                intent.putExtra(StopActivity.SOURCE_TYPE, StopActivity.SOURCE_TYPE_STOP)
                 intent.putExtra(StopActivity.EXTRA_STOP_ID, searchSuggestion.id)
                 intent.putExtra(StopActivity.EXTRA_STOP_SYMBOL, searchSuggestion.symbol)
+                Log.i("Profiler", "Intent sent")
                 startActivity(intent)
             }
 
@@ -132,13 +134,13 @@                 textView.text = Html.fromHtml(text[0] + "
" + t) } } - searchView.attachNavigationDrawerToMenuButton(findViewById(R.id.drawer_layout) as DrawerLayout) + searchView.attachNavigationDrawerToMenuButton(drawer_layout as DrawerLayout) } private fun prepareFavourites() { favourites = FavouriteStorage.getFavouriteStorage(context) val layoutManager = LinearLayoutManager(context) - favouritesList = findViewById(R.id.favouritesList) as RecyclerView + favouritesList = favourites_list favouritesList.adapter = FavouritesAdapter(context, favourites.favouritesList, this) favouritesList.layoutManager = layoutManager } @@ -193,8 +195,8 @@ startService(Intent(context, TimetableDownloader::class.java)) } override fun onBackPressed() { - if (drawerLayout.isDrawerOpen(drawer)) { - drawerLayout.closeDrawer(drawer) + if (drawerLayout.isDrawerOpen(drawerView)) { + drawerLayout.closeDrawer(drawerView) return } if (!searchView.setSearchFocused(false)) { @@ -277,6 +279,7 @@ favouritesList.adapter.notifyDataSetChanged() return true } + @SuppressLint("MissingSuperCall") override fun onSaveInstanceState(outState: Bundle) { //hack below line to be commented to prevent crash on nougat. //super.onSaveInstanceState(outState); diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/EditFavouriteActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/EditFavouriteActivity.kt index 3034ce46980b184e3776a19abea7046668bbf725..26f0d5872cbb12303e7c8f75f164b97d5294aa1b 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/EditFavouriteActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/EditFavouriteActivity.kt @@ -4,13 +4,12 @@ import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.support.v7.widget.DividerItemDecoration import android.support.v7.widget.LinearLayoutManager -import android.support.v7.widget.RecyclerView -import android.support.v7.widget.Toolbar import android.widget.EditText import ml.adamsprogs.bimba.R import ml.adamsprogs.bimba.models.Favourite import ml.adamsprogs.bimba.models.FavouriteEditRowAdapter import ml.adamsprogs.bimba.models.FavouriteStorage +import kotlinx.android.synthetic.main.activity_edit_favourite.* class EditFavouriteActivity : AppCompatActivity() { companion object { @@ -30,16 +29,15 @@ if (favourite == null) finish() favourites = FavouriteStorage.getFavouriteStorage(this) - val recyclerView = findViewById(R.id.favourite_edit_list) as RecyclerView? + val recyclerView = favourite_edit_list val layoutManager = LinearLayoutManager(this) recyclerView!!.layoutManager = layoutManager val dividerItemDecoration = DividerItemDecoration(this, layoutManager.orientation) recyclerView.addItemDecoration(dividerItemDecoration) recyclerView.adapter = FavouriteEditRowAdapter(favourite!!) - val toolbar = findViewById(R.id.toolbar) as Toolbar setSupportActionBar(toolbar) supportActionBar?.title = getString(R.string.edit_favourite_title, favourite!!.name) - nameEdit = findViewById(R.id.favourite_name_edit) as EditText + nameEdit = favourite_name_edit nameEdit.setText(favourite!!.name) } diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt index acd4d6fbe1ef29d2ed450a0aedad5a8be982517b..e913730326bcc98b6a0e22a129ffafb4f4c46644 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/NoDbActivity.kt @@ -4,9 +4,8 @@ import android.content.Intent import android.support.v7.app.AppCompatActivity import android.os.Bundle import android.content.IntentFilter -import android.widget.TextView import ml.adamsprogs.bimba.* - +import kotlinx.android.synthetic.main.activity_nodb.* class NoDbActivity : AppCompatActivity(), NetworkStateReceiver.OnConnectivityChangeListener, MessageReceiver.OnTimetableDownloadListener { private val networkStateReceiver = NetworkStateReceiver() @@ -24,7 +23,7 @@ timetableDownloadReceiver.addOnTimetableDownloadListener(this) if (!NetworkStateReceiver.isNetworkAvailable(this)) { askedForNetwork = true - (findViewById(R.id.noDbCaption) as TextView).text = getString(R.string.no_db_connect) + no_db_caption.text = getString(R.string.no_db_connect) filter = IntentFilter("android.net.conn.CONNECTIVITY_CHANGE") registerReceiver(networkStateReceiver, filter) networkStateReceiver.addOnConnectivityChangeListener(this) @@ -39,7 +38,7 @@ filter.addCategory(Intent.CATEGORY_DEFAULT) registerReceiver(timetableDownloadReceiver, filter) if (!NetworkStateReceiver.isNetworkAvailable(this)) { askedForNetwork = true - (findViewById(R.id.noDbCaption) as TextView).text = getString(R.string.no_db_connect) + no_db_caption.text = getString(R.string.no_db_connect) filter = IntentFilter("android.net.conn.CONNECTIVITY_CHANGE") registerReceiver(networkStateReceiver, filter) networkStateReceiver.addOnConnectivityChangeListener(this) @@ -48,7 +47,7 @@ downloadTimetable() } private fun downloadTimetable() { - (findViewById(R.id.noDbCaption) as TextView).text = getString(R.string.no_db_downloading) + no_db_caption.text = getString(R.string.no_db_downloading) serviceRunning = true intent = Intent(this, TimetableDownloader::class.java) intent.putExtra(TimetableDownloader.EXTRA_FORCE, true) @@ -70,7 +69,7 @@ networkStateReceiver.removeOnConnectivityChangeListener(this) startActivity(Intent(this, DashActivity::class.java)) finish() } - else -> (findViewById(R.id.noDbCaption) as TextView).text = getString(R.string.error_try_later) + else -> no_db_caption.text = getString(R.string.error_try_later) } } diff --git a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt index 56342f6feab9caf4c444e1d6b517128cf2fd07b8..7a8fb57b6c09ece0b8185e464fb9abea5a5ddb9e 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/activities/StopActivity.kt @@ -12,23 +12,29 @@ import android.support.v7.widget.* import android.support.v4.app.* import android.support.v4.view.* import android.support.v4.content.res.ResourcesCompat -import android.util.Log import ml.adamsprogs.bimba.models.* import ml.adamsprogs.bimba.* import kotlin.concurrent.thread +import kotlinx.android.synthetic.main.activity_stop.* +//check does favourites retain onVM after parcelation? Ie. does it refresh? class StopActivity : AppCompatActivity(), MessageReceiver.OnVmListener { companion object { val EXTRA_STOP_ID = "stopId" val EXTRA_STOP_SYMBOL = "stopSymbol" + val EXTRA_FAVOURITE = "favourite" val REQUESTER_ID = "stopActivity" + val SOURCE_TYPE = "sourceType" + val SOURCE_TYPE_STOP = "stop" + val SOURCE_TYPE_FAV = "favourite" } - private lateinit var stopId: String - private lateinit var stopSymbol: String + private var stopId: String? = null + private var stopSymbol: String? = null + private var favourite: Favourite? = null private var timetableType = "departure" private var sectionsPagerAdapter: SectionsPagerAdapter? = null private var viewPager: ViewPager? = null @@ -40,30 +46,49 @@ private lateinit var timerTask: TimerTask private val context = this private val receiver = MessageReceiver() + private lateinit var sourceType: String + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_stop) - stopId = intent.getStringExtra(EXTRA_STOP_ID) - stopSymbol = intent.getStringExtra(EXTRA_STOP_SYMBOL) - val toolbar = findViewById(R.id.toolbar) as Toolbar + timetable = Timetable.getTimetable() + + sourceType = intent.getStringExtra(SOURCE_TYPE) + + val toolbar = findViewById<Toolbar>(R.id.toolbar) setSupportActionBar(toolbar) + when (sourceType) { + SOURCE_TYPE_STOP -> { + stopId = intent.getStringExtra(EXTRA_STOP_ID) + stopSymbol = intent.getStringExtra(EXTRA_STOP_SYMBOL) + supportActionBar?.title = timetable.getStopName(stopId!!) + } + SOURCE_TYPE_FAV -> { + favourite = intent.getParcelableExtra(EXTRA_FAVOURITE) + supportActionBar?.title = favourite!!.name + + } + } + createTimerTask() prepareOnDownloadListener() - timetable = Timetable.getTimetable() - supportActionBar?.title = timetable.getStopName(stopId) - - viewPager = findViewById(R.id.container) as ViewPager - tabLayout = findViewById(R.id.tabs) as TabLayout + viewPager = container + tabLayout = tabs sectionsPagerAdapter = SectionsPagerAdapter(supportFragmentManager, null) thread { - sectionsPagerAdapter!!.departures = Departure.createDepartures(stopId) - Log.i("Stop", "Deps created") - runOnUiThread { sectionsPagerAdapter?.notifyDataSetChanged() } + if (sourceType == SOURCE_TYPE_STOP) { + sectionsPagerAdapter!!.departures = Departure.createDepartures(stopId!!) + } else { + sectionsPagerAdapter!!.departures = favourite!!.allDepartures() + } + runOnUiThread { + sectionsPagerAdapter?.notifyDataSetChanged() + } } viewPager!!.adapter = sectionsPagerAdapter @@ -74,23 +99,28 @@ selectTodayPage() scheduleRefresh() - val fab = findViewById(R.id.fab) as FloatingActionButton + showFab() + } + + private fun showFab() { + if (sourceType == SOURCE_TYPE_FAV) + return val favourites = FavouriteStorage.getFavouriteStorage(context) - if (!favourites.has(stopSymbol)) { + if (!favourites.has(stopSymbol!!)) { fab.setImageDrawable(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_favourite_empty, this.theme)) } fab.setOnClickListener { - if (!favourites.has(stopSymbol)) { + if (!favourites.has(stopSymbol!!)) { val items = ArrayList<HashMap<String, String>>() - timetable.getLines(stopId).forEach { + timetable.getLines(stopId!!).forEach { val o = HashMap<String, String>() - o[Favourite.TAG_STOP] = stopId + o[Favourite.TAG_STOP] = stopId!! o[Favourite.TAG_LINE] = it items.add(o) } - favourites.add(stopSymbol, items) + favourites.add(stopSymbol as String, items) fab.setImageDrawable(ResourcesCompat.getDrawable(context.resources, R.drawable.ic_favourite, this.theme)) } else { Snackbar.make(it, getString(R.string.stop_already_fav), Snackbar.LENGTH_LONG) @@ -106,6 +136,9 @@ val vmIntent = Intent(context, VmClient::class.java) vmIntent.putExtra(VmClient.EXTRA_STOP_SYMBOL, stopSymbol) vmIntent.putExtra(VmClient.EXTRA_REQUESTER, REQUESTER_ID) startService(vmIntent) + runOnUiThread { + sectionsPagerAdapter?.notifyDataSetChanged() + } } } } @@ -119,8 +152,8 @@ receiver.addOnVmListener(context as MessageReceiver.OnVmListener) } override fun onVm(vmDepartures: ArrayList<Departure>?, requester: String) { - if (timetableType == "departure" && requester == REQUESTER_ID) { - val fullDepartures = Departure.createDepartures(stopId) + if (timetableType == "departure" && requester == REQUESTER_ID && sourceType == SOURCE_TYPE_STOP) { + val fullDepartures = Departure.createDepartures(stopId!!) if (vmDepartures != null) { fullDepartures[today.getMode()] = vmDepartures } @@ -156,14 +189,20 @@ if (id == R.id.action_change_type) { if (timetableType == "departure") { timetableType = "full" item.icon = (ResourcesCompat.getDrawable(resources, R.drawable.ic_timetable_departure, this.theme)) - sectionsPagerAdapter?.departures = timetable.getStopDepartures(stopId) + if (sourceType == SOURCE_TYPE_STOP) + sectionsPagerAdapter?.departures = timetable.getStopDepartures(stopId!!) + else + sectionsPagerAdapter?.departures = favourite!!.fullTimetable() sectionsPagerAdapter?.relativeTime = false sectionsPagerAdapter?.notifyDataSetChanged() timer.cancel() } else { timetableType = "departure" item.icon = (ResourcesCompat.getDrawable(resources, R.drawable.ic_timetable_full, this.theme)) - sectionsPagerAdapter?.departures = Departure.createDepartures(stopId) + if (sourceType == SOURCE_TYPE_STOP) + sectionsPagerAdapter?.departures = Departure.createDepartures(stopId!!) + else + sectionsPagerAdapter?.departures = favourite!!.allDepartures() sectionsPagerAdapter?.relativeTime = true sectionsPagerAdapter?.notifyDataSetChanged() scheduleRefresh() @@ -188,10 +227,10 @@ savedInstanceState: Bundle?): View? { val rootView = inflater!!.inflate(R.layout.fragment_stop, container, false) val layoutManager = LinearLayoutManager(activity) - val departuresList: RecyclerView = rootView.findViewById(R.id.departuresList) as RecyclerView + val departuresList: RecyclerView = rootView.findViewById(R.id.departuresList) departuresList.addItemDecoration(DividerItemDecoration(departuresList.context, layoutManager.orientation)) - val departures = arguments.getStringArrayList("departures")?.map{ Departure.fromString(it) } + val departures = arguments.getStringArrayList("departures")?.map { Departure.fromString(it) } departuresList.adapter = DeparturesAdapter(activity, departures, arguments["relativeTime"] as Boolean) departuresList.layoutManager = layoutManager @@ -201,12 +240,11 @@ companion object { private val ARG_SECTION_NUMBER = "section_number" - fun newInstance(sectionNumber: Int, stopId: String, departures: ArrayList<Departure>?, relativeTime: Boolean): + fun newInstance(sectionNumber: Int, departures: ArrayList<Departure>?, relativeTime: Boolean): PlaceholderFragment { val fragment = PlaceholderFragment() val args = Bundle() args.putInt(ARG_SECTION_NUMBER, sectionNumber) - args.putString("stop", stopId) if (departures != null) { val d = ArrayList<String>() departures.mapTo(d) { it.toString() } @@ -235,7 +273,7 @@ 0 -> mode = Timetable.MODE_WORKDAYS 1 -> mode = Timetable.MODE_SATURDAYS 2 -> mode = Timetable.MODE_SUNDAYS } - return PlaceholderFragment.newInstance(position + 1, stopId, departures?.get(mode), relativeTime) + return PlaceholderFragment.newInstance(position + 1, departures?.get(mode), relativeTime) } override fun getCount() = 3 diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt index 036976a39cdee66aee5c8027fc688a3cb1592813..8be55d625ee4c3f580996c0cf6809352e91a3cb9 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/Departure.kt @@ -1,5 +1,6 @@ package ml.adamsprogs.bimba.models +import android.util.Log import java.util.* import kotlin.collections.ArrayList @@ -38,23 +39,29 @@ } fun createDepartures(stopId: String): HashMap<String, ArrayList<Departure>> { val timetable = Timetable.getTimetable() + Log.i("Profiler/Departure", "Got timetable") val departures = timetable.getStopDepartures(stopId) + Log.i("Profiler/Departure", "Got departures") val moreDepartures = HashMap<String, ArrayList<Departure>>() for ((k, v) in departures) { moreDepartures[k] = ArrayList() for (departure in v) moreDepartures[k]!!.add(departure.copy()) } + Log.i("Profiler/Departure", "Duplicated departures") val rolledDepartures = HashMap<String, ArrayList<Departure>>() for ((_, tomorrowDepartures) in moreDepartures) { tomorrowDepartures.forEach { it.tomorrow = true } } + Log.i("Profiler/Departure", "Set tomorrow") for ((mode, _) in departures) { rolledDepartures[mode] = (departures[mode] as ArrayList<Departure> + moreDepartures[mode] as ArrayList<Departure>) as ArrayList<Departure> + Log.i("Profiler/Departure", "Joined departures for $mode") rolledDepartures[mode] = filterDepartures(rolledDepartures[mode]!!) + Log.i("Profiler/Departure", "Filtered departures for $mode") } return rolledDepartures diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/DeparturesAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/DeparturesAdapter.kt index 45561679123a7d51e4db7779c659345e8afaac68..57a1d726719af4607ec42df4cdfa59809fb43d8b 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/DeparturesAdapter.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/DeparturesAdapter.kt @@ -94,12 +94,12 @@ return ViewHolder(rowView) } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val root = itemView.findViewById(R.id.departureRow)!! - val lineTextView: TextView = itemView.findViewById(R.id.lineNumber) as TextView - val timeTextView: TextView = itemView.findViewById(R.id.departureTime) as TextView - val directionTextView: TextView = itemView.findViewById(R.id.departureDirection) as TextView - val typeIcon: ImageView = itemView.findViewById(R.id.departureTypeIcon) as ImageView - val infoIcon: ImageView = itemView.findViewById(R.id.departureInfoIcon) as ImageView - val floorIcon: ImageView = itemView.findViewById(R.id.departureFloorIcon) as ImageView + val root = itemView.findViewById<View>(R.id.departureRow)!! + val lineTextView: TextView = itemView.findViewById(R.id.lineNumber) + val timeTextView: TextView = itemView.findViewById(R.id.departureTime) + val directionTextView: TextView = itemView.findViewById(R.id.departureDirection) + val typeIcon: ImageView = itemView.findViewById(R.id.departureTypeIcon) + val infoIcon: ImageView = itemView.findViewById(R.id.departureInfoIcon) + val floorIcon: ImageView = itemView.findViewById(R.id.departureFloorIcon) } } \ No newline at end of file diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt index 9b9d7525391486c5d55b953c1bb6d8e4d011a589..e08b3ad8e021062b0b3f9341225b007b13b904e8 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/Favourite.kt @@ -53,7 +53,7 @@ } override fun describeContents(): Int { - return 105 + return Parcelable.CONTENTS_FILE_DESCRIPTOR } override fun writeToParcel(dest: Parcel?, flags: Int) { @@ -141,5 +141,13 @@ } val TAG_STOP = "stop" val TAG_LINE = "line" + } + + fun allDepartures(): HashMap<String, ArrayList<Departure>>? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. + } + + fun fullTimetable(): HashMap<String, ArrayList<Departure>>? { + TODO("not implemented") //To change body of created functions use File | Settings | File Templates. } } diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/FavouriteEditRowAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/FavouriteEditRowAdapter.kt index 96881bab8514c1b54cb2635ea4e9c7826e832158..0b729b648a91f5108e529d17b6f5c87b29a515cb 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/FavouriteEditRowAdapter.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/FavouriteEditRowAdapter.kt @@ -43,8 +43,8 @@ return ViewHolder(rowView) } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val rowTextView = itemView.findViewById(R.id.favourite_edit_row) as TextView - val splitButton = itemView.findViewById(R.id.favourite_edit_split) as ImageView - val deleteButton = itemView.findViewById(R.id.favourite_edit_delete) as ImageView + val rowTextView:TextView = itemView.findViewById(R.id.favourite_edit_row) + val splitButton:ImageView = itemView.findViewById(R.id.favourite_edit_split) + val deleteButton:ImageView = itemView.findViewById(R.id.favourite_edit_delete) } } \ No newline at end of file diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/FavouritesAdapter.kt b/app/src/main/java/ml/adamsprogs/bimba/models/FavouritesAdapter.kt index 62506b751f954db068782aa7604f17c0be9993c0..f430213010b49f50058dd0f571ee258ce991bf63 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/FavouritesAdapter.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/FavouritesAdapter.kt @@ -3,6 +3,7 @@ import android.app.Activity import android.content.Context import android.os.Build +import android.support.design.widget.AppBarLayout import android.support.v4.content.res.ResourcesCompat import android.support.v7.widget.* import android.support.v7.widget.PopupMenu @@ -13,6 +14,7 @@ import android.view.LayoutInflater import java.util.* import kotlin.concurrent.thread import android.util.TypedValue +import com.arlib.floatingsearchview.FloatingSearchView import ml.adamsprogs.bimba.Declinator import kotlin.collections.ArrayList @@ -139,11 +141,11 @@ private fun setSelecting() { context as Activity if (isSelecting) { - context.findViewById(R.id.search_view).visibility = View.INVISIBLE - context.findViewById(R.id.appbar).visibility = View.VISIBLE + context.findViewById<FloatingSearchView>(R.id.search_view).visibility = View.INVISIBLE + context.findViewById<AppBarLayout>(R.id.appbar).visibility = View.VISIBLE } else { - context.findViewById(R.id.search_view).visibility = View.VISIBLE - context.findViewById(R.id.appbar).visibility = View.INVISIBLE + context.findViewById<FloatingSearchView>(R.id.search_view).visibility = View.VISIBLE + context.findViewById<AppBarLayout>(R.id.appbar).visibility = View.INVISIBLE } } @@ -166,12 +168,12 @@ } } inner class ViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) { - val root = itemView.findViewById(R.id.favourite_card) as CardView - val nameTextView = itemView.findViewById(R.id.favourite_name) as TextView - val timeTextView = itemView.findViewById(R.id.favourite_time) as TextView - val lineTextView = itemView.findViewById(R.id.favourite_line) as TextView - val moreButton = itemView.findViewById(R.id.favourite_more_button) as ImageView - val typeIcon = itemView.findViewById(R.id.departureTypeIcon) as ImageView + val root:CardView = itemView.findViewById(R.id.favourite_card) + val nameTextView:TextView = itemView.findViewById(R.id.favourite_name) + val timeTextView:TextView = itemView.findViewById(R.id.favourite_time) + val lineTextView:TextView = itemView.findViewById(R.id.favourite_line) + val moreButton:ImageView = itemView.findViewById(R.id.favourite_more_button) + val typeIcon:ImageView = itemView.findViewById(R.id.departureTypeIcon) } interface OnMenuItemClickListener { diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt b/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt index 4cf47653862c3a2204262901f603e67cfcbf2003..a9071c7c56ff94066c808e5421276882231dde0f 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/StopSuggestion.kt @@ -6,12 +6,11 @@ import com.arlib.floatingsearchview.suggestions.model.SearchSuggestion class StopSuggestion(text: String, val id: String, val symbol: String) : SearchSuggestion { private val body: String = text - private val CONTENTS_SUGGESTION = 0x0105 constructor(parcel: Parcel) : this(parcel.readString(), parcel.readString(), parcel.readString()) override fun describeContents(): Int { - return CONTENTS_SUGGESTION + return Parcelable.CONTENTS_FILE_DESCRIPTOR } override fun writeToParcel(dest: Parcel?, flags: Int) { diff --git a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt index 374e225e0466b2c3aa6c319ccc10b7f857ec2062..e36ad93ecce2365dc879c8ebd9bde571e70ab06b 100644 --- a/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt +++ b/app/src/main/java/ml/adamsprogs/bimba/models/Timetable.kt @@ -125,7 +125,7 @@ val departures = HashMap>() departures.put(MODE_WORKDAYS, ArrayList()) departures.put(MODE_SATURDAYS, ArrayList()) departures.put(MODE_SUNDAYS, ArrayList()) - while (cursor.moveToNext()) { + while (cursor.moveToNext()) { //fixme first moveToNext takes 2s, subsequent ones are instant departures[cursor.getString(1)]?.add(Departure(cursor.getString(0), cursor.getString(1), cursor.getString(2), cursor.getInt(3) == 1, cursor.getString(4), cursor.getString(5), tomorrow = tomorrow)) diff --git a/app/src/main/res/layout/activity_dash.xml b/app/src/main/res/layout/activity_dash.xml index db6a3e4266c2744e8b4d7bbc09b2c78e83285a0b..120aa55d494af4dc38b0eda1ada09d28eb19086d 100644 --- a/app/src/main/res/layout/activity_dash.xml +++ b/app/src/main/res/layout/activity_dash.xml @@ -30,7 +30,7 @@ app:popupTheme="@style/AppTheme.PopupOverlay" /> </android.support.design.widget.AppBarLayout> <android.support.v7.widget.RecyclerView - android:id="@+id/favouritesList" + android:id="@+id/favourites_list" android:layout_width="0dp" android:layout_height="0dp" android:layout_marginBottom="0dp" @@ -39,7 +39,7 @@ android:scrollbars="none" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent" - app:layout_constraintBottom_toBottomOf="@+id/search_view" /> + app:layout_constraintBottom_toBottomOf="@id/search_view" /> <com.arlib.floatingsearchview.FloatingSearchView android:id="@+id/search_view" diff --git a/app/src/main/res/layout/activity_nodb.xml b/app/src/main/res/layout/activity_nodb.xml index 287aaa941d98a4342927ca898de4e9840ee48e38..63b8cd16a003e2fccabadb5fbc343f558b5a51ff 100644 --- a/app/src/main/res/layout/activity_nodb.xml +++ b/app/src/main/res/layout/activity_nodb.xml @@ -18,7 +18,7 @@ android:layout_height="match_parent" android:orientation="vertical"> <TextView - android:id="@+id/noDbCaption" + android:id="@+id/no_db_caption" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" diff --git a/app/src/main/res/layout/row_favourite.xml b/app/src/main/res/layout/row_favourite.xml index 977dae12323f363cc40bd7491a237c147cbee81a..76733ef1eb085c419ae1f120e5d09cc15585cd62 100644 --- a/app/src/main/res/layout/row_favourite.xml +++ b/app/src/main/res/layout/row_favourite.xml @@ -29,7 +29,7 @@ android:id="@+id/favourite_time" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:text="@string/calculating" + android:text="@string/loading" android:textAppearance="@style/TextAppearance.AppCompat.Headline" app:layout_constraintStart_toStartOf="@+id/favourite_line" app:layout_constraintTop_toBottomOf="@+id/favourite_name" diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 9ee2fea2f026c6183667e944b0c85656d1e4f44a..8f3e09faf5ea5ec104651267b31f7897dd7c334e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -34,7 +34,7 @@ favourite element split button <string name="no_next_departure">No next departure</string> <string name="action_merge">Merge</string> <string name="merge_favourites">Merge favourites</string> - <string name="calculating">Calculating…</string> + <string name="loading">Loading…</string> <string name="departure_in__singular_genitive">In %1$s minute</string> <string name="departure_in__plural_genitive">In %1$s minutes</string> <string name="departure_in__plural_nominative">In %1$s minutes</string> diff --git a/app/src/main/res/values-pl/strings.xml b/app/src/main/res/values-pl/strings.xml index b22642ffd108404c7f677ac34a2f771c1ef03df6..60e683c4bf3f682680d82ee5d72896b2daa1dba4 100644 --- a/app/src/main/res/values-pl/strings.xml +++ b/app/src/main/res/values-pl/strings.xml @@ -28,7 +28,7 @@ Nazwa ulubionego <string name="no_next_departure">Brak następnego odjazdu</string> <string name="action_merge">Połącz</string> <string name="merge_favourites">Połącz ulubione</string> - <string name="calculating">Obliczam…</string> + <string name="loading">Ładowanie…</string> <string name="departure_in__singular_genitive">Za %1$s minutę</string> <string name="departure_in__plural_genitive">Za %1$s minut</string> <string name="departure_in__plural_nominative">Za %1$s minuty</string> diff --git a/build.gradle b/build.gradle index a52487381ec53f408d3143a60dddbfb825a4b7f7..02877a16f9e22be3c03186d22d0e41e2ee0063c1 100644 --- a/build.gradle +++ b/build.gradle @@ -9,7 +9,7 @@ //maven { url 'https://dl.bintray.com/guardian/android' } // TooLargeTool google() } dependencies { - classpath 'com.android.tools.build:gradle:3.0.0-beta6' + classpath 'com.android.tools.build:gradle:3.0.0-rc2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong diff --git a/database/scraper.py b/database/scraper.py index 6475d82f51b09be68be5c9a9fe89efc903f174a0..c94b49f40429e6b8759cb084b10a90696fdfbef4 100755 --- a/database/scraper.py +++ b/database/scraper.py @@ -50,12 +50,17 @@ """ index = self.__get('https://www.ztm.poznan.pl/goeuropa-api/node_stops/{}'.format(node)) stops = [] for stop in json.loads(index.text): + name = stop['stop']['name'] stop_id = stop['stop']['id'] number = re.findall("\\d+", stop['stop']['symbol'])[0] lat = stop['stop']['lat'] lon = stop['stop']['lon'] + # todo test directions = ', '.join(['{} → {}'.format(transfer['name'], transfer['headsign']) - for transfer in stop['transfers']]) + for transfer in stop['transfers'] + if transfer['headsign'] != name]) + if directions == '': + continue stops.append((stop_id, node, number, lat, lon, directions)) return stops