Skip to content

Commit

Permalink
fix notification channel being retained on canceled new timer
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvchandler committed Mar 28, 2019
1 parent 4a65dc4 commit c955e85
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 67 deletions.
58 changes: 28 additions & 30 deletions app/src/main/java/Progress_bars.kt
Original file line number Diff line number Diff line change
Expand Up @@ -209,43 +209,41 @@ class Progress_bars: Dynamic_theme_activity()
}

// handle toolbar menu presses
override fun onOptionsItemSelected(item: MenuItem): Boolean
override fun onOptionsItemSelected(item: MenuItem) = when(item.itemId)
{
when(item.itemId)
R.id.add_butt ->
{
R.id.add_butt ->
{
startActivityForResult(Intent(this, Settings::class.java), RESULT_EDIT_DATA)
return true
}
startActivityForResult(Intent(this, Settings::class.java), RESULT_EDIT_DATA)
true
}

R.id.undo ->
{
adapter.undo()
return true
}
R.id.undo ->
{
adapter.undo()
true
}

R.id.redo ->
{
adapter.redo()
return true
}
R.id.redo ->
{
adapter.redo()
true
}

R.id.settings ->
{
// open app settings menu
startActivity(Intent(this, Preferences::class.java))
return true
}
R.id.settings ->
{
// open app settings menu
startActivity(Intent(this, Preferences::class.java))
true
}

R.id.about ->
{
// show about dialog
About_dialog().show(supportFragmentManager, "about")
return true
}
R.id.about ->
{
// show about dialog
About_dialog().show(supportFragmentManager, "about")
true
}
return false

else -> super.onOptionsItemSelected(item)
}

override fun onActivityResult(request_code: Int, result_code: Int, intent: Intent?)
Expand Down
17 changes: 8 additions & 9 deletions app/src/main/java/settings/Countdown_text.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.app.NavUtils
import androidx.databinding.DataBindingUtil
import org.mattvchandler.progressbars.R
import org.mattvchandler.progressbars.databinding.ActivityCountdownTextBinding
Expand Down Expand Up @@ -85,26 +86,24 @@ class Countdown_text: Dynamic_theme_activity()
val intent = Intent()
intent.putExtra(EXTRA_DATA, data)
setResult(AppCompatActivity.RESULT_OK, intent)
finish()
}

override fun onBackPressed()
{
go_back()
super.onBackPressed()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean
override fun onOptionsItemSelected(item: MenuItem) = when(item.itemId)
{
// make home button go back
when(item.itemId)
android.R.id.home ->
{
android.R.id.home ->
{
go_back()
return true
}
go_back()
NavUtils.navigateUpFromSameTask(this)
true
}
return false
else -> super.onOptionsItemSelected(item)
}

companion object
Expand Down
61 changes: 40 additions & 21 deletions app/src/main/java/settings/Settings.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import android.widget.TimePicker
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.core.app.NavUtils
import androidx.databinding.DataBindingUtil
import com.google.android.material.textfield.TextInputEditText
import org.mattvchandler.progressbars.R
Expand Down Expand Up @@ -302,38 +303,57 @@ class Settings: Dynamic_theme_activity(), DatePickerDialog.OnDateSetListener, Ti
return true
}

override fun onOptionsItemSelected(item: MenuItem): Boolean
override fun onOptionsItemSelected(item: MenuItem) = when(item.itemId)
{
when(item.itemId)
R.id.save_butt ->
{
R.id.save_butt ->
// dump all widget data into data struct
if(store_widgets_to_data())
{
// dump all widget data into data struct
if(!store_widgets_to_data())
return true

// check to make sure start time is before end
if(data.separate_time && data.end_time < data.start_time)
{
Toast.makeText(this, R.string.end_before_start_err, Toast.LENGTH_LONG).show()
return true
}
else
{
val intent = Intent()
intent.putExtra(EXTRA_EDIT_DATA, data)
setResult(AppCompatActivity.RESULT_OK, intent)

val intent = Intent()
intent.putExtra(EXTRA_EDIT_DATA, data)
setResult(AppCompatActivity.RESULT_OK, intent)

finish()
return true
finish()
}
}
true
}

R.id.settings ->
{
startActivity(Intent(this, Preferences::class.java))
return true
}
R.id.settings ->
{
startActivity(Intent(this, Preferences::class.java))
true
}
return false

android.R.id.home ->
{
cancel()
NavUtils.navigateUpFromSameTask(this)
true
}

else -> super.onOptionsItemSelected(item)
}

override fun onBackPressed()
{
cancel()
super.onBackPressed()
}

private fun cancel()
{
// if this was a new timer, delete any notification channel that may have been created
if(Build.VERSION.SDK_INT > 26 && !intent.hasExtra(EXTRA_EDIT_DATA) && data.has_notification_channel)
data.delete_notification_channel(this)
}

// dump all widget data into data obj
Expand Down Expand Up @@ -686,7 +706,6 @@ class Settings: Dynamic_theme_activity(), DatePickerDialog.OnDateSetListener, Ti

override fun onActivityResult(request_code: Int, result_code: Int, intent: Intent?)
{
// get data back from Countdown_text
if(result_code == AppCompatActivity.RESULT_OK)
{
when(request_code)
Expand Down
11 changes: 4 additions & 7 deletions app/src/main/java/util/Preferences.kt
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,10 @@ class Preferences: Dynamic_theme_activity()
supportFragmentManager.beginTransaction().replace(R.id.preferences, Progress_bar_prefs_frag()).commit()
}

override fun onOptionsItemSelected(item: MenuItem): Boolean
{
// make home button go back
when(item.itemId)
override fun onOptionsItemSelected(item: MenuItem) = when(item.itemId)
{
android.R.id.home -> { finish(); return true }
// make home button go back
android.R.id.home -> { finish(); true }
else -> super.onOptionsItemSelected(item)
}
return false
}
}

0 comments on commit c955e85

Please sign in to comment.