Skip to content
This repository has been archived by the owner on Oct 3, 2022. It is now read-only.

Commit

Permalink
Merge pull request #64 from Doomsdayrs/development
Browse files Browse the repository at this point in the history
v1.1.0
  • Loading branch information
Doomsdayrs authored Jan 2, 2020
2 parents 56e5786 + 405184a commit d5e9aae
Show file tree
Hide file tree
Showing 40 changed files with 394 additions and 271 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId 'com.github.doomsdayrs.apps.shosetsu'
minSdkVersion 22
targetSdkVersion 29
versionCode 22
versionName "v1.0.0"
versionCode 23
versionName "v1.1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ object DownloadManager {
/**
* Initializes download manager
*/
@JvmStatic
fun initDownloadManager(activity: Activity) {
if (downloadTask.isCanceled) downloadTask = DownloadTask(activity)
if (Database.DatabaseDownloads.getDownloadCount() >= 1)
Expand All @@ -61,7 +60,6 @@ object DownloadManager {
*
* @param downloadItem download item to add
*/
@JvmStatic
fun addToDownload(activity: Activity?, downloadItem: DownloadItem) {
if (!Database.DatabaseDownloads.inDownloads(downloadItem)) {
Database.DatabaseDownloads.addToDownloads(downloadItem)
Expand All @@ -79,7 +77,6 @@ object DownloadManager {
* @param downloadItem download item to remove
* @return if downloaded
*/
@JvmStatic
fun delete(context: Context?, downloadItem: DownloadItem): Boolean {
Log.d("DeletingChapter", downloadItem.toString())
val file = File(Utilities.shoDir + "/download/" + downloadItem.formatter.formatterID + "/" + downloadItem.novelName + "/" + downloadItem.chapterName + ".txt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import java.util.*
*/
object UpdateManager {
private var chapterUpdater: ChapterUpdater? = null
@JvmStatic
fun init(novelCards: ArrayList<Int>, context: Context) {
if (chapterUpdater == null) {
chapterUpdater = ChapterUpdater(novelCards, context)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import android.util.Log
import android.view.MenuItem
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.github.doomsdayrs.api.shosetsu.services.core.objects.Novel
import com.github.doomsdayrs.api.shosetsu.services.core.objects.NovelChapter
import com.github.doomsdayrs.api.shosetsu.services.core.objects.NovelStatus
import com.github.doomsdayrs.apps.shosetsu.R
Expand All @@ -29,6 +31,7 @@ import com.github.doomsdayrs.apps.shosetsu.variables.enums.Status
import java.io.*
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.collections.ArrayList

/*
* This file is part of Shosetsu.
Expand Down Expand Up @@ -64,6 +67,14 @@ object Utilities {
lateinit var trackingPreferences: SharedPreferences
lateinit var backupPreferences: SharedPreferences

fun convertNovelArrayToString2DArray(array: List<Novel>): ArrayList<Array<String>> {
val a: ArrayList<Array<String>> = ArrayList()
for (novel in array) {
a.add(arrayOf(novel.title, novel.link, novel.imageURL))
}
return a
}

fun regret(context: Context) {
Toast.makeText(context, context.getString(R.string.regret), Toast.LENGTH_LONG).show()
}
Expand Down Expand Up @@ -91,7 +102,6 @@ object Utilities {
* @param input String to clean
* @return string without specials
*/
@JvmStatic
fun cleanString(input: String): String {
return input.replace("[^A-Za-z0-9]".toRegex(), "_")
}
Expand Down Expand Up @@ -140,14 +150,14 @@ object Utilities {
return null
}

/**
* Checks string before deserialization
* If null or empty, returns "". Else deserializes the string and returns
*
* @param string String to be checked
* @return Completed String
*/
@JvmStatic
/**
* Checks string before deserialization
* If null or empty, returns "". Else deserializes the string and returns
*
* @param string String to be checked
* @return Completed String
*/
fun checkStringDeserialize(string: String): String {
if (string.isEmpty()) {
return ""
Expand All @@ -164,14 +174,14 @@ object Utilities {
return ""
}

/**
* Checks string before serialization
* If null or empty, returns "". Else serializes the string and returns
*
* @param string String to be checked
* @return Completed String
*/
@JvmStatic
/**
* Checks string before serialization
* If null or empty, returns "". Else serializes the string and returns
*
* @param string String to be checked
* @return Completed String
*/
fun checkStringSerialize(string: String?): String {
if (string == null || string.isEmpty()) {
return ""
Expand All @@ -185,13 +195,13 @@ object Utilities {
return ""
}

/**
* Converts String Stati back into Stati
*
* @param s String title
* @return Stati
*/
@JvmStatic
/**
* Converts String Stati back into Stati
*
* @param s String title
* @return Stati
*/
fun convertStringToStati(s: String): NovelStatus {
return when (s) {
"Publishing" -> NovelStatus.PUBLISHING
Expand All @@ -202,13 +212,13 @@ object Utilities {
}
}

/**
* Converts Array of Strings into a String
*
* @param a array of strings
* @return String Array
*/
@JvmStatic
/**
* Converts Array of Strings into a String
*
* @param a array of strings
* @return String Array
*/
fun convertArrayToString(a: Array<String?>?): String {
if (a != null && a.isNotEmpty()) {
for (x in a.indices) {
Expand All @@ -219,13 +229,13 @@ object Utilities {
return "[]"
}

/**
* Converts a String Array back into an Array of Strings
*
* @param s String array
* @return Array of Strings
*/
@JvmStatic
/**
* Converts a String Array back into an Array of Strings
*
* @param s String array
* @return Array of Strings
*/
fun convertStringToArray(s: String): Array<String> {
val a = s.substring(1, s.length - 1).split(", ".toRegex()).toTypedArray()
for (x in a.indices) {
Expand Down Expand Up @@ -323,23 +333,19 @@ object Utilities {
return if (activeNetwork != null) activeNetwork.type == ConnectivityManager.TYPE_WIFI || activeNetwork.type == ConnectivityManager.TYPE_MOBILE else false
}//TODO: Check this also, this doesn't seem to be a nice way to do things.

/**
* Is reader in night mode
*
* @return true if so, otherwise false
*/
val isReaderNightMode: Boolean
get() =//TODO: Check this also, this doesn't seem to be a nice way to do things.
Settings.ReaderTextColor == Color.WHITE

fun setNightNode() {
setReaderColor(Color.WHITE, Color.BLACK)
}

fun unsetNightMode() {
fun setLightMode() {
setReaderColor(Color.BLACK, Color.WHITE)
}

fun setSepiaMode(context: Context) {
setReaderColor(Color.BLACK, ContextCompat.getColor(context, R.color.wheat))
}

/**
* Sets the reader color
*
Expand All @@ -355,14 +361,20 @@ object Utilities {
.apply()
}

/**
* Swaps the reader colors
*/
fun swapReaderColor() {
if (isReaderNightMode) {
setReaderColor(Color.BLACK, Color.WHITE)
} else {
setReaderColor(Color.WHITE, Color.BLACK)
fun getReaderColor(context: Context): Int {
return when (Settings.ReaderTextBackgroundColor) {
Color.WHITE -> {
1
}
Color.BLACK -> {
0
}
ContextCompat.getColor(context, R.color.wheat) -> {
2
}
else -> {
1
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public static ArrayList<DownloadItem> getDownloadList() {
String nName = cursor.getString(cursor.getColumnIndex(Columns.NOVEL_NAME.toString()));
String cName = cursor.getString(cursor.getColumnIndex(Columns.CHAPTER_NAME.toString()));
int formatter = DatabaseIdentification.getFormatterIDFromChapterID(id);
downloadItems.add(new DownloadItem(Objects.requireNonNull(DefaultScrapers.getByID(formatter)), nName, cName, id));
downloadItems.add(new DownloadItem(Objects.requireNonNull(DefaultScrapers.Companion.getByID(formatter)), nName, cName, id));
}
cursor.close();

Expand All @@ -422,7 +422,7 @@ public static DownloadItem getFirstDownload() {
String cName = cursor.getString(cursor.getColumnIndex(Columns.CHAPTER_NAME.toString()));
int formatter = getFormatterIDFromChapterID(id);
cursor.close();
return new DownloadItem(Objects.requireNonNull(DefaultScrapers.getByID(formatter)), nName, cName, id);
return new DownloadItem(Objects.requireNonNull(DefaultScrapers.Companion.getByID(formatter)), nName, cName, id);
}
}

Expand All @@ -432,7 +432,7 @@ public static DownloadItem getFirstDownload() {
* @param downloadItem download item to remove
*/
public static void removeDownload(@NonNull DownloadItem downloadItem) {
sqLiteDatabase.delete(Tables.DOWNLOADS.toString(), Columns.PARENT_ID + "=" + DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.chapterURL) + "", null);
sqLiteDatabase.delete(Tables.DOWNLOADS.toString(), Columns.PARENT_ID + "=" + DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.getChapterURL()) + "", null);
}

/**
Expand All @@ -447,9 +447,9 @@ public static void addToDownloads(@NonNull DownloadItem downloadItem) {
Columns.CHAPTER_NAME + "," +
Columns.PAUSED + ") " +
"values (" +
DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.chapterURL) + ",'" +
DownloadItem.cleanse(downloadItem.novelName) + "','" +
DownloadItem.cleanse(downloadItem.chapterName) + "'," + 0 + ")");
DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.getChapterURL()) + ",'" +
DownloadItem.Companion.cleanse(downloadItem.getNovelName()) + "','" +
DownloadItem.Companion.cleanse(downloadItem.getChapterName()) + "'," + 0 + ")");
}

/**
Expand All @@ -459,7 +459,7 @@ public static void addToDownloads(@NonNull DownloadItem downloadItem) {
* @return if is in list
*/
public static boolean inDownloads(@NonNull DownloadItem downloadItem) {
Cursor cursor = sqLiteDatabase.rawQuery("SELECT " + Columns.PARENT_ID + " from " + Tables.DOWNLOADS + " where " + Columns.PARENT_ID + " = " + DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.chapterURL) + "", null);
Cursor cursor = sqLiteDatabase.rawQuery("SELECT " + Columns.PARENT_ID + " from " + Tables.DOWNLOADS + " where " + Columns.PARENT_ID + " = " + DatabaseIdentification.getChapterIDFromChapterURL(downloadItem.getChapterURL()) + "", null);
int a = cursor.getCount();
cursor.close();
return !(a <= 0);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ object WebViewScrapper {
* @param url URL to retrieve;
* @return Document of the URL
*/
@JvmStatic
fun docFromURL(url: String?, cloudflare: Boolean): Document? {
if (url != null) {
Log.i("URL load", url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ class CatalogueSearchQuery(private val catalogueFragment: CatalogueFragment) : S
catalogueFragment.isQuery = true
val recycleCards = ArrayList(catalogueFragment.catalogueNovelCards)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
recycleCards.removeIf { recycleCard: CatalogueNovelCard? -> !recycleCard!!.title.toLowerCase().contains(newText.toLowerCase()) }
recycleCards.removeIf { recycleCard: CatalogueNovelCard? -> !recycleCard!!.title.toLowerCase(Locale.ROOT).contains(newText.toLowerCase(Locale.ROOT)) }
} else {
for (x in recycleCards.indices.reversed()) {
if (!recycleCards[x]!!.title.toLowerCase().contains(newText.toLowerCase())) {
if (!recycleCards[x]!!.title.toLowerCase(Locale.ROOT).contains(newText.toLowerCase(Locale.ROOT))) {
recycleCards.removeAt(x)
}
}
Expand Down
Loading

0 comments on commit d5e9aae

Please sign in to comment.