Skip to content

Commit

Permalink
Makes tileservice open barcode when no favorite, open favorite o.w.
Browse files Browse the repository at this point in the history
  • Loading branch information
IzHoBX committed Jun 15, 2020
1 parent c3c1d68 commit 93d5a5e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
17 changes: 13 additions & 4 deletions app/src/main/java/com/izho/saveentry/ExpressCheckoutTileService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import com.izho.saveentry.data.getAppDatabase
class ExpressCheckoutTileService: TileService(), LifecycleOwner {
private val mDispatcher = ServiceLifecycleDispatcher(this)
private var nextVisitToUse:VisitWithLocation? = null;

private var hasFavorite = false

override fun onCreate() {
mDispatcher.onServicePreSuperOnCreate()
Expand All @@ -30,6 +30,11 @@ class ExpressCheckoutTileService: TileService(), LifecycleOwner {
nextVisitToUse = null
}
})

database.dao.getAllFavoriteLocations().observe(this, Observer { favourites ->
hasFavorite = favourites.isNotEmpty()
})

}

override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
Expand Down Expand Up @@ -60,11 +65,15 @@ class ExpressCheckoutTileService: TileService(), LifecycleOwner {
intent.putExtra("action", "checkOut")
intent.putExtra("visitId", nextVisitToUse!!.visit.visitId)
intent.putExtra("url", nextVisitToUse!!.location.url)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
} else {
intent = Intent(this, LiveBarcodeScanningActivity::class.java)
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
if(hasFavorite) {
intent = Intent(this, MainActivity::class.java)
intent.putExtra("scrollToFavourtie", true)
} else {
intent = Intent(this, LiveBarcodeScanningActivity::class.java)
}
}
intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK;
this.startActivity(intent)
Log.v("start", "activity")
val it = Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS)
Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/com/izho/saveentry/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,18 @@ class MainActivity : AppCompatActivity() {
}

fun setSelectedTab() {
val database = getAppDatabase(this, resetDb = false)
val activeVisits = database.dao.getAllActiveVisitWithLocation().observe(this, Observer { activeVisits ->
if (activeVisits == null || activeVisits.isEmpty()) {
viewPager.setCurrentItem((TAB_LABELS.indexOf("Favorites")), false)
}
})
if(intent.hasExtra("scrollToFavourtie")) {
viewPager.setCurrentItem((TAB_LABELS.indexOf("Favorites")), false)
//so that subsequent opening of the app wont be stucked to favorite
intent.removeExtra("scrollToFavourtie")
} else {
val database = getAppDatabase(this, resetDb = false)
val activeVisits = database.dao.getAllActiveVisitWithLocation().observe(this, Observer { activeVisits ->
if (activeVisits == null || activeVisits.isEmpty()) {
viewPager.setCurrentItem((TAB_LABELS.indexOf("Favorites")), false)
}
})
}
}

class PageAdapter(activity: AppCompatActivity) : FragmentStateAdapter(activity) {
Expand Down

0 comments on commit 93d5a5e

Please sign in to comment.