diff --git a/.idea/androidDexCompiler.xml b/.idea/androidDexCompiler.xml index f6e673a..5a8b4b2 100644 --- a/.idea/androidDexCompiler.xml +++ b/.idea/androidDexCompiler.xml @@ -1,3 +1,7 @@ - + + + + diff --git a/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlBuilder.kt b/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlBuilder.kt index b246416..b9bd7f8 100644 --- a/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlBuilder.kt +++ b/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlBuilder.kt @@ -19,6 +19,7 @@ along with this program. If not, see package com.silverkeytech.news_engine.outlines import java.util.ArrayList +import android.util.Log public class OpmlBuilder{ class object { @@ -41,10 +42,16 @@ public class OpmlBuilder{ } public class BodyBuilder (val opml : Opml){ + class object { + public val TAG: String = javaClass().getSimpleName() + } + var currentLevel = 0 var currentOutline = Outline() var parentOutline : Outline? = null var parents : ArrayList = ArrayList() + var counterLevelUp = 0 + var counterLevelDown = 0 var rootOutlines : ArrayList? = null { opml.body = Body() @@ -52,6 +59,8 @@ public class OpmlBuilder{ } public fun startLevel(level : Int){ + counterLevelUp++ + Log.d(TAG, "Counter Level Up $counterLevelUp") if (level == 0){ currentLevel = 0 currentOutline = Outline() @@ -80,6 +89,7 @@ public class OpmlBuilder{ } public fun endLevel(level : Int){ + counterLevelDown++ if (level < currentLevel && level > 0){ parentOutline = parents.get(level - 1) currentLevel = level @@ -87,7 +97,12 @@ public class OpmlBuilder{ else if (level == 0){ currentLevel = 0 } + else { + val isEqual = level == currentLevel + Log.d(TAG, "Level $level is equal to $currentLevel $isEqual") + } + Log.d(TAG, "Counter Level Down $counterLevelDown") } public fun setText(text : String) { currentOutline.text = text } diff --git a/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlParser.kt b/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlParser.kt index 23c3440..1b594b7 100644 --- a/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlParser.kt +++ b/NewsEngine/src/com/silverkeytech/news_engine/outlines/OpmlParser.kt @@ -25,10 +25,10 @@ import com.thebuzzmedia.sjxp.rule.DefaultRule import com.silverkeytech.news_engine.xml.attributeRule import com.silverkeytech.news_engine.xml.tagRule -public class OpmlParser{ +public class OpmlParser { public fun parse(input: InputStream, rss: OpmlBuilder) { var items = arrayListOf>(headTitle, headDateCreated, headDateModified, headOwnerName, headOwnerEmail) - for (i in 0..15){ + for (i in 0..15) { items.add(outlineTag(i)) items.add(outlineAttributes(i)) } @@ -39,7 +39,7 @@ public class OpmlParser{ val headTitle = textRule("/opml/head/title", {(text, opml) -> opml.head.setTitle(text) - }) +}) val headDateCreated = textRule("/opml/head/dateCreated", {(text, opml) -> opml.head.setDateCreated(text) @@ -57,9 +57,9 @@ val headOwnerEmail = textRule("/opml/head/ownerEmail", {(text, opml opml.head.setOwnerEmail(text) }) -fun outlineTag(level : Int) : DefaultRule{ +fun outlineTag(level: Int): DefaultRule { if (level < 0) - throw IllegalArgumentException() + throw IllegalArgumentException() var path = "/opml/body" for (i in 0..level) @@ -74,7 +74,7 @@ fun outlineTag(level : Int) : DefaultRule{ } //(path: String, action: (attrName: String, attrValue: String, rss: T) -> Unit, vararg attrNames: String?): DefaultRule -fun outlineAttributes(level : Int) : DefaultRule{ +fun outlineAttributes(level: Int): DefaultRule { if (level < 0) throw IllegalArgumentException() @@ -83,7 +83,7 @@ fun outlineAttributes(level : Int) : DefaultRule{ path += "/outline" return attributeRule(path, { attrName, attrValue, opml -> - when(attrName){ + when(attrName) { "text" -> opml.body.setText(attrValue) "url" -> opml.body.setUrl(attrValue) "xmlUrl" -> opml.body.setXmlUrl(attrValue) @@ -92,7 +92,8 @@ fun outlineAttributes(level : Int) : DefaultRule{ "name" -> opml.body.setName(attrValue) "language" -> opml.body.setLanguage(attrValue) "opmlUrl" -> opml.body.setOpmlUrl(attrValue) - else -> { } //empty + else -> { + } //empty } }, "text", "url", "xmlUrl", "htmlUrl", "type", "name", "language", "opmlUrl") } diff --git a/src/com/silverkeytech/android_rivers/ResizeTextActionMode.kt b/src/com/silverkeytech/android_rivers/ResizeTextActionMode.kt index bcaf522..d200fcf 100644 --- a/src/com/silverkeytech/android_rivers/ResizeTextActionMode.kt +++ b/src/com/silverkeytech/android_rivers/ResizeTextActionMode.kt @@ -29,6 +29,7 @@ public trait WithVisualModificationPanel{ open fun getActivity(): Activity } +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class ResizeTextActionMode (private val parent: WithVisualModificationPanel, private var mode: ActionMode?): ActionMode.Callback{ val INCREASE_SIZE = 1 val DECREASE_SIZE = 2 diff --git a/src/com/silverkeytech/android_rivers/Texts.kt b/src/com/silverkeytech/android_rivers/Texts.kt index f08a1a2..86ec024 100644 --- a/src/com/silverkeytech/android_rivers/Texts.kt +++ b/src/com/silverkeytech/android_rivers/Texts.kt @@ -40,8 +40,8 @@ fun scrubHtml(text: String?): String { if (text.isNullOrEmpty()) return "" else { - val text = text!!.trim().replaceAll("(
|
)", "\n") - val spanned = android.text.Html.fromHtml(text) as SpannableStringBuilder + val txt = text!!.trim().replaceAll("(
|
)", "\n") + val spanned = android.text.Html.fromHtml(txt) as SpannableStringBuilder val spannedObjects = spanned.getSpans(0, spanned.length(), javaClass())!! for(i in 0..(spannedObjects.size - 1)){ diff --git a/src/com/silverkeytech/android_rivers/asyncs/DeleteAllPodcastsAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DeleteAllPodcastsAsync.kt index 3f57da3..7f59f9e 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DeleteAllPodcastsAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DeleteAllPodcastsAsync.kt @@ -30,6 +30,7 @@ import com.silverkeytech.android_rivers.Result import com.silverkeytech.android_rivers.InfinityProgressDialog import com.silverkeytech.android_rivers.R +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DeleteAllPodcastsAsync(it: Context?): AsyncTask>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadBookmarksAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadBookmarksAsync.kt index a07bbaa..2e2fab0 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadBookmarksAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadBookmarksAsync.kt @@ -35,6 +35,7 @@ import com.silverkeytech.android_rivers.Result import com.silverkeytech.android_rivers.R import com.silverkeytech.android_rivers.httpGet +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DownloadBookmarksAsync(it: Context, ignoreCache: Boolean): AsyncTask>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadCollectionAsRiverAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadCollectionAsRiverAsync.kt index 9f9538e..fa66dc7 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadCollectionAsRiverAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadCollectionAsRiverAsync.kt @@ -40,6 +40,7 @@ import com.silverkeytech.android_rivers.PreferenceDefaults import com.silverkeytech.android_rivers.makeLocalUrl import com.silverkeytech.android_rivers.toHoursInMinutes +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DownloadCollectionAsRiverAsync(it: Context?, private val collectionId: Int): AsyncTask>>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadFeedAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadFeedAsync.kt index eaf8ed1..271c16d 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadFeedAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadFeedAsync.kt @@ -35,6 +35,7 @@ import com.silverkeytech.android_rivers.InfinityProgressDialog import com.silverkeytech.android_rivers.daysBeforeNow import com.silverkeytech.android_rivers.PreferenceDefaults +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DownloadFeedAsync(it: Context?, ignoreCache: Boolean): AsyncTask>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadImageAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadImageAsync.kt index 6cae87b..ae48849 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadImageAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadImageAsync.kt @@ -43,6 +43,7 @@ import com.silverkeytech.android_rivers.findView public data class DownloadedFile(val contentType: String, val filePath: String) +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DownloadImageAsync(it: Context?): AsyncTask>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadOpmlAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadOpmlAsync.kt index 1e311ee..6b866c6 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadOpmlAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadOpmlAsync.kt @@ -38,6 +38,7 @@ import com.silverkeytech.android_rivers.PreferenceDefaults import com.silverkeytech.android_rivers.startOutlinerActivity import com.silverkeytech.android_rivers.traverse +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] public class DownloadOpmlAsync(it: Context?): AsyncTask>>(){ class object { public val TAG: String = javaClass().getSimpleName() diff --git a/src/com/silverkeytech/android_rivers/asyncs/DownloadRiverContentAsync.kt b/src/com/silverkeytech/android_rivers/asyncs/DownloadRiverContentAsync.kt index 438fd03..38fb39a 100644 --- a/src/com/silverkeytech/android_rivers/asyncs/DownloadRiverContentAsync.kt +++ b/src/com/silverkeytech/android_rivers/asyncs/DownloadRiverContentAsync.kt @@ -32,6 +32,7 @@ import com.silverkeytech.android_rivers.InfinityProgressDialog import com.silverkeytech.android_rivers.R import com.silverkeytech.android_rivers.downloadSingleRiver +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] //Responsible for handling a river js downloading and display in asynchronous way public class DownloadRiverContentAsync(it: Context?, val language: String): AsyncTask>(){ class object { diff --git a/src/com/silverkeytech/android_rivers/services/PodcastPlayerService.kt b/src/com/silverkeytech/android_rivers/services/PodcastPlayerService.kt index d74b2f2..8a2cd0f 100644 --- a/src/com/silverkeytech/android_rivers/services/PodcastPlayerService.kt +++ b/src/com/silverkeytech/android_rivers/services/PodcastPlayerService.kt @@ -52,8 +52,9 @@ import com.silverkeytech.android_rivers.with import com.silverkeytech.android_rivers.isModernAndroid import com.silverkeytech.android_rivers.Params -public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener, OnAudioFocusChangeListener { - class object{ +[suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE")] +public open class PodcastPlayerService() : Service(), MediaPlayer.OnErrorListener, OnAudioFocusChangeListener { + class object { public val TAG: String = javaClass().getSimpleName() public val CURRENT_POSITION: String = "CURRENT_POSITION" public val TOTAL_DURATION: String = "TOTAL_DURATION" @@ -63,7 +64,7 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener private var mediaPlayer: MediaPlayer? = null private var lastPlayPosition: Int = 0 - inner class ServiceBinder(): Binder() { + inner class ServiceBinder() : Binder() { fun getService(): PodcastPlayerService? { return this@PodcastPlayerService } @@ -93,13 +94,12 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener this.setTextViewText(R.id.notification_podcast_player_status_text, getString(R.string.download_starts)) } - if (isModernAndroid()){ + if (isModernAndroid()) { //workaround on grey background on Android 4.03 https://code.google.com/p/android/issues/detail?id=23863&thanks=23863&ts=1325611036 val id = Resources.getSystem().getIdentifier("status_bar_latest_event_content", "id", "android") notification.contentView?.removeAllViews(id) notification.contentView!!.addView(id, remote) - } - else + } else notification.contentView = remote return notification @@ -133,11 +133,10 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener audioManager = getSystemService(Context.AUDIO_SERVICE) as AudioManager val result = audioManager?.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); - try{ + try { if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { updateText("Sorry, I cannot play $podcastTitle at this moment") - } - else{ + } else { updateText("Playing $podcastTitle") mediaPlayer = MediaPlayer.create(this, Uri.parse(podcastPath!!)) @@ -146,7 +145,7 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener //mediaPlayer?.setVolume(100.0, 100.0) mediaPlayer?.start() - mediaPlayer!!.setOnCompletionListener(object: MediaPlayer.OnCompletionListener{ + mediaPlayer!!.setOnCompletionListener(object: MediaPlayer.OnCompletionListener { public override fun onCompletion(p0: MediaPlayer?) { updateText("Podcast completed") } @@ -156,22 +155,21 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener } progressThread?.start() - } - catch(e: Exception){ + } catch(e: Exception) { Log.d(TAG, "Exception in starting PodcastPlayerService ${e.getMessage()}") } return super.onStartCommand(intent, flags, startId) } - private val progress: Runnable = object : Runnable{ + private val progress: Runnable = object : Runnable { public override fun run() { - try{ + try { Log.d(TAG, "Music progress update trying to start with isPlaying ${isPlaying()}") - while (isPlaying()){ + while (isPlaying()) { Thread.sleep(500) - if (progressHandler != null){ + if (progressHandler != null) { val msg = Message() val bundle = Bundle() bundle.putInt(PodcastPlayerService.CURRENT_POSITION, mediaPlayer!!.getCurrentPosition()) @@ -181,8 +179,7 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener } } Log.d(TAG, "Music progress update stops") - } - catch(e: Exception){ + } catch(e: Exception) { Log.d(TAG, "Exception in progress thread ${e.getMessage()}") } } @@ -194,14 +191,13 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener private var isPausedDueToAudioFocusLoss = false public override fun onAudioFocusChange(p0: Int) { - if (p0 == AUDIOFOCUS_LOSS_TRANSIENT){ - if (isPlaying()) { + if (p0 == AUDIOFOCUS_LOSS_TRANSIENT) { + if (isPlaying()) { this.pauseMusic() isPausedDueToAudioFocusLoss = true } - } - else if (p0 == AudioManager.AUDIOFOCUS_GAIN) { - if (isPaused() && isPausedDueToAudioFocusLoss){ + } else if (p0 == AudioManager.AUDIOFOCUS_GAIN) { + if (isPaused() && isPausedDueToAudioFocusLoss) { this.resumeMusic() isPausedDueToAudioFocusLoss = false } @@ -226,57 +222,53 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener } public fun pauseMusic(): Unit { - try{ - if (mediaPlayer!!.isPlaying()){ + try { + if (mediaPlayer!!.isPlaying()) { mediaPlayer!!.pause() lastPlayPosition = mediaPlayer!!.getCurrentPosition() updateText("$podcastTitle is paused") Log.d(TAG, "$podcastTitle is paused") stopProgressThread() } - } - catch (e: Exception){ + } catch (e: Exception) { Log.d(TAG, "Pause music throws ${e.getMessage()}") } } public fun resumeMusic(): Unit { - try{ - if (!mediaPlayer!!.isPlaying()){ + try { + if (!mediaPlayer!!.isPlaying()) { mediaPlayer?.seekTo(lastPlayPosition) mediaPlayer?.start() updateText("Playing $podcastTitle") Log.d(TAG, "Resume Playing $podcastTitle") restartProgressThread() } - } - catch (e: Exception){ + } catch (e: Exception) { Log.d(TAG, "Resume music throws ${e.getMessage()}") } } private fun restartProgressThread() { - try{ + try { progressThread?.interrupt() progressThread = Thread(progress) progressThread?.start() - } - catch (e: Exception){ + } catch (e: Exception) { Log.d(TAG, "Restart Progress Thread throws ${e.getMessage()}") } } private fun stopProgressThread() { - try{ + try { progressThread?.interrupt() - } - catch (e: Exception){ + } catch (e: Exception) { Log.d(TAG, "Stop Progress Thread throws ${e.getMessage()}") } } public fun stopMusic(): Unit { - try{ + try { mediaPlayer?.stop() mediaPlayer?.release() updateText("$podcastTitle is stopped") @@ -284,8 +276,7 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener stopProgressThread() Log.d(TAG, "Stop playing $podcastTitle and Stopping service") this.stopSelf() - } - catch (e: Exception){ + } catch (e: Exception) { Log.d(TAG, "Stop Music throws ${e.getMessage()}") } } @@ -304,12 +295,11 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener public override fun onDestroy(): Unit { super.onDestroy() - if (mediaPlayer != null){ + if (mediaPlayer != null) { try { mediaPlayer!!.stop() mediaPlayer!!.release() - } - finally { + } finally { mediaPlayer = null } } @@ -317,12 +307,11 @@ public open class PodcastPlayerService(): Service(), MediaPlayer.OnErrorListener public override fun onError(mp: MediaPlayer?, what: Int, extra: Int): Boolean { Toast.makeText(this, "Music player failed", Toast.LENGTH_SHORT).show() - if (mediaPlayer != null){ + if (mediaPlayer != null) { try { mediaPlayer!!.stop() mediaPlayer!!.release() - } - finally { + } finally { mediaPlayer = null } }