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
+6 -7
View File
@@ -14,24 +14,23 @@ android {
} }
buildTypes { buildTypes {
release { release {
minifyEnabled false minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
// signingConfig signingConfigs.release
} }
} }
} }
dependencies { dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0-alpha04' implementation 'androidx.appcompat:appcompat:1.1.0-alpha05'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0-alpha03' androidTestImplementation 'androidx.test:runner:1.2.0-beta01'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-alpha03' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0-beta01'
implementation 'org.jsoup:jsoup:1.11.3' implementation 'org.jsoup:jsoup:1.11.3'
implementation 'androidx.cardview:cardview:1.0.0' implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha04' implementation 'androidx.recyclerview:recyclerview:1.1.0-alpha05'
implementation 'com.google.android.material:material:1.1.0-alpha05' implementation 'com.google.android.material:material:1.1.0-alpha06'
implementation 'com.android.support:customtabs:28.0.0' implementation 'com.android.support:customtabs:28.0.0'
implementation 'com.jaredrummler:android-device-names:1.1.8' implementation 'com.jaredrummler:android-device-names:1.1.8'
@@ -1,6 +1,9 @@
package com.denizd.substitutionplan package com.denizd.substitutionplan
import android.app.ActivityManager 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.Context
import android.content.Intent import android.content.Intent
import android.content.SharedPreferences import android.content.SharedPreferences
@@ -54,6 +57,8 @@ class Main : AppCompatActivity(R.layout.activity_main) {
edit.putInt("launchDev", prefs.getInt("launchDev", 0) + 1) edit.putInt("launchDev", prefs.getInt("launchDev", 0) + 1)
edit.apply() edit.apply()
notificationJob()
val handler = Handler() val handler = Handler()
val toolbar = findViewById<Toolbar>(R.id.toolbar) val toolbar = findViewById<Toolbar>(R.id.toolbar)
@@ -284,7 +289,7 @@ class Main : AppCompatActivity(R.layout.activity_main) {
}, 600) }, 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) "s", "x", "z" -> prefs.getString("username", "") + getString(R.string.nosplan)
else -> prefs.getString("username", "") + getString(R.string.splan) else -> prefs.getString("username", "") + getString(R.string.splan)
} }
@@ -367,6 +372,17 @@ class Main : AppCompatActivity(R.layout.activity_main) {
return true 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() { override fun onBackPressed() {
if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) { if (bottomSheetBehaviour.state == BottomSheetBehavior.STATE_EXPANDED) {
bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED bottomSheetBehaviour.state = BottomSheetBehavior.STATE_COLLAPSED
@@ -133,7 +133,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
} }
hiddenBtn.setOnLongClickListener { 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, _ -> DeviceName.with(mContext).request { deviceInfo, _ ->
name = deviceInfo.marketName name = deviceInfo.marketName
@@ -350,13 +350,11 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight) else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
} }
val dialogView = LayoutInflater.from(mContext).inflate(R.layout.edittext_dialog, null) 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 dialogEditText = dialogView.findViewById<EditText>(R.id.dialog_edittext)
val dialogButton = dialogView.findViewById<Button>(R.id.dialog_button) val dialogButton = dialogView.findViewById<Button>(R.id.dialog_button)
title.text = getString(R.string.experimentalmenu) dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(R.string.experimentalmenu)
dialogText.text = getString(R.string.fortest) dialogView.findViewById<TextView>(R.id.dialogtext).text = getString(R.string.fortest)
dialogButton.setOnClickListener { dialogButton.setOnClickListener {
when (dialogEditText.text.toString()) { when (dialogEditText.text.toString()) {
"@DIAGNOSTICS" -> { "@DIAGNOSTICS" -> {
@@ -365,12 +363,11 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight) else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
} }
val devDialogView = LayoutInflater.from(mContext).inflate(R.layout.diagnostics_dialog, null) 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 devDialogText = devDialogView.findViewById<TextView>(R.id.dialogtext)
val resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch) val resetLaunchBtn = devDialogView.findViewById<Button>(R.id.btnResetLaunch)
val resetNotifBtn = devDialogView.findViewById<Button>(R.id.btnResetNotif) 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) devDialogText.text = getDiagnosticsText(prefs)
resetLaunchBtn.setOnClickListener { resetLaunchBtn.setOnClickListener {
@@ -402,7 +399,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight) else -> AlertDialog.Builder(mContext, R.style.AlertDialogCustomLight)
} }
val dateDialogView = LayoutInflater.from(mContext).inflate(R.layout.dating_dialog, null) 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 datingBtn = dateDialogView.findViewById<Button>(R.id.dating_btn)
val boyTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt1) val boyTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt1)
val girlTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt2) 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 girlCb = dateDialogView.findViewById<CheckBox>(R.id.cb2)
val percentage = dateDialogView.findViewById<TextView>(R.id.dating_txtp) 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 { datingBtn.setOnClickListener {
try { try {
var boyP: Double = 0.0
var girlP: Double = 0.0
var perc: Double = 0.0
if (boyTxt.text.toString().isEmpty() || boyCb.isChecked) { if (boyTxt.text.toString().isEmpty() || boyCb.isChecked) {
boyTxt.setText(DataGetter.boy[gen.nextInt(DataGetter.boy.size)]) 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)]) girlTxt.setText(DataGetter.girl[gen.nextInt(DataGetter.girl.size)])
} }
boyP = boyTxt.text!!.length.toDouble() val boyP = boyTxt.text!!.length.toDouble()
girlP = girlTxt.text!!.length.toDouble() val girlP = girlTxt.text!!.length.toDouble()
perc = when { var perc = when {
girlP < boyP -> (girlP / boyP) * 100 girlP < boyP -> (girlP / boyP) * 100
else -> (boyP / girlP) * 100 else -> (boyP / girlP) * 100
} }
+2 -1
View File
@@ -190,6 +190,7 @@
android:layout_margin="8dp" android:layout_margin="8dp"
android:text="@string/clearcolour" android:text="@string/clearcolour"
android:textColor="?attr/colorText" android:textColor="?attr/colorText"
app:strokeColor="?attr/colorText"/> app:strokeColor="?attr/colorText"
app:strokeWidth="1dp"/>
</TableLayout> </TableLayout>
+3 -3
View File
@@ -33,7 +33,7 @@
android:id="@+id/txtLayoutName" android:id="@+id/txtLayoutName"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent" app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp" app:boxStrokeWidth="1dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
@@ -211,7 +211,7 @@
android:id="@+id/txtLayoutClasses" android:id="@+id/txtLayoutClasses"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent" app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp" app:boxStrokeWidth="1dp"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginStart="8dp" android:layout_marginStart="8dp"
@@ -262,7 +262,7 @@
android:importantForAutofill="no" android:importantForAutofill="no"
android:textColorHint="?attr/colorHint" android:textColorHint="?attr/colorHint"
app:boxStrokeColor="?attr/colorAccent" app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp" app:boxStrokeWidth="1dp"
app:layout_constraintEnd_toStartOf="@+id/chipHelpCourses" app:layout_constraintEnd_toStartOf="@+id/chipHelpCourses"
app:layout_constraintStart_toStartOf="@+id/txtLayoutClasses" app:layout_constraintStart_toStartOf="@+id/txtLayoutClasses"
app:layout_constraintTop_toBottomOf="@+id/txtLayoutClasses"> app:layout_constraintTop_toBottomOf="@+id/txtLayoutClasses">
@@ -126,6 +126,7 @@
android:text="@string/calculate" android:text="@string/calculate"
android:textColor="@color/datingPink" android:textColor="@color/datingPink"
app:strokeColor="@color/datingPink" app:strokeColor="@color/datingPink"
app:strokeWidth="1dp"
android:layout_gravity="start|center_vertical" android:layout_gravity="start|center_vertical"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/> style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
@@ -42,6 +42,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?attr/colorAccent" android:textColor="?attr/colorAccent"
app:strokeColor="?attr/colorAccent" app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"
android:layout_marginStart="24dp" android:layout_marginStart="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:text="Reset launch counter" android:text="Reset launch counter"
@@ -53,6 +54,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:textColor="?attr/colorAccent" android:textColor="?attr/colorAccent"
app:strokeColor="?attr/colorAccent" app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"
android:layout_marginStart="24dp" android:layout_marginStart="24dp"
android:layout_marginEnd="24dp" android:layout_marginEnd="24dp"
android:layout_marginBottom="16dp" android:layout_marginBottom="16dp"
+3 -2
View File
@@ -39,7 +39,7 @@
<com.google.android.material.textfield.TextInputLayout <com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox" style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="?attr/colorAccent" app:boxStrokeColor="?attr/colorAccent"
app:boxStrokeWidth="2dp" app:boxStrokeWidth="1dp"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"
@@ -66,7 +66,8 @@
android:textColor="?attr/colorAccent" android:textColor="?attr/colorAccent"
android:text="@string/positivebutton" android:text="@string/positivebutton"
style="@style/Widget.MaterialComponents.Button.OutlinedButton" style="@style/Widget.MaterialComponents.Button.OutlinedButton"
app:strokeColor="?attr/colorAccent"/> app:strokeColor="?attr/colorAccent"
app:strokeWidth="1dp"/>
</LinearLayout> </LinearLayout>
@@ -10,6 +10,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
app:strokeColor="?attr/colorText" app:strokeColor="?attr/colorText"
app:strokeWidth="1dp"
android:textColor="?attr/colorText" android:textColor="?attr/colorText"
android:text="@string/clearall" android:text="@string/clearall"
android:layout_marginTop="8dp" android:layout_marginTop="8dp"