Archived
Notification service added (back?) to Main.kt
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package com.denizd.substitutionplan
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.job.JobInfo
|
||||
import android.app.job.JobScheduler
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
@@ -54,6 +57,8 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
edit.putInt("launchDev", prefs.getInt("launchDev", 0) + 1)
|
||||
edit.apply()
|
||||
|
||||
notificationJob()
|
||||
|
||||
val handler = Handler()
|
||||
|
||||
val toolbar = findViewById<Toolbar>(R.id.toolbar)
|
||||
@@ -284,7 +289,7 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
}, 600)
|
||||
}
|
||||
|
||||
val userPlan: String = when (prefs.getString("username", "")[prefs.getString("username", "").length - 1].toString().toLowerCase() as String) {
|
||||
val userPlan: String = when (prefs.getString("username", "")[prefs.getString("username", "").length - 1].toString().toLowerCase()) {
|
||||
"s", "x", "z" -> prefs.getString("username", "") + getString(R.string.nosplan)
|
||||
else -> prefs.getString("username", "") + getString(R.string.splan)
|
||||
}
|
||||
@@ -367,6 +372,17 @@ class Main : AppCompatActivity(R.layout.activity_main) {
|
||||
return true
|
||||
}
|
||||
|
||||
private fun notificationJob() {
|
||||
val componentName = ComponentName(this, ScheduledJobService::class.java)
|
||||
val info = JobInfo.Builder(42, componentName)
|
||||
.setRequiresCharging(false)
|
||||
.setPersisted(true)
|
||||
.setPeriodic(900000)
|
||||
.build()
|
||||
val scheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
scheduler.schedule(info)
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
|
||||
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
|
||||
|
||||
@@ -133,7 +133,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
}
|
||||
|
||||
hiddenBtn.setOnLongClickListener {
|
||||
hiddenMenu()
|
||||
debugMenu()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -338,7 +338,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
|
||||
}
|
||||
|
||||
private fun hiddenMenu(): Boolean {
|
||||
private fun debugMenu(): Boolean {
|
||||
|
||||
DeviceName.with(mContext).request { deviceInfo, _ ->
|
||||
name = deviceInfo.marketName
|
||||
@@ -350,13 +350,11 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
|
||||
}
|
||||
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.edittext_dialog, null)
|
||||
val title = dialogView.findViewById<TextView>(R.id.textviewtitle)
|
||||
val dialogText = dialogView.findViewById<TextView>(R.id.dialogtext)
|
||||
val dialogEditText = dialogView.findViewById<EditText>(R.id.dialog_edittext)
|
||||
val dialogButton = dialogView.findViewById<Button>(R.id.dialog_button)
|
||||
|
||||
title.text = getString(R.string.experimentalmenu)
|
||||
dialogText.text = getString(R.string.fortest)
|
||||
dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(R.string.experimentalmenu)
|
||||
dialogView.findViewById<TextView>(R.id.dialogtext).text = getString(R.string.fortest)
|
||||
dialogButton.setOnClickListener {
|
||||
when (dialogEditText.text.toString()) {
|
||||
"@DIAGNOSTICS" -> {
|
||||
@@ -365,12 +363,11 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
|
||||
}
|
||||
val devDialogView = LayoutInflater.from(mContext).inflate(R.layout.diagnostics_dialog, null)
|
||||
val devTitle = devDialogView.findViewById<TextView>(R.id.textviewtitle)
|
||||
val devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
|
||||
val resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch)
|
||||
val resetNotifBtn = devDialogView.findViewById<Button>(R.id.btnResetNotif)
|
||||
|
||||
devTitle.text = getString(R.string.diagnosticsmenu)
|
||||
devDialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(R.string.diagnosticsmenu)
|
||||
devDialogText.text = getDiagnosticsText(prefs)
|
||||
|
||||
resetLaunchBtn.setOnClickListener {
|
||||
@@ -402,7 +399,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
|
||||
}
|
||||
val dateDialogView = LayoutInflater.from(mContext).inflate(R.layout.dating_dialog, null)
|
||||
val dateTitle = dateDialogView.findViewById<TextView>(R.id.textviewtitle)
|
||||
val datingBtn = dateDialogView.findViewById<Button>(R.id.dating_btn)
|
||||
val boyTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt1)
|
||||
val girlTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt2)
|
||||
@@ -410,14 +406,10 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
val girlCb = dateDialogView.findViewById<CheckBox>(R.id.cb2)
|
||||
val percentage = dateDialogView.findViewById<TextView>(R.id.dating_txtp)
|
||||
|
||||
dateTitle.text = getString(R.string.dating)
|
||||
dateDialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(R.string.dating)
|
||||
|
||||
datingBtn.setOnClickListener {
|
||||
try {
|
||||
var boyP: Double = 0.0
|
||||
var girlP: Double = 0.0
|
||||
var perc: Double = 0.0
|
||||
|
||||
if (boyTxt.text.toString().isEmpty() || boyCb.isChecked) {
|
||||
boyTxt.setText(DataGetter.boy[gen.nextInt(DataGetter.boy.size)])
|
||||
}
|
||||
@@ -425,10 +417,10 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
|
||||
girlTxt.setText(DataGetter.girl[gen.nextInt(DataGetter.girl.size)])
|
||||
}
|
||||
|
||||
boyP = boyTxt.text!!.length.toDouble()
|
||||
girlP = girlTxt.text!!.length.toDouble()
|
||||
val boyP = boyTxt.text!!.length.toDouble()
|
||||
val girlP = girlTxt.text!!.length.toDouble()
|
||||
|
||||
perc = when {
|
||||
var perc = when {
|
||||
girlP < boyP -> (girlP / boyP) * 100
|
||||
else -> (boyP / girlP) * 100
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user