Notification service added (back?) to Main.kt

This commit is contained in:
Deniz Düzgören
2019-05-16 16:14:03 +02:00
parent b38cd038d4
commit 3119fdac73
9 changed files with 44 additions and 31 deletions
@@ -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
}
+2 -1
View File
@@ -190,6 +190,7 @@
android:layout_margin="8dp"
android:text="@string/clearcolour"
android:textColor="?attr/colorText"
app:strokeColor="?attr/colorText"/>
app:strokeColor="?attr/colorText"
app:strokeWidth="1dp"/>
</TableLayout>
+3 -3
View File
@@ -33,7 +33,7 @@
android:id="@+id/txtLayoutName"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp"
app:boxStrokeWidth="1dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
@@ -211,7 +211,7 @@
android:id="@+id/txtLayoutClasses"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp"
app:boxStrokeWidth="1dp"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
@@ -262,7 +262,7 @@
android:importantForAutofill="no"
android:textColorHint="?attr/colorHint"
app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp"
app:boxStrokeWidth="1dp"
app:layout_constraintEnd_toStartOf="@+id/chipHelpCourses"
app:layout_constraintStart_toStartOf="@+id/txtLayoutClasses"
app:layout_constraintTop_toBottomOf="@+id/txtLayoutClasses">
@@ -126,6 +126,7 @@
android:text="@string/calculate"
android:textColor="@color/datingPink"
app:strokeColor="@color/datingPink"
app:strokeWidth="1dp"
android:layout_gravity="start|center_vertical"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
@@ -42,6 +42,7 @@
android:layout_height="wrap_content"
android:textColor="?attr/colorAccent"
app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:text="Reset launch counter"
@@ -53,6 +54,7 @@
android:layout_height="wrap_content"
android:textColor="?attr/colorAccent"
app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"
android:layout_marginStart="24dp"
android:layout_marginEnd="24dp"
android:layout_marginBottom="16dp"
+3 -2
View File
@@ -39,7 +39,7 @@
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp"
app:boxStrokeWidth="1dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
@@ -66,7 +66,8 @@
android:textColor="?attr/colorAccent"
android:text="@string/positivebutton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="?attr/colorAccent"/>
app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"/>
</LinearLayout>
@@ -10,6 +10,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:strokeColor="?attr/colorText"
app:strokeWidth="1dp"
android:textColor="?attr/colorText"
android:text="@string/clearall"
android:layout_marginTop="8dp"