Improved the naming of constant variables to "SCREAMING_SNAKE_CASE," which is our default naming convention for constants.

* Fixed some other ktlint issues.
This commit is contained in:
MohitMaliFtechiz 2025-02-24 12:42:31 +05:30
parent 6721be1764
commit 8527e2070d
15 changed files with 244 additions and 230 deletions

View File

@ -12,6 +12,7 @@ ktlint_standard_function-signature = disabled
ktlint_standard_blank-line-before-declaration = disabled ktlint_standard_blank-line-before-declaration = disabled
ktlint_standard_string-template-indent = disabled ktlint_standard_string-template-indent = disabled
ktlint_standard_multiline-expression-wrapping = disabled ktlint_standard_multiline-expression-wrapping = disabled
ktlint_standard_package-name = disabled
[{*.sht,*.html,*.shtm,*.shtml,*.htm}] [{*.sht,*.html,*.shtm,*.shtml,*.htm}]
indent_style=space indent_style=space

View File

@ -19,118 +19,119 @@ package org.kiwix.kiwixmobile
// @LargeTest // @LargeTest
// @RunWith(AndroidJUnit4.class) // @RunWith(AndroidJUnit4.class)
class ZimTest { /* class ZimTest {
Temporary Disabled //
@Inject // Temporary Disabled
Context context; // @Inject
// Context context;
@Rule //
public ActivityTestRule<KiwixMainActivity> mActivityTestRule = new ActivityTestRule<>( // @Rule
KiwixMainActivity.class, false, false); // public ActivityTestRule<KiwixMainActivity> mActivityTestRule = new ActivityTestRule<>(
// KiwixMainActivity.class, false, false);
@Before public void setUp() { //
TestComponent component = DaggerTestComponent.builder().applicationModule // @Before public void setUp() {
(new ApplicationModule( // TestComponent component = DaggerTestComponent.builder().applicationModule
(CoreApp) getInstrumentation().getTargetContext().getApplicationContext())).build(); // (new ApplicationModule(
// (CoreApp) getInstrumentation().getTargetContext().getApplicationContext())).build();
((CoreApp) getInstrumentation().getTargetContext().getApplicationContext()).setCoreComponent(component); //
// ((CoreApp) getInstrumentation().getTargetContext().getApplicationContext()).setCoreComponent(component);
component.inject(this); //
new ZimContentProvider().setupDagger(); // component.inject(this);
} // new ZimContentProvider().setupDagger();
// }
@Test //
public void zimTest() { // @Test
Intent intent = new Intent(); // public void zimTest() {
File file = new File(context.getFilesDir(), "test.zim"); // Intent intent = new Intent();
try { // File file = new File(context.getFilesDir(), "test.zim");
file.createNewFile(); // try {
} catch (IOException e) { // file.createNewFile();
e.printStackTrace(); // } catch (IOException e) {
} // e.printStackTrace();
intent.setData(Uri.fromFile(file)); // }
// intent.setData(Uri.fromFile(file));
mActivityTestRule.launchActivity(intent); //
// mActivityTestRule.launchActivity(intent);
try { //
onView(withId(R.id.menu_home)).perform(click()); // try {
} catch (NoMatchingViewException e) { // onView(withId(R.id.menu_home)).perform(click());
openContextualActionModeOverflowMenu(); // } catch (NoMatchingViewException e) {
onView(withText("Home")).perform(click()); // openContextualActionModeOverflowMenu();
} // onView(withText("Home")).perform(click());
onWebView().withElement(findElement(Locator.LINK_TEXT, "A Fool for You")); // }
// onWebView().withElement(findElement(Locator.LINK_TEXT, "A Fool for You"));
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT)); //
// onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT));
ViewInteraction textView = onView( //
allOf(withId(R.id.titleText), withText("Summary"), // ViewInteraction textView = onView(
childAtPosition( // allOf(withId(R.id.titleText), withText("Summary"),
childAtPosition( // childAtPosition(
withId(R.id.right_drawer_list), // childAtPosition(
0), // withId(R.id.right_drawer_list),
0), // 0),
isDisplayed())); // 0),
textView.check(matches(withText("Summary"))); // isDisplayed()));
// textView.check(matches(withText("Summary")));
onView(withId(R.id.drawer_layout)).perform(DrawerActions.close(Gravity.RIGHT)); //
// onView(withId(R.id.drawer_layout)).perform(DrawerActions.close(Gravity.RIGHT));
onWebView().withElement(findElement(Locator.LINK_TEXT, "A Fool for You")).perform(webClick()); //
// onWebView().withElement(findElement(Locator.LINK_TEXT, "A Fool for You")).perform(webClick());
onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT)); //
// onView(withId(R.id.drawer_layout)).perform(DrawerActions.open(Gravity.RIGHT));
ViewInteraction textView2 = onView( //
allOf(withId(R.id.titleText), withText("A Fool for You"), // ViewInteraction textView2 = onView(
childAtPosition( // allOf(withId(R.id.titleText), withText("A Fool for You"),
childAtPosition( // childAtPosition(
withId(R.id.right_drawer_list), // childAtPosition(
0), // withId(R.id.right_drawer_list),
0), // 0),
isDisplayed())); // 0),
textView2.check(matches(withText("A Fool for You"))); // isDisplayed()));
// textView2.check(matches(withText("A Fool for You")));
ViewInteraction textView3 = onView( //
allOf(withId(R.id.titleText), withText("Personnel"), // ViewInteraction textView3 = onView(
childAtPosition( // allOf(withId(R.id.titleText), withText("Personnel"),
childAtPosition( // childAtPosition(
withId(R.id.right_drawer_list), // childAtPosition(
1), // withId(R.id.right_drawer_list),
0), // 1),
isDisplayed())); // 0),
textView3.check(matches(withText("Personnel"))); // isDisplayed()));
// textView3.check(matches(withText("Personnel")));
ViewInteraction textView4 = onView( //
allOf(withId(R.id.titleText), withText("Covers"), // ViewInteraction textView4 = onView(
childAtPosition( // allOf(withId(R.id.titleText), withText("Covers"),
childAtPosition( // childAtPosition(
withId(R.id.right_drawer_list), // childAtPosition(
2), // withId(R.id.right_drawer_list),
0), // 2),
isDisplayed())); // 0),
textView4.check(matches(withText("Covers"))); // isDisplayed()));
// textView4.check(matches(withText("Covers")));
openContextualActionModeOverflowMenu(); //
// openContextualActionModeOverflowMenu();
onView(withText("Help")) //
.perform(click()); // onView(withText("Help"))
} // .perform(click());
// }
private static Matcher<View> childAtPosition( //
final Matcher<View> parentMatcher, final int position) { // private static Matcher<View> childAtPosition(
// final Matcher<View> parentMatcher, final int position) {
return new TypeSafeMatcher<View>() { //
@Override // return new TypeSafeMatcher<View>() {
public void describeTo(Description description) { // @Override
description.appendText("Child at position " + position + " in parent "); // public void describeTo(Description description) {
parentMatcher.describeTo(description); // description.appendText("Child at position " + position + " in parent ");
} // parentMatcher.describeTo(description);
// }
@Override //
public boolean matchesSafely(View view) { // @Override
ViewParent parent = view.getParent(); // public boolean matchesSafely(View view) {
return parent instanceof ViewGroup && parentMatcher.matches(parent) // ViewParent parent = view.getParent();
&& view.equals(((ViewGroup) parent).getChildAt(position)); // return parent instanceof ViewGroup && parentMatcher.matches(parent)
} // && view.equals(((ViewGroup) parent).getChildAt(position));
}; // }
} // };
*/ // }
//
} }

View File

@ -61,9 +61,9 @@ import javax.inject.Singleton
object TestUtils { object TestUtils {
private const val TAG = "TESTUTILS" private const val TAG = "TESTUTILS"
@JvmField var TEST_PAUSE_MS = 3000 const val TEST_PAUSE_MS = 3000
var TEST_PAUSE_MS_FOR_SEARCH_TEST = 1000 const val TEST_PAUSE_MS_FOR_SEARCH_TEST = 1000
var TEST_PAUSE_MS_FOR_DOWNLOAD_TEST = 10000 const val TEST_PAUSE_MS_FOR_DOWNLOAD_TEST = 10000
const val RETRY_COUNT_FOR_FLAKY_TEST = 3 const val RETRY_COUNT_FOR_FLAKY_TEST = 3
/* /*

View File

@ -40,9 +40,9 @@ import javax.inject.Inject
class IntroFragment : BaseFragment(), IntroContract.View, FragmentActivityExtensions { class IntroFragment : BaseFragment(), IntroContract.View, FragmentActivityExtensions {
companion object { companion object {
private const val timerDelay: Long = 0 private const val TIMER_DELAY: Long = 0
private const val timerPeriod: Long = 2000 private const val TIMER_PERIOD: Long = 2000
private const val animationDuration: Long = 800 private const val ANIMATION_DURATION: Long = 800
} }
private val handler = Handler(Looper.getMainLooper()) private val handler = Handler(Looper.getMainLooper())
@ -83,8 +83,8 @@ class IntroFragment : BaseFragment(), IntroContract.View, FragmentActivityExtens
} }
} }
}, },
timerDelay, TIMER_DELAY,
timerPeriod TIMER_PERIOD
) )
views.forEach { views.forEach {
it.setOnClickListener { dismissAutoRotate() } it.setOnClickListener { dismissAutoRotate() }
@ -123,7 +123,7 @@ class IntroFragment : BaseFragment(), IntroContract.View, FragmentActivityExtens
val airplane = views[1].findViewById<ImageView>(R.id.airplane) ?: return val airplane = views[1].findViewById<ImageView>(R.id.airplane) ?: return
airplane.isVisible = position == 1 airplane.isVisible = position == 1
if (position == 1) { if (position == 1) {
airplane.animate().translationX(airplane.width.toFloat()).duration = animationDuration airplane.animate().translationX(airplane.width.toFloat()).duration = ANIMATION_DURATION
} else { } else {
airplane.animate().translationX(-airplane.width.toFloat()) airplane.animate().translationX(-airplane.width.toFloat())
} }

View File

@ -28,7 +28,8 @@ data class BookmarkEntity(
@Id var id: Long = 0, @Id var id: Long = 0,
val zimId: String, val zimId: String,
var zimName: String, var zimName: String,
var zimFilePath: String?, // keep this to handle previously saved bookmarks // keep this to handle previously saved bookmarks
var zimFilePath: String?,
@Convert(converter = ZimSourceConverter::class, dbType = String::class) @Convert(converter = ZimSourceConverter::class, dbType = String::class)
var zimReaderSource: ZimReaderSource?, var zimReaderSource: ZimReaderSource?,
var bookmarkUrl: String, var bookmarkUrl: String,
@ -39,7 +40,8 @@ data class BookmarkEntity(
item.databaseId, item.databaseId,
item.zimId, item.zimId,
item.zimName, item.zimName,
null, // pass null for new bookmarks // pass null for new bookmarks
null,
item.zimReaderSource, item.zimReaderSource,
item.bookmarkUrl, item.bookmarkUrl,
item.title, item.title,

View File

@ -28,7 +28,8 @@ data class HistoryEntity(
@Id var id: Long = 0L, @Id var id: Long = 0L,
val zimId: String, val zimId: String,
val zimName: String, val zimName: String,
val zimFilePath: String?, // keep this to handle previously saved history // keep this to handle previously saved history
val zimFilePath: String?,
@Convert(converter = ZimSourceConverter::class, dbType = String::class) @Convert(converter = ZimSourceConverter::class, dbType = String::class)
var zimReaderSource: ZimReaderSource?, var zimReaderSource: ZimReaderSource?,
val favicon: String?, val favicon: String?,
@ -41,7 +42,8 @@ data class HistoryEntity(
historyItem.databaseId, historyItem.databaseId,
historyItem.zimId, historyItem.zimId,
historyItem.zimName, historyItem.zimName,
null, // pass null for new history items // pass null for new history items
null,
historyItem.zimReaderSource, historyItem.zimReaderSource,
historyItem.favicon, historyItem.favicon,
historyItem.historyUrl, historyItem.historyUrl,

View File

@ -28,7 +28,8 @@ import org.kiwix.kiwixmobile.core.reader.ZimReaderSource
data class NotesEntity( data class NotesEntity(
@Id var id: Long = 0L, @Id var id: Long = 0L,
val zimId: String, val zimId: String,
var zimFilePath: String?, // keep this to handle previously saved notes // keep this to handle previously saved notes
var zimFilePath: String?,
@Convert(converter = ZimSourceConverter::class, dbType = String::class) @Convert(converter = ZimSourceConverter::class, dbType = String::class)
var zimReaderSource: ZimReaderSource?, var zimReaderSource: ZimReaderSource?,
val zimUrl: String, val zimUrl: String,
@ -39,7 +40,8 @@ data class NotesEntity(
constructor(item: NoteListItem) : this( constructor(item: NoteListItem) : this(
id = item.databaseId, id = item.databaseId,
zimId = item.zimId, zimId = item.zimId,
zimFilePath = null, // pass null for new notes // pass null for new notes
zimFilePath = null,
zimReaderSource = item.zimReaderSource, zimReaderSource = item.zimReaderSource,
zimUrl = item.zimUrl, zimUrl = item.zimUrl,
noteTitle = item.title, noteTitle = item.title,

View File

@ -30,7 +30,8 @@ data class NotesRoomEntity(
@PrimaryKey(autoGenerate = true) @PrimaryKey(autoGenerate = true)
var id: Long = 0L, var id: Long = 0L,
val zimId: String, val zimId: String,
var zimFilePath: String?, // keep this to handle previously saved notes // keep this to handle previously saved notes
var zimFilePath: String?,
@TypeConverters(ZimSourceRoomConverter::class) @TypeConverters(ZimSourceRoomConverter::class)
var zimReaderSource: ZimReaderSource?, var zimReaderSource: ZimReaderSource?,
val zimUrl: String, val zimUrl: String,

View File

@ -143,22 +143,22 @@ open class ErrorActivity : BaseActivity() {
// List of supported email apps // List of supported email apps
private val supportedEmailPackages = private val supportedEmailPackages =
listOf( listOf(
"com.google.android.gm", // Gmail "com.google.android.gm",
"com.zoho.mail", // Zoho Mail "com.zoho.mail",
"com.microsoft.office.outlook", // Outlook "com.microsoft.office.outlook",
"com.yahoo.mobile.client.android.mail", // Yahoo Mail "com.yahoo.mobile.client.android.mail",
"me.bluemail.mail", // BlueMail "me.bluemail.mail",
"ch.protonmail.android", // ProtonMail "ch.protonmail.android",
"com.fsck.k9", // K-9 Mail "com.fsck.k9",
"com.maildroid", // Maildroid "com.maildroid",
"org.kman.AquaMail", // Aqua Mail "org.kman.AquaMail",
"com.edison.android.mail", // Edison Mail "com.edison.android.mail",
"com.readdle.spark", // Spark "com.readdle.spark",
"com.gmx.mobile.android.mail", // GMX Mail "com.gmx.mobile.android.mail",
"com.fastmail", // FastMail "com.fastmail",
"ru.mail.mailapp", // Mail.ru "ru.mail.mailapp",
"ru.yandex.mail", // Yandex.Mail "ru.yandex.mail",
"de.tutao.tutanota" // Tutanota "de.tutao.tutanota"
) )
private val sendEmailLauncher = private val sendEmailLauncher =

View File

@ -67,7 +67,6 @@ import javax.inject.Inject
* Notes are saved as text files at location: "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt" * Notes are saved as text files at location: "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt"
*/ */
// constant
const val DISABLE_ICON_ITEM_ALPHA = 130 const val DISABLE_ICON_ITEM_ALPHA = 130
const val ENABLE_ICON_ITEM_ALPHA = 255 const val ENABLE_ICON_ITEM_ALPHA = 255

View File

@ -30,5 +30,7 @@ data class BookmarkState(
) : PageState<LibkiwixBookmarkItem>() { ) : PageState<LibkiwixBookmarkItem>() {
override val visiblePageItems: List<PageRelated> = filteredPageItems override val visiblePageItems: List<PageRelated> = filteredPageItems
override fun copyWithNewItems(newItems: List<LibkiwixBookmarkItem>): PageState<LibkiwixBookmarkItem> = copy(pageItems = newItems) override fun copyWithNewItems(
newItems: List<LibkiwixBookmarkItem>
): PageState<LibkiwixBookmarkItem> = copy(pageItems = newItems)
} }

View File

@ -48,7 +48,9 @@ class LanguageUtils(private val context: Context) {
.map { locale -> locale.trim { it <= ' ' } } .map { locale -> locale.trim { it <= ' ' } }
} }
private fun sortWithCollator(languageCodesFromAssets: MutableList<LanguageContainer>): MutableList<LanguageContainer> { private fun sortWithCollator(
languageCodesFromAssets: MutableList<LanguageContainer>
): MutableList<LanguageContainer> {
val localeCollator = val localeCollator =
Collator.getInstance(context.locale).apply { strength = Collator.SECONDARY } Collator.getInstance(context.locale).apply { strength = Collator.SECONDARY }
languageCodesFromAssets.sortWith( languageCodesFromAssets.sortWith(

View File

@ -42,10 +42,11 @@ object NetworkUtils {
* check if network of type WIFI is connected * check if network of type WIFI is connected
* *
* @return true if WIFI is connected * @return true if WIFI is connected
*
* TODO method isWiFi should be renamed to isWifiConnected to
* express the state which is checked
* (postponed to refactoring deprecated android.net.* usage)
*/ */
// TODO method isWiFi should be renamed to isWifiConnected to
// express the state which is checked
// (postponed to refactoring deprecated android.net.* usage)
fun isWiFi(context: Context): Boolean { fun isWiFi(context: Context): Boolean {
val connectivity = val connectivity =
context context

View File

@ -37,13 +37,12 @@ import org.kiwix.kiwixmobile.core.extensions.getAttribute
import org.kiwix.kiwixmobile.core.utils.StyleUtils.fromHtml import org.kiwix.kiwixmobile.core.utils.StyleUtils.fromHtml
import javax.inject.Inject import javax.inject.Inject
class AlertDialogShower @Inject constructor(private val activity: Activity) : class AlertDialogShower @Inject constructor(private val activity: Activity) : DialogShower {
DialogShower {
companion object { companion object {
const val externalLinkLeftMargin = 10 const val EXTERNAL_LINK_LEFT_MARGIN = 10
const val externalLinkRightMargin = 10 const val EXTERNAL_LINK_RIGHT_MARGIN = 10
const val externalLinkTopMargin = 10 const val EXTERNAL_LINK_TOP_MARGIN = 10
const val externalLinkBottomMargin = 0 const val EXTERNAL_LINK_BOTTOM_MARGIN = 0
} }
override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit, uri: Uri?) = override fun show(dialog: KiwixDialog, vararg clickListeners: () -> Unit, uri: Uri?) =
@ -108,10 +107,10 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT LayoutParams.WRAP_CONTENT
).apply { ).apply {
topMargin = externalLinkTopMargin topMargin = EXTERNAL_LINK_TOP_MARGIN
bottomMargin = externalLinkBottomMargin bottomMargin = EXTERNAL_LINK_BOTTOM_MARGIN
leftMargin = externalLinkLeftMargin leftMargin = EXTERNAL_LINK_LEFT_MARGIN
rightMargin = externalLinkRightMargin rightMargin = EXTERNAL_LINK_RIGHT_MARGIN
} }
private fun bodyArguments(dialog: KiwixDialog) = private fun bodyArguments(dialog: KiwixDialog) =
@ -120,4 +119,4 @@ class AlertDialogShower @Inject constructor(private val activity: Activity) :
} else { } else {
emptyArray() emptyArray()
} }
} }

View File

@ -25,9 +25,11 @@ import java.lang.System.currentTimeMillis
import javax.inject.Inject import javax.inject.Inject
import javax.inject.Singleton import javax.inject.Singleton
/** Authored by s-ayush2903 on 19 June 2020 */ /**
* Authored by s-ayush2903 on 19 June 2020
/** A class for writing logs to the file in the device */ *
* A class for writing logs to the file in the device
*/
@Singleton @Singleton
class FileLogger @Inject constructor() { class FileLogger @Inject constructor() {
fun writeLogFile(context: Context, shouldWriteDeviceLogs: Boolean = true): File { fun writeLogFile(context: Context, shouldWriteDeviceLogs: Boolean = true): File {