Fix #1934 Converted constants to Kotlin

This commit is contained in:
Hritik Wadhwa 2020-03-21 16:26:15 +05:30
parent bdd47e1195
commit e90a1dc992
7 changed files with 70 additions and 89 deletions

View File

@ -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));

View File

@ -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<HistoryActivity>(),
Constants.REQUEST_HISTORY_ITEM_CHOSEN
REQUEST_HISTORY_ITEM_CHOSEN
)
}
hostBooks.menuItemClickListener { menuClickListener.onHostBooksMenuClicked() }

View File

@ -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<Unit> {
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()
}

View File

@ -1,77 +0,0 @@
/*
* Kiwix Android
* Copyright (c) 2019 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
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";
}

View File

@ -0,0 +1,54 @@
/*
* Kiwix Android
* Copyright (c) 2020 Kiwix <android.kiwix.org>
* 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 <http://www.gnu.org/licenses/>.
*
*/
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"
}

View File

@ -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 "";
}
}

View File

@ -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) }
}