From e90a1dc992714474e7d20876449b394cc76372f6 Mon Sep 17 00:00:00 2001 From: Hritik Wadhwa Date: Sat, 21 Mar 2020 16:26:15 +0530 Subject: [PATCH] Fix #1934 Converted constants to Kotlin --- .../HotspotNotificationManager.java | 4 +- .../kiwix/kiwixmobile/core/main/MainMenu.kt | 7 +- .../viewmodel/effects/OpenSearchItem.kt | 4 +- .../kiwixmobile/core/utils/Constants.java | 77 ------------------- .../kiwix/kiwixmobile/core/utils/Constants.kt | 54 +++++++++++++ .../kiwixmobile/core/utils/NetworkUtils.java | 4 +- .../effects/SearchIntentProcessingTest.kt | 9 ++- 7 files changed, 70 insertions(+), 89 deletions(-) delete mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.java create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt diff --git a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java index d0f59df2c..3db7a797d 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/webserver/wifi_hotspot/HotspotNotificationManager.java @@ -29,7 +29,7 @@ import androidx.annotation.NonNull; import androidx.core.app.NotificationCompat; import javax.inject.Inject; import org.kiwix.kiwixmobile.R; -import org.kiwix.kiwixmobile.core.utils.Constants; +import static org.kiwix.kiwixmobile.core.utils.Constants.HOTSPOT_SERVICE_CHANNEL_ID; import org.kiwix.kiwixmobile.webserver.ZimHostActivity; public class HotspotNotificationManager { @@ -50,7 +50,7 @@ public class HotspotNotificationManager { private void hotspotNotificationChannel() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { NotificationChannel hotspotServiceChannel = new NotificationChannel( - Constants.HOTSPOT_SERVICE_CHANNEL_ID, + HOTSPOT_SERVICE_CHANNEL_ID, context.getString(R.string.hotspot_service_channel_name), NotificationManager.IMPORTANCE_DEFAULT); hotspotServiceChannel.setDescription(context.getString(R.string.hotspot_channel_description)); diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainMenu.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainMenu.kt index 1a268b34b..9835222b6 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainMenu.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/MainMenu.kt @@ -32,8 +32,9 @@ import org.kiwix.kiwixmobile.core.history.HistoryActivity import org.kiwix.kiwixmobile.core.reader.ZimFileReader import org.kiwix.kiwixmobile.core.search.SearchActivity import org.kiwix.kiwixmobile.core.settings.CoreSettingsActivity -import org.kiwix.kiwixmobile.core.utils.Constants import org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_ZIM_FILE +import org.kiwix.kiwixmobile.core.utils.Constants.REQUEST_PREFERENCES +import org.kiwix.kiwixmobile.core.utils.Constants.REQUEST_HISTORY_ITEM_CHOSEN const val REQUEST_FILE_SEARCH = 1236 @@ -114,13 +115,13 @@ class MainMenu( settings.menuItemClickListener { activity.startActivityForResult( internal(CoreSettingsActivity::class.java), - Constants.REQUEST_PREFERENCES + REQUEST_PREFERENCES ) } history.menuItemClickListener { activity.startActivityForResult( activity.intent(), - Constants.REQUEST_HISTORY_ITEM_CHOSEN + REQUEST_HISTORY_ITEM_CHOSEN ) } hostBooks.menuItemClickListener { menuClickListener.onHostBooksMenuClicked() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItem.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItem.kt index d6726900d..dec470bb2 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItem.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/OpenSearchItem.kt @@ -23,13 +23,13 @@ import android.content.Intent import androidx.appcompat.app.AppCompatActivity import org.kiwix.kiwixmobile.core.base.SideEffect import org.kiwix.kiwixmobile.core.search.adapter.SearchListItem -import org.kiwix.kiwixmobile.core.utils.Constants +import org.kiwix.kiwixmobile.core.utils.Constants.TAG_FILE_SEARCHED data class OpenSearchItem(private val searchListItem: SearchListItem) : SideEffect { override fun invokeWith(activity: AppCompatActivity) { activity.setResult( Activity.RESULT_OK, - Intent().putExtra(Constants.TAG_FILE_SEARCHED, searchListItem.value) + Intent().putExtra(TAG_FILE_SEARCHED, searchListItem.value) ) activity.finish() } diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.java b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.java deleted file mode 100644 index 0f0a902cf..000000000 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.java +++ /dev/null @@ -1,77 +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; - -public final class Constants { - - public static final String TAG_KIWIX = "kiwix"; - - public static final String CONTACT_EMAIL_ADDRESS = "android@kiwix.org"; - - // Request stuff - - public static final int REQUEST_STORAGE_PERMISSION = 1; - - public static final int REQUEST_WRITE_STORAGE_PERMISSION_ADD_NOTE = 3; - - public static final int REQUEST_HISTORY_ITEM_CHOSEN = 99; - - public static final int REQUEST_FILE_SELECT = 1234; - - public static final int REQUEST_PREFERENCES = 1235; - - public static final int BOOKMARK_CHOSEN_REQUEST = 1; - - // Result stuff - public static final int RESULT_RESTART = 1236; - - public static final int RESULT_HISTORY_CLEARED = 1239; - - // Tags - public static final String TAG_FILE_SEARCHED = "searchedarticle"; - - public static final String TAG_CURRENT_FILE = "currentzimfile"; - - public static final String TAG_CURRENT_ARTICLES = "currentarticles"; - - public static final String TAG_CURRENT_POSITIONS = "currentpositions"; - - public static final String TAG_CURRENT_TAB = "currenttab"; - - // Extras - public static final String EXTRA_ZIM_FILE = "zimFile"; - - public static final String EXTRA_CHOSE_X_URL = "choseXURL"; - - public static final String EXTRA_CHOSE_X_TITLE = "choseXTitle"; - - public static final String EXTRA_CHOSE_X_FILE = "choseXFile"; - - public static final String EXTRA_EXTERNAL_LINK = "external_link"; - - public static final String EXTRA_SEARCH = "search"; - - public static final String EXTRA_IS_WIDGET_VOICE = "isWidgetVoice"; - public static final String HOTSPOT_SERVICE_CHANNEL_ID = "hotspotService"; - - public static final String EXTRA_WEBVIEWS_LIST = "webviewsList"; - - public static final String EXTRA_SEARCH_TEXT = "searchText"; - - public static final String OLD_PROVIDER_DOMAIN = "org.kiwix.zim.base"; -} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt new file mode 100644 index 000000000..84197bfaa --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/Constants.kt @@ -0,0 +1,54 @@ +/* + * Kiwix Android + * Copyright (c) 2020 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 + +object Constants { + const val TAG_KIWIX = "kiwix" + const val CONTACT_EMAIL_ADDRESS = "android@kiwix.org"; + + // Request stuff + const val REQUEST_STORAGE_PERMISSION = 1 + const val REQUEST_WRITE_STORAGE_PERMISSION_ADD_NOTE = 3 + const val REQUEST_HISTORY_ITEM_CHOSEN = 99 + const val REQUEST_FILE_SELECT = 1234 + const val REQUEST_PREFERENCES = 1235 + const val BOOKMARK_CHOSEN_REQUEST = 1 + + // Result stuff + const val RESULT_RESTART = 1236 + const val RESULT_HISTORY_CLEARED = 1239 + + // Tags + const val TAG_FILE_SEARCHED = "searchedarticle" + const val TAG_CURRENT_FILE = "currentzimfile" + const val TAG_CURRENT_ARTICLES = "currentarticles" + const val TAG_CURRENT_POSITIONS = "currentpositions" + const val TAG_CURRENT_TAB = "currenttab" + + // Extras + const val EXTRA_ZIM_FILE = "zimFile" + const val EXTRA_CHOSE_X_URL = "choseXURL" + const val EXTRA_CHOSE_X_TITLE = "choseXTitle" + const val EXTRA_CHOSE_X_FILE = "choseXFile" + const val EXTRA_EXTERNAL_LINK = "external_link" + const val EXTRA_SEARCH = "search" + const val EXTRA_IS_WIDGET_VOICE = "isWidgetVoice" + const val HOTSPOT_SERVICE_CHANNEL_ID = "hotspotService" + const val EXTRA_WEBVIEWS_LIST = "webviewsList" + const val OLD_PROVIDER_DOMAIN = "org.kiwix.zim.base" +} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/NetworkUtils.java b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/NetworkUtils.java index bb9a0f2e6..770c0897d 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/utils/NetworkUtils.java +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/utils/NetworkUtils.java @@ -25,6 +25,8 @@ import android.util.Log; import java.util.UUID; import org.kiwix.kiwixmobile.core.R; +import static org.kiwix.kiwixmobile.core.utils.Constants.TAG_KIWIX; + public class NetworkUtils { /** * check availability of any network @@ -115,7 +117,7 @@ public class NetworkUtils { details = details.trim().replaceAll(" +", " "); return details; } catch (Exception e) { - Log.d(Constants.TAG_KIWIX, "Context invalid url: " + url, e); + Log.d(TAG_KIWIX, "Context invalid url: " + url, e); return ""; } } diff --git a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SearchIntentProcessingTest.kt b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SearchIntentProcessingTest.kt index 8d91a2e8b..0008f9bcc 100644 --- a/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SearchIntentProcessingTest.kt +++ b/core/src/test/java/org/kiwix/kiwixmobile/core/search/viewmodel/effects/SearchIntentProcessingTest.kt @@ -32,7 +32,8 @@ import org.junit.jupiter.api.Test import org.kiwix.kiwixmobile.core.search.viewmodel.Action import org.kiwix.kiwixmobile.core.search.viewmodel.Action.Filter import org.kiwix.kiwixmobile.core.search.viewmodel.Action.ReceivedPromptForSpeechInput -import org.kiwix.kiwixmobile.core.utils.Constants +import org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_SEARCH +import org.kiwix.kiwixmobile.core.utils.Constants.EXTRA_IS_WIDGET_VOICE internal class SearchIntentProcessingTest { @@ -65,15 +66,15 @@ internal class SearchIntentProcessingTest { @Test fun `invoke with offers action when EXTRA_SEARCH present`() { val extra = "" - every { intent.hasExtra(Constants.EXTRA_SEARCH) } returns true - every { intent.getStringExtra(Constants.EXTRA_SEARCH) } returns extra + every { intent.hasExtra(EXTRA_SEARCH) } returns true + every { intent.getStringExtra(EXTRA_SEARCH) } returns extra SearchIntentProcessing(intent, actions).invokeWith(activity) verifySequence { actions.offer(Filter(extra)) } } @Test fun `invoke with offers action when EXTRA_IS_WIDGET_VOICE present`() { - every { intent.getBooleanExtra(Constants.EXTRA_IS_WIDGET_VOICE, false) } returns true + every { intent.getBooleanExtra(EXTRA_IS_WIDGET_VOICE, false) } returns true SearchIntentProcessing(intent, actions).invokeWith(activity) verifySequence { actions.offer(ReceivedPromptForSpeechInput) } }