Skip to content

Commit

Permalink
Merge pull request #39 from tal-sitton/upgrade-sdk
Browse files Browse the repository at this point in the history
upgraded sdk, and changed the onBack because deprecation
  • Loading branch information
tal-sitton authored Sep 18, 2022
2 parents 2c65a92 + eea4518 commit 171b4e8
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 22 deletions.
9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ plugins {
}

android {
compileSdk 32
compileSdk 33

defaultConfig {
applicationId "com.example.movietime"
minSdk 26
targetSdk 32
versionCode 1
versionName "1.0"
targetSdk 33
versionCode 2
versionName "0.7"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down Expand Up @@ -44,6 +44,7 @@ dependencies {
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.5'
implementation 'androidx.navigation:navigation-ui-ktx:2.3.5'
implementation 'com.google.android.gms:play-services-location:18.0.0'
implementation 'androidx.appcompat:appcompat:1.6.0-rc01'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/example/movietime/AboutActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AboutActivity : MyTemplateActivity() {

val mainActivityButton: Button = findViewById(R.id.backButton)
mainActivityButton.setOnClickListener {
onBackPressed()
onBackPressedCallback.handleOnBackPressed()
}

val supportButton: ImageView = findViewById(R.id.supportButton)
Expand All @@ -27,7 +27,7 @@ class AboutActivity : MyTemplateActivity() {

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == R.id.action_about) {
onBackPressed()
onBackPressedCallback.handleOnBackPressed()
return true
}
return super.onOptionsItemSelected(item)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/movietime/CinemaActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class CinemaActivity : MyTemplateActivity() {
val mainButton: TextView = findViewById(R.id.cinemaButton)
mainButton.setBackgroundResource(R.drawable.top_buttons_clicked)
mainButton.setOnClickListener {
onBackPressed()
onBackPressedCallback.handleOnBackPressed()
}
mainButton.text = "אישור"
val dateButton: TextView = findViewById(R.id.dateButton)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/movietime/DateActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class DateActivity : MyTemplateActivity() {
mainButton.setBackgroundResource(R.drawable.top_buttons_clicked)
mainButton.text = "אישור"
mainButton.setOnClickListener {
onBackPressed()
onBackPressedCallback.handleOnBackPressed()
}
val cinemaButton: TextView = findViewById(R.id.cinemaButton)
val movieButton: TextView = findViewById(R.id.movieButton)
Expand Down
35 changes: 26 additions & 9 deletions app/src/main/java/com/example/movietime/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import android.os.Bundle
import android.view.Gravity
import android.view.View
import android.widget.*
import androidx.activity.OnBackPressedCallback
import java.time.LocalDateTime


class MainActivity : MyTemplateActivity() {
Expand Down Expand Up @@ -71,7 +73,18 @@ class MainActivity : MyTemplateActivity() {
DateActivity.checkScreening(screening)
}.toSet()

if (filteredDateScreenings.isEmpty()) {
DateActivity.selectedDays.clear()
DateActivity.selectedDays.add(LocalDateTime.now().plusDays(1).dayOfMonth)
DateActivity.restarted = false
DateActivity.selectedDatStr = "מחר"
filteredDateScreenings = allScreenings.filter { screening ->
DateActivity.checkScreening(screening)
}.toSet()
}

filteredScreenings = filteredDateScreenings.toList()
prevFilteredScreenings = filteredScreenings
}
}

Expand Down Expand Up @@ -123,9 +136,10 @@ class MainActivity : MyTemplateActivity() {
grid.removeAllViewsInLayout()
var i = 1
val notFound: TextView = findViewById(R.id.noMovieFound)
if (filteredScreenings.isEmpty())
if (filteredScreenings.isEmpty()) {
notFound.visibility = TextView.VISIBLE
else
return
} else
notFound.visibility = TextView.INVISIBLE

var prevDay = filteredScreenings.elementAt(0).dateTime.dayOfMonth
Expand Down Expand Up @@ -176,13 +190,16 @@ class MainActivity : MyTemplateActivity() {
}

private var backPressedTime: Long = 0
override fun onBackPressed() {
if (backPressedTime + 2000 > System.currentTimeMillis()) {
this.finishAffinity()
} else {
Toast.makeText(baseContext, "לחץ שנית בכדי לסגור את האפליקציה", Toast.LENGTH_SHORT)
.show()
backPressedTime = System.currentTimeMillis()

override val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (backPressedTime + 2000 > System.currentTimeMillis()) {
finishAffinity()
} else {
Toast.makeText(baseContext, "לחץ שנית בכדי לסגור את האפליקציה", Toast.LENGTH_SHORT)
.show()
backPressedTime = System.currentTimeMillis()
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/example/movietime/MovieActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class MovieActivity : MyTemplateActivity() {
val movieButton: TextView = findViewById(R.id.movieButton)
movieButton.setBackgroundResource(R.drawable.top_buttons_clicked)
movieButton.setOnClickListener {
onBackPressed()
onBackPressedCallback.handleOnBackPressed()
}
movieButton.text = "אישור"

Expand Down
17 changes: 13 additions & 4 deletions app/src/main/java/com/example/movietime/MyTemplateActivity.kt
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
package com.example.movietime

import android.content.Intent
import android.os.Bundle
import android.view.Menu
import android.view.MenuItem
import android.widget.ProgressBar
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity

open class MyTemplateActivity : AppCompatActivity() {

override fun onBackPressed() {
finish()
overridePendingTransition(0, 0)
open val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
finish()
overridePendingTransition(0, 0)
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}

override fun onCreateOptionsMenu(menu: Menu?): Boolean {
Expand All @@ -25,7 +34,7 @@ open class MyTemplateActivity : AppCompatActivity() {
MainActivity.resetToDefault()
MainActivity.filter()
recreate()
item.actionView.postDelayed({ item.actionView = null }, 1)
(item.actionView as ProgressBar).postDelayed({ item.actionView = null }, 1)
true
}
R.id.action_about -> {
Expand Down

0 comments on commit 171b4e8

Please sign in to comment.