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

Commit

Permalink
Merge branch 'master' of https://github.com/inorichi/tachiyomi
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	app/build.gradle
#	app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt
#	app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt
#	app/src/main/res/layout/manga_info_controller.xml
#	app/src/main/res/raw/changelog_release.xml
  • Loading branch information
NerdNumber9 committed Mar 13, 2018
2 parents 87a2ac7 + 0d5b8ed commit 615fa05
Show file tree
Hide file tree
Showing 45 changed files with 2,419 additions and 1,085 deletions.
13 changes: 8 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
minSdkVersion 16
targetSdkVersion 27
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 6802
versionName "v6.8.2-EH"
versionCode 7000
versionName "v7.0.0-EH"

buildConfigField "String", "COMMIT_COUNT", "\"${getCommitCount()}\""
buildConfigField "String", "COMMIT_SHA", "\"${getGitSha()}\""
Expand Down Expand Up @@ -107,7 +107,7 @@ android {
dependencies {

// Modified dependencies
implementation 'com.github.inorichi:subsampling-scale-image-view:c19b883'
implementation 'com.github.inorichi:subsampling-scale-image-view:81b9d68'
implementation 'com.github.inorichi:junrar-android:634c1f5'

// Android support library
Expand Down Expand Up @@ -206,7 +206,10 @@ dependencies {
implementation 'me.gujun.android.taggroup:library:1.4@aar'

// Conductor
implementation "com.bluelinelabs:conductor:2.1.4"
implementation "com.github.inorichi.Conductor:conductor:05c4d4d"
implementation ("com.bluelinelabs:conductor-support:2.1.5-SNAPSHOT") {
exclude group: "com.bluelinelabs", module: "conductor"
}
implementation 'com.github.inorichi:conductor-support-preference:27.0.2'

// RxBindings
Expand Down Expand Up @@ -250,7 +253,7 @@ dependencies {
}

buildscript {
ext.kotlin_version = '1.2.21'
ext.kotlin_version = '1.2.30'
repositories {
mavenCentral()
}
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@
android:scheme="tachiyomi" />
</intent-filter>
</activity>
<activity
android:name=".extension.util.ExtensionInstallActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"/>

<provider
android:name="android.support.v4.content.FileProvider"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ data class ALManga(
val id: Int,
val title_romaji: String,
val image_url_lge: String,
val description: String,
val description: String?,
val type: String,
val publishing_status: String,
val start_date_fuzzy: String,
Expand All @@ -25,7 +25,7 @@ data class ALManga(
title = title_romaji
total_chapters = this@ALManga.total_chapters
cover_url = image_url_lge
summary = description
summary = description ?: ""
tracking_url = AnilistApi.mangaUrl(remote_id)
publishing_status = this@ALManga.publishing_status
publishing_type = type
Expand All @@ -39,7 +39,6 @@ data class ALManga(
start_date_fuzzy.orEmpty()
}
}

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,6 @@ class ExtensionManager(
* Returns the relay of the available extensions as an observable.
*/
fun getAvailableExtensionsObservable(): Observable<List<Extension.Available>> {
if (!availableExtensionsRelay.hasValue()) {
findAvailableExtensions()
}
return availableExtensionsRelay.asObservable()
}

Expand Down Expand Up @@ -204,6 +201,16 @@ class ExtensionManager(
return installExtension(availableExt)
}

/**
* Sets the result of the installation of an extension.
*
* @param downloadId The id of the download.
* @param result Whether the extension was installed or not.
*/
fun setInstallationResult(downloadId: Long, result: Boolean) {
installer.setInstallationResult(downloadId, result)
}

/**
* Uninstalls the extension that matches the given package name.
*
Expand Down Expand Up @@ -298,17 +305,14 @@ class ExtensionManager(

override fun onExtensionInstalled(extension: Extension.Installed) {
registerNewExtension(extension.withUpdateCheck())
installer.onApkInstalled(extension.pkgName)
}

override fun onExtensionUpdated(extension: Extension.Installed) {
registerUpdatedExtension(extension.withUpdateCheck())
installer.onApkInstalled(extension.pkgName)
}

override fun onExtensionUntrusted(extension: Extension.Untrusted) {
untrustedExtensions += extension
installer.onApkInstalled(extension.pkgName)
}

override fun onPackageUninstalled(pkgName: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package eu.kanade.tachiyomi.extension.util

import android.app.Activity
import android.content.Intent
import android.os.Bundle
import eu.kanade.tachiyomi.extension.ExtensionManager
import eu.kanade.tachiyomi.util.toast
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get

/**
* Activity used to install extensions, because we can only receive the result of the installation
* with [startActivityForResult], which we need to update the UI.
*/
class ExtensionInstallActivity : Activity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val installIntent = Intent(Intent.ACTION_INSTALL_PACKAGE)
.setDataAndType(intent.data, intent.type)
.putExtra(Intent.EXTRA_RETURN_RESULT, true)
.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)

try {
startActivityForResult(installIntent, INSTALL_REQUEST_CODE)
} catch (error: Exception) {
// Either install package can't be found (probably bots) or there's a security exception
// with the download manager. Nothing we can workaround.
toast(error.message)
}
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == INSTALL_REQUEST_CODE) {
checkInstallationResult(resultCode)
}
finish()
}

private fun checkInstallationResult(resultCode: Int) {
val downloadId = intent.extras.getLong(ExtensionInstaller.EXTRA_DOWNLOAD_ID)
val success = resultCode == RESULT_OK

val extensionManager = Injekt.get<ExtensionManager>()
extensionManager.setInstallationResult(downloadId, success)
}

private companion object {
const val INSTALL_REQUEST_CODE = 500
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ internal class ExtensionInstaller(private val context: Context) {
.mergeWith(pollStatus(id))
// Force an error if the download takes more than 3 minutes
.mergeWith(Observable.timer(3, TimeUnit.MINUTES).map { InstallStep.Error })
// Force an error if the install process takes more than 10 seconds
.flatMap { Observable.just(it).mergeWith(timeoutWhenInstalling(it)) }
// Stop when the application is installed or errors
.takeUntil { it.isCompleted() }
// Always notify on main thread
Expand Down Expand Up @@ -118,27 +116,15 @@ internal class ExtensionInstaller(private val context: Context) {
}
}

/**
* Returns an observable that timeouts the installation after a specified time when the apk has
* been downloaded.
*
* @param currentStep The current step of the installation process.
*/
private fun timeoutWhenInstalling(currentStep: InstallStep): Observable<InstallStep> {
return Observable.just(currentStep)
.filter { it == InstallStep.Installing }
.delay(10, TimeUnit.SECONDS)
.map { InstallStep.Error }
}

/**
* Starts an intent to install the extension at the given uri.
*
* @param uri The uri of the extension to install.
*/
fun installApk(uri: Uri) {
val intent = Intent(Intent.ACTION_VIEW)
fun installApk(downloadId: Long, uri: Uri) {
val intent = Intent(context, ExtensionInstallActivity::class.java)
.setDataAndType(uri, APK_MIME)
.putExtra(EXTRA_DOWNLOAD_ID, downloadId)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION)

context.startActivity(intent)
Expand All @@ -158,13 +144,14 @@ internal class ExtensionInstaller(private val context: Context) {
}

/**
* Called when an extension is installed, allowing to update its installation step.
* Sets the result of the installation of an extension.
*
* @param pkgName The package name of the installed application.
* @param downloadId The id of the download.
* @param result Whether the extension was installed or not.
*/
fun onApkInstalled(pkgName: String) {
val id = activeDownloads[pkgName] ?: return
downloadsRelay.call(id to InstallStep.Installed)
fun setInstallationResult(downloadId: Long, result: Boolean) {
val step = if (result) InstallStep.Installed else InstallStep.Error
downloadsRelay.call(downloadId to step)
}

/**
Expand Down Expand Up @@ -243,17 +230,18 @@ internal class ExtensionInstaller(private val context: Context) {
@Suppress("DEPRECATION")
val uriCompat = File(cursor.getString(cursor.getColumnIndex(
DownloadManager.COLUMN_LOCAL_FILENAME))).getUriCompat(context)
installApk(uriCompat)
installApk(id, uriCompat)
}
}
} else {
installApk(uri)
installApk(id, uri)
}
}
}

private companion object {
companion object {
const val APK_MIME = "application/vnd.android.package-archive"
const val EXTRA_DOWNLOAD_ID = "ExtensionInstaller.extra.DOWNLOAD_ID"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ internal object ExtensionLoader {
* contains the required feature flag before trying to load it.
*/
fun loadExtensionFromPkgName(context: Context, pkgName: String): LoadResult {
val pkgInfo = context.packageManager.getPackageInfo(pkgName, PACKAGE_FLAGS)
val pkgInfo = try {
context.packageManager.getPackageInfo(pkgName, PACKAGE_FLAGS)
} catch (error: PackageManager.NameNotFoundException) {
// Unlikely, but the package may have been uninstalled at this point
return LoadResult.Error(error)
}
if (!isPackageAnExtension(pkgInfo)) {
return LoadResult.Error("Tried to load a package that wasn't a extension")
}
Expand All @@ -83,9 +88,15 @@ internal object ExtensionLoader {
private fun loadExtension(context: Context, pkgName: String, pkgInfo: PackageInfo): LoadResult {
val pkgManager = context.packageManager

val appInfo = pkgManager.getApplicationInfo(pkgName, PackageManager.GET_META_DATA)
val appInfo = try {
pkgManager.getApplicationInfo(pkgName, PackageManager.GET_META_DATA)
} catch (error: PackageManager.NameNotFoundException) {
// Unlikely, but the package may have been uninstalled at this point
return LoadResult.Error(error)
}

val extName = pkgManager.getApplicationLabel(appInfo).toString().substringAfter("Tachiyomi: ")
val extName = pkgManager.getApplicationLabel(appInfo)?.toString()
.orEmpty().substringAfter("Tachiyomi: ")
val versionName = pkgInfo.versionName
val versionCode = pkgInfo.versionCode

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ class Kissmanga : ParsedHttpSource() {
Genre("Mystery"),
Genre("One shot"),
Genre("Psychological"),
Genre("Reincarnation"),
Genre("Romance"),
Genre("School Life"),
Genre("Sci-fi"),
Expand All @@ -240,9 +239,7 @@ class Kissmanga : ParsedHttpSource() {
Genre("Smut"),
Genre("Sports"),
Genre("Supernatural"),
Genre("Time Travel"),
Genre("Tragedy"),
Genre("Transported"),
Genre("Webtoon"),
Genre("Yaoi"),
Genre("Yuri")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.bluelinelabs.conductor.ControllerChangeType
import com.bluelinelabs.conductor.RestoreViewOnCreateController
import kotlinx.android.extensions.LayoutContainer
import kotlinx.android.synthetic.*
import timber.log.Timber

abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle),
LayoutContainer {
Expand All @@ -21,6 +22,22 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
override fun postCreateView(controller: Controller, view: View) {
onViewCreated(view)
}

override fun preCreateView(controller: Controller) {
Timber.d("Create view for ${controller.instance()}")
}

override fun preAttach(controller: Controller, view: View) {
Timber.d("Attach view for ${controller.instance()}")
}

override fun preDetach(controller: Controller, view: View) {
Timber.d("Detach view for ${controller.instance()}")
}

override fun preDestroyView(controller: Controller, view: View) {
Timber.d("Destroy view for ${controller.instance()}")
}
})
}

Expand Down Expand Up @@ -63,6 +80,10 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
(activity as? AppCompatActivity)?.supportActionBar?.title = getTitle()
}

private fun Controller.instance(): String {
return "${javaClass.simpleName}@${Integer.toHexString(hashCode())}"
}

/**
* Workaround for disappearing menu items when collapsing an expandable item like a SearchView.
* This method should be removed when fixed upstream.
Expand All @@ -81,4 +102,4 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr
})
}

}
}
Loading

0 comments on commit 615fa05

Please sign in to comment.