Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrated some of the files to kotlin. #348

Merged
merged 3 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ android {
versionCode 23_05_23_003
versionName "2023.05.23.3"

setProperty("archivesBaseName", versionName)

resValue "string", "app_name", "QuranApp"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class ActivityAbout : BaseActivity() {

private fun initHeader(header: BoldHeader) {
header.let {
it.setCallback { onBackPressed() }
it.setCallback { onBackPressedDispatcher.onBackPressed() }
it.setTitleText(R.string.strTitleAboutUs)
it.setShowRightIcon(false)
it.setShowSearchIcon(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.GridLayoutManager;
Expand Down Expand Up @@ -117,7 +118,7 @@ private void initHeader(BoldHeader header) {
header.setCallback(new BoldHeader.BoldHeaderCallback() {
@Override
public void onBackIconClick() {
onBackPressed();
getOnBackPressedDispatcher().onBackPressed();
}

@Override
Expand All @@ -137,8 +138,8 @@ public void onRightIconClick() {
private void deleteAllWithCheckpoint() {
boolean isSelecting = mAdapter != null && mAdapter.mIsSelecting && !mAdapter.mSelectedModels.isEmpty();
String title = isSelecting ? getString(R.string.strTitleBookmarkDeleteCount,
mAdapter.mSelectedModels.size()) : getString(
R.string.strTitleBookmarkDeleteAll);
mAdapter.mSelectedModels.size()) : getString(
R.string.strTitleBookmarkDeleteAll);
int dec = isSelecting ? R.string.strMsgBookmarkDeleteSelected : R.string.strMsgBookmarkDeleteAll;
int labelNeg = isSelecting ? R.string.strLabelRemove : R.string.strLabelRemoveAll;

Expand Down Expand Up @@ -230,7 +231,7 @@ public void onView(BookmarkModel model, int position) {

public void onOpen(BookmarkModel model) {
Intent intent = ReaderFactory.prepareVerseRangeIntent(model.getChapterNo(), model.getFromVerseNo(),
model.getToVerseNo());
model.getToVerseNo());
intent.setClass(this, ActivityReader.class);
startActivity(intent);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,14 +218,14 @@ private void bindTitle(LytReferenceVerseTitleBinding binding, ReferenceVerseItem

@Override
public void onBookmarkRemoved(BookmarkModel model) {
int adapterPosition = getAdapterPosition();
int adapterPosition = getBindingAdapterPosition();
mVerseModels.get(adapterPosition).setBookmarked(false);
notifyItemChanged(adapterPosition);
}

@Override
public void onBookmarkAdded(BookmarkModel model) {
int adapterPosition = getAdapterPosition();
int adapterPosition = getBindingAdapterPosition();
mVerseModels.get(adapterPosition).setBookmarked(true);
notifyItemChanged(adapterPosition);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ADPScriptCleanup(
fileUtils.getKFQPCScriptFontDir(model.scriptKey).deleteRecursively()

model.isCleared = true
notifyItemChanged(adapterPosition)
notifyItemChanged(bindingAdapterPosition)
}
setFocusOnNegative(true)
}.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class ADPTafsirCleanup(
setNegativeButton(R.string.strLabelDelete, ColorUtils.DANGER) { _, _ ->
File(fileUtils.tafsirDir, model.tafsirModel.key).deleteRecursively()
model.isCleared = true
notifyItemChanged(adapterPosition)
notifyItemChanged(bindingAdapterPosition)
}
setFocusOnNegative(true)
}.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ class ADPTranslationCleanup(ctx: Context, private val items: List<TranslBaseMode
QuranTranslationFactory(itemView.context).use {
it.deleteTranslation(bookInfo.slug)
model.isDeleted = true
notifyItemChanged(adapterPosition)
notifyItemChanged(bindingAdapterPosition)
}
}
setFocusOnNegative(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class ADPTafsirGroup(private val models: List<TafsirGroupModel>) :

it.setOnClickListener {
group.isExpanded = !group.isExpanded
notifyItemChanged(adapterPosition)
notifyItemChanged(bindingAdapterPosition)
}
}

Expand All @@ -56,7 +56,7 @@ class ADPTafsirGroup(private val models: List<TafsirGroupModel>) :
}
}

models[adapterPosition].tafsirs[changedIndex].isChecked = true
models[bindingAdapterPosition].tafsirs[changedIndex].isChecked = true
notifyDataSetChanged()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class ADPDownloadTranslationsGroup(

it.setOnClickListener {
group.isExpanded = !group.isExpanded
notifyItemChanged(adapterPosition)
notifyItemChanged(bindingAdapterPosition)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class FragSettingsScripts : FragSettingsBase(), ServiceConnection {
override fun setupHeader(activity: ActivitySettings, header: BoldHeader) {
super.setupHeader(activity, header)
header.apply {
setCallback { activity.onBackPressed() }
setCallback { activity.onBackPressedDispatcher.onBackPressed() }
disableRightBtn(true)
setShowSearchIcon(false)
setShowRightIcon(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void setupHeader(ActivitySettings activity, BoldHeader header) {
header.setCallback(new BoldHeader.BoldHeaderCallback() {
@Override
public void onBackIconClick() {
activity.onBackPressed();
activity.getOnBackPressedDispatcher().onBackPressed();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class FragSettingsTranslationsDownload :

if (isTranslationDownloading(bookInfo.slug)) {
model.isDownloading = true
adapter.notifyItemChanged(vhTransl.adapterPosition)
adapter.notifyItemChanged(vhTransl.bindingAdapterPosition)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,18 @@ class FragAppLogsCrash : BaseFragment() {
files.sortedByDescending { it.lastModified() }.forEach { logFile ->
val log = logFile.readText()
val logShort = if (log.length > 200) log.substring(0, 200) + "... ${log.length - 200} more chars" else log
val formattedDateTime = DateUtils.format(
DateUtils.toDate(logFile.name, Log.FILE_NAME_DATE_FORMAT),
DateUtils.DATETIME_FORMAT_USER
)

val parsedDate = DateUtils.toDate(logFile.name, Log.FILE_NAME_DATE_FORMAT)
val formattedDateTime = if (parsedDate != null) DateUtils.format(parsedDate, DateUtils.DATETIME_FORMAT_USER) else logFile.name

logs.add(
AppLogModel(
formattedDateTime,
"Fatal Crash",
logFile,
log,
logShort,
)
AppLogModel(
formattedDateTime,
"Fatal Crash",
logFile,
log,
logShort,
)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,17 @@ class FragAppLogsSuppressed : BaseFragment() {
val (datetimeStr, place) = logFile.nameWithoutExtension.split("@")
val log = logFile.readText()
val logShort = if (log.length > 200) log.substring(0, 200) + "... ${log.length - 200} more chars" else log
val formattedDateTime = DateUtils.format(
DateUtils.toDate(datetimeStr, Log.FILE_NAME_DATE_FORMAT),
DateUtils.DATETIME_FORMAT_USER
)
val parsedDate = DateUtils.toDate(datetimeStr, Log.FILE_NAME_DATE_FORMAT)
val formattedDateTime = if (parsedDate != null) DateUtils.format(parsedDate, DateUtils.DATETIME_FORMAT_USER) else datetimeStr

logs.add(
AppLogModel(
formattedDateTime,
place,
logFile,
log,
logShort,
)
AppLogModel(
formattedDateTime,
place,
logFile,
log,
logShort,
)
)
}

Expand Down

This file was deleted.

32 changes: 19 additions & 13 deletions app/src/main/java/com/quranapp/android/utils/app/InfoUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package com.quranapp.android.utils.app
import android.content.Context
import android.content.DialogInterface
import android.net.Uri
import androidx.browser.customtabs.CustomTabColorSchemeParams
import androidx.browser.customtabs.CustomTabsIntent
import androidx.core.content.ContextCompat
import com.quranapp.android.R
Expand Down Expand Up @@ -53,15 +54,15 @@ object InfoUtils {
if (e !is CancellationException) {
Logger.reportError(e)
MessageUtils.popMessage(
context,
context.getString(R.string.strMsgSomethingWrong),
"${context.getString(R.string.strMsgCouldNotOpenPage)} ${
context.getString(
R.string.strMsgTryLater
)
}",
context.getString(R.string.strLabelClose),
null
context,
context.getString(R.string.strMsgSomethingWrong),
"${context.getString(R.string.strMsgCouldNotOpenPage)} ${
context.getString(
R.string.strMsgTryLater
)
}",
context.getString(R.string.strLabelClose),
null
)
}
}
Expand All @@ -85,10 +86,15 @@ object InfoUtils {
}

private fun prepareCustomTab(context: Context): CustomTabsIntent {
val colorSchemeParams = CustomTabColorSchemeParams.Builder()
.setToolbarColor(ContextCompat.getColor(context, R.color.colorBGPage))
.setNavigationBarColor(ContextCompat.getColor(context, R.color.colorBGPage))
.build()

return CustomTabsIntent.Builder()
.setToolbarColor(ContextCompat.getColor(context, R.color.colorBGPage))
.setShowTitle(true)
.setUrlBarHidingEnabled(true)
.build()
.setDefaultColorSchemeParams(colorSchemeParams)
.setShowTitle(true)
.setUrlBarHidingEnabled(true)
.build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ public void openReference(int chapterNo, int fromVerse, int toVerse) {
QuranMeta quranMeta = mActivity.mQuranMeta;

if (!QuranMeta.isChapterValid(chapterNo) || !quranMeta.isVerseRangeValid4Chapter(chapterNo, fromVerse,
toVerse)) {
toVerse)) {
Log.d(chapterNo, fromVerse, toVerse);
MessageUtils.showRemovableToast(mActivity, "Could not open references", Toast.LENGTH_LONG);
MessageUtils.INSTANCE.showRemovableToast(mActivity, "Could not open references", Toast.LENGTH_LONG);
return;
}

mActivity.showReferenceSingleVerseOrRange(
TranslUtils.defaultTranslationSlugs(),
chapterNo, new Pair<>(fromVerse, toVerse)
TranslUtils.defaultTranslationSlugs(),
chapterNo, new Pair<>(fromVerse, toVerse)
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* Copyright (c) Faisal Khan (https://github.com/faisalcodes)
* Created on 1/4/2022.
* All rights reserved.
*/
package com.quranapp.android.utils.exceptions

class HttpNotFoundException @JvmOverloads constructor(msg: String? = "Not found") : RuntimeException(msg)
Loading