From 7df5ab19bb9caff9ad26fcac406ed4383f6eb955 Mon Sep 17 00:00:00 2001 From: gouri-panda Date: Fri, 4 Sep 2020 16:05:28 +0530 Subject: [PATCH] #2342 Converted RateAppCounter.java to kotlin --- .../core/utils/dialog/RateAppCounter.java | 55 ------------------- .../core/utils/dialog/RateAppCounter.kt | 51 +++++++++++++++++ 2 files changed, 51 insertions(+), 55 deletions(-) delete mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.kt diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java deleted file mode 100644 index c75e9d057..000000000 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.core.utils.dialog; - -import android.content.Context; -import android.content.SharedPreferences; - -public class RateAppCounter { - - private static final String MASTER_NAME = "visitCounter"; - private static final String NOTHANKS_CLICKED = "clickedNoThanks"; - - private SharedPreferences visitCounter; - - RateAppCounter(Context context) { - visitCounter = context.getSharedPreferences(MASTER_NAME, 0); - visitCounter = context.getSharedPreferences(NOTHANKS_CLICKED, 0); - } - - public boolean getNoThanksState() { - return visitCounter.getBoolean(NOTHANKS_CLICKED, false); - } - - public void setNoThanksState(boolean val) { - SharedPreferences.Editor CounterEditor = visitCounter.edit(); - CounterEditor.putBoolean(NOTHANKS_CLICKED, val); - CounterEditor.apply(); - } - - public int getCount() { - return visitCounter.getInt("count", 0); - } - - public void setCount(int count) { - SharedPreferences.Editor CounterEditor = visitCounter.edit(); - CounterEditor.putInt("count", count); - CounterEditor.apply(); - } -} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.kt new file mode 100644 index 000000000..fc934bf22 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/dialog/RateAppCounter.kt @@ -0,0 +1,51 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.kiwix.kiwixmobile.core.utils.dialog + +import android.content.Context +import android.content.SharedPreferences + +class RateAppCounter internal constructor(context: Context) { + private var visitCounter: SharedPreferences + + init { + visitCounter = context.getSharedPreferences(NO_THANKS_CLICKED, 0) + } + + var noThanksState: Boolean + get() = visitCounter.getBoolean(NO_THANKS_CLICKED, false) + set(value) { + visitCounter.edit().apply { + putBoolean(NO_THANKS_CLICKED, value) + apply() + } + } + + var count: Int + get() = visitCounter.getInt("count", 0) + set(count) { + visitCounter.edit().apply { + putInt("count", count) + apply() + } + } + + companion object { + private const val NO_THANKS_CLICKED = "clickedNoThanks" + } +}